Remove unnecessary braces
[wine/multimedia.git] / dsound_private.h
blobbe0f91cb824da5fa3bea534fedd2836057fe9565
1 /* DirectSound
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2001 TransGaming Technologies, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 /* Linux does not support better timing than 10ms */
23 #define DS_TIME_RES 2 /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */
25 /* Default refresh count, can be overridden */
26 #define FAKE_REFRESH_COUNT (1000/DS_TIME_DEL/2)
29 #ifdef __WINESRC__
31 #ifdef __APPLE__
32 #include <OpenAL/al.h>
33 #include <OpenAL/alc.h>
34 #else
35 #include <AL/al.h>
36 #include <AL/alc.h>
37 #endif
39 #else
41 #include <al.h>
42 #include <alc.h>
44 #include <stdio.h>
46 extern int LogLevel;
48 #ifdef DEBUG_INFO
49 #define TRACE(fmt,args...) do { \
50 if(LogLevel >= 3) \
51 fprintf(stderr, "%04x:trace:dsound:%s " fmt, (UINT)GetCurrentThreadId(), __FUNCTION__, ##args); \
52 } while(0)
53 #define WARN(fmt,args...) do { \
54 if(LogLevel >= 2) \
55 fprintf(stderr, "%04x:warn:dsound:%s " fmt, (UINT)GetCurrentThreadId(), __FUNCTION__, ##args); \
56 } while(0)
57 #define FIXME(fmt,args...) do { \
58 if(LogLevel >= 1) \
59 fprintf(stderr, "%04x:fixme:dsound:%s " fmt, (UINT)GetCurrentThreadId(), __FUNCTION__, ##args); \
60 } while(0)
61 #define ERR(fmt,args...) do { \
62 if(LogLevel >= 0) \
63 fprintf(stderr, "%04x:err:dsound:%s " fmt, (UINT)GetCurrentThreadId(), __FUNCTION__, ##args); \
64 } while(0)
65 #else
66 #define TRACE(args...)
67 #define WARN(args...)
68 #define FIXME(args...)
69 #define ERR(args...)
70 #endif
72 const char *wine_dbg_sprintf( const char *format, ... );
73 const char *wine_dbgstr_wn( const WCHAR *str, int n );
75 static inline const char *debugstr_guid( const GUID *id )
77 if (!id) return "(null)";
78 if (!((ULONG_PTR)id >> 16)) return wine_dbg_sprintf( "<guid-0x%04hx>", (WORD)(ULONG_PTR)id );
79 return wine_dbg_sprintf( "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
80 id->Data1, id->Data2, id->Data3,
81 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
82 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
85 static inline const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
87 #endif
90 #include "alext.h"
91 #include "eax.h"
93 /* Set to 1 to build a DLL that can be used in an app that uses OpenAL itself.
94 * Thread-local contexts are needed for true concurrency, however. Disallowing
95 * concurrency can avoid a save and restore of the context. */
96 #define ALLOW_CONCURRENT_AL 0
98 /* All openal functions */
99 extern int openal_loaded;
100 #ifdef SONAME_LIBOPENAL
101 extern LPALCCREATECONTEXT palcCreateContext;
102 extern LPALCMAKECONTEXTCURRENT palcMakeContextCurrent;
103 extern LPALCPROCESSCONTEXT palcProcessContext;
104 extern LPALCSUSPENDCONTEXT palcSuspendContext;
105 extern LPALCDESTROYCONTEXT palcDestroyContext;
106 extern LPALCGETCURRENTCONTEXT palcGetCurrentContext;
107 extern LPALCGETCONTEXTSDEVICE palcGetContextsDevice;
108 extern LPALCOPENDEVICE palcOpenDevice;
109 extern LPALCCLOSEDEVICE palcCloseDevice;
110 extern LPALCGETERROR palcGetError;
111 extern LPALCISEXTENSIONPRESENT palcIsExtensionPresent;
112 extern LPALCGETPROCADDRESS palcGetProcAddress;
113 extern LPALCGETENUMVALUE palcGetEnumValue;
114 extern LPALCGETSTRING palcGetString;
115 extern LPALCGETINTEGERV palcGetIntegerv;
116 extern LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice;
117 extern LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice;
118 extern LPALCCAPTURESTART palcCaptureStart;
119 extern LPALCCAPTURESTOP palcCaptureStop;
120 extern LPALCCAPTURESAMPLES palcCaptureSamples;
121 extern LPALENABLE palEnable;
122 extern LPALDISABLE palDisable;
123 extern LPALISENABLED palIsEnabled;
124 extern LPALGETSTRING palGetString;
125 extern LPALGETBOOLEANV palGetBooleanv;
126 extern LPALGETINTEGERV palGetIntegerv;
127 extern LPALGETFLOATV palGetFloatv;
128 extern LPALGETDOUBLEV palGetDoublev;
129 extern LPALGETBOOLEAN palGetBoolean;
130 extern LPALGETINTEGER palGetInteger;
131 extern LPALGETFLOAT palGetFloat;
132 extern LPALGETDOUBLE palGetDouble;
133 extern LPALGETERROR palGetError;
134 extern LPALISEXTENSIONPRESENT palIsExtensionPresent;
135 extern LPALGETPROCADDRESS palGetProcAddress;
136 extern LPALGETENUMVALUE palGetEnumValue;
137 extern LPALLISTENERF palListenerf;
138 extern LPALLISTENER3F palListener3f;
139 extern LPALLISTENERFV palListenerfv;
140 extern LPALLISTENERI palListeneri;
141 extern LPALLISTENER3I palListener3i;
142 extern LPALLISTENERIV palListeneriv;
143 extern LPALGETLISTENERF palGetListenerf;
144 extern LPALGETLISTENER3F palGetListener3f;
145 extern LPALGETLISTENERFV palGetListenerfv;
146 extern LPALGETLISTENERI palGetListeneri;
147 extern LPALGETLISTENER3I palGetListener3i;
148 extern LPALGETLISTENERIV palGetListeneriv;
149 extern LPALGENSOURCES palGenSources;
150 extern LPALDELETESOURCES palDeleteSources;
151 extern LPALISSOURCE palIsSource;
152 extern LPALSOURCEF palSourcef;
153 extern LPALSOURCE3F palSource3f;
154 extern LPALSOURCEFV palSourcefv;
155 extern LPALSOURCEI palSourcei;
156 extern LPALSOURCE3I palSource3i;
157 extern LPALSOURCEIV palSourceiv;
158 extern LPALGETSOURCEF palGetSourcef;
159 extern LPALGETSOURCE3F palGetSource3f;
160 extern LPALGETSOURCEFV palGetSourcefv;
161 extern LPALGETSOURCEI palGetSourcei;
162 extern LPALGETSOURCE3I palGetSource3i;
163 extern LPALGETSOURCEIV palGetSourceiv;
164 extern LPALSOURCEPLAYV palSourcePlayv;
165 extern LPALSOURCESTOPV palSourceStopv;
166 extern LPALSOURCEREWINDV palSourceRewindv;
167 extern LPALSOURCEPAUSEV palSourcePausev;
168 extern LPALSOURCEPLAY palSourcePlay;
169 extern LPALSOURCESTOP palSourceStop;
170 extern LPALSOURCEREWIND palSourceRewind;
171 extern LPALSOURCEPAUSE palSourcePause;
172 extern LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers;
173 extern LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers;
174 extern LPALGENBUFFERS palGenBuffers;
175 extern LPALDELETEBUFFERS palDeleteBuffers;
176 extern LPALISBUFFER palIsBuffer;
177 extern LPALBUFFERF palBufferf;
178 extern LPALBUFFER3F palBuffer3f;
179 extern LPALBUFFERFV palBufferfv;
180 extern LPALBUFFERI palBufferi;
181 extern LPALBUFFER3I palBuffer3i;
182 extern LPALBUFFERIV palBufferiv;
183 extern LPALGETBUFFERF palGetBufferf;
184 extern LPALGETBUFFER3F palGetBuffer3f;
185 extern LPALGETBUFFERFV palGetBufferfv;
186 extern LPALGETBUFFERI palGetBufferi;
187 extern LPALGETBUFFER3I palGetBuffer3i;
188 extern LPALGETBUFFERIV palGetBufferiv;
189 extern LPALBUFFERDATA palBufferData;
190 extern LPALDOPPLERFACTOR palDopplerFactor;
191 extern LPALDOPPLERVELOCITY palDopplerVelocity;
192 extern LPALDISTANCEMODEL palDistanceModel;
193 extern LPALSPEEDOFSOUND palSpeedOfSound;
195 #define alcCreateContext palcCreateContext
196 #define alcMakeContextCurrent palcMakeContextCurrent
197 #define alcProcessContext palcProcessContext
198 #define alcSuspendContext palcSuspendContext
199 #define alcDestroyContext palcDestroyContext
200 #define alcGetCurrentContext palcGetCurrentContext
201 #define alcGetContextsDevice palcGetContextsDevice
202 #define alcOpenDevice palcOpenDevice
203 #define alcCloseDevice palcCloseDevice
204 #define alcGetError palcGetError
205 #define alcIsExtensionPresent palcIsExtensionPresent
206 #define alcGetProcAddress palcGetProcAddress
207 #define alcGetEnumValue palcGetEnumValue
208 #define alcGetString palcGetString
209 #define alcGetIntegerv palcGetIntegerv
210 #define alcCaptureOpenDevice palcCaptureOpenDevice
211 #define alcCaptureCloseDevice palcCaptureCloseDevice
212 #define alcCaptureStart palcCaptureStart
213 #define alcCaptureStop palcCaptureStop
214 #define alcCaptureSamples palcCaptureSamples
215 #define alEnable palEnable
216 #define alDisable palDisable
217 #define alIsEnabled palIsEnabled
218 #define alGetString palGetString
219 #define alGetBooleanv palGetBooleanv
220 #define alGetIntegerv palGetIntegerv
221 #define alGetFloatv palGetFloatv
222 #define alGetDoublev palGetDoublev
223 #define alGetBoolean palGetBoolean
224 #define alGetInteger palGetInteger
225 #define alGetFloat palGetFloat
226 #define alGetDouble palGetDouble
227 #define alGetError palGetError
228 #define alIsExtensionPresent palIsExtensionPresent
229 #define alGetProcAddress palGetProcAddress
230 #define alGetEnumValue palGetEnumValue
231 #define alListenerf palListenerf
232 #define alListener3f palListener3f
233 #define alListenerfv palListenerfv
234 #define alListeneri palListeneri
235 #define alListener3i palListener3i
236 #define alListeneriv palListeneriv
237 #define alGetListenerf palGetListenerf
238 #define alGetListener3f palGetListener3f
239 #define alGetListenerfv palGetListenerfv
240 #define alGetListeneri palGetListeneri
241 #define alGetListener3i palGetListener3i
242 #define alGetListeneriv palGetListeneriv
243 #define alGenSources palGenSources
244 #define alDeleteSources palDeleteSources
245 #define alIsSource palIsSource
246 #define alSourcef palSourcef
247 #define alSource3f palSource3f
248 #define alSourcefv palSourcefv
249 #define alSourcei palSourcei
250 #define alSource3i palSource3i
251 #define alSourceiv palSourceiv
252 #define alGetSourcef palGetSourcef
253 #define alGetSource3f palGetSource3f
254 #define alGetSourcefv palGetSourcefv
255 #define alGetSourcei palGetSourcei
256 #define alGetSource3i palGetSource3i
257 #define alGetSourceiv palGetSourceiv
258 #define alSourcePlayv palSourcePlayv
259 #define alSourceStopv palSourceStopv
260 #define alSourceRewindv palSourceRewindv
261 #define alSourcePausev palSourcePausev
262 #define alSourcePlay palSourcePlay
263 #define alSourceStop palSourceStop
264 #define alSourceRewind palSourceRewind
265 #define alSourcePause palSourcePause
266 #define alSourceQueueBuffers palSourceQueueBuffers
267 #define alSourceUnqueueBuffers palSourceUnqueueBuffers
268 #define alGenBuffers palGenBuffers
269 #define alDeleteBuffers palDeleteBuffers
270 #define alIsBuffer palIsBuffer
271 #define alBufferf palBufferf
272 #define alBuffer3f palBuffer3f
273 #define alBufferfv palBufferfv
274 #define alBufferi palBufferi
275 #define alBuffer3i palBuffer3i
276 #define alBufferiv palBufferiv
277 #define alGetBufferf palGetBufferf
278 #define alGetBuffer3f palGetBuffer3f
279 #define alGetBufferfv palGetBufferfv
280 #define alGetBufferi palGetBufferi
281 #define alGetBuffer3i palGetBuffer3i
282 #define alGetBufferiv palGetBufferiv
283 #define alBufferData palBufferData
284 #define alDopplerFactor palDopplerFactor
285 #define alDopplerVelocity palDopplerVelocity
286 #define alDistanceModel palDistanceModel
287 #define alSpeedOfSound palSpeedOfSound
288 #endif
290 #include <math.h>
291 #include "wingdi.h"
292 #include "mmreg.h"
294 /* OpenAL only allows for 1 single access to the device at the same time */
295 extern CRITICAL_SECTION openal_crst;
297 extern const ALCchar *DSOUND_getdevicestrings(void);
298 extern const ALCchar *DSOUND_getcapturedevicestrings(void);
300 extern LPALCMAKECONTEXTCURRENT set_context;
301 extern LPALCGETCURRENTCONTEXT get_context;
302 extern BOOL local_contexts;
304 /* Device implementation */
305 typedef struct DS8Primary DS8Primary;
306 typedef struct DS8Buffer DS8Buffer;
308 typedef struct DS8Impl
310 IDirectSound8 IDirectSound8_iface;
312 LONG ref;
313 BOOL is_8;
315 LONG *deviceref;
316 ALCdevice *device;
317 DS8Primary *primary;
319 DWORD speaker_config;
320 DWORD prio_level;
321 GUID guid;
322 } DS8Impl;
324 /* Sample types */
325 #define AL_BYTE 0x1400
326 #define AL_UNSIGNED_BYTE 0x1401
327 #define AL_SHORT 0x1402
328 #define AL_UNSIGNED_SHORT 0x1403
329 #define AL_INT 0x1404
330 #define AL_UNSIGNED_INT 0x1405
331 #define AL_FLOAT 0x1406
332 #define AL_DOUBLE 0x1407
333 #define AL_BYTE3 0x1408
334 #define AL_UNSIGNED_BYTE3 0x1409
335 #define AL_MULAW 0x1410
336 #define AL_IMA4 0x1411
338 /* Channel configurations */
339 #define AL_MONO 0x1500
340 #define AL_STEREO 0x1501
341 #define AL_REAR 0x1502
342 #define AL_QUAD 0x1503
343 #define AL_5POINT1 0x1504 /* (WFX order) */
344 #define AL_6POINT1 0x1505 /* (WFX order) */
345 #define AL_7POINT1 0x1506 /* (WFX order) */
347 enum {
348 EXT_EFX,
349 EXT_FLOAT32,
350 EXT_MCFORMATS,
351 EXT_STATIC_BUFFER,
352 SOFT_BUFFER_SAMPLES,
353 SOFT_BUFFER_SUB_DATA,
354 SOFT_DEFERRED_UPDATES,
356 MAX_EXTENSIONS
359 typedef struct ExtALFuncs
361 PFNALBUFFERSUBDATASOFTPROC BufferSubData;
362 PFNALBUFFERDATASTATICPROC BufferDataStatic;
364 LPALGENEFFECTS GenEffects;
365 LPALDELETEEFFECTS DeleteEffects;
366 LPALEFFECTI Effecti;
367 LPALEFFECTF Effectf;
369 LPALGENAUXILIARYEFFECTSLOTS GenAuxiliaryEffectSlots;
370 LPALDELETEAUXILIARYEFFECTSLOTS DeleteAuxiliaryEffectSlots;
371 LPALAUXILIARYEFFECTSLOTI AuxiliaryEffectSloti;
373 void (AL_APIENTRY*BufferSamplesSOFT)(ALuint,ALuint,ALenum,ALsizei,ALenum,ALenum,const ALvoid*);
374 void (AL_APIENTRY*BufferSubSamplesSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,const ALvoid*);
375 void (AL_APIENTRY*GetBufferSamplesSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,ALvoid*);
376 ALboolean (AL_APIENTRY*IsBufferFormatSupportedSOFT)(ALenum);
378 void (AL_APIENTRY*DeferUpdates)(void);
379 void (AL_APIENTRY*ProcessUpdates)(void);
380 } ExtALFuncs;
382 struct DS8Primary
384 IDirectSoundBuffer IDirectSoundBuffer_iface;
385 IDirectSound3DListener IDirectSound3DListener_iface;
386 IKsPropertySet IKsPropertySet_iface;
388 LONG ref, ds3d_ref, prop_ref;
389 IDirectSoundBuffer8 *write_emu;
390 DS8Impl *parent;
392 CRITICAL_SECTION crst;
394 DWORD buf_size;
395 BOOL stopped;
396 DWORD flags;
397 WAVEFORMATEXTENSIBLE format;
398 ALCcontext *ctx;
400 ALboolean SupportedExt[MAX_EXTENSIONS];
402 ALuint *sources;
403 DWORD nsources, sizesources;
404 DWORD max_sources;
405 DS8Buffer **buffers;
406 DWORD nbuffers, sizebuffers;
407 DS8Buffer **notifies;
408 DWORD nnotifies, sizenotifies;
409 UINT timer_id;
410 DWORD timer_res;
412 ALuint auxslot;
413 ALuint effect;
414 EAXLISTENERPROPERTIES eax_prop;
416 ExtALFuncs ExtAL;
417 union {
418 struct {
419 BOOL pos : 1;
420 BOOL vel : 1;
421 BOOL orientation : 1;
422 BOOL distancefactor : 1;
423 BOOL rollofffactor : 1;
424 BOOL dopplerfactor : 1;
425 BOOL effect : 1;
426 } bit;
427 int flags;
428 } dirty;
429 ALfloat rollofffactor;
430 DS3DLISTENER listen;
433 typedef struct DS8Data DS8Data;
435 struct DS8Buffer
437 IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
438 IDirectSound3DBuffer IDirectSound3DBuffer_iface;
439 IDirectSoundNotify IDirectSoundNotify_iface;
440 IKsPropertySet IKsPropertySet_iface;
442 LONG ref, ds3d_ref, not_ref, prop_ref;
443 LONG all_ref;
445 DWORD ds3dmode;
446 DS8Primary *primary;
447 DS8Data *buffer;
448 ALuint source;
449 ALuint curidx;
450 BOOL isplaying, islooping, bufferlost;
451 ALCcontext *ctx;
452 ExtALFuncs *ExtAL;
453 CRITICAL_SECTION *crst;
455 DS3DBUFFER ds3dbuffer;
456 union {
457 struct {
458 BOOL pos : 1;
459 BOOL vel : 1;
460 BOOL cone_angles : 1;
461 BOOL cone_orient : 1;
462 BOOL cone_outsidevolume : 1;
463 BOOL min_distance : 1;
464 BOOL max_distance : 1;
465 BOOL mode : 1;
466 } bit;
467 int flags;
468 } dirty;
470 DWORD nnotify, lastpos;
471 DSBPOSITIONNOTIFY *notify;
474 extern HRESULT DS8Primary_Create(DS8Primary **prim, DS8Impl *parent);
475 extern void DS8Primary_Destroy(DS8Primary *prim);
477 extern HRESULT DS8Buffer_Create(DS8Buffer **ppv, DS8Primary *parent, DS8Buffer *orig);
478 extern void DS8Buffer_Destroy(DS8Buffer *buf);
480 static inline ALdouble gain_to_mB(ALdouble gain)
482 return log10(gain) * 2000.0;
484 static inline ALdouble mB_to_gain(ALdouble millibels)
486 return pow(10.0, millibels/2000.0);
489 static inline LONG clampI(LONG val, LONG minval, LONG maxval)
491 if(val >= maxval) return maxval;
492 if(val <= minval) return minval;
493 return val;
495 static inline ULONG clampU(ULONG val, ULONG minval, ULONG maxval)
497 if(val >= maxval) return maxval;
498 if(val <= minval) return minval;
499 return val;
501 static inline FLOAT clampF(FLOAT val, FLOAT minval, FLOAT maxval)
503 if(val >= maxval) return maxval;
504 if(val <= minval) return minval;
505 return val;
509 #define getALError() \
510 do { \
511 ALenum err = alGetError(); \
512 if(err != AL_NO_ERROR) \
513 ERR(">>>>>>>>>>>> Received AL error %#x on context %p, %s:%u\n", err, get_context(), __FUNCTION__, __LINE__); \
514 } while (0)
516 #define getALCError(dev) \
517 do { \
518 ALenum err = alcGetError(dev); \
519 if(err != ALC_NO_ERROR) \
520 ERR(">>>>>>>>>>>> Received ALC error %#x on device %p, %s:%u\n", err, dev, __FUNCTION__, __LINE__); \
521 } while(0)
523 #if ALLOW_CONCURRENT_AL
525 #define setALContext(actx) \
526 do { \
527 ALCcontext *__old_ctx, *cur_ctx = actx; \
528 if (!local_contexts) EnterCriticalSection(&openal_crst); \
529 __old_ctx = get_context(); \
530 if (__old_ctx != cur_ctx && set_context(cur_ctx) == ALC_FALSE) {\
531 ERR("Couldn't set current context!!\n"); \
532 getALCError(alcGetContextsDevice(cur_ctx)); \
535 /* Only restore a NULL context if using global contexts, for TLS contexts always restore */
536 #define popALContext() \
537 if (__old_ctx != cur_ctx && \
538 (local_contexts || __old_ctx) && \
539 set_context(__old_ctx) == ALC_FALSE) { \
540 ERR("Couldn't restore old context!!\n"); \
541 getALCError(alcGetContextsDevice(__old_ctx)); \
543 if (!local_contexts) LeaveCriticalSection(&openal_crst); \
544 } while (0)
546 #else
548 #define setALContext(actx) \
549 do { \
550 ALCcontext *cur_ctx = actx; \
551 if (!local_contexts) EnterCriticalSection(&openal_crst); \
552 if (set_context(cur_ctx) == ALC_FALSE) { \
553 ERR("Couldn't set current context!!\n"); \
554 getALCError(alcGetContextsDevice(cur_ctx)); \
557 #define popALContext() \
558 if (!local_contexts) LeaveCriticalSection(&openal_crst); \
559 } while (0)
561 #endif
563 HRESULT DSOUND_Create(REFIID riid, void **ppDS);
564 HRESULT DSOUND_Create8(REFIID riid, void **ppDS);
565 HRESULT DSOUND_FullDuplexCreate(REFIID riid, void **ppDSFD);
566 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, void **piks);
567 HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppDSC);
568 HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppDSC8);
570 extern const GUID DSOUND_renderer_guid;
571 extern const GUID DSOUND_capture_guid;