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
43 #include "dsound_private.h"
45 #ifndef DECLSPEC_EXPORT
47 #define DECLSPEC_EXPORT __declspec(dllexport)
49 #define DECLSPEC_EXPORT
53 DEFINE_GUID(CLSID_DirectSoundPrivate
,0x11ab3ec0,0x25ec,0x11d1,0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca);
58 const GUID DSOUND_renderer_guid
= { 0xbd6dd71a, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
59 const GUID DSOUND_capture_guid
= { 0xbd6dd71b, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
61 const IID DSPROPSETID_EAX20_ListenerProperties
= {
62 0x0306a6a8, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
65 const IID DSPROPSETID_EAX20_BufferProperties
= {
66 0x0306a6a7, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
69 const EAXLISTENERPROPERTIES EnvironmentDefaults
[EAX_ENVIRONMENT_COUNT
] =
71 REVERB_PRESET_GENERIC
,
72 REVERB_PRESET_PADDEDCELL
,
74 REVERB_PRESET_BATHROOM
,
75 REVERB_PRESET_LIVINGROOM
,
76 REVERB_PRESET_STONEROOM
,
77 REVERB_PRESET_AUDITORIUM
,
78 REVERB_PRESET_CONCERTHALL
,
82 REVERB_PRESET_CARPETEDHALLWAY
,
83 REVERB_PRESET_HALLWAY
,
84 REVERB_PRESET_STONECORRIDOR
,
88 REVERB_PRESET_MOUNTAINS
,
91 REVERB_PRESET_PARKINGLOT
,
92 REVERB_PRESET_SEWERPIPE
,
93 REVERB_PRESET_UNDERWATER
,
94 REVERB_PRESET_DRUGGED
,
96 REVERB_PRESET_PSYCHOTIC
99 static CRITICAL_SECTION_DEBUG openal_crst_debug
=
102 { &openal_crst_debug
.ProcessLocksList
,
103 &openal_crst_debug
.ProcessLocksList
},
104 0, 0, { (DWORD_PTR
)(__FILE__
": openal_crst_debug") }
106 CRITICAL_SECTION openal_crst
= { &openal_crst_debug
, -1, 0, 0, 0, 0 };
108 int openal_loaded
= 0;
109 static HANDLE openal_handle
= NULL
;
110 LPALCCREATECONTEXT palcCreateContext
= NULL
;
111 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent
= NULL
;
112 LPALCPROCESSCONTEXT palcProcessContext
= NULL
;
113 LPALCSUSPENDCONTEXT palcSuspendContext
= NULL
;
114 LPALCDESTROYCONTEXT palcDestroyContext
= NULL
;
115 LPALCGETCURRENTCONTEXT palcGetCurrentContext
= NULL
;
116 LPALCGETCONTEXTSDEVICE palcGetContextsDevice
= NULL
;
117 LPALCOPENDEVICE palcOpenDevice
= NULL
;
118 LPALCCLOSEDEVICE palcCloseDevice
= NULL
;
119 LPALCGETERROR palcGetError
= NULL
;
120 LPALCISEXTENSIONPRESENT palcIsExtensionPresent
= NULL
;
121 LPALCGETPROCADDRESS palcGetProcAddress
= NULL
;
122 LPALCGETENUMVALUE palcGetEnumValue
= NULL
;
123 LPALCGETSTRING palcGetString
= NULL
;
124 LPALCGETINTEGERV palcGetIntegerv
= NULL
;
125 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice
= NULL
;
126 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice
= NULL
;
127 LPALCCAPTURESTART palcCaptureStart
= NULL
;
128 LPALCCAPTURESTOP palcCaptureStop
= NULL
;
129 LPALCCAPTURESAMPLES palcCaptureSamples
= NULL
;
130 LPALENABLE palEnable
= NULL
;
131 LPALDISABLE palDisable
= NULL
;
132 LPALISENABLED palIsEnabled
= NULL
;
133 LPALGETSTRING palGetString
= NULL
;
134 LPALGETBOOLEANV palGetBooleanv
= NULL
;
135 LPALGETINTEGERV palGetIntegerv
= NULL
;
136 LPALGETFLOATV palGetFloatv
= NULL
;
137 LPALGETDOUBLEV palGetDoublev
= NULL
;
138 LPALGETBOOLEAN palGetBoolean
= NULL
;
139 LPALGETINTEGER palGetInteger
= NULL
;
140 LPALGETFLOAT palGetFloat
= NULL
;
141 LPALGETDOUBLE palGetDouble
= NULL
;
142 LPALGETERROR palGetError
= NULL
;
143 LPALISEXTENSIONPRESENT palIsExtensionPresent
= NULL
;
144 LPALGETPROCADDRESS palGetProcAddress
= NULL
;
145 LPALGETENUMVALUE palGetEnumValue
= NULL
;
146 LPALLISTENERF palListenerf
= NULL
;
147 LPALLISTENER3F palListener3f
= NULL
;
148 LPALLISTENERFV palListenerfv
= NULL
;
149 LPALLISTENERI palListeneri
= NULL
;
150 LPALLISTENER3I palListener3i
= NULL
;
151 LPALLISTENERIV palListeneriv
= NULL
;
152 LPALGETLISTENERF palGetListenerf
= NULL
;
153 LPALGETLISTENER3F palGetListener3f
= NULL
;
154 LPALGETLISTENERFV palGetListenerfv
= NULL
;
155 LPALGETLISTENERI palGetListeneri
= NULL
;
156 LPALGETLISTENER3I palGetListener3i
= NULL
;
157 LPALGETLISTENERIV palGetListeneriv
= NULL
;
158 LPALGENSOURCES palGenSources
= NULL
;
159 LPALDELETESOURCES palDeleteSources
= NULL
;
160 LPALISSOURCE palIsSource
= NULL
;
161 LPALSOURCEF palSourcef
= NULL
;
162 LPALSOURCE3F palSource3f
= NULL
;
163 LPALSOURCEFV palSourcefv
= NULL
;
164 LPALSOURCEI palSourcei
= NULL
;
165 LPALSOURCE3I palSource3i
= NULL
;
166 LPALSOURCEIV palSourceiv
= NULL
;
167 LPALGETSOURCEF palGetSourcef
= NULL
;
168 LPALGETSOURCE3F palGetSource3f
= NULL
;
169 LPALGETSOURCEFV palGetSourcefv
= NULL
;
170 LPALGETSOURCEI palGetSourcei
= NULL
;
171 LPALGETSOURCE3I palGetSource3i
= NULL
;
172 LPALGETSOURCEIV palGetSourceiv
= NULL
;
173 LPALSOURCEPLAYV palSourcePlayv
= NULL
;
174 LPALSOURCESTOPV palSourceStopv
= NULL
;
175 LPALSOURCEREWINDV palSourceRewindv
= NULL
;
176 LPALSOURCEPAUSEV palSourcePausev
= NULL
;
177 LPALSOURCEPLAY palSourcePlay
= NULL
;
178 LPALSOURCESTOP palSourceStop
= NULL
;
179 LPALSOURCEREWIND palSourceRewind
= NULL
;
180 LPALSOURCEPAUSE palSourcePause
= NULL
;
181 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers
= NULL
;
182 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers
= NULL
;
183 LPALGENBUFFERS palGenBuffers
= NULL
;
184 LPALDELETEBUFFERS palDeleteBuffers
= NULL
;
185 LPALISBUFFER palIsBuffer
= NULL
;
186 LPALBUFFERF palBufferf
= NULL
;
187 LPALBUFFER3F palBuffer3f
= NULL
;
188 LPALBUFFERFV palBufferfv
= NULL
;
189 LPALBUFFERI palBufferi
= NULL
;
190 LPALBUFFER3I palBuffer3i
= NULL
;
191 LPALBUFFERIV palBufferiv
= NULL
;
192 LPALGETBUFFERF palGetBufferf
= NULL
;
193 LPALGETBUFFER3F palGetBuffer3f
= NULL
;
194 LPALGETBUFFERFV palGetBufferfv
= NULL
;
195 LPALGETBUFFERI palGetBufferi
= NULL
;
196 LPALGETBUFFER3I palGetBuffer3i
= NULL
;
197 LPALGETBUFFERIV palGetBufferiv
= NULL
;
198 LPALBUFFERDATA palBufferData
= NULL
;
199 LPALDOPPLERFACTOR palDopplerFactor
= NULL
;
200 LPALDOPPLERVELOCITY palDopplerVelocity
= NULL
;
201 LPALDISTANCEMODEL palDistanceModel
= NULL
;
202 LPALSPEEDOFSOUND palSpeedOfSound
= NULL
;
204 LPALCMAKECONTEXTCURRENT set_context
;
205 LPALCGETCURRENTCONTEXT get_context
;
208 static void EnterALSectionTLS(ALCcontext
*ctx
);
209 static void LeaveALSectionTLS(void);
210 static void EnterALSectionGlob(ALCcontext
*ctx
);
211 static void LeaveALSectionGlob(void);
214 void (*EnterALSection
)(ALCcontext
*ctx
) = EnterALSectionGlob
;
215 void (*LeaveALSection
)(void) = LeaveALSectionGlob
;
218 static BOOL
load_libopenal(void)
220 const char libname
[] = "dsoal-aldrv.dll";
224 str
= getenv("DSOAL_LOGLEVEL");
226 LogLevel
= atoi(str
);
228 openal_handle
= LoadLibraryA(libname
);
231 ERR("Couldn't load %s: %lu\n", libname
, GetLastError());
235 #define LOAD_FUNCPTR(f) do { \
236 if((*((void**)&p##f) = GetProcAddress(openal_handle, #f)) == NULL) \
238 ERR("Couldn't lookup %s in %s\n", #f, libname); \
243 LOAD_FUNCPTR(alcCreateContext
);
244 LOAD_FUNCPTR(alcMakeContextCurrent
);
245 LOAD_FUNCPTR(alcProcessContext
);
246 LOAD_FUNCPTR(alcSuspendContext
);
247 LOAD_FUNCPTR(alcDestroyContext
);
248 LOAD_FUNCPTR(alcGetCurrentContext
);
249 LOAD_FUNCPTR(alcGetContextsDevice
);
250 LOAD_FUNCPTR(alcOpenDevice
);
251 LOAD_FUNCPTR(alcCloseDevice
);
252 LOAD_FUNCPTR(alcGetError
);
253 LOAD_FUNCPTR(alcIsExtensionPresent
);
254 LOAD_FUNCPTR(alcGetProcAddress
);
255 LOAD_FUNCPTR(alcGetEnumValue
);
256 LOAD_FUNCPTR(alcGetString
);
257 LOAD_FUNCPTR(alcGetIntegerv
);
258 LOAD_FUNCPTR(alcCaptureOpenDevice
);
259 LOAD_FUNCPTR(alcCaptureCloseDevice
);
260 LOAD_FUNCPTR(alcCaptureStart
);
261 LOAD_FUNCPTR(alcCaptureStop
);
262 LOAD_FUNCPTR(alcCaptureSamples
);
263 LOAD_FUNCPTR(alEnable
);
264 LOAD_FUNCPTR(alDisable
);
265 LOAD_FUNCPTR(alIsEnabled
);
266 LOAD_FUNCPTR(alGetString
);
267 LOAD_FUNCPTR(alGetBooleanv
);
268 LOAD_FUNCPTR(alGetIntegerv
);
269 LOAD_FUNCPTR(alGetFloatv
);
270 LOAD_FUNCPTR(alGetDoublev
);
271 LOAD_FUNCPTR(alGetBoolean
);
272 LOAD_FUNCPTR(alGetInteger
);
273 LOAD_FUNCPTR(alGetFloat
);
274 LOAD_FUNCPTR(alGetDouble
);
275 LOAD_FUNCPTR(alGetError
);
276 LOAD_FUNCPTR(alIsExtensionPresent
);
277 LOAD_FUNCPTR(alGetProcAddress
);
278 LOAD_FUNCPTR(alGetEnumValue
);
279 LOAD_FUNCPTR(alListenerf
);
280 LOAD_FUNCPTR(alListener3f
);
281 LOAD_FUNCPTR(alListenerfv
);
282 LOAD_FUNCPTR(alListeneri
);
283 LOAD_FUNCPTR(alListener3i
);
284 LOAD_FUNCPTR(alListeneriv
);
285 LOAD_FUNCPTR(alGetListenerf
);
286 LOAD_FUNCPTR(alGetListener3f
);
287 LOAD_FUNCPTR(alGetListenerfv
);
288 LOAD_FUNCPTR(alGetListeneri
);
289 LOAD_FUNCPTR(alGetListener3i
);
290 LOAD_FUNCPTR(alGetListeneriv
);
291 LOAD_FUNCPTR(alGenSources
);
292 LOAD_FUNCPTR(alDeleteSources
);
293 LOAD_FUNCPTR(alIsSource
);
294 LOAD_FUNCPTR(alSourcef
);
295 LOAD_FUNCPTR(alSource3f
);
296 LOAD_FUNCPTR(alSourcefv
);
297 LOAD_FUNCPTR(alSourcei
);
298 LOAD_FUNCPTR(alSource3i
);
299 LOAD_FUNCPTR(alSourceiv
);
300 LOAD_FUNCPTR(alGetSourcef
);
301 LOAD_FUNCPTR(alGetSource3f
);
302 LOAD_FUNCPTR(alGetSourcefv
);
303 LOAD_FUNCPTR(alGetSourcei
);
304 LOAD_FUNCPTR(alGetSource3i
);
305 LOAD_FUNCPTR(alGetSourceiv
);
306 LOAD_FUNCPTR(alSourcePlayv
);
307 LOAD_FUNCPTR(alSourceStopv
);
308 LOAD_FUNCPTR(alSourceRewindv
);
309 LOAD_FUNCPTR(alSourcePausev
);
310 LOAD_FUNCPTR(alSourcePlay
);
311 LOAD_FUNCPTR(alSourceStop
);
312 LOAD_FUNCPTR(alSourceRewind
);
313 LOAD_FUNCPTR(alSourcePause
);
314 LOAD_FUNCPTR(alSourceQueueBuffers
);
315 LOAD_FUNCPTR(alSourceUnqueueBuffers
);
316 LOAD_FUNCPTR(alGenBuffers
);
317 LOAD_FUNCPTR(alDeleteBuffers
);
318 LOAD_FUNCPTR(alIsBuffer
);
319 LOAD_FUNCPTR(alBufferf
);
320 LOAD_FUNCPTR(alBuffer3f
);
321 LOAD_FUNCPTR(alBufferfv
);
322 LOAD_FUNCPTR(alBufferi
);
323 LOAD_FUNCPTR(alBuffer3i
);
324 LOAD_FUNCPTR(alBufferiv
);
325 LOAD_FUNCPTR(alGetBufferf
);
326 LOAD_FUNCPTR(alGetBuffer3f
);
327 LOAD_FUNCPTR(alGetBufferfv
);
328 LOAD_FUNCPTR(alGetBufferi
);
329 LOAD_FUNCPTR(alGetBuffer3i
);
330 LOAD_FUNCPTR(alGetBufferiv
);
331 LOAD_FUNCPTR(alBufferData
);
332 LOAD_FUNCPTR(alDopplerFactor
);
333 LOAD_FUNCPTR(alDopplerVelocity
);
334 LOAD_FUNCPTR(alDistanceModel
);
335 LOAD_FUNCPTR(alSpeedOfSound
);
339 WARN("Unloading %s\n", libname
);
340 if (openal_handle
!= NULL
)
341 FreeLibrary(openal_handle
);
342 openal_handle
= NULL
;
347 TRACE("Loaded %s\n", libname
);
349 local_contexts
= alcIsExtensionPresent(NULL
, "ALC_EXT_thread_local_context");
352 TRACE("Found ALC_EXT_thread_local_context\n");
354 set_context
= alcGetProcAddress(NULL
, "alcSetThreadContext");
355 get_context
= alcGetProcAddress(NULL
, "alcGetThreadContext");
356 if(!set_context
|| !get_context
)
358 ERR("TLS advertised but functions not found, disabling thread local contexts\n");
364 set_context
= alcMakeContextCurrent
;
365 get_context
= alcGetCurrentContext
;
369 EnterALSection
= EnterALSectionTLS
;
370 LeaveALSection
= LeaveALSectionTLS
;
377 static void EnterALSectionTLS(ALCcontext
*ctx
)
379 if(LIKELY(ctx
== TlsGetValue(TlsThreadPtr
)))
382 if(LIKELY(set_context(ctx
) != ALC_FALSE
))
383 TlsSetValue(TlsThreadPtr
, ctx
);
386 ERR("Couldn't set current context!!\n");
387 checkALCError(alcGetContextsDevice(ctx
));
390 static void LeaveALSectionTLS(void)
394 static void EnterALSectionGlob(ALCcontext
*ctx
)
396 EnterCriticalSection(&openal_crst
);
397 if(UNLIKELY(alcMakeContextCurrent(ctx
) == ALC_FALSE
))
399 ERR("Couldn't set current context!!\n");
400 checkALCError(alcGetContextsDevice(ctx
));
403 static void LeaveALSectionGlob(void)
405 LeaveCriticalSection(&openal_crst
);
409 const ALCchar
*DSOUND_getdevicestrings(void)
411 if(alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT"))
412 return alcGetString(NULL
, ALC_ALL_DEVICES_SPECIFIER
);
413 return alcGetString(NULL
, ALC_DEVICE_SPECIFIER
);
416 const ALCchar
*DSOUND_getcapturedevicestrings(void)
418 return alcGetString(NULL
, ALC_CAPTURE_DEVICE_SPECIFIER
);
421 /***************************************************************************
422 * GetDeviceID [DSOUND.9]
424 * Retrieves unique identifier of default device specified
427 * pGuidSrc [I] Address of device GUID.
428 * pGuidDest [O] Address to receive unique device GUID.
432 * Failure: DSERR_INVALIDPARAM
435 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
436 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
437 * DSDEVID_DefaultVoiceCapture.
438 * Returns pGuidSrc if pGuidSrc is a valid device or the device
439 * GUID for the specified constants.
441 DECLSPEC_EXPORT HRESULT WINAPI
GetDeviceID(LPCGUID pGuidSrc
, LPGUID pGuidDest
)
443 TRACE("(%s, %p)\n", debugstr_guid(pGuidSrc
), pGuidDest
);
447 WARN("invalid parameter: pGuidSrc == NULL\n");
448 return DSERR_INVALIDPARAM
;
451 if(pGuidDest
== NULL
)
453 WARN("invalid parameter: pGuidDest == NULL\n");
454 return DSERR_INVALIDPARAM
;
457 if(IsEqualGUID(&DSDEVID_DefaultPlayback
, pGuidSrc
) ||
458 IsEqualGUID(&DSDEVID_DefaultVoicePlayback
, pGuidSrc
))
459 *pGuidDest
= DSOUND_renderer_guid
;
460 else if(IsEqualGUID(&DSDEVID_DefaultCapture
, pGuidSrc
) ||
461 IsEqualGUID(&DSDEVID_DefaultVoiceCapture
, pGuidSrc
))
462 *pGuidDest
= DSOUND_capture_guid
;
464 *pGuidDest
= *pGuidSrc
;
466 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
472 LPDSENUMCALLBACKA callA
;
479 static BOOL CALLBACK
w2a_callback(LPGUID guid
, LPCWSTR descW
, LPCWSTR modW
, LPVOID data
)
481 struct ConvAcontext
*context
= data
;
485 desclen
= WideCharToMultiByte(CP_ACP
, 0, descW
, -1, NULL
, 0, NULL
, NULL
);
486 modlen
= WideCharToMultiByte(CP_ACP
, 0, modW
, -1, NULL
, 0, NULL
, NULL
);
488 if(desclen
+modlen
> context
->strlen
)
490 CHAR
*newstr
= realloc(context
->str
, desclen
+modlen
+2);
491 if(!newstr
) return FALSE
;
493 context
->str
= newstr
;
494 context
->strlen
= desclen
+modlen
;
497 descA
= context
->str
;
498 modA
= context
->str
+ desclen
+1;
500 WideCharToMultiByte(CP_ACP
, 0, descW
, -1, descA
, desclen
, NULL
, NULL
);
502 WideCharToMultiByte(CP_ACP
, 0, modW
, -1, modA
, modlen
, NULL
, NULL
);
505 return context
->callA(guid
, descA
, modA
, context
->data
);
508 /***************************************************************************
509 * DirectSoundEnumerateA [DSOUND.2]
511 * Enumerate all DirectSound drivers installed in the system
514 * lpDSEnumCallback [I] Address of callback function.
515 * lpContext [I] Address of user defined context passed to callback function.
519 * Failure: DSERR_INVALIDPARAM
521 DECLSPEC_EXPORT HRESULT WINAPI
DirectSoundEnumerateA(
522 LPDSENUMCALLBACKA lpDSEnumCallback
,
525 struct ConvAcontext context
;
528 TRACE("lpDSEnumCallback = %p, lpContext = %p\n", lpDSEnumCallback
, lpContext
);
530 if(lpDSEnumCallback
== NULL
) {
531 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
532 return DSERR_INVALIDPARAM
;
535 context
.callA
= lpDSEnumCallback
;
536 context
.data
= lpContext
;
540 ret
= DirectSoundEnumerateW(w2a_callback
, &context
);
546 /***************************************************************************
547 * DirectSoundEnumerateW [DSOUND.3]
549 * Enumerate all DirectSound drivers installed in the system
552 * lpDSEnumCallback [I] Address of callback function.
553 * lpContext [I] Address of user defined context passed to callback function.
557 * Failure: DSERR_INVALIDPARAM
559 DECLSPEC_EXPORT HRESULT WINAPI
DirectSoundEnumerateW(
560 LPDSENUMCALLBACKW lpDSEnumCallback
,
563 TRACE("lpDSEnumCallback = %p, lpContext = %p\n", lpDSEnumCallback
, lpContext
);
565 if(!lpDSEnumCallback
)
567 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
568 return DSERR_INVALIDPARAM
;
573 ERR("Attempting to enumerate sound cards without OpenAL support\n");
574 ERR("Please recompile wine with OpenAL for sound to work\n");
578 WCHAR
*devwstr
= NULL
;
580 const ALCchar
*devstr
;
583 EnterCriticalSection(&openal_crst
);
584 devstr
= DSOUND_getdevicestrings();
585 if(!devstr
|| !*devstr
)
588 TRACE("calling lpDSEnumCallback(NULL,\"%ls\",\"%ls\",%p)\n",
589 L
"Primary Sound Driver", L
"", lpContext
);
590 if(lpDSEnumCallback(NULL
, L
"Primary Sound Driver", L
"", lpContext
) == FALSE
)
593 guid
= DSOUND_renderer_guid
;
597 len
= MultiByteToWideChar(CP_UTF8
, 0, devstr
, -1, NULL
, 0);
602 WCHAR
*str
= realloc(devwstr
, (len
+1)*sizeof(WCHAR
));
608 MultiByteToWideChar(CP_UTF8
, 0, devstr
, -1, devwstr
, len
);
611 TRACE("calling lpDSEnumCallback(%s,\"%ls\",\"%ls\",%p)\n",
612 debugstr_guid(&guid
), devwstr
, L
"wineal.drv", lpContext
);
613 if(lpDSEnumCallback(&guid
, devwstr
, L
"wineal.drv", lpContext
) == FALSE
)
617 devstr
+= strlen(devstr
)+1;
620 LeaveCriticalSection(&openal_crst
);
626 /***************************************************************************
627 * DirectSoundCaptureEnumerateA [DSOUND.7]
629 * Enumerate all DirectSound drivers installed in the system.
632 * lpDSEnumCallback [I] Address of callback function.
633 * lpContext [I] Address of user defined context passed to callback function.
637 * Failure: DSERR_INVALIDPARAM
639 DECLSPEC_EXPORT HRESULT WINAPI
DirectSoundCaptureEnumerateA(
640 LPDSENUMCALLBACKA lpDSEnumCallback
,
643 struct ConvAcontext context
;
646 TRACE("lpDSEnumCallback = %p, lpContext = %p\n", lpDSEnumCallback
, lpContext
);
648 if(lpDSEnumCallback
== NULL
) {
649 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
650 return DSERR_INVALIDPARAM
;
653 context
.callA
= lpDSEnumCallback
;
654 context
.data
= lpContext
;
658 ret
= DirectSoundCaptureEnumerateW(w2a_callback
, &context
);
664 /***************************************************************************
665 * DirectSoundCaptureEnumerateW [DSOUND.8]
667 * Enumerate all DirectSound drivers installed in the system.
670 * lpDSEnumCallback [I] Address of callback function.
671 * lpContext [I] Address of user defined context passed to callback function.
675 * Failure: DSERR_INVALIDPARAM
677 DECLSPEC_EXPORT HRESULT WINAPI
DirectSoundCaptureEnumerateW(
678 LPDSENUMCALLBACKW lpDSEnumCallback
,
681 TRACE("lpDSEnumCallback = %p, lpContext = %p\n", lpDSEnumCallback
, lpContext
);
683 if(!lpDSEnumCallback
)
685 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
686 return DSERR_INVALIDPARAM
;
691 ERR("Attempting to enumerate sound cards without OpenAL support\n");
692 ERR("Please recompile wine with OpenAL for sound to work\n");
696 WCHAR
*devwstr
= NULL
;
698 const ALCchar
*devstr
;
701 EnterCriticalSection(&openal_crst
);
702 devstr
= DSOUND_getcapturedevicestrings();
703 if(!devstr
|| !*devstr
)
706 TRACE("calling lpDSEnumCallback(NULL,\"%ls\",\"%ls\",%p)\n",
707 L
"Primary Sound Driver", L
"", lpContext
);
708 if(lpDSEnumCallback(NULL
, L
"Primary Sound Driver", L
"", lpContext
) == FALSE
)
711 guid
= DSOUND_capture_guid
;
715 len
= MultiByteToWideChar(CP_UTF8
, 0, devstr
, -1, NULL
, 0);
720 WCHAR
*str
= realloc(devwstr
, (len
+1)*sizeof(WCHAR
));
726 MultiByteToWideChar(CP_UTF8
, 0, devstr
, -1, devwstr
, len
);
729 TRACE("calling lpDSEnumCallback(%s,\"%ls\",\"%ls\",%p)\n",
730 debugstr_guid(&guid
), devwstr
, L
"wineal.drv", lpContext
);
731 if(lpDSEnumCallback(&guid
, devwstr
, L
"wineal.drv", lpContext
) == FALSE
)
735 devstr
+= strlen(devstr
)+1;
738 LeaveCriticalSection(&openal_crst
);
745 /*******************************************************************************
746 * DirectSoundCreate (DSOUND.1)
748 * Creates and initializes a DirectSound interface.
751 * lpcGUID [I] Address of the GUID that identifies the sound device.
752 * ppDS [O] Address of a variable to receive the interface pointer.
753 * pUnkOuter [I] Must be NULL.
757 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
758 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
760 DECLSPEC_EXPORT HRESULT WINAPI
761 DirectSoundCreate(LPCGUID lpcGUID
, IDirectSound
**ppDS
, IUnknown
*pUnkOuter
)
766 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDS
, pUnkOuter
);
769 WARN("invalid parameter: ppDS == NULL\n");
770 return DSERR_INVALIDPARAM
;
774 if (pUnkOuter
!= NULL
) {
775 WARN("invalid parameter: pUnkOuter != NULL\n");
776 return DSERR_INVALIDPARAM
;
779 hr
= DSOUND_Create(&IID_IDirectSound
, &pDS
);
783 hr
= IDirectSound_Initialize(*ppDS
, lpcGUID
);
786 IDirectSound_Release(*ppDS
);
794 /*******************************************************************************
795 * DirectSoundCreate8 (DSOUND.11)
797 * Creates and initializes a DirectSound8 interface.
800 * lpcGUID [I] Address of the GUID that identifies the sound device.
801 * ppDS [O] Address of a variable to receive the interface pointer.
802 * pUnkOuter [I] Must be NULL.
806 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
807 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
809 DECLSPEC_EXPORT HRESULT WINAPI
810 DirectSoundCreate8(LPCGUID lpcGUID
, IDirectSound8
**ppDS
, IUnknown
*pUnkOuter
)
815 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDS
, pUnkOuter
);
818 WARN("invalid parameter: ppDS == NULL\n");
819 return DSERR_INVALIDPARAM
;
823 if (pUnkOuter
!= NULL
) {
824 WARN("invalid parameter: pUnkOuter != NULL\n");
825 return DSERR_INVALIDPARAM
;
828 hr
= DSOUND_Create8(&IID_IDirectSound8
, &pDS
);
832 hr
= IDirectSound8_Initialize(*ppDS
, lpcGUID
);
835 IDirectSound8_Release(*ppDS
);
843 /***************************************************************************
844 * DirectSoundCaptureCreate [DSOUND.6]
846 * Create and initialize a DirectSoundCapture interface.
849 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
850 * lplpDSC [O] Address of a variable to receive the interface pointer.
851 * pUnkOuter [I] Must be NULL.
855 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
859 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
860 * or NULL for the default device or DSDEVID_DefaultCapture or
861 * DSDEVID_DefaultVoiceCapture.
863 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
865 DECLSPEC_EXPORT HRESULT WINAPI
866 DirectSoundCaptureCreate(LPCGUID lpcGUID
, IDirectSoundCapture
**ppDSC
, IUnknown
*pUnkOuter
)
871 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC
, pUnkOuter
);
875 WARN("invalid parameter: ppDSC == NULL\n");
876 return DSERR_INVALIDPARAM
;
882 WARN("invalid parameter: pUnkOuter != NULL\n");
883 return DSERR_NOAGGREGATION
;
886 hr
= DSOUND_CaptureCreate(&IID_IDirectSoundCapture
, &pDSC
);
890 hr
= IDirectSoundCapture_Initialize(*ppDSC
, lpcGUID
);
893 IDirectSoundCapture_Release(*ppDSC
);
901 /***************************************************************************
902 * DirectSoundCaptureCreate8 [DSOUND.12]
904 * Create and initialize a DirectSoundCapture interface.
907 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
908 * lplpDSC [O] Address of a variable to receive the interface pointer.
909 * pUnkOuter [I] Must be NULL.
913 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
917 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
918 * or NULL for the default device or DSDEVID_DefaultCapture or
919 * DSDEVID_DefaultVoiceCapture.
921 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
923 DECLSPEC_EXPORT HRESULT WINAPI
924 DirectSoundCaptureCreate8(LPCGUID lpcGUID
, IDirectSoundCapture8
**ppDSC8
, IUnknown
*pUnkOuter
)
929 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC8
, pUnkOuter
);
933 WARN("invalid parameter: ppDSC8 == NULL\n");
934 return DSERR_INVALIDPARAM
;
940 WARN("invalid parameter: pUnkOuter != NULL\n");
941 return DSERR_NOAGGREGATION
;
944 hr
= DSOUND_CaptureCreate8(&IID_IDirectSoundCapture
, &pDSC8
);
948 hr
= IDirectSoundCapture_Initialize(*ppDSC8
, lpcGUID
);
951 IDirectSoundCapture_Release(*ppDSC8
);
959 /*******************************************************************************
960 * DirectSound ClassFactory
963 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
966 IClassFactory IClassFactory_iface
;
969 FnCreateInstance pfnCreateInstance
;
972 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
974 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
977 static HRESULT WINAPI
DSCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
979 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
980 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
983 if (IsEqualIID(riid
, &IID_IUnknown
) ||
984 IsEqualIID(riid
, &IID_IClassFactory
))
987 IUnknown_AddRef(iface
);
991 return E_NOINTERFACE
;
994 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
996 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
997 ULONG ref
= InterlockedIncrement(&(This
->ref
));
998 TRACE("(%p) ref was %lu\n", This
, ref
- 1);
1002 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
1004 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1005 ULONG ref
= InterlockedDecrement(&(This
->ref
));
1006 TRACE("(%p) ref was %lu\n", This
, ref
+ 1);
1007 /* static class, won't be freed */
1011 static HRESULT WINAPI
DSCF_CreateInstance(
1012 LPCLASSFACTORY iface
,
1017 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1018 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
1021 return CLASS_E_NOAGGREGATION
;
1023 if (ppobj
== NULL
) {
1024 WARN("invalid parameter\n");
1025 return DSERR_INVALIDPARAM
;
1028 return This
->pfnCreateInstance(riid
, ppobj
);
1031 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
1033 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
1034 FIXME("(%p, %d) stub!\n", This
, dolock
);
1038 static const IClassFactoryVtbl DSCF_Vtbl
= {
1039 DSCF_QueryInterface
,
1042 DSCF_CreateInstance
,
1046 static IClassFactoryImpl DSOUND_CF
[] = {
1047 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSound
, DSOUND_Create
},
1048 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSound8
, DSOUND_Create8
},
1049 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture
, DSOUND_CaptureCreate
},
1050 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture8
, DSOUND_CaptureCreate8
},
1051 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSoundFullDuplex
, DSOUND_FullDuplexCreate
},
1052 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSoundPrivate
, IKsPrivatePropertySetImpl_Create
},
1053 { {NULL
}, 0, NULL
, NULL
}
1056 /*******************************************************************************
1057 * DllGetClassObject [DSOUND.@]
1058 * Retrieves class object from a DLL object
1061 * Docs say returns STDAPI
1064 * rclsid [I] CLSID for the class object
1065 * riid [I] Reference to identifier of interface for class object
1066 * ppv [O] Address of variable to receive interface pointer for riid
1070 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
1073 DECLSPEC_EXPORT HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1076 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1079 WARN("invalid parameter\n");
1080 return E_INVALIDARG
;
1085 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
1086 !IsEqualIID(riid
, &IID_IUnknown
)) {
1087 WARN("no interface for %s\n", debugstr_guid(riid
));
1088 return E_NOINTERFACE
;
1091 while (NULL
!= DSOUND_CF
[i
].rclsid
) {
1092 if (IsEqualGUID(rclsid
, DSOUND_CF
[i
].rclsid
)) {
1093 DSCF_AddRef(&DSOUND_CF
[i
].IClassFactory_iface
);
1094 *ppv
= &DSOUND_CF
[i
];
1100 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
1101 debugstr_guid(riid
), ppv
);
1102 return CLASS_E_CLASSNOTAVAILABLE
;
1106 /*******************************************************************************
1107 * DllCanUnloadNow [DSOUND.4]
1108 * Determines whether the DLL is in use.
1114 DECLSPEC_EXPORT HRESULT WINAPI
DllCanUnloadNow(void)
1116 FIXME("(void): stub\n");
1120 /***********************************************************************
1121 * DllMain (DSOUND.init)
1123 DECLSPEC_EXPORT BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1125 TRACE("(%p, %lu, %p)\n", hInstDLL
, fdwReason
, lpvReserved
);
1129 case DLL_PROCESS_ATTACH
:
1130 TRACE("DLL_PROCESS_ATTACH\n");
1131 if(!load_libopenal())
1133 TlsThreadPtr
= TlsAlloc();
1134 /* Increase refcount on dsound by 1 */
1135 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
1138 case DLL_THREAD_ATTACH
:
1139 TRACE("DLL_THREAD_ATTACH\n");
1142 case DLL_THREAD_DETACH
:
1143 TRACE("DLL_THREAD_DETACH\n");
1148 case DLL_PROCESS_DETACH
:
1149 TRACE("DLL_PROCESS_DETACH\n");
1151 FreeLibrary(openal_handle
);
1152 TlsFree(TlsThreadPtr
);
1156 TRACE("UNKNOWN REASON\n");
1163 /***********************************************************************
1164 * DllRegisterServer (DSOUND.@)
1166 HRESULT WINAPI
DllRegisterServer(void)
1168 return __wine_register_resources(instance
);
1171 /***********************************************************************
1172 * DllUnregisterServer (DSOUND.@)
1174 HRESULT WINAPI
DllUnregisterServer(void)
1176 return __wine_unregister_resources(instance
);