Add EAX 2.0 buffer properties
[dsound-openal.git] / dsound_main.c
blob4b593de5ad7df248d4007f748406f7fc136f2824
1 /* DirectSound
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.
24 * TODO:
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
35 #include <stdarg.h>
37 #ifdef __WINESRC__
39 #include "wine/library.h"
41 #define COBJMACROS
42 #define NONAMELESSSTRUCT
43 #define NONAMELESSUNION
44 #include "windef.h"
45 #include "winbase.h"
46 #include "winuser.h"
47 #include "winnls.h"
48 #include "winreg.h"
49 #include "mmsystem.h"
50 #include "winternl.h"
51 #include "mmddk.h"
52 #include "wine/debug.h"
53 #include "dsound.h"
54 #include "dsconf.h"
55 #include "ks.h"
56 #include "initguid.h"
57 #include "ksmedia.h"
58 #include "rpcproxy.h"
60 #include "dsound_private.h"
62 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
64 #else
66 #define WINVER 0x0600
67 #include <windows.h>
68 #include <dsound.h>
70 #include "dsound_private.h"
72 #ifndef CP_UNIXCP
73 #define CP_UNIXCP 65010
74 #endif
76 DEFINE_GUID(CLSID_DirectSoundPrivate,0x11ab3ec0,0x25ec,0x11d1,0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca);
78 int LogLevel = 1;
80 #endif
82 static HINSTANCE instance;
84 const GUID DSOUND_renderer_guid = { 0xbd6dd71a, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
85 const GUID DSOUND_capture_guid = { 0xbd6dd71b, 0x3deb, 0x11d1, { 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 } };
87 const IID DSPROPSETID_EAX20_ListenerProperties = {
88 0x0306a6a8, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
91 const IID DSPROPSETID_EAX20_BufferProperties = {
92 0x0306a6a7, 0xb224, 0x11d2, { 0x99, 0xe5, 0x00, 0x00, 0xe8, 0xd8, 0xc7, 0x22 }
95 const EAXLISTENERPROPERTIES EnvironmentDefaults[EAX_ENVIRONMENT_COUNT] =
97 REVERB_PRESET_GENERIC,
98 REVERB_PRESET_PADDEDCELL,
99 REVERB_PRESET_ROOM,
100 REVERB_PRESET_BATHROOM,
101 REVERB_PRESET_LIVINGROOM,
102 REVERB_PRESET_STONEROOM,
103 REVERB_PRESET_AUDITORIUM,
104 REVERB_PRESET_CONCERTHALL,
105 REVERB_PRESET_CAVE,
106 REVERB_PRESET_ARENA,
107 REVERB_PRESET_HANGAR,
108 REVERB_PRESET_CARPETEDHALLWAY,
109 REVERB_PRESET_HALLWAY,
110 REVERB_PRESET_STONECORRIDOR,
111 REVERB_PRESET_ALLEY,
112 REVERB_PRESET_FOREST,
113 REVERB_PRESET_CITY,
114 REVERB_PRESET_MOUNTAINS,
115 REVERB_PRESET_QUARRY,
116 REVERB_PRESET_PLAIN,
117 REVERB_PRESET_PARKINGLOT,
118 REVERB_PRESET_SEWERPIPE,
119 REVERB_PRESET_UNDERWATER,
120 REVERB_PRESET_DRUGGED,
121 REVERB_PRESET_DIZZY,
122 REVERB_PRESET_PSYCHOTIC
125 static CRITICAL_SECTION_DEBUG openal_crst_debug =
127 0, 0, &openal_crst,
128 { &openal_crst_debug.ProcessLocksList,
129 &openal_crst_debug.ProcessLocksList },
130 0, 0, { (DWORD_PTR)(__FILE__ ": openal_crst_debug") }
132 CRITICAL_SECTION openal_crst = { &openal_crst_debug, -1, 0, 0, 0, 0 };
134 int openal_loaded = 0;
135 #ifdef SONAME_LIBOPENAL
136 static void *openal_handle = NULL;
137 LPALCCREATECONTEXT palcCreateContext = NULL;
138 LPALCMAKECONTEXTCURRENT palcMakeContextCurrent = NULL;
139 LPALCPROCESSCONTEXT palcProcessContext = NULL;
140 LPALCSUSPENDCONTEXT palcSuspendContext = NULL;
141 LPALCDESTROYCONTEXT palcDestroyContext = NULL;
142 LPALCGETCURRENTCONTEXT palcGetCurrentContext = NULL;
143 LPALCGETCONTEXTSDEVICE palcGetContextsDevice = NULL;
144 LPALCOPENDEVICE palcOpenDevice = NULL;
145 LPALCCLOSEDEVICE palcCloseDevice = NULL;
146 LPALCGETERROR palcGetError = NULL;
147 LPALCISEXTENSIONPRESENT palcIsExtensionPresent = NULL;
148 LPALCGETPROCADDRESS palcGetProcAddress = NULL;
149 LPALCGETENUMVALUE palcGetEnumValue = NULL;
150 LPALCGETSTRING palcGetString = NULL;
151 LPALCGETINTEGERV palcGetIntegerv = NULL;
152 LPALCCAPTUREOPENDEVICE palcCaptureOpenDevice = NULL;
153 LPALCCAPTURECLOSEDEVICE palcCaptureCloseDevice = NULL;
154 LPALCCAPTURESTART palcCaptureStart = NULL;
155 LPALCCAPTURESTOP palcCaptureStop = NULL;
156 LPALCCAPTURESAMPLES palcCaptureSamples = NULL;
157 LPALENABLE palEnable = NULL;
158 LPALDISABLE palDisable = NULL;
159 LPALISENABLED palIsEnabled = NULL;
160 LPALGETSTRING palGetString = NULL;
161 LPALGETBOOLEANV palGetBooleanv = NULL;
162 LPALGETINTEGERV palGetIntegerv = NULL;
163 LPALGETFLOATV palGetFloatv = NULL;
164 LPALGETDOUBLEV palGetDoublev = NULL;
165 LPALGETBOOLEAN palGetBoolean = NULL;
166 LPALGETINTEGER palGetInteger = NULL;
167 LPALGETFLOAT palGetFloat = NULL;
168 LPALGETDOUBLE palGetDouble = NULL;
169 LPALGETERROR palGetError = NULL;
170 LPALISEXTENSIONPRESENT palIsExtensionPresent = NULL;
171 LPALGETPROCADDRESS palGetProcAddress = NULL;
172 LPALGETENUMVALUE palGetEnumValue = NULL;
173 LPALLISTENERF palListenerf = NULL;
174 LPALLISTENER3F palListener3f = NULL;
175 LPALLISTENERFV palListenerfv = NULL;
176 LPALLISTENERI palListeneri = NULL;
177 LPALLISTENER3I palListener3i = NULL;
178 LPALLISTENERIV palListeneriv = NULL;
179 LPALGETLISTENERF palGetListenerf = NULL;
180 LPALGETLISTENER3F palGetListener3f = NULL;
181 LPALGETLISTENERFV palGetListenerfv = NULL;
182 LPALGETLISTENERI palGetListeneri = NULL;
183 LPALGETLISTENER3I palGetListener3i = NULL;
184 LPALGETLISTENERIV palGetListeneriv = NULL;
185 LPALGENSOURCES palGenSources = NULL;
186 LPALDELETESOURCES palDeleteSources = NULL;
187 LPALISSOURCE palIsSource = NULL;
188 LPALSOURCEF palSourcef = NULL;
189 LPALSOURCE3F palSource3f = NULL;
190 LPALSOURCEFV palSourcefv = NULL;
191 LPALSOURCEI palSourcei = NULL;
192 LPALSOURCE3I palSource3i = NULL;
193 LPALSOURCEIV palSourceiv = NULL;
194 LPALGETSOURCEF palGetSourcef = NULL;
195 LPALGETSOURCE3F palGetSource3f = NULL;
196 LPALGETSOURCEFV palGetSourcefv = NULL;
197 LPALGETSOURCEI palGetSourcei = NULL;
198 LPALGETSOURCE3I palGetSource3i = NULL;
199 LPALGETSOURCEIV palGetSourceiv = NULL;
200 LPALSOURCEPLAYV palSourcePlayv = NULL;
201 LPALSOURCESTOPV palSourceStopv = NULL;
202 LPALSOURCEREWINDV palSourceRewindv = NULL;
203 LPALSOURCEPAUSEV palSourcePausev = NULL;
204 LPALSOURCEPLAY palSourcePlay = NULL;
205 LPALSOURCESTOP palSourceStop = NULL;
206 LPALSOURCEREWIND palSourceRewind = NULL;
207 LPALSOURCEPAUSE palSourcePause = NULL;
208 LPALSOURCEQUEUEBUFFERS palSourceQueueBuffers = NULL;
209 LPALSOURCEUNQUEUEBUFFERS palSourceUnqueueBuffers = NULL;
210 LPALGENBUFFERS palGenBuffers = NULL;
211 LPALDELETEBUFFERS palDeleteBuffers = NULL;
212 LPALISBUFFER palIsBuffer = NULL;
213 LPALBUFFERF palBufferf = NULL;
214 LPALBUFFER3F palBuffer3f = NULL;
215 LPALBUFFERFV palBufferfv = NULL;
216 LPALBUFFERI palBufferi = NULL;
217 LPALBUFFER3I palBuffer3i = NULL;
218 LPALBUFFERIV palBufferiv = NULL;
219 LPALGETBUFFERF palGetBufferf = NULL;
220 LPALGETBUFFER3F palGetBuffer3f = NULL;
221 LPALGETBUFFERFV palGetBufferfv = NULL;
222 LPALGETBUFFERI palGetBufferi = NULL;
223 LPALGETBUFFER3I palGetBuffer3i = NULL;
224 LPALGETBUFFERIV palGetBufferiv = NULL;
225 LPALBUFFERDATA palBufferData = NULL;
226 LPALDOPPLERFACTOR palDopplerFactor = NULL;
227 LPALDOPPLERVELOCITY palDopplerVelocity = NULL;
228 LPALDISTANCEMODEL palDistanceModel = NULL;
229 LPALSPEEDOFSOUND palSpeedOfSound = NULL;
230 #endif
232 LPALCMAKECONTEXTCURRENT set_context;
233 LPALCGETCURRENTCONTEXT get_context;
234 BOOL local_contexts;
236 static void load_libopenal(void)
238 #ifndef __WINESRC__
239 const char *str = getenv("DSOAL_LOGLEVEL");
240 if(str && *str)
241 LogLevel = atoi(str);
242 #elif defined(SONAME_LIBOPENAL)
243 BOOL failed = FALSE;
244 char error[128];
246 openal_handle = wine_dlopen(SONAME_LIBOPENAL, RTLD_NOW, error, sizeof(error));
247 if(!openal_handle)
248 ERR("Couldn't load " SONAME_LIBOPENAL ": %s\n", error);
249 #define LOAD_FUNCPTR(f) \
250 if((p##f = wine_dlsym(openal_handle, #f, NULL, 0)) == NULL) { \
251 ERR("Couldn't lookup %s in " SONAME_LIBOPENAL "\n", #f); \
252 failed = TRUE; \
255 LOAD_FUNCPTR(alcCreateContext);
256 LOAD_FUNCPTR(alcMakeContextCurrent);
257 LOAD_FUNCPTR(alcProcessContext);
258 LOAD_FUNCPTR(alcSuspendContext);
259 LOAD_FUNCPTR(alcDestroyContext);
260 LOAD_FUNCPTR(alcGetCurrentContext);
261 LOAD_FUNCPTR(alcGetContextsDevice);
262 LOAD_FUNCPTR(alcOpenDevice);
263 LOAD_FUNCPTR(alcCloseDevice);
264 LOAD_FUNCPTR(alcGetError);
265 LOAD_FUNCPTR(alcIsExtensionPresent);
266 LOAD_FUNCPTR(alcGetProcAddress);
267 LOAD_FUNCPTR(alcGetEnumValue);
268 LOAD_FUNCPTR(alcGetString);
269 LOAD_FUNCPTR(alcGetIntegerv);
270 LOAD_FUNCPTR(alcCaptureOpenDevice);
271 LOAD_FUNCPTR(alcCaptureCloseDevice);
272 LOAD_FUNCPTR(alcCaptureStart);
273 LOAD_FUNCPTR(alcCaptureStop);
274 LOAD_FUNCPTR(alcCaptureSamples);
275 LOAD_FUNCPTR(alEnable);
276 LOAD_FUNCPTR(alDisable);
277 LOAD_FUNCPTR(alIsEnabled);
278 LOAD_FUNCPTR(alGetString);
279 LOAD_FUNCPTR(alGetBooleanv);
280 LOAD_FUNCPTR(alGetIntegerv);
281 LOAD_FUNCPTR(alGetFloatv);
282 LOAD_FUNCPTR(alGetDoublev);
283 LOAD_FUNCPTR(alGetBoolean);
284 LOAD_FUNCPTR(alGetInteger);
285 LOAD_FUNCPTR(alGetFloat);
286 LOAD_FUNCPTR(alGetDouble);
287 LOAD_FUNCPTR(alGetError);
288 LOAD_FUNCPTR(alIsExtensionPresent);
289 LOAD_FUNCPTR(alGetProcAddress);
290 LOAD_FUNCPTR(alGetEnumValue);
291 LOAD_FUNCPTR(alListenerf);
292 LOAD_FUNCPTR(alListener3f);
293 LOAD_FUNCPTR(alListenerfv);
294 LOAD_FUNCPTR(alListeneri);
295 LOAD_FUNCPTR(alListener3i);
296 LOAD_FUNCPTR(alListeneriv);
297 LOAD_FUNCPTR(alGetListenerf);
298 LOAD_FUNCPTR(alGetListener3f);
299 LOAD_FUNCPTR(alGetListenerfv);
300 LOAD_FUNCPTR(alGetListeneri);
301 LOAD_FUNCPTR(alGetListener3i);
302 LOAD_FUNCPTR(alGetListeneriv);
303 LOAD_FUNCPTR(alGenSources);
304 LOAD_FUNCPTR(alDeleteSources);
305 LOAD_FUNCPTR(alIsSource);
306 LOAD_FUNCPTR(alSourcef);
307 LOAD_FUNCPTR(alSource3f);
308 LOAD_FUNCPTR(alSourcefv);
309 LOAD_FUNCPTR(alSourcei);
310 LOAD_FUNCPTR(alSource3i);
311 LOAD_FUNCPTR(alSourceiv);
312 LOAD_FUNCPTR(alGetSourcef);
313 LOAD_FUNCPTR(alGetSource3f);
314 LOAD_FUNCPTR(alGetSourcefv);
315 LOAD_FUNCPTR(alGetSourcei);
316 LOAD_FUNCPTR(alGetSource3i);
317 LOAD_FUNCPTR(alGetSourceiv);
318 LOAD_FUNCPTR(alSourcePlayv);
319 LOAD_FUNCPTR(alSourceStopv);
320 LOAD_FUNCPTR(alSourceRewindv);
321 LOAD_FUNCPTR(alSourcePausev);
322 LOAD_FUNCPTR(alSourcePlay);
323 LOAD_FUNCPTR(alSourceStop);
324 LOAD_FUNCPTR(alSourceRewind);
325 LOAD_FUNCPTR(alSourcePause);
326 LOAD_FUNCPTR(alSourceQueueBuffers);
327 LOAD_FUNCPTR(alSourceUnqueueBuffers);
328 LOAD_FUNCPTR(alGenBuffers);
329 LOAD_FUNCPTR(alDeleteBuffers);
330 LOAD_FUNCPTR(alIsBuffer);
331 LOAD_FUNCPTR(alBufferf);
332 LOAD_FUNCPTR(alBuffer3f);
333 LOAD_FUNCPTR(alBufferfv);
334 LOAD_FUNCPTR(alBufferi);
335 LOAD_FUNCPTR(alBuffer3i);
336 LOAD_FUNCPTR(alBufferiv);
337 LOAD_FUNCPTR(alGetBufferf);
338 LOAD_FUNCPTR(alGetBuffer3f);
339 LOAD_FUNCPTR(alGetBufferfv);
340 LOAD_FUNCPTR(alGetBufferi);
341 LOAD_FUNCPTR(alGetBuffer3i);
342 LOAD_FUNCPTR(alGetBufferiv);
343 LOAD_FUNCPTR(alBufferData);
344 LOAD_FUNCPTR(alDopplerFactor);
345 LOAD_FUNCPTR(alDopplerVelocity);
346 LOAD_FUNCPTR(alDistanceModel);
347 LOAD_FUNCPTR(alSpeedOfSound);
348 #undef LOAD_FUNCPTR
349 if (failed)
351 WARN("Unloading openal\n");
352 if (openal_handle != RTLD_DEFAULT)
353 wine_dlclose(openal_handle, NULL, 0);
354 openal_handle = NULL;
356 else
357 #endif
359 openal_loaded = 1;
361 local_contexts = alcIsExtensionPresent(NULL, "ALC_EXT_thread_local_context");
362 if(local_contexts)
364 set_context = alcGetProcAddress(NULL, "alcSetThreadContext");
365 get_context = alcGetProcAddress(NULL, "alcGetThreadContext");
366 if(!set_context || !get_context)
368 ERR("TLS advertised but functions not found, disabling thread local context\n");
369 local_contexts = 0;
372 if(!local_contexts)
374 set_context = alcMakeContextCurrent;
375 get_context = alcGetCurrentContext;
380 const ALCchar *DSOUND_getdevicestrings(void)
382 if(alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT"))
383 return alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
384 return alcGetString(NULL, ALC_DEVICE_SPECIFIER);
387 const ALCchar *DSOUND_getcapturedevicestrings(void)
389 return alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
392 /***************************************************************************
393 * GetDeviceID [DSOUND.9]
395 * Retrieves unique identifier of default device specified
397 * PARAMS
398 * pGuidSrc [I] Address of device GUID.
399 * pGuidDest [O] Address to receive unique device GUID.
401 * RETURNS
402 * Success: DS_OK
403 * Failure: DSERR_INVALIDPARAM
405 * NOTES
406 * pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
407 * DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
408 * DSDEVID_DefaultVoiceCapture.
409 * Returns pGuidSrc if pGuidSrc is a valid device or the device
410 * GUID for the specified constants.
412 HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
414 TRACE("(%s, %p)\n", debugstr_guid(pGuidSrc), pGuidDest);
416 if(pGuidSrc == NULL)
418 WARN("invalid parameter: pGuidSrc == NULL\n");
419 return DSERR_INVALIDPARAM;
422 if(pGuidDest == NULL)
424 WARN("invalid parameter: pGuidDest == NULL\n");
425 return DSERR_INVALIDPARAM;
428 if(IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc) ||
429 IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc))
430 *pGuidDest = DSOUND_renderer_guid;
431 else if(IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc) ||
432 IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc))
433 *pGuidDest = DSOUND_capture_guid;
434 else
435 *pGuidDest = *pGuidSrc;
437 TRACE("returns %s\n", debugstr_guid(pGuidDest));
438 return DS_OK;
441 struct morecontext
443 LPDSENUMCALLBACKW callW;
444 LPVOID data;
447 static BOOL CALLBACK w_to_a_callback(LPGUID guid, LPCSTR descA, LPCSTR modA, LPVOID data)
449 struct morecontext *context = data;
450 WCHAR descW[MAXPNAMELEN], modW[MAXPNAMELEN];
452 MultiByteToWideChar(CP_ACP, 0, descA, -1, descW, sizeof(descW)/sizeof(descW[0]));
453 MultiByteToWideChar(CP_ACP, 0, modA, -1, modW, sizeof(modW)/sizeof(modW[0]));
455 return context->callW(guid, descW, modW, context->data);
458 /***************************************************************************
459 * DirectSoundEnumerateA [DSOUND.2]
461 * Enumerate all DirectSound drivers installed in the system
463 * PARAMS
464 * lpDSEnumCallback [I] Address of callback function.
465 * lpContext [I] Address of user defined context passed to callback function.
467 * RETURNS
468 * Success: DS_OK
469 * Failure: DSERR_INVALIDPARAM
471 HRESULT WINAPI DirectSoundEnumerateA(
472 LPDSENUMCALLBACKA lpDSEnumCallback,
473 LPVOID lpContext)
475 TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
476 lpDSEnumCallback, lpContext);
478 if (lpDSEnumCallback == NULL) {
479 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
480 return DSERR_INVALIDPARAM;
482 else if (openal_loaded)
484 const ALCchar *devstr;
485 GUID guid;
487 EnterCriticalSection(&openal_crst);
488 devstr = DSOUND_getdevicestrings();
489 if(!devstr || !*devstr)
490 goto out;
492 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
493 "Primary Sound Driver","",lpContext);
494 if(lpDSEnumCallback(NULL, "Primary Sound Driver", "", lpContext) == FALSE)
495 goto out;
497 guid = DSOUND_renderer_guid;
498 do {
499 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
500 debugstr_guid(&guid),devstr,"wineal.drv",lpContext);
501 if(lpDSEnumCallback(&guid, devstr, "wineal.drv", lpContext) == FALSE)
502 goto out;
503 guid.Data4[7]++;
504 devstr += strlen(devstr)+1;
505 } while(*devstr);
506 out:
507 LeaveCriticalSection(&openal_crst);
509 else
511 ERR("Attempting to enumerate sound cards without OpenAL support\n");
512 ERR("Please recompile wine with OpenAL for sound to work\n");
514 return DS_OK;
517 /***************************************************************************
518 * DirectSoundEnumerateW [DSOUND.3]
520 * Enumerate all DirectSound drivers installed in the system
522 * PARAMS
523 * lpDSEnumCallback [I] Address of callback function.
524 * lpContext [I] Address of user defined context passed to callback function.
526 * RETURNS
527 * Success: DS_OK
528 * Failure: DSERR_INVALIDPARAM
530 HRESULT WINAPI DirectSoundEnumerateW(
531 LPDSENUMCALLBACKW lpDSEnumCallback,
532 LPVOID lpContext )
534 struct morecontext context;
536 if(lpDSEnumCallback == NULL) {
537 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
538 return DSERR_INVALIDPARAM;
541 context.callW = lpDSEnumCallback;
542 context.data = lpContext;
544 return DirectSoundEnumerateA(w_to_a_callback, &context);
547 /***************************************************************************
548 * DirectSoundCaptureEnumerateA [DSOUND.7]
550 * Enumerate all DirectSound drivers installed in the system.
552 * PARAMS
553 * lpDSEnumCallback [I] Address of callback function.
554 * lpContext [I] Address of user defined context passed to callback function.
556 * RETURNS
557 * Success: DS_OK
558 * Failure: DSERR_INVALIDPARAM
560 HRESULT WINAPI DirectSoundCaptureEnumerateA(
561 LPDSENUMCALLBACKA lpDSEnumCallback,
562 LPVOID lpContext)
564 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
566 if (lpDSEnumCallback == NULL) {
567 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
568 return DSERR_INVALIDPARAM;
570 else if (openal_loaded)
572 const ALCchar *devstr;
573 GUID guid;
575 EnterCriticalSection(&openal_crst);
576 devstr = DSOUND_getcapturedevicestrings();
577 if(!devstr || !*devstr)
578 goto out;
580 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
581 "Primary Sound Capture Driver","",lpContext);
582 if(lpDSEnumCallback(NULL, "Primary Sound Driver", "", lpContext) == FALSE)
583 goto out;
585 guid = DSOUND_capture_guid;
586 do {
587 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
588 debugstr_guid(&guid),devstr,"wineal.drv",lpContext);
589 if(lpDSEnumCallback(&guid, devstr, "wineal.drv", lpContext) == FALSE)
590 goto out;
591 guid.Data4[7]++;
592 devstr += strlen(devstr)+1;
593 } while(*devstr);
594 out:
595 LeaveCriticalSection(&openal_crst);
597 else
599 ERR("Attempting to enumerate sound cards without OpenAL support\n");
600 ERR("Please recompile wine with OpenAL for sound to work\n");
602 return DS_OK;
605 /***************************************************************************
606 * DirectSoundCaptureEnumerateW [DSOUND.8]
608 * Enumerate all DirectSound drivers installed in the system.
610 * PARAMS
611 * lpDSEnumCallback [I] Address of callback function.
612 * lpContext [I] Address of user defined context passed to callback function.
614 * RETURNS
615 * Success: DS_OK
616 * Failure: DSERR_INVALIDPARAM
618 HRESULT WINAPI
619 DirectSoundCaptureEnumerateW(
620 LPDSENUMCALLBACKW lpDSEnumCallback,
621 LPVOID lpContext)
623 struct morecontext context;
625 if (lpDSEnumCallback == NULL) {
626 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
627 return DSERR_INVALIDPARAM;
630 context.callW = lpDSEnumCallback;
631 context.data = lpContext;
633 return DirectSoundCaptureEnumerateA(w_to_a_callback, &context);
636 /*******************************************************************************
637 * DirectSoundCreate (DSOUND.1)
639 * Creates and initializes a DirectSound interface.
641 * PARAMS
642 * lpcGUID [I] Address of the GUID that identifies the sound device.
643 * ppDS [O] Address of a variable to receive the interface pointer.
644 * pUnkOuter [I] Must be NULL.
646 * RETURNS
647 * Success: DS_OK
648 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
649 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
651 HRESULT WINAPI
652 DirectSoundCreate(LPCGUID lpcGUID, IDirectSound **ppDS, IUnknown *pUnkOuter)
654 HRESULT hr;
655 void *pDS;
657 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID), ppDS, pUnkOuter);
659 if (ppDS == NULL) {
660 WARN("invalid parameter: ppDS == NULL\n");
661 return DSERR_INVALIDPARAM;
663 *ppDS = NULL;
665 if (pUnkOuter != NULL) {
666 WARN("invalid parameter: pUnkOuter != NULL\n");
667 return DSERR_INVALIDPARAM;
670 hr = DSOUND_Create(&IID_IDirectSound, &pDS);
671 if(SUCCEEDED(hr))
673 *ppDS = pDS;
674 hr = IDirectSound_Initialize(*ppDS, lpcGUID);
675 if(FAILED(hr))
677 IDirectSound_Release(*ppDS);
678 *ppDS = NULL;
682 return hr;
685 /*******************************************************************************
686 * DirectSoundCreate8 (DSOUND.11)
688 * Creates and initializes a DirectSound8 interface.
690 * PARAMS
691 * lpcGUID [I] Address of the GUID that identifies the sound device.
692 * ppDS [O] Address of a variable to receive the interface pointer.
693 * pUnkOuter [I] Must be NULL.
695 * RETURNS
696 * Success: DS_OK
697 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
698 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
700 HRESULT WINAPI
701 DirectSoundCreate8(LPCGUID lpcGUID, IDirectSound8 **ppDS, IUnknown *pUnkOuter)
703 HRESULT hr;
704 void *pDS;
706 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID), ppDS, pUnkOuter);
708 if (ppDS == NULL) {
709 WARN("invalid parameter: ppDS == NULL\n");
710 return DSERR_INVALIDPARAM;
712 *ppDS = NULL;
714 if (pUnkOuter != NULL) {
715 WARN("invalid parameter: pUnkOuter != NULL\n");
716 return DSERR_INVALIDPARAM;
719 hr = DSOUND_Create8(&IID_IDirectSound8, &pDS);
720 if(SUCCEEDED(hr))
722 *ppDS = pDS;
723 hr = IDirectSound8_Initialize(*ppDS, lpcGUID);
724 if(FAILED(hr))
726 IDirectSound8_Release(*ppDS);
727 *ppDS = NULL;
731 return hr;
734 /***************************************************************************
735 * DirectSoundCaptureCreate [DSOUND.6]
737 * Create and initialize a DirectSoundCapture interface.
739 * PARAMS
740 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
741 * lplpDSC [O] Address of a variable to receive the interface pointer.
742 * pUnkOuter [I] Must be NULL.
744 * RETURNS
745 * Success: DS_OK
746 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
747 * DSERR_OUTOFMEMORY
749 * NOTES
750 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
751 * or NULL for the default device or DSDEVID_DefaultCapture or
752 * DSDEVID_DefaultVoiceCapture.
754 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
756 HRESULT WINAPI
757 DirectSoundCaptureCreate(LPCGUID lpcGUID, IDirectSoundCapture **ppDSC, IUnknown *pUnkOuter)
759 HRESULT hr;
760 void *pDSC;
762 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID), ppDSC, pUnkOuter);
764 if(ppDSC == NULL)
766 WARN("invalid parameter: ppDSC == NULL\n");
767 return DSERR_INVALIDPARAM;
769 *ppDSC = NULL;
771 if(pUnkOuter)
773 WARN("invalid parameter: pUnkOuter != NULL\n");
774 return DSERR_NOAGGREGATION;
777 hr = DSOUND_CaptureCreate(&IID_IDirectSoundCapture, &pDSC);
778 if(SUCCEEDED(hr))
780 *ppDSC = pDSC;
781 hr = IDirectSoundCapture_Initialize(*ppDSC, lpcGUID);
782 if(FAILED(hr))
784 IDirectSoundCapture_Release(*ppDSC);
785 *ppDSC = NULL;
789 return hr;
792 /***************************************************************************
793 * DirectSoundCaptureCreate8 [DSOUND.12]
795 * Create and initialize a DirectSoundCapture interface.
797 * PARAMS
798 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
799 * lplpDSC [O] Address of a variable to receive the interface pointer.
800 * pUnkOuter [I] Must be NULL.
802 * RETURNS
803 * Success: DS_OK
804 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
805 * DSERR_OUTOFMEMORY
807 * NOTES
808 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
809 * or NULL for the default device or DSDEVID_DefaultCapture or
810 * DSDEVID_DefaultVoiceCapture.
812 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
814 HRESULT WINAPI
815 DirectSoundCaptureCreate8(LPCGUID lpcGUID, IDirectSoundCapture8 **ppDSC8, IUnknown *pUnkOuter)
817 HRESULT hr;
818 void *pDSC8;
820 TRACE("(%s, %p, %p)\n", debugstr_guid(lpcGUID), ppDSC8, pUnkOuter);
822 if(ppDSC8 == NULL)
824 WARN("invalid parameter: ppDSC8 == NULL\n");
825 return DSERR_INVALIDPARAM;
827 *ppDSC8 = NULL;
829 if(pUnkOuter)
831 WARN("invalid parameter: pUnkOuter != NULL\n");
832 return DSERR_NOAGGREGATION;
835 hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture, &pDSC8);
836 if(SUCCEEDED(hr))
838 *ppDSC8 = pDSC8;
839 hr = IDirectSoundCapture_Initialize(*ppDSC8, lpcGUID);
840 if(FAILED(hr))
842 IDirectSoundCapture_Release(*ppDSC8);
843 *ppDSC8 = NULL;
847 return hr;
850 /*******************************************************************************
851 * DirectSound ClassFactory
854 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
856 typedef struct {
857 IClassFactory IClassFactory_iface;
858 LONG ref;
859 REFCLSID rclsid;
860 FnCreateInstance pfnCreateInstance;
861 } IClassFactoryImpl;
863 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
865 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
868 static HRESULT WINAPI DSCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
870 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
871 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
872 if (ppobj == NULL)
873 return E_POINTER;
874 if (IsEqualIID(riid, &IID_IUnknown) ||
875 IsEqualIID(riid, &IID_IClassFactory))
877 *ppobj = iface;
878 IUnknown_AddRef(iface);
879 return S_OK;
881 *ppobj = NULL;
882 return E_NOINTERFACE;
885 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
887 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
888 ULONG ref = InterlockedIncrement(&(This->ref));
889 TRACE("(%p) ref was %"LONGFMT"u\n", This, ref - 1);
890 return ref;
893 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
895 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
896 ULONG ref = InterlockedDecrement(&(This->ref));
897 TRACE("(%p) ref was %"LONGFMT"u\n", This, ref + 1);
898 /* static class, won't be freed */
899 return ref;
902 static HRESULT WINAPI DSCF_CreateInstance(
903 LPCLASSFACTORY iface,
904 LPUNKNOWN pOuter,
905 REFIID riid,
906 LPVOID *ppobj)
908 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
909 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
911 if (pOuter)
912 return CLASS_E_NOAGGREGATION;
914 if (ppobj == NULL) {
915 WARN("invalid parameter\n");
916 return DSERR_INVALIDPARAM;
918 *ppobj = NULL;
919 return This->pfnCreateInstance(riid, ppobj);
922 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
924 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
925 FIXME("(%p, %d) stub!\n", This, dolock);
926 return S_OK;
929 static const IClassFactoryVtbl DSCF_Vtbl = {
930 DSCF_QueryInterface,
931 DSCF_AddRef,
932 DSCF_Release,
933 DSCF_CreateInstance,
934 DSCF_LockServer
937 static IClassFactoryImpl DSOUND_CF[] = {
938 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSound, DSOUND_Create },
939 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSound8, DSOUND_Create8 },
940 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSoundCapture, DSOUND_CaptureCreate },
941 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSoundCapture8, DSOUND_CaptureCreate8 },
942 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSoundFullDuplex, DSOUND_FullDuplexCreate },
943 { {(IClassFactoryVtbl*)&DSCF_Vtbl}, 1, &CLSID_DirectSoundPrivate, IKsPrivatePropertySetImpl_Create },
944 { {NULL}, 0, NULL, NULL }
947 /*******************************************************************************
948 * DllGetClassObject [DSOUND.@]
949 * Retrieves class object from a DLL object
951 * NOTES
952 * Docs say returns STDAPI
954 * PARAMS
955 * rclsid [I] CLSID for the class object
956 * riid [I] Reference to identifier of interface for class object
957 * ppv [O] Address of variable to receive interface pointer for riid
959 * RETURNS
960 * Success: S_OK
961 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
962 * E_UNEXPECTED
964 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
966 int i = 0;
967 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
969 if (ppv == NULL) {
970 WARN("invalid parameter\n");
971 return E_INVALIDARG;
974 *ppv = NULL;
976 if (!IsEqualIID(riid, &IID_IClassFactory) &&
977 !IsEqualIID(riid, &IID_IUnknown)) {
978 WARN("no interface for %s\n", debugstr_guid(riid));
979 return E_NOINTERFACE;
982 while (NULL != DSOUND_CF[i].rclsid) {
983 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
984 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
985 *ppv = &DSOUND_CF[i];
986 return S_OK;
988 i++;
991 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
992 debugstr_guid(riid), ppv);
993 return CLASS_E_CLASSNOTAVAILABLE;
997 /*******************************************************************************
998 * DllCanUnloadNow [DSOUND.4]
999 * Determines whether the DLL is in use.
1001 * RETURNS
1002 * Success: S_OK
1003 * Failure: S_FALSE
1005 HRESULT WINAPI DllCanUnloadNow(void)
1007 FIXME("(void): stub\n");
1008 return S_FALSE;
1011 /***********************************************************************
1012 * DllMain (DSOUND.init)
1014 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
1016 TRACE("(%p, %"LONGFMT"u, %p)\n", hInstDLL, fdwReason, lpvReserved);
1018 switch(fdwReason)
1020 case DLL_PROCESS_ATTACH:
1021 TRACE("DLL_PROCESS_ATTACH\n");
1022 instance = hInstDLL;
1023 load_libopenal();
1024 /* Increase refcount on dsound by 1 */
1025 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
1026 break;
1028 case DLL_THREAD_DETACH:
1029 TRACE("DLL_THREAD_DETACH\n");
1030 #if !ALLOW_CONCURRENT_AL
1031 if(local_contexts)
1032 set_context(NULL);
1033 #endif
1034 break;
1036 case DLL_PROCESS_DETACH:
1037 TRACE("DLL_PROCESS_DETACH\n");
1038 #ifdef SONAME_LIBOPENAL
1039 if(openal_handle)
1040 wine_dlclose(openal_handle, NULL, 0);
1041 #endif
1042 break;
1044 default:
1045 TRACE("UNKNOWN REASON\n");
1046 break;
1048 return TRUE;
1051 #ifdef __WINESRC__
1052 /***********************************************************************
1053 * DllRegisterServer (DSOUND.@)
1055 HRESULT WINAPI DllRegisterServer(void)
1057 return __wine_register_resources(instance);
1060 /***********************************************************************
1061 * DllUnregisterServer (DSOUND.@)
1063 HRESULT WINAPI DllUnregisterServer(void)
1065 return __wine_unregister_resources(instance);
1067 #endif