Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / sound / driver / dsound / sound_driver_dsound.h
blobe928cf137ffac08d1233ef7c08218dfd126c9575
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef NL_SOUND_DRIVER_DSOUND_H
18 #define NL_SOUND_DRIVER_DSOUND_H
20 #include "nel/sound/driver/sound_driver.h"
22 #include "source_dsound.h"
23 #include "buffer_dsound.h"
25 namespace NLSOUND {
27 class IListener;
28 class ISource;
29 class IBuffer;
30 class CListenerDSound;
31 class CSourceDSound;
32 class CBufferDSound;
34 class CSoundDriverDSound : public ISoundDriver
36 public:
37 /// Constructor
38 CSoundDriverDSound(ISoundDriver::IStringMapperProvider *stringMapper);
40 virtual ~CSoundDriverDSound();
42 /// Return the instance of the singleton
43 static CSoundDriverDSound *instance() { return _Instance; }
45 /// Return a list of available devices for the user. The value at index 0 is empty, and is used for automatic device selection.
46 virtual void getDevices(std::vector<std::string> &devices);
47 /// Initialize the driver with a user selected device. If device.empty(), the default or most appropriate device is used.
48 virtual void initDevice(const std::string &device, TSoundOptions options);
50 /// Return options that are enabled (including those that cannot be disabled on this driver).
51 virtual TSoundOptions getOptions();
52 /// Return if an option is enabled (including those that cannot be disabled on this driver).
53 virtual bool getOption(TSoundOptions option);
55 /// Create the listener instance
56 virtual IListener *createListener();
58 /// Create a sound buffer
59 virtual IBuffer *createBuffer();
61 // Source management
63 /// Create a source
64 virtual ISource *createSource();
66 /// Commit all the changes made to 3D settings of listener and sources
67 virtual void commit3DChanges();
69 /// Return the maximum number of sources that can created
70 virtual uint countMaxSources();
72 /// Count the number of available hardware streaming 3D buffers
73 uint countHw3DBuffers();
75 /// Count the number of available hardware streaming 2D buffers
76 uint countHw2DBuffers();
78 /// Count the number of sources that are actually playing.
79 uint countPlayingSources();
81 /// Update all the driver and its sources. To be called only by the timer callback.
82 void update();
84 /// Write information about the driver to the output stream.
85 void writeProfile(std::string& out);
88 /** Set the gain (volume value inside [0 , 1]). (default: 1)
89 * 0.0 -> silence
90 * 0.5 -> -6dB
91 * 1.0 -> no attenuation
92 * values > 1 (amplification) not supported by most drivers
94 void setGain( float gain );
96 /// Get the gain
97 float getGain();
99 /// Return the string mapper
100 IStringMapperProvider *getStringMapper() {return _StringMapper;}
102 #if EAX_AVAILABLE == 1
103 LPKSPROPERTYSET createPropertySet(CSourceDSound *source);
104 #endif
106 /// Create a music channel, destroy with destroyMusicChannel
107 virtual IMusicChannel *createMusicChannel() { return NULL; }
109 /// Destroy a music channel
110 virtual void destroyMusicChannel(IMusicChannel * /* musicChannel */) { nlassert(false); }
112 /** Get music info. Returns false if the song is not found or the function is not implemented.
113 * If the song has no name, result is filled with the filename.
114 * \param filepath path to file, CPath::lookup done by driver
115 * \param artist returns the song artist (empty if not available)
116 * \param title returns the title (empty if not available)
118 virtual bool getMusicInfo(const std::string & /* filepath */, std::string &artist, std::string &title, float &length) { artist.clear(); title.clear(); length = 0.f; return false; }
120 private:
122 // The callback for the multimedia timer
123 static void CALLBACK TimerCallback(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
125 // The refence to the singleton.
126 static CSoundDriverDSound* _Instance;
128 // The period of the timer.
129 static uint32 _TimerPeriod;
131 friend CBufferDSound::~CBufferDSound();
132 friend CSourceDSound::~CSourceDSound();
134 /// Remove a buffer (should be called by the friend destructor of the buffer class)
135 virtual void removeBuffer(IBuffer *buffer);
137 /// Remove a source (should be called by the friend destructor of the source class)
138 virtual void removeSource(ISource *source);
141 virtual void startBench();
142 virtual void endBench();
143 virtual void displayBench(NLMISC::CLog *log);
146 /// Get audio/container extensions that are supported natively by the driver implementation.
147 virtual void getMusicExtensions(std::vector<std::string> & /* extensions */) const { }
148 /// Return if a music extension is supported by the driver's music channel.
149 virtual bool isMusicExtensionSupported(const std::string & /* extension */) const { return false; }
152 // The DirectSound object
153 LPDIRECTSOUND _DirectSound;
155 // The application-wide primary buffer
156 LPDIRECTSOUNDBUFFER _PrimaryBuffer;
158 // The capabilities of the driver
159 DSCAPS _Caps;
161 // Array with the allocated sources
162 //CSourceDSound** _Sources;
163 std::set<CSourceDSound*> _Sources;
165 // The number of allocated sources
166 uint _SourceCount;
168 // The Windows ID of the multimedia timer used in the update.
169 UINT _TimerID;
171 // The timer resolution.
172 uint32 _TimerResolution;
174 /// The EAX support is requested and accepted (ie, there is enougth hardware 3D buffer)
175 bool _UseEAX;
176 /// The string mapper provided by client code
177 IStringMapperProvider *_StringMapper;
178 /// Driver options
179 TSoundOptions _Options;
181 #if NLSOUND_PROFILE
182 protected:
185 uint _TimerInterval[1024];
186 uint _TimerIntervalCount;
187 NLMISC::TTicks _TimerDate;
188 double _TotalTime;
189 double _TotalUpdateTime;
190 uint32 _UpdateCount;
191 uint32 _UpdateSources;
192 uint32 _UpdateExec;
195 public:
197 void printDriverInfo(FILE* fp);
198 uint countTimerIntervals();
199 uint getTimerIntervals(uint index);
200 void addTimerInterval(uint32 dt);
201 double getCPULoad();
202 double getTotalTime() { return _TotalTime; };
203 double getAverageUpdateTime() { return (_UpdateCount) ? _TotalUpdateTime / _UpdateCount : 0.0; }
204 uint32 getAverageUpdateSources() { return (_UpdateExec) ? _UpdateSources / _UpdateExec : 0; }
205 double getUpdatePercentage() { return (_UpdateCount) ? (double) _UpdateExec / (double) _UpdateCount: 0; }
206 #endif
212 } // NLSOUND
214 #endif // NL_SOUND_DRIVER_DSOUND_H