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 LPDSENUMCALLBACKA callA
;
469 static BOOL CALLBACK
a_to_w_callback(LPGUID guid
, LPCWSTR descW
, LPCWSTR modW
, LPVOID data
)
471 struct morecontext
*context
= data
;
472 char descA
[MAXPNAMELEN
], modA
[MAXPNAMELEN
];
474 WideCharToMultiByte(CP_ACP
, 0, descW
, -1, descA
, sizeof(descA
), NULL
, NULL
);
475 WideCharToMultiByte(CP_ACP
, 0, modW
, -1, modA
, sizeof(modA
), NULL
, NULL
);
477 return context
->callA(guid
, descA
, modA
, 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 struct morecontext context
;
499 if (lpDSEnumCallback
== NULL
) {
500 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
501 return DSERR_INVALIDPARAM
;
504 context
.callA
= lpDSEnumCallback
;
505 context
.data
= lpContext
;
507 return DirectSoundEnumerateW(a_to_w_callback
, &context
);
510 /***************************************************************************
511 * DirectSoundEnumerateW [DSOUND.3]
513 * Enumerate all DirectSound drivers installed in the system
516 * lpDSEnumCallback [I] Address of callback function.
517 * lpContext [I] Address of user defined context passed to callback function.
521 * Failure: DSERR_INVALIDPARAM
523 HRESULT WINAPI
DirectSoundEnumerateW(
524 LPDSENUMCALLBACKW lpDSEnumCallback
,
527 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
528 lpDSEnumCallback
, lpContext
);
530 if (lpDSEnumCallback
== NULL
) {
531 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
532 return DSERR_INVALIDPARAM
;
534 else if (openal_loaded
)
537 WCHAR wDesc
[MAXPNAMELEN
];
538 WCHAR wName
[MAXPNAMELEN
];
539 const ALCchar
*devstr
;
540 static const WCHAR empty
[] = { 0 };
541 EnterCriticalSection(&openal_crst
);
542 devstr
= DSOUND_getdevicestrings();
543 if (!devstr
|| !*devstr
)
546 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
547 "Primary Sound Driver","",lpContext
);
548 MultiByteToWideChar( CP_ACP
, 0, "Primary Sound Driver", -1,
549 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
) );
550 if (lpDSEnumCallback(NULL
, wDesc
, empty
, lpContext
) == FALSE
)
553 guid
= DSOUND_renderer_guid
;
555 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
556 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
557 MultiByteToWideChar( CP_UNIXCP
, 0, devstr
, -1,
558 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
)-1 );
559 wDesc
[sizeof(wDesc
)/sizeof(WCHAR
)-1] = 0;
560 MultiByteToWideChar( CP_ACP
, 0, "wineal.drv", -1,
561 wName
, sizeof(wName
)/sizeof(WCHAR
)-1 );
562 if (lpDSEnumCallback(&guid
, wDesc
, wName
, lpContext
) == FALSE
)
565 devstr
+= strlen(devstr
)+1;
569 LeaveCriticalSection(&openal_crst
);
573 ERR("Attempting to enumerate sound cards without OpenAL support\n");
574 ERR("Please recompile wine with OpenAL for sound to work\n");
579 /***************************************************************************
580 * DirectSoundCaptureEnumerateA [DSOUND.7]
582 * Enumerate all DirectSound drivers installed in the system.
585 * lpDSEnumCallback [I] Address of callback function.
586 * lpContext [I] Address of user defined context passed to callback function.
590 * Failure: DSERR_INVALIDPARAM
592 HRESULT WINAPI
DirectSoundCaptureEnumerateA(
593 LPDSENUMCALLBACKA lpDSEnumCallback
,
596 struct morecontext context
;
598 if (lpDSEnumCallback
== NULL
) {
599 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
600 return DSERR_INVALIDPARAM
;
603 context
.callA
= lpDSEnumCallback
;
604 context
.data
= lpContext
;
606 return DirectSoundCaptureEnumerateW(a_to_w_callback
, &context
);
609 /***************************************************************************
610 * DirectSoundCaptureEnumerateW [DSOUND.8]
612 * Enumerate all DirectSound drivers installed in the system.
615 * lpDSEnumCallback [I] Address of callback function.
616 * lpContext [I] Address of user defined context passed to callback function.
620 * Failure: DSERR_INVALIDPARAM
623 DirectSoundCaptureEnumerateW(
624 LPDSENUMCALLBACKW lpDSEnumCallback
,
627 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
629 if (lpDSEnumCallback
== NULL
) {
630 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
631 return DSERR_INVALIDPARAM
;
633 else if (openal_loaded
)
636 WCHAR wDesc
[MAXPNAMELEN
];
637 WCHAR wName
[MAXPNAMELEN
];
638 const ALCchar
*devstr
;
639 static const WCHAR empty
[] = { 0 };
641 EnterCriticalSection(&openal_crst
);
642 devstr
= DSOUND_getcapturedevicestrings();
643 if (!devstr
|| !*devstr
)
646 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
647 "Primary Sound Capture Driver","",lpContext
);
648 MultiByteToWideChar( CP_ACP
, 0, "Primary Sound Driver", -1,
649 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
) );
650 if (lpDSEnumCallback(NULL
, wDesc
, empty
, lpContext
) == FALSE
)
653 guid
= DSOUND_capture_guid
;
655 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
656 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
657 MultiByteToWideChar( CP_UNIXCP
, 0, devstr
, -1,
658 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
)-1 );
659 wDesc
[sizeof(wDesc
)/sizeof(WCHAR
)-1] = 0;
660 MultiByteToWideChar( CP_ACP
, 0, "wineal.drv", -1,
661 wName
, sizeof(wName
)/sizeof(WCHAR
)-1 );
662 if (lpDSEnumCallback(&guid
, wDesc
, wName
, lpContext
) == FALSE
)
665 devstr
+= strlen(devstr
)+1;
669 LeaveCriticalSection(&openal_crst
);
673 ERR("Attempting to enumerate sound cards without OpenAL support\n");
674 ERR("Please recompile wine with OpenAL for sound to work\n");
679 /*******************************************************************************
680 * DirectSoundCreate (DSOUND.1)
682 * Creates and initializes a DirectSound interface.
685 * lpcGUID [I] Address of the GUID that identifies the sound device.
686 * ppDS [O] Address of a variable to receive the interface pointer.
687 * pUnkOuter [I] Must be NULL.
691 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
692 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
694 HRESULT WINAPI
DirectSoundCreate(
702 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
705 WARN("invalid parameter: ppDS == NULL\n");
706 return DSERR_INVALIDPARAM
;
709 if (pUnkOuter
!= NULL
) {
710 WARN("invalid parameter: pUnkOuter != NULL\n");
712 return DSERR_INVALIDPARAM
;
715 hr
= DSOUND_Create(&IID_IDirectSound
, (void **)&pDS
);
717 hr
= IDirectSound_Initialize(pDS
, lpcGUID
);
719 if (hr
!= DSERR_ALREADYINITIALIZED
) {
720 IDirectSound_Release(pDS
);
732 /*******************************************************************************
733 * DirectSoundCreate8 (DSOUND.11)
735 * Creates and initializes a DirectSound8 interface.
738 * lpcGUID [I] Address of the GUID that identifies the sound device.
739 * ppDS [O] Address of a variable to receive the interface pointer.
740 * pUnkOuter [I] Must be NULL.
744 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
745 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
747 HRESULT WINAPI
DirectSoundCreate8(
749 LPDIRECTSOUND8
*ppDS
,
755 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
758 WARN("invalid parameter: ppDS == NULL\n");
759 return DSERR_INVALIDPARAM
;
762 if (pUnkOuter
!= NULL
) {
763 WARN("invalid parameter: pUnkOuter != NULL\n");
765 return DSERR_INVALIDPARAM
;
768 hr
= DSOUND_Create8(&IID_IDirectSound8
, (void**)&pDS
);
770 hr
= IDirectSound8_Initialize(pDS
, lpcGUID
);
772 if (hr
!= DSERR_ALREADYINITIALIZED
) {
773 IDirectSound8_Release(pDS
);
785 /***************************************************************************
786 * DirectSoundCaptureCreate [DSOUND.6]
788 * Create and initialize a DirectSoundCapture interface.
791 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
792 * lplpDSC [O] Address of a variable to receive the interface pointer.
793 * pUnkOuter [I] Must be NULL.
797 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
801 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
802 * or NULL for the default device or DSDEVID_DefaultCapture or
803 * DSDEVID_DefaultVoiceCapture.
805 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
807 HRESULT WINAPI
DirectSoundCaptureCreate(
809 IDirectSoundCapture
**ppDSC
,
815 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC
, pUnkOuter
);
819 WARN("invalid parameter: ppDSC == NULL\n");
820 return DSERR_INVALIDPARAM
;
826 WARN("invalid parameter: pUnkOuter != NULL\n");
827 return DSERR_NOAGGREGATION
;
830 hr
= DSOUND_CaptureCreate(&IID_IDirectSoundCapture
, &pDSC
);
834 hr
= IDirectSoundCapture_Initialize(*ppDSC
, lpcGUID
);
837 IDirectSoundCapture_Release(*ppDSC
);
845 /***************************************************************************
846 * DirectSoundCaptureCreate8 [DSOUND.12]
848 * Create and initialize a DirectSoundCapture interface.
851 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
852 * lplpDSC [O] Address of a variable to receive the interface pointer.
853 * pUnkOuter [I] Must be NULL.
857 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
861 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
862 * or NULL for the default device or DSDEVID_DefaultCapture or
863 * DSDEVID_DefaultVoiceCapture.
865 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
867 HRESULT WINAPI
DirectSoundCaptureCreate8(
869 IDirectSoundCapture8
**ppDSC8
,
875 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC8
, pUnkOuter
);
879 WARN("invalid parameter: ppDSC8 == NULL\n");
880 return DSERR_INVALIDPARAM
;
886 WARN("invalid parameter: pUnkOuter != NULL\n");
887 return DSERR_NOAGGREGATION
;
890 hr
= DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8
, &pDSC8
);
894 hr
= IDirectSoundCapture_Initialize(*ppDSC8
, lpcGUID
);
897 IDirectSoundCapture_Release(*ppDSC8
);
905 /*******************************************************************************
906 * DirectSound ClassFactory
909 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
912 IClassFactory IClassFactory_iface
;
915 FnCreateInstance pfnCreateInstance
;
918 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
920 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
923 static HRESULT WINAPI
DSCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
925 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
926 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
929 if (IsEqualIID(riid
, &IID_IUnknown
) ||
930 IsEqualIID(riid
, &IID_IClassFactory
))
933 IUnknown_AddRef(iface
);
937 return E_NOINTERFACE
;
940 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
942 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
943 ULONG ref
= InterlockedIncrement(&(This
->ref
));
944 TRACE("(%p) ref was %d\n", This
, ref
- 1);
948 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
950 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
951 ULONG ref
= InterlockedDecrement(&(This
->ref
));
952 TRACE("(%p) ref was %d\n", This
, ref
+ 1);
953 /* static class, won't be freed */
957 static HRESULT WINAPI
DSCF_CreateInstance(
958 LPCLASSFACTORY iface
,
963 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
964 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
967 return CLASS_E_NOAGGREGATION
;
970 WARN("invalid parameter\n");
971 return DSERR_INVALIDPARAM
;
974 return This
->pfnCreateInstance(riid
, ppobj
);
977 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
979 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
980 FIXME("(%p, %d) stub!\n", This
, dolock
);
984 static const IClassFactoryVtbl DSCF_Vtbl
= {
992 static IClassFactoryImpl DSOUND_CF
[] = {
993 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound
, DSOUND_Create
},
994 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound8
, DSOUND_Create8
},
995 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture
, DSOUND_CaptureCreate
},
996 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture8
, DSOUND_CaptureCreate8
},
997 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundFullDuplex
, DSOUND_FullDuplexCreate
},
998 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundPrivate
, IKsPrivatePropertySetImpl_Create
},
999 { {NULL
}, 0, NULL
, NULL
}
1002 /*******************************************************************************
1003 * DllGetClassObject [DSOUND.@]
1004 * Retrieves class object from a DLL object
1007 * Docs say returns STDAPI
1010 * rclsid [I] CLSID for the class object
1011 * riid [I] Reference to identifier of interface for class object
1012 * ppv [O] Address of variable to receive interface pointer for riid
1016 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
1019 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1022 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1025 WARN("invalid parameter\n");
1026 return E_INVALIDARG
;
1031 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
1032 !IsEqualIID(riid
, &IID_IUnknown
)) {
1033 WARN("no interface for %s\n", debugstr_guid(riid
));
1034 return E_NOINTERFACE
;
1037 while (NULL
!= DSOUND_CF
[i
].rclsid
) {
1038 if (IsEqualGUID(rclsid
, DSOUND_CF
[i
].rclsid
)) {
1039 DSCF_AddRef(&DSOUND_CF
[i
].IClassFactory_iface
);
1040 *ppv
= &DSOUND_CF
[i
];
1046 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
1047 debugstr_guid(riid
), ppv
);
1048 return CLASS_E_CLASSNOTAVAILABLE
;
1052 /*******************************************************************************
1053 * DllCanUnloadNow [DSOUND.4]
1054 * Determines whether the DLL is in use.
1060 HRESULT WINAPI
DllCanUnloadNow(void)
1062 FIXME("(void): stub\n");
1066 /***********************************************************************
1067 * DllMain (DSOUND.init)
1069 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1071 TRACE("(%p, %d, %p)\n", hInstDLL
, fdwReason
, lpvReserved
);
1075 case DLL_PROCESS_ATTACH
:
1076 TRACE("DLL_PROCESS_ATTACH\n");
1077 instance
= hInstDLL
;
1079 DisableThreadLibraryCalls(hInstDLL
);
1080 /* Increase refcount on dsound by 1 */
1081 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
1083 case DLL_PROCESS_DETACH
:
1084 TRACE("DLL_PROCESS_DETACH\n");
1085 #ifdef SONAME_LIBOPENAL
1087 wine_dlclose(openal_handle
, NULL
, 0);
1088 #endif /*SONAME_LIBOPENAL*/
1091 TRACE("UNKNOWN REASON\n");
1097 /***********************************************************************
1098 * DllRegisterServer (DSOUND.@)
1100 HRESULT WINAPI
DllRegisterServer(void)
1102 return __wine_register_resources(instance
, NULL
);
1105 /***********************************************************************
1106 * DllUnregisterServer (DSOUND.@)
1108 HRESULT WINAPI
DllUnregisterServer(void)
1110 return __wine_unregister_resources(instance
, NULL
);