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);
81 static HINSTANCE instance
;
83 const GUID DSOUND_renderer_guid
= { 0xbd6dd71a, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
84 const GUID DSOUND_capture_guid
= { 0xbd6dd71b, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
86 const IID DSPROPSETID_EAX20_ListenerProperties
= {
87 0x0306a6a8, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
90 const EAXLISTENERPROPERTIES EnvironmentDefaults
[EAX_ENVIRONMENT_COUNT
] =
92 REVERB_PRESET_GENERIC
,
93 REVERB_PRESET_PADDEDCELL
,
95 REVERB_PRESET_BATHROOM
,
96 REVERB_PRESET_LIVINGROOM
,
97 REVERB_PRESET_STONEROOM
,
98 REVERB_PRESET_AUDITORIUM
,
99 REVERB_PRESET_CONCERTHALL
,
102 REVERB_PRESET_HANGAR
,
103 REVERB_PRESET_CARPETEDHALLWAY
,
104 REVERB_PRESET_HALLWAY
,
105 REVERB_PRESET_STONECORRIDOR
,
107 REVERB_PRESET_FOREST
,
109 REVERB_PRESET_MOUNTAINS
,
110 REVERB_PRESET_QUARRY
,
112 REVERB_PRESET_PARKINGLOT
,
113 REVERB_PRESET_SEWERPIPE
,
114 REVERB_PRESET_UNDERWATER
,
115 REVERB_PRESET_DRUGGED
,
117 REVERB_PRESET_PSYCHOTIC
120 static CRITICAL_SECTION_DEBUG openal_crst_debug
=
123 { &openal_crst_debug
.ProcessLocksList
,
124 &openal_crst_debug
.ProcessLocksList
},
125 0, 0, { (DWORD_PTR
)(__FILE__
": openal_crst_debug") }
127 CRITICAL_SECTION openal_crst
= { &openal_crst_debug
, -1, 0, 0, 0, 0 };
129 int openal_loaded
= 0;
130 #ifdef SONAME_LIBOPENAL
131 static void *openal_handle
= NULL
;
132 LPALCCREATECONTEXT palcCreateContext
= NULL
;
133 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent
= NULL
;
134 LPALCPROCESSCONTEXT palcProcessContext
= NULL
;
135 LPALCSUSPENDCONTEXT palcSuspendContext
= NULL
;
136 LPALCDESTROYCONTEXT palcDestroyContext
= NULL
;
137 LPALCGETCURRENTCONTEXT palcGetCurrentContext
= NULL
;
138 LPALCGETCONTEXTSDEVICE palcGetContextsDevice
= NULL
;
139 LPALCOPENDEVICE palcOpenDevice
= NULL
;
140 LPALCCLOSEDEVICE palcCloseDevice
= NULL
;
141 LPALCGETERROR palcGetError
= NULL
;
142 LPALCISEXTENSIONPRESENT palcIsExtensionPresent
= NULL
;
143 LPALCGETPROCADDRESS palcGetProcAddress
= NULL
;
144 LPALCGETENUMVALUE palcGetEnumValue
= NULL
;
145 LPALCGETSTRING palcGetString
= NULL
;
146 LPALCGETINTEGERV palcGetIntegerv
= NULL
;
147 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice
= NULL
;
148 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice
= NULL
;
149 LPALCCAPTURESTART palcCaptureStart
= NULL
;
150 LPALCCAPTURESTOP palcCaptureStop
= NULL
;
151 LPALCCAPTURESAMPLES palcCaptureSamples
= NULL
;
152 LPALENABLE palEnable
= NULL
;
153 LPALDISABLE palDisable
= NULL
;
154 LPALISENABLED palIsEnabled
= NULL
;
155 LPALGETSTRING palGetString
= NULL
;
156 LPALGETBOOLEANV palGetBooleanv
= NULL
;
157 LPALGETINTEGERV palGetIntegerv
= NULL
;
158 LPALGETFLOATV palGetFloatv
= NULL
;
159 LPALGETDOUBLEV palGetDoublev
= NULL
;
160 LPALGETBOOLEAN palGetBoolean
= NULL
;
161 LPALGETINTEGER palGetInteger
= NULL
;
162 LPALGETFLOAT palGetFloat
= NULL
;
163 LPALGETDOUBLE palGetDouble
= NULL
;
164 LPALGETERROR palGetError
= NULL
;
165 LPALISEXTENSIONPRESENT palIsExtensionPresent
= NULL
;
166 LPALGETPROCADDRESS palGetProcAddress
= NULL
;
167 LPALGETENUMVALUE palGetEnumValue
= NULL
;
168 LPALLISTENERF palListenerf
= NULL
;
169 LPALLISTENER3F palListener3f
= NULL
;
170 LPALLISTENERFV palListenerfv
= NULL
;
171 LPALLISTENERI palListeneri
= NULL
;
172 LPALLISTENER3I palListener3i
= NULL
;
173 LPALLISTENERIV palListeneriv
= NULL
;
174 LPALGETLISTENERF palGetListenerf
= NULL
;
175 LPALGETLISTENER3F palGetListener3f
= NULL
;
176 LPALGETLISTENERFV palGetListenerfv
= NULL
;
177 LPALGETLISTENERI palGetListeneri
= NULL
;
178 LPALGETLISTENER3I palGetListener3i
= NULL
;
179 LPALGETLISTENERIV palGetListeneriv
= NULL
;
180 LPALGENSOURCES palGenSources
= NULL
;
181 LPALDELETESOURCES palDeleteSources
= NULL
;
182 LPALISSOURCE palIsSource
= NULL
;
183 LPALSOURCEF palSourcef
= NULL
;
184 LPALSOURCE3F palSource3f
= NULL
;
185 LPALSOURCEFV palSourcefv
= NULL
;
186 LPALSOURCEI palSourcei
= NULL
;
187 LPALSOURCE3I palSource3i
= NULL
;
188 LPALSOURCEIV palSourceiv
= NULL
;
189 LPALGETSOURCEF palGetSourcef
= NULL
;
190 LPALGETSOURCE3F palGetSource3f
= NULL
;
191 LPALGETSOURCEFV palGetSourcefv
= NULL
;
192 LPALGETSOURCEI palGetSourcei
= NULL
;
193 LPALGETSOURCE3I palGetSource3i
= NULL
;
194 LPALGETSOURCEIV palGetSourceiv
= NULL
;
195 LPALSOURCEPLAYV palSourcePlayv
= NULL
;
196 LPALSOURCESTOPV palSourceStopv
= NULL
;
197 LPALSOURCEREWINDV palSourceRewindv
= NULL
;
198 LPALSOURCEPAUSEV palSourcePausev
= NULL
;
199 LPALSOURCEPLAY palSourcePlay
= NULL
;
200 LPALSOURCESTOP palSourceStop
= NULL
;
201 LPALSOURCEREWIND palSourceRewind
= NULL
;
202 LPALSOURCEPAUSE palSourcePause
= NULL
;
203 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers
= NULL
;
204 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers
= NULL
;
205 LPALGENBUFFERS palGenBuffers
= NULL
;
206 LPALDELETEBUFFERS palDeleteBuffers
= NULL
;
207 LPALISBUFFER palIsBuffer
= NULL
;
208 LPALBUFFERF palBufferf
= NULL
;
209 LPALBUFFER3F palBuffer3f
= NULL
;
210 LPALBUFFERFV palBufferfv
= NULL
;
211 LPALBUFFERI palBufferi
= NULL
;
212 LPALBUFFER3I palBuffer3i
= NULL
;
213 LPALBUFFERIV palBufferiv
= NULL
;
214 LPALGETBUFFERF palGetBufferf
= NULL
;
215 LPALGETBUFFER3F palGetBuffer3f
= NULL
;
216 LPALGETBUFFERFV palGetBufferfv
= NULL
;
217 LPALGETBUFFERI palGetBufferi
= NULL
;
218 LPALGETBUFFER3I palGetBuffer3i
= NULL
;
219 LPALGETBUFFERIV palGetBufferiv
= NULL
;
220 LPALBUFFERDATA palBufferData
= NULL
;
221 LPALDOPPLERFACTOR palDopplerFactor
= NULL
;
222 LPALDOPPLERVELOCITY palDopplerVelocity
= NULL
;
223 LPALDISTANCEMODEL palDistanceModel
= NULL
;
224 LPALSPEEDOFSOUND palSpeedOfSound
= NULL
;
227 LPALCMAKECONTEXTCURRENT set_context
;
228 LPALCGETCURRENTCONTEXT get_context
;
231 static void load_libopenal(void)
234 const char *str
= getenv("DSOAL_LOGLEVEL");
236 LogLevel
= atoi(str
);
237 #elif defined(SONAME_LIBOPENAL)
241 openal_handle
= wine_dlopen(SONAME_LIBOPENAL
, RTLD_NOW
, error
, sizeof(error
));
243 ERR("Couldn't load " SONAME_LIBOPENAL
": %s\n", error
);
244 #define LOAD_FUNCPTR(f) \
245 if((p##f = wine_dlsym(openal_handle, #f, NULL, 0)) == NULL) { \
246 ERR("Couldn't lookup %s in " SONAME_LIBOPENAL "\n", #f); \
250 LOAD_FUNCPTR(alcCreateContext
);
251 LOAD_FUNCPTR(alcMakeContextCurrent
);
252 LOAD_FUNCPTR(alcProcessContext
);
253 LOAD_FUNCPTR(alcSuspendContext
);
254 LOAD_FUNCPTR(alcDestroyContext
);
255 LOAD_FUNCPTR(alcGetCurrentContext
);
256 LOAD_FUNCPTR(alcGetContextsDevice
);
257 LOAD_FUNCPTR(alcOpenDevice
);
258 LOAD_FUNCPTR(alcCloseDevice
);
259 LOAD_FUNCPTR(alcGetError
);
260 LOAD_FUNCPTR(alcIsExtensionPresent
);
261 LOAD_FUNCPTR(alcGetProcAddress
);
262 LOAD_FUNCPTR(alcGetEnumValue
);
263 LOAD_FUNCPTR(alcGetString
);
264 LOAD_FUNCPTR(alcGetIntegerv
);
265 LOAD_FUNCPTR(alcCaptureOpenDevice
);
266 LOAD_FUNCPTR(alcCaptureCloseDevice
);
267 LOAD_FUNCPTR(alcCaptureStart
);
268 LOAD_FUNCPTR(alcCaptureStop
);
269 LOAD_FUNCPTR(alcCaptureSamples
);
270 LOAD_FUNCPTR(alEnable
);
271 LOAD_FUNCPTR(alDisable
);
272 LOAD_FUNCPTR(alIsEnabled
);
273 LOAD_FUNCPTR(alGetString
);
274 LOAD_FUNCPTR(alGetBooleanv
);
275 LOAD_FUNCPTR(alGetIntegerv
);
276 LOAD_FUNCPTR(alGetFloatv
);
277 LOAD_FUNCPTR(alGetDoublev
);
278 LOAD_FUNCPTR(alGetBoolean
);
279 LOAD_FUNCPTR(alGetInteger
);
280 LOAD_FUNCPTR(alGetFloat
);
281 LOAD_FUNCPTR(alGetDouble
);
282 LOAD_FUNCPTR(alGetError
);
283 LOAD_FUNCPTR(alIsExtensionPresent
);
284 LOAD_FUNCPTR(alGetProcAddress
);
285 LOAD_FUNCPTR(alGetEnumValue
);
286 LOAD_FUNCPTR(alListenerf
);
287 LOAD_FUNCPTR(alListener3f
);
288 LOAD_FUNCPTR(alListenerfv
);
289 LOAD_FUNCPTR(alListeneri
);
290 LOAD_FUNCPTR(alListener3i
);
291 LOAD_FUNCPTR(alListeneriv
);
292 LOAD_FUNCPTR(alGetListenerf
);
293 LOAD_FUNCPTR(alGetListener3f
);
294 LOAD_FUNCPTR(alGetListenerfv
);
295 LOAD_FUNCPTR(alGetListeneri
);
296 LOAD_FUNCPTR(alGetListener3i
);
297 LOAD_FUNCPTR(alGetListeneriv
);
298 LOAD_FUNCPTR(alGenSources
);
299 LOAD_FUNCPTR(alDeleteSources
);
300 LOAD_FUNCPTR(alIsSource
);
301 LOAD_FUNCPTR(alSourcef
);
302 LOAD_FUNCPTR(alSource3f
);
303 LOAD_FUNCPTR(alSourcefv
);
304 LOAD_FUNCPTR(alSourcei
);
305 LOAD_FUNCPTR(alSource3i
);
306 LOAD_FUNCPTR(alSourceiv
);
307 LOAD_FUNCPTR(alGetSourcef
);
308 LOAD_FUNCPTR(alGetSource3f
);
309 LOAD_FUNCPTR(alGetSourcefv
);
310 LOAD_FUNCPTR(alGetSourcei
);
311 LOAD_FUNCPTR(alGetSource3i
);
312 LOAD_FUNCPTR(alGetSourceiv
);
313 LOAD_FUNCPTR(alSourcePlayv
);
314 LOAD_FUNCPTR(alSourceStopv
);
315 LOAD_FUNCPTR(alSourceRewindv
);
316 LOAD_FUNCPTR(alSourcePausev
);
317 LOAD_FUNCPTR(alSourcePlay
);
318 LOAD_FUNCPTR(alSourceStop
);
319 LOAD_FUNCPTR(alSourceRewind
);
320 LOAD_FUNCPTR(alSourcePause
);
321 LOAD_FUNCPTR(alSourceQueueBuffers
);
322 LOAD_FUNCPTR(alSourceUnqueueBuffers
);
323 LOAD_FUNCPTR(alGenBuffers
);
324 LOAD_FUNCPTR(alDeleteBuffers
);
325 LOAD_FUNCPTR(alIsBuffer
);
326 LOAD_FUNCPTR(alBufferf
);
327 LOAD_FUNCPTR(alBuffer3f
);
328 LOAD_FUNCPTR(alBufferfv
);
329 LOAD_FUNCPTR(alBufferi
);
330 LOAD_FUNCPTR(alBuffer3i
);
331 LOAD_FUNCPTR(alBufferiv
);
332 LOAD_FUNCPTR(alGetBufferf
);
333 LOAD_FUNCPTR(alGetBuffer3f
);
334 LOAD_FUNCPTR(alGetBufferfv
);
335 LOAD_FUNCPTR(alGetBufferi
);
336 LOAD_FUNCPTR(alGetBuffer3i
);
337 LOAD_FUNCPTR(alGetBufferiv
);
338 LOAD_FUNCPTR(alBufferData
);
339 LOAD_FUNCPTR(alDopplerFactor
);
340 LOAD_FUNCPTR(alDopplerVelocity
);
341 LOAD_FUNCPTR(alDistanceModel
);
342 LOAD_FUNCPTR(alSpeedOfSound
);
346 WARN("Unloading openal\n");
347 if (openal_handle
!= RTLD_DEFAULT
)
348 wine_dlclose(openal_handle
, NULL
, 0);
349 openal_handle
= NULL
;
356 local_contexts
= alcIsExtensionPresent(NULL
, "ALC_EXT_thread_local_context");
359 set_context
= alcGetProcAddress(NULL
, "alcSetThreadContext");
360 get_context
= alcGetProcAddress(NULL
, "alcGetThreadContext");
361 if(!set_context
|| !get_context
)
363 ERR("TLS advertised but functions not found, disabling thread local context\n");
369 set_context
= alcMakeContextCurrent
;
370 get_context
= alcGetCurrentContext
;
375 const ALCchar
*DSOUND_getdevicestrings(void)
377 const ALCchar
*str
= NULL
;
380 multiple
= alcIsExtensionPresent(NULL
, "ALC_ENUMERATE_ALL_EXT");
382 str
= alcGetString(NULL
, ALC_ALL_DEVICES_SPECIFIER
);
384 str
= alcGetString(NULL
, ALC_DEVICE_SPECIFIER
);
388 const ALCchar
*DSOUND_getcapturedevicestrings(void)
390 const ALCchar
*str
= NULL
;
391 str
= alcGetString(NULL
, ALC_CAPTURE_DEVICE_SPECIFIER
);
395 /***************************************************************************
396 * GetDeviceID [DSOUND.9]
398 * Retrieves unique identifier of default device specified
401 * pGuidSrc [I] Address of device GUID.
402 * pGuidDest [O] Address to receive unique device GUID.
406 * Failure: DSERR_INVALIDPARAM
409 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
410 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
411 * DSDEVID_DefaultVoiceCapture.
412 * Returns pGuidSrc if pGuidSrc is a valid device or the device
413 * GUID for the specified constants.
415 HRESULT WINAPI
GetDeviceID(LPCGUID pGuidSrc
, LPGUID pGuidDest
)
417 TRACE("(%s,%p)\n", debugstr_guid(pGuidSrc
),pGuidDest
);
419 if ( pGuidSrc
== NULL
) {
420 WARN("invalid parameter: pGuidSrc == NULL\n");
421 return DSERR_INVALIDPARAM
;
424 if ( pGuidDest
== NULL
) {
425 WARN("invalid parameter: pGuidDest == NULL\n");
426 return DSERR_INVALIDPARAM
;
429 if ( IsEqualGUID( &DSDEVID_DefaultPlayback
, pGuidSrc
) ||
430 IsEqualGUID( &DSDEVID_DefaultVoicePlayback
, pGuidSrc
) ) {
431 *pGuidDest
= DSOUND_renderer_guid
;
432 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
436 if ( IsEqualGUID( &DSDEVID_DefaultCapture
, pGuidSrc
) ||
437 IsEqualGUID( &DSDEVID_DefaultVoiceCapture
, pGuidSrc
) ) {
438 *pGuidDest
= DSOUND_capture_guid
;
439 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
443 *pGuidDest
= *pGuidSrc
;
444 TRACE("returns %s\n", debugstr_guid(pGuidDest
));
451 LPDSENUMCALLBACKW callW
;
455 static BOOL CALLBACK
w_to_a_callback(LPGUID guid
, LPCSTR descA
, LPCSTR modA
, LPVOID data
)
457 struct morecontext
*context
= data
;
458 WCHAR descW
[MAXPNAMELEN
], modW
[MAXPNAMELEN
];
460 MultiByteToWideChar(CP_ACP
, 0, descA
, -1, descW
, sizeof(descW
)/sizeof(descW
[0]));
461 MultiByteToWideChar(CP_ACP
, 0, modA
, -1, modW
, sizeof(modW
)/sizeof(modW
[0]));
463 return context
->callW(guid
, descW
, modW
, context
->data
);
466 /***************************************************************************
467 * DirectSoundEnumerateA [DSOUND.2]
469 * Enumerate all DirectSound drivers installed in the system
472 * lpDSEnumCallback [I] Address of callback function.
473 * lpContext [I] Address of user defined context passed to callback function.
477 * Failure: DSERR_INVALIDPARAM
479 HRESULT WINAPI
DirectSoundEnumerateA(
480 LPDSENUMCALLBACKA lpDSEnumCallback
,
483 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
484 lpDSEnumCallback
, lpContext
);
486 if (lpDSEnumCallback
== NULL
) {
487 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
488 return DSERR_INVALIDPARAM
;
490 else if (openal_loaded
)
492 const ALCchar
*devstr
;
495 EnterCriticalSection(&openal_crst
);
496 devstr
= DSOUND_getdevicestrings();
497 if(!devstr
|| !*devstr
)
500 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
501 "Primary Sound Driver","",lpContext
);
502 if(lpDSEnumCallback(NULL
, "Primary Sound Driver", "", lpContext
) == FALSE
)
505 guid
= DSOUND_renderer_guid
;
507 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
508 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
509 if(lpDSEnumCallback(&guid
, devstr
, "wineal.drv", lpContext
) == FALSE
)
512 devstr
+= strlen(devstr
)+1;
515 LeaveCriticalSection(&openal_crst
);
519 ERR("Attempting to enumerate sound cards without OpenAL support\n");
520 ERR("Please recompile wine with OpenAL for sound to work\n");
525 /***************************************************************************
526 * DirectSoundEnumerateW [DSOUND.3]
528 * Enumerate all DirectSound drivers installed in the system
531 * lpDSEnumCallback [I] Address of callback function.
532 * lpContext [I] Address of user defined context passed to callback function.
536 * Failure: DSERR_INVALIDPARAM
538 HRESULT WINAPI
DirectSoundEnumerateW(
539 LPDSENUMCALLBACKW lpDSEnumCallback
,
542 struct morecontext context
;
544 if(lpDSEnumCallback
== NULL
) {
545 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
546 return DSERR_INVALIDPARAM
;
549 context
.callW
= lpDSEnumCallback
;
550 context
.data
= lpContext
;
552 return DirectSoundEnumerateA(w_to_a_callback
, &context
);
555 /***************************************************************************
556 * DirectSoundCaptureEnumerateA [DSOUND.7]
558 * Enumerate all DirectSound drivers installed in the system.
561 * lpDSEnumCallback [I] Address of callback function.
562 * lpContext [I] Address of user defined context passed to callback function.
566 * Failure: DSERR_INVALIDPARAM
568 HRESULT WINAPI
DirectSoundCaptureEnumerateA(
569 LPDSENUMCALLBACKA lpDSEnumCallback
,
572 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
574 if (lpDSEnumCallback
== NULL
) {
575 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
576 return DSERR_INVALIDPARAM
;
578 else if (openal_loaded
)
580 const ALCchar
*devstr
;
583 EnterCriticalSection(&openal_crst
);
584 devstr
= DSOUND_getcapturedevicestrings();
585 if(!devstr
|| !*devstr
)
588 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
589 "Primary Sound Capture Driver","",lpContext
);
590 if(lpDSEnumCallback(NULL
, "Primary Sound Driver", "", lpContext
) == FALSE
)
593 guid
= DSOUND_capture_guid
;
595 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
596 debugstr_guid(&guid
),devstr
,"wineal.drv",lpContext
);
597 if(lpDSEnumCallback(&guid
, devstr
, "wineal.drv", lpContext
) == FALSE
)
600 devstr
+= strlen(devstr
)+1;
603 LeaveCriticalSection(&openal_crst
);
607 ERR("Attempting to enumerate sound cards without OpenAL support\n");
608 ERR("Please recompile wine with OpenAL for sound to work\n");
613 /***************************************************************************
614 * DirectSoundCaptureEnumerateW [DSOUND.8]
616 * Enumerate all DirectSound drivers installed in the system.
619 * lpDSEnumCallback [I] Address of callback function.
620 * lpContext [I] Address of user defined context passed to callback function.
624 * Failure: DSERR_INVALIDPARAM
627 DirectSoundCaptureEnumerateW(
628 LPDSENUMCALLBACKW lpDSEnumCallback
,
631 struct morecontext context
;
633 if (lpDSEnumCallback
== NULL
) {
634 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
635 return DSERR_INVALIDPARAM
;
638 context
.callW
= lpDSEnumCallback
;
639 context
.data
= lpContext
;
641 return DirectSoundCaptureEnumerateA(w_to_a_callback
, &context
);
644 /*******************************************************************************
645 * DirectSoundCreate (DSOUND.1)
647 * Creates and initializes a DirectSound interface.
650 * lpcGUID [I] Address of the GUID that identifies the sound device.
651 * ppDS [O] Address of a variable to receive the interface pointer.
652 * pUnkOuter [I] Must be NULL.
656 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
657 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
659 HRESULT WINAPI
DirectSoundCreate(
667 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
670 WARN("invalid parameter: ppDS == NULL\n");
671 return DSERR_INVALIDPARAM
;
674 if (pUnkOuter
!= NULL
) {
675 WARN("invalid parameter: pUnkOuter != NULL\n");
677 return DSERR_INVALIDPARAM
;
680 hr
= DSOUND_Create(&IID_IDirectSound
, (void **)&pDS
);
682 hr
= IDirectSound_Initialize(pDS
, lpcGUID
);
684 if (hr
!= DSERR_ALREADYINITIALIZED
) {
685 IDirectSound_Release(pDS
);
697 /*******************************************************************************
698 * DirectSoundCreate8 (DSOUND.11)
700 * Creates and initializes a DirectSound8 interface.
703 * lpcGUID [I] Address of the GUID that identifies the sound device.
704 * ppDS [O] Address of a variable to receive the interface pointer.
705 * pUnkOuter [I] Must be NULL.
709 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
710 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
712 HRESULT WINAPI
DirectSoundCreate8(
714 LPDIRECTSOUND8
*ppDS
,
720 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
723 WARN("invalid parameter: ppDS == NULL\n");
724 return DSERR_INVALIDPARAM
;
727 if (pUnkOuter
!= NULL
) {
728 WARN("invalid parameter: pUnkOuter != NULL\n");
730 return DSERR_INVALIDPARAM
;
733 hr
= DSOUND_Create8(&IID_IDirectSound8
, (void**)&pDS
);
735 hr
= IDirectSound8_Initialize(pDS
, lpcGUID
);
737 if (hr
!= DSERR_ALREADYINITIALIZED
) {
738 IDirectSound8_Release(pDS
);
750 /***************************************************************************
751 * DirectSoundCaptureCreate [DSOUND.6]
753 * Create and initialize a DirectSoundCapture interface.
756 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
757 * lplpDSC [O] Address of a variable to receive the interface pointer.
758 * pUnkOuter [I] Must be NULL.
762 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
766 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
767 * or NULL for the default device or DSDEVID_DefaultCapture or
768 * DSDEVID_DefaultVoiceCapture.
770 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
772 HRESULT WINAPI
DirectSoundCaptureCreate(
774 IDirectSoundCapture
**ppDSC
,
780 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC
, pUnkOuter
);
784 WARN("invalid parameter: ppDSC == NULL\n");
785 return DSERR_INVALIDPARAM
;
791 WARN("invalid parameter: pUnkOuter != NULL\n");
792 return DSERR_NOAGGREGATION
;
795 hr
= DSOUND_CaptureCreate(&IID_IDirectSoundCapture
, &pDSC
);
799 hr
= IDirectSoundCapture_Initialize(*ppDSC
, lpcGUID
);
802 IDirectSoundCapture_Release(*ppDSC
);
810 /***************************************************************************
811 * DirectSoundCaptureCreate8 [DSOUND.12]
813 * Create and initialize a DirectSoundCapture interface.
816 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
817 * lplpDSC [O] Address of a variable to receive the interface pointer.
818 * pUnkOuter [I] Must be NULL.
822 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
826 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
827 * or NULL for the default device or DSDEVID_DefaultCapture or
828 * DSDEVID_DefaultVoiceCapture.
830 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
832 HRESULT WINAPI
DirectSoundCaptureCreate8(
834 IDirectSoundCapture8
**ppDSC8
,
840 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID
), ppDSC8
, pUnkOuter
);
844 WARN("invalid parameter: ppDSC8 == NULL\n");
845 return DSERR_INVALIDPARAM
;
851 WARN("invalid parameter: pUnkOuter != NULL\n");
852 return DSERR_NOAGGREGATION
;
855 hr
= DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8
, &pDSC8
);
859 hr
= IDirectSoundCapture_Initialize(*ppDSC8
, lpcGUID
);
862 IDirectSoundCapture_Release(*ppDSC8
);
870 /*******************************************************************************
871 * DirectSound ClassFactory
874 typedef HRESULT (*FnCreateInstance
)(REFIID riid
, LPVOID
*ppobj
);
877 IClassFactory IClassFactory_iface
;
880 FnCreateInstance pfnCreateInstance
;
883 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
885 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
888 static HRESULT WINAPI
DSCF_QueryInterface(LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppobj
)
890 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
891 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
894 if (IsEqualIID(riid
, &IID_IUnknown
) ||
895 IsEqualIID(riid
, &IID_IClassFactory
))
898 IUnknown_AddRef(iface
);
902 return E_NOINTERFACE
;
905 static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface
)
907 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
908 ULONG ref
= InterlockedIncrement(&(This
->ref
));
909 TRACE("(%p) ref was %"LONGFMT
"u\n", This
, ref
- 1);
913 static ULONG WINAPI
DSCF_Release(LPCLASSFACTORY iface
)
915 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
916 ULONG ref
= InterlockedDecrement(&(This
->ref
));
917 TRACE("(%p) ref was %"LONGFMT
"u\n", This
, ref
+ 1);
918 /* static class, won't be freed */
922 static HRESULT WINAPI
DSCF_CreateInstance(
923 LPCLASSFACTORY iface
,
928 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
929 TRACE("(%p, %p, %s, %p)\n", This
, pOuter
, debugstr_guid(riid
), ppobj
);
932 return CLASS_E_NOAGGREGATION
;
935 WARN("invalid parameter\n");
936 return DSERR_INVALIDPARAM
;
939 return This
->pfnCreateInstance(riid
, ppobj
);
942 static HRESULT WINAPI
DSCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
944 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
945 FIXME("(%p, %d) stub!\n", This
, dolock
);
949 static const IClassFactoryVtbl DSCF_Vtbl
= {
957 static IClassFactoryImpl DSOUND_CF
[] = {
958 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound
, DSOUND_Create
},
959 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSound8
, DSOUND_Create8
},
960 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture
, DSOUND_CaptureCreate
},
961 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundCapture8
, DSOUND_CaptureCreate8
},
962 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundFullDuplex
, DSOUND_FullDuplexCreate
},
963 { {(IClassFactoryVtbl
*)&DSCF_Vtbl
}, 1, &CLSID_DirectSoundPrivate
, IKsPrivatePropertySetImpl_Create
},
964 { {NULL
}, 0, NULL
, NULL
}
967 /*******************************************************************************
968 * DllGetClassObject [DSOUND.@]
969 * Retrieves class object from a DLL object
972 * Docs say returns STDAPI
975 * rclsid [I] CLSID for the class object
976 * riid [I] Reference to identifier of interface for class object
977 * ppv [O] Address of variable to receive interface pointer for riid
981 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
984 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
987 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
990 WARN("invalid parameter\n");
996 if (!IsEqualIID(riid
, &IID_IClassFactory
) &&
997 !IsEqualIID(riid
, &IID_IUnknown
)) {
998 WARN("no interface for %s\n", debugstr_guid(riid
));
999 return E_NOINTERFACE
;
1002 while (NULL
!= DSOUND_CF
[i
].rclsid
) {
1003 if (IsEqualGUID(rclsid
, DSOUND_CF
[i
].rclsid
)) {
1004 DSCF_AddRef(&DSOUND_CF
[i
].IClassFactory_iface
);
1005 *ppv
= &DSOUND_CF
[i
];
1011 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid
),
1012 debugstr_guid(riid
), ppv
);
1013 return CLASS_E_CLASSNOTAVAILABLE
;
1017 /*******************************************************************************
1018 * DllCanUnloadNow [DSOUND.4]
1019 * Determines whether the DLL is in use.
1025 HRESULT WINAPI
DllCanUnloadNow(void)
1027 FIXME("(void): stub\n");
1031 /***********************************************************************
1032 * DllMain (DSOUND.init)
1034 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1036 TRACE("(%p, %"LONGFMT
"u, %p)\n", hInstDLL
, fdwReason
, lpvReserved
);
1040 case DLL_PROCESS_ATTACH
:
1041 TRACE("DLL_PROCESS_ATTACH\n");
1042 instance
= hInstDLL
;
1044 DisableThreadLibraryCalls(hInstDLL
);
1045 /* Increase refcount on dsound by 1 */
1046 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (LPCWSTR
)hInstDLL
, &hInstDLL
);
1048 case DLL_PROCESS_DETACH
:
1049 TRACE("DLL_PROCESS_DETACH\n");
1050 #ifdef SONAME_LIBOPENAL
1052 wine_dlclose(openal_handle
, NULL
, 0);
1053 #endif /*SONAME_LIBOPENAL*/
1056 TRACE("UNKNOWN REASON\n");
1063 /***********************************************************************
1064 * DllRegisterServer (DSOUND.@)
1066 HRESULT WINAPI
DllRegisterServer(void)
1068 return __wine_register_resources(instance
, NULL
);
1071 /***********************************************************************
1072 * DllUnregisterServer (DSOUND.@)
1074 HRESULT WINAPI
DllUnregisterServer(void)
1076 return __wine_unregister_resources(instance
, NULL
);