Add a .gitignore to ignore the build directory
[wine/multimedia.git] / dsound8.c
blob9d8561da1e569e100c573f34fd9c6c8aa45a054f
1 /* DirectSound COM interface
3 * Copyright 2009 Maarten Lankhorst
5 * Some code taken from the original dsound-openal implementation
6 * Copyright 2007-2009 Chris Robinson
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
25 #ifdef __WINESRC__
27 #define COBJMACROS
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "winreg.h"
35 #include "mmsystem.h"
36 #include "winternl.h"
37 #include "mmddk.h"
38 #include "wine/debug.h"
39 #include "dsound.h"
41 #include "dsound_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
45 #else
47 #define WINVER 0x6100
48 #include <windows.h>
49 #include <dsound.h>
51 #include "dsound_private.h"
53 #ifndef DSSPEAKER_7POINT1
54 #define DSSPEAKER_7POINT1 7
55 #endif
57 #endif
59 static DS8Impl **devicelist;
60 static UINT devicelistsize;
62 static const IDirectSound8Vtbl DS8_Vtbl;
64 HRESULT DSOUND_Create(REFIID riid, LPVOID *ds)
66 HRESULT hr;
68 if(IsEqualIID(riid, &IID_IDirectSound8))
69 return E_NOINTERFACE;
70 hr = DSOUND_Create8(riid, ds);
71 if(hr == S_OK)
72 ((DS8Impl*)*ds)->is_8 = FALSE;
73 return hr;
76 static void DS8Impl_Destroy(DS8Impl *This);
78 static const WCHAR speakerconfigkey[] = {
79 'S','Y','S','T','E','M','\\',
80 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
81 'C','o','n','t','r','o','l','\\',
82 'M','e','d','i','a','R','e','s','o','u','r','c','e','s','\\',
83 'D','i','r','e','c','t','S','o','u','n','d','\\',
84 'S','p','e','a','k','e','r',' ','C','o','n','f','i','g','u','r','a','t','i','o','n',0
87 static const WCHAR speakerconfig[] = {
88 'S','p','e','a','k','e','r',' ','C','o','n','f','i','g','u','r','a','t','i','o','n',0
91 HRESULT DSOUND_Create8(REFIID riid, LPVOID *ds)
93 DS8Impl *This;
94 HKEY regkey;
95 HRESULT hr;
97 *ds = NULL;
98 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This));
99 if(!This)
100 return E_OUTOFMEMORY;
101 This->is_8 = TRUE;
102 This->IDirectSound8_iface.lpVtbl = &DS8_Vtbl;
103 This->speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_5POINT1, DSSPEAKER_GEOMETRY_WIDE);
105 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, speakerconfigkey, 0, KEY_READ, &regkey) == ERROR_SUCCESS)
107 DWORD type, conf, confsize = sizeof(DWORD);
109 if(RegQueryValueExW(regkey, speakerconfig, NULL, &type, (BYTE*)&conf, &confsize) == ERROR_SUCCESS)
111 if(type == REG_DWORD)
112 This->speaker_config = conf;
115 RegCloseKey(regkey);
117 /*RegGetValueW(HKEY_LOCAL_MACHINE, speakerconfigkey, speakerconfig, RRF_RT_REG_DWORD, NULL, &This->speaker_config, NULL);*/
119 hr = IUnknown_QueryInterface(&This->IDirectSound8_iface, riid, ds);
120 if(FAILED(hr))
121 DS8Impl_Destroy(This);
122 else
124 void *temp;
126 EnterCriticalSection(&openal_crst);
127 if(devicelist)
128 temp = HeapReAlloc(GetProcessHeap(), 0, devicelist, sizeof(*devicelist)*(devicelistsize+1));
129 else
130 temp = HeapAlloc(GetProcessHeap(), 0, sizeof(*devicelist)*(devicelistsize+1));
131 if(temp)
133 devicelist = temp;
134 devicelist[devicelistsize++] = This;
136 LeaveCriticalSection(&openal_crst);
138 return hr;
141 static void DS8Impl_Destroy(DS8Impl *This)
143 UINT i;
145 EnterCriticalSection(&openal_crst);
146 for(i = 0;i < devicelistsize;i++)
148 if(devicelist[i] == This)
150 devicelist[i] = devicelist[--devicelistsize];
151 if(devicelistsize == 0)
153 HeapFree(GetProcessHeap(), 0, devicelist);
154 devicelist = NULL;
156 break;
160 if(This->deviceref && InterlockedDecrement(This->deviceref) == 0)
162 if(This->primary)
163 DS8Primary_Destroy(This->primary);
164 if(This->device)
165 alcCloseDevice(This->device);
167 HeapFree(GetProcessHeap(), 0, This->deviceref);
169 else if(This->deviceref && This->primary->parent == This)
171 /* If the primary is referencing this as its parent, update it to
172 * reference another handle for the device */
173 for(i = 0;i < devicelistsize;i++)
175 if(devicelist[i]->primary == This->primary)
177 This->primary->parent = devicelist[i];
178 break;
182 LeaveCriticalSection(&openal_crst);
184 HeapFree(GetProcessHeap(), 0, This);
187 static inline DS8Impl *impl_from_IDirectSound8(IDirectSound8 *iface)
189 return CONTAINING_RECORD(iface, DS8Impl, IDirectSound8_iface);
192 static HRESULT WINAPI DS8_QueryInterface(IDirectSound8 *iface, REFIID riid, LPVOID *ppv)
194 DS8Impl *This = impl_from_IDirectSound8(iface);
196 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
198 *ppv = NULL;
199 if(IsEqualIID(riid, &IID_IUnknown) ||
200 IsEqualIID(riid, &IID_IDirectSound))
201 *ppv = &This->IDirectSound8_iface;
202 else if((IsEqualIID(riid, &IID_IDirectSound8)))
204 if(This->is_8)
205 *ppv = &This->IDirectSound8_iface;
207 else
208 FIXME("Unhandled GUID: %s\n", debugstr_guid(riid));
210 if(*ppv)
212 IUnknown_AddRef((IUnknown*)*ppv);
213 return S_OK;
216 return E_NOINTERFACE;
219 static ULONG WINAPI DS8_AddRef(IDirectSound8 *iface)
221 DS8Impl *This = impl_from_IDirectSound8(iface);
222 LONG ref;
224 ref = InterlockedIncrement(&This->ref);
225 TRACE("Reference count incremented to %d\n", ref);
227 return ref;
230 static ULONG WINAPI DS8_Release(IDirectSound8 *iface)
232 DS8Impl *This = impl_from_IDirectSound8(iface);
233 LONG ref;
235 ref = InterlockedDecrement(&This->ref);
236 TRACE("Reference count decremented to %d\n", ref);
237 if(ref == 0)
238 DS8Impl_Destroy(This);
240 return ref;
243 static HRESULT WINAPI DS8_CreateSoundBuffer(IDirectSound8 *iface, LPCDSBUFFERDESC desc, LPLPDIRECTSOUNDBUFFER buf, IUnknown *pUnkOuter)
245 DS8Impl *This = impl_from_IDirectSound8(iface);
246 HRESULT hr;
248 TRACE("(%p)->(%p, %p, %p)\n", iface, desc, buf, pUnkOuter);
250 if(!buf)
252 WARN("buf is null\n");
253 return DSERR_INVALIDPARAM;
255 *buf = NULL;
257 if(pUnkOuter)
259 WARN("Aggregation isn't supported\n");
260 return DSERR_NOAGGREGATION;
262 if(!desc || desc->dwSize < sizeof(DSBUFFERDESC1))
264 WARN("Invalid buffer %p/%u\n", desc, desc?desc->dwSize:0);
265 return DSERR_INVALIDPARAM;
267 if(desc->dwSize >= sizeof(DSBUFFERDESC))
269 if(!(desc->dwFlags&DSBCAPS_CTRL3D))
271 if(!IsEqualGUID(&desc->guid3DAlgorithm, &GUID_NULL))
273 WARN("Invalid 3D algorithm GUID specified for non-3D buffer: %s\n", debugstr_guid(&desc->guid3DAlgorithm));
274 return DSERR_INVALIDPARAM;
277 else
278 TRACE("Requested 3D algorithm GUID: %s\n", debugstr_guid(&desc->guid3DAlgorithm));
281 /* OpenAL doesn't support playing with 3d and panning at same time.. */
282 if((desc->dwFlags&(DSBCAPS_CTRL3D|DSBCAPS_CTRLPAN)) == (DSBCAPS_CTRL3D|DSBCAPS_CTRLPAN))
284 if(!This->is_8)
285 ERR("Cannot create buffers with 3D and panning control\n");
286 else
287 WARN("Cannot create buffers with 3D and panning control\n");
288 return DSERR_INVALIDPARAM;
291 EnterCriticalSection(&openal_crst);
292 if(!This->device)
293 hr = DSERR_UNINITIALIZED;
294 else if((desc->dwFlags&DSBCAPS_PRIMARYBUFFER))
296 IDirectSoundBuffer *prim = &This->primary->IDirectSoundBuffer_iface;
298 hr = S_OK;
299 if(IDirectSoundBuffer_AddRef(prim) == 1)
301 hr = IDirectSoundBuffer_Initialize(prim, (IDirectSound*)&This->IDirectSound8_iface, desc);
302 if(FAILED(hr))
304 IDirectSoundBuffer_Release(prim);
305 prim = NULL;
308 *buf = prim;
310 else
312 DS8Buffer *dsb;
314 hr = DS8Buffer_Create(&dsb, This->primary, NULL);
315 if(SUCCEEDED(hr))
317 hr = IDirectSoundBuffer8_Initialize(&dsb->IDirectSoundBuffer8_iface, (IDirectSound*)&This->IDirectSound8_iface, desc);
318 if(FAILED(hr))
319 IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface);
320 else
322 dsb->bufferlost = (This->prio_level == DSSCL_WRITEPRIMARY);
323 *buf = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface;
327 LeaveCriticalSection(&openal_crst);
329 TRACE("%08x\n", hr);
330 return hr;
333 static HRESULT WINAPI DS8_GetCaps(IDirectSound8 *iface, LPDSCAPS caps)
335 DS8Impl *This = impl_from_IDirectSound8(iface);
336 HRESULT hr = S_OK;
337 TRACE("\n");
339 EnterCriticalSection(&openal_crst);
340 if(!This->device)
341 hr = DSERR_UNINITIALIZED;
342 else if(!caps || caps->dwSize < sizeof(*caps))
343 hr = DSERR_INVALIDPARAM;
344 else
346 LONG count = This->primary->max_sources;
348 setALContext(This->primary->ctx);
349 caps->dwFlags = DSCAPS_CONTINUOUSRATE |
350 DSCAPS_PRIMARY16BIT | DSCAPS_PRIMARYSTEREO |
351 DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARYMONO |
352 DSCAPS_SECONDARY16BIT | DSCAPS_SECONDARY8BIT |
353 DSCAPS_SECONDARYMONO | DSCAPS_SECONDARYSTEREO;
354 caps->dwPrimaryBuffers = 1;
355 caps->dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
356 caps->dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
357 caps->dwMaxHwMixingAllBuffers =
358 caps->dwMaxHwMixingStaticBuffers =
359 caps->dwMaxHwMixingStreamingBuffers =
360 caps->dwMaxHw3DAllBuffers =
361 caps->dwMaxHw3DStaticBuffers =
362 caps->dwMaxHw3DStreamingBuffers = count;
363 count -= This->primary->nbuffers;
364 if(count < 0)
366 ERR("How did the count drop below 0?\n");
367 count = 0;
369 caps->dwFreeHwMixingAllBuffers =
370 caps->dwFreeHwMixingStaticBuffers =
371 caps->dwFreeHwMixingStreamingBuffers =
372 caps->dwFreeHw3DAllBuffers =
373 caps->dwFreeHw3DStaticBuffers =
374 caps->dwFreeHw3DStreamingBuffers = count;
375 caps->dwTotalHwMemBytes =
376 caps->dwFreeHwMemBytes = 64 * 1024 * 1024;
377 caps->dwMaxContigFreeHwMemBytes = caps->dwFreeHwMemBytes;
378 caps->dwUnlockTransferRateHwBuffers = 4096;
379 caps->dwPlayCpuOverheadSwBuffers = 0;
380 popALContext();
382 LeaveCriticalSection(&openal_crst);
384 return hr;
386 static HRESULT WINAPI DS8_DuplicateSoundBuffer(IDirectSound8 *iface, IDirectSoundBuffer *in, IDirectSoundBuffer **out)
388 DS8Impl *This = impl_from_IDirectSound8(iface);
389 HRESULT hr = S_OK;
391 TRACE("(%p)->(%p, %p)\n", iface, in, out);
393 EnterCriticalSection(&openal_crst);
394 if(!This->device)
395 hr = DSERR_UNINITIALIZED;
396 else if(!in || !out)
397 hr = DSERR_INVALIDPARAM;
398 else
400 DWORD i;
401 DSBCAPS caps;
402 DS8Buffer *buf;
404 *out = NULL;
406 for(i = 0; i < This->primary->nbuffers; ++i)
408 if(This->primary->buffers[i] == (DS8Buffer*)in)
409 break;
411 if(i == This->primary->nbuffers)
413 hr = DSERR_INVALIDPARAM;
414 WARN("Buffer %p not found\n", in);
415 goto out;
418 caps.dwSize = sizeof(caps);
419 hr = IDirectSoundBuffer_GetCaps(in, &caps);
420 if(SUCCEEDED(hr) && (caps.dwFlags&DSBCAPS_CTRLFX))
422 WARN("Cannot duplicate buffer %p, which has DSBCAPS_CTRLFX\n", in);
423 hr = DSERR_INVALIDPARAM;
425 if(SUCCEEDED(hr))
426 hr = DS8Buffer_Create(&buf, This->primary, (DS8Buffer*)in);
427 if(SUCCEEDED(hr))
429 *out = (IDirectSoundBuffer*)&buf->IDirectSoundBuffer8_iface;
430 hr = IDirectSoundBuffer_Initialize(*out, NULL, NULL);
432 if(SUCCEEDED(hr))
434 DWORD savelost = ((DS8Buffer*)in)->bufferlost;
435 ((DS8Buffer*)in)->bufferlost = 0;
436 /* According to MSDN volume isn't copied
438 if((caps.dwFlags&DSBCAPS_CTRLPAN))
440 LONG pan;
441 if(SUCCEEDED(IDirectSoundBuffer_GetPan(in, &pan)))
442 IDirectSoundBuffer_SetPan(*out, pan);
444 if((caps.dwFlags&DSBCAPS_CTRLFREQUENCY))
446 DWORD freq;
447 if(SUCCEEDED(IDirectSoundBuffer_GetFrequency(in, &freq)))
448 IDirectSoundBuffer_SetFrequency(*out, freq);
450 if((caps.dwFlags&DSBCAPS_CTRL3D))
452 IDirectSound3DBuffer *buf3d;
453 DS3DBUFFER DS3DBuffer;
454 HRESULT subhr;
456 subhr = IDirectSound_QueryInterface(in, &IID_IDirectSound3DBuffer, (void**)&buf3d);
457 if(SUCCEEDED(subhr))
459 DS3DBuffer.dwSize = sizeof(DS3DBuffer);
460 subhr = IDirectSound3DBuffer_GetAllParameters(buf3d, &DS3DBuffer);
461 IDirectSound3DBuffer_Release(buf3d);
463 if(SUCCEEDED(subhr))
464 subhr = IDirectSoundBuffer_QueryInterface(*out, &IID_IDirectSound3DBuffer, (void**)&buf3d);
465 if(SUCCEEDED(subhr))
467 subhr = IDirectSound3DBuffer_SetAllParameters(buf3d, &DS3DBuffer, DS3D_IMMEDIATE);
468 IDirectSound3DBuffer_Release(buf3d);
471 ((DS8Buffer*)in)->bufferlost = buf->bufferlost = savelost;
473 if(FAILED(hr))
475 if(*out)
476 IDirectSoundBuffer_Release(*out);
477 *out = NULL;
478 goto out;
481 out:
482 LeaveCriticalSection(&openal_crst);
483 return hr;
486 static HRESULT WINAPI DS8_SetCooperativeLevel(IDirectSound8 *iface, HWND hwnd, DWORD level)
488 DS8Impl *This = impl_from_IDirectSound8(iface);
489 HRESULT hr = S_OK;
491 TRACE("(%p)->(%p, %u)\n", iface, hwnd, level);
493 EnterCriticalSection(&openal_crst);
494 if(!This->device)
495 hr = DSERR_UNINITIALIZED;
496 else if(level > DSSCL_WRITEPRIMARY || level < DSSCL_NORMAL)
497 hr = E_INVALIDARG;
498 else if(level == DSSCL_WRITEPRIMARY && (This->prio_level != DSSCL_WRITEPRIMARY))
500 DWORD i, state;
502 for(i = 0; i < This->primary->nbuffers; ++i)
504 DS8Buffer *buf = This->primary->buffers[i];
505 if(FAILED(IDirectSoundBuffer_GetStatus(&buf->IDirectSoundBuffer8_iface, &state)) ||
506 (state&DSBSTATUS_PLAYING))
508 WARN("DSSCL_WRITEPRIMARY set with playing buffers!\n");
509 hr = DSERR_INVALIDCALL;
510 goto out;
512 /* Mark buffer as lost */
513 buf->bufferlost = 1;
515 if(This->primary->write_emu)
517 ERR("Why was there a write_emu?\n");
518 /* Delete it */
519 IDirectSoundBuffer8_Release(This->primary->write_emu);
520 This->primary->write_emu = NULL;
522 if(This->primary->flags)
524 /* Primary has open references.. create write_emu */
525 DSBUFFERDESC desc;
526 DS8Buffer *emu;
528 memset(&desc, 0, sizeof(desc));
529 desc.dwSize = sizeof(desc);
530 desc.dwFlags = DSBCAPS_LOCHARDWARE | (This->primary->flags&DSBCAPS_CTRLPAN);
531 desc.dwBufferBytes = This->primary->buf_size;
532 desc.lpwfxFormat = &This->primary->format.Format;
534 hr = DS8Buffer_Create(&emu, This->primary, NULL);
535 if(SUCCEEDED(hr))
537 This->primary->write_emu = &emu->IDirectSoundBuffer8_iface;
538 hr = IDirectSoundBuffer8_Initialize(This->primary->write_emu, (IDirectSound*)&This->IDirectSound8_iface, &desc);
539 if(FAILED(hr))
541 IDirectSoundBuffer8_Release(This->primary->write_emu);
542 This->primary->write_emu = NULL;
547 else if(This->prio_level == DSSCL_WRITEPRIMARY && level != DSSCL_WRITEPRIMARY && This->primary->write_emu)
549 TRACE("Nuking write_emu\n");
550 /* Delete it */
551 IDirectSoundBuffer8_Release(This->primary->write_emu);
552 This->primary->write_emu = NULL;
554 if(SUCCEEDED(hr))
555 This->prio_level = level;
556 out:
557 LeaveCriticalSection(&openal_crst);
559 return hr;
562 static HRESULT WINAPI DS8_Compact(IDirectSound8 *iface)
564 DS8Impl *This = impl_from_IDirectSound8(iface);
565 HRESULT hr = S_OK;
567 TRACE("(%p)->()\n", iface);
569 EnterCriticalSection(&openal_crst);
570 if(!This->device)
571 hr = DSERR_UNINITIALIZED;
572 else if(This->prio_level < DSSCL_PRIORITY)
573 hr = DSERR_PRIOLEVELNEEDED;
574 LeaveCriticalSection(&openal_crst);
576 return hr;
579 static HRESULT WINAPI DS8_GetSpeakerConfig(IDirectSound8 *iface, DWORD *config)
581 DS8Impl *This = impl_from_IDirectSound8(iface);
582 HRESULT hr = S_OK;
584 TRACE("(%p)->(%p)\n", iface, config);
586 if(!config)
587 return DSERR_INVALIDPARAM;
589 EnterCriticalSection(&openal_crst);
590 if(!This->device)
591 hr = DSERR_UNINITIALIZED;
592 else
593 *config = This->speaker_config;
594 LeaveCriticalSection(&openal_crst);
596 return hr;
599 static HRESULT WINAPI DS8_SetSpeakerConfig(IDirectSound8 *iface, DWORD config)
601 DS8Impl *This = impl_from_IDirectSound8(iface);
602 HRESULT hr;
604 TRACE("(%p)->(0x%08x)\n", iface, config);
606 EnterCriticalSection(&openal_crst);
607 if(!This->device)
608 hr = DSERR_UNINITIALIZED;
609 else
611 HKEY key;
612 DWORD geo, speaker;
614 geo = DSSPEAKER_GEOMETRY(config);
615 speaker = DSSPEAKER_CONFIG(config);
617 hr = DSERR_INVALIDPARAM;
618 if(geo && (geo < DSSPEAKER_GEOMETRY_MIN || geo > DSSPEAKER_GEOMETRY_MAX))
620 WARN("Invalid speaker angle %u\n", geo);
621 goto out;
623 if(speaker < DSSPEAKER_HEADPHONE || speaker > DSSPEAKER_7POINT1)
625 WARN("Invalid speaker config %u\n", speaker);
626 goto out;
629 hr = DSERR_GENERIC;
630 if(!RegCreateKeyExW(HKEY_LOCAL_MACHINE, speakerconfigkey, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL))
632 RegSetValueExW(key, speakerconfig, 0, REG_DWORD, (const BYTE*)&config, sizeof(DWORD));
633 This->speaker_config = config;
634 RegCloseKey(key);
635 hr = S_OK;
638 out:
639 LeaveCriticalSection(&openal_crst);
641 return hr;
644 static HRESULT WINAPI DS8_Initialize(IDirectSound8 *iface, const GUID *devguid)
646 DS8Impl *This = impl_from_IDirectSound8(iface);
647 const ALCchar *drv_name;
648 HRESULT hr;
649 UINT n;
651 TRACE("(%p)->(%s)\n", iface, debugstr_guid(devguid));
653 if(!openal_loaded)
654 return DSERR_NODRIVER;
656 if(!devguid)
657 devguid = &DSDEVID_DefaultPlayback;
659 EnterCriticalSection(&openal_crst);
661 hr = DSERR_ALREADYINITIALIZED;
662 if(This->device)
663 goto out;
665 hr = GetDeviceID(devguid, &This->guid);
666 if(FAILED(hr))
667 goto out;
669 for(n = 0;n < devicelistsize;n++)
671 if(devicelist[n]->device && devicelist[n]->is_8 == This->is_8 &&
672 IsEqualGUID(&devicelist[n]->guid, &This->guid))
674 TRACE("Matched already open device %p\n", devicelist[n]);
676 This->device = devicelist[n]->device;
677 This->primary = devicelist[n]->primary;
678 This->deviceref = devicelist[n]->deviceref;
679 InterlockedIncrement(This->deviceref);
681 hr = DS_OK;
682 goto out;
686 if(!This->deviceref)
688 hr = DSERR_OUTOFMEMORY;
689 if(!(This->deviceref=HeapAlloc(GetProcessHeap(), 0, sizeof(LONG))))
690 goto out;
691 This->deviceref[0] = 1;
694 hr = DSERR_NODRIVER;
695 if(!(drv_name=DSOUND_getdevicestrings()) ||
696 memcmp(&This->guid, &DSOUND_renderer_guid, sizeof(GUID)-1) != 0)
698 WARN("No device found\n");
699 goto out;
702 n = This->guid.Data4[7];
703 while(*drv_name && n--)
704 drv_name += strlen(drv_name) + 1;
705 if(!*drv_name)
707 WARN("No device string found\n");
708 goto out;
711 This->device = alcOpenDevice(drv_name);
712 if(!This->device)
714 alcGetError(NULL);
715 WARN("Couldn't open device \"%s\"\n", drv_name);
716 goto out;
718 TRACE("Opened device: %s\n", alcGetString(This->device, ALC_DEVICE_SPECIFIER));
720 hr = DS8Primary_Create(&This->primary, This);
721 if(FAILED(hr))
723 alcCloseDevice(This->device);
724 This->device = NULL;
727 out:
728 LeaveCriticalSection(&openal_crst);
730 return hr;
733 /* I, Maarten Lankhorst, hereby declare this driver certified
734 * What this means.. ? An extra bit set
736 static HRESULT WINAPI DS8_VerifyCertification(IDirectSound8 *iface, DWORD *certified)
738 DS8Impl *This = impl_from_IDirectSound8(iface);
739 HRESULT hr;
741 TRACE("(%p)->(%p)\n", iface, certified);
743 if(!certified)
744 return DSERR_INVALIDPARAM;
746 EnterCriticalSection(&openal_crst);
747 hr = S_OK;
748 if(!This->device)
749 hr = DSERR_UNINITIALIZED;
750 else
751 *certified = DS_CERTIFIED;
752 LeaveCriticalSection(&openal_crst);
754 return hr;
757 static const IDirectSound8Vtbl DS8_Vtbl =
759 DS8_QueryInterface,
760 DS8_AddRef,
761 DS8_Release,
762 DS8_CreateSoundBuffer,
763 DS8_GetCaps,
764 DS8_DuplicateSoundBuffer,
765 DS8_SetCooperativeLevel,
766 DS8_Compact,
767 DS8_GetSpeakerConfig,
768 DS8_SetSpeakerConfig,
769 DS8_Initialize,
770 DS8_VerifyCertification