Remove an errant early-out check
[dsound-openal.git] / dsound_private.h
blob3cef29758b6059e6dfd6c3b802c263c53c16d235
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 #include <stdio.h>
30 #include <math.h>
31 #include <dsound.h>
32 #include <mmdeviceapi.h>
33 #include <devpropdef.h>
35 #include "wingdi.h"
36 #include "mmreg.h"
38 #include "alc.h"
39 #include "al.h"
40 #include "alext.h"
42 #include "eax.h"
44 #ifndef AL_SOFT_map_buffer
45 #define AL_SOFT_map_buffer 1
46 typedef unsigned int ALbitfieldSOFT;
47 #define AL_MAP_READ_BIT_SOFT 0x00000001
48 #define AL_MAP_WRITE_BIT_SOFT 0x00000002
49 #define AL_MAP_PERSISTENT_BIT_SOFT 0x00000004
50 #define AL_PRESERVE_DATA_BIT_SOFT 0x00000008
51 typedef void (AL_APIENTRY*LPALBUFFERSTORAGESOFT)(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq, ALbitfieldSOFT flags);
52 typedef void* (AL_APIENTRY*LPALMAPBUFFERSOFT)(ALuint buffer, ALsizei offset, ALsizei length, ALbitfieldSOFT access);
53 typedef void (AL_APIENTRY*LPALUNMAPBUFFERSOFT)(ALuint buffer);
54 typedef void (AL_APIENTRY*LPALFLUSHMAPPEDBUFFERSOFT)(ALuint buffer, ALsizei offset, ALsizei length);
55 #endif
58 #ifdef __GNUC__
59 #define LIKELY(x) __builtin_expect(!!(x), !0)
60 #define UNLIKELY(x) __builtin_expect(!!(x), !!0)
61 #else
62 #define LIKELY(x) (!!(x))
63 #define UNLIKELY(x) (!!(x))
64 #endif
67 extern int LogLevel;
68 extern FILE *LogFile;
70 #define DO_PRINT(a, ...) do { \
71 fprintf(LogFile, a, __VA_ARGS__); \
72 fflush(LogFile); \
73 } while(0)
75 #ifdef _MSC_VER
76 #define TRACE(fmt, ...) do { \
77 if(UNLIKELY(LogLevel >= 3)) \
78 DO_PRINT("%04x:trace:dsound:%s " fmt, (UINT)GetCurrentThreadId(), \
79 __FUNCTION__, __VA_ARGS__); \
80 } while(0)
81 #define WARN(fmt, ...) do { \
82 if(UNLIKELY(LogLevel >= 2)) \
83 DO_PRINT("%04x:warn:dsound:%s " fmt, (UINT)GetCurrentThreadId(), \
84 __FUNCTION__, __VA_ARGS__); \
85 } while(0)
86 #define FIXME(fmt, ...) do { \
87 if(UNLIKELY(LogLevel >= 1)) \
88 DO_PRINT("%04x:fixme:dsound:%s " fmt, (UINT)GetCurrentThreadId(), \
89 __FUNCTION__, __VA_ARGS__); \
90 } while(0)
91 #define ERR(fmt, ...) do { \
92 if(UNLIKELY(LogLevel >= 0)) \
93 DO_PRINT("%04x:err:dsound:%s " fmt, (UINT)GetCurrentThreadId(), \
94 __FUNCTION__, __VA_ARGS__); \
95 } while(0)
97 #else
99 #define TRACE(fmt, ...) do { \
100 if(UNLIKELY(LogLevel >= 3)) \
101 DO_PRINT("%04x:trace:dsound:%s " fmt, (UINT)GetCurrentThreadId(), \
102 __FUNCTION__, ## __VA_ARGS__); \
103 } while(0)
104 #define WARN(fmt, ...) do { \
105 if(UNLIKELY(LogLevel >= 2)) \
106 DO_PRINT("%04x:warn:dsound:%s " fmt, (UINT)GetCurrentThreadId(), \
107 __FUNCTION__, ## __VA_ARGS__); \
108 } while(0)
109 #define FIXME(fmt, ...) do { \
110 if(UNLIKELY(LogLevel >= 1)) \
111 DO_PRINT("%04x:fixme:dsound:%s " fmt, (UINT)GetCurrentThreadId(), \
112 __FUNCTION__, ## __VA_ARGS__); \
113 } while(0)
114 #define ERR(fmt, ...) do { \
115 if(UNLIKELY(LogLevel >= 0)) \
116 DO_PRINT("%04x:err:dsound:%s " fmt, (UINT)GetCurrentThreadId(), \
117 __FUNCTION__, ## __VA_ARGS__); \
118 } while(0)
119 #endif
121 const char *wine_dbg_sprintf( const char *format, ... );
122 const char *wine_dbgstr_wn( const WCHAR *str, int n );
123 const char *debugstr_guid( const GUID *id );
125 static inline const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
128 #ifndef U64
129 #if defined(_MSC_VER)
130 #define U64(x) (x##ui64)
131 #elif SIZEOF_LONG == 8
132 #define U64(x) (x##ul)
133 #else
134 #define U64(x) (x##ull)
135 #endif
136 #endif
138 /* Define a CTZ64 macro (count trailing zeros, for 64-bit integers). The result
139 * is *UNDEFINED* if the value is 0.
141 #ifdef __GNUC__
143 #if SIZEOF_LONG == 8
144 #define POPCNT64 __builtin_popcountl
145 #define CTZ64 __builtin_ctzl
146 #else
147 #define POPCNT64 __builtin_popcountll
148 #define CTZ64 __builtin_ctzll
149 #endif
151 #else
153 /* There be black magics here. The popcnt64 method is derived from
154 * https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
156 static inline int fallback_popcnt64(DWORD64 v)
158 v = v - ((v >> 1) & U64(0x5555555555555555));
159 v = (v & U64(0x3333333333333333)) + ((v >> 2) & U64(0x3333333333333333));
160 v = (v + (v >> 4)) & U64(0x0f0f0f0f0f0f0f0f);
161 return (int)((v * U64(0x0101010101010101)) >> 56);
163 #define POPCNT64 fallback_popcnt64
165 #if defined(HAVE_BITSCANFORWARD64_INTRINSIC)
167 static inline int msvc64_ctz64(DWORD64 v)
169 unsigned long idx = 64;
170 _BitScanForward64(&idx, v);
171 return (int)idx;
173 #define CTZ64 msvc64_ctz64
175 #elif defined(HAVE_BITSCANFORWARD_INTRINSIC)
177 static inline int msvc_ctz64(DWORD64 v)
179 unsigned long idx = 64;
180 if(!_BitScanForward(&idx, v&0xffffffff))
182 if(_BitScanForward(&idx, v>>32))
183 idx += 32;
185 return (int)idx;
187 #define CTZ64 msvc_ctz64
189 #else
191 static inline int fallback_ctz64(DWORD64 value)
193 return fallback_popcnt64(~value & (value - 1));
195 #define CTZ64 fallback_ctz64
196 #endif
197 #endif
200 /* All openal functions */
201 extern int openal_loaded;
202 extern LPALCCREATECONTEXT palcCreateContext;
203 extern LPALCMAKECONTEXTCURRENT palcMakeContextCurrent;
204 extern LPALCPROCESSCONTEXT palcProcessContext;
205 extern LPALCSUSPENDCONTEXT palcSuspendContext;
206 extern LPALCDESTROYCONTEXT palcDestroyContext;
207 extern LPALCGETCURRENTCONTEXT palcGetCurrentContext;
208 extern LPALCGETCONTEXTSDEVICE palcGetContextsDevice;
209 extern LPALCOPENDEVICE palcOpenDevice;
210 extern LPALCCLOSEDEVICE palcCloseDevice;
211 extern LPALCGETERROR palcGetError;
212 extern LPALCISEXTENSIONPRESENT palcIsExtensionPresent;
213 extern LPALCGETPROCADDRESS palcGetProcAddress;
214 extern LPALCGETENUMVALUE palcGetEnumValue;
215 extern LPALCGETSTRING palcGetString;
216 extern LPALCGETINTEGERV palcGetIntegerv;
217 extern LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice;
218 extern LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice;
219 extern LPALCCAPTURESTART palcCaptureStart;
220 extern LPALCCAPTURESTOP palcCaptureStop;
221 extern LPALCCAPTURESAMPLES palcCaptureSamples;
222 extern LPALENABLE palEnable;
223 extern LPALDISABLE palDisable;
224 extern LPALISENABLED palIsEnabled;
225 extern LPALGETSTRING palGetString;
226 extern LPALGETBOOLEANV palGetBooleanv;
227 extern LPALGETINTEGERV palGetIntegerv;
228 extern LPALGETFLOATV palGetFloatv;
229 extern LPALGETDOUBLEV palGetDoublev;
230 extern LPALGETBOOLEAN palGetBoolean;
231 extern LPALGETINTEGER palGetInteger;
232 extern LPALGETFLOAT palGetFloat;
233 extern LPALGETDOUBLE palGetDouble;
234 extern LPALGETERROR palGetError;
235 extern LPALISEXTENSIONPRESENT palIsExtensionPresent;
236 extern LPALGETPROCADDRESS palGetProcAddress;
237 extern LPALGETENUMVALUE palGetEnumValue;
238 extern LPALLISTENERF palListenerf;
239 extern LPALLISTENER3F palListener3f;
240 extern LPALLISTENERFV palListenerfv;
241 extern LPALLISTENERI palListeneri;
242 extern LPALLISTENER3I palListener3i;
243 extern LPALLISTENERIV palListeneriv;
244 extern LPALGETLISTENERF palGetListenerf;
245 extern LPALGETLISTENER3F palGetListener3f;
246 extern LPALGETLISTENERFV palGetListenerfv;
247 extern LPALGETLISTENERI palGetListeneri;
248 extern LPALGETLISTENER3I palGetListener3i;
249 extern LPALGETLISTENERIV palGetListeneriv;
250 extern LPALGENSOURCES palGenSources;
251 extern LPALDELETESOURCES palDeleteSources;
252 extern LPALISSOURCE palIsSource;
253 extern LPALSOURCEF palSourcef;
254 extern LPALSOURCE3F palSource3f;
255 extern LPALSOURCEFV palSourcefv;
256 extern LPALSOURCEI palSourcei;
257 extern LPALSOURCE3I palSource3i;
258 extern LPALSOURCEIV palSourceiv;
259 extern LPALGETSOURCEF palGetSourcef;
260 extern LPALGETSOURCE3F palGetSource3f;
261 extern LPALGETSOURCEFV palGetSourcefv;
262 extern LPALGETSOURCEI palGetSourcei;
263 extern LPALGETSOURCE3I palGetSource3i;
264 extern LPALGETSOURCEIV palGetSourceiv;
265 extern LPALSOURCEPLAYV palSourcePlayv;
266 extern LPALSOURCESTOPV palSourceStopv;
267 extern LPALSOURCEREWINDV palSourceRewindv;
268 extern LPALSOURCEPAUSEV palSourcePausev;
269 extern LPALSOURCEPLAY palSourcePlay;
270 extern LPALSOURCESTOP palSourceStop;
271 extern LPALSOURCEREWIND palSourceRewind;
272 extern LPALSOURCEPAUSE palSourcePause;
273 extern LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers;
274 extern LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers;
275 extern LPALGENBUFFERS palGenBuffers;
276 extern LPALDELETEBUFFERS palDeleteBuffers;
277 extern LPALISBUFFER palIsBuffer;
278 extern LPALBUFFERF palBufferf;
279 extern LPALBUFFER3F palBuffer3f;
280 extern LPALBUFFERFV palBufferfv;
281 extern LPALBUFFERI palBufferi;
282 extern LPALBUFFER3I palBuffer3i;
283 extern LPALBUFFERIV palBufferiv;
284 extern LPALGETBUFFERF palGetBufferf;
285 extern LPALGETBUFFER3F palGetBuffer3f;
286 extern LPALGETBUFFERFV palGetBufferfv;
287 extern LPALGETBUFFERI palGetBufferi;
288 extern LPALGETBUFFER3I palGetBuffer3i;
289 extern LPALGETBUFFERIV palGetBufferiv;
290 extern LPALBUFFERDATA palBufferData;
291 extern LPALDOPPLERFACTOR palDopplerFactor;
292 extern LPALDOPPLERVELOCITY palDopplerVelocity;
293 extern LPALDISTANCEMODEL palDistanceModel;
294 extern LPALSPEEDOFSOUND palSpeedOfSound;
296 #define alcCreateContext palcCreateContext
297 #define alcMakeContextCurrent palcMakeContextCurrent
298 #define alcProcessContext palcProcessContext
299 #define alcSuspendContext palcSuspendContext
300 #define alcDestroyContext palcDestroyContext
301 #define alcGetCurrentContext palcGetCurrentContext
302 #define alcGetContextsDevice palcGetContextsDevice
303 #define alcOpenDevice palcOpenDevice
304 #define alcCloseDevice palcCloseDevice
305 #define alcGetError palcGetError
306 #define alcIsExtensionPresent palcIsExtensionPresent
307 #define alcGetProcAddress palcGetProcAddress
308 #define alcGetEnumValue palcGetEnumValue
309 #define alcGetString palcGetString
310 #define alcGetIntegerv palcGetIntegerv
311 #define alcCaptureOpenDevice palcCaptureOpenDevice
312 #define alcCaptureCloseDevice palcCaptureCloseDevice
313 #define alcCaptureStart palcCaptureStart
314 #define alcCaptureStop palcCaptureStop
315 #define alcCaptureSamples palcCaptureSamples
316 #define alEnable palEnable
317 #define alDisable palDisable
318 #define alIsEnabled palIsEnabled
319 #define alGetString palGetString
320 #define alGetBooleanv palGetBooleanv
321 #define alGetIntegerv palGetIntegerv
322 #define alGetFloatv palGetFloatv
323 #define alGetDoublev palGetDoublev
324 #define alGetBoolean palGetBoolean
325 #define alGetInteger palGetInteger
326 #define alGetFloat palGetFloat
327 #define alGetDouble palGetDouble
328 #define alGetError palGetError
329 #define alIsExtensionPresent palIsExtensionPresent
330 #define alGetProcAddress palGetProcAddress
331 #define alGetEnumValue palGetEnumValue
332 #define alListenerf palListenerf
333 #define alListener3f palListener3f
334 #define alListenerfv palListenerfv
335 #define alListeneri palListeneri
336 #define alListener3i palListener3i
337 #define alListeneriv palListeneriv
338 #define alGetListenerf palGetListenerf
339 #define alGetListener3f palGetListener3f
340 #define alGetListenerfv palGetListenerfv
341 #define alGetListeneri palGetListeneri
342 #define alGetListener3i palGetListener3i
343 #define alGetListeneriv palGetListeneriv
344 #define alGenSources palGenSources
345 #define alDeleteSources palDeleteSources
346 #define alIsSource palIsSource
347 #define alSourcef palSourcef
348 #define alSource3f palSource3f
349 #define alSourcefv palSourcefv
350 #define alSourcei palSourcei
351 #define alSource3i palSource3i
352 #define alSourceiv palSourceiv
353 #define alGetSourcef palGetSourcef
354 #define alGetSource3f palGetSource3f
355 #define alGetSourcefv palGetSourcefv
356 #define alGetSourcei palGetSourcei
357 #define alGetSource3i palGetSource3i
358 #define alGetSourceiv palGetSourceiv
359 #define alSourcePlayv palSourcePlayv
360 #define alSourceStopv palSourceStopv
361 #define alSourceRewindv palSourceRewindv
362 #define alSourcePausev palSourcePausev
363 #define alSourcePlay palSourcePlay
364 #define alSourceStop palSourceStop
365 #define alSourceRewind palSourceRewind
366 #define alSourcePause palSourcePause
367 #define alSourceQueueBuffers palSourceQueueBuffers
368 #define alSourceUnqueueBuffers palSourceUnqueueBuffers
369 #define alGenBuffers palGenBuffers
370 #define alDeleteBuffers palDeleteBuffers
371 #define alIsBuffer palIsBuffer
372 #define alBufferf palBufferf
373 #define alBuffer3f palBuffer3f
374 #define alBufferfv palBufferfv
375 #define alBufferi palBufferi
376 #define alBuffer3i palBuffer3i
377 #define alBufferiv palBufferiv
378 #define alGetBufferf palGetBufferf
379 #define alGetBuffer3f palGetBuffer3f
380 #define alGetBufferfv palGetBufferfv
381 #define alGetBufferi palGetBufferi
382 #define alGetBuffer3i palGetBuffer3i
383 #define alGetBufferiv palGetBufferiv
384 #define alBufferData palBufferData
385 #define alDopplerFactor palDopplerFactor
386 #define alDopplerVelocity palDopplerVelocity
387 #define alDistanceModel palDistanceModel
388 #define alSpeedOfSound palSpeedOfSound
390 /* Extension functions. Technically device- or driver-specific, but as long as
391 * they're pulled from the NULL device it should be routed correctly.
393 typedef ALenum(AL_APIENTRY*LPEAXSET)(
394 const GUID* property_set_id,
395 ALuint property_id,
396 ALuint property_source_id,
397 ALvoid* property_buffer,
398 ALuint property_size);
399 typedef ALenum(AL_APIENTRY*LPEAXGET)(
400 const GUID* property_set_id,
401 ALuint property_id,
402 ALuint property_source_id,
403 ALvoid* property_buffer,
404 ALuint property_size);
406 extern LPEAXSET pEAXSet;
407 extern LPEAXGET pEAXGet;
408 extern LPALDEFERUPDATESSOFT palDeferUpdatesSOFT;
409 extern LPALPROCESSUPDATESSOFT palProcessUpdatesSOFT;
410 extern LPALBUFFERSTORAGESOFT palBufferStorageSOFT;
411 extern LPALMAPBUFFERSOFT palMapBufferSOFT;
412 extern LPALUNMAPBUFFERSOFT palUnmapBufferSOFT;
413 extern LPALFLUSHMAPPEDBUFFERSOFT palFlushMappedBufferSOFT;
415 #define EAXSet pEAXSet
416 #define EAXGet pEAXGet
417 #define alDeferUpdatesSOFT palDeferUpdatesSOFT
418 #define alProcessUpdatesSOFT palProcessUpdatesSOFT
419 #define alBufferStorageSOFT palBufferStorageSOFT
420 #define alMapBufferSOFT palMapBufferSOFT
421 #define alUnmapBufferSOFT palUnmapBufferSOFT
422 #define alFlushMappedBufferSOFT palFlushMappedBufferSOFT
425 #ifndef E_PROP_ID_UNSUPPORTED
426 #define E_PROP_ID_UNSUPPORTED ((HRESULT)0x80070490)
427 #endif
429 typedef enum {
430 DSPROPERTY_VMANAGER_MODE = 0,
431 DSPROPERTY_VMANAGER_PRIORITY,
432 DSPROPERTY_VMANAGER_STATE
433 } DSPROPERTY_VMANAGER;
436 typedef enum {
437 DSPROPERTY_VMANAGER_MODE_DEFAULT = 0,
438 DSPROPERTY_VMANAGER_MODE_AUTO,
439 DSPROPERTY_VMANAGER_MODE_REPORT,
440 DSPROPERTY_VMANAGER_MODE_USER,
441 VMANAGER_MODE_MAX
442 } VmMode;
445 typedef enum {
446 DSPROPERTY_VMANAGER_STATE_PLAYING3DHW = 0,
447 DSPROPERTY_VMANAGER_STATE_SILENT,
448 DSPROPERTY_VMANAGER_STATE_BUMPED,
449 DSPROPERTY_VMANAGER_STATE_PLAYFAILED,
450 VMANAGER_STATE_MAX
451 } VmState;
453 /* OpenAL only allows for 1 single access to the device at the same time */
454 extern CRITICAL_SECTION openal_crst;
456 extern LPALCMAKECONTEXTCURRENT set_context;
457 extern LPALCGETCURRENTCONTEXT get_context;
458 extern BOOL local_contexts;
461 extern DWORD TlsThreadPtr;
462 extern void (*EnterALSection)(ALCcontext *ctx);
463 extern void (*LeaveALSection)(void);
466 typedef struct DSDevice DSDevice;
467 typedef struct DSPrimary DSPrimary;
468 typedef struct DSBuffer DSBuffer;
471 enum {
472 EXT_EAX,
473 EXT_FLOAT32,
474 EXT_MCFORMATS,
475 SOFT_DEFERRED_UPDATES,
476 SOFT_SOURCE_SPATIALIZE,
477 SOFTX_MAP_BUFFER,
479 MAX_EXTENSIONS
483 #define BITFIELD_ARRAY_SIZE(b) ((b+7) / 8)
484 #define BITFIELD_SET(arr, b) ((arr)[(b)>>3] |= 1<<((b)&7))
485 #define BITFIELD_TEST(arr, b) ((arr)[(b)>>3] & (1<<((b)&7)))
487 /* Maximum number of emulated hardware buffers. May be less depending on source
488 * availability.
490 #define MAX_HWBUFFERS 128
492 #define MAX_SOURCES 1024
493 typedef struct SourceCollection {
494 DWORD maxhw_alloc, availhw_num;
495 DWORD maxsw_alloc, availsw_num;
496 } SourceCollection;
498 typedef struct DeviceShare {
499 LONG ref;
501 ALCdevice *device;
502 ALCcontext *ctx;
503 ALCint refresh;
505 ALboolean Exts[BITFIELD_ARRAY_SIZE(MAX_EXTENSIONS)];
507 CRITICAL_SECTION crst;
509 SourceCollection sources;
511 HANDLE thread_hdl;
512 DWORD thread_id;
514 HANDLE queue_timer;
515 HANDLE timer_evt;
516 volatile LONG quit_now;
518 ALsizei nprimaries;
519 DSPrimary **primaries;
521 GUID guid;
522 DWORD speaker_config;
524 DWORD vm_managermode;
525 } DeviceShare;
527 #define HAS_EXTENSION(s, e) BITFIELD_TEST((s)->Exts, e)
530 typedef struct DSData {
531 LONG ref;
533 DSPrimary *primary;
535 /* Lock was called and unlock isn't? */
536 LONG locked;
538 WAVEFORMATEXTENSIBLE format;
540 ALsizei buf_size;
541 ALenum buf_format;
542 DWORD dsbflags;
543 BYTE *data;
544 ALuint bid;
545 } DSData;
546 /* Amount of buffers that have to be queued when
547 * bufferdatastatic and buffersubdata are not available */
548 #define QBUFFERS 4
550 union BufferParamFlags {
551 LONG flags;
552 struct {
553 BOOL pos : 1;
554 BOOL vel : 1;
555 BOOL cone_angles : 1;
556 BOOL cone_orient : 1;
557 BOOL cone_outsidevolume : 1;
558 BOOL min_distance : 1;
559 BOOL max_distance : 1;
560 BOOL mode : 1;
561 } bit;
564 struct DSBuffer {
565 IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
566 IDirectSound3DBuffer IDirectSound3DBuffer_iface;
567 IDirectSoundNotify IDirectSoundNotify_iface;
568 IKsPropertySet IKsPropertySet_iface;
570 LONG ref, ds3d_ref, not_ref, prop_ref;
571 LONG all_ref;
573 DeviceShare *share;
574 DSPrimary *primary;
576 /* From the primary */
577 ALCcontext *ctx;
579 DSData *buffer;
580 ALuint source;
582 ALsizei segsize;
583 ALsizei data_offset;
584 ALsizei queue_base;
585 ALsizei curidx;
586 ALuint stream_bids[QBUFFERS];
588 BOOL init_done : 1;
589 BOOL isplaying : 1;
590 BOOL islooping : 1;
591 BOOL bufferlost : 1;
593 /* Must be 0 (deferred, not yet placed), DSBSTATUS_LOCSOFTWARE, or
594 * DSBSTATUS_LOCHARDWARE.
596 DWORD loc_status;
598 struct {
599 LONG vol, pan;
600 DWORD frequency;
601 DS3DBUFFER ds3d;
602 } current;
603 struct {
604 DS3DBUFFER ds3d;
605 } deferred;
606 union BufferParamFlags dirty;
608 DWORD nnotify, lastpos;
609 DSBPOSITIONNOTIFY *notify;
611 DWORD vm_voicepriority;
612 //DWORD vm_voicestate;
616 struct DSBufferGroup {
617 DWORD64 FreeBuffers;
618 DSBuffer *Buffers;
622 enum {
623 FXSLOT_EFFECT_REVERB,
624 FXSLOT_EFFECT_CHORUS,
626 FXSLOT_EFFECT_NULL,
629 union PrimaryParamFlags {
630 LONG flags;
631 struct {
632 LONG pos : 1;
633 LONG vel : 1;
634 LONG orientation : 1;
635 LONG distancefactor : 1;
636 LONG rollofffactor : 1;
637 LONG dopplerfactor : 1;
638 } bit;
641 struct DSPrimary {
642 IDirectSoundBuffer IDirectSoundBuffer_iface;
643 IDirectSound3DListener IDirectSound3DListener_iface;
644 IKsPropertySet IKsPropertySet_iface;
646 LONG ref, ds3d_ref, prop_ref;
647 IDirectSoundBuffer *write_emu;
648 DSDevice *parent;
650 DeviceShare *share;
651 /* Taken from the share */
652 ALCcontext *ctx;
653 ALCint refresh;
655 DWORD buf_size;
656 BOOL stopped;
657 DWORD flags;
658 WAVEFORMATEXTENSIBLE format;
660 DSBuffer **notifies;
661 DWORD nnotifies, sizenotifies;
663 ALint primary_idx;
665 struct {
666 DS3DLISTENER ds3d;
667 } current;
668 struct {
669 DS3DLISTENER ds3d;
670 } deferred;
671 union PrimaryParamFlags dirty;
673 DWORD NumBufferGroups;
674 struct DSBufferGroup *BufferGroups;
678 /* Device implementation */
679 struct DSDevice {
680 IDirectSound8 IDirectSound8_iface;
681 IDirectSound IDirectSound_iface;
682 IUnknown IUnknown_iface;
684 LONG ref, unkref, dsref;
685 BOOL is_8;
687 DeviceShare *share;
689 /* Taken from the share */
690 ALCdevice *device;
692 DSPrimary primary;
694 DWORD prio_level;
698 DEFINE_GUID(GUID_NULL, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
700 DEFINE_GUID(CLSID_DirectSoundPrivate, 0x11ab3ec0, 0x25ec, 0x11d1, 0xa4, 0xd8, 0x00, 0xc0, 0x4f, 0xc2, 0x8a, 0xca);
702 DEFINE_GUID(DSPROPSETID_DirectSoundDevice, 0x84624f82, 0x25ec, 0x11d1, 0xa4, 0xd8, 0x00, 0xc0, 0x4f, 0xc2, 0x8a, 0xca);
704 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
705 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, 0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
707 DEFINE_DEVPROPKEY(DEVPKEY_Device_FriendlyName, 0xa45c254e,0xdf1c,0x4efd,0x80,0x20,0x67,0xd1,0x46,0xa8,0x50,0xe0, 14);
709 DEFINE_GUID(DSPROPSETID_ZOOMFX_BufferProperties, 0xcd5368e0, 0x3450, 0x11d3, 0x8b, 0x6e, 0x00, 0x10, 0x5a, 0x9b, 0x7b, 0xbc);
710 DEFINE_GUID(DSPROPSETID_I3DL2_ListenerProperties, 0xda0f0520, 0x300a, 0x11d3, 0x8a, 0x2b, 0x00, 0x60, 0x97, 0x0d, 0xb0, 0x11);
711 DEFINE_GUID(DSPROPSETID_I3DL2_BufferProperties, 0xda0f0521, 0x300a, 0x11d3, 0x8a, 0x2b, 0x00, 0x60, 0x97, 0x0d, 0xb0, 0x11);
713 DEFINE_GUID(DSPROPSETID_VoiceManager, 0x62a69bae, 0xdf9d, 0x11d1, 0x99, 0xa6, 0x00, 0xc0, 0x4f, 0xc9, 0x9d, 0x46);
716 HRESULT DSPrimary_PreInit(DSPrimary *prim, DSDevice *parent);
717 void DSPrimary_Clear(DSPrimary *prim);
718 void DSPrimary_triggernots(DSPrimary *prim);
719 void DSPrimary_streamfeeder(DSPrimary *prim, BYTE *scratch_mem/*2K non-permanent memory*/);
720 HRESULT WINAPI DSPrimary_Initialize(IDirectSoundBuffer *iface, IDirectSound *ds, const DSBUFFERDESC *desc);
721 HRESULT WINAPI DSPrimary3D_CommitDeferredSettings(IDirectSound3DListener *iface);
723 HRESULT DSBuffer_Create(DSBuffer **ppv, DSPrimary *parent, IDirectSoundBuffer *orig);
724 void DSBuffer_Destroy(DSBuffer *buf);
725 HRESULT DSBuffer_GetInterface(DSBuffer *buf, REFIID riid, void **ppv);
726 void DSBuffer_SetParams(DSBuffer *buffer, const DS3DBUFFER *params, LONG flags);
727 HRESULT WINAPI DSBuffer_GetCurrentPosition(IDirectSoundBuffer8 *iface, DWORD *playpos, DWORD *curpos);
728 HRESULT WINAPI DSBuffer_GetStatus(IDirectSoundBuffer8 *iface, DWORD *status);
729 HRESULT WINAPI DSBuffer_Initialize(IDirectSoundBuffer8 *iface, IDirectSound *ds, const DSBUFFERDESC *desc);
731 HRESULT EAX1_Query(DSPrimary *prim, DWORD propid, ULONG *pTypeSupport);
732 HRESULT EAX1Buffer_Query(DSBuffer *buf, DWORD propid, ULONG *pTypeSupport);
734 HRESULT EAX2_Query(DSPrimary *prim, DWORD propid, ULONG *pTypeSupport);
735 HRESULT EAX2Buffer_Query(DSBuffer *buf, DWORD propid, ULONG *pTypeSupport);
737 HRESULT EAX3_Query(DSPrimary *prim, DWORD propid, ULONG *pTypeSupport);
738 HRESULT EAX3Buffer_Query(DSBuffer *buf, DWORD propid, ULONG *pTypeSupport);
740 HRESULT EAX4Context_Query(DSPrimary *prim, DWORD propid, ULONG *pTypeSupport);
741 HRESULT EAX4Slot_Query(DSPrimary *prim, DWORD propid, ULONG *pTypeSupport);
742 HRESULT EAX4Source_Query(DSBuffer *buf, DWORD propid, ULONG *pTypeSupport);
744 HRESULT VoiceMan_Query(DSBuffer *buf, DWORD propid, ULONG *pTypeSupport);
745 HRESULT VoiceMan_Set(DSBuffer *buf, DWORD propid, void *pPropData, ULONG cbPropData);
746 HRESULT VoiceMan_Get(DSBuffer *buf, DWORD propid, void *pPropData, ULONG cbPropData, ULONG *pcbReturned);
748 static inline LONG gain_to_mB(float gain)
750 return (gain > 1e-5f) ? (LONG)(log10f(gain) * 2000.0f) : -10000l;
752 static inline float mB_to_gain(float millibels)
754 return (millibels > -10000.0f) ? powf(10.0f, millibels/2000.0f) : 0.0f;
757 static inline LONG clampI(LONG val, LONG minval, LONG maxval)
759 if(val >= maxval) return maxval;
760 if(val <= minval) return minval;
761 return val;
763 static inline ULONG clampU(ULONG val, ULONG minval, ULONG maxval)
765 if(val >= maxval) return maxval;
766 if(val <= minval) return minval;
767 return val;
769 static inline FLOAT clampF(FLOAT val, FLOAT minval, FLOAT maxval)
771 if(val >= maxval) return maxval;
772 if(val <= minval) return minval;
773 return val;
776 static inline LONG minI(LONG a, LONG b)
777 { return (a < b) ? a : b; }
778 static inline float minF(float a, float b)
779 { return (a < b) ? a : b; }
781 static inline float maxF(float a, float b)
782 { return (a > b) ? a : b; }
785 #define checkALError() do { \
786 ALenum err = alGetError(); \
787 if(err != AL_NO_ERROR) \
788 ERR(">>>>>>>>>>>> Received AL error %#x on context %p, %s:%u\n", \
789 err, get_context(), __FUNCTION__, __LINE__); \
790 } while (0)
792 #define checkALCError(dev) do { \
793 ALenum err = alcGetError(dev); \
794 if(err != ALC_NO_ERROR) \
795 ERR(">>>>>>>>>>>> Received ALC error %#x on device %p, %s:%u\n", \
796 err, dev, __FUNCTION__, __LINE__); \
797 } while(0)
800 #define setALContext(actx) EnterALSection(actx)
801 #define popALContext() LeaveALSection()
804 HRESULT DSOUND_Create(REFIID riid, void **ppDS);
805 HRESULT DSOUND_Create8(REFIID riid, void **ppDS);
806 HRESULT DSOUND_FullDuplexCreate(REFIID riid, void **ppDSFD);
807 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, void **piks);
808 HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppDSC);
809 HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppDSC);
811 typedef BOOL (CALLBACK *PRVTENUMCALLBACK)(EDataFlow flow, LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data);
812 HRESULT enumerate_mmdevices(EDataFlow flow, PRVTENUMCALLBACK cb, void *user);
813 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device);
814 void release_mmdevice(IMMDevice *device, HRESULT init_hr);
816 extern const WCHAR aldriver_name[];
818 #ifndef DECLSPEC_EXPORT
819 #ifdef _WIN32
820 #define DECLSPEC_EXPORT __declspec(dllexport)
821 #else
822 #define DECLSPEC_EXPORT
823 #endif
824 #endif
826 HRESULT WINAPI DSOAL_GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest);