Add missing include
[wine/multimedia.git] / dsound8.c
blob5b15343ef7d86f26c0b76d0b1c116f6589817785
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 0x0600
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->IDirectSound8_iface.lpVtbl = (IDirectSound8Vtbl*)&DS8_Vtbl;
103 This->is_8 = TRUE;
104 This->speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_5POINT1, DSSPEAKER_GEOMETRY_WIDE);
106 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, speakerconfigkey, 0, KEY_READ, &regkey) == ERROR_SUCCESS)
108 DWORD type, conf, confsize = sizeof(DWORD);
110 if(RegQueryValueExW(regkey, speakerconfig, NULL, &type, (BYTE*)&conf, &confsize) == ERROR_SUCCESS)
112 if(type == REG_DWORD)
113 This->speaker_config = conf;
116 RegCloseKey(regkey);
118 /*RegGetValueW(HKEY_LOCAL_MACHINE, speakerconfigkey, speakerconfig, RRF_RT_REG_DWORD, NULL, &This->speaker_config, NULL);*/
120 hr = IUnknown_QueryInterface(&This->IDirectSound8_iface, riid, ds);
121 if(FAILED(hr))
122 DS8Impl_Destroy(This);
123 else
125 void *temp;
127 EnterCriticalSection(&openal_crst);
128 if(devicelist)
129 temp = HeapReAlloc(GetProcessHeap(), 0, devicelist, sizeof(*devicelist)*(devicelistsize+1));
130 else
131 temp = HeapAlloc(GetProcessHeap(), 0, sizeof(*devicelist)*(devicelistsize+1));
132 if(temp)
134 devicelist = temp;
135 devicelist[devicelistsize++] = This;
137 LeaveCriticalSection(&openal_crst);
139 return hr;
142 static void DS8Impl_Destroy(DS8Impl *This)
144 UINT i;
146 EnterCriticalSection(&openal_crst);
147 for(i = 0;i < devicelistsize;i++)
149 if(devicelist[i] == This)
151 devicelist[i] = devicelist[--devicelistsize];
152 if(devicelistsize == 0)
154 HeapFree(GetProcessHeap(), 0, devicelist);
155 devicelist = NULL;
157 break;
161 if(This->deviceref && InterlockedDecrement(This->deviceref) == 0)
163 if(This->primary)
164 DS8Primary_Destroy(This->primary);
165 if(This->device)
166 alcCloseDevice(This->device);
168 HeapFree(GetProcessHeap(), 0, This->deviceref);
170 else if(This->deviceref && This->primary->parent == This)
172 /* If the primary is referencing this as its parent, update it to
173 * reference another handle for the device */
174 for(i = 0;i < devicelistsize;i++)
176 if(devicelist[i]->primary == This->primary)
178 This->primary->parent = devicelist[i];
179 break;
183 LeaveCriticalSection(&openal_crst);
185 HeapFree(GetProcessHeap(), 0, This);
188 static inline DS8Impl *impl_from_IDirectSound8(IDirectSound8 *iface)
190 return CONTAINING_RECORD(iface, DS8Impl, IDirectSound8_iface);
193 static HRESULT WINAPI DS8_QueryInterface(IDirectSound8 *iface, REFIID riid, LPVOID *ppv)
195 DS8Impl *This = impl_from_IDirectSound8(iface);
197 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv);
199 *ppv = NULL;
200 if(IsEqualIID(riid, &IID_IUnknown) ||
201 IsEqualIID(riid, &IID_IDirectSound))
202 *ppv = &This->IDirectSound8_iface;
203 else if((IsEqualIID(riid, &IID_IDirectSound8)))
205 if(This->is_8)
206 *ppv = &This->IDirectSound8_iface;
208 else
209 FIXME("Unhandled GUID: %s\n", debugstr_guid(riid));
211 if(*ppv)
213 IUnknown_AddRef((IUnknown*)*ppv);
214 return S_OK;
217 return E_NOINTERFACE;
220 static ULONG WINAPI DS8_AddRef(IDirectSound8 *iface)
222 DS8Impl *This = impl_from_IDirectSound8(iface);
223 LONG ref;
225 ref = InterlockedIncrement(&This->ref);
226 TRACE("Reference count incremented to %d\n", ref);
228 return ref;
231 static ULONG WINAPI DS8_Release(IDirectSound8 *iface)
233 DS8Impl *This = impl_from_IDirectSound8(iface);
234 LONG ref;
236 ref = InterlockedDecrement(&This->ref);
237 TRACE("Reference count decremented to %d\n", ref);
238 if(ref == 0)
239 DS8Impl_Destroy(This);
241 return ref;
244 static HRESULT WINAPI DS8_CreateSoundBuffer(IDirectSound8 *iface, LPCDSBUFFERDESC desc, LPLPDIRECTSOUNDBUFFER buf, IUnknown *pUnkOuter)
246 DS8Impl *This = impl_from_IDirectSound8(iface);
247 HRESULT hr;
249 TRACE("(%p)->(%p, %p, %p)\n", iface, desc, buf, pUnkOuter);
251 if(!buf)
253 WARN("buf is null\n");
254 return DSERR_INVALIDPARAM;
256 *buf = NULL;
258 if(pUnkOuter)
260 WARN("Aggregation isn't supported\n");
261 return DSERR_NOAGGREGATION;
263 if(!desc || desc->dwSize < sizeof(DSBUFFERDESC1))
265 WARN("Invalid buffer %p/%u\n", desc, desc?desc->dwSize:0);
266 return DSERR_INVALIDPARAM;
268 if(desc->dwSize >= sizeof(DSBUFFERDESC))
270 if(!(desc->dwFlags&DSBCAPS_CTRL3D))
272 if(!IsEqualGUID(&desc->guid3DAlgorithm, &GUID_NULL))
274 WARN("Invalid 3D algorithm GUID specified for non-3D buffer: %s\n", debugstr_guid(&desc->guid3DAlgorithm));
275 return DSERR_INVALIDPARAM;
278 else
279 TRACE("Requested 3D algorithm GUID: %s\n", debugstr_guid(&desc->guid3DAlgorithm));
282 /* OpenAL doesn't support playing with 3d and panning at same time.. */
283 if((desc->dwFlags&(DSBCAPS_CTRL3D|DSBCAPS_CTRLPAN)) == (DSBCAPS_CTRL3D|DSBCAPS_CTRLPAN))
285 if(!This->is_8)
286 ERR("Cannot create buffers with 3D and panning control\n");
287 else
288 WARN("Cannot create buffers with 3D and panning control\n");
289 return DSERR_INVALIDPARAM;
292 EnterCriticalSection(&openal_crst);
293 if(!This->device)
294 hr = DSERR_UNINITIALIZED;
295 else if((desc->dwFlags&DSBCAPS_PRIMARYBUFFER))
297 IDirectSoundBuffer *prim = &This->primary->IDirectSoundBuffer_iface;
299 hr = S_OK;
300 if(IDirectSoundBuffer_AddRef(prim) == 1)
302 hr = IDirectSoundBuffer_Initialize(prim, (IDirectSound*)&This->IDirectSound8_iface, desc);
303 if(FAILED(hr))
305 IDirectSoundBuffer_Release(prim);
306 prim = NULL;
309 *buf = prim;
311 else
313 DS8Buffer *dsb;
315 hr = DS8Buffer_Create(&dsb, This->primary, NULL);
316 if(SUCCEEDED(hr))
318 hr = IDirectSoundBuffer8_Initialize(&dsb->IDirectSoundBuffer8_iface, (IDirectSound*)&This->IDirectSound8_iface, desc);
319 if(FAILED(hr))
320 IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface);
321 else
323 dsb->bufferlost = (This->prio_level == DSSCL_WRITEPRIMARY);
324 *buf = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface;
328 LeaveCriticalSection(&openal_crst);
330 TRACE("%08x\n", hr);
331 return hr;
334 static HRESULT WINAPI DS8_GetCaps(IDirectSound8 *iface, LPDSCAPS caps)
336 DS8Impl *This = impl_from_IDirectSound8(iface);
337 HRESULT hr = S_OK;
338 TRACE("\n");
340 EnterCriticalSection(&openal_crst);
341 if(!This->device)
342 hr = DSERR_UNINITIALIZED;
343 else if(!caps || caps->dwSize < sizeof(*caps))
344 hr = DSERR_INVALIDPARAM;
345 else
347 LONG count = This->primary->max_sources;
349 setALContext(This->primary->ctx);
350 caps->dwFlags = DSCAPS_CONTINUOUSRATE |
351 DSCAPS_PRIMARY16BIT | DSCAPS_PRIMARYSTEREO |
352 DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARYMONO |
353 DSCAPS_SECONDARY16BIT | DSCAPS_SECONDARY8BIT |
354 DSCAPS_SECONDARYMONO | DSCAPS_SECONDARYSTEREO;
355 caps->dwPrimaryBuffers = 1;
356 caps->dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
357 caps->dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
358 caps->dwMaxHwMixingAllBuffers =
359 caps->dwMaxHwMixingStaticBuffers =
360 caps->dwMaxHwMixingStreamingBuffers =
361 caps->dwMaxHw3DAllBuffers =
362 caps->dwMaxHw3DStaticBuffers =
363 caps->dwMaxHw3DStreamingBuffers = count;
364 count -= This->primary->nbuffers;
365 if(count < 0)
367 ERR("How did the count drop below 0?\n");
368 count = 0;
370 caps->dwFreeHwMixingAllBuffers =
371 caps->dwFreeHwMixingStaticBuffers =
372 caps->dwFreeHwMixingStreamingBuffers =
373 caps->dwFreeHw3DAllBuffers =
374 caps->dwFreeHw3DStaticBuffers =
375 caps->dwFreeHw3DStreamingBuffers = count;
376 caps->dwTotalHwMemBytes =
377 caps->dwFreeHwMemBytes = 64 * 1024 * 1024;
378 caps->dwMaxContigFreeHwMemBytes = caps->dwFreeHwMemBytes;
379 caps->dwUnlockTransferRateHwBuffers = 4096;
380 caps->dwPlayCpuOverheadSwBuffers = 0;
381 popALContext();
383 LeaveCriticalSection(&openal_crst);
385 return hr;
387 static HRESULT WINAPI DS8_DuplicateSoundBuffer(IDirectSound8 *iface, IDirectSoundBuffer *in, IDirectSoundBuffer **out)
389 DS8Impl *This = impl_from_IDirectSound8(iface);
390 HRESULT hr = S_OK;
392 TRACE("(%p)->(%p, %p)\n", iface, in, out);
394 EnterCriticalSection(&openal_crst);
395 if(!This->device)
396 hr = DSERR_UNINITIALIZED;
397 else if(!in || !out)
398 hr = DSERR_INVALIDPARAM;
399 else
401 DWORD i;
402 DSBCAPS caps;
403 DS8Buffer *buf;
405 *out = NULL;
407 for(i = 0; i < This->primary->nbuffers; ++i)
409 if(This->primary->buffers[i] == (DS8Buffer*)in)
410 break;
412 if(i == This->primary->nbuffers)
414 hr = DSERR_INVALIDPARAM;
415 WARN("Buffer %p not found\n", in);
416 goto out;
419 caps.dwSize = sizeof(caps);
420 hr = IDirectSoundBuffer_GetCaps(in, &caps);
421 if(SUCCEEDED(hr) && (caps.dwFlags&DSBCAPS_CTRLFX))
423 WARN("Cannot duplicate buffer %p, which has DSBCAPS_CTRLFX\n", in);
424 hr = DSERR_INVALIDPARAM;
426 if(SUCCEEDED(hr))
427 hr = DS8Buffer_Create(&buf, This->primary, (DS8Buffer*)in);
428 if(SUCCEEDED(hr))
430 *out = (IDirectSoundBuffer*)&buf->IDirectSoundBuffer8_iface;
431 hr = IDirectSoundBuffer_Initialize(*out, NULL, NULL);
433 if(SUCCEEDED(hr))
435 DWORD savelost = ((DS8Buffer*)in)->bufferlost;
436 ((DS8Buffer*)in)->bufferlost = 0;
437 /* According to MSDN volume isn't copied
439 if((caps.dwFlags&DSBCAPS_CTRLPAN))
441 LONG pan;
442 if(SUCCEEDED(IDirectSoundBuffer_GetPan(in, &pan)))
443 IDirectSoundBuffer_SetPan(*out, pan);
445 if((caps.dwFlags&DSBCAPS_CTRLFREQUENCY))
447 DWORD freq;
448 if(SUCCEEDED(IDirectSoundBuffer_GetFrequency(in, &freq)))
449 IDirectSoundBuffer_SetFrequency(*out, freq);
451 if((caps.dwFlags&DSBCAPS_CTRL3D))
453 IDirectSound3DBuffer *buf3d;
454 DS3DBUFFER DS3DBuffer;
455 HRESULT subhr;
457 subhr = IDirectSound_QueryInterface(in, &IID_IDirectSound3DBuffer, (void**)&buf3d);
458 if(SUCCEEDED(subhr))
460 DS3DBuffer.dwSize = sizeof(DS3DBuffer);
461 subhr = IDirectSound3DBuffer_GetAllParameters(buf3d, &DS3DBuffer);
462 IDirectSound3DBuffer_Release(buf3d);
464 if(SUCCEEDED(subhr))
465 subhr = IDirectSoundBuffer_QueryInterface(*out, &IID_IDirectSound3DBuffer, (void**)&buf3d);
466 if(SUCCEEDED(subhr))
468 subhr = IDirectSound3DBuffer_SetAllParameters(buf3d, &DS3DBuffer, DS3D_IMMEDIATE);
469 IDirectSound3DBuffer_Release(buf3d);
472 ((DS8Buffer*)in)->bufferlost = buf->bufferlost = savelost;
474 if(FAILED(hr))
476 if(*out)
477 IDirectSoundBuffer_Release(*out);
478 *out = NULL;
479 goto out;
482 out:
483 LeaveCriticalSection(&openal_crst);
484 return hr;
487 static HRESULT WINAPI DS8_SetCooperativeLevel(IDirectSound8 *iface, HWND hwnd, DWORD level)
489 DS8Impl *This = impl_from_IDirectSound8(iface);
490 HRESULT hr = S_OK;
492 TRACE("(%p)->(%p, %u)\n", iface, hwnd, level);
494 EnterCriticalSection(&openal_crst);
495 if(!This->device)
496 hr = DSERR_UNINITIALIZED;
497 else if(level > DSSCL_WRITEPRIMARY || level < DSSCL_NORMAL)
498 hr = E_INVALIDARG;
499 else if(level == DSSCL_WRITEPRIMARY && (This->prio_level != DSSCL_WRITEPRIMARY))
501 DWORD i, state;
503 for(i = 0; i < This->primary->nbuffers; ++i)
505 DS8Buffer *buf = This->primary->buffers[i];
506 if(FAILED(IDirectSoundBuffer_GetStatus(&buf->IDirectSoundBuffer8_iface, &state)) ||
507 (state&DSBSTATUS_PLAYING))
509 WARN("DSSCL_WRITEPRIMARY set with playing buffers!\n");
510 hr = DSERR_INVALIDCALL;
511 goto out;
513 /* Mark buffer as lost */
514 buf->bufferlost = 1;
516 if(This->primary->write_emu)
518 ERR("Why was there a write_emu?\n");
519 /* Delete it */
520 IDirectSoundBuffer8_Release(This->primary->write_emu);
521 This->primary->write_emu = NULL;
523 if(This->primary->flags)
525 /* Primary has open references.. create write_emu */
526 DSBUFFERDESC desc;
527 DS8Buffer *emu;
529 memset(&desc, 0, sizeof(desc));
530 desc.dwSize = sizeof(desc);
531 desc.dwFlags = DSBCAPS_LOCHARDWARE | (This->primary->flags&DSBCAPS_CTRLPAN);
532 desc.dwBufferBytes = This->primary->buf_size;
533 desc.lpwfxFormat = &This->primary->format.Format;
535 hr = DS8Buffer_Create(&emu, This->primary, NULL);
536 if(SUCCEEDED(hr))
538 This->primary->write_emu = &emu->IDirectSoundBuffer8_iface;
539 hr = IDirectSoundBuffer8_Initialize(This->primary->write_emu, (IDirectSound*)&This->IDirectSound8_iface, &desc);
540 if(FAILED(hr))
542 IDirectSoundBuffer8_Release(This->primary->write_emu);
543 This->primary->write_emu = NULL;
548 else if(This->prio_level == DSSCL_WRITEPRIMARY && level != DSSCL_WRITEPRIMARY && This->primary->write_emu)
550 TRACE("Nuking write_emu\n");
551 /* Delete it */
552 IDirectSoundBuffer8_Release(This->primary->write_emu);
553 This->primary->write_emu = NULL;
555 if(SUCCEEDED(hr))
556 This->prio_level = level;
557 out:
558 LeaveCriticalSection(&openal_crst);
560 return hr;
563 static HRESULT WINAPI DS8_Compact(IDirectSound8 *iface)
565 DS8Impl *This = impl_from_IDirectSound8(iface);
566 HRESULT hr = S_OK;
568 TRACE("(%p)->()\n", iface);
570 EnterCriticalSection(&openal_crst);
571 if(!This->device)
572 hr = DSERR_UNINITIALIZED;
573 else if(This->prio_level < DSSCL_PRIORITY)
574 hr = DSERR_PRIOLEVELNEEDED;
575 LeaveCriticalSection(&openal_crst);
577 return hr;
580 static HRESULT WINAPI DS8_GetSpeakerConfig(IDirectSound8 *iface, DWORD *config)
582 DS8Impl *This = impl_from_IDirectSound8(iface);
583 HRESULT hr = S_OK;
585 TRACE("(%p)->(%p)\n", iface, config);
587 if(!config)
588 return DSERR_INVALIDPARAM;
590 EnterCriticalSection(&openal_crst);
591 if(!This->device)
592 hr = DSERR_UNINITIALIZED;
593 else
594 *config = This->speaker_config;
595 LeaveCriticalSection(&openal_crst);
597 return hr;
600 static HRESULT WINAPI DS8_SetSpeakerConfig(IDirectSound8 *iface, DWORD config)
602 DS8Impl *This = impl_from_IDirectSound8(iface);
603 HRESULT hr;
605 TRACE("(%p)->(0x%08x)\n", iface, config);
607 EnterCriticalSection(&openal_crst);
608 if(!This->device)
609 hr = DSERR_UNINITIALIZED;
610 else
612 HKEY key;
613 DWORD geo, speaker;
615 geo = DSSPEAKER_GEOMETRY(config);
616 speaker = DSSPEAKER_CONFIG(config);
618 hr = DSERR_INVALIDPARAM;
619 if(geo && (geo < DSSPEAKER_GEOMETRY_MIN || geo > DSSPEAKER_GEOMETRY_MAX))
621 WARN("Invalid speaker angle %u\n", geo);
622 goto out;
624 if(speaker < DSSPEAKER_HEADPHONE || speaker > DSSPEAKER_7POINT1)
626 WARN("Invalid speaker config %u\n", speaker);
627 goto out;
630 hr = DSERR_GENERIC;
631 if(!RegCreateKeyExW(HKEY_LOCAL_MACHINE, speakerconfigkey, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL))
633 RegSetValueExW(key, speakerconfig, 0, REG_DWORD, (const BYTE*)&config, sizeof(DWORD));
634 This->speaker_config = config;
635 RegCloseKey(key);
636 hr = S_OK;
639 out:
640 LeaveCriticalSection(&openal_crst);
642 return hr;
645 static HRESULT WINAPI DS8_Initialize(IDirectSound8 *iface, const GUID *devguid)
647 DS8Impl *This = impl_from_IDirectSound8(iface);
648 const ALCchar *drv_name;
649 HRESULT hr;
650 UINT n;
652 TRACE("(%p)->(%s)\n", iface, debugstr_guid(devguid));
654 if(!openal_loaded)
655 return DSERR_NODRIVER;
657 if(!devguid)
658 devguid = &DSDEVID_DefaultPlayback;
660 EnterCriticalSection(&openal_crst);
662 hr = DSERR_ALREADYINITIALIZED;
663 if(This->device)
664 goto out;
666 hr = GetDeviceID(devguid, &This->guid);
667 if(FAILED(hr))
668 goto out;
670 for(n = 0;n < devicelistsize;n++)
672 if(devicelist[n]->device && devicelist[n]->is_8 == This->is_8 &&
673 IsEqualGUID(&devicelist[n]->guid, &This->guid))
675 TRACE("Matched already open device %p\n", devicelist[n]);
677 This->device = devicelist[n]->device;
678 This->primary = devicelist[n]->primary;
679 This->deviceref = devicelist[n]->deviceref;
680 InterlockedIncrement(This->deviceref);
682 hr = DS_OK;
683 goto out;
687 if(!This->deviceref)
689 hr = DSERR_OUTOFMEMORY;
690 if(!(This->deviceref=HeapAlloc(GetProcessHeap(), 0, sizeof(LONG))))
691 goto out;
692 This->deviceref[0] = 1;
695 hr = DSERR_NODRIVER;
696 if(!(drv_name=DSOUND_getdevicestrings()) ||
697 memcmp(&This->guid, &DSOUND_renderer_guid, sizeof(GUID)-1) != 0)
699 WARN("No device found\n");
700 goto out;
703 n = This->guid.Data4[7];
704 while(*drv_name && n--)
705 drv_name += strlen(drv_name) + 1;
706 if(!*drv_name)
708 WARN("No device string found\n");
709 goto out;
712 This->device = alcOpenDevice(drv_name);
713 if(!This->device)
715 alcGetError(NULL);
716 WARN("Couldn't open device \"%s\"\n", drv_name);
717 goto out;
719 TRACE("Opened device: %s\n", alcGetString(This->device, ALC_DEVICE_SPECIFIER));
721 hr = DS8Primary_Create(&This->primary, This);
722 if(FAILED(hr))
724 alcCloseDevice(This->device);
725 This->device = NULL;
728 out:
729 LeaveCriticalSection(&openal_crst);
731 return hr;
734 /* I, Maarten Lankhorst, hereby declare this driver certified
735 * What this means.. ? An extra bit set
737 static HRESULT WINAPI DS8_VerifyCertification(IDirectSound8 *iface, DWORD *certified)
739 DS8Impl *This = impl_from_IDirectSound8(iface);
740 HRESULT hr;
742 TRACE("(%p)->(%p)\n", iface, certified);
744 if(!certified)
745 return DSERR_INVALIDPARAM;
747 EnterCriticalSection(&openal_crst);
748 hr = S_OK;
749 if(!This->device)
750 hr = DSERR_UNINITIALIZED;
751 else
752 *certified = DS_CERTIFIED;
753 LeaveCriticalSection(&openal_crst);
755 return hr;
758 static const IDirectSound8Vtbl DS8_Vtbl =
760 DS8_QueryInterface,
761 DS8_AddRef,
762 DS8_Release,
763 DS8_CreateSoundBuffer,
764 DS8_GetCaps,
765 DS8_DuplicateSoundBuffer,
766 DS8_SetCooperativeLevel,
767 DS8_Compact,
768 DS8_GetSpeakerConfig,
769 DS8_SetSpeakerConfig,
770 DS8_Initialize,
771 DS8_VerifyCertification