Fix some unused parameter warnings
[dsound-openal.git] / dsound_main.c
blobe4657cff4da2dddaf93657b5872f36d2d883e784
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"
59 #include "dsound_private.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
63 #else
65 #define WINVER 0x0600
66 #include <windows.h>
67 #include <dsound.h>
69 #include "dsound_private.h"
71 #ifndef CP_UNIXCP
72 #define CP_UNIXCP 65010
73 #endif
75 DEFINE_GUID(CLSID_DirectSoundPrivate,0x11ab3ec0,0x25ec,0x11d1,0xa4,0xd8,0x00,0xc0,0x4f,0xc2,0x8a,0xca);
77 int LogLevel = 1;
79 #endif
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,
92 REVERB_PRESET_ROOM,
93 REVERB_PRESET_BATHROOM,
94 REVERB_PRESET_LIVINGROOM,
95 REVERB_PRESET_STONEROOM,
96 REVERB_PRESET_AUDITORIUM,
97 REVERB_PRESET_CONCERTHALL,
98 REVERB_PRESET_CAVE,
99 REVERB_PRESET_ARENA,
100 REVERB_PRESET_HANGAR,
101 REVERB_PRESET_CARPETEDHALLWAY,
102 REVERB_PRESET_HALLWAY,
103 REVERB_PRESET_STONECORRIDOR,
104 REVERB_PRESET_ALLEY,
105 REVERB_PRESET_FOREST,
106 REVERB_PRESET_CITY,
107 REVERB_PRESET_MOUNTAINS,
108 REVERB_PRESET_QUARRY,
109 REVERB_PRESET_PLAIN,
110 REVERB_PRESET_PARKINGLOT,
111 REVERB_PRESET_SEWERPIPE,
112 REVERB_PRESET_UNDERWATER,
113 REVERB_PRESET_DRUGGED,
114 REVERB_PRESET_DIZZY,
115 REVERB_PRESET_PSYCHOTIC
118 static CRITICAL_SECTION_DEBUG openal_crst_debug =
120 0, 0, &openal_crst,
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;
223 #endif
225 LPALCMAKECONTEXTCURRENT set_context;
226 LPALCGETCURRENTCONTEXT get_context;
227 BOOL local_contexts;
229 static void load_libopenal(void)
231 #ifndef __WINESRC__
232 const char *str = getenv("DSOAL_LOGLEVEL");
233 if(str && *str)
234 LogLevel = atoi(str);
235 #elif defined(SONAME_LIBOPENAL)
236 BOOL failed = FALSE;
237 char error[128];
239 openal_handle = wine_dlopen(SONAME_LIBOPENAL, RTLD_NOW, error, sizeof(error));
240 if(!openal_handle)
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); \
245 failed = TRUE; \
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);
341 #undef LOAD_FUNCPTR
342 if (failed)
344 WARN("Unloading openal\n");
345 if (openal_handle != RTLD_DEFAULT)
346 wine_dlclose(openal_handle, NULL, 0);
347 openal_handle = NULL;
349 else
350 #endif
352 openal_loaded = 1;
354 local_contexts = alcIsExtensionPresent(NULL, "ALC_EXT_thread_local_context");
355 if(local_contexts)
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");
362 local_contexts = 0;
365 if(!local_contexts)
367 set_context = alcMakeContextCurrent;
368 get_context = alcGetCurrentContext;
373 const ALCchar *DSOUND_getdevicestrings(void)
375 const ALCchar *str = NULL;
376 int multiple;
378 multiple = alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT");
379 if (multiple)
380 str = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
381 else
382 str = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
383 return str;
386 const ALCchar *DSOUND_getcapturedevicestrings(void)
388 const ALCchar *str = NULL;
389 str = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
390 return str;
393 /***************************************************************************
394 * GetDeviceID [DSOUND.9]
396 * Retrieves unique identifier of default device specified
398 * PARAMS
399 * pGuidSrc [I] Address of device GUID.
400 * pGuidDest [O] Address to receive unique device GUID.
402 * RETURNS
403 * Success: DS_OK
404 * Failure: DSERR_INVALIDPARAM
406 * NOTES
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));
431 return DS_OK;
434 if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
435 IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
436 *pGuidDest = DSOUND_capture_guid;
437 TRACE("returns %s\n", debugstr_guid(pGuidDest));
438 return DS_OK;
441 *pGuidDest = *pGuidSrc;
442 TRACE("returns %s\n", debugstr_guid(pGuidDest));
444 return DS_OK;
447 struct morecontext
449 LPDSENUMCALLBACKA callA;
450 LPVOID data;
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
469 * PARAMS
470 * lpDSEnumCallback [I] Address of callback function.
471 * lpContext [I] Address of user defined context passed to callback function.
473 * RETURNS
474 * Success: DS_OK
475 * Failure: DSERR_INVALIDPARAM
477 HRESULT WINAPI DirectSoundEnumerateA(
478 LPDSENUMCALLBACKA lpDSEnumCallback,
479 LPVOID lpContext)
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
499 * PARAMS
500 * lpDSEnumCallback [I] Address of callback function.
501 * lpContext [I] Address of user defined context passed to callback function.
503 * RETURNS
504 * Success: DS_OK
505 * Failure: DSERR_INVALIDPARAM
507 HRESULT WINAPI DirectSoundEnumerateW(
508 LPDSENUMCALLBACKW lpDSEnumCallback,
509 LPVOID lpContext )
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)
520 GUID guid;
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)
528 goto out;
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)
535 goto out;
537 guid = DSOUND_renderer_guid;
538 do {
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)
547 goto out;
548 guid.Data4[7]++;
549 devstr += strlen(devstr)+1;
550 } while (*devstr);
552 out:
553 LeaveCriticalSection(&openal_crst);
555 else
557 ERR("Attempting to enumerate sound cards without OpenAL support\n");
558 ERR("Please recompile wine with OpenAL for sound to work\n");
560 return DS_OK;
563 /***************************************************************************
564 * DirectSoundCaptureEnumerateA [DSOUND.7]
566 * Enumerate all DirectSound drivers installed in the system.
568 * PARAMS
569 * lpDSEnumCallback [I] Address of callback function.
570 * lpContext [I] Address of user defined context passed to callback function.
572 * RETURNS
573 * Success: DS_OK
574 * Failure: DSERR_INVALIDPARAM
576 HRESULT WINAPI DirectSoundCaptureEnumerateA(
577 LPDSENUMCALLBACKA lpDSEnumCallback,
578 LPVOID lpContext)
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.
598 * PARAMS
599 * lpDSEnumCallback [I] Address of callback function.
600 * lpContext [I] Address of user defined context passed to callback function.
602 * RETURNS
603 * Success: DS_OK
604 * Failure: DSERR_INVALIDPARAM
606 HRESULT WINAPI
607 DirectSoundCaptureEnumerateW(
608 LPDSENUMCALLBACKW lpDSEnumCallback,
609 LPVOID lpContext)
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)
619 GUID guid;
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)
628 goto out;
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)
635 goto out;
637 guid = DSOUND_capture_guid;
638 do {
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)
647 goto out;
648 guid.Data4[7]++;
649 devstr += strlen(devstr)+1;
650 } while (*devstr);
652 out:
653 LeaveCriticalSection(&openal_crst);
655 else
657 ERR("Attempting to enumerate sound cards without OpenAL support\n");
658 ERR("Please recompile wine with OpenAL for sound to work\n");
660 return DS_OK;
663 /*******************************************************************************
664 * DirectSoundCreate (DSOUND.1)
666 * Creates and initializes a DirectSound interface.
668 * PARAMS
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.
673 * RETURNS
674 * Success: DS_OK
675 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
676 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
678 HRESULT WINAPI DirectSoundCreate(
679 LPCGUID lpcGUID,
680 LPDIRECTSOUND *ppDS,
681 IUnknown *pUnkOuter)
683 HRESULT hr;
684 LPDIRECTSOUND pDS;
686 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
688 if (ppDS == NULL) {
689 WARN("invalid parameter: ppDS == NULL\n");
690 return DSERR_INVALIDPARAM;
693 if (pUnkOuter != NULL) {
694 WARN("invalid parameter: pUnkOuter != NULL\n");
695 *ppDS = 0;
696 return DSERR_INVALIDPARAM;
699 hr = DSOUND_Create(&IID_IDirectSound, (void **)&pDS);
700 if (hr == DS_OK) {
701 hr = IDirectSound_Initialize(pDS, lpcGUID);
702 if (hr != DS_OK) {
703 if (hr != DSERR_ALREADYINITIALIZED) {
704 IDirectSound_Release(pDS);
705 pDS = 0;
706 } else
707 hr = DS_OK;
711 *ppDS = pDS;
713 return hr;
716 /*******************************************************************************
717 * DirectSoundCreate8 (DSOUND.11)
719 * Creates and initializes a DirectSound8 interface.
721 * PARAMS
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.
726 * RETURNS
727 * Success: DS_OK
728 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
729 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
731 HRESULT WINAPI DirectSoundCreate8(
732 LPCGUID lpcGUID,
733 LPDIRECTSOUND8 *ppDS,
734 IUnknown *pUnkOuter)
736 HRESULT hr;
737 LPDIRECTSOUND8 pDS;
739 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
741 if (ppDS == NULL) {
742 WARN("invalid parameter: ppDS == NULL\n");
743 return DSERR_INVALIDPARAM;
746 if (pUnkOuter != NULL) {
747 WARN("invalid parameter: pUnkOuter != NULL\n");
748 *ppDS = 0;
749 return DSERR_INVALIDPARAM;
752 hr = DSOUND_Create8(&IID_IDirectSound8, (void**)&pDS);
753 if (hr == DS_OK) {
754 hr = IDirectSound8_Initialize(pDS, lpcGUID);
755 if (hr != DS_OK) {
756 if (hr != DSERR_ALREADYINITIALIZED) {
757 IDirectSound8_Release(pDS);
758 pDS = 0;
759 } else
760 hr = DS_OK;
764 *ppDS = pDS;
766 return hr;
769 /***************************************************************************
770 * DirectSoundCaptureCreate [DSOUND.6]
772 * Create and initialize a DirectSoundCapture interface.
774 * PARAMS
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.
779 * RETURNS
780 * Success: DS_OK
781 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
782 * DSERR_OUTOFMEMORY
784 * NOTES
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(
792 LPCGUID lpcGUID,
793 LPDIRECTSOUNDCAPTURE *ppDSC,
794 LPUNKNOWN pUnkOuter)
796 HRESULT hr;
797 LPDIRECTSOUNDCAPTURE pDSC;
798 TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), ppDSC, pUnkOuter);
800 if (ppDSC == NULL) {
801 WARN("invalid parameter: ppDSC == NULL\n");
802 return DSERR_INVALIDPARAM;
805 if (pUnkOuter) {
806 WARN("invalid parameter: pUnkOuter != NULL\n");
807 *ppDSC = NULL;
808 return DSERR_NOAGGREGATION;
811 hr = DSOUND_CaptureCreate(&IID_IDirectSoundCapture, &pDSC);
812 if (hr == DS_OK) {
813 hr = IDirectSoundCapture_Initialize(pDSC, lpcGUID);
814 if (hr != DS_OK) {
815 IDirectSoundCapture_Release(pDSC);
816 pDSC = 0;
820 *ppDSC = pDSC;
822 return hr;
825 /***************************************************************************
826 * DirectSoundCaptureCreate8 [DSOUND.12]
828 * Create and initialize a DirectSoundCapture interface.
830 * PARAMS
831 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
832 * lplpDSC [O] Address of a variable to receive the interface pointer.
833 * pUnkOuter [I] Must be NULL.
835 * RETURNS
836 * Success: DS_OK
837 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
838 * DSERR_OUTOFMEMORY
840 * NOTES
841 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
842 * or NULL for the default device or DSDEVID_DefaultCapture or
843 * DSDEVID_DefaultVoiceCapture.
845 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
847 HRESULT WINAPI DirectSoundCaptureCreate8(
848 LPCGUID lpcGUID,
849 LPDIRECTSOUNDCAPTURE8 *ppDSC8,
850 LPUNKNOWN pUnkOuter)
852 HRESULT hr;
853 LPDIRECTSOUNDCAPTURE8 pDSC8;
854 TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), ppDSC8, pUnkOuter);
856 if (ppDSC8 == NULL) {
857 WARN("invalid parameter: ppDSC8 == NULL\n");
858 return DSERR_INVALIDPARAM;
861 if (pUnkOuter) {
862 WARN("invalid parameter: pUnkOuter != NULL\n");
863 *ppDSC8 = NULL;
864 return DSERR_NOAGGREGATION;
867 hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, &pDSC8);
868 if (hr == DS_OK) {
869 hr = IDirectSoundCapture_Initialize(pDSC8, lpcGUID);
870 if (hr != DS_OK) {
871 IDirectSoundCapture_Release(pDSC8);
872 pDSC8 = 0;
876 *ppDSC8 = pDSC8;
878 return hr;
881 /*******************************************************************************
882 * DirectSound ClassFactory
885 typedef HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
887 typedef struct {
888 IClassFactory IClassFactory_iface;
889 LONG ref;
890 REFCLSID rclsid;
891 FnCreateInstance pfnCreateInstance;
892 } IClassFactoryImpl;
894 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
896 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
899 static HRESULT WINAPI DSCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
901 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
902 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
903 if (ppobj == NULL)
904 return E_POINTER;
905 if (IsEqualIID(riid, &IID_IUnknown) ||
906 IsEqualIID(riid, &IID_IClassFactory))
908 *ppobj = iface;
909 IUnknown_AddRef(iface);
910 return S_OK;
912 *ppobj = NULL;
913 return E_NOINTERFACE;
916 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
918 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
919 ULONG ref = InterlockedIncrement(&(This->ref));
920 TRACE("(%p) ref was %d\n", This, ref - 1);
921 return ref;
924 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
926 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
927 ULONG ref = InterlockedDecrement(&(This->ref));
928 TRACE("(%p) ref was %d\n", This, ref + 1);
929 /* static class, won't be freed */
930 return ref;
933 static HRESULT WINAPI DSCF_CreateInstance(
934 LPCLASSFACTORY iface,
935 LPUNKNOWN pOuter,
936 REFIID riid,
937 LPVOID *ppobj)
939 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
940 TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
942 if (pOuter)
943 return CLASS_E_NOAGGREGATION;
945 if (ppobj == NULL) {
946 WARN("invalid parameter\n");
947 return DSERR_INVALIDPARAM;
949 *ppobj = NULL;
950 return This->pfnCreateInstance(riid, ppobj);
953 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
955 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
956 FIXME("(%p, %d) stub!\n", This, dolock);
957 return S_OK;
960 static const IClassFactoryVtbl DSCF_Vtbl = {
961 DSCF_QueryInterface,
962 DSCF_AddRef,
963 DSCF_Release,
964 DSCF_CreateInstance,
965 DSCF_LockServer
968 static IClassFactoryImpl DSOUND_CF[] = {
969 { {&DSCF_Vtbl}, 1, &CLSID_DirectSound, DSOUND_Create },
970 { {&DSCF_Vtbl}, 1, &CLSID_DirectSound8, DSOUND_Create8 },
971 { {&DSCF_Vtbl}, 1, &CLSID_DirectSoundCapture, (FnCreateInstance)DSOUND_CaptureCreate },
972 { {&DSCF_Vtbl}, 1, &CLSID_DirectSoundCapture8, (FnCreateInstance)DSOUND_CaptureCreate8 },
973 { {&DSCF_Vtbl}, 1, &CLSID_DirectSoundFullDuplex, (FnCreateInstance)DSOUND_FullDuplexCreate },
974 { {&DSCF_Vtbl}, 1, &CLSID_DirectSoundPrivate, IKsPrivatePropertySetImpl_Create },
975 { {NULL}, 0, NULL, NULL }
978 /*******************************************************************************
979 * DllGetClassObject [DSOUND.@]
980 * Retrieves class object from a DLL object
982 * NOTES
983 * Docs say returns STDAPI
985 * PARAMS
986 * rclsid [I] CLSID for the class object
987 * riid [I] Reference to identifier of interface for class object
988 * ppv [O] Address of variable to receive interface pointer for riid
990 * RETURNS
991 * Success: S_OK
992 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
993 * E_UNEXPECTED
995 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
997 int i = 0;
998 TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
1000 if (ppv == NULL) {
1001 WARN("invalid parameter\n");
1002 return E_INVALIDARG;
1005 *ppv = NULL;
1007 if (!IsEqualIID(riid, &IID_IClassFactory) &&
1008 !IsEqualIID(riid, &IID_IUnknown)) {
1009 WARN("no interface for %s\n", debugstr_guid(riid));
1010 return E_NOINTERFACE;
1013 while (NULL != DSOUND_CF[i].rclsid) {
1014 if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
1015 DSCF_AddRef(&DSOUND_CF[i].IClassFactory_iface);
1016 *ppv = &DSOUND_CF[i];
1017 return S_OK;
1019 i++;
1022 WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
1023 debugstr_guid(riid), ppv);
1024 return CLASS_E_CLASSNOTAVAILABLE;
1028 /*******************************************************************************
1029 * DllCanUnloadNow [DSOUND.4]
1030 * Determines whether the DLL is in use.
1032 * RETURNS
1033 * Success: S_OK
1034 * Failure: S_FALSE
1036 HRESULT WINAPI DllCanUnloadNow(void)
1038 FIXME("(void): stub\n");
1039 return S_FALSE;
1042 /***********************************************************************
1043 * DllMain (DSOUND.init)
1045 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
1047 TRACE("(%p, %d, %p)\n", hInstDLL, fdwReason, lpvReserved);
1049 switch (fdwReason) {
1050 case DLL_PROCESS_ATTACH:
1051 TRACE("DLL_PROCESS_ATTACH\n");
1052 load_libopenal();
1053 DisableThreadLibraryCalls(hInstDLL);
1054 /* Increase refcount on dsound by 1 */
1055 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
1056 break;
1057 case DLL_PROCESS_DETACH:
1058 TRACE("DLL_PROCESS_DETACH\n");
1059 #ifdef SONAME_LIBOPENAL
1060 if (openal_handle)
1061 wine_dlclose(openal_handle, NULL, 0);
1062 #endif /*SONAME_LIBOPENAL*/
1063 break;
1064 default:
1065 TRACE("UNKNOWN REASON\n");
1066 break;
1068 return TRUE;