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
.DeleteAuxiliaryEffectSlots(1, &share
->auxslot
);
102 set_context(old_ctx
);
103 alcDestroyContext(share
->ctx
);
104 LeaveCriticalSection(&openal_crst
);
108 alcCloseDevice(share
->device
);
109 share
->device
= NULL
;
111 share
->crst
.DebugInfo
->Spare
[0] = 0;
112 DeleteCriticalSection(&share
->crst
);
114 HeapFree(GetProcessHeap(), 0, share
);
117 static HRESULT
DSShare_Create(REFIID guid
, DeviceShare
**out
)
119 const ALCchar
*drv_name
;
125 share
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*share
));
126 if(!share
) return DSERR_OUTOFMEMORY
;
129 InitializeCriticalSection(&share
->crst
);
130 share
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": Device.crst");
133 if(!(drv_name
=DSOUND_getdevicestrings()) ||
134 memcmp(guid
, &DSOUND_renderer_guid
, sizeof(GUID
)-1) != 0)
136 WARN("No device found\n");
141 while(*drv_name
&& n
--)
142 drv_name
+= strlen(drv_name
) + 1;
145 WARN("No device string found\n");
148 memcpy(&share
->guid
, guid
, sizeof(GUID
));
150 share
->device
= alcOpenDevice(drv_name
);
154 WARN("Couldn't open device \"%s\"\n", drv_name
);
157 TRACE("Opened device: %s\n", alcGetString(share
->device
, ALC_DEVICE_SPECIFIER
));
160 share
->ctx
= alcCreateContext(share
->device
, NULL
);
163 ALCenum err
= alcGetError(share
->device
);
164 ERR("Could not create context (0x%x)!\n", err
);
168 setALContext(share
->ctx
);
169 if(alIsExtensionPresent("AL_EXT_FLOAT32"))
171 TRACE("Found AL_EXT_FLOAT32\n");
172 share
->SupportedExt
[EXT_FLOAT32
] = AL_TRUE
;
174 if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
176 TRACE("Found AL_EXT_MCFORMATS\n");
177 share
->SupportedExt
[EXT_MCFORMATS
] = AL_TRUE
;
179 if(alIsExtensionPresent("AL_EXT_STATIC_BUFFER"))
181 TRACE("Found AL_EXT_STATIC_BUFFER\n");
182 share
->ExtAL
.BufferDataStatic
= alGetProcAddress("alBufferDataStatic");
183 share
->SupportedExt
[EXT_STATIC_BUFFER
] = AL_TRUE
;
185 if(alIsExtensionPresent("AL_SOFTX_buffer_samples"))
187 TRACE("Found AL_SOFTX_buffer_samples\n");
188 share
->ExtAL
.BufferSamplesSOFT
= alGetProcAddress("alBufferSamplesSOFT");
189 share
->ExtAL
.BufferSubSamplesSOFT
= alGetProcAddress("alBufferSubSamplesSOFT");
190 share
->ExtAL
.GetBufferSamplesSOFT
= alGetProcAddress("alGetBufferSamplesSOFT");
191 share
->ExtAL
.IsBufferFormatSupportedSOFT
= alGetProcAddress("alIsBufferFormatSupportedSOFT");
192 share
->SupportedExt
[SOFT_BUFFER_SAMPLES
] = AL_TRUE
;
194 if(alIsExtensionPresent("AL_SOFT_buffer_sub_data"))
196 TRACE("Found AL_SOFT_buffer_sub_data\n");
197 share
->ExtAL
.BufferSubData
= alGetProcAddress("alBufferSubDataSOFT");
198 share
->SupportedExt
[SOFT_BUFFER_SUB_DATA
] = AL_TRUE
;
200 if(alIsExtensionPresent("AL_SOFTX_deferred_updates"))
202 TRACE("Found AL_SOFTX_deferred_updates\n");
203 share
->ExtAL
.DeferUpdatesSOFT
= alGetProcAddress("alDeferUpdatesSOFT");
204 share
->ExtAL
.ProcessUpdatesSOFT
= alGetProcAddress("alProcessUpdatesSOFT");
205 share
->SupportedExt
[SOFT_DEFERRED_UPDATES
] = AL_TRUE
;
208 if(alcIsExtensionPresent(share
->device
, "ALC_EXT_EFX"))
210 #define LOAD_FUNC(x) (share->ExtAL.x = alGetProcAddress("al"#x))
211 LOAD_FUNC(GenEffects
);
212 LOAD_FUNC(DeleteEffects
);
216 LOAD_FUNC(GenAuxiliaryEffectSlots
);
217 LOAD_FUNC(DeleteAuxiliaryEffectSlots
);
218 LOAD_FUNC(AuxiliaryEffectSloti
);
220 share
->SupportedExt
[EXT_EFX
] = AL_TRUE
;
222 share
->ExtAL
.GenAuxiliaryEffectSlots(1, &share
->auxslot
);
225 if(!share
->SupportedExt
[SOFT_BUFFER_SUB_DATA
] &&
226 !share
->SupportedExt
[SOFT_BUFFER_SAMPLES
] &&
227 !share
->SupportedExt
[EXT_STATIC_BUFFER
])
229 ERR("Missing alBufferSubDataSOFT, alBufferSamplesSOFT , and alBufferDataStatic on device '%s', sound playback quality may be degraded\n",
230 alcGetString(share
->device
, ALC_DEVICE_SPECIFIER
));
231 ERR("Please consider using OpenAL-Soft\n");
234 share
->max_sources
= 0;
235 while(share
->max_sources
< MAX_SOURCES
)
237 alGenSources(1, &share
->sources
[share
->max_sources
]);
238 if(alGetError() != AL_NO_ERROR
)
240 share
->max_sources
++;
242 share
->nsources
= share
->max_sources
;
246 temp
= HeapReAlloc(GetProcessHeap(), 0, sharelist
, sizeof(*sharelist
)*(sharelistsize
+1));
248 temp
= HeapAlloc(GetProcessHeap(), 0, sizeof(*sharelist
)*(sharelistsize
+1));
252 sharelist
[sharelistsize
++] = share
;
259 DSShare_Destroy(share
);
263 static ULONG
DSShare_AddRef(DeviceShare
*share
)
265 ULONG ref
= InterlockedIncrement(&share
->ref
);
269 static ULONG
DSShare_Release(DeviceShare
*share
)
271 ULONG ref
= InterlockedDecrement(&share
->ref
);
272 if(ref
== 0) DSShare_Destroy(share
);
277 static const IDirectSound8Vtbl DS8_Vtbl
;
278 static const IDirectSoundVtbl DS_Vtbl
;
280 static inline DS8Impl
*impl_from_IDirectSound8(IDirectSound8
*iface
)
282 return CONTAINING_RECORD(iface
, DS8Impl
, IDirectSound8_iface
);
285 static inline DS8Impl
*impl_from_IDirectSound(IDirectSound
*iface
)
287 return CONTAINING_RECORD(iface
, DS8Impl
, IDirectSound_iface
);
290 HRESULT
DSOUND_Create(REFIID riid
, void **ds
)
294 hr
= DSOUND_Create8(&IID_IDirectSound
, ds
);
297 DS8Impl
*impl
= impl_from_IDirectSound(*ds
);
300 if(!IsEqualIID(riid
, &IID_IDirectSound
))
302 hr
= IDirectSound_QueryInterface(&impl
->IDirectSound_iface
, riid
, ds
);
303 IDirectSound_Release(&impl
->IDirectSound_iface
);
309 static void DS8Impl_Destroy(DS8Impl
*This
);
311 static const WCHAR speakerconfigkey
[] = {
312 'S','Y','S','T','E','M','\\',
313 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
314 'C','o','n','t','r','o','l','\\',
315 'M','e','d','i','a','R','e','s','o','u','r','c','e','s','\\',
316 'D','i','r','e','c','t','S','o','u','n','d','\\',
317 'S','p','e','a','k','e','r',' ','C','o','n','f','i','g','u','r','a','t','i','o','n',0
320 static const WCHAR speakerconfig
[] = {
321 'S','p','e','a','k','e','r',' ','C','o','n','f','i','g','u','r','a','t','i','o','n',0
324 HRESULT
DSOUND_Create8(REFIID riid
, LPVOID
*ds
)
331 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*This
));
332 if(!This
) return DSERR_OUTOFMEMORY
;
334 This
->IDirectSound8_iface
.lpVtbl
= (IDirectSound8Vtbl
*)&DS8_Vtbl
;
335 This
->IDirectSound_iface
.lpVtbl
= (IDirectSoundVtbl
*)&DS_Vtbl
;
338 This
->speaker_config
= DSSPEAKER_COMBINED(DSSPEAKER_5POINT1
, DSSPEAKER_GEOMETRY_WIDE
);
340 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, speakerconfigkey
, 0, KEY_READ
, ®key
) == ERROR_SUCCESS
)
342 DWORD type
, conf
, confsize
= sizeof(DWORD
);
344 if(RegQueryValueExW(regkey
, speakerconfig
, NULL
, &type
, (BYTE
*)&conf
, &confsize
) == ERROR_SUCCESS
)
346 if(type
== REG_DWORD
)
347 This
->speaker_config
= conf
;
352 /*RegGetValueW(HKEY_LOCAL_MACHINE, speakerconfigkey, speakerconfig, RRF_RT_REG_DWORD, NULL, &This->speaker_config, NULL);*/
354 hr
= IDirectSound8_QueryInterface(&This
->IDirectSound8_iface
, riid
, ds
);
356 DS8Impl_Destroy(This
);
360 static void DS8Impl_Destroy(DS8Impl
*This
)
362 DS8Primary_Clear(&This
->primary
);
364 DSShare_Release(This
->share
);
367 HeapFree(GetProcessHeap(), 0, This
);
371 static HRESULT WINAPI
DS8_QueryInterface(IDirectSound8
*iface
, REFIID riid
, LPVOID
*ppv
)
373 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
375 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
378 if(IsEqualIID(riid
, &IID_IUnknown
))
379 *ppv
= &This
->IDirectSound8_iface
;
380 else if(IsEqualIID(riid
, &IID_IDirectSound8
))
383 *ppv
= &This
->IDirectSound8_iface
;
385 else if(IsEqualIID(riid
, &IID_IDirectSound
))
386 *ppv
= &This
->IDirectSound_iface
;
388 FIXME("Unhandled GUID: %s\n", debugstr_guid(riid
));
392 IUnknown_AddRef((IUnknown
*)*ppv
);
396 return E_NOINTERFACE
;
399 static ULONG WINAPI
DS8_AddRef(IDirectSound8
*iface
)
401 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
404 ref
= InterlockedIncrement(&This
->ref
);
405 TRACE("Reference count incremented to %"LONGFMT
"d\n", ref
);
410 static ULONG WINAPI
DS8_Release(IDirectSound8
*iface
)
412 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
415 ref
= InterlockedDecrement(&This
->ref
);
416 TRACE("Reference count decremented to %"LONGFMT
"d\n", ref
);
418 DS8Impl_Destroy(This
);
423 static HRESULT WINAPI
DS8_CreateSoundBuffer(IDirectSound8
*iface
, LPCDSBUFFERDESC desc
, LPLPDIRECTSOUNDBUFFER buf
, IUnknown
*pUnkOuter
)
425 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
428 TRACE("(%p)->(%p, %p, %p)\n", iface
, desc
, buf
, pUnkOuter
);
432 WARN("buf is null\n");
433 return DSERR_INVALIDPARAM
;
439 WARN("Aggregation isn't supported\n");
440 return DSERR_NOAGGREGATION
;
442 if(!desc
|| desc
->dwSize
< sizeof(DSBUFFERDESC1
))
444 WARN("Invalid buffer %p/%"LONGFMT
"u\n", desc
, desc
?desc
->dwSize
:0);
445 return DSERR_INVALIDPARAM
;
450 WARN("Device not initialized\n");
451 return DSERR_UNINITIALIZED
;
454 TRACE("Requested buffer:\n"
455 " Size = %"LONGFMT
"u\n"
456 " Flags = 0x%08"LONGFMT
"x\n"
457 " BufferBytes = %"LONGFMT
"u\n",
458 desc
->dwSize
, desc
->dwFlags
, desc
->dwBufferBytes
);
460 if(desc
->dwSize
>= sizeof(DSBUFFERDESC
))
462 if(!(desc
->dwFlags
&DSBCAPS_CTRL3D
))
464 if(!IsEqualGUID(&desc
->guid3DAlgorithm
, &GUID_NULL
))
466 WARN("Invalid 3D algorithm GUID specified for non-3D buffer: %s\n", debugstr_guid(&desc
->guid3DAlgorithm
));
467 return DSERR_INVALIDPARAM
;
471 TRACE("Requested 3D algorithm GUID: %s\n", debugstr_guid(&desc
->guid3DAlgorithm
));
474 /* OpenAL doesn't support playing with 3d and panning at same time.. */
475 if((desc
->dwFlags
&(DSBCAPS_CTRL3D
|DSBCAPS_CTRLPAN
)) == (DSBCAPS_CTRL3D
|DSBCAPS_CTRLPAN
))
478 ERR("Cannot create buffers with 3D and panning control\n");
480 WARN("Cannot create buffers with 3D and panning control\n");
481 return DSERR_INVALIDPARAM
;
484 EnterCriticalSection(This
->primary
.crst
);
485 if((desc
->dwFlags
&DSBCAPS_PRIMARYBUFFER
))
487 IDirectSoundBuffer
*prim
= &This
->primary
.IDirectSoundBuffer_iface
;
490 if(IDirectSoundBuffer_AddRef(prim
) == 1)
492 hr
= IDirectSoundBuffer_Initialize(prim
, &This
->IDirectSound_iface
, desc
);
495 IDirectSoundBuffer_Release(prim
);
505 hr
= DS8Buffer_Create(&dsb
, &This
->primary
, NULL
);
508 hr
= IDirectSoundBuffer8_Initialize(&dsb
->IDirectSoundBuffer8_iface
, &This
->IDirectSound_iface
, desc
);
510 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
513 dsb
->bufferlost
= (This
->prio_level
== DSSCL_WRITEPRIMARY
);
514 *buf
= &dsb
->IDirectSoundBuffer_iface
;
518 LeaveCriticalSection(This
->primary
.crst
);
520 TRACE("%08"LONGFMT
"x\n", hr
);
524 static HRESULT WINAPI
DS8_GetCaps(IDirectSound8
*iface
, LPDSCAPS caps
)
526 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
528 TRACE("(%p)->(%p)\n", iface
, caps
);
532 WARN("Device not initialized\n");
533 return DSERR_UNINITIALIZED
;
536 if(!caps
|| caps
->dwSize
< sizeof(*caps
))
538 WARN("Invalid DSCAPS (%p, %"LONGFMT
"u)\n", caps
, (caps
?caps
->dwSize
:0));
539 return DSERR_INVALIDPARAM
;
542 EnterCriticalSection(&This
->share
->crst
);
544 caps
->dwFlags
= DSCAPS_CONTINUOUSRATE
|
545 DSCAPS_PRIMARY16BIT
| DSCAPS_PRIMARYSTEREO
|
546 DSCAPS_PRIMARY8BIT
| DSCAPS_PRIMARYMONO
|
547 DSCAPS_SECONDARY16BIT
| DSCAPS_SECONDARY8BIT
|
548 DSCAPS_SECONDARYMONO
| DSCAPS_SECONDARYSTEREO
;
549 caps
->dwPrimaryBuffers
= 1;
550 caps
->dwMinSecondarySampleRate
= DSBFREQUENCY_MIN
;
551 caps
->dwMaxSecondarySampleRate
= DSBFREQUENCY_MAX
;
552 caps
->dwMaxHwMixingAllBuffers
=
553 caps
->dwMaxHwMixingStaticBuffers
=
554 caps
->dwMaxHwMixingStreamingBuffers
=
555 caps
->dwMaxHw3DAllBuffers
=
556 caps
->dwMaxHw3DStaticBuffers
=
557 caps
->dwMaxHw3DStreamingBuffers
= This
->share
->max_sources
;
558 caps
->dwFreeHwMixingAllBuffers
=
559 caps
->dwFreeHwMixingStaticBuffers
=
560 caps
->dwFreeHwMixingStreamingBuffers
=
561 caps
->dwFreeHw3DAllBuffers
=
562 caps
->dwFreeHw3DStaticBuffers
=
563 caps
->dwFreeHw3DStreamingBuffers
= This
->share
->nsources
;
564 caps
->dwTotalHwMemBytes
=
565 caps
->dwFreeHwMemBytes
= 64 * 1024 * 1024;
566 caps
->dwMaxContigFreeHwMemBytes
= caps
->dwFreeHwMemBytes
;
567 caps
->dwUnlockTransferRateHwBuffers
= 4096;
568 caps
->dwPlayCpuOverheadSwBuffers
= 0;
570 LeaveCriticalSection(&This
->share
->crst
);
574 static HRESULT WINAPI
DS8_DuplicateSoundBuffer(IDirectSound8
*iface
, IDirectSoundBuffer
*in
, IDirectSoundBuffer
**out
)
576 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
581 TRACE("(%p)->(%p, %p)\n", iface
, in
, out
);
585 WARN("Device not initialized\n");
586 return DSERR_UNINITIALIZED
;
591 WARN("Invalid pointer: int = %p, out = %p\n", in
, out
);
592 return DSERR_INVALIDPARAM
;
596 caps
.dwSize
= sizeof(caps
);
597 hr
= IDirectSoundBuffer_GetCaps(in
, &caps
);
598 if(SUCCEEDED(hr
) && (caps
.dwFlags
&DSBCAPS_PRIMARYBUFFER
))
600 WARN("Cannot duplicate buffer %p, which has DSBCAPS_PRIMARYBUFFER\n", in
);
601 hr
= DSERR_INVALIDPARAM
;
603 if(SUCCEEDED(hr
) && (caps
.dwFlags
&DSBCAPS_CTRLFX
))
605 WARN("Cannot duplicate buffer %p, which has DSBCAPS_CTRLFX\n", in
);
606 hr
= DSERR_INVALIDPARAM
;
609 hr
= DS8Buffer_Create(&buf
, &This
->primary
, in
);
612 *out
= &buf
->IDirectSoundBuffer_iface
;
613 hr
= IDirectSoundBuffer_Initialize(*out
, NULL
, NULL
);
617 /* According to MSDN volume isn't copied */
618 if((caps
.dwFlags
&DSBCAPS_CTRLPAN
))
621 if(SUCCEEDED(IDirectSoundBuffer_GetPan(in
, &pan
)))
622 IDirectSoundBuffer_SetPan(*out
, pan
);
624 if((caps
.dwFlags
&DSBCAPS_CTRLFREQUENCY
))
627 if(SUCCEEDED(IDirectSoundBuffer_GetFrequency(in
, &freq
)))
628 IDirectSoundBuffer_SetFrequency(*out
, freq
);
630 if((caps
.dwFlags
&DSBCAPS_CTRL3D
))
632 IDirectSound3DBuffer
*buf3d
;
633 DS3DBUFFER DS3DBuffer
;
636 subhr
= IDirectSound_QueryInterface(in
, &IID_IDirectSound3DBuffer
, (void**)&buf3d
);
639 DS3DBuffer
.dwSize
= sizeof(DS3DBuffer
);
640 subhr
= IDirectSound3DBuffer_GetAllParameters(buf3d
, &DS3DBuffer
);
641 IDirectSound3DBuffer_Release(buf3d
);
644 subhr
= IDirectSoundBuffer_QueryInterface(*out
, &IID_IDirectSound3DBuffer
, (void**)&buf3d
);
647 subhr
= IDirectSound3DBuffer_SetAllParameters(buf3d
, &DS3DBuffer
, DS3D_IMMEDIATE
);
648 IDirectSound3DBuffer_Release(buf3d
);
655 IDirectSoundBuffer_Release(*out
);
662 static HRESULT WINAPI
DS8_SetCooperativeLevel(IDirectSound8
*iface
, HWND hwnd
, DWORD level
)
664 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
667 TRACE("(%p)->(%p, %"LONGFMT
"u)\n", iface
, hwnd
, level
);
671 WARN("Device not initialized\n");
672 return DSERR_UNINITIALIZED
;
675 if(level
> DSSCL_WRITEPRIMARY
|| level
< DSSCL_NORMAL
)
677 WARN("Invalid coop level: %"LONGFMT
"u\n", level
);
678 return DSERR_INVALIDPARAM
;
681 EnterCriticalSection(This
->primary
.crst
);
682 if(level
== DSSCL_WRITEPRIMARY
&& (This
->prio_level
!= DSSCL_WRITEPRIMARY
))
686 for(i
= 0; i
< This
->primary
.nbuffers
; ++i
)
688 DS8Buffer
*buf
= This
->primary
.buffers
[i
];
689 if(FAILED(IDirectSoundBuffer_GetStatus(&buf
->IDirectSoundBuffer8_iface
, &state
)) ||
690 (state
&DSBSTATUS_PLAYING
))
692 WARN("DSSCL_WRITEPRIMARY set with playing buffers!\n");
693 hr
= DSERR_INVALIDCALL
;
696 /* Mark buffer as lost */
699 if(This
->primary
.write_emu
)
701 ERR("Why was there a write_emu?\n");
703 IDirectSoundBuffer8_Release(This
->primary
.write_emu
);
704 This
->primary
.write_emu
= NULL
;
706 if(This
->primary
.flags
)
708 /* Primary has open references.. create write_emu */
712 memset(&desc
, 0, sizeof(desc
));
713 desc
.dwSize
= sizeof(desc
);
714 desc
.dwFlags
= DSBCAPS_LOCHARDWARE
| (This
->primary
.flags
&DSBCAPS_CTRLPAN
);
715 desc
.dwBufferBytes
= This
->primary
.buf_size
;
716 desc
.lpwfxFormat
= &This
->primary
.format
.Format
;
718 hr
= DS8Buffer_Create(&emu
, &This
->primary
, NULL
);
721 This
->primary
.write_emu
= &emu
->IDirectSoundBuffer8_iface
;
722 hr
= IDirectSoundBuffer8_Initialize(This
->primary
.write_emu
, &This
->IDirectSound_iface
, &desc
);
725 IDirectSoundBuffer8_Release(This
->primary
.write_emu
);
726 This
->primary
.write_emu
= NULL
;
731 else if(This
->prio_level
== DSSCL_WRITEPRIMARY
&& level
!= DSSCL_WRITEPRIMARY
&& This
->primary
.write_emu
)
733 TRACE("Nuking write_emu\n");
735 IDirectSoundBuffer8_Release(This
->primary
.write_emu
);
736 This
->primary
.write_emu
= NULL
;
739 This
->prio_level
= level
;
741 LeaveCriticalSection(This
->primary
.crst
);
746 static HRESULT WINAPI
DS8_Compact(IDirectSound8
*iface
)
748 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
751 TRACE("(%p)->()\n", iface
);
755 WARN("Device not initialized\n");
756 return DSERR_UNINITIALIZED
;
759 EnterCriticalSection(&This
->share
->crst
);
760 if(This
->prio_level
< DSSCL_PRIORITY
)
762 WARN("Coop level not high enough (%"LONGFMT
"u)\n", This
->prio_level
);
763 hr
= DSERR_PRIOLEVELNEEDED
;
765 LeaveCriticalSection(&This
->share
->crst
);
770 static HRESULT WINAPI
DS8_GetSpeakerConfig(IDirectSound8
*iface
, DWORD
*config
)
772 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
775 TRACE("(%p)->(%p)\n", iface
, config
);
778 return DSERR_INVALIDPARAM
;
783 WARN("Device not initialized\n");
784 return DSERR_UNINITIALIZED
;
787 EnterCriticalSection(&This
->share
->crst
);
788 *config
= This
->speaker_config
;
789 LeaveCriticalSection(&This
->share
->crst
);
794 static HRESULT WINAPI
DS8_SetSpeakerConfig(IDirectSound8
*iface
, DWORD config
)
796 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
801 TRACE("(%p)->(0x%08"LONGFMT
"x)\n", iface
, config
);
805 WARN("Device not initialized\n");
806 return DSERR_UNINITIALIZED
;
809 geo
= DSSPEAKER_GEOMETRY(config
);
810 speaker
= DSSPEAKER_CONFIG(config
);
812 if(geo
&& (geo
< DSSPEAKER_GEOMETRY_MIN
|| geo
> DSSPEAKER_GEOMETRY_MAX
))
814 WARN("Invalid speaker angle %"LONGFMT
"u\n", geo
);
815 return DSERR_INVALIDPARAM
;
817 if(speaker
< DSSPEAKER_HEADPHONE
|| speaker
> DSSPEAKER_7POINT1
)
819 WARN("Invalid speaker config %"LONGFMT
"u\n", speaker
);
820 return DSERR_INVALIDPARAM
;
823 EnterCriticalSection(&This
->share
->crst
);
826 if(!RegCreateKeyExW(HKEY_LOCAL_MACHINE
, speakerconfigkey
, 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
828 RegSetValueExW(key
, speakerconfig
, 0, REG_DWORD
, (const BYTE
*)&config
, sizeof(DWORD
));
829 This
->speaker_config
= config
;
834 LeaveCriticalSection(&This
->share
->crst
);
838 static HRESULT WINAPI
DS8_Initialize(IDirectSound8
*iface
, const GUID
*devguid
)
840 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
845 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(devguid
));
848 return DSERR_NODRIVER
;
852 WARN("Device already initialized\n");
853 return DSERR_ALREADYINITIALIZED
;
857 devguid
= &DSDEVID_DefaultPlayback
;
858 hr
= GetDeviceID(devguid
, &guid
);
862 EnterCriticalSection(&openal_crst
);
864 for(n
= 0;n
< sharelistsize
;n
++)
866 if(IsEqualGUID(&sharelist
[n
]->guid
, &guid
))
868 TRACE("Matched already open device %p\n", sharelist
[n
]->device
);
870 This
->share
= sharelist
[n
];
871 DSShare_AddRef(This
->share
);
877 hr
= DSShare_Create(&guid
, &This
->share
);
880 This
->device
= This
->share
->device
;
881 hr
= DS8Primary_PreInit(&This
->primary
, This
);
887 DSShare_Release(This
->share
);
891 LeaveCriticalSection(&openal_crst
);
895 /* I, Maarten Lankhorst, hereby declare this driver certified
896 * What this means.. ? An extra bit set
898 static HRESULT WINAPI
DS8_VerifyCertification(IDirectSound8
*iface
, DWORD
*certified
)
900 DS8Impl
*This
= impl_from_IDirectSound8(iface
);
902 TRACE("(%p)->(%p)\n", iface
, certified
);
905 return DSERR_INVALIDPARAM
;
910 WARN("Device not initialized\n");
911 return DSERR_UNINITIALIZED
;
914 *certified
= DS_CERTIFIED
;
919 static const IDirectSound8Vtbl DS8_Vtbl
= {
923 DS8_CreateSoundBuffer
,
925 DS8_DuplicateSoundBuffer
,
926 DS8_SetCooperativeLevel
,
928 DS8_GetSpeakerConfig
,
929 DS8_SetSpeakerConfig
,
931 DS8_VerifyCertification
935 static HRESULT WINAPI
DS_QueryInterface(IDirectSound
*iface
, REFIID riid
, LPVOID
*ppv
)
937 DS8Impl
*This
= impl_from_IDirectSound(iface
);
938 return DS8_QueryInterface(&This
->IDirectSound8_iface
, riid
, ppv
);
941 static ULONG WINAPI
DS_AddRef(IDirectSound
*iface
)
943 DS8Impl
*This
= impl_from_IDirectSound(iface
);
944 return DS8_AddRef(&This
->IDirectSound8_iface
);
947 static ULONG WINAPI
DS_Release(IDirectSound
*iface
)
949 DS8Impl
*This
= impl_from_IDirectSound(iface
);
950 return DS8_Release(&This
->IDirectSound8_iface
);
953 static HRESULT WINAPI
DS_CreateSoundBuffer(IDirectSound
*iface
, LPCDSBUFFERDESC desc
, LPLPDIRECTSOUNDBUFFER buf
, IUnknown
*pUnkOuter
)
955 DS8Impl
*This
= impl_from_IDirectSound(iface
);
956 return DS8_CreateSoundBuffer(&This
->IDirectSound8_iface
, desc
, buf
, pUnkOuter
);
959 static HRESULT WINAPI
DS_GetCaps(IDirectSound
*iface
, LPDSCAPS caps
)
961 DS8Impl
*This
= impl_from_IDirectSound(iface
);
962 return DS8_GetCaps(&This
->IDirectSound8_iface
, caps
);
964 static HRESULT WINAPI
DS_DuplicateSoundBuffer(IDirectSound
*iface
, IDirectSoundBuffer
*in
, IDirectSoundBuffer
**out
)
966 DS8Impl
*This
= impl_from_IDirectSound(iface
);
967 return DS8_DuplicateSoundBuffer(&This
->IDirectSound8_iface
, in
, out
);
970 static HRESULT WINAPI
DS_SetCooperativeLevel(IDirectSound
*iface
, HWND hwnd
, DWORD level
)
972 DS8Impl
*This
= impl_from_IDirectSound(iface
);
973 return DS8_SetCooperativeLevel(&This
->IDirectSound8_iface
, hwnd
, level
);
976 static HRESULT WINAPI
DS_Compact(IDirectSound
*iface
)
978 DS8Impl
*This
= impl_from_IDirectSound(iface
);
979 return DS8_Compact(&This
->IDirectSound8_iface
);
982 static HRESULT WINAPI
DS_GetSpeakerConfig(IDirectSound
*iface
, DWORD
*config
)
984 DS8Impl
*This
= impl_from_IDirectSound(iface
);
985 return DS8_GetSpeakerConfig(&This
->IDirectSound8_iface
, config
);
988 static HRESULT WINAPI
DS_SetSpeakerConfig(IDirectSound
*iface
, DWORD config
)
990 DS8Impl
*This
= impl_from_IDirectSound(iface
);
991 return DS8_SetSpeakerConfig(&This
->IDirectSound8_iface
, config
);
994 static HRESULT WINAPI
DS_Initialize(IDirectSound
*iface
, const GUID
*devguid
)
996 DS8Impl
*This
= impl_from_IDirectSound(iface
);
997 return DS8_Initialize(&This
->IDirectSound8_iface
, devguid
);
1000 static const IDirectSoundVtbl DS_Vtbl
= {
1004 DS_CreateSoundBuffer
,
1006 DS_DuplicateSoundBuffer
,
1007 DS_SetCooperativeLevel
,
1009 DS_GetSpeakerConfig
,
1010 DS_SetSpeakerConfig
,