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 EAXLISTENERPROPERTIES EnvironmentDefaults
[EAX_ENVIRONMENT_COUNT
] =
93 REVERB_PRESET_GENERIC
,
94 REVERB_PRESET_PADDEDCELL
,
96 REVERB_PRESET_BATHROOM
,
97 REVERB_PRESET_LIVINGROOM
,
98 REVERB_PRESET_STONEROOM
,
99 REVERB_PRESET_AUDITORIUM
,
100 REVERB_PRESET_CONCERTHALL
,
103 REVERB_PRESET_HANGAR
,
104 REVERB_PRESET_CARPETEDHALLWAY
,
105 REVERB_PRESET_HALLWAY
,
106 REVERB_PRESET_STONECORRIDOR
,
108 REVERB_PRESET_FOREST
,
110 REVERB_PRESET_MOUNTAINS
,
111 REVERB_PRESET_QUARRY
,
113 REVERB_PRESET_PARKINGLOT
,
114 REVERB_PRESET_SEWERPIPE
,
115 REVERB_PRESET_UNDERWATER
,
116 REVERB_PRESET_DRUGGED
,
118 REVERB_PRESET_PSYCHOTIC
121 static CRITICAL_SECTION_DEBUG openal_crst_debug
=
124 { &openal_crst_debug
.ProcessLocksList
,
125 &openal_crst_debug
.ProcessLocksList
},
126 0, 0, { (DWORD_PTR
)(__FILE__
": openal_crst_debug") }
128 CRITICAL_SECTION openal_crst
= { &openal_crst_debug
, -1, 0, 0, 0, 0 };
130 int openal_loaded
= 0;
131 #ifdef SONAME_LIBOPENAL
132 static void *openal_handle
= NULL
;
133 LPALCCREATECONTEXT palcCreateContext
= NULL
;
134 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent
= NULL
;
135 LPALCPROCESSCONTEXT palcProcessContext
= NULL
;
136 LPALCSUSPENDCONTEXT palcSuspendContext
= NULL
;
137 LPALCDESTROYCONTEXT palcDestroyContext
= NULL
;
138 LPALCGETCURRENTCONTEXT palcGetCurrentContext
= NULL
;
139 LPALCGETCONTEXTSDEVICE palcGetContextsDevice
= NULL
;
140 LPALCOPENDEVICE palcOpenDevice
= NULL
;
141 LPALCCLOSEDEVICE palcCloseDevice
= NULL
;
142 LPALCGETERROR palcGetError
= NULL
;
143 LPALCISEXTENSIONPRESENT palcIsExtensionPresent
= NULL
;
144 LPALCGETPROCADDRESS palcGetProcAddress
= NULL
;
145 LPALCGETENUMVALUE palcGetEnumValue
= NULL
;
146 LPALCGETSTRING palcGetString
= NULL
;
147 LPALCGETINTEGERV palcGetIntegerv
= NULL
;
148 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice
= NULL
;
149 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice
= NULL
;
150 LPALCCAPTURESTART palcCaptureStart
= NULL
;
151 LPALCCAPTURESTOP palcCaptureStop
= NULL
;
152 LPALCCAPTURESAMPLES palcCaptureSamples
= NULL
;
153 LPALENABLE palEnable
= NULL
;
154 LPALDISABLE palDisable
= NULL
;
155 LPALISENABLED palIsEnabled
= NULL
;
156 LPALGETSTRING palGetString
= NULL
;
157 LPALGETBOOLEANV palGetBooleanv
= NULL
;
158 LPALGETINTEGERV palGetIntegerv
= NULL
;
159 LPALGETFLOATV palGetFloatv
= NULL
;
160 LPALGETDOUBLEV palGetDoublev
= NULL
;
161 LPALGETBOOLEAN palGetBoolean
= NULL
;
162 LPALGETINTEGER palGetInteger
= NULL
;
163 LPALGETFLOAT palGetFloat
= NULL
;
164 LPALGETDOUBLE palGetDouble
= NULL
;
165 LPALGETERROR palGetError
= NULL
;
166 LPALISEXTENSIONPRESENT palIsExtensionPresent
= NULL
;
167 LPALGETPROCADDRESS palGetProcAddress
= NULL
;
168 LPALGETENUMVALUE palGetEnumValue
= NULL
;
169 LPALLISTENERF palListenerf
= NULL
;
170 LPALLISTENER3F palListener3f
= NULL
;
171 LPALLISTENERFV palListenerfv
= NULL
;
172 LPALLISTENERI palListeneri
= NULL
;
173 LPALLISTENER3I palListener3i
= NULL
;
174 LPALLISTENERIV palListeneriv
= NULL
;
175 LPALGETLISTENERF palGetListenerf
= NULL
;
176 LPALGETLISTENER3F palGetListener3f
= NULL
;
177 LPALGETLISTENERFV palGetListenerfv
= NULL
;
178 LPALGETLISTENERI palGetListeneri
= NULL
;
179 LPALGETLISTENER3I palGetListener3i
= NULL
;
180 LPALGETLISTENERIV palGetListeneriv
= NULL
;
181 LPALGENSOURCES palGenSources
= NULL
;
182 LPALDELETESOURCES palDeleteSources
= NULL
;
183 LPALISSOURCE palIsSource
= NULL
;
184 LPALSOURCEF palSourcef
= NULL
;
185 LPALSOURCE3F palSource3f
= NULL
;
186 LPALSOURCEFV palSourcefv
= NULL
;
187 LPALSOURCEI palSourcei
= NULL
;
188 LPALSOURCE3I palSource3i
= NULL
;
189 LPALSOURCEIV palSourceiv
= NULL
;
190 LPALGETSOURCEF palGetSourcef
= NULL
;
191 LPALGETSOURCE3F palGetSource3f
= NULL
;
192 LPALGETSOURCEFV palGetSourcefv
= NULL
;
193 LPALGETSOURCEI palGetSourcei
= NULL
;
194 LPALGETSOURCE3I palGetSource3i
= NULL
;
195 LPALGETSOURCEIV palGetSourceiv
= NULL
;
196 LPALSOURCEPLAYV palSourcePlayv
= NULL
;
197 LPALSOURCESTOPV palSourceStopv
= NULL
;
198 LPALSOURCEREWINDV palSourceRewindv
= NULL
;
199 LPALSOURCEPAUSEV palSourcePausev
= NULL
;
200 LPALSOURCEPLAY palSourcePlay
= NULL
;
201 LPALSOURCESTOP palSourceStop
= NULL
;
202 LPALSOURCEREWIND palSourceRewind
= NULL
;
203 LPALSOURCEPAUSE palSourcePause
= NULL
;
204 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers
= NULL
;
205 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers
= NULL
;
206 LPALGENBUFFERS palGenBuffers
= NULL
;
207 LPALDELETEBUFFERS palDeleteBuffers
= NULL
;
208 LPALISBUFFER palIsBuffer
= NULL
;
209 LPALBUFFERF palBufferf
= NULL
;
210 LPALBUFFER3F palBuffer3f
= NULL
;
211 LPALBUFFERFV palBufferfv
= NULL
;
212 LPALBUFFERI palBufferi
= NULL
;
213 LPALBUFFER3I palBuffer3i
= NULL
;
214 LPALBUFFERIV palBufferiv
= NULL
;
215 LPALGETBUFFERF palGetBufferf
= NULL
;
216 LPALGETBUFFER3F palGetBuffer3f
= NULL
;
217 LPALGETBUFFERFV palGetBufferfv
= NULL
;
218 LPALGETBUFFERI palGetBufferi
= NULL
;
219 LPALGETBUFFER3I palGetBuffer3i
= NULL
;
220 LPALGETBUFFERIV palGetBufferiv
= NULL
;
221 LPALBUFFERDATA palBufferData
= NULL
;
222 LPALDOPPLERFACTOR palDopplerFactor
= NULL
;
223 LPALDOPPLERVELOCITY palDopplerVelocity
= NULL
;
224 LPALDISTANCEMODEL palDistanceModel
= NULL
;
225 LPALSPEEDOFSOUND palSpeedOfSound
= NULL
;
228 LPALCMAKECONTEXTCURRENT set_context
;
229 LPALCGETCURRENTCONTEXT get_context
;
232 static void load_libopenal(void)
235 const char *str
= getenv("DSOAL_LOGLEVEL");
237 LogLevel
= atoi(str
);
238 #elif defined(SONAME_LIBOPENAL)
242 openal_handle
= wine_dlopen(SONAME_LIBOPENAL
, RTLD_NOW
, error
, sizeof(error
));
244 ERR("Couldn't load " SONAME_LIBOPENAL
": %s\n", error
);
245 #define LOAD_FUNCPTR(f) \
246 if((p##f = wine_dlsym(openal_handle, #f, NULL, 0)) == NULL) { \
247 ERR("Couldn't lookup %s in " SONAME_LIBOPENAL "\n", #f); \
251 LOAD_FUNCPTR(alcCreateContext
);
252 LOAD_FUNCPTR(alcMakeContextCurrent
);
253 LOAD_FUNCPTR(alcProcessContext
);
254 LOAD_FUNCPTR(alcSuspendContext
);
255 LOAD_FUNCPTR(alcDestroyContext
);
256 LOAD_FUNCPTR(alcGetCurrentContext
);
257 LOAD_FUNCPTR(alcGetContextsDevice
);
258 LOAD_FUNCPTR(alcOpenDevice
);
259 LOAD_FUNCPTR(alcCloseDevice
);
260 LOAD_FUNCPTR(alcGetError
);
261 LOAD_FUNCPTR(alcIsExtensionPresent
);
262 LOAD_FUNCPTR(alcGetProcAddress
);
263 LOAD_FUNCPTR(alcGetEnumValue
);
264 LOAD_FUNCPTR(alcGetString
);
265 LOAD_FUNCPTR(alcGetIntegerv
);
266 LOAD_FUNCPTR(alcCaptureOpenDevice
);
267 LOAD_FUNCPTR(alcCaptureCloseDevice
);
268 LOAD_FUNCPTR(alcCaptureStart
);
269 LOAD_FUNCPTR(alcCaptureStop
);
270 LOAD_FUNCPTR(alcCaptureSamples
);
271 LOAD_FUNCPTR(alEnable
);
272 LOAD_FUNCPTR(alDisable
);
273 LOAD_FUNCPTR(alIsEnabled
);
274 LOAD_FUNCPTR(alGetString
);
275 LOAD_FUNCPTR(alGetBooleanv
);
276 LOAD_FUNCPTR(alGetIntegerv
);
277 LOAD_FUNCPTR(alGetFloatv
);
278 LOAD_FUNCPTR(alGetDoublev
);
279 LOAD_FUNCPTR(alGetBoolean
);
280 LOAD_FUNCPTR(alGetInteger
);
281 LOAD_FUNCPTR(alGetFloat
);
282 LOAD_FUNCPTR(alGetDouble
);
283 LOAD_FUNCPTR(alGetError
);
284 LOAD_FUNCPTR(alIsExtensionPresent
);
285 LOAD_FUNCPTR(alGetProcAddress
);
286 LOAD_FUNCPTR(alGetEnumValue
);
287 LOAD_FUNCPTR(alListenerf
);
288 LOAD_FUNCPTR(alListener3f
);
289 LOAD_FUNCPTR(alListenerfv
);
290 LOAD_FUNCPTR(alListeneri
);
291 LOAD_FUNCPTR(alListener3i
);
292 LOAD_FUNCPTR(alListeneriv
);
293 LOAD_FUNCPTR(alGetListenerf
);
294 LOAD_FUNCPTR(alGetListener3f
);
295 LOAD_FUNCPTR(alGetListenerfv
);
296 LOAD_FUNCPTR(alGetListeneri
);
297 LOAD_FUNCPTR(alGetListener3i
);
298 LOAD_FUNCPTR(alGetListeneriv
);
299 LOAD_FUNCPTR(alGenSources
);
300 LOAD_FUNCPTR(alDeleteSources
);
301 LOAD_FUNCPTR(alIsSource
);
302 LOAD_FUNCPTR(alSourcef
);
303 LOAD_FUNCPTR(alSource3f
);
304 LOAD_FUNCPTR(alSourcefv
);
305 LOAD_FUNCPTR(alSourcei
);
306 LOAD_FUNCPTR(alSource3i
);
307 LOAD_FUNCPTR(alSourceiv
);
308 LOAD_FUNCPTR(alGetSourcef
);
309 LOAD_FUNCPTR(alGetSource3f
);
310 LOAD_FUNCPTR(alGetSourcefv
);
311 LOAD_FUNCPTR(alGetSourcei
);
312 LOAD_FUNCPTR(alGetSource3i
);
313 LOAD_FUNCPTR(alGetSourceiv
);
314 LOAD_FUNCPTR(alSourcePlayv
);
315 LOAD_FUNCPTR(alSourceStopv
);
316 LOAD_FUNCPTR(alSourceRewindv
);
317 LOAD_FUNCPTR(alSourcePausev
);
318 LOAD_FUNCPTR(alSourcePlay
);
319 LOAD_FUNCPTR(alSourceStop
);
320 LOAD_FUNCPTR(alSourceRewind
);
321 LOAD_FUNCPTR(alSourcePause
);
322 LOAD_FUNCPTR(alSourceQueueBuffers
);
323 LOAD_FUNCPTR(alSourceUnqueueBuffers
);
324 LOAD_FUNCPTR(alGenBuffers
);
325 LOAD_FUNCPTR(alDeleteBuffers
);
326 LOAD_FUNCPTR(alIsBuffer
);
327 LOAD_FUNCPTR(alBufferf
);
328 LOAD_FUNCPTR(alBuffer3f
);
329 LOAD_FUNCPTR(alBufferfv
);
330 LOAD_FUNCPTR(alBufferi
);
331 LOAD_FUNCPTR(alBuffer3i
);
332 LOAD_FUNCPTR(alBufferiv
);
333 LOAD_FUNCPTR(alGetBufferf
);
334 LOAD_FUNCPTR(alGetBuffer3f
);
335 LOAD_FUNCPTR(alGetBufferfv
);
336 LOAD_FUNCPTR(alGetBufferi
);
337 LOAD_FUNCPTR(alGetBuffer3i
);
338 LOAD_FUNCPTR(alGetBufferiv
);
339 LOAD_FUNCPTR(alBufferData
);
340 LOAD_FUNCPTR(alDopplerFactor
);
341 LOAD_FUNCPTR(alDopplerVelocity
);
342 LOAD_FUNCPTR(alDistanceModel
);
343 LOAD_FUNCPTR(alSpeedOfSound
);
347 WARN("Unloading openal\n");
348 if (openal_handle
!= RTLD_DEFAULT
)
349 wine_dlclose(openal_handle
, NULL
, 0);
350 openal_handle
= NULL
;
357 local_contexts
= alcIsExtensionPresent(NULL
, "ALC_EXT_thread_local_context");
360 set_context
= alcGetProcAddress(NULL
, "alcSetThreadContext");
361 get_context
= alcGetProcAddress(NULL
, "alcGetThreadContext");
362 if(!set_context
|| !get_context
)
364 ERR("TLS advertised but functions not found, disabling thread local context\n");
370 set_context
= alcMakeContextCurrent
;
371 get_context
= alcGetCurrentContext
;
376 const ALCchar
*DSOUND_getdevicestrings(void)
378 const ALCchar
*str
= NULL
;
381 multiple
= alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT");
383 str
= alcGetString(NULL
, ALC_ALL_DEVICES_SPECIFIER
);
385 str
= alcGetString(NULL
, ALC_DEVICE_SPECIFIER
);
389 const ALCchar
*DSOUND_getcapturedevicestrings(void)
391 const ALCchar
*str
= NULL
;
392 str
= alcGetString(NULL
, ALC_CAPTURE_DEVICE_SPECIFIER
);
396 /***************************************************************************
397 * GetDeviceID [DSOUND.9]
399 * Retrieves unique identifier of default device specified
402 * pGuidSrc [I] Address of device GUID.
403 * pGuidDest [O] Address to receive unique device GUID.
407 * Failure: DSERR_INVALIDPARAM
410 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
411 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
412 * DSDEVID_DefaultVoiceCapture.
413 * Returns pGuidSrc if pGuidSrc is a valid device or the device
414 * GUID for the specified constants.
416 HRESULT WINAPI
GetDeviceID(LPCGUID pGuidSrc
, LPGUID pGuidDest
)
418 TRACE("(%s,%p)\n", debugstr_guid(pGuidSrc
),pGuidDest
);
420 if ( pGuidSrc
== NULL
) {
421 WARN("invalid parameter: pGuidSrc == NULL\n");
422 return DSERR_INVALIDPARAM
;
425 if ( pGuidDest
== NULL
) {
426 WARN("invalid parameter: pGuidDest == NULL\n");
427 return DSERR_INVALIDPARAM
;
430 if ( IsEqualGUID( &DSDEVID_DefaultPlayback
, pGuidSrc
) ||
431 IsEqualGUID( &DSDEVID_DefaultVoicePlayback
, pGuidSrc
) ) {
432 *pGuidDest
= DSOUND_renderer_guid
;
433 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
437 if ( IsEqualGUID( &DSDEVID_DefaultCapture
, pGuidSrc
) ||
438 IsEqualGUID( &DSDEVID_DefaultVoiceCapture
, pGuidSrc
) ) {
439 *pGuidDest
= DSOUND_capture_guid
;
440 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
444 *pGuidDest
= *pGuidSrc
;
445 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
452 LPDSENUMCALLBACKW callW
;
456 static BOOL CALLBACK
w_to_a_callback(LPGUID guid
, LPCSTR descA
, LPCSTR modA
, LPVOID data
)
458 struct morecontext
*context
= data
;
459 WCHAR descW
[MAXPNAMELEN
], modW
[MAXPNAMELEN
];
461 MultiByteToWideChar(CP_ACP
, 0, descA
, -1, descW
, sizeof(descW
)/sizeof(descW
[0]));
462 MultiByteToWideChar(CP_ACP
, 0, modA
, -1, modW
, sizeof(modW
)/sizeof(modW
[0]));
464 return context
->callW(guid
, descW
, modW
, context
->data
);
467 /***************************************************************************
468 * DirectSoundEnumerateA [DSOUND.2]
470 * Enumerate all DirectSound drivers installed in the system
473 * lpDSEnumCallback [I] Address of callback function.
474 * lpContext [I] Address of user defined context passed to callback function.
478 * Failure: DSERR_INVALIDPARAM
480 HRESULT WINAPI
DirectSoundEnumerateA(
481 LPDSENUMCALLBACKA lpDSEnumCallback
,
484 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
485 lpDSEnumCallback
, lpContext
);
487 if (lpDSEnumCallback
== NULL
) {
488 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
489 return DSERR_INVALIDPARAM
;
491 else if (openal_loaded
)
493 const ALCchar
*devstr
;
496 EnterCriticalSection(&openal_crst
);
497 devstr
= DSOUND_getdevicestrings();
498 if(!devstr
|| !*devstr
)
501 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
502 "Primary Sound Driver","",lpContext
);
503 if(lpDSEnumCallback(NULL
, "Primary Sound Driver", "", lpContext
) == FALSE
)
506 guid
= DSOUND_renderer_guid
;
508 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
509 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
510 if(lpDSEnumCallback(&guid
, devstr
, "wineal.drv", lpContext
) == FALSE
)
513 devstr
+= strlen(devstr
)+1;
516 LeaveCriticalSection(&openal_crst
);
520 ERR("Attempting to enumerate sound cards without OpenAL support\n");
521 ERR("Please recompile wine with OpenAL for sound to work\n");
526 /***************************************************************************
527 * DirectSoundEnumerateW [DSOUND.3]
529 * Enumerate all DirectSound drivers installed in the system
532 * lpDSEnumCallback [I] Address of callback function.
533 * lpContext [I] Address of user defined context passed to callback function.
537 * Failure: DSERR_INVALIDPARAM
539 HRESULT WINAPI
DirectSoundEnumerateW(
540 LPDSENUMCALLBACKW lpDSEnumCallback
,
543 struct morecontext context
;
545 if(lpDSEnumCallback
== NULL
) {
546 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
547 return DSERR_INVALIDPARAM
;
550 context
.callW
= lpDSEnumCallback
;
551 context
.data
= lpContext
;
553 return DirectSoundEnumerateA(w_to_a_callback
, &context
);
556 /***************************************************************************
557 * DirectSoundCaptureEnumerateA [DSOUND.7]
559 * Enumerate all DirectSound drivers installed in the system.
562 * lpDSEnumCallback [I] Address of callback function.
563 * lpContext [I] Address of user defined context passed to callback function.
567 * Failure: DSERR_INVALIDPARAM
569 HRESULT WINAPI
DirectSoundCaptureEnumerateA(
570 LPDSENUMCALLBACKA lpDSEnumCallback
,
573 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
575 if (lpDSEnumCallback
== NULL
) {
576 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
577 return DSERR_INVALIDPARAM
;
579 else if (openal_loaded
)
581 const ALCchar
*devstr
;
584 EnterCriticalSection(&openal_crst
);
585 devstr
= DSOUND_getcapturedevicestrings();
586 if(!devstr
|| !*devstr
)
589 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
590 "Primary Sound Capture Driver","",lpContext
);
591 if(lpDSEnumCallback(NULL
, "Primary Sound Driver", "", lpContext
) == FALSE
)
594 guid
= DSOUND_capture_guid
;
596 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
597 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
598 if(lpDSEnumCallback(&guid
, devstr
, "wineal.drv", lpContext
) == FALSE
)
601 devstr
+= strlen(devstr
)+1;
604 LeaveCriticalSection(&openal_crst
);
608 ERR("Attempting to enumerate sound cards without OpenAL support\n");
609 ERR("Please recompile wine with OpenAL for sound to work\n");
614 /***************************************************************************
615 * DirectSoundCaptureEnumerateW [DSOUND.8]
617 * Enumerate all DirectSound drivers installed in the system.
620 * lpDSEnumCallback [I] Address of callback function.
621 * lpContext [I] Address of user defined context passed to callback function.
625 * Failure: DSERR_INVALIDPARAM
628 DirectSoundCaptureEnumerateW(
629 LPDSENUMCALLBACKW lpDSEnumCallback
,
632 struct morecontext context
;
634 if (lpDSEnumCallback
== NULL
) {
635 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
636 return DSERR_INVALIDPARAM
;
639 context
.callW
= lpDSEnumCallback
;
640 context
.data
= lpContext
;
642 return DirectSoundCaptureEnumerateA(w_to_a_callback
, &context
);
645 /*******************************************************************************
646 * DirectSoundCreate (DSOUND.1)
648 * Creates and initializes a DirectSound interface.
651 * lpcGUID [I] Address of the GUID that identifies the sound device.
652 * ppDS [O] Address of a variable to receive the interface pointer.
653 * pUnkOuter [I] Must be NULL.
657 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
658 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
661 DirectSoundCreate(LPCGUID lpcGUID
, IDirectSound
**ppDS
, IUnknown
*pUnkOuter
)
666 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDS
, pUnkOuter
);
669 WARN("invalid parameter: ppDS == NULL\n");
670 return DSERR_INVALIDPARAM
;
674 if (pUnkOuter
!= NULL
) {
675 WARN("invalid parameter: pUnkOuter != NULL\n");
676 return DSERR_INVALIDPARAM
;
679 hr
= DSOUND_Create(&IID_IDirectSound
, &pDS
);
683 hr
= IDirectSound_Initialize(*ppDS
, lpcGUID
);
686 IDirectSound_Release(*ppDS
);
694 /*******************************************************************************
695 * DirectSoundCreate8 (DSOUND.11)
697 * Creates and initializes a DirectSound8 interface.
700 * lpcGUID [I] Address of the GUID that identifies the sound device.
701 * ppDS [O] Address of a variable to receive the interface pointer.
702 * pUnkOuter [I] Must be NULL.
706 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
707 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
710 DirectSoundCreate8(LPCGUID lpcGUID
, IDirectSound8
**ppDS
, IUnknown
*pUnkOuter
)
715 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDS
, pUnkOuter
);
718 WARN("invalid parameter: ppDS == NULL\n");
719 return DSERR_INVALIDPARAM
;
723 if (pUnkOuter
!= NULL
) {
724 WARN("invalid parameter: pUnkOuter != NULL\n");
725 return DSERR_INVALIDPARAM
;
728 hr
= DSOUND_Create8(&IID_IDirectSound8
, &pDS
);
732 hr
= IDirectSound8_Initialize(*ppDS
, lpcGUID
);
735 IDirectSound8_Release(*ppDS
);
743 /***************************************************************************
744 * DirectSoundCaptureCreate [DSOUND.6]
746 * Create and initialize a DirectSoundCapture interface.
749 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
750 * lplpDSC [O] Address of a variable to receive the interface pointer.
751 * pUnkOuter [I] Must be NULL.
755 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
759 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
760 * or NULL for the default device or DSDEVID_DefaultCapture or
761 * DSDEVID_DefaultVoiceCapture.
763 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
766 DirectSoundCaptureCreate(LPCGUID lpcGUID
, IDirectSoundCapture
**ppDSC
, IUnknown
*pUnkOuter
)
771 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC
, pUnkOuter
);
775 WARN("invalid parameter: ppDSC == NULL\n");
776 return DSERR_INVALIDPARAM
;
782 WARN("invalid parameter: pUnkOuter != NULL\n");
783 return DSERR_NOAGGREGATION
;
786 hr
= DSOUND_CaptureCreate(&IID_IDirectSoundCapture
, &pDSC
);
790 hr
= IDirectSoundCapture_Initialize(*ppDSC
, lpcGUID
);
793 IDirectSoundCapture_Release(*ppDSC
);
801 /***************************************************************************
802 * DirectSoundCaptureCreate8 [DSOUND.12]
804 * Create and initialize a DirectSoundCapture interface.
807 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
808 * lplpDSC [O] Address of a variable to receive the interface pointer.
809 * pUnkOuter [I] Must be NULL.
813 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
817 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
818 * or NULL for the default device or DSDEVID_DefaultCapture or
819 * DSDEVID_DefaultVoiceCapture.
821 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
824 DirectSoundCaptureCreate8(LPCGUID lpcGUID
, IDirectSoundCapture8
**ppDSC8
, IUnknown
*pUnkOuter
)
829 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC8
, pUnkOuter
);
833 WARN("invalid parameter: ppDSC8 == NULL\n");
834 return DSERR_INVALIDPARAM
;
840 WARN("invalid parameter: pUnkOuter != NULL\n");
841 return DSERR_NOAGGREGATION
;
844 hr
= DSOUND_CaptureCreate(&IID_IDirectSoundCapture8
, &pDSC8
);
848 hr
= IDirectSoundCapture_Initialize(*ppDSC8
, lpcGUID
);
851 IDirectSoundCapture_Release(*ppDSC8
);
859 /*******************************************************************************
860 * DirectSound ClassFactory
863 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
866 IClassFactory IClassFactory_iface
;
869 FnCreateInstance pfnCreateInstance
;
872 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
874 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
877 static HRESULT WINAPI
DSCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
879 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
880 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
883 if (IsEqualIID(riid
, &IID_IUnknown
) ||
884 IsEqualIID(riid
, &IID_IClassFactory
))
887 IUnknown_AddRef(iface
);
891 return E_NOINTERFACE
;
894 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
896 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
897 ULONG ref
= InterlockedIncrement(&(This
->ref
));
898 TRACE("(%p) ref was %"LONGFMT
"u\n", This
, ref
- 1);
902 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
904 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
905 ULONG ref
= InterlockedDecrement(&(This
->ref
));
906 TRACE("(%p) ref was %"LONGFMT
"u\n", This
, ref
+ 1);
907 /* static class, won't be freed */
911 static HRESULT WINAPI
DSCF_CreateInstance(
912 LPCLASSFACTORY iface
,
917 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
918 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
921 return CLASS_E_NOAGGREGATION
;
924 WARN("invalid parameter\n");
925 return DSERR_INVALIDPARAM
;
928 return This
->pfnCreateInstance(riid
, ppobj
);
931 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
933 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
934 FIXME("(%p, %d) stub!\n", This
, dolock
);
938 static const IClassFactoryVtbl DSCF_Vtbl
= {
946 static IClassFactoryImpl DSOUND_CF
[] = {
947 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound
, DSOUND_Create
},
948 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound8
, DSOUND_Create8
},
949 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture
, DSOUND_CaptureCreate
},
950 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture8
, DSOUND_CaptureCreate
},
951 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundFullDuplex
, DSOUND_FullDuplexCreate
},
952 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundPrivate
, IKsPrivatePropertySetImpl_Create
},
953 { {NULL
}, 0, NULL
, NULL
}
956 /*******************************************************************************
957 * DllGetClassObject [DSOUND.@]
958 * Retrieves class object from a DLL object
961 * Docs say returns STDAPI
964 * rclsid [I] CLSID for the class object
965 * riid [I] Reference to identifier of interface for class object
966 * ppv [O] Address of variable to receive interface pointer for riid
970 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
973 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
976 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
979 WARN("invalid parameter\n");
985 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
986 !IsEqualIID(riid
, &IID_IUnknown
)) {
987 WARN("no interface for %s\n", debugstr_guid(riid
));
988 return E_NOINTERFACE
;
991 while (NULL
!= DSOUND_CF
[i
].rclsid
) {
992 if (IsEqualGUID(rclsid
, DSOUND_CF
[i
].rclsid
)) {
993 DSCF_AddRef(&DSOUND_CF
[i
].IClassFactory_iface
);
994 *ppv
= &DSOUND_CF
[i
];
1000 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
1001 debugstr_guid(riid
), ppv
);
1002 return CLASS_E_CLASSNOTAVAILABLE
;
1006 /*******************************************************************************
1007 * DllCanUnloadNow [DSOUND.4]
1008 * Determines whether the DLL is in use.
1014 HRESULT WINAPI
DllCanUnloadNow(void)
1016 FIXME("(void): stub\n");
1020 /***********************************************************************
1021 * DllMain (DSOUND.init)
1023 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1025 TRACE("(%p, %"LONGFMT
"u, %p)\n", hInstDLL
, fdwReason
, lpvReserved
);
1029 case DLL_PROCESS_ATTACH
:
1030 TRACE("DLL_PROCESS_ATTACH\n");
1031 instance
= hInstDLL
;
1033 DisableThreadLibraryCalls(hInstDLL
);
1034 /* Increase refcount on dsound by 1 */
1035 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
1037 case DLL_PROCESS_DETACH
:
1038 TRACE("DLL_PROCESS_DETACH\n");
1039 #ifdef SONAME_LIBOPENAL
1041 wine_dlclose(openal_handle
, NULL
, 0);
1042 #endif /*SONAME_LIBOPENAL*/
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
);