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
);
235 #elif defined(SONAME_LIBOPENAL)
239 openal_handle
= wine_dlopen(SONAME_LIBOPENAL
, RTLD_NOW
, error
, sizeof(error
));
241 ERR("Couldn't load " SONAME_LIBOPENAL
": %s\n", error
);
242 #define LOAD_FUNCPTR(f) \
243 if((p##f = wine_dlsym(openal_handle, #f, NULL, 0)) == NULL) { \
244 ERR("Couldn't lookup %s in " SONAME_LIBOPENAL "\n", #f); \
248 LOAD_FUNCPTR(alcCreateContext
);
249 LOAD_FUNCPTR(alcMakeContextCurrent
);
250 LOAD_FUNCPTR(alcProcessContext
);
251 LOAD_FUNCPTR(alcSuspendContext
);
252 LOAD_FUNCPTR(alcDestroyContext
);
253 LOAD_FUNCPTR(alcGetCurrentContext
);
254 LOAD_FUNCPTR(alcGetContextsDevice
);
255 LOAD_FUNCPTR(alcOpenDevice
);
256 LOAD_FUNCPTR(alcCloseDevice
);
257 LOAD_FUNCPTR(alcGetError
);
258 LOAD_FUNCPTR(alcIsExtensionPresent
);
259 LOAD_FUNCPTR(alcGetProcAddress
);
260 LOAD_FUNCPTR(alcGetEnumValue
);
261 LOAD_FUNCPTR(alcGetString
);
262 LOAD_FUNCPTR(alcGetIntegerv
);
263 LOAD_FUNCPTR(alcCaptureOpenDevice
);
264 LOAD_FUNCPTR(alcCaptureCloseDevice
);
265 LOAD_FUNCPTR(alcCaptureStart
);
266 LOAD_FUNCPTR(alcCaptureStop
);
267 LOAD_FUNCPTR(alcCaptureSamples
);
268 LOAD_FUNCPTR(alEnable
);
269 LOAD_FUNCPTR(alDisable
);
270 LOAD_FUNCPTR(alIsEnabled
);
271 LOAD_FUNCPTR(alGetString
);
272 LOAD_FUNCPTR(alGetBooleanv
);
273 LOAD_FUNCPTR(alGetIntegerv
);
274 LOAD_FUNCPTR(alGetFloatv
);
275 LOAD_FUNCPTR(alGetDoublev
);
276 LOAD_FUNCPTR(alGetBoolean
);
277 LOAD_FUNCPTR(alGetInteger
);
278 LOAD_FUNCPTR(alGetFloat
);
279 LOAD_FUNCPTR(alGetDouble
);
280 LOAD_FUNCPTR(alGetError
);
281 LOAD_FUNCPTR(alIsExtensionPresent
);
282 LOAD_FUNCPTR(alGetProcAddress
);
283 LOAD_FUNCPTR(alGetEnumValue
);
284 LOAD_FUNCPTR(alListenerf
);
285 LOAD_FUNCPTR(alListener3f
);
286 LOAD_FUNCPTR(alListenerfv
);
287 LOAD_FUNCPTR(alListeneri
);
288 LOAD_FUNCPTR(alListener3i
);
289 LOAD_FUNCPTR(alListeneriv
);
290 LOAD_FUNCPTR(alGetListenerf
);
291 LOAD_FUNCPTR(alGetListener3f
);
292 LOAD_FUNCPTR(alGetListenerfv
);
293 LOAD_FUNCPTR(alGetListeneri
);
294 LOAD_FUNCPTR(alGetListener3i
);
295 LOAD_FUNCPTR(alGetListeneriv
);
296 LOAD_FUNCPTR(alGenSources
);
297 LOAD_FUNCPTR(alDeleteSources
);
298 LOAD_FUNCPTR(alIsSource
);
299 LOAD_FUNCPTR(alSourcef
);
300 LOAD_FUNCPTR(alSource3f
);
301 LOAD_FUNCPTR(alSourcefv
);
302 LOAD_FUNCPTR(alSourcei
);
303 LOAD_FUNCPTR(alSource3i
);
304 LOAD_FUNCPTR(alSourceiv
);
305 LOAD_FUNCPTR(alGetSourcef
);
306 LOAD_FUNCPTR(alGetSource3f
);
307 LOAD_FUNCPTR(alGetSourcefv
);
308 LOAD_FUNCPTR(alGetSourcei
);
309 LOAD_FUNCPTR(alGetSource3i
);
310 LOAD_FUNCPTR(alGetSourceiv
);
311 LOAD_FUNCPTR(alSourcePlayv
);
312 LOAD_FUNCPTR(alSourceStopv
);
313 LOAD_FUNCPTR(alSourceRewindv
);
314 LOAD_FUNCPTR(alSourcePausev
);
315 LOAD_FUNCPTR(alSourcePlay
);
316 LOAD_FUNCPTR(alSourceStop
);
317 LOAD_FUNCPTR(alSourceRewind
);
318 LOAD_FUNCPTR(alSourcePause
);
319 LOAD_FUNCPTR(alSourceQueueBuffers
);
320 LOAD_FUNCPTR(alSourceUnqueueBuffers
);
321 LOAD_FUNCPTR(alGenBuffers
);
322 LOAD_FUNCPTR(alDeleteBuffers
);
323 LOAD_FUNCPTR(alIsBuffer
);
324 LOAD_FUNCPTR(alBufferf
);
325 LOAD_FUNCPTR(alBuffer3f
);
326 LOAD_FUNCPTR(alBufferfv
);
327 LOAD_FUNCPTR(alBufferi
);
328 LOAD_FUNCPTR(alBuffer3i
);
329 LOAD_FUNCPTR(alBufferiv
);
330 LOAD_FUNCPTR(alGetBufferf
);
331 LOAD_FUNCPTR(alGetBuffer3f
);
332 LOAD_FUNCPTR(alGetBufferfv
);
333 LOAD_FUNCPTR(alGetBufferi
);
334 LOAD_FUNCPTR(alGetBuffer3i
);
335 LOAD_FUNCPTR(alGetBufferiv
);
336 LOAD_FUNCPTR(alBufferData
);
337 LOAD_FUNCPTR(alDopplerFactor
);
338 LOAD_FUNCPTR(alDopplerVelocity
);
339 LOAD_FUNCPTR(alDistanceModel
);
340 LOAD_FUNCPTR(alSpeedOfSound
);
344 WARN("Unloading openal\n");
345 if (openal_handle
!= RTLD_DEFAULT
)
346 wine_dlclose(openal_handle
, NULL
, 0);
347 openal_handle
= NULL
;
354 local_contexts
= alcIsExtensionPresent(NULL
, "ALC_EXT_thread_local_context");
357 set_context
= alcGetProcAddress(NULL
, "alcSetThreadContext");
358 get_context
= alcGetProcAddress(NULL
, "alcGetThreadContext");
359 if(!set_context
|| !get_context
)
361 ERR("TLS advertised but functions not found, disabling thread local context\n");
367 set_context
= alcMakeContextCurrent
;
368 get_context
= alcGetCurrentContext
;
373 const ALCchar
*DSOUND_getdevicestrings(void)
375 const ALCchar
*str
= NULL
;
378 multiple
= alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT");
380 str
= alcGetString(NULL
, ALC_ALL_DEVICES_SPECIFIER
);
382 str
= alcGetString(NULL
, ALC_DEVICE_SPECIFIER
);
386 const ALCchar
*DSOUND_getcapturedevicestrings(void)
388 const ALCchar
*str
= NULL
;
389 str
= alcGetString(NULL
, ALC_CAPTURE_DEVICE_SPECIFIER
);
393 /***************************************************************************
394 * GetDeviceID [DSOUND.9]
396 * Retrieves unique identifier of default device specified
399 * pGuidSrc [I] Address of device GUID.
400 * pGuidDest [O] Address to receive unique device GUID.
404 * Failure: DSERR_INVALIDPARAM
407 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
408 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
409 * DSDEVID_DefaultVoiceCapture.
410 * Returns pGuidSrc if pGuidSrc is a valid device or the device
411 * GUID for the specified constants.
413 HRESULT WINAPI
GetDeviceID(LPCGUID pGuidSrc
, LPGUID pGuidDest
)
415 TRACE("(%s,%p)\n", debugstr_guid(pGuidSrc
),pGuidDest
);
417 if ( pGuidSrc
== NULL
) {
418 WARN("invalid parameter: pGuidSrc == NULL\n");
419 return DSERR_INVALIDPARAM
;
422 if ( pGuidDest
== NULL
) {
423 WARN("invalid parameter: pGuidDest == NULL\n");
424 return DSERR_INVALIDPARAM
;
427 if ( IsEqualGUID( &DSDEVID_DefaultPlayback
, pGuidSrc
) ||
428 IsEqualGUID( &DSDEVID_DefaultVoicePlayback
, pGuidSrc
) ) {
429 *pGuidDest
= DSOUND_renderer_guid
;
430 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
434 if ( IsEqualGUID( &DSDEVID_DefaultCapture
, pGuidSrc
) ||
435 IsEqualGUID( &DSDEVID_DefaultVoiceCapture
, pGuidSrc
) ) {
436 *pGuidDest
= DSOUND_capture_guid
;
437 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
441 *pGuidDest
= *pGuidSrc
;
442 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
449 LPDSENUMCALLBACKA callA
;
453 static BOOL CALLBACK
a_to_w_callback(LPGUID guid
, LPCWSTR descW
, LPCWSTR modW
, LPVOID data
)
455 struct morecontext
*context
= data
;
456 char descA
[MAXPNAMELEN
], modA
[MAXPNAMELEN
];
458 WideCharToMultiByte(CP_ACP
, 0, descW
, -1, descA
, sizeof(descA
), NULL
, NULL
);
459 WideCharToMultiByte(CP_ACP
, 0, modW
, -1, modA
, sizeof(modA
), NULL
, NULL
);
461 return context
->callA(guid
, descA
, modA
, context
->data
);
464 /***************************************************************************
465 * DirectSoundEnumerateA [DSOUND.2]
467 * Enumerate all DirectSound drivers installed in the system
470 * lpDSEnumCallback [I] Address of callback function.
471 * lpContext [I] Address of user defined context passed to callback function.
475 * Failure: DSERR_INVALIDPARAM
477 HRESULT WINAPI
DirectSoundEnumerateA(
478 LPDSENUMCALLBACKA lpDSEnumCallback
,
481 struct morecontext context
;
483 if (lpDSEnumCallback
== NULL
) {
484 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
485 return DSERR_INVALIDPARAM
;
488 context
.callA
= lpDSEnumCallback
;
489 context
.data
= lpContext
;
491 return DirectSoundEnumerateW(a_to_w_callback
, &context
);
494 /***************************************************************************
495 * DirectSoundEnumerateW [DSOUND.3]
497 * Enumerate all DirectSound drivers installed in the system
500 * lpDSEnumCallback [I] Address of callback function.
501 * lpContext [I] Address of user defined context passed to callback function.
505 * Failure: DSERR_INVALIDPARAM
507 HRESULT WINAPI
DirectSoundEnumerateW(
508 LPDSENUMCALLBACKW lpDSEnumCallback
,
511 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
512 lpDSEnumCallback
, lpContext
);
514 if (lpDSEnumCallback
== NULL
) {
515 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
516 return DSERR_INVALIDPARAM
;
518 else if (openal_loaded
)
521 WCHAR wDesc
[MAXPNAMELEN
];
522 WCHAR wName
[MAXPNAMELEN
];
523 const ALCchar
*devstr
;
524 static const WCHAR empty
[] = { 0 };
525 EnterCriticalSection(&openal_crst
);
526 devstr
= DSOUND_getdevicestrings();
527 if (!devstr
|| !*devstr
)
530 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
531 "Primary Sound Driver","",lpContext
);
532 MultiByteToWideChar( CP_ACP
, 0, "Primary Sound Driver", -1,
533 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
) );
534 if (lpDSEnumCallback(NULL
, wDesc
, empty
, lpContext
) == FALSE
)
537 guid
= DSOUND_renderer_guid
;
539 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
540 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
541 MultiByteToWideChar( CP_UNIXCP
, 0, devstr
, -1,
542 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
)-1 );
543 wDesc
[sizeof(wDesc
)/sizeof(WCHAR
)-1] = 0;
544 MultiByteToWideChar( CP_ACP
, 0, "wineal.drv", -1,
545 wName
, sizeof(wName
)/sizeof(WCHAR
)-1 );
546 if (lpDSEnumCallback(&guid
, wDesc
, wName
, lpContext
) == FALSE
)
549 devstr
+= strlen(devstr
)+1;
553 LeaveCriticalSection(&openal_crst
);
557 ERR("Attempting to enumerate sound cards without OpenAL support\n");
558 ERR("Please recompile wine with OpenAL for sound to work\n");
563 /***************************************************************************
564 * DirectSoundCaptureEnumerateA [DSOUND.7]
566 * Enumerate all DirectSound drivers installed in the system.
569 * lpDSEnumCallback [I] Address of callback function.
570 * lpContext [I] Address of user defined context passed to callback function.
574 * Failure: DSERR_INVALIDPARAM
576 HRESULT WINAPI
DirectSoundCaptureEnumerateA(
577 LPDSENUMCALLBACKA lpDSEnumCallback
,
580 struct morecontext context
;
582 if (lpDSEnumCallback
== NULL
) {
583 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
584 return DSERR_INVALIDPARAM
;
587 context
.callA
= lpDSEnumCallback
;
588 context
.data
= lpContext
;
590 return DirectSoundCaptureEnumerateW(a_to_w_callback
, &context
);
593 /***************************************************************************
594 * DirectSoundCaptureEnumerateW [DSOUND.8]
596 * Enumerate all DirectSound drivers installed in the system.
599 * lpDSEnumCallback [I] Address of callback function.
600 * lpContext [I] Address of user defined context passed to callback function.
604 * Failure: DSERR_INVALIDPARAM
607 DirectSoundCaptureEnumerateW(
608 LPDSENUMCALLBACKW lpDSEnumCallback
,
611 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
613 if (lpDSEnumCallback
== NULL
) {
614 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
615 return DSERR_INVALIDPARAM
;
617 else if (openal_loaded
)
620 WCHAR wDesc
[MAXPNAMELEN
];
621 WCHAR wName
[MAXPNAMELEN
];
622 const ALCchar
*devstr
;
623 static const WCHAR empty
[] = { 0 };
625 EnterCriticalSection(&openal_crst
);
626 devstr
= DSOUND_getcapturedevicestrings();
627 if (!devstr
|| !*devstr
)
630 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
631 "Primary Sound Capture Driver","",lpContext
);
632 MultiByteToWideChar( CP_ACP
, 0, "Primary Sound Driver", -1,
633 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
) );
634 if (lpDSEnumCallback(NULL
, wDesc
, empty
, lpContext
) == FALSE
)
637 guid
= DSOUND_capture_guid
;
639 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
640 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
641 MultiByteToWideChar( CP_UNIXCP
, 0, devstr
, -1,
642 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
)-1 );
643 wDesc
[sizeof(wDesc
)/sizeof(WCHAR
)-1] = 0;
644 MultiByteToWideChar( CP_ACP
, 0, "wineal.drv", -1,
645 wName
, sizeof(wName
)/sizeof(WCHAR
)-1 );
646 if (lpDSEnumCallback(&guid
, wDesc
, wName
, lpContext
) == FALSE
)
649 devstr
+= strlen(devstr
)+1;
653 LeaveCriticalSection(&openal_crst
);
657 ERR("Attempting to enumerate sound cards without OpenAL support\n");
658 ERR("Please recompile wine with OpenAL for sound to work\n");
663 /*******************************************************************************
664 * DirectSoundCreate (DSOUND.1)
666 * Creates and initializes a DirectSound interface.
669 * lpcGUID [I] Address of the GUID that identifies the sound device.
670 * ppDS [O] Address of a variable to receive the interface pointer.
671 * pUnkOuter [I] Must be NULL.
675 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
676 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
678 HRESULT WINAPI
DirectSoundCreate(
686 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
689 WARN("invalid parameter: ppDS == NULL\n");
690 return DSERR_INVALIDPARAM
;
693 if (pUnkOuter
!= NULL
) {
694 WARN("invalid parameter: pUnkOuter != NULL\n");
696 return DSERR_INVALIDPARAM
;
699 hr
= DSOUND_Create(&IID_IDirectSound
, (void **)&pDS
);
701 hr
= IDirectSound_Initialize(pDS
, lpcGUID
);
703 if (hr
!= DSERR_ALREADYINITIALIZED
) {
704 IDirectSound_Release(pDS
);
716 /*******************************************************************************
717 * DirectSoundCreate8 (DSOUND.11)
719 * Creates and initializes a DirectSound8 interface.
722 * lpcGUID [I] Address of the GUID that identifies the sound device.
723 * ppDS [O] Address of a variable to receive the interface pointer.
724 * pUnkOuter [I] Must be NULL.
728 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
729 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
731 HRESULT WINAPI
DirectSoundCreate8(
733 LPDIRECTSOUND8
*ppDS
,
739 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
742 WARN("invalid parameter: ppDS == NULL\n");
743 return DSERR_INVALIDPARAM
;
746 if (pUnkOuter
!= NULL
) {
747 WARN("invalid parameter: pUnkOuter != NULL\n");
749 return DSERR_INVALIDPARAM
;
752 hr
= DSOUND_Create8(&IID_IDirectSound8
, (void**)&pDS
);
754 hr
= IDirectSound8_Initialize(pDS
, lpcGUID
);
756 if (hr
!= DSERR_ALREADYINITIALIZED
) {
757 IDirectSound8_Release(pDS
);
769 /***************************************************************************
770 * DirectSoundCaptureCreate [DSOUND.6]
772 * Create and initialize a DirectSoundCapture interface.
775 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
776 * lplpDSC [O] Address of a variable to receive the interface pointer.
777 * pUnkOuter [I] Must be NULL.
781 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
785 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
786 * or NULL for the default device or DSDEVID_DefaultCapture or
787 * DSDEVID_DefaultVoiceCapture.
789 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
791 HRESULT WINAPI
DirectSoundCaptureCreate(
793 IDirectSoundCapture
**ppDSC
,
799 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC
, pUnkOuter
);
803 WARN("invalid parameter: ppDSC == NULL\n");
804 return DSERR_INVALIDPARAM
;
810 WARN("invalid parameter: pUnkOuter != NULL\n");
811 return DSERR_NOAGGREGATION
;
814 hr
= DSOUND_CaptureCreate(&IID_IDirectSoundCapture
, &pDSC
);
818 hr
= IDirectSoundCapture_Initialize(*ppDSC
, lpcGUID
);
821 IDirectSoundCapture_Release(*ppDSC
);
829 /***************************************************************************
830 * DirectSoundCaptureCreate8 [DSOUND.12]
832 * Create and initialize a DirectSoundCapture interface.
835 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
836 * lplpDSC [O] Address of a variable to receive the interface pointer.
837 * pUnkOuter [I] Must be NULL.
841 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
845 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
846 * or NULL for the default device or DSDEVID_DefaultCapture or
847 * DSDEVID_DefaultVoiceCapture.
849 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
851 HRESULT WINAPI
DirectSoundCaptureCreate8(
853 IDirectSoundCapture8
**ppDSC8
,
859 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC8
, pUnkOuter
);
863 WARN("invalid parameter: ppDSC8 == NULL\n");
864 return DSERR_INVALIDPARAM
;
870 WARN("invalid parameter: pUnkOuter != NULL\n");
871 return DSERR_NOAGGREGATION
;
874 hr
= DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8
, &pDSC8
);
878 hr
= IDirectSoundCapture_Initialize(*ppDSC8
, lpcGUID
);
881 IDirectSoundCapture_Release(*ppDSC8
);
889 /*******************************************************************************
890 * DirectSound ClassFactory
893 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
896 IClassFactory IClassFactory_iface
;
899 FnCreateInstance pfnCreateInstance
;
902 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
904 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
907 static HRESULT WINAPI
DSCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
909 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
910 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
913 if (IsEqualIID(riid
, &IID_IUnknown
) ||
914 IsEqualIID(riid
, &IID_IClassFactory
))
917 IUnknown_AddRef(iface
);
921 return E_NOINTERFACE
;
924 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
926 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
927 ULONG ref
= InterlockedIncrement(&(This
->ref
));
928 TRACE("(%p) ref was %d\n", This
, ref
- 1);
932 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
934 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
935 ULONG ref
= InterlockedDecrement(&(This
->ref
));
936 TRACE("(%p) ref was %d\n", This
, ref
+ 1);
937 /* static class, won't be freed */
941 static HRESULT WINAPI
DSCF_CreateInstance(
942 LPCLASSFACTORY iface
,
947 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
948 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
951 return CLASS_E_NOAGGREGATION
;
954 WARN("invalid parameter\n");
955 return DSERR_INVALIDPARAM
;
958 return This
->pfnCreateInstance(riid
, ppobj
);
961 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
963 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
964 FIXME("(%p, %d) stub!\n", This
, dolock
);
968 static const IClassFactoryVtbl DSCF_Vtbl
= {
976 static IClassFactoryImpl DSOUND_CF
[] = {
977 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound
, DSOUND_Create
},
978 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound8
, DSOUND_Create8
},
979 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture
, DSOUND_CaptureCreate
},
980 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture8
, DSOUND_CaptureCreate8
},
981 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundFullDuplex
, DSOUND_FullDuplexCreate
},
982 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundPrivate
, IKsPrivatePropertySetImpl_Create
},
983 { {NULL
}, 0, NULL
, NULL
}
986 /*******************************************************************************
987 * DllGetClassObject [DSOUND.@]
988 * Retrieves class object from a DLL object
991 * Docs say returns STDAPI
994 * rclsid [I] CLSID for the class object
995 * riid [I] Reference to identifier of interface for class object
996 * ppv [O] Address of variable to receive interface pointer for riid
1000 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
1003 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
1006 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
1009 WARN("invalid parameter\n");
1010 return E_INVALIDARG
;
1015 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
1016 !IsEqualIID(riid
, &IID_IUnknown
)) {
1017 WARN("no interface for %s\n", debugstr_guid(riid
));
1018 return E_NOINTERFACE
;
1021 while (NULL
!= DSOUND_CF
[i
].rclsid
) {
1022 if (IsEqualGUID(rclsid
, DSOUND_CF
[i
].rclsid
)) {
1023 DSCF_AddRef(&DSOUND_CF
[i
].IClassFactory_iface
);
1024 *ppv
= &DSOUND_CF
[i
];
1030 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
1031 debugstr_guid(riid
), ppv
);
1032 return CLASS_E_CLASSNOTAVAILABLE
;
1036 /*******************************************************************************
1037 * DllCanUnloadNow [DSOUND.4]
1038 * Determines whether the DLL is in use.
1044 HRESULT WINAPI
DllCanUnloadNow(void)
1046 FIXME("(void): stub\n");
1050 /***********************************************************************
1051 * DllMain (DSOUND.init)
1053 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1055 TRACE("(%p, %d, %p)\n", hInstDLL
, fdwReason
, lpvReserved
);
1057 switch (fdwReason
) {
1058 case DLL_PROCESS_ATTACH
:
1059 TRACE("DLL_PROCESS_ATTACH\n");
1061 DisableThreadLibraryCalls(hInstDLL
);
1062 /* Increase refcount on dsound by 1 */
1063 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
1065 case DLL_PROCESS_DETACH
:
1066 TRACE("DLL_PROCESS_DETACH\n");
1067 #ifdef SONAME_LIBOPENAL
1069 wine_dlclose(openal_handle
, NULL
, 0);
1070 #endif /*SONAME_LIBOPENAL*/
1073 TRACE("UNKNOWN REASON\n");