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"
59 #include "dsound_private.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
69 #include "dsound_private.h"
72 #define CP_UNIXCP 65010
75 DEFINE_GUID(CLSID_DirectSoundPrivate
,0x11ab3ec0,0x25ec,0x11d1,0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca);
81 const GUID DSOUND_renderer_guid
= { 0xbd6dd71a, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
82 const GUID DSOUND_capture_guid
= { 0xbd6dd71b, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
84 const IID DSPROPSETID_EAX20_ListenerProperties
= {
85 0x0306a6a8, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
88 const EAXLISTENERPROPERTIES EnvironmentDefaults
[EAX_ENVIRONMENT_COUNT
] =
90 REVERB_PRESET_GENERIC
,
91 REVERB_PRESET_PADDEDCELL
,
93 REVERB_PRESET_BATHROOM
,
94 REVERB_PRESET_LIVINGROOM
,
95 REVERB_PRESET_STONEROOM
,
96 REVERB_PRESET_AUDITORIUM
,
97 REVERB_PRESET_CONCERTHALL
,
100 REVERB_PRESET_HANGAR
,
101 REVERB_PRESET_CARPETEDHALLWAY
,
102 REVERB_PRESET_HALLWAY
,
103 REVERB_PRESET_STONECORRIDOR
,
105 REVERB_PRESET_FOREST
,
107 REVERB_PRESET_MOUNTAINS
,
108 REVERB_PRESET_QUARRY
,
110 REVERB_PRESET_PARKINGLOT
,
111 REVERB_PRESET_SEWERPIPE
,
112 REVERB_PRESET_UNDERWATER
,
113 REVERB_PRESET_DRUGGED
,
115 REVERB_PRESET_PSYCHOTIC
118 static CRITICAL_SECTION_DEBUG openal_crst_debug
=
121 { &openal_crst_debug
.ProcessLocksList
,
122 &openal_crst_debug
.ProcessLocksList
},
123 0, 0, { (DWORD_PTR
)(__FILE__
": openal_crst_debug") }
125 CRITICAL_SECTION openal_crst
= { &openal_crst_debug
, -1, 0, 0, 0, 0 };
127 int openal_loaded
= 0;
128 #ifdef SONAME_LIBOPENAL
129 static void *openal_handle
= NULL
;
130 LPALCCREATECONTEXT palcCreateContext
= NULL
;
131 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent
= NULL
;
132 LPALCPROCESSCONTEXT palcProcessContext
= NULL
;
133 LPALCSUSPENDCONTEXT palcSuspendContext
= NULL
;
134 LPALCDESTROYCONTEXT palcDestroyContext
= NULL
;
135 LPALCGETCURRENTCONTEXT palcGetCurrentContext
= NULL
;
136 LPALCGETCONTEXTSDEVICE palcGetContextsDevice
= NULL
;
137 LPALCOPENDEVICE palcOpenDevice
= NULL
;
138 LPALCCLOSEDEVICE palcCloseDevice
= NULL
;
139 LPALCGETERROR palcGetError
= NULL
;
140 LPALCISEXTENSIONPRESENT palcIsExtensionPresent
= NULL
;
141 LPALCGETPROCADDRESS palcGetProcAddress
= NULL
;
142 LPALCGETENUMVALUE palcGetEnumValue
= NULL
;
143 LPALCGETSTRING palcGetString
= NULL
;
144 LPALCGETINTEGERV palcGetIntegerv
= NULL
;
145 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice
= NULL
;
146 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice
= NULL
;
147 LPALCCAPTURESTART palcCaptureStart
= NULL
;
148 LPALCCAPTURESTOP palcCaptureStop
= NULL
;
149 LPALCCAPTURESAMPLES palcCaptureSamples
= NULL
;
150 LPALENABLE palEnable
= NULL
;
151 LPALDISABLE palDisable
= NULL
;
152 LPALISENABLED palIsEnabled
= NULL
;
153 LPALGETSTRING palGetString
= NULL
;
154 LPALGETBOOLEANV palGetBooleanv
= NULL
;
155 LPALGETINTEGERV palGetIntegerv
= NULL
;
156 LPALGETFLOATV palGetFloatv
= NULL
;
157 LPALGETDOUBLEV palGetDoublev
= NULL
;
158 LPALGETBOOLEAN palGetBoolean
= NULL
;
159 LPALGETINTEGER palGetInteger
= NULL
;
160 LPALGETFLOAT palGetFloat
= NULL
;
161 LPALGETDOUBLE palGetDouble
= NULL
;
162 LPALGETERROR palGetError
= NULL
;
163 LPALISEXTENSIONPRESENT palIsExtensionPresent
= NULL
;
164 LPALGETPROCADDRESS palGetProcAddress
= NULL
;
165 LPALGETENUMVALUE palGetEnumValue
= NULL
;
166 LPALLISTENERF palListenerf
= NULL
;
167 LPALLISTENER3F palListener3f
= NULL
;
168 LPALLISTENERFV palListenerfv
= NULL
;
169 LPALLISTENERI palListeneri
= NULL
;
170 LPALLISTENER3I palListener3i
= NULL
;
171 LPALLISTENERIV palListeneriv
= NULL
;
172 LPALGETLISTENERF palGetListenerf
= NULL
;
173 LPALGETLISTENER3F palGetListener3f
= NULL
;
174 LPALGETLISTENERFV palGetListenerfv
= NULL
;
175 LPALGETLISTENERI palGetListeneri
= NULL
;
176 LPALGETLISTENER3I palGetListener3i
= NULL
;
177 LPALGETLISTENERIV palGetListeneriv
= NULL
;
178 LPALGENSOURCES palGenSources
= NULL
;
179 LPALDELETESOURCES palDeleteSources
= NULL
;
180 LPALISSOURCE palIsSource
= NULL
;
181 LPALSOURCEF palSourcef
= NULL
;
182 LPALSOURCE3F palSource3f
= NULL
;
183 LPALSOURCEFV palSourcefv
= NULL
;
184 LPALSOURCEI palSourcei
= NULL
;
185 LPALSOURCE3I palSource3i
= NULL
;
186 LPALSOURCEIV palSourceiv
= NULL
;
187 LPALGETSOURCEF palGetSourcef
= NULL
;
188 LPALGETSOURCE3F palGetSource3f
= NULL
;
189 LPALGETSOURCEFV palGetSourcefv
= NULL
;
190 LPALGETSOURCEI palGetSourcei
= NULL
;
191 LPALGETSOURCE3I palGetSource3i
= NULL
;
192 LPALGETSOURCEIV palGetSourceiv
= NULL
;
193 LPALSOURCEPLAYV palSourcePlayv
= NULL
;
194 LPALSOURCESTOPV palSourceStopv
= NULL
;
195 LPALSOURCEREWINDV palSourceRewindv
= NULL
;
196 LPALSOURCEPAUSEV palSourcePausev
= NULL
;
197 LPALSOURCEPLAY palSourcePlay
= NULL
;
198 LPALSOURCESTOP palSourceStop
= NULL
;
199 LPALSOURCEREWIND palSourceRewind
= NULL
;
200 LPALSOURCEPAUSE palSourcePause
= NULL
;
201 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers
= NULL
;
202 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers
= NULL
;
203 LPALGENBUFFERS palGenBuffers
= NULL
;
204 LPALDELETEBUFFERS palDeleteBuffers
= NULL
;
205 LPALISBUFFER palIsBuffer
= NULL
;
206 LPALBUFFERF palBufferf
= NULL
;
207 LPALBUFFER3F palBuffer3f
= NULL
;
208 LPALBUFFERFV palBufferfv
= NULL
;
209 LPALBUFFERI palBufferi
= NULL
;
210 LPALBUFFER3I palBuffer3i
= NULL
;
211 LPALBUFFERIV palBufferiv
= NULL
;
212 LPALGETBUFFERF palGetBufferf
= NULL
;
213 LPALGETBUFFER3F palGetBuffer3f
= NULL
;
214 LPALGETBUFFERFV palGetBufferfv
= NULL
;
215 LPALGETBUFFERI palGetBufferi
= NULL
;
216 LPALGETBUFFER3I palGetBuffer3i
= NULL
;
217 LPALGETBUFFERIV palGetBufferiv
= NULL
;
218 LPALBUFFERDATA palBufferData
= NULL
;
219 LPALDOPPLERFACTOR palDopplerFactor
= NULL
;
220 LPALDOPPLERVELOCITY palDopplerVelocity
= NULL
;
221 LPALDISTANCEMODEL palDistanceModel
= NULL
;
222 LPALSPEEDOFSOUND palSpeedOfSound
= NULL
;
225 LPALCMAKECONTEXTCURRENT set_context
;
226 LPALCGETCURRENTCONTEXT get_context
;
229 static void load_libopenal(void)
232 const char *str
= getenv("DSOAL_LOGLEVEL");
234 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 LPDSENUMCALLBACKA callA
;
456 static BOOL CALLBACK
a_to_w_callback(LPGUID guid
, LPCWSTR descW
, LPCWSTR modW
, LPVOID data
)
458 struct morecontext
*context
= data
;
459 char descA
[MAXPNAMELEN
], modA
[MAXPNAMELEN
];
461 WideCharToMultiByte(CP_ACP
, 0, descW
, -1, descA
, sizeof(descA
), NULL
, NULL
);
462 WideCharToMultiByte(CP_ACP
, 0, modW
, -1, modA
, sizeof(modA
), NULL
, NULL
);
464 return context
->callA(guid
, descA
, modA
, 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 struct morecontext context
;
486 if (lpDSEnumCallback
== NULL
) {
487 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
488 return DSERR_INVALIDPARAM
;
491 context
.callA
= lpDSEnumCallback
;
492 context
.data
= lpContext
;
494 return DirectSoundEnumerateW(a_to_w_callback
, &context
);
497 /***************************************************************************
498 * DirectSoundEnumerateW [DSOUND.3]
500 * Enumerate all DirectSound drivers installed in the system
503 * lpDSEnumCallback [I] Address of callback function.
504 * lpContext [I] Address of user defined context passed to callback function.
508 * Failure: DSERR_INVALIDPARAM
510 HRESULT WINAPI
DirectSoundEnumerateW(
511 LPDSENUMCALLBACKW lpDSEnumCallback
,
514 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
515 lpDSEnumCallback
, lpContext
);
517 if (lpDSEnumCallback
== NULL
) {
518 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
519 return DSERR_INVALIDPARAM
;
521 else if (openal_loaded
)
524 WCHAR wDesc
[MAXPNAMELEN
];
525 WCHAR wName
[MAXPNAMELEN
];
526 const ALCchar
*devstr
;
527 static const WCHAR empty
[] = { 0 };
528 EnterCriticalSection(&openal_crst
);
529 devstr
= DSOUND_getdevicestrings();
530 if (!devstr
|| !*devstr
)
533 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
534 "Primary Sound Driver","",lpContext
);
535 MultiByteToWideChar( CP_ACP
, 0, "Primary Sound Driver", -1,
536 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
) );
537 if (lpDSEnumCallback(NULL
, wDesc
, empty
, lpContext
) == FALSE
)
540 guid
= DSOUND_renderer_guid
;
542 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
543 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
544 MultiByteToWideChar( CP_UNIXCP
, 0, devstr
, -1,
545 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
)-1 );
546 wDesc
[sizeof(wDesc
)/sizeof(WCHAR
)-1] = 0;
547 MultiByteToWideChar( CP_ACP
, 0, "wineal.drv", -1,
548 wName
, sizeof(wName
)/sizeof(WCHAR
)-1 );
549 if (lpDSEnumCallback(&guid
, wDesc
, wName
, lpContext
) == FALSE
)
552 devstr
+= strlen(devstr
)+1;
556 LeaveCriticalSection(&openal_crst
);
560 ERR("Attempting to enumerate sound cards without OpenAL support\n");
561 ERR("Please recompile wine with OpenAL for sound to work\n");
566 /***************************************************************************
567 * DirectSoundCaptureEnumerateA [DSOUND.7]
569 * Enumerate all DirectSound drivers installed in the system.
572 * lpDSEnumCallback [I] Address of callback function.
573 * lpContext [I] Address of user defined context passed to callback function.
577 * Failure: DSERR_INVALIDPARAM
579 HRESULT WINAPI
DirectSoundCaptureEnumerateA(
580 LPDSENUMCALLBACKA lpDSEnumCallback
,
583 struct morecontext context
;
585 if (lpDSEnumCallback
== NULL
) {
586 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
587 return DSERR_INVALIDPARAM
;
590 context
.callA
= lpDSEnumCallback
;
591 context
.data
= lpContext
;
593 return DirectSoundCaptureEnumerateW(a_to_w_callback
, &context
);
596 /***************************************************************************
597 * DirectSoundCaptureEnumerateW [DSOUND.8]
599 * Enumerate all DirectSound drivers installed in the system.
602 * lpDSEnumCallback [I] Address of callback function.
603 * lpContext [I] Address of user defined context passed to callback function.
607 * Failure: DSERR_INVALIDPARAM
610 DirectSoundCaptureEnumerateW(
611 LPDSENUMCALLBACKW lpDSEnumCallback
,
614 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
616 if (lpDSEnumCallback
== NULL
) {
617 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
618 return DSERR_INVALIDPARAM
;
620 else if (openal_loaded
)
623 WCHAR wDesc
[MAXPNAMELEN
];
624 WCHAR wName
[MAXPNAMELEN
];
625 const ALCchar
*devstr
;
626 static const WCHAR empty
[] = { 0 };
628 EnterCriticalSection(&openal_crst
);
629 devstr
= DSOUND_getcapturedevicestrings();
630 if (!devstr
|| !*devstr
)
633 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
634 "Primary Sound Capture Driver","",lpContext
);
635 MultiByteToWideChar( CP_ACP
, 0, "Primary Sound Driver", -1,
636 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
) );
637 if (lpDSEnumCallback(NULL
, wDesc
, empty
, lpContext
) == FALSE
)
640 guid
= DSOUND_capture_guid
;
642 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
643 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
644 MultiByteToWideChar( CP_UNIXCP
, 0, devstr
, -1,
645 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
)-1 );
646 wDesc
[sizeof(wDesc
)/sizeof(WCHAR
)-1] = 0;
647 MultiByteToWideChar( CP_ACP
, 0, "wineal.drv", -1,
648 wName
, sizeof(wName
)/sizeof(WCHAR
)-1 );
649 if (lpDSEnumCallback(&guid
, wDesc
, wName
, lpContext
) == FALSE
)
652 devstr
+= strlen(devstr
)+1;
656 LeaveCriticalSection(&openal_crst
);
660 ERR("Attempting to enumerate sound cards without OpenAL support\n");
661 ERR("Please recompile wine with OpenAL for sound to work\n");
666 /*******************************************************************************
667 * DirectSoundCreate (DSOUND.1)
669 * Creates and initializes a DirectSound interface.
672 * lpcGUID [I] Address of the GUID that identifies the sound device.
673 * ppDS [O] Address of a variable to receive the interface pointer.
674 * pUnkOuter [I] Must be NULL.
678 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
679 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
681 HRESULT WINAPI
DirectSoundCreate(
689 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
692 WARN("invalid parameter: ppDS == NULL\n");
693 return DSERR_INVALIDPARAM
;
696 if (pUnkOuter
!= NULL
) {
697 WARN("invalid parameter: pUnkOuter != NULL\n");
699 return DSERR_INVALIDPARAM
;
702 hr
= DSOUND_Create(&IID_IDirectSound
, (void **)&pDS
);
704 hr
= IDirectSound_Initialize(pDS
, lpcGUID
);
706 if (hr
!= DSERR_ALREADYINITIALIZED
) {
707 IDirectSound_Release(pDS
);
719 /*******************************************************************************
720 * DirectSoundCreate8 (DSOUND.11)
722 * Creates and initializes a DirectSound8 interface.
725 * lpcGUID [I] Address of the GUID that identifies the sound device.
726 * ppDS [O] Address of a variable to receive the interface pointer.
727 * pUnkOuter [I] Must be NULL.
731 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
732 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
734 HRESULT WINAPI
DirectSoundCreate8(
736 LPDIRECTSOUND8
*ppDS
,
742 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
745 WARN("invalid parameter: ppDS == NULL\n");
746 return DSERR_INVALIDPARAM
;
749 if (pUnkOuter
!= NULL
) {
750 WARN("invalid parameter: pUnkOuter != NULL\n");
752 return DSERR_INVALIDPARAM
;
755 hr
= DSOUND_Create8(&IID_IDirectSound8
, (void**)&pDS
);
757 hr
= IDirectSound8_Initialize(pDS
, lpcGUID
);
759 if (hr
!= DSERR_ALREADYINITIALIZED
) {
760 IDirectSound8_Release(pDS
);
772 /***************************************************************************
773 * DirectSoundCaptureCreate [DSOUND.6]
775 * Create and initialize a DirectSoundCapture interface.
778 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
779 * lplpDSC [O] Address of a variable to receive the interface pointer.
780 * pUnkOuter [I] Must be NULL.
784 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
788 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
789 * or NULL for the default device or DSDEVID_DefaultCapture or
790 * DSDEVID_DefaultVoiceCapture.
792 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
794 HRESULT WINAPI
DirectSoundCaptureCreate(
796 LPDIRECTSOUNDCAPTURE
*ppDSC
,
800 LPDIRECTSOUNDCAPTURE pDSC
;
801 TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID
), ppDSC
, pUnkOuter
);
804 WARN("invalid parameter: ppDSC == NULL\n");
805 return DSERR_INVALIDPARAM
;
809 WARN("invalid parameter: pUnkOuter != NULL\n");
811 return DSERR_NOAGGREGATION
;
814 hr
= DSOUND_CaptureCreate(&IID_IDirectSoundCapture
, &pDSC
);
816 hr
= IDirectSoundCapture_Initialize(pDSC
, lpcGUID
);
818 IDirectSoundCapture_Release(pDSC
);
828 /***************************************************************************
829 * DirectSoundCaptureCreate8 [DSOUND.12]
831 * Create and initialize a DirectSoundCapture interface.
834 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
835 * lplpDSC [O] Address of a variable to receive the interface pointer.
836 * pUnkOuter [I] Must be NULL.
840 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
844 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
845 * or NULL for the default device or DSDEVID_DefaultCapture or
846 * DSDEVID_DefaultVoiceCapture.
848 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
850 HRESULT WINAPI
DirectSoundCaptureCreate8(
852 LPDIRECTSOUNDCAPTURE8
*ppDSC8
,
856 LPDIRECTSOUNDCAPTURE8 pDSC8
;
857 TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID
), ppDSC8
, pUnkOuter
);
859 if (ppDSC8
== NULL
) {
860 WARN("invalid parameter: ppDSC8 == NULL\n");
861 return DSERR_INVALIDPARAM
;
865 WARN("invalid parameter: pUnkOuter != NULL\n");
867 return DSERR_NOAGGREGATION
;
870 hr
= DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8
, &pDSC8
);
872 hr
= IDirectSoundCapture_Initialize(pDSC8
, lpcGUID
);
874 IDirectSoundCapture_Release(pDSC8
);
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 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSound
, DSOUND_Create
},
973 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSound8
, DSOUND_Create8
},
974 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture
, (FnCreateInstance
)DSOUND_CaptureCreate
},
975 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture8
, (FnCreateInstance
)DSOUND_CaptureCreate8
},
976 { {&DSCF_Vtbl
}, 1, &CLSID_DirectSoundFullDuplex
, (FnCreateInstance
)DSOUND_FullDuplexCreate
},
977 { {&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
);
1052 switch (fdwReason
) {
1053 case DLL_PROCESS_ATTACH
:
1054 TRACE("DLL_PROCESS_ATTACH\n");
1056 DisableThreadLibraryCalls(hInstDLL
);
1057 /* Increase refcount on dsound by 1 */
1058 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
1060 case DLL_PROCESS_DETACH
:
1061 TRACE("DLL_PROCESS_DETACH\n");
1062 #ifdef SONAME_LIBOPENAL
1064 wine_dlclose(openal_handle
, NULL
, 0);
1065 #endif /*SONAME_LIBOPENAL*/
1068 TRACE("UNKNOWN REASON\n");