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
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
38 #include "wine/debug.h"
41 #include "dsound_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
51 #include "dsound_private.h"
53 #ifndef DSSPEAKER_7POINT1
54 #define DSSPEAKER_7POINT1 7
59 static DeviceShare
**sharelist
;
60 static UINT sharelistsize
;
62 static void DSShare_Destroy(DeviceShare
*share
)
66 EnterCriticalSection(&openal_crst
);
67 for(i
= 0;i
< sharelistsize
;i
++)
69 if(sharelist
[i
] == share
)
71 sharelist
[i
] = sharelist
[--sharelistsize
];
72 if(sharelistsize
== 0)
74 HeapFree(GetProcessHeap(), 0, sharelist
);
80 LeaveCriticalSection(&openal_crst
);
84 /* Calling setALContext is not appropriate here,
85 * since we *have* to unset the context before destroying it
89 EnterCriticalSection(&openal_crst
);
90 old_ctx
= get_context();
91 if(old_ctx
!= share
->ctx
)
92 set_context(share
->ctx
);
97 alDeleteSources(share
->nsources
, share
->sources
);
100 share
->ExtAL
.DeleteEffects(1, &share
->effect
);
102 share
->ExtAL
.DeleteAuxiliaryEffectSlots(1, &share
->auxslot
);
104 set_context(old_ctx
);
105 alcDestroyContext(share
->ctx
);
106 LeaveCriticalSection(&openal_crst
);
110 alcCloseDevice(share
->device
);
111 share
->device
= NULL
;
113 share
->crst
.DebugInfo
->Spare
[0] = 0;
114 DeleteCriticalSection(&share
->crst
);
116 HeapFree(GetProcessHeap(), 0, share
);
119 static HRESULT
DSShare_Create(REFIID guid
, DeviceShare
**out
)
121 const ALCchar
*drv_name
;
127 share
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*share
));
128 if(!share
) return DSERR_OUTOFMEMORY
;
131 InitializeCriticalSection(&share
->crst
);
132 share
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": Device.crst");
135 if(!(drv_name
=DSOUND_getdevicestrings()) ||
136 memcmp(guid
, &DSOUND_renderer_guid
, sizeof(GUID
)-1) != 0)
138 WARN("No device found\n");
143 while(*drv_name
&& n
--)
144 drv_name
+= strlen(drv_name
) + 1;
147 WARN("No device string found\n");
150 memcpy(&share
->guid
, guid
, sizeof(GUID
));
152 share
->device
= alcOpenDevice(drv_name
);
156 WARN("Couldn't open device \"%s\"\n", drv_name
);
159 TRACE("Opened device: %s\n", alcGetString(share
->device
, ALC_DEVICE_SPECIFIER
));
162 share
->ctx
= alcCreateContext(share
->device
, NULL
);
165 ALCenum err
= alcGetError(share
->device
);
166 ERR("Could not create context (0x%x)!\n", err
);
170 setALContext(share
->ctx
);
171 if(alIsExtensionPresent("AL_EXT_FLOAT32"))
173 TRACE("Found AL_EXT_FLOAT32\n");
174 share
->SupportedExt
[EXT_FLOAT32
] = AL_TRUE
;
176 if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
178 TRACE("Found AL_EXT_MCFORMATS\n");
179 share
->SupportedExt
[EXT_MCFORMATS
] = AL_TRUE
;
181 if(alIsExtensionPresent("AL_EXT_STATIC_BUFFER"))
183 TRACE("Found AL_EXT_STATIC_BUFFER\n");
184 share
->ExtAL
.BufferDataStatic
= alGetProcAddress("alBufferDataStatic");
185 share
->SupportedExt
[EXT_STATIC_BUFFER
] = AL_TRUE
;
187 if(alIsExtensionPresent("AL_SOFTX_buffer_samples"))
189 TRACE("Found AL_SOFTX_buffer_samples\n");
190 share
->ExtAL
.BufferSamplesSOFT
= alGetProcAddress("alBufferSamplesSOFT");
191 share
->ExtAL
.BufferSubSamplesSOFT
= alGetProcAddress("alBufferSubSamplesSOFT");
192 share
->ExtAL
.GetBufferSamplesSOFT
= alGetProcAddress("alGetBufferSamplesSOFT");
193 share
->ExtAL
.IsBufferFormatSupportedSOFT
= alGetProcAddress("alIsBufferFormatSupportedSOFT");
194 share
->SupportedExt
[SOFT_BUFFER_SAMPLES
] = AL_TRUE
;
196 if(alIsExtensionPresent("AL_SOFT_buffer_sub_data"))
198 TRACE("Found AL_SOFT_buffer_sub_data\n");
199 share
->ExtAL
.BufferSubData
= alGetProcAddress("alBufferSubDataSOFT");
200 share
->SupportedExt
[SOFT_BUFFER_SUB_DATA
] = AL_TRUE
;
202 if(alIsExtensionPresent("AL_SOFTX_deferred_updates"))
204 TRACE("Found AL_SOFTX_deferred_updates\n");
205 share
->ExtAL
.DeferUpdatesSOFT
= alGetProcAddress("alDeferUpdatesSOFT");
206 share
->ExtAL
.ProcessUpdatesSOFT
= alGetProcAddress("alProcessUpdatesSOFT");
207 share
->SupportedExt
[SOFT_DEFERRED_UPDATES
] = AL_TRUE
;
210 if(alcIsExtensionPresent(share
->device
, "ALC_EXT_EFX"))
212 #define LOAD_FUNC(x) (share->ExtAL.x = alGetProcAddress("al"#x))
213 LOAD_FUNC(GenEffects
);
214 LOAD_FUNC(DeleteEffects
);
218 LOAD_FUNC(GenAuxiliaryEffectSlots
);
219 LOAD_FUNC(DeleteAuxiliaryEffectSlots
);
220 LOAD_FUNC(AuxiliaryEffectSloti
);
222 share
->SupportedExt
[EXT_EFX
] = AL_TRUE
;
224 share
->ExtAL
.GenEffects(1, &share
->effect
);
225 share
->ExtAL
.Effecti(share
->effect
, AL_EFFECT_TYPE
, AL_EFFECT_REVERB
);
227 share
->ExtAL
.GenAuxiliaryEffectSlots(1, &share
->auxslot
);
230 if(!share
->SupportedExt
[SOFT_BUFFER_SUB_DATA
] &&
231 !share
->SupportedExt
[SOFT_BUFFER_SAMPLES
] &&
232 !share
->SupportedExt
[EXT_STATIC_BUFFER
])
234 ERR("Missing alBufferSubDataSOFT, alBufferSamplesSOFT , and alBufferDataStatic on device '%s', sound playback quality may be degraded\n",
235 alcGetString(share
->device
, ALC_DEVICE_SPECIFIER
));
236 ERR("Please consider using OpenAL-Soft\n");
239 share
->max_sources
= 0;
240 while(share
->max_sources
< MAX_SOURCES
)
242 alGenSources(1, &share
->sources
[share
->max_sources
]);
243 if(alGetError() != AL_NO_ERROR
)
245 share
->max_sources
++;
247 share
->nsources
= share
->max_sources
;
251 temp
= HeapReAlloc(GetProcessHeap(), 0, sharelist
, sizeof(*sharelist
)*(sharelistsize
+1));
253 temp
= HeapAlloc(GetProcessHeap(), 0, sizeof(*sharelist
)*(sharelistsize
+1));
257 sharelist
[sharelistsize
++] = share
;
264 DSShare_Destroy(share
);
268 static ULONG
DSShare_AddRef(DeviceShare
*share
)
270 ULONG ref
= InterlockedIncrement(&share
->ref
);
274 static ULONG
DSShare_Release(DeviceShare
*share
)
276 ULONG ref
= InterlockedDecrement(&share
->ref
);
277 if(ref
== 0) DSShare_Destroy(share
);
282 static const IDirectSound8Vtbl DS8_Vtbl
;
283 static const IDirectSoundVtbl DS_Vtbl
;
285 static inline DS8Impl
*impl_from_IDirectSound8(IDirectSound8
*iface
)
287 return CONTAINING_RECORD(iface
, DS8Impl
, IDirectSound8_iface
);
290 static inline DS8Impl
*impl_from_IDirectSound(IDirectSound
*iface
)
292 return CONTAINING_RECORD(iface
, DS8Impl
, IDirectSound_iface
);
295 HRESULT
DSOUND_Create(REFIID riid
, void **ds
)
299 hr
= DSOUND_Create8(&IID_IDirectSound
, ds
);
302 DS8Impl
*impl
= impl_from_IDirectSound(*ds
);
305 if(!IsEqualIID(riid
, &IID_IDirectSound
))
307 hr
= IDirectSound_QueryInterface(&impl
->IDirectSound_iface
, riid
, ds
);
308 IDirectSound_Release(&impl
->IDirectSound_iface
);
314 static void DS8Impl_Destroy(DS8Impl
*This
);
316 static const WCHAR speakerconfigkey
[] = {
317 'S','Y','S','T','E','M','\\',
318 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
319 'C','o','n','t','r','o','l','\\',
320 'M','e','d','i','a','R','e','s','o','u','r','c','e','s','\\',
321 'D','i','r','e','c','t','S','o','u','n','d','\\',
322 'S','p','e','a','k','e','r',' ','C','o','n','f','i','g','u','r','a','t','i','o','n',0
325 static const WCHAR speakerconfig
[] = {
326 'S','p','e','a','k','e','r',' ','C','o','n','f','i','g','u','r','a','t','i','o','n',0
329 HRESULT
DSOUND_Create8(REFIID riid
, LPVOID
*ds
)
336 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*This
));
337 if(!This
) return DSERR_OUTOFMEMORY
;
339 This
->IDirectSound8_iface
.lpVtbl
= (IDirectSound8Vtbl
*)&DS8_Vtbl
;
340 This
->IDirectSound_iface
.lpVtbl
= (IDirectSoundVtbl
*)&DS_Vtbl
;
343 This
->speaker_config
= DSSPEAKER_COMBINED(DSSPEAKER_5POINT1
, DSSPEAKER_GEOMETRY_WIDE
);
345 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, speakerconfigkey
, 0, KEY_READ
, ®key
) == ERROR_SUCCESS
)
347 DWORD type
, conf
, confsize
= sizeof(DWORD
);
349 if(RegQueryValueExW(regkey
, speakerconfig
, NULL
, &type
, (BYTE
*)&conf
, &confsize
) == ERROR_SUCCESS
)
351 if(type
== REG_DWORD
)
352 This
->speaker_config
= conf
;
357 /*RegGetValueW(HKEY_LOCAL_MACHINE, speakerconfigkey, speakerconfig, RRF_RT_REG_DWORD, NULL, &This->speaker_config, NULL);*/
359 hr
= IDirectSound8_QueryInterface(&This
->IDirectSound8_iface
, riid
, ds
);
361 DS8Impl_Destroy(This
);
365 static void DS8Impl_Destroy(DS8Impl
*This
)
367 DS8Primary_Destroy(&This
->primary
);
369 DSShare_Release(This
->share
);
372 HeapFree(GetProcessHeap(), 0, This
);
376 static HRESULT WINAPI
DS8_QueryInterface(IDirectSound8
*iface
, REFIID riid
, LPVOID
*ppv
)
378 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
380 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
383 if(IsEqualIID(riid
, &IID_IUnknown
) ||
384 IsEqualIID(riid
, &IID_IDirectSound
))
385 *ppv
= &This
->IDirectSound8_iface
;
386 else if((IsEqualIID(riid
, &IID_IDirectSound8
)))
389 *ppv
= &This
->IDirectSound8_iface
;
392 FIXME("Unhandled GUID: %s\n", debugstr_guid(riid
));
396 IUnknown_AddRef((IUnknown
*)*ppv
);
400 return E_NOINTERFACE
;
403 static ULONG WINAPI
DS8_AddRef(IDirectSound8
*iface
)
405 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
408 ref
= InterlockedIncrement(&This
->ref
);
409 TRACE("Reference count incremented to %"LONGFMT
"d\n", ref
);
414 static ULONG WINAPI
DS8_Release(IDirectSound8
*iface
)
416 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
419 ref
= InterlockedDecrement(&This
->ref
);
420 TRACE("Reference count decremented to %"LONGFMT
"d\n", ref
);
422 DS8Impl_Destroy(This
);
427 static HRESULT WINAPI
DS8_CreateSoundBuffer(IDirectSound8
*iface
, LPCDSBUFFERDESC desc
, LPLPDIRECTSOUNDBUFFER buf
, IUnknown
*pUnkOuter
)
429 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
432 TRACE("(%p)->(%p, %p, %p)\n", iface
, desc
, buf
, pUnkOuter
);
436 WARN("buf is null\n");
437 return DSERR_INVALIDPARAM
;
443 WARN("Aggregation isn't supported\n");
444 return DSERR_NOAGGREGATION
;
446 if(!desc
|| desc
->dwSize
< sizeof(DSBUFFERDESC1
))
448 WARN("Invalid buffer %p/%"LONGFMT
"u\n", desc
, desc
?desc
->dwSize
:0);
449 return DSERR_INVALIDPARAM
;
454 WARN("Device not initialized\n");
455 return DSERR_UNINITIALIZED
;
458 TRACE("Requested buffer:\n"
459 " Size = %"LONGFMT
"u\n"
460 " Flags = 0x%08"LONGFMT
"x\n"
461 " BufferBytes = %"LONGFMT
"u\n",
462 desc
->dwSize
, desc
->dwFlags
, desc
->dwBufferBytes
);
464 if(desc
->dwSize
>= sizeof(DSBUFFERDESC
))
466 if(!(desc
->dwFlags
&DSBCAPS_CTRL3D
))
468 if(!IsEqualGUID(&desc
->guid3DAlgorithm
, &GUID_NULL
))
470 WARN("Invalid 3D algorithm GUID specified for non-3D buffer: %s\n", debugstr_guid(&desc
->guid3DAlgorithm
));
471 return DSERR_INVALIDPARAM
;
475 TRACE("Requested 3D algorithm GUID: %s\n", debugstr_guid(&desc
->guid3DAlgorithm
));
478 /* OpenAL doesn't support playing with 3d and panning at same time.. */
479 if((desc
->dwFlags
&(DSBCAPS_CTRL3D
|DSBCAPS_CTRLPAN
)) == (DSBCAPS_CTRL3D
|DSBCAPS_CTRLPAN
))
482 ERR("Cannot create buffers with 3D and panning control\n");
484 WARN("Cannot create buffers with 3D and panning control\n");
485 return DSERR_INVALIDPARAM
;
488 EnterCriticalSection(This
->primary
.crst
);
489 if((desc
->dwFlags
&DSBCAPS_PRIMARYBUFFER
))
491 IDirectSoundBuffer
*prim
= &This
->primary
.IDirectSoundBuffer_iface
;
494 if(IDirectSoundBuffer_AddRef(prim
) == 1)
496 hr
= IDirectSoundBuffer_Initialize(prim
, &This
->IDirectSound_iface
, desc
);
499 IDirectSoundBuffer_Release(prim
);
509 hr
= DS8Buffer_Create(&dsb
, &This
->primary
, NULL
);
512 hr
= IDirectSoundBuffer8_Initialize(&dsb
->IDirectSoundBuffer8_iface
, &This
->IDirectSound_iface
, desc
);
514 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
517 dsb
->bufferlost
= (This
->prio_level
== DSSCL_WRITEPRIMARY
);
518 *buf
= &dsb
->IDirectSoundBuffer_iface
;
522 LeaveCriticalSection(This
->primary
.crst
);
524 TRACE("%08"LONGFMT
"x\n", hr
);
528 static HRESULT WINAPI
DS8_GetCaps(IDirectSound8
*iface
, LPDSCAPS caps
)
530 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
532 TRACE("(%p)->(%p)\n", iface
, caps
);
536 WARN("Device not initialized\n");
537 return DSERR_UNINITIALIZED
;
540 if(!caps
|| caps
->dwSize
< sizeof(*caps
))
542 WARN("Invalid DSCAPS (%p, %"LONGFMT
"u)\n", caps
, (caps
?caps
->dwSize
:0));
543 return DSERR_INVALIDPARAM
;
546 EnterCriticalSection(&This
->share
->crst
);
548 caps
->dwFlags
= DSCAPS_CONTINUOUSRATE
|
549 DSCAPS_PRIMARY16BIT
| DSCAPS_PRIMARYSTEREO
|
550 DSCAPS_PRIMARY8BIT
| DSCAPS_PRIMARYMONO
|
551 DSCAPS_SECONDARY16BIT
| DSCAPS_SECONDARY8BIT
|
552 DSCAPS_SECONDARYMONO
| DSCAPS_SECONDARYSTEREO
;
553 caps
->dwPrimaryBuffers
= 1;
554 caps
->dwMinSecondarySampleRate
= DSBFREQUENCY_MIN
;
555 caps
->dwMaxSecondarySampleRate
= DSBFREQUENCY_MAX
;
556 caps
->dwMaxHwMixingAllBuffers
=
557 caps
->dwMaxHwMixingStaticBuffers
=
558 caps
->dwMaxHwMixingStreamingBuffers
=
559 caps
->dwMaxHw3DAllBuffers
=
560 caps
->dwMaxHw3DStaticBuffers
=
561 caps
->dwMaxHw3DStreamingBuffers
= This
->share
->max_sources
;
562 caps
->dwFreeHwMixingAllBuffers
=
563 caps
->dwFreeHwMixingStaticBuffers
=
564 caps
->dwFreeHwMixingStreamingBuffers
=
565 caps
->dwFreeHw3DAllBuffers
=
566 caps
->dwFreeHw3DStaticBuffers
=
567 caps
->dwFreeHw3DStreamingBuffers
= This
->share
->nsources
;
568 caps
->dwTotalHwMemBytes
=
569 caps
->dwFreeHwMemBytes
= 64 * 1024 * 1024;
570 caps
->dwMaxContigFreeHwMemBytes
= caps
->dwFreeHwMemBytes
;
571 caps
->dwUnlockTransferRateHwBuffers
= 4096;
572 caps
->dwPlayCpuOverheadSwBuffers
= 0;
574 LeaveCriticalSection(&This
->share
->crst
);
578 static HRESULT WINAPI
DS8_DuplicateSoundBuffer(IDirectSound8
*iface
, IDirectSoundBuffer
*in
, IDirectSoundBuffer
**out
)
580 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
585 TRACE("(%p)->(%p, %p)\n", iface
, in
, out
);
589 WARN("Device not initialized\n");
590 return DSERR_UNINITIALIZED
;
595 WARN("Invalid pointer: int = %p, out = %p\n", in
, out
);
596 return DSERR_INVALIDPARAM
;
600 caps
.dwSize
= sizeof(caps
);
601 hr
= IDirectSoundBuffer_GetCaps(in
, &caps
);
602 if(SUCCEEDED(hr
) && (caps
.dwFlags
&DSBCAPS_PRIMARYBUFFER
))
604 WARN("Cannot duplicate buffer %p, which has DSBCAPS_PRIMARYBUFFER\n", in
);
605 hr
= DSERR_INVALIDPARAM
;
607 if(SUCCEEDED(hr
) && (caps
.dwFlags
&DSBCAPS_CTRLFX
))
609 WARN("Cannot duplicate buffer %p, which has DSBCAPS_CTRLFX\n", in
);
610 hr
= DSERR_INVALIDPARAM
;
613 hr
= DS8Buffer_Create(&buf
, &This
->primary
, in
);
616 *out
= &buf
->IDirectSoundBuffer_iface
;
617 hr
= IDirectSoundBuffer_Initialize(*out
, NULL
, NULL
);
621 /* According to MSDN volume isn't copied */
622 if((caps
.dwFlags
&DSBCAPS_CTRLPAN
))
625 if(SUCCEEDED(IDirectSoundBuffer_GetPan(in
, &pan
)))
626 IDirectSoundBuffer_SetPan(*out
, pan
);
628 if((caps
.dwFlags
&DSBCAPS_CTRLFREQUENCY
))
631 if(SUCCEEDED(IDirectSoundBuffer_GetFrequency(in
, &freq
)))
632 IDirectSoundBuffer_SetFrequency(*out
, freq
);
634 if((caps
.dwFlags
&DSBCAPS_CTRL3D
))
636 IDirectSound3DBuffer
*buf3d
;
637 DS3DBUFFER DS3DBuffer
;
640 subhr
= IDirectSound_QueryInterface(in
, &IID_IDirectSound3DBuffer
, (void**)&buf3d
);
643 DS3DBuffer
.dwSize
= sizeof(DS3DBuffer
);
644 subhr
= IDirectSound3DBuffer_GetAllParameters(buf3d
, &DS3DBuffer
);
645 IDirectSound3DBuffer_Release(buf3d
);
648 subhr
= IDirectSoundBuffer_QueryInterface(*out
, &IID_IDirectSound3DBuffer
, (void**)&buf3d
);
651 subhr
= IDirectSound3DBuffer_SetAllParameters(buf3d
, &DS3DBuffer
, DS3D_IMMEDIATE
);
652 IDirectSound3DBuffer_Release(buf3d
);
659 IDirectSoundBuffer_Release(*out
);
666 static HRESULT WINAPI
DS8_SetCooperativeLevel(IDirectSound8
*iface
, HWND hwnd
, DWORD level
)
668 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
671 TRACE("(%p)->(%p, %"LONGFMT
"u)\n", iface
, hwnd
, level
);
675 WARN("Device not initialized\n");
676 return DSERR_UNINITIALIZED
;
679 if(level
> DSSCL_WRITEPRIMARY
|| level
< DSSCL_NORMAL
)
681 WARN("Invalid coop level: %"LONGFMT
"u\n", level
);
682 return DSERR_INVALIDPARAM
;
685 EnterCriticalSection(This
->primary
.crst
);
686 if(level
== DSSCL_WRITEPRIMARY
&& (This
->prio_level
!= DSSCL_WRITEPRIMARY
))
690 for(i
= 0; i
< This
->primary
.nbuffers
; ++i
)
692 DS8Buffer
*buf
= This
->primary
.buffers
[i
];
693 if(FAILED(IDirectSoundBuffer_GetStatus(&buf
->IDirectSoundBuffer8_iface
, &state
)) ||
694 (state
&DSBSTATUS_PLAYING
))
696 WARN("DSSCL_WRITEPRIMARY set with playing buffers!\n");
697 hr
= DSERR_INVALIDCALL
;
700 /* Mark buffer as lost */
703 if(This
->primary
.write_emu
)
705 ERR("Why was there a write_emu?\n");
707 IDirectSoundBuffer8_Release(This
->primary
.write_emu
);
708 This
->primary
.write_emu
= NULL
;
710 if(This
->primary
.flags
)
712 /* Primary has open references.. create write_emu */
716 memset(&desc
, 0, sizeof(desc
));
717 desc
.dwSize
= sizeof(desc
);
718 desc
.dwFlags
= DSBCAPS_LOCHARDWARE
| (This
->primary
.flags
&DSBCAPS_CTRLPAN
);
719 desc
.dwBufferBytes
= This
->primary
.buf_size
;
720 desc
.lpwfxFormat
= &This
->primary
.format
.Format
;
722 hr
= DS8Buffer_Create(&emu
, &This
->primary
, NULL
);
725 This
->primary
.write_emu
= &emu
->IDirectSoundBuffer8_iface
;
726 hr
= IDirectSoundBuffer8_Initialize(This
->primary
.write_emu
, &This
->IDirectSound_iface
, &desc
);
729 IDirectSoundBuffer8_Release(This
->primary
.write_emu
);
730 This
->primary
.write_emu
= NULL
;
735 else if(This
->prio_level
== DSSCL_WRITEPRIMARY
&& level
!= DSSCL_WRITEPRIMARY
&& This
->primary
.write_emu
)
737 TRACE("Nuking write_emu\n");
739 IDirectSoundBuffer8_Release(This
->primary
.write_emu
);
740 This
->primary
.write_emu
= NULL
;
743 This
->prio_level
= level
;
745 LeaveCriticalSection(This
->primary
.crst
);
750 static HRESULT WINAPI
DS8_Compact(IDirectSound8
*iface
)
752 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
755 TRACE("(%p)->()\n", iface
);
759 WARN("Device not initialized\n");
760 return DSERR_UNINITIALIZED
;
763 EnterCriticalSection(&This
->share
->crst
);
764 if(This
->prio_level
< DSSCL_PRIORITY
)
766 WARN("Coop level not high enough (%"LONGFMT
"u)\n", This
->prio_level
);
767 hr
= DSERR_PRIOLEVELNEEDED
;
769 LeaveCriticalSection(&This
->share
->crst
);
774 static HRESULT WINAPI
DS8_GetSpeakerConfig(IDirectSound8
*iface
, DWORD
*config
)
776 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
779 TRACE("(%p)->(%p)\n", iface
, config
);
782 return DSERR_INVALIDPARAM
;
787 WARN("Device not initialized\n");
788 return DSERR_UNINITIALIZED
;
791 EnterCriticalSection(&This
->share
->crst
);
792 *config
= This
->speaker_config
;
793 LeaveCriticalSection(&This
->share
->crst
);
798 static HRESULT WINAPI
DS8_SetSpeakerConfig(IDirectSound8
*iface
, DWORD config
)
800 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
805 TRACE("(%p)->(0x%08"LONGFMT
"x)\n", iface
, config
);
809 WARN("Device not initialized\n");
810 return DSERR_UNINITIALIZED
;
813 geo
= DSSPEAKER_GEOMETRY(config
);
814 speaker
= DSSPEAKER_CONFIG(config
);
816 if(geo
&& (geo
< DSSPEAKER_GEOMETRY_MIN
|| geo
> DSSPEAKER_GEOMETRY_MAX
))
818 WARN("Invalid speaker angle %"LONGFMT
"u\n", geo
);
819 return DSERR_INVALIDPARAM
;
821 if(speaker
< DSSPEAKER_HEADPHONE
|| speaker
> DSSPEAKER_7POINT1
)
823 WARN("Invalid speaker config %"LONGFMT
"u\n", speaker
);
824 return DSERR_INVALIDPARAM
;
827 EnterCriticalSection(&This
->share
->crst
);
830 if(!RegCreateKeyExW(HKEY_LOCAL_MACHINE
, speakerconfigkey
, 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
832 RegSetValueExW(key
, speakerconfig
, 0, REG_DWORD
, (const BYTE
*)&config
, sizeof(DWORD
));
833 This
->speaker_config
= config
;
838 LeaveCriticalSection(&This
->share
->crst
);
842 static HRESULT WINAPI
DS8_Initialize(IDirectSound8
*iface
, const GUID
*devguid
)
844 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
849 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(devguid
));
852 return DSERR_NODRIVER
;
856 WARN("Device already initialized\n");
857 return DSERR_ALREADYINITIALIZED
;
861 devguid
= &DSDEVID_DefaultPlayback
;
862 hr
= GetDeviceID(devguid
, &guid
);
866 EnterCriticalSection(&openal_crst
);
868 for(n
= 0;n
< sharelistsize
;n
++)
870 if(IsEqualGUID(&sharelist
[n
]->guid
, &guid
))
872 TRACE("Matched already open device %p\n", sharelist
[n
]->device
);
874 This
->share
= sharelist
[n
];
875 DSShare_AddRef(This
->share
);
881 hr
= DSShare_Create(&guid
, &This
->share
);
884 This
->device
= This
->share
->device
;
885 hr
= DS8Primary_Create(&This
->primary
, This
);
891 DSShare_Release(This
->share
);
895 LeaveCriticalSection(&openal_crst
);
899 /* I, Maarten Lankhorst, hereby declare this driver certified
900 * What this means.. ? An extra bit set
902 static HRESULT WINAPI
DS8_VerifyCertification(IDirectSound8
*iface
, DWORD
*certified
)
904 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
906 TRACE("(%p)->(%p)\n", iface
, certified
);
909 return DSERR_INVALIDPARAM
;
914 WARN("Device not initialized\n");
915 return DSERR_UNINITIALIZED
;
918 *certified
= DS_CERTIFIED
;
923 static const IDirectSound8Vtbl DS8_Vtbl
= {
927 DS8_CreateSoundBuffer
,
929 DS8_DuplicateSoundBuffer
,
930 DS8_SetCooperativeLevel
,
932 DS8_GetSpeakerConfig
,
933 DS8_SetSpeakerConfig
,
935 DS8_VerifyCertification
939 static HRESULT WINAPI
DS_QueryInterface(IDirectSound
*iface
, REFIID riid
, LPVOID
*ppv
)
941 DS8Impl
*This
= impl_from_IDirectSound(iface
);
942 return DS8_QueryInterface(&This
->IDirectSound8_iface
, riid
, ppv
);
945 static ULONG WINAPI
DS_AddRef(IDirectSound
*iface
)
947 DS8Impl
*This
= impl_from_IDirectSound(iface
);
948 return DS8_AddRef(&This
->IDirectSound8_iface
);
951 static ULONG WINAPI
DS_Release(IDirectSound
*iface
)
953 DS8Impl
*This
= impl_from_IDirectSound(iface
);
954 return DS8_Release(&This
->IDirectSound8_iface
);
957 static HRESULT WINAPI
DS_CreateSoundBuffer(IDirectSound
*iface
, LPCDSBUFFERDESC desc
, LPLPDIRECTSOUNDBUFFER buf
, IUnknown
*pUnkOuter
)
959 DS8Impl
*This
= impl_from_IDirectSound(iface
);
960 return DS8_CreateSoundBuffer(&This
->IDirectSound8_iface
, desc
, buf
, pUnkOuter
);
963 static HRESULT WINAPI
DS_GetCaps(IDirectSound
*iface
, LPDSCAPS caps
)
965 DS8Impl
*This
= impl_from_IDirectSound(iface
);
966 return DS8_GetCaps(&This
->IDirectSound8_iface
, caps
);
968 static HRESULT WINAPI
DS_DuplicateSoundBuffer(IDirectSound
*iface
, IDirectSoundBuffer
*in
, IDirectSoundBuffer
**out
)
970 DS8Impl
*This
= impl_from_IDirectSound(iface
);
971 return DS8_DuplicateSoundBuffer(&This
->IDirectSound8_iface
, in
, out
);
974 static HRESULT WINAPI
DS_SetCooperativeLevel(IDirectSound
*iface
, HWND hwnd
, DWORD level
)
976 DS8Impl
*This
= impl_from_IDirectSound(iface
);
977 return DS8_SetCooperativeLevel(&This
->IDirectSound8_iface
, hwnd
, level
);
980 static HRESULT WINAPI
DS_Compact(IDirectSound
*iface
)
982 DS8Impl
*This
= impl_from_IDirectSound(iface
);
983 return DS8_Compact(&This
->IDirectSound8_iface
);
986 static HRESULT WINAPI
DS_GetSpeakerConfig(IDirectSound
*iface
, DWORD
*config
)
988 DS8Impl
*This
= impl_from_IDirectSound(iface
);
989 return DS8_GetSpeakerConfig(&This
->IDirectSound8_iface
, config
);
992 static HRESULT WINAPI
DS_SetSpeakerConfig(IDirectSound
*iface
, DWORD config
)
994 DS8Impl
*This
= impl_from_IDirectSound(iface
);
995 return DS8_SetSpeakerConfig(&This
->IDirectSound8_iface
, config
);
998 static HRESULT WINAPI
DS_Initialize(IDirectSound
*iface
, const GUID
*devguid
)
1000 DS8Impl
*This
= impl_from_IDirectSound(iface
);
1001 return DS8_Initialize(&This
->IDirectSound8_iface
, devguid
);
1004 static const IDirectSoundVtbl DS_Vtbl
= {
1008 DS_CreateSoundBuffer
,
1010 DS_DuplicateSoundBuffer
,
1011 DS_SetCooperativeLevel
,
1013 DS_GetSpeakerConfig
,
1014 DS_SetSpeakerConfig
,