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);
80 /* From dlls/winecrt0/register.c */
81 static HRESULT
__wine_register_resources(HMODULE module
, const CLSID
*clsid
)
87 static HRESULT
__wine_unregister_resources(HMODULE module
, const CLSID
*clsid
)
95 static HINSTANCE instance
;
97 const GUID DSOUND_renderer_guid
= { 0xbd6dd71a, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
98 const GUID DSOUND_capture_guid
= { 0xbd6dd71b, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
100 const IID DSPROPSETID_EAX20_ListenerProperties
= {
101 0x0306a6a8, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
104 const EAXLISTENERPROPERTIES EnvironmentDefaults
[EAX_ENVIRONMENT_COUNT
] =
106 REVERB_PRESET_GENERIC
,
107 REVERB_PRESET_PADDEDCELL
,
109 REVERB_PRESET_BATHROOM
,
110 REVERB_PRESET_LIVINGROOM
,
111 REVERB_PRESET_STONEROOM
,
112 REVERB_PRESET_AUDITORIUM
,
113 REVERB_PRESET_CONCERTHALL
,
116 REVERB_PRESET_HANGAR
,
117 REVERB_PRESET_CARPETEDHALLWAY
,
118 REVERB_PRESET_HALLWAY
,
119 REVERB_PRESET_STONECORRIDOR
,
121 REVERB_PRESET_FOREST
,
123 REVERB_PRESET_MOUNTAINS
,
124 REVERB_PRESET_QUARRY
,
126 REVERB_PRESET_PARKINGLOT
,
127 REVERB_PRESET_SEWERPIPE
,
128 REVERB_PRESET_UNDERWATER
,
129 REVERB_PRESET_DRUGGED
,
131 REVERB_PRESET_PSYCHOTIC
134 static CRITICAL_SECTION_DEBUG openal_crst_debug
=
137 { &openal_crst_debug
.ProcessLocksList
,
138 &openal_crst_debug
.ProcessLocksList
},
139 0, 0, { (DWORD_PTR
)(__FILE__
": openal_crst_debug") }
141 CRITICAL_SECTION openal_crst
= { &openal_crst_debug
, -1, 0, 0, 0, 0 };
143 int openal_loaded
= 0;
144 #ifdef SONAME_LIBOPENAL
145 static void *openal_handle
= NULL
;
146 LPALCCREATECONTEXT palcCreateContext
= NULL
;
147 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent
= NULL
;
148 LPALCPROCESSCONTEXT palcProcessContext
= NULL
;
149 LPALCSUSPENDCONTEXT palcSuspendContext
= NULL
;
150 LPALCDESTROYCONTEXT palcDestroyContext
= NULL
;
151 LPALCGETCURRENTCONTEXT palcGetCurrentContext
= NULL
;
152 LPALCGETCONTEXTSDEVICE palcGetContextsDevice
= NULL
;
153 LPALCOPENDEVICE palcOpenDevice
= NULL
;
154 LPALCCLOSEDEVICE palcCloseDevice
= NULL
;
155 LPALCGETERROR palcGetError
= NULL
;
156 LPALCISEXTENSIONPRESENT palcIsExtensionPresent
= NULL
;
157 LPALCGETPROCADDRESS palcGetProcAddress
= NULL
;
158 LPALCGETENUMVALUE palcGetEnumValue
= NULL
;
159 LPALCGETSTRING palcGetString
= NULL
;
160 LPALCGETINTEGERV palcGetIntegerv
= NULL
;
161 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice
= NULL
;
162 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice
= NULL
;
163 LPALCCAPTURESTART palcCaptureStart
= NULL
;
164 LPALCCAPTURESTOP palcCaptureStop
= NULL
;
165 LPALCCAPTURESAMPLES palcCaptureSamples
= NULL
;
166 LPALENABLE palEnable
= NULL
;
167 LPALDISABLE palDisable
= NULL
;
168 LPALISENABLED palIsEnabled
= NULL
;
169 LPALGETSTRING palGetString
= NULL
;
170 LPALGETBOOLEANV palGetBooleanv
= NULL
;
171 LPALGETINTEGERV palGetIntegerv
= NULL
;
172 LPALGETFLOATV palGetFloatv
= NULL
;
173 LPALGETDOUBLEV palGetDoublev
= NULL
;
174 LPALGETBOOLEAN palGetBoolean
= NULL
;
175 LPALGETINTEGER palGetInteger
= NULL
;
176 LPALGETFLOAT palGetFloat
= NULL
;
177 LPALGETDOUBLE palGetDouble
= NULL
;
178 LPALGETERROR palGetError
= NULL
;
179 LPALISEXTENSIONPRESENT palIsExtensionPresent
= NULL
;
180 LPALGETPROCADDRESS palGetProcAddress
= NULL
;
181 LPALGETENUMVALUE palGetEnumValue
= NULL
;
182 LPALLISTENERF palListenerf
= NULL
;
183 LPALLISTENER3F palListener3f
= NULL
;
184 LPALLISTENERFV palListenerfv
= NULL
;
185 LPALLISTENERI palListeneri
= NULL
;
186 LPALLISTENER3I palListener3i
= NULL
;
187 LPALLISTENERIV palListeneriv
= NULL
;
188 LPALGETLISTENERF palGetListenerf
= NULL
;
189 LPALGETLISTENER3F palGetListener3f
= NULL
;
190 LPALGETLISTENERFV palGetListenerfv
= NULL
;
191 LPALGETLISTENERI palGetListeneri
= NULL
;
192 LPALGETLISTENER3I palGetListener3i
= NULL
;
193 LPALGETLISTENERIV palGetListeneriv
= NULL
;
194 LPALGENSOURCES palGenSources
= NULL
;
195 LPALDELETESOURCES palDeleteSources
= NULL
;
196 LPALISSOURCE palIsSource
= NULL
;
197 LPALSOURCEF palSourcef
= NULL
;
198 LPALSOURCE3F palSource3f
= NULL
;
199 LPALSOURCEFV palSourcefv
= NULL
;
200 LPALSOURCEI palSourcei
= NULL
;
201 LPALSOURCE3I palSource3i
= NULL
;
202 LPALSOURCEIV palSourceiv
= NULL
;
203 LPALGETSOURCEF palGetSourcef
= NULL
;
204 LPALGETSOURCE3F palGetSource3f
= NULL
;
205 LPALGETSOURCEFV palGetSourcefv
= NULL
;
206 LPALGETSOURCEI palGetSourcei
= NULL
;
207 LPALGETSOURCE3I palGetSource3i
= NULL
;
208 LPALGETSOURCEIV palGetSourceiv
= NULL
;
209 LPALSOURCEPLAYV palSourcePlayv
= NULL
;
210 LPALSOURCESTOPV palSourceStopv
= NULL
;
211 LPALSOURCEREWINDV palSourceRewindv
= NULL
;
212 LPALSOURCEPAUSEV palSourcePausev
= NULL
;
213 LPALSOURCEPLAY palSourcePlay
= NULL
;
214 LPALSOURCESTOP palSourceStop
= NULL
;
215 LPALSOURCEREWIND palSourceRewind
= NULL
;
216 LPALSOURCEPAUSE palSourcePause
= NULL
;
217 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers
= NULL
;
218 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers
= NULL
;
219 LPALGENBUFFERS palGenBuffers
= NULL
;
220 LPALDELETEBUFFERS palDeleteBuffers
= NULL
;
221 LPALISBUFFER palIsBuffer
= NULL
;
222 LPALBUFFERF palBufferf
= NULL
;
223 LPALBUFFER3F palBuffer3f
= NULL
;
224 LPALBUFFERFV palBufferfv
= NULL
;
225 LPALBUFFERI palBufferi
= NULL
;
226 LPALBUFFER3I palBuffer3i
= NULL
;
227 LPALBUFFERIV palBufferiv
= NULL
;
228 LPALGETBUFFERF palGetBufferf
= NULL
;
229 LPALGETBUFFER3F palGetBuffer3f
= NULL
;
230 LPALGETBUFFERFV palGetBufferfv
= NULL
;
231 LPALGETBUFFERI palGetBufferi
= NULL
;
232 LPALGETBUFFER3I palGetBuffer3i
= NULL
;
233 LPALGETBUFFERIV palGetBufferiv
= NULL
;
234 LPALBUFFERDATA palBufferData
= NULL
;
235 LPALDOPPLERFACTOR palDopplerFactor
= NULL
;
236 LPALDOPPLERVELOCITY palDopplerVelocity
= NULL
;
237 LPALDISTANCEMODEL palDistanceModel
= NULL
;
238 LPALSPEEDOFSOUND palSpeedOfSound
= NULL
;
241 LPALCMAKECONTEXTCURRENT set_context
;
242 LPALCGETCURRENTCONTEXT get_context
;
245 static void load_libopenal(void)
248 const char *str
= getenv("DSOAL_LOGLEVEL");
250 LogLevel
= atoi(str
);
251 #elif defined(SONAME_LIBOPENAL)
255 openal_handle
= wine_dlopen(SONAME_LIBOPENAL
, RTLD_NOW
, error
, sizeof(error
));
257 ERR("Couldn't load " SONAME_LIBOPENAL
": %s\n", error
);
258 #define LOAD_FUNCPTR(f) \
259 if((p##f = wine_dlsym(openal_handle, #f, NULL, 0)) == NULL) { \
260 ERR("Couldn't lookup %s in " SONAME_LIBOPENAL "\n", #f); \
264 LOAD_FUNCPTR(alcCreateContext
);
265 LOAD_FUNCPTR(alcMakeContextCurrent
);
266 LOAD_FUNCPTR(alcProcessContext
);
267 LOAD_FUNCPTR(alcSuspendContext
);
268 LOAD_FUNCPTR(alcDestroyContext
);
269 LOAD_FUNCPTR(alcGetCurrentContext
);
270 LOAD_FUNCPTR(alcGetContextsDevice
);
271 LOAD_FUNCPTR(alcOpenDevice
);
272 LOAD_FUNCPTR(alcCloseDevice
);
273 LOAD_FUNCPTR(alcGetError
);
274 LOAD_FUNCPTR(alcIsExtensionPresent
);
275 LOAD_FUNCPTR(alcGetProcAddress
);
276 LOAD_FUNCPTR(alcGetEnumValue
);
277 LOAD_FUNCPTR(alcGetString
);
278 LOAD_FUNCPTR(alcGetIntegerv
);
279 LOAD_FUNCPTR(alcCaptureOpenDevice
);
280 LOAD_FUNCPTR(alcCaptureCloseDevice
);
281 LOAD_FUNCPTR(alcCaptureStart
);
282 LOAD_FUNCPTR(alcCaptureStop
);
283 LOAD_FUNCPTR(alcCaptureSamples
);
284 LOAD_FUNCPTR(alEnable
);
285 LOAD_FUNCPTR(alDisable
);
286 LOAD_FUNCPTR(alIsEnabled
);
287 LOAD_FUNCPTR(alGetString
);
288 LOAD_FUNCPTR(alGetBooleanv
);
289 LOAD_FUNCPTR(alGetIntegerv
);
290 LOAD_FUNCPTR(alGetFloatv
);
291 LOAD_FUNCPTR(alGetDoublev
);
292 LOAD_FUNCPTR(alGetBoolean
);
293 LOAD_FUNCPTR(alGetInteger
);
294 LOAD_FUNCPTR(alGetFloat
);
295 LOAD_FUNCPTR(alGetDouble
);
296 LOAD_FUNCPTR(alGetError
);
297 LOAD_FUNCPTR(alIsExtensionPresent
);
298 LOAD_FUNCPTR(alGetProcAddress
);
299 LOAD_FUNCPTR(alGetEnumValue
);
300 LOAD_FUNCPTR(alListenerf
);
301 LOAD_FUNCPTR(alListener3f
);
302 LOAD_FUNCPTR(alListenerfv
);
303 LOAD_FUNCPTR(alListeneri
);
304 LOAD_FUNCPTR(alListener3i
);
305 LOAD_FUNCPTR(alListeneriv
);
306 LOAD_FUNCPTR(alGetListenerf
);
307 LOAD_FUNCPTR(alGetListener3f
);
308 LOAD_FUNCPTR(alGetListenerfv
);
309 LOAD_FUNCPTR(alGetListeneri
);
310 LOAD_FUNCPTR(alGetListener3i
);
311 LOAD_FUNCPTR(alGetListeneriv
);
312 LOAD_FUNCPTR(alGenSources
);
313 LOAD_FUNCPTR(alDeleteSources
);
314 LOAD_FUNCPTR(alIsSource
);
315 LOAD_FUNCPTR(alSourcef
);
316 LOAD_FUNCPTR(alSource3f
);
317 LOAD_FUNCPTR(alSourcefv
);
318 LOAD_FUNCPTR(alSourcei
);
319 LOAD_FUNCPTR(alSource3i
);
320 LOAD_FUNCPTR(alSourceiv
);
321 LOAD_FUNCPTR(alGetSourcef
);
322 LOAD_FUNCPTR(alGetSource3f
);
323 LOAD_FUNCPTR(alGetSourcefv
);
324 LOAD_FUNCPTR(alGetSourcei
);
325 LOAD_FUNCPTR(alGetSource3i
);
326 LOAD_FUNCPTR(alGetSourceiv
);
327 LOAD_FUNCPTR(alSourcePlayv
);
328 LOAD_FUNCPTR(alSourceStopv
);
329 LOAD_FUNCPTR(alSourceRewindv
);
330 LOAD_FUNCPTR(alSourcePausev
);
331 LOAD_FUNCPTR(alSourcePlay
);
332 LOAD_FUNCPTR(alSourceStop
);
333 LOAD_FUNCPTR(alSourceRewind
);
334 LOAD_FUNCPTR(alSourcePause
);
335 LOAD_FUNCPTR(alSourceQueueBuffers
);
336 LOAD_FUNCPTR(alSourceUnqueueBuffers
);
337 LOAD_FUNCPTR(alGenBuffers
);
338 LOAD_FUNCPTR(alDeleteBuffers
);
339 LOAD_FUNCPTR(alIsBuffer
);
340 LOAD_FUNCPTR(alBufferf
);
341 LOAD_FUNCPTR(alBuffer3f
);
342 LOAD_FUNCPTR(alBufferfv
);
343 LOAD_FUNCPTR(alBufferi
);
344 LOAD_FUNCPTR(alBuffer3i
);
345 LOAD_FUNCPTR(alBufferiv
);
346 LOAD_FUNCPTR(alGetBufferf
);
347 LOAD_FUNCPTR(alGetBuffer3f
);
348 LOAD_FUNCPTR(alGetBufferfv
);
349 LOAD_FUNCPTR(alGetBufferi
);
350 LOAD_FUNCPTR(alGetBuffer3i
);
351 LOAD_FUNCPTR(alGetBufferiv
);
352 LOAD_FUNCPTR(alBufferData
);
353 LOAD_FUNCPTR(alDopplerFactor
);
354 LOAD_FUNCPTR(alDopplerVelocity
);
355 LOAD_FUNCPTR(alDistanceModel
);
356 LOAD_FUNCPTR(alSpeedOfSound
);
360 WARN("Unloading openal\n");
361 if (openal_handle
!= RTLD_DEFAULT
)
362 wine_dlclose(openal_handle
, NULL
, 0);
363 openal_handle
= NULL
;
370 local_contexts
= alcIsExtensionPresent(NULL
, "ALC_EXT_thread_local_context");
373 set_context
= alcGetProcAddress(NULL
, "alcSetThreadContext");
374 get_context
= alcGetProcAddress(NULL
, "alcGetThreadContext");
375 if(!set_context
|| !get_context
)
377 ERR("TLS advertised but functions not found, disabling thread local context\n");
383 set_context
= alcMakeContextCurrent
;
384 get_context
= alcGetCurrentContext
;
389 const ALCchar
*DSOUND_getdevicestrings(void)
391 const ALCchar
*str
= NULL
;
394 multiple
= alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT");
396 str
= alcGetString(NULL
, ALC_ALL_DEVICES_SPECIFIER
);
398 str
= alcGetString(NULL
, ALC_DEVICE_SPECIFIER
);
402 const ALCchar
*DSOUND_getcapturedevicestrings(void)
404 const ALCchar
*str
= NULL
;
405 str
= alcGetString(NULL
, ALC_CAPTURE_DEVICE_SPECIFIER
);
409 /***************************************************************************
410 * GetDeviceID [DSOUND.9]
412 * Retrieves unique identifier of default device specified
415 * pGuidSrc [I] Address of device GUID.
416 * pGuidDest [O] Address to receive unique device GUID.
420 * Failure: DSERR_INVALIDPARAM
423 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
424 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
425 * DSDEVID_DefaultVoiceCapture.
426 * Returns pGuidSrc if pGuidSrc is a valid device or the device
427 * GUID for the specified constants.
429 HRESULT WINAPI
GetDeviceID(LPCGUID pGuidSrc
, LPGUID pGuidDest
)
431 TRACE("(%s,%p)\n", debugstr_guid(pGuidSrc
),pGuidDest
);
433 if ( pGuidSrc
== NULL
) {
434 WARN("invalid parameter: pGuidSrc == NULL\n");
435 return DSERR_INVALIDPARAM
;
438 if ( pGuidDest
== NULL
) {
439 WARN("invalid parameter: pGuidDest == NULL\n");
440 return DSERR_INVALIDPARAM
;
443 if ( IsEqualGUID( &DSDEVID_DefaultPlayback
, pGuidSrc
) ||
444 IsEqualGUID( &DSDEVID_DefaultVoicePlayback
, pGuidSrc
) ) {
445 *pGuidDest
= DSOUND_renderer_guid
;
446 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
450 if ( IsEqualGUID( &DSDEVID_DefaultCapture
, pGuidSrc
) ||
451 IsEqualGUID( &DSDEVID_DefaultVoiceCapture
, pGuidSrc
) ) {
452 *pGuidDest
= DSOUND_capture_guid
;
453 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
457 *pGuidDest
= *pGuidSrc
;
458 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
465 LPDSENUMCALLBACKW callW
;
469 static BOOL CALLBACK
w_to_a_callback(LPGUID guid
, LPCSTR descA
, LPCSTR modA
, LPVOID data
)
471 struct morecontext
*context
= data
;
472 WCHAR descW
[MAXPNAMELEN
], modW
[MAXPNAMELEN
];
474 MultiByteToWideChar(CP_ACP
, 0, descA
, -1, descW
, sizeof(descW
)/sizeof(descW
[0]));
475 MultiByteToWideChar(CP_ACP
, 0, modA
, -1, modW
, sizeof(modW
)/sizeof(modW
[0]));
477 return context
->callW(guid
, descW
, modW
, context
->data
);
480 /***************************************************************************
481 * DirectSoundEnumerateA [DSOUND.2]
483 * Enumerate all DirectSound drivers installed in the system
486 * lpDSEnumCallback [I] Address of callback function.
487 * lpContext [I] Address of user defined context passed to callback function.
491 * Failure: DSERR_INVALIDPARAM
493 HRESULT WINAPI
DirectSoundEnumerateA(
494 LPDSENUMCALLBACKA lpDSEnumCallback
,
497 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
498 lpDSEnumCallback
, lpContext
);
500 if (lpDSEnumCallback
== NULL
) {
501 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
502 return DSERR_INVALIDPARAM
;
504 else if (openal_loaded
)
506 const ALCchar
*devstr
;
509 EnterCriticalSection(&openal_crst
);
510 devstr
= DSOUND_getdevicestrings();
511 if(!devstr
|| !*devstr
)
514 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
515 "Primary Sound Driver","",lpContext
);
516 if(lpDSEnumCallback(NULL
, "Primary Sound Driver", "", lpContext
) == FALSE
)
519 guid
= DSOUND_renderer_guid
;
521 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
522 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
523 if(lpDSEnumCallback(&guid
, devstr
, "wineal.drv", lpContext
) == FALSE
)
526 devstr
+= strlen(devstr
)+1;
529 LeaveCriticalSection(&openal_crst
);
533 ERR("Attempting to enumerate sound cards without OpenAL support\n");
534 ERR("Please recompile wine with OpenAL for sound to work\n");
539 /***************************************************************************
540 * DirectSoundEnumerateW [DSOUND.3]
542 * Enumerate all DirectSound drivers installed in the system
545 * lpDSEnumCallback [I] Address of callback function.
546 * lpContext [I] Address of user defined context passed to callback function.
550 * Failure: DSERR_INVALIDPARAM
552 HRESULT WINAPI
DirectSoundEnumerateW(
553 LPDSENUMCALLBACKW lpDSEnumCallback
,
556 struct morecontext context
;
558 if(lpDSEnumCallback
== NULL
) {
559 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
560 return DSERR_INVALIDPARAM
;
563 context
.callW
= lpDSEnumCallback
;
564 context
.data
= lpContext
;
566 return DirectSoundEnumerateA(w_to_a_callback
, &context
);
569 /***************************************************************************
570 * DirectSoundCaptureEnumerateA [DSOUND.7]
572 * Enumerate all DirectSound drivers installed in the system.
575 * lpDSEnumCallback [I] Address of callback function.
576 * lpContext [I] Address of user defined context passed to callback function.
580 * Failure: DSERR_INVALIDPARAM
582 HRESULT WINAPI
DirectSoundCaptureEnumerateA(
583 LPDSENUMCALLBACKA lpDSEnumCallback
,
586 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
588 if (lpDSEnumCallback
== NULL
) {
589 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
590 return DSERR_INVALIDPARAM
;
592 else if (openal_loaded
)
594 const ALCchar
*devstr
;
597 EnterCriticalSection(&openal_crst
);
598 devstr
= DSOUND_getcapturedevicestrings();
599 if(!devstr
|| !*devstr
)
602 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
603 "Primary Sound Capture Driver","",lpContext
);
604 if(lpDSEnumCallback(NULL
, "Primary Sound Driver", "", lpContext
) == FALSE
)
607 guid
= DSOUND_capture_guid
;
609 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
610 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
611 if(lpDSEnumCallback(&guid
, devstr
, "wineal.drv", lpContext
) == FALSE
)
614 devstr
+= strlen(devstr
)+1;
617 LeaveCriticalSection(&openal_crst
);
621 ERR("Attempting to enumerate sound cards without OpenAL support\n");
622 ERR("Please recompile wine with OpenAL for sound to work\n");
627 /***************************************************************************
628 * DirectSoundCaptureEnumerateW [DSOUND.8]
630 * Enumerate all DirectSound drivers installed in the system.
633 * lpDSEnumCallback [I] Address of callback function.
634 * lpContext [I] Address of user defined context passed to callback function.
638 * Failure: DSERR_INVALIDPARAM
641 DirectSoundCaptureEnumerateW(
642 LPDSENUMCALLBACKW lpDSEnumCallback
,
645 struct morecontext context
;
647 if (lpDSEnumCallback
== NULL
) {
648 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
649 return DSERR_INVALIDPARAM
;
652 context
.callW
= lpDSEnumCallback
;
653 context
.data
= lpContext
;
655 return DirectSoundCaptureEnumerateA(w_to_a_callback
, &context
);
658 /*******************************************************************************
659 * DirectSoundCreate (DSOUND.1)
661 * Creates and initializes a DirectSound interface.
664 * lpcGUID [I] Address of the GUID that identifies the sound device.
665 * ppDS [O] Address of a variable to receive the interface pointer.
666 * pUnkOuter [I] Must be NULL.
670 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
671 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
673 HRESULT WINAPI
DirectSoundCreate(
681 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
684 WARN("invalid parameter: ppDS == NULL\n");
685 return DSERR_INVALIDPARAM
;
688 if (pUnkOuter
!= NULL
) {
689 WARN("invalid parameter: pUnkOuter != NULL\n");
691 return DSERR_INVALIDPARAM
;
694 hr
= DSOUND_Create(&IID_IDirectSound
, (void **)&pDS
);
696 hr
= IDirectSound_Initialize(pDS
, lpcGUID
);
698 if (hr
!= DSERR_ALREADYINITIALIZED
) {
699 IDirectSound_Release(pDS
);
711 /*******************************************************************************
712 * DirectSoundCreate8 (DSOUND.11)
714 * Creates and initializes a DirectSound8 interface.
717 * lpcGUID [I] Address of the GUID that identifies the sound device.
718 * ppDS [O] Address of a variable to receive the interface pointer.
719 * pUnkOuter [I] Must be NULL.
723 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
724 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
726 HRESULT WINAPI
DirectSoundCreate8(
728 LPDIRECTSOUND8
*ppDS
,
734 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
737 WARN("invalid parameter: ppDS == NULL\n");
738 return DSERR_INVALIDPARAM
;
741 if (pUnkOuter
!= NULL
) {
742 WARN("invalid parameter: pUnkOuter != NULL\n");
744 return DSERR_INVALIDPARAM
;
747 hr
= DSOUND_Create8(&IID_IDirectSound8
, (void**)&pDS
);
749 hr
= IDirectSound8_Initialize(pDS
, lpcGUID
);
751 if (hr
!= DSERR_ALREADYINITIALIZED
) {
752 IDirectSound8_Release(pDS
);
764 /***************************************************************************
765 * DirectSoundCaptureCreate [DSOUND.6]
767 * Create and initialize a DirectSoundCapture interface.
770 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
771 * lplpDSC [O] Address of a variable to receive the interface pointer.
772 * pUnkOuter [I] Must be NULL.
776 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
780 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
781 * or NULL for the default device or DSDEVID_DefaultCapture or
782 * DSDEVID_DefaultVoiceCapture.
784 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
786 HRESULT WINAPI
DirectSoundCaptureCreate(
788 IDirectSoundCapture
**ppDSC
,
794 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC
, pUnkOuter
);
798 WARN("invalid parameter: ppDSC == NULL\n");
799 return DSERR_INVALIDPARAM
;
805 WARN("invalid parameter: pUnkOuter != NULL\n");
806 return DSERR_NOAGGREGATION
;
809 hr
= DSOUND_CaptureCreate(&IID_IDirectSoundCapture
, &pDSC
);
813 hr
= IDirectSoundCapture_Initialize(*ppDSC
, lpcGUID
);
816 IDirectSoundCapture_Release(*ppDSC
);
824 /***************************************************************************
825 * DirectSoundCaptureCreate8 [DSOUND.12]
827 * Create and initialize a DirectSoundCapture interface.
830 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
831 * lplpDSC [O] Address of a variable to receive the interface pointer.
832 * pUnkOuter [I] Must be NULL.
836 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
840 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
841 * or NULL for the default device or DSDEVID_DefaultCapture or
842 * DSDEVID_DefaultVoiceCapture.
844 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
846 HRESULT WINAPI
DirectSoundCaptureCreate8(
848 IDirectSoundCapture8
**ppDSC8
,
854 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC8
, pUnkOuter
);
858 WARN("invalid parameter: ppDSC8 == NULL\n");
859 return DSERR_INVALIDPARAM
;
865 WARN("invalid parameter: pUnkOuter != NULL\n");
866 return DSERR_NOAGGREGATION
;
869 hr
= DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8
, &pDSC8
);
873 hr
= IDirectSoundCapture_Initialize(*ppDSC8
, lpcGUID
);
876 IDirectSoundCapture_Release(*ppDSC8
);
884 /*******************************************************************************
885 * DirectSound ClassFactory
888 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
891 IClassFactory IClassFactory_iface
;
894 FnCreateInstance pfnCreateInstance
;
897 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
899 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
902 static HRESULT WINAPI
DSCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
904 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
905 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
908 if (IsEqualIID(riid
, &IID_IUnknown
) ||
909 IsEqualIID(riid
, &IID_IClassFactory
))
912 IUnknown_AddRef(iface
);
916 return E_NOINTERFACE
;
919 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
921 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
922 ULONG ref
= InterlockedIncrement(&(This
->ref
));
923 TRACE("(%p) ref was %d\n", This
, ref
- 1);
927 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
929 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
930 ULONG ref
= InterlockedDecrement(&(This
->ref
));
931 TRACE("(%p) ref was %d\n", This
, ref
+ 1);
932 /* static class, won't be freed */
936 static HRESULT WINAPI
DSCF_CreateInstance(
937 LPCLASSFACTORY iface
,
942 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
943 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
946 return CLASS_E_NOAGGREGATION
;
949 WARN("invalid parameter\n");
950 return DSERR_INVALIDPARAM
;
953 return This
->pfnCreateInstance(riid
, ppobj
);
956 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
958 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
959 FIXME("(%p, %d) stub!\n", This
, dolock
);
963 static const IClassFactoryVtbl DSCF_Vtbl
= {
971 static IClassFactoryImpl DSOUND_CF
[] = {
972 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound
, DSOUND_Create
},
973 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound8
, DSOUND_Create8
},
974 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture
, DSOUND_CaptureCreate
},
975 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture8
, DSOUND_CaptureCreate8
},
976 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundFullDuplex
, DSOUND_FullDuplexCreate
},
977 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundPrivate
, IKsPrivatePropertySetImpl_Create
},
978 { {NULL
}, 0, NULL
, NULL
}
981 /*******************************************************************************
982 * DllGetClassObject [DSOUND.@]
983 * Retrieves class object from a DLL object
986 * Docs say returns STDAPI
989 * rclsid [I] CLSID for the class object
990 * riid [I] Reference to identifier of interface for class object
991 * ppv [O] Address of variable to receive interface pointer for riid
995 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
998 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1001 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1004 WARN("invalid parameter\n");
1005 return E_INVALIDARG
;
1010 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
1011 !IsEqualIID(riid
, &IID_IUnknown
)) {
1012 WARN("no interface for %s\n", debugstr_guid(riid
));
1013 return E_NOINTERFACE
;
1016 while (NULL
!= DSOUND_CF
[i
].rclsid
) {
1017 if (IsEqualGUID(rclsid
, DSOUND_CF
[i
].rclsid
)) {
1018 DSCF_AddRef(&DSOUND_CF
[i
].IClassFactory_iface
);
1019 *ppv
= &DSOUND_CF
[i
];
1025 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
1026 debugstr_guid(riid
), ppv
);
1027 return CLASS_E_CLASSNOTAVAILABLE
;
1031 /*******************************************************************************
1032 * DllCanUnloadNow [DSOUND.4]
1033 * Determines whether the DLL is in use.
1039 HRESULT WINAPI
DllCanUnloadNow(void)
1041 FIXME("(void): stub\n");
1045 /***********************************************************************
1046 * DllMain (DSOUND.init)
1048 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1050 TRACE("(%p, %d, %p)\n", hInstDLL
, fdwReason
, lpvReserved
);
1054 case DLL_PROCESS_ATTACH
:
1055 TRACE("DLL_PROCESS_ATTACH\n");
1056 instance
= hInstDLL
;
1058 DisableThreadLibraryCalls(hInstDLL
);
1059 /* Increase refcount on dsound by 1 */
1060 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
1062 case DLL_PROCESS_DETACH
:
1063 TRACE("DLL_PROCESS_DETACH\n");
1064 #ifdef SONAME_LIBOPENAL
1066 wine_dlclose(openal_handle
, NULL
, 0);
1067 #endif /*SONAME_LIBOPENAL*/
1070 TRACE("UNKNOWN REASON\n");
1076 /***********************************************************************
1077 * DllRegisterServer (DSOUND.@)
1079 HRESULT WINAPI
DllRegisterServer(void)
1081 return __wine_register_resources(instance
, NULL
);
1084 /***********************************************************************
1085 * DllUnregisterServer (DSOUND.@)
1087 HRESULT WINAPI
DllUnregisterServer(void)
1089 return __wine_unregister_resources(instance
, NULL
);