3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2002 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
21 * Most thread locking is complete. There may be a few race
22 * conditions still lurking.
25 * Implement SetCooperativeLevel properly (need to address focus issues)
26 * Implement DirectSound3DBuffers (stubs in place)
27 * Use hardware 3D support if available
28 * Add critical section locking inside Release and AddRef methods
29 * Handle static buffers - put those in hardware, non-static not in hardware
30 * Hardware DuplicateSoundBuffer
31 * Proper volume calculation for 3d buffers
32 * Remove DS_HEL_FRAGS and use mixer fragment length for it
39 #include "wine/library.h"
42 #define NONAMELESSSTRUCT
43 #define NONAMELESSUNION
52 #include "wine/debug.h"
60 #include "dsound_private.h"
62 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
70 #include "dsound_private.h"
73 #define CP_UNIXCP 65010
76 DEFINE_GUID(CLSID_DirectSoundPrivate
,0x11ab3ec0,0x25ec,0x11d1,0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca);
82 static HINSTANCE instance
;
84 const GUID DSOUND_renderer_guid
= { 0xbd6dd71a, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
85 const GUID DSOUND_capture_guid
= { 0xbd6dd71b, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
87 const IID DSPROPSETID_EAX20_ListenerProperties
= {
88 0x0306a6a8, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
91 const IID DSPROPSETID_EAX20_BufferProperties
= {
92 0x0306a6a7, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
95 const EAXLISTENERPROPERTIES EnvironmentDefaults
[EAX_ENVIRONMENT_COUNT
] =
97 REVERB_PRESET_GENERIC
,
98 REVERB_PRESET_PADDEDCELL
,
100 REVERB_PRESET_BATHROOM
,
101 REVERB_PRESET_LIVINGROOM
,
102 REVERB_PRESET_STONEROOM
,
103 REVERB_PRESET_AUDITORIUM
,
104 REVERB_PRESET_CONCERTHALL
,
107 REVERB_PRESET_HANGAR
,
108 REVERB_PRESET_CARPETEDHALLWAY
,
109 REVERB_PRESET_HALLWAY
,
110 REVERB_PRESET_STONECORRIDOR
,
112 REVERB_PRESET_FOREST
,
114 REVERB_PRESET_MOUNTAINS
,
115 REVERB_PRESET_QUARRY
,
117 REVERB_PRESET_PARKINGLOT
,
118 REVERB_PRESET_SEWERPIPE
,
119 REVERB_PRESET_UNDERWATER
,
120 REVERB_PRESET_DRUGGED
,
122 REVERB_PRESET_PSYCHOTIC
125 static CRITICAL_SECTION_DEBUG openal_crst_debug
=
128 { &openal_crst_debug
.ProcessLocksList
,
129 &openal_crst_debug
.ProcessLocksList
},
130 0, 0, { (DWORD_PTR
)(__FILE__
": openal_crst_debug") }
132 CRITICAL_SECTION openal_crst
= { &openal_crst_debug
, -1, 0, 0, 0, 0 };
134 int openal_loaded
= 0;
135 #ifdef SONAME_LIBOPENAL
136 static void *openal_handle
= NULL
;
137 LPALCCREATECONTEXT palcCreateContext
= NULL
;
138 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent
= NULL
;
139 LPALCPROCESSCONTEXT palcProcessContext
= NULL
;
140 LPALCSUSPENDCONTEXT palcSuspendContext
= NULL
;
141 LPALCDESTROYCONTEXT palcDestroyContext
= NULL
;
142 LPALCGETCURRENTCONTEXT palcGetCurrentContext
= NULL
;
143 LPALCGETCONTEXTSDEVICE palcGetContextsDevice
= NULL
;
144 LPALCOPENDEVICE palcOpenDevice
= NULL
;
145 LPALCCLOSEDEVICE palcCloseDevice
= NULL
;
146 LPALCGETERROR palcGetError
= NULL
;
147 LPALCISEXTENSIONPRESENT palcIsExtensionPresent
= NULL
;
148 LPALCGETPROCADDRESS palcGetProcAddress
= NULL
;
149 LPALCGETENUMVALUE palcGetEnumValue
= NULL
;
150 LPALCGETSTRING palcGetString
= NULL
;
151 LPALCGETINTEGERV palcGetIntegerv
= NULL
;
152 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice
= NULL
;
153 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice
= NULL
;
154 LPALCCAPTURESTART palcCaptureStart
= NULL
;
155 LPALCCAPTURESTOP palcCaptureStop
= NULL
;
156 LPALCCAPTURESAMPLES palcCaptureSamples
= NULL
;
157 LPALENABLE palEnable
= NULL
;
158 LPALDISABLE palDisable
= NULL
;
159 LPALISENABLED palIsEnabled
= NULL
;
160 LPALGETSTRING palGetString
= NULL
;
161 LPALGETBOOLEANV palGetBooleanv
= NULL
;
162 LPALGETINTEGERV palGetIntegerv
= NULL
;
163 LPALGETFLOATV palGetFloatv
= NULL
;
164 LPALGETDOUBLEV palGetDoublev
= NULL
;
165 LPALGETBOOLEAN palGetBoolean
= NULL
;
166 LPALGETINTEGER palGetInteger
= NULL
;
167 LPALGETFLOAT palGetFloat
= NULL
;
168 LPALGETDOUBLE palGetDouble
= NULL
;
169 LPALGETERROR palGetError
= NULL
;
170 LPALISEXTENSIONPRESENT palIsExtensionPresent
= NULL
;
171 LPALGETPROCADDRESS palGetProcAddress
= NULL
;
172 LPALGETENUMVALUE palGetEnumValue
= NULL
;
173 LPALLISTENERF palListenerf
= NULL
;
174 LPALLISTENER3F palListener3f
= NULL
;
175 LPALLISTENERFV palListenerfv
= NULL
;
176 LPALLISTENERI palListeneri
= NULL
;
177 LPALLISTENER3I palListener3i
= NULL
;
178 LPALLISTENERIV palListeneriv
= NULL
;
179 LPALGETLISTENERF palGetListenerf
= NULL
;
180 LPALGETLISTENER3F palGetListener3f
= NULL
;
181 LPALGETLISTENERFV palGetListenerfv
= NULL
;
182 LPALGETLISTENERI palGetListeneri
= NULL
;
183 LPALGETLISTENER3I palGetListener3i
= NULL
;
184 LPALGETLISTENERIV palGetListeneriv
= NULL
;
185 LPALGENSOURCES palGenSources
= NULL
;
186 LPALDELETESOURCES palDeleteSources
= NULL
;
187 LPALISSOURCE palIsSource
= NULL
;
188 LPALSOURCEF palSourcef
= NULL
;
189 LPALSOURCE3F palSource3f
= NULL
;
190 LPALSOURCEFV palSourcefv
= NULL
;
191 LPALSOURCEI palSourcei
= NULL
;
192 LPALSOURCE3I palSource3i
= NULL
;
193 LPALSOURCEIV palSourceiv
= NULL
;
194 LPALGETSOURCEF palGetSourcef
= NULL
;
195 LPALGETSOURCE3F palGetSource3f
= NULL
;
196 LPALGETSOURCEFV palGetSourcefv
= NULL
;
197 LPALGETSOURCEI palGetSourcei
= NULL
;
198 LPALGETSOURCE3I palGetSource3i
= NULL
;
199 LPALGETSOURCEIV palGetSourceiv
= NULL
;
200 LPALSOURCEPLAYV palSourcePlayv
= NULL
;
201 LPALSOURCESTOPV palSourceStopv
= NULL
;
202 LPALSOURCEREWINDV palSourceRewindv
= NULL
;
203 LPALSOURCEPAUSEV palSourcePausev
= NULL
;
204 LPALSOURCEPLAY palSourcePlay
= NULL
;
205 LPALSOURCESTOP palSourceStop
= NULL
;
206 LPALSOURCEREWIND palSourceRewind
= NULL
;
207 LPALSOURCEPAUSE palSourcePause
= NULL
;
208 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers
= NULL
;
209 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers
= NULL
;
210 LPALGENBUFFERS palGenBuffers
= NULL
;
211 LPALDELETEBUFFERS palDeleteBuffers
= NULL
;
212 LPALISBUFFER palIsBuffer
= NULL
;
213 LPALBUFFERF palBufferf
= NULL
;
214 LPALBUFFER3F palBuffer3f
= NULL
;
215 LPALBUFFERFV palBufferfv
= NULL
;
216 LPALBUFFERI palBufferi
= NULL
;
217 LPALBUFFER3I palBuffer3i
= NULL
;
218 LPALBUFFERIV palBufferiv
= NULL
;
219 LPALGETBUFFERF palGetBufferf
= NULL
;
220 LPALGETBUFFER3F palGetBuffer3f
= NULL
;
221 LPALGETBUFFERFV palGetBufferfv
= NULL
;
222 LPALGETBUFFERI palGetBufferi
= NULL
;
223 LPALGETBUFFER3I palGetBuffer3i
= NULL
;
224 LPALGETBUFFERIV palGetBufferiv
= NULL
;
225 LPALBUFFERDATA palBufferData
= NULL
;
226 LPALDOPPLERFACTOR palDopplerFactor
= NULL
;
227 LPALDOPPLERVELOCITY palDopplerVelocity
= NULL
;
228 LPALDISTANCEMODEL palDistanceModel
= NULL
;
229 LPALSPEEDOFSOUND palSpeedOfSound
= NULL
;
232 LPALCMAKECONTEXTCURRENT set_context
;
233 LPALCGETCURRENTCONTEXT get_context
;
236 static void load_libopenal(void)
239 const char *str
= getenv("DSOAL_LOGLEVEL");
241 LogLevel
= atoi(str
);
242 #elif defined(SONAME_LIBOPENAL)
246 openal_handle
= wine_dlopen(SONAME_LIBOPENAL
, RTLD_NOW
, error
, sizeof(error
));
248 ERR("Couldn't load " SONAME_LIBOPENAL
": %s\n", error
);
249 #define LOAD_FUNCPTR(f) \
250 if((p##f = wine_dlsym(openal_handle, #f, NULL, 0)) == NULL) { \
251 ERR("Couldn't lookup %s in " SONAME_LIBOPENAL "\n", #f); \
255 LOAD_FUNCPTR(alcCreateContext
);
256 LOAD_FUNCPTR(alcMakeContextCurrent
);
257 LOAD_FUNCPTR(alcProcessContext
);
258 LOAD_FUNCPTR(alcSuspendContext
);
259 LOAD_FUNCPTR(alcDestroyContext
);
260 LOAD_FUNCPTR(alcGetCurrentContext
);
261 LOAD_FUNCPTR(alcGetContextsDevice
);
262 LOAD_FUNCPTR(alcOpenDevice
);
263 LOAD_FUNCPTR(alcCloseDevice
);
264 LOAD_FUNCPTR(alcGetError
);
265 LOAD_FUNCPTR(alcIsExtensionPresent
);
266 LOAD_FUNCPTR(alcGetProcAddress
);
267 LOAD_FUNCPTR(alcGetEnumValue
);
268 LOAD_FUNCPTR(alcGetString
);
269 LOAD_FUNCPTR(alcGetIntegerv
);
270 LOAD_FUNCPTR(alcCaptureOpenDevice
);
271 LOAD_FUNCPTR(alcCaptureCloseDevice
);
272 LOAD_FUNCPTR(alcCaptureStart
);
273 LOAD_FUNCPTR(alcCaptureStop
);
274 LOAD_FUNCPTR(alcCaptureSamples
);
275 LOAD_FUNCPTR(alEnable
);
276 LOAD_FUNCPTR(alDisable
);
277 LOAD_FUNCPTR(alIsEnabled
);
278 LOAD_FUNCPTR(alGetString
);
279 LOAD_FUNCPTR(alGetBooleanv
);
280 LOAD_FUNCPTR(alGetIntegerv
);
281 LOAD_FUNCPTR(alGetFloatv
);
282 LOAD_FUNCPTR(alGetDoublev
);
283 LOAD_FUNCPTR(alGetBoolean
);
284 LOAD_FUNCPTR(alGetInteger
);
285 LOAD_FUNCPTR(alGetFloat
);
286 LOAD_FUNCPTR(alGetDouble
);
287 LOAD_FUNCPTR(alGetError
);
288 LOAD_FUNCPTR(alIsExtensionPresent
);
289 LOAD_FUNCPTR(alGetProcAddress
);
290 LOAD_FUNCPTR(alGetEnumValue
);
291 LOAD_FUNCPTR(alListenerf
);
292 LOAD_FUNCPTR(alListener3f
);
293 LOAD_FUNCPTR(alListenerfv
);
294 LOAD_FUNCPTR(alListeneri
);
295 LOAD_FUNCPTR(alListener3i
);
296 LOAD_FUNCPTR(alListeneriv
);
297 LOAD_FUNCPTR(alGetListenerf
);
298 LOAD_FUNCPTR(alGetListener3f
);
299 LOAD_FUNCPTR(alGetListenerfv
);
300 LOAD_FUNCPTR(alGetListeneri
);
301 LOAD_FUNCPTR(alGetListener3i
);
302 LOAD_FUNCPTR(alGetListeneriv
);
303 LOAD_FUNCPTR(alGenSources
);
304 LOAD_FUNCPTR(alDeleteSources
);
305 LOAD_FUNCPTR(alIsSource
);
306 LOAD_FUNCPTR(alSourcef
);
307 LOAD_FUNCPTR(alSource3f
);
308 LOAD_FUNCPTR(alSourcefv
);
309 LOAD_FUNCPTR(alSourcei
);
310 LOAD_FUNCPTR(alSource3i
);
311 LOAD_FUNCPTR(alSourceiv
);
312 LOAD_FUNCPTR(alGetSourcef
);
313 LOAD_FUNCPTR(alGetSource3f
);
314 LOAD_FUNCPTR(alGetSourcefv
);
315 LOAD_FUNCPTR(alGetSourcei
);
316 LOAD_FUNCPTR(alGetSource3i
);
317 LOAD_FUNCPTR(alGetSourceiv
);
318 LOAD_FUNCPTR(alSourcePlayv
);
319 LOAD_FUNCPTR(alSourceStopv
);
320 LOAD_FUNCPTR(alSourceRewindv
);
321 LOAD_FUNCPTR(alSourcePausev
);
322 LOAD_FUNCPTR(alSourcePlay
);
323 LOAD_FUNCPTR(alSourceStop
);
324 LOAD_FUNCPTR(alSourceRewind
);
325 LOAD_FUNCPTR(alSourcePause
);
326 LOAD_FUNCPTR(alSourceQueueBuffers
);
327 LOAD_FUNCPTR(alSourceUnqueueBuffers
);
328 LOAD_FUNCPTR(alGenBuffers
);
329 LOAD_FUNCPTR(alDeleteBuffers
);
330 LOAD_FUNCPTR(alIsBuffer
);
331 LOAD_FUNCPTR(alBufferf
);
332 LOAD_FUNCPTR(alBuffer3f
);
333 LOAD_FUNCPTR(alBufferfv
);
334 LOAD_FUNCPTR(alBufferi
);
335 LOAD_FUNCPTR(alBuffer3i
);
336 LOAD_FUNCPTR(alBufferiv
);
337 LOAD_FUNCPTR(alGetBufferf
);
338 LOAD_FUNCPTR(alGetBuffer3f
);
339 LOAD_FUNCPTR(alGetBufferfv
);
340 LOAD_FUNCPTR(alGetBufferi
);
341 LOAD_FUNCPTR(alGetBuffer3i
);
342 LOAD_FUNCPTR(alGetBufferiv
);
343 LOAD_FUNCPTR(alBufferData
);
344 LOAD_FUNCPTR(alDopplerFactor
);
345 LOAD_FUNCPTR(alDopplerVelocity
);
346 LOAD_FUNCPTR(alDistanceModel
);
347 LOAD_FUNCPTR(alSpeedOfSound
);
351 WARN("Unloading openal\n");
352 if (openal_handle
!= RTLD_DEFAULT
)
353 wine_dlclose(openal_handle
, NULL
, 0);
354 openal_handle
= NULL
;
361 local_contexts
= alcIsExtensionPresent(NULL
, "ALC_EXT_thread_local_context");
364 set_context
= alcGetProcAddress(NULL
, "alcSetThreadContext");
365 get_context
= alcGetProcAddress(NULL
, "alcGetThreadContext");
366 if(!set_context
|| !get_context
)
368 ERR("TLS advertised but functions not found, disabling thread local context\n");
374 set_context
= alcMakeContextCurrent
;
375 get_context
= alcGetCurrentContext
;
380 const ALCchar
*DSOUND_getdevicestrings(void)
382 if(alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT"))
383 return alcGetString(NULL
, ALC_ALL_DEVICES_SPECIFIER
);
384 return alcGetString(NULL
, ALC_DEVICE_SPECIFIER
);
387 const ALCchar
*DSOUND_getcapturedevicestrings(void)
389 return alcGetString(NULL
, ALC_CAPTURE_DEVICE_SPECIFIER
);
392 /***************************************************************************
393 * GetDeviceID [DSOUND.9]
395 * Retrieves unique identifier of default device specified
398 * pGuidSrc [I] Address of device GUID.
399 * pGuidDest [O] Address to receive unique device GUID.
403 * Failure: DSERR_INVALIDPARAM
406 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
407 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
408 * DSDEVID_DefaultVoiceCapture.
409 * Returns pGuidSrc if pGuidSrc is a valid device or the device
410 * GUID for the specified constants.
412 HRESULT WINAPI
GetDeviceID(LPCGUID pGuidSrc
, LPGUID pGuidDest
)
414 TRACE("(%s, %p)\n", debugstr_guid(pGuidSrc
), pGuidDest
);
418 WARN("invalid parameter: pGuidSrc == NULL\n");
419 return DSERR_INVALIDPARAM
;
422 if(pGuidDest
== NULL
)
424 WARN("invalid parameter: pGuidDest == NULL\n");
425 return DSERR_INVALIDPARAM
;
428 if(IsEqualGUID(&DSDEVID_DefaultPlayback
, pGuidSrc
) ||
429 IsEqualGUID(&DSDEVID_DefaultVoicePlayback
, pGuidSrc
))
430 *pGuidDest
= DSOUND_renderer_guid
;
431 else if(IsEqualGUID(&DSDEVID_DefaultCapture
, pGuidSrc
) ||
432 IsEqualGUID(&DSDEVID_DefaultVoiceCapture
, pGuidSrc
))
433 *pGuidDest
= DSOUND_capture_guid
;
435 *pGuidDest
= *pGuidSrc
;
437 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
443 LPDSENUMCALLBACKW callW
;
447 static BOOL CALLBACK
w_to_a_callback(LPGUID guid
, LPCSTR descA
, LPCSTR modA
, LPVOID data
)
449 struct morecontext
*context
= data
;
450 WCHAR descW
[MAXPNAMELEN
], modW
[MAXPNAMELEN
];
452 MultiByteToWideChar(CP_ACP
, 0, descA
, -1, descW
, sizeof(descW
)/sizeof(descW
[0]));
453 MultiByteToWideChar(CP_ACP
, 0, modA
, -1, modW
, sizeof(modW
)/sizeof(modW
[0]));
455 return context
->callW(guid
, descW
, modW
, context
->data
);
458 /***************************************************************************
459 * DirectSoundEnumerateA [DSOUND.2]
461 * Enumerate all DirectSound drivers installed in the system
464 * lpDSEnumCallback [I] Address of callback function.
465 * lpContext [I] Address of user defined context passed to callback function.
469 * Failure: DSERR_INVALIDPARAM
471 HRESULT WINAPI
DirectSoundEnumerateA(
472 LPDSENUMCALLBACKA lpDSEnumCallback
,
475 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
476 lpDSEnumCallback
, lpContext
);
478 if (lpDSEnumCallback
== NULL
) {
479 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
480 return DSERR_INVALIDPARAM
;
482 else if (openal_loaded
)
484 const ALCchar
*devstr
;
487 EnterCriticalSection(&openal_crst
);
488 devstr
= DSOUND_getdevicestrings();
489 if(!devstr
|| !*devstr
)
492 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
493 "Primary Sound Driver","",lpContext
);
494 if(lpDSEnumCallback(NULL
, "Primary Sound Driver", "", lpContext
) == FALSE
)
497 guid
= DSOUND_renderer_guid
;
499 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
500 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
501 if(lpDSEnumCallback(&guid
, devstr
, "wineal.drv", lpContext
) == FALSE
)
504 devstr
+= strlen(devstr
)+1;
507 LeaveCriticalSection(&openal_crst
);
511 ERR("Attempting to enumerate sound cards without OpenAL support\n");
512 ERR("Please recompile wine with OpenAL for sound to work\n");
517 /***************************************************************************
518 * DirectSoundEnumerateW [DSOUND.3]
520 * Enumerate all DirectSound drivers installed in the system
523 * lpDSEnumCallback [I] Address of callback function.
524 * lpContext [I] Address of user defined context passed to callback function.
528 * Failure: DSERR_INVALIDPARAM
530 HRESULT WINAPI
DirectSoundEnumerateW(
531 LPDSENUMCALLBACKW lpDSEnumCallback
,
534 struct morecontext context
;
536 if(lpDSEnumCallback
== NULL
) {
537 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
538 return DSERR_INVALIDPARAM
;
541 context
.callW
= lpDSEnumCallback
;
542 context
.data
= lpContext
;
544 return DirectSoundEnumerateA(w_to_a_callback
, &context
);
547 /***************************************************************************
548 * DirectSoundCaptureEnumerateA [DSOUND.7]
550 * Enumerate all DirectSound drivers installed in the system.
553 * lpDSEnumCallback [I] Address of callback function.
554 * lpContext [I] Address of user defined context passed to callback function.
558 * Failure: DSERR_INVALIDPARAM
560 HRESULT WINAPI
DirectSoundCaptureEnumerateA(
561 LPDSENUMCALLBACKA lpDSEnumCallback
,
564 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
566 if (lpDSEnumCallback
== NULL
) {
567 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
568 return DSERR_INVALIDPARAM
;
570 else if (openal_loaded
)
572 const ALCchar
*devstr
;
575 EnterCriticalSection(&openal_crst
);
576 devstr
= DSOUND_getcapturedevicestrings();
577 if(!devstr
|| !*devstr
)
580 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
581 "Primary Sound Capture Driver","",lpContext
);
582 if(lpDSEnumCallback(NULL
, "Primary Sound Driver", "", lpContext
) == FALSE
)
585 guid
= DSOUND_capture_guid
;
587 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
588 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
589 if(lpDSEnumCallback(&guid
, devstr
, "wineal.drv", lpContext
) == FALSE
)
592 devstr
+= strlen(devstr
)+1;
595 LeaveCriticalSection(&openal_crst
);
599 ERR("Attempting to enumerate sound cards without OpenAL support\n");
600 ERR("Please recompile wine with OpenAL for sound to work\n");
605 /***************************************************************************
606 * DirectSoundCaptureEnumerateW [DSOUND.8]
608 * Enumerate all DirectSound drivers installed in the system.
611 * lpDSEnumCallback [I] Address of callback function.
612 * lpContext [I] Address of user defined context passed to callback function.
616 * Failure: DSERR_INVALIDPARAM
619 DirectSoundCaptureEnumerateW(
620 LPDSENUMCALLBACKW lpDSEnumCallback
,
623 struct morecontext context
;
625 if (lpDSEnumCallback
== NULL
) {
626 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
627 return DSERR_INVALIDPARAM
;
630 context
.callW
= lpDSEnumCallback
;
631 context
.data
= lpContext
;
633 return DirectSoundCaptureEnumerateA(w_to_a_callback
, &context
);
636 /*******************************************************************************
637 * DirectSoundCreate (DSOUND.1)
639 * Creates and initializes a DirectSound interface.
642 * lpcGUID [I] Address of the GUID that identifies the sound device.
643 * ppDS [O] Address of a variable to receive the interface pointer.
644 * pUnkOuter [I] Must be NULL.
648 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
649 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
652 DirectSoundCreate(LPCGUID lpcGUID
, IDirectSound
**ppDS
, IUnknown
*pUnkOuter
)
657 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDS
, pUnkOuter
);
660 WARN("invalid parameter: ppDS == NULL\n");
661 return DSERR_INVALIDPARAM
;
665 if (pUnkOuter
!= NULL
) {
666 WARN("invalid parameter: pUnkOuter != NULL\n");
667 return DSERR_INVALIDPARAM
;
670 hr
= DSOUND_Create(&IID_IDirectSound
, &pDS
);
674 hr
= IDirectSound_Initialize(*ppDS
, lpcGUID
);
677 IDirectSound_Release(*ppDS
);
685 /*******************************************************************************
686 * DirectSoundCreate8 (DSOUND.11)
688 * Creates and initializes a DirectSound8 interface.
691 * lpcGUID [I] Address of the GUID that identifies the sound device.
692 * ppDS [O] Address of a variable to receive the interface pointer.
693 * pUnkOuter [I] Must be NULL.
697 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
698 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
701 DirectSoundCreate8(LPCGUID lpcGUID
, IDirectSound8
**ppDS
, IUnknown
*pUnkOuter
)
706 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDS
, pUnkOuter
);
709 WARN("invalid parameter: ppDS == NULL\n");
710 return DSERR_INVALIDPARAM
;
714 if (pUnkOuter
!= NULL
) {
715 WARN("invalid parameter: pUnkOuter != NULL\n");
716 return DSERR_INVALIDPARAM
;
719 hr
= DSOUND_Create8(&IID_IDirectSound8
, &pDS
);
723 hr
= IDirectSound8_Initialize(*ppDS
, lpcGUID
);
726 IDirectSound8_Release(*ppDS
);
734 /***************************************************************************
735 * DirectSoundCaptureCreate [DSOUND.6]
737 * Create and initialize a DirectSoundCapture interface.
740 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
741 * lplpDSC [O] Address of a variable to receive the interface pointer.
742 * pUnkOuter [I] Must be NULL.
746 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
750 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
751 * or NULL for the default device or DSDEVID_DefaultCapture or
752 * DSDEVID_DefaultVoiceCapture.
754 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
757 DirectSoundCaptureCreate(LPCGUID lpcGUID
, IDirectSoundCapture
**ppDSC
, IUnknown
*pUnkOuter
)
762 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC
, pUnkOuter
);
766 WARN("invalid parameter: ppDSC == NULL\n");
767 return DSERR_INVALIDPARAM
;
773 WARN("invalid parameter: pUnkOuter != NULL\n");
774 return DSERR_NOAGGREGATION
;
777 hr
= DSOUND_CaptureCreate(&IID_IDirectSoundCapture
, &pDSC
);
781 hr
= IDirectSoundCapture_Initialize(*ppDSC
, lpcGUID
);
784 IDirectSoundCapture_Release(*ppDSC
);
792 /***************************************************************************
793 * DirectSoundCaptureCreate8 [DSOUND.12]
795 * Create and initialize a DirectSoundCapture interface.
798 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
799 * lplpDSC [O] Address of a variable to receive the interface pointer.
800 * pUnkOuter [I] Must be NULL.
804 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
808 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
809 * or NULL for the default device or DSDEVID_DefaultCapture or
810 * DSDEVID_DefaultVoiceCapture.
812 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
815 DirectSoundCaptureCreate8(LPCGUID lpcGUID
, IDirectSoundCapture8
**ppDSC8
, IUnknown
*pUnkOuter
)
820 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC8
, pUnkOuter
);
824 WARN("invalid parameter: ppDSC8 == NULL\n");
825 return DSERR_INVALIDPARAM
;
831 WARN("invalid parameter: pUnkOuter != NULL\n");
832 return DSERR_NOAGGREGATION
;
835 hr
= DSOUND_CaptureCreate8(&IID_IDirectSoundCapture
, &pDSC8
);
839 hr
= IDirectSoundCapture_Initialize(*ppDSC8
, lpcGUID
);
842 IDirectSoundCapture_Release(*ppDSC8
);
850 /*******************************************************************************
851 * DirectSound ClassFactory
854 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
857 IClassFactory IClassFactory_iface
;
860 FnCreateInstance pfnCreateInstance
;
863 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
865 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
868 static HRESULT WINAPI
DSCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
870 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
871 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
874 if (IsEqualIID(riid
, &IID_IUnknown
) ||
875 IsEqualIID(riid
, &IID_IClassFactory
))
878 IUnknown_AddRef(iface
);
882 return E_NOINTERFACE
;
885 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
887 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
888 ULONG ref
= InterlockedIncrement(&(This
->ref
));
889 TRACE("(%p) ref was %"LONGFMT
"u\n", This
, ref
- 1);
893 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
895 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
896 ULONG ref
= InterlockedDecrement(&(This
->ref
));
897 TRACE("(%p) ref was %"LONGFMT
"u\n", This
, ref
+ 1);
898 /* static class, won't be freed */
902 static HRESULT WINAPI
DSCF_CreateInstance(
903 LPCLASSFACTORY iface
,
908 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
909 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
912 return CLASS_E_NOAGGREGATION
;
915 WARN("invalid parameter\n");
916 return DSERR_INVALIDPARAM
;
919 return This
->pfnCreateInstance(riid
, ppobj
);
922 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
924 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
925 FIXME("(%p, %d) stub!\n", This
, dolock
);
929 static const IClassFactoryVtbl DSCF_Vtbl
= {
937 static IClassFactoryImpl DSOUND_CF
[] = {
938 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound
, DSOUND_Create
},
939 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound8
, DSOUND_Create8
},
940 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture
, DSOUND_CaptureCreate
},
941 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture8
, DSOUND_CaptureCreate8
},
942 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundFullDuplex
, DSOUND_FullDuplexCreate
},
943 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundPrivate
, IKsPrivatePropertySetImpl_Create
},
944 { {NULL
}, 0, NULL
, NULL
}
947 /*******************************************************************************
948 * DllGetClassObject [DSOUND.@]
949 * Retrieves class object from a DLL object
952 * Docs say returns STDAPI
955 * rclsid [I] CLSID for the class object
956 * riid [I] Reference to identifier of interface for class object
957 * ppv [O] Address of variable to receive interface pointer for riid
961 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
964 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
967 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
970 WARN("invalid parameter\n");
976 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
977 !IsEqualIID(riid
, &IID_IUnknown
)) {
978 WARN("no interface for %s\n", debugstr_guid(riid
));
979 return E_NOINTERFACE
;
982 while (NULL
!= DSOUND_CF
[i
].rclsid
) {
983 if (IsEqualGUID(rclsid
, DSOUND_CF
[i
].rclsid
)) {
984 DSCF_AddRef(&DSOUND_CF
[i
].IClassFactory_iface
);
985 *ppv
= &DSOUND_CF
[i
];
991 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
992 debugstr_guid(riid
), ppv
);
993 return CLASS_E_CLASSNOTAVAILABLE
;
997 /*******************************************************************************
998 * DllCanUnloadNow [DSOUND.4]
999 * Determines whether the DLL is in use.
1005 HRESULT WINAPI
DllCanUnloadNow(void)
1007 FIXME("(void): stub\n");
1011 /***********************************************************************
1012 * DllMain (DSOUND.init)
1014 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1016 TRACE("(%p, %"LONGFMT
"u, %p)\n", hInstDLL
, fdwReason
, lpvReserved
);
1020 case DLL_PROCESS_ATTACH
:
1021 TRACE("DLL_PROCESS_ATTACH\n");
1022 instance
= hInstDLL
;
1024 /* Increase refcount on dsound by 1 */
1025 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
1028 case DLL_THREAD_DETACH
:
1029 TRACE("DLL_THREAD_DETACH\n");
1030 #if !ALLOW_CONCURRENT_AL
1036 case DLL_PROCESS_DETACH
:
1037 TRACE("DLL_PROCESS_DETACH\n");
1038 #ifdef SONAME_LIBOPENAL
1040 wine_dlclose(openal_handle
, NULL
, 0);
1045 TRACE("UNKNOWN REASON\n");
1052 /***********************************************************************
1053 * DllRegisterServer (DSOUND.@)
1055 HRESULT WINAPI
DllRegisterServer(void)
1057 return __wine_register_resources(instance
);
1060 /***********************************************************************
1061 * DllUnregisterServer (DSOUND.@)
1063 HRESULT WINAPI
DllUnregisterServer(void)
1065 return __wine_unregister_resources(instance
);