3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2002 TransGaming Technologies, Inc.
6 * Copyright 2004 Robert Reif
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
39 #include "wine/debug.h"
41 #include "dsound_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
45 typedef struct IDirectSoundImpl
{
46 IUnknown IUnknown_inner
;
47 IDirectSound8 IDirectSound8_iface
;
48 IUnknown
*outer_unk
; /* internal */
49 LONG ref
, refds
, numIfaces
;
50 DirectSoundDevice
*device
;
54 static const char * dumpCooperativeLevel(DWORD level
)
56 #define LE(x) case x: return #x
61 LE(DSSCL_WRITEPRIMARY
);
64 return wine_dbg_sprintf("Unknown(%08x)", level
);
67 static void _dump_DSCAPS(DWORD xmask
) {
72 #define FE(x) { x, #x },
73 FE(DSCAPS_PRIMARYMONO
)
74 FE(DSCAPS_PRIMARYSTEREO
)
75 FE(DSCAPS_PRIMARY8BIT
)
76 FE(DSCAPS_PRIMARY16BIT
)
77 FE(DSCAPS_CONTINUOUSRATE
)
80 FE(DSCAPS_SECONDARYMONO
)
81 FE(DSCAPS_SECONDARYSTEREO
)
82 FE(DSCAPS_SECONDARY8BIT
)
83 FE(DSCAPS_SECONDARY16BIT
)
88 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
89 if ((flags
[i
].mask
& xmask
) == flags
[i
].mask
)
90 TRACE("%s ",flags
[i
].name
);
93 static void _dump_DSBCAPS(DWORD xmask
) {
98 #define FE(x) { x, #x },
99 FE(DSBCAPS_PRIMARYBUFFER
)
101 FE(DSBCAPS_LOCHARDWARE
)
102 FE(DSBCAPS_LOCSOFTWARE
)
104 FE(DSBCAPS_CTRLFREQUENCY
)
106 FE(DSBCAPS_CTRLVOLUME
)
107 FE(DSBCAPS_CTRLPOSITIONNOTIFY
)
108 FE(DSBCAPS_STICKYFOCUS
)
109 FE(DSBCAPS_GLOBALFOCUS
)
110 FE(DSBCAPS_GETCURRENTPOSITION2
)
111 FE(DSBCAPS_MUTE3DATMAXDISTANCE
)
116 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
117 if ((flags
[i
].mask
& xmask
) == flags
[i
].mask
)
118 TRACE("%s ",flags
[i
].name
);
121 /*******************************************************************************
124 static HRESULT
DirectSoundDevice_Create(DirectSoundDevice
** ppDevice
)
126 DirectSoundDevice
* device
;
127 TRACE("(%p)\n", ppDevice
);
129 /* Allocate memory */
130 device
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(DirectSoundDevice
));
131 if (device
== NULL
) {
132 WARN("out of memory\n");
133 return DSERR_OUTOFMEMORY
;
137 device
->priolevel
= DSSCL_NORMAL
;
138 device
->state
= STATE_STOPPED
;
139 device
->speaker_config
= DSSPEAKER_COMBINED(DSSPEAKER_STEREO
, DSSPEAKER_GEOMETRY_WIDE
);
141 DSOUND_ParseSpeakerConfig(device
);
143 /* 3D listener initial parameters */
144 device
->ds3dl
.dwSize
= sizeof(DS3DLISTENER
);
145 device
->ds3dl
.vPosition
.x
= 0.0;
146 device
->ds3dl
.vPosition
.y
= 0.0;
147 device
->ds3dl
.vPosition
.z
= 0.0;
148 device
->ds3dl
.vVelocity
.x
= 0.0;
149 device
->ds3dl
.vVelocity
.y
= 0.0;
150 device
->ds3dl
.vVelocity
.z
= 0.0;
151 device
->ds3dl
.vOrientFront
.x
= 0.0;
152 device
->ds3dl
.vOrientFront
.y
= 0.0;
153 device
->ds3dl
.vOrientFront
.z
= 1.0;
154 device
->ds3dl
.vOrientTop
.x
= 0.0;
155 device
->ds3dl
.vOrientTop
.y
= 1.0;
156 device
->ds3dl
.vOrientTop
.z
= 0.0;
157 device
->ds3dl
.flDistanceFactor
= DS3D_DEFAULTDISTANCEFACTOR
;
158 device
->ds3dl
.flRolloffFactor
= DS3D_DEFAULTROLLOFFFACTOR
;
159 device
->ds3dl
.flDopplerFactor
= DS3D_DEFAULTDOPPLERFACTOR
;
161 device
->guid
= GUID_NULL
;
163 /* Set default wave format (may need it for waveOutOpen) */
164 device
->primary_pwfx
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(WAVEFORMATEXTENSIBLE
));
165 if (!device
->primary_pwfx
) {
166 WARN("out of memory\n");
167 HeapFree(GetProcessHeap(),0,device
);
168 return DSERR_OUTOFMEMORY
;
171 device
->primary_pwfx
->wFormatTag
= WAVE_FORMAT_PCM
;
172 device
->primary_pwfx
->nSamplesPerSec
= 22050;
173 device
->primary_pwfx
->wBitsPerSample
= 8;
174 device
->primary_pwfx
->nChannels
= 2;
175 device
->primary_pwfx
->nBlockAlign
= device
->primary_pwfx
->wBitsPerSample
* device
->primary_pwfx
->nChannels
/ 8;
176 device
->primary_pwfx
->nAvgBytesPerSec
= device
->primary_pwfx
->nSamplesPerSec
* device
->primary_pwfx
->nBlockAlign
;
177 device
->primary_pwfx
->cbSize
= 0;
179 InitializeCriticalSection(&(device
->mixlock
));
180 device
->mixlock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": DirectSoundDevice.mixlock");
182 RtlInitializeResource(&(device
->buffer_list_lock
));
189 static ULONG
DirectSoundDevice_AddRef(DirectSoundDevice
* device
)
191 ULONG ref
= InterlockedIncrement(&(device
->ref
));
192 TRACE("(%p) ref was %d\n", device
, ref
- 1);
196 static ULONG
DirectSoundDevice_Release(DirectSoundDevice
* device
)
199 ULONG ref
= InterlockedDecrement(&(device
->ref
));
200 TRACE("(%p) ref was %u\n", device
, ref
+ 1);
204 SetEvent(device
->sleepev
);
205 if (device
->thread
) {
206 WaitForSingleObject(device
->thread_finished
, INFINITE
);
207 CloseHandle(device
->thread
);
208 CloseHandle(device
->thread_finished
);
210 CloseHandle(device
->sleepev
);
212 EnterCriticalSection(&DSOUND_renderers_lock
);
213 list_remove(&device
->entry
);
214 LeaveCriticalSection(&DSOUND_renderers_lock
);
216 /* It is allowed to release this object even when buffers are playing */
217 if (device
->buffers
) {
218 WARN("%d secondary buffers not released\n", device
->nrofbuffers
);
219 for( i
=0;i
<device
->nrofbuffers
;i
++)
220 secondarybuffer_destroy(device
->buffers
[i
]);
223 hr
= DSOUND_PrimaryDestroy(device
);
225 WARN("DSOUND_PrimaryDestroy failed\n");
228 IAudioClient_Stop(device
->client
);
229 IAudioClient_Release(device
->client
);
232 IAudioRenderClient_Release(device
->render
);
234 IAudioStreamVolume_Release(device
->volume
);
236 HeapFree(GetProcessHeap(), 0, device
->tmp_buffer
);
237 HeapFree(GetProcessHeap(), 0, device
->buffer
);
238 RtlDeleteResource(&device
->buffer_list_lock
);
239 device
->mixlock
.DebugInfo
->Spare
[0] = 0;
240 DeleteCriticalSection(&device
->mixlock
);
241 HeapFree(GetProcessHeap(),0,device
);
242 TRACE("(%p) released\n", device
);
247 BOOL
DSOUND_check_supported(IAudioClient
*client
, DWORD rate
,
248 DWORD depth
, WORD channels
)
250 WAVEFORMATEX fmt
, *junk
;
253 fmt
.wFormatTag
= WAVE_FORMAT_PCM
;
254 fmt
.nChannels
= channels
;
255 fmt
.nSamplesPerSec
= rate
;
256 fmt
.wBitsPerSample
= depth
;
257 fmt
.nBlockAlign
= (channels
* depth
) / 8;
258 fmt
.nAvgBytesPerSec
= rate
* fmt
.nBlockAlign
;
261 hr
= IAudioClient_IsFormatSupported(client
, AUDCLNT_SHAREMODE_SHARED
, &fmt
, &junk
);
268 static HRESULT
DirectSoundDevice_Initialize(DirectSoundDevice
** ppDevice
, LPCGUID lpcGUID
)
272 DirectSoundDevice
*device
;
275 TRACE("(%p,%s)\n",ppDevice
,debugstr_guid(lpcGUID
));
277 if (*ppDevice
!= NULL
) {
278 WARN("already initialized\n");
279 return DSERR_ALREADYINITIALIZED
;
282 /* Default device? */
283 if (!lpcGUID
|| IsEqualGUID(lpcGUID
, &GUID_NULL
))
284 lpcGUID
= &DSDEVID_DefaultPlayback
;
286 if(IsEqualGUID(lpcGUID
, &DSDEVID_DefaultCapture
) ||
287 IsEqualGUID(lpcGUID
, &DSDEVID_DefaultVoiceCapture
))
288 return DSERR_NODRIVER
;
290 if (GetDeviceID(lpcGUID
, &devGUID
) != DS_OK
) {
291 WARN("invalid parameter: lpcGUID\n");
292 return DSERR_INVALIDPARAM
;
295 hr
= get_mmdevice(eRender
, &devGUID
, &mmdevice
);
299 EnterCriticalSection(&DSOUND_renderers_lock
);
301 LIST_FOR_EACH_ENTRY(device
, &DSOUND_renderers
, DirectSoundDevice
, entry
){
302 if(IsEqualGUID(&device
->guid
, &devGUID
)){
303 IMMDevice_Release(mmdevice
);
304 DirectSoundDevice_AddRef(device
);
306 LeaveCriticalSection(&DSOUND_renderers_lock
);
311 hr
= DirectSoundDevice_Create(&device
);
313 WARN("DirectSoundDevice_Create failed\n");
314 IMMDevice_Release(mmdevice
);
315 LeaveCriticalSection(&DSOUND_renderers_lock
);
319 device
->mmdevice
= mmdevice
;
320 device
->guid
= devGUID
;
321 device
->sleepev
= CreateEventW(0, 0, 0, 0);
322 device
->buflen
= ds_hel_buflen
;
324 hr
= DSOUND_ReopenDevice(device
, FALSE
);
327 HeapFree(GetProcessHeap(), 0, device
);
328 LeaveCriticalSection(&DSOUND_renderers_lock
);
329 IMMDevice_Release(mmdevice
);
330 WARN("DSOUND_ReopenDevice failed: %08x\n", hr
);
334 ZeroMemory(&device
->drvcaps
, sizeof(device
->drvcaps
));
336 if(DSOUND_check_supported(device
->client
, 11025, 8, 1) ||
337 DSOUND_check_supported(device
->client
, 22050, 8, 1) ||
338 DSOUND_check_supported(device
->client
, 44100, 8, 1) ||
339 DSOUND_check_supported(device
->client
, 48000, 8, 1) ||
340 DSOUND_check_supported(device
->client
, 96000, 8, 1))
341 device
->drvcaps
.dwFlags
|= DSCAPS_PRIMARY8BIT
| DSCAPS_PRIMARYMONO
;
343 if(DSOUND_check_supported(device
->client
, 11025, 16, 1) ||
344 DSOUND_check_supported(device
->client
, 22050, 16, 1) ||
345 DSOUND_check_supported(device
->client
, 44100, 16, 1) ||
346 DSOUND_check_supported(device
->client
, 48000, 16, 1) ||
347 DSOUND_check_supported(device
->client
, 96000, 16, 1))
348 device
->drvcaps
.dwFlags
|= DSCAPS_PRIMARY16BIT
| DSCAPS_PRIMARYMONO
;
350 if(DSOUND_check_supported(device
->client
, 11025, 8, 2) ||
351 DSOUND_check_supported(device
->client
, 22050, 8, 2) ||
352 DSOUND_check_supported(device
->client
, 44100, 8, 2) ||
353 DSOUND_check_supported(device
->client
, 48000, 8, 2) ||
354 DSOUND_check_supported(device
->client
, 96000, 8, 2))
355 device
->drvcaps
.dwFlags
|= DSCAPS_PRIMARY8BIT
| DSCAPS_PRIMARYSTEREO
;
357 if(DSOUND_check_supported(device
->client
, 11025, 16, 2) ||
358 DSOUND_check_supported(device
->client
, 22050, 16, 2) ||
359 DSOUND_check_supported(device
->client
, 44100, 16, 2) ||
360 DSOUND_check_supported(device
->client
, 48000, 16, 2) ||
361 DSOUND_check_supported(device
->client
, 96000, 16, 2))
362 device
->drvcaps
.dwFlags
|= DSCAPS_PRIMARY16BIT
| DSCAPS_PRIMARYSTEREO
;
364 /* the dsound mixer supports all of the following */
365 device
->drvcaps
.dwFlags
|= DSCAPS_SECONDARY8BIT
| DSCAPS_SECONDARY16BIT
;
366 device
->drvcaps
.dwFlags
|= DSCAPS_SECONDARYMONO
| DSCAPS_SECONDARYSTEREO
;
367 device
->drvcaps
.dwFlags
|= DSCAPS_CONTINUOUSRATE
;
369 device
->drvcaps
.dwPrimaryBuffers
= 1;
370 device
->drvcaps
.dwMinSecondarySampleRate
= DSBFREQUENCY_MIN
;
371 device
->drvcaps
.dwMaxSecondarySampleRate
= DSBFREQUENCY_MAX
;
372 device
->drvcaps
.dwMaxHwMixingAllBuffers
= 16;
373 device
->drvcaps
.dwMaxHwMixingStaticBuffers
= device
->drvcaps
.dwMaxHwMixingAllBuffers
;
374 device
->drvcaps
.dwMaxHwMixingStreamingBuffers
= device
->drvcaps
.dwMaxHwMixingAllBuffers
;
375 device
->drvcaps
.dwFreeHwMixingAllBuffers
= device
->drvcaps
.dwMaxHwMixingAllBuffers
;
376 device
->drvcaps
.dwFreeHwMixingStaticBuffers
= device
->drvcaps
.dwMaxHwMixingStaticBuffers
;
377 device
->drvcaps
.dwFreeHwMixingStreamingBuffers
= device
->drvcaps
.dwMaxHwMixingStreamingBuffers
;
379 ZeroMemory(&device
->volpan
, sizeof(device
->volpan
));
381 device
->thread_finished
= CreateEventW(0, 0, 0, 0);
382 device
->thread
= CreateThread(0, 0, DSOUND_mixthread
, device
, 0, 0);
383 SetThreadPriority(device
->thread
, THREAD_PRIORITY_TIME_CRITICAL
);
386 list_add_tail(&DSOUND_renderers
, &device
->entry
);
388 LeaveCriticalSection(&DSOUND_renderers_lock
);
393 static HRESULT
DirectSoundDevice_CreateSoundBuffer(
394 DirectSoundDevice
* device
,
395 LPCDSBUFFERDESC dsbd
,
396 LPLPDIRECTSOUNDBUFFER ppdsb
,
400 HRESULT hres
= DS_OK
;
401 TRACE("(%p,%p,%p,%p)\n",device
,dsbd
,ppdsb
,lpunk
);
403 if (device
== NULL
) {
404 WARN("not initialized\n");
405 return DSERR_UNINITIALIZED
;
409 WARN("invalid parameter: dsbd == NULL\n");
410 return DSERR_INVALIDPARAM
;
413 if (dsbd
->dwSize
!= sizeof(DSBUFFERDESC
) &&
414 dsbd
->dwSize
!= sizeof(DSBUFFERDESC1
)) {
415 WARN("invalid parameter: dsbd\n");
416 return DSERR_INVALIDPARAM
;
420 WARN("invalid parameter: ppdsb == NULL\n");
421 return DSERR_INVALIDPARAM
;
425 if (TRACE_ON(dsound
)) {
426 TRACE("(structsize=%d)\n",dsbd
->dwSize
);
427 TRACE("(flags=0x%08x:\n",dsbd
->dwFlags
);
428 _dump_DSBCAPS(dsbd
->dwFlags
);
430 TRACE("(bufferbytes=%d)\n",dsbd
->dwBufferBytes
);
431 TRACE("(lpwfxFormat=%p)\n",dsbd
->lpwfxFormat
);
434 if (!(dsbd
->dwFlags
& DSBCAPS_PRIMARYBUFFER
) &&
435 dsbd
->dwFlags
& DSBCAPS_LOCHARDWARE
&&
436 device
->drvcaps
.dwFreeHwMixingAllBuffers
== 0)
438 WARN("ran out of emulated hardware buffers\n");
439 return DSERR_ALLOCATED
;
442 if (dsbd
->dwFlags
& DSBCAPS_PRIMARYBUFFER
) {
443 if (dsbd
->lpwfxFormat
!= NULL
) {
444 WARN("invalid parameter: dsbd->lpwfxFormat must be NULL for "
446 return DSERR_INVALIDPARAM
;
449 if (device
->primary
) {
450 WARN("Primary Buffer already created\n");
451 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8
)(device
->primary
));
452 *ppdsb
= (LPDIRECTSOUNDBUFFER
)(device
->primary
);
454 hres
= primarybuffer_create(device
, &device
->primary
, dsbd
);
455 if (device
->primary
) {
456 *ppdsb
= (IDirectSoundBuffer
*)&device
->primary
->IDirectSoundBuffer8_iface
;
457 device
->primary
->dsbd
.dwFlags
&= ~(DSBCAPS_LOCHARDWARE
| DSBCAPS_LOCSOFTWARE
);
458 device
->primary
->dsbd
.dwFlags
|= DSBCAPS_LOCSOFTWARE
;
460 WARN("primarybuffer_create() failed\n");
463 if (dsbd
->lpwfxFormat
== NULL
) {
464 WARN("invalid parameter: dsbd->lpwfxFormat can't be NULL for "
465 "secondary buffer\n");
466 return DSERR_INVALIDPARAM
;
469 if(dsbd
->lpwfxFormat
->wFormatTag
!= WAVE_FORMAT_PCM
&&
470 dsbd
->lpwfxFormat
->wFormatTag
!= WAVE_FORMAT_IEEE_FLOAT
&&
471 dsbd
->lpwfxFormat
->wFormatTag
!= WAVE_FORMAT_EXTENSIBLE
) {
472 WARN("We can't mix this format: 0x%x\n", dsbd
->lpwfxFormat
->wFormatTag
);
476 if(dsbd
->lpwfxFormat
->wBitsPerSample
< 8 || dsbd
->lpwfxFormat
->wBitsPerSample
% 8 != 0 ||
477 dsbd
->lpwfxFormat
->nChannels
== 0 || dsbd
->lpwfxFormat
->nSamplesPerSec
== 0 ||
478 dsbd
->lpwfxFormat
->nAvgBytesPerSec
== 0 ||
479 dsbd
->lpwfxFormat
->nBlockAlign
!= dsbd
->lpwfxFormat
->nChannels
* dsbd
->lpwfxFormat
->wBitsPerSample
/ 8) {
480 WARN("Format inconsistency\n");
481 return DSERR_INVALIDPARAM
;
484 if (dsbd
->lpwfxFormat
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
486 WAVEFORMATEXTENSIBLE
*pwfxe
= (WAVEFORMATEXTENSIBLE
*)dsbd
->lpwfxFormat
;
488 /* check if cbSize is at least 22 bytes */
489 if (pwfxe
->Format
.cbSize
< (sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
)))
491 WARN("Too small a cbSize %u\n", pwfxe
->Format
.cbSize
);
492 return DSERR_INVALIDPARAM
;
495 /* cbSize should be 22 bytes, with one possible exception */
496 if (pwfxe
->Format
.cbSize
> (sizeof(WAVEFORMATEXTENSIBLE
) - sizeof(WAVEFORMATEX
)) &&
497 !((IsEqualGUID(&pwfxe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
) || IsEqualGUID(&pwfxe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)) &&
498 pwfxe
->Format
.cbSize
== sizeof(WAVEFORMATEXTENSIBLE
)))
500 WARN("Too big a cbSize %u\n", pwfxe
->Format
.cbSize
);
501 return DSERR_CONTROLUNAVAIL
;
504 if ((!IsEqualGUID(&pwfxe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)) && (!IsEqualGUID(&pwfxe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)))
506 if (!IsEqualGUID(&pwfxe
->SubFormat
, &GUID_NULL
))
507 FIXME("SubFormat %s not supported right now.\n", debugstr_guid(&pwfxe
->SubFormat
));
508 return DSERR_INVALIDPARAM
;
510 if (pwfxe
->Samples
.wValidBitsPerSample
> dsbd
->lpwfxFormat
->wBitsPerSample
)
512 WARN("Samples.wValidBitsPerSample(%d) > Format.wBitsPerSample (%d)\n", pwfxe
->Samples
.wValidBitsPerSample
, pwfxe
->Format
.wBitsPerSample
);
513 return DSERR_INVALIDPARAM
;
515 if (pwfxe
->Samples
.wValidBitsPerSample
&& pwfxe
->Samples
.wValidBitsPerSample
< dsbd
->lpwfxFormat
->wBitsPerSample
)
517 WARN("Non-packed formats may not function : %d/%d\n", pwfxe
->Samples
.wValidBitsPerSample
, dsbd
->lpwfxFormat
->wBitsPerSample
);
521 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
522 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
523 dsbd
->lpwfxFormat
->wFormatTag
, dsbd
->lpwfxFormat
->nChannels
,
524 dsbd
->lpwfxFormat
->nSamplesPerSec
,
525 dsbd
->lpwfxFormat
->nAvgBytesPerSec
,
526 dsbd
->lpwfxFormat
->nBlockAlign
,
527 dsbd
->lpwfxFormat
->wBitsPerSample
, dsbd
->lpwfxFormat
->cbSize
);
529 if (from8
&& (dsbd
->dwFlags
& DSBCAPS_CTRL3D
) && (dsbd
->lpwfxFormat
->nChannels
!= 1)) {
530 WARN("invalid parameter: 3D buffer format must be mono\n");
531 return DSERR_INVALIDPARAM
;
534 if (from8
&& (dsbd
->dwFlags
& DSBCAPS_CTRL3D
) && (dsbd
->dwFlags
& DSBCAPS_CTRLPAN
)) {
535 WARN("invalid parameter: DSBCAPS_CTRL3D and DSBCAPS_CTRLPAN cannot be used together\n");
536 return DSERR_INVALIDPARAM
;
539 hres
= secondarybuffer_create(device
, dsbd
, ppdsb
);
540 if (SUCCEEDED(hres
)) {
541 if (dsbd
->dwFlags
& DSBCAPS_LOCHARDWARE
)
542 device
->drvcaps
.dwFreeHwMixingAllBuffers
--;
544 WARN("IDirectSoundBufferImpl_Create failed\n");
550 static HRESULT
DirectSoundDevice_DuplicateSoundBuffer(
551 DirectSoundDevice
* device
,
552 LPDIRECTSOUNDBUFFER psb
,
553 LPLPDIRECTSOUNDBUFFER ppdsb
)
555 HRESULT hres
= DS_OK
;
556 IDirectSoundBufferImpl
* dsb
;
557 TRACE("(%p,%p,%p)\n",device
,psb
,ppdsb
);
559 if (device
== NULL
) {
560 WARN("not initialized\n");
561 return DSERR_UNINITIALIZED
;
565 WARN("invalid parameter: psb == NULL\n");
566 return DSERR_INVALIDPARAM
;
570 WARN("invalid parameter: ppdsb == NULL\n");
571 return DSERR_INVALIDPARAM
;
574 /* make sure we have a secondary buffer */
575 if (psb
== (IDirectSoundBuffer
*)&device
->primary
->IDirectSoundBuffer8_iface
) {
576 WARN("trying to duplicate primary buffer\n");
578 return DSERR_INVALIDCALL
;
581 /* duplicate the actual buffer implementation */
582 hres
= IDirectSoundBufferImpl_Duplicate(device
, &dsb
, (IDirectSoundBufferImpl
*)psb
);
584 *ppdsb
= (IDirectSoundBuffer
*)&dsb
->IDirectSoundBuffer8_iface
;
586 WARN("IDirectSoundBufferImpl_Duplicate failed\n");
592 * Add secondary buffer to buffer list.
593 * Gets exclusive access to buffer for writing.
595 HRESULT
DirectSoundDevice_AddBuffer(
596 DirectSoundDevice
* device
,
597 IDirectSoundBufferImpl
* pDSB
)
599 IDirectSoundBufferImpl
**newbuffers
;
602 TRACE("(%p, %p)\n", device
, pDSB
);
604 RtlAcquireResourceExclusive(&(device
->buffer_list_lock
), TRUE
);
607 newbuffers
= HeapReAlloc(GetProcessHeap(),0,device
->buffers
,sizeof(IDirectSoundBufferImpl
*)*(device
->nrofbuffers
+1));
609 newbuffers
= HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl
*)*(device
->nrofbuffers
+1));
612 device
->buffers
= newbuffers
;
613 device
->buffers
[device
->nrofbuffers
] = pDSB
;
614 device
->nrofbuffers
++;
615 TRACE("buffer count is now %d\n", device
->nrofbuffers
);
617 ERR("out of memory for buffer list! Current buffer count is %d\n", device
->nrofbuffers
);
618 hr
= DSERR_OUTOFMEMORY
;
621 RtlReleaseResource(&(device
->buffer_list_lock
));
627 * Remove secondary buffer from buffer list.
628 * Gets exclusive access to buffer for writing.
630 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice
* device
, IDirectSoundBufferImpl
* pDSB
)
634 TRACE("(%p, %p)\n", device
, pDSB
);
636 RtlAcquireResourceExclusive(&(device
->buffer_list_lock
), TRUE
);
638 if (device
->nrofbuffers
== 1) {
639 assert(device
->buffers
[0] == pDSB
);
640 HeapFree(GetProcessHeap(), 0, device
->buffers
);
641 device
->buffers
= NULL
;
643 for (i
= 0; i
< device
->nrofbuffers
; i
++) {
644 if (device
->buffers
[i
] == pDSB
) {
645 /* Put the last buffer of the list in the (now empty) position */
646 device
->buffers
[i
] = device
->buffers
[device
->nrofbuffers
- 1];
651 device
->nrofbuffers
--;
652 TRACE("buffer count is now %d\n", device
->nrofbuffers
);
654 RtlReleaseResource(&(device
->buffer_list_lock
));
657 /*******************************************************************************
658 * IUnknown Implementation for DirectSound
661 static void directsound_destroy(IDirectSoundImpl
*This
)
664 DirectSoundDevice_Release(This
->device
);
665 HeapFree(GetProcessHeap(),0,This
);
666 TRACE("(%p) released\n", This
);
669 static inline IDirectSoundImpl
*impl_from_IUnknown(IUnknown
*iface
)
671 return CONTAINING_RECORD(iface
, IDirectSoundImpl
, IUnknown_inner
);
674 static HRESULT WINAPI
IUnknownImpl_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
676 IDirectSoundImpl
*This
= impl_from_IUnknown(iface
);
678 TRACE("(%p,%s,%p)\n", This
, debugstr_guid(riid
), ppv
);
681 WARN("invalid parameter\n");
686 if (IsEqualIID(riid
, &IID_IUnknown
))
687 *ppv
= &This
->IUnknown_inner
;
688 else if (IsEqualIID(riid
, &IID_IDirectSound
) ||
689 (IsEqualIID(riid
, &IID_IDirectSound8
) && This
->has_ds8
))
690 *ppv
= &This
->IDirectSound8_iface
;
692 WARN("unknown IID %s\n", debugstr_guid(riid
));
693 return E_NOINTERFACE
;
696 IUnknown_AddRef((IUnknown
*)*ppv
);
700 static ULONG WINAPI
IUnknownImpl_AddRef(IUnknown
*iface
)
702 IDirectSoundImpl
*This
= impl_from_IUnknown(iface
);
703 ULONG ref
= InterlockedIncrement(&This
->ref
);
705 TRACE("(%p) ref=%d\n", This
, ref
);
708 InterlockedIncrement(&This
->numIfaces
);
713 static ULONG WINAPI
IUnknownImpl_Release(IUnknown
*iface
)
715 IDirectSoundImpl
*This
= impl_from_IUnknown(iface
);
716 ULONG ref
= InterlockedDecrement(&This
->ref
);
718 TRACE("(%p) ref=%d\n", This
, ref
);
720 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
721 directsound_destroy(This
);
726 static const IUnknownVtbl unk_vtbl
=
728 IUnknownImpl_QueryInterface
,
733 /*******************************************************************************
734 * IDirectSound and IDirectSound8 Implementation
736 static inline IDirectSoundImpl
*impl_from_IDirectSound8(IDirectSound8
*iface
)
738 return CONTAINING_RECORD(iface
, IDirectSoundImpl
, IDirectSound8_iface
);
741 static HRESULT WINAPI
IDirectSound8Impl_QueryInterface(IDirectSound8
*iface
, REFIID riid
,
744 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
745 TRACE("(%p,%s,%p)\n", This
, debugstr_guid(riid
), ppv
);
746 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
749 static ULONG WINAPI
IDirectSound8Impl_AddRef(IDirectSound8
*iface
)
751 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
752 ULONG ref
= InterlockedIncrement(&This
->refds
);
754 TRACE("(%p) refds=%d\n", This
, ref
);
757 InterlockedIncrement(&This
->numIfaces
);
762 static ULONG WINAPI
IDirectSound8Impl_Release(IDirectSound8
*iface
)
764 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
765 ULONG ref
= InterlockedDecrement(&(This
->refds
));
767 TRACE("(%p) refds=%d\n", This
, ref
);
769 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
770 directsound_destroy(This
);
775 static HRESULT WINAPI
IDirectSound8Impl_CreateSoundBuffer(IDirectSound8
*iface
,
776 const DSBUFFERDESC
*dsbd
, IDirectSoundBuffer
**ppdsb
, IUnknown
*lpunk
)
778 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
779 TRACE("(%p,%p,%p,%p)\n", This
, dsbd
, ppdsb
, lpunk
);
780 return DirectSoundDevice_CreateSoundBuffer(This
->device
, dsbd
, ppdsb
, lpunk
, This
->has_ds8
);
783 static HRESULT WINAPI
IDirectSound8Impl_GetCaps(IDirectSound8
*iface
, DSCAPS
*dscaps
)
785 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
787 TRACE("(%p, %p)\n", This
, dscaps
);
790 WARN("not initialized\n");
791 return DSERR_UNINITIALIZED
;
794 WARN("invalid parameter: dscaps = NULL\n");
795 return DSERR_INVALIDPARAM
;
797 if (dscaps
->dwSize
< sizeof(*dscaps
)) {
798 WARN("invalid parameter: dscaps->dwSize = %d\n", dscaps
->dwSize
);
799 return DSERR_INVALIDPARAM
;
802 dscaps
->dwFlags
= This
->device
->drvcaps
.dwFlags
;
803 dscaps
->dwMinSecondarySampleRate
= This
->device
->drvcaps
.dwMinSecondarySampleRate
;
804 dscaps
->dwMaxSecondarySampleRate
= This
->device
->drvcaps
.dwMaxSecondarySampleRate
;
805 dscaps
->dwPrimaryBuffers
= This
->device
->drvcaps
.dwPrimaryBuffers
;
806 dscaps
->dwMaxHwMixingAllBuffers
= This
->device
->drvcaps
.dwMaxHwMixingAllBuffers
;
807 dscaps
->dwMaxHwMixingStaticBuffers
= This
->device
->drvcaps
.dwMaxHwMixingStaticBuffers
;
808 dscaps
->dwMaxHwMixingStreamingBuffers
= This
->device
->drvcaps
.dwMaxHwMixingStreamingBuffers
;
809 dscaps
->dwFreeHwMixingAllBuffers
= This
->device
->drvcaps
.dwFreeHwMixingAllBuffers
;
810 dscaps
->dwFreeHwMixingStaticBuffers
= This
->device
->drvcaps
.dwFreeHwMixingAllBuffers
;
811 dscaps
->dwFreeHwMixingStreamingBuffers
= This
->device
->drvcaps
.dwFreeHwMixingAllBuffers
;
813 dscaps
->dwMaxHw3DAllBuffers
= This
->device
->drvcaps
.dwMaxHw3DAllBuffers
;
814 dscaps
->dwMaxHw3DStaticBuffers
= This
->device
->drvcaps
.dwMaxHw3DStaticBuffers
;
815 dscaps
->dwMaxHw3DStreamingBuffers
= This
->device
->drvcaps
.dwMaxHw3DStreamingBuffers
;
816 dscaps
->dwFreeHw3DAllBuffers
= This
->device
->drvcaps
.dwFreeHw3DAllBuffers
;
817 dscaps
->dwFreeHw3DStaticBuffers
= This
->device
->drvcaps
.dwFreeHw3DStaticBuffers
;
818 dscaps
->dwFreeHw3DStreamingBuffers
= This
->device
->drvcaps
.dwFreeHw3DStreamingBuffers
;
819 dscaps
->dwTotalHwMemBytes
= This
->device
->drvcaps
.dwTotalHwMemBytes
;
820 dscaps
->dwFreeHwMemBytes
= This
->device
->drvcaps
.dwFreeHwMemBytes
;
821 dscaps
->dwMaxContigFreeHwMemBytes
= This
->device
->drvcaps
.dwMaxContigFreeHwMemBytes
;
822 dscaps
->dwUnlockTransferRateHwBuffers
= This
->device
->drvcaps
.dwUnlockTransferRateHwBuffers
;
823 dscaps
->dwPlayCpuOverheadSwBuffers
= This
->device
->drvcaps
.dwPlayCpuOverheadSwBuffers
;
825 if (TRACE_ON(dsound
)) {
826 TRACE("(flags=0x%08x:\n", dscaps
->dwFlags
);
827 _dump_DSCAPS(dscaps
->dwFlags
);
834 static HRESULT WINAPI
IDirectSound8Impl_DuplicateSoundBuffer(IDirectSound8
*iface
,
835 IDirectSoundBuffer
*psb
, IDirectSoundBuffer
**ppdsb
)
837 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
838 TRACE("(%p,%p,%p)\n", This
, psb
, ppdsb
);
839 return DirectSoundDevice_DuplicateSoundBuffer(This
->device
, psb
, ppdsb
);
842 static HRESULT WINAPI
IDirectSound8Impl_SetCooperativeLevel(IDirectSound8
*iface
, HWND hwnd
,
845 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
846 DirectSoundDevice
*device
= This
->device
;
849 TRACE("(%p,%p,%s)\n", This
, hwnd
, dumpCooperativeLevel(level
));
852 WARN("not initialized\n");
853 return DSERR_UNINITIALIZED
;
856 if (level
== DSSCL_PRIORITY
|| level
== DSSCL_EXCLUSIVE
) {
857 WARN("level=%s not fully supported\n",
858 level
==DSSCL_PRIORITY
? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
861 RtlAcquireResourceExclusive(&device
->buffer_list_lock
, TRUE
);
862 EnterCriticalSection(&device
->mixlock
);
863 if ((level
== DSSCL_WRITEPRIMARY
) != (device
->priolevel
== DSSCL_WRITEPRIMARY
))
864 hr
= DSOUND_ReopenDevice(device
, level
== DSSCL_WRITEPRIMARY
);
866 device
->priolevel
= level
;
867 LeaveCriticalSection(&device
->mixlock
);
868 RtlReleaseResource(&device
->buffer_list_lock
);
872 static HRESULT WINAPI
IDirectSound8Impl_Compact(IDirectSound8
*iface
)
874 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
876 TRACE("(%p)\n", This
);
879 WARN("not initialized\n");
880 return DSERR_UNINITIALIZED
;
883 if (This
->device
->priolevel
< DSSCL_PRIORITY
) {
884 WARN("incorrect priority level\n");
885 return DSERR_PRIOLEVELNEEDED
;
890 static HRESULT WINAPI
IDirectSound8Impl_GetSpeakerConfig(IDirectSound8
*iface
, DWORD
*config
)
892 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
894 TRACE("(%p, %p)\n", This
, config
);
897 WARN("not initialized\n");
898 return DSERR_UNINITIALIZED
;
901 WARN("invalid parameter: config == NULL\n");
902 return DSERR_INVALIDPARAM
;
905 WARN("not fully functional\n");
906 *config
= This
->device
->speaker_config
;
910 static HRESULT WINAPI
IDirectSound8Impl_SetSpeakerConfig(IDirectSound8
*iface
, DWORD config
)
912 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
914 TRACE("(%p,0x%08x)\n", This
, config
);
917 WARN("not initialized\n");
918 return DSERR_UNINITIALIZED
;
921 /* NOP on Vista and above */
926 static HRESULT WINAPI
IDirectSound8Impl_Initialize(IDirectSound8
*iface
, const GUID
*lpcGuid
)
928 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
929 TRACE("(%p, %s)\n", This
, debugstr_guid(lpcGuid
));
930 return DirectSoundDevice_Initialize(&This
->device
, lpcGuid
);
933 static HRESULT WINAPI
IDirectSound8Impl_VerifyCertification(IDirectSound8
*iface
, DWORD
*certified
)
935 IDirectSoundImpl
*This
= impl_from_IDirectSound8(iface
);
937 TRACE("(%p, %p)\n", This
, certified
);
940 WARN("not initialized\n");
941 return DSERR_UNINITIALIZED
;
944 if (This
->device
->drvcaps
.dwFlags
& DSCAPS_CERTIFIED
)
945 *certified
= DS_CERTIFIED
;
947 *certified
= DS_UNCERTIFIED
;
952 static const IDirectSound8Vtbl ds8_vtbl
=
954 IDirectSound8Impl_QueryInterface
,
955 IDirectSound8Impl_AddRef
,
956 IDirectSound8Impl_Release
,
957 IDirectSound8Impl_CreateSoundBuffer
,
958 IDirectSound8Impl_GetCaps
,
959 IDirectSound8Impl_DuplicateSoundBuffer
,
960 IDirectSound8Impl_SetCooperativeLevel
,
961 IDirectSound8Impl_Compact
,
962 IDirectSound8Impl_GetSpeakerConfig
,
963 IDirectSound8Impl_SetSpeakerConfig
,
964 IDirectSound8Impl_Initialize
,
965 IDirectSound8Impl_VerifyCertification
968 HRESULT
IDirectSoundImpl_Create(IUnknown
*outer_unk
, REFIID riid
, void **ppv
, BOOL has_ds8
)
970 IDirectSoundImpl
*obj
;
973 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
976 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*obj
));
978 WARN("out of memory\n");
979 return DSERR_OUTOFMEMORY
;
982 setup_dsound_options();
984 obj
->IUnknown_inner
.lpVtbl
= &unk_vtbl
;
985 obj
->IDirectSound8_iface
.lpVtbl
= &ds8_vtbl
;
990 obj
->has_ds8
= has_ds8
;
992 /* COM aggregation supported only internally */
994 obj
->outer_unk
= outer_unk
;
996 obj
->outer_unk
= &obj
->IUnknown_inner
;
998 hr
= IUnknown_QueryInterface(&obj
->IUnknown_inner
, riid
, ppv
);
999 IUnknown_Release(&obj
->IUnknown_inner
);
1004 HRESULT
DSOUND_Create(REFIID riid
, void **ppv
)
1006 return IDirectSoundImpl_Create(NULL
, riid
, ppv
, FALSE
);
1009 HRESULT
DSOUND_Create8(REFIID riid
, void **ppv
)
1011 return IDirectSoundImpl_Create(NULL
, riid
, ppv
, TRUE
);
1014 /*******************************************************************************
1015 * DirectSoundCreate (DSOUND.1)
1017 * Creates and initializes a DirectSound interface.
1020 * lpcGUID [I] Address of the GUID that identifies the sound device.
1021 * ppDS [O] Address of a variable to receive the interface pointer.
1022 * pUnkOuter [I] Must be NULL.
1026 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1027 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1029 HRESULT WINAPI
DirectSoundCreate(
1031 LPDIRECTSOUND
*ppDS
,
1032 IUnknown
*pUnkOuter
)
1037 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
1040 WARN("invalid parameter: ppDS == NULL\n");
1041 return DSERR_INVALIDPARAM
;
1044 if (pUnkOuter
!= NULL
) {
1045 WARN("invalid parameter: pUnkOuter != NULL\n");
1047 return DSERR_INVALIDPARAM
;
1050 hr
= DSOUND_Create(&IID_IDirectSound
, (void **)&pDS
);
1052 hr
= IDirectSound_Initialize(pDS
, lpcGUID
);
1054 if (hr
!= DSERR_ALREADYINITIALIZED
) {
1055 IDirectSound_Release(pDS
);
1067 /*******************************************************************************
1068 * DirectSoundCreate8 (DSOUND.11)
1070 * Creates and initializes a DirectSound8 interface.
1073 * lpcGUID [I] Address of the GUID that identifies the sound device.
1074 * ppDS [O] Address of a variable to receive the interface pointer.
1075 * pUnkOuter [I] Must be NULL.
1079 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1080 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1082 HRESULT WINAPI
DirectSoundCreate8(
1084 LPDIRECTSOUND8
*ppDS
,
1085 IUnknown
*pUnkOuter
)
1090 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID
),ppDS
,pUnkOuter
);
1093 WARN("invalid parameter: ppDS == NULL\n");
1094 return DSERR_INVALIDPARAM
;
1097 if (pUnkOuter
!= NULL
) {
1098 WARN("invalid parameter: pUnkOuter != NULL\n");
1100 return DSERR_INVALIDPARAM
;
1103 hr
= DSOUND_Create8(&IID_IDirectSound8
, (void **)&pDS
);
1105 hr
= IDirectSound8_Initialize(pDS
, lpcGUID
);
1107 if (hr
!= DSERR_ALREADYINITIALIZED
) {
1108 IDirectSound8_Release(pDS
);
1120 void DSOUND_ParseSpeakerConfig(DirectSoundDevice
*device
)
1122 switch (DSSPEAKER_CONFIG(device
->speaker_config
)) {
1123 case DSSPEAKER_MONO
:
1124 device
->speaker_angles
[0] = M_PI
/180.0f
* 0.0f
;
1125 device
->speaker_num
[0] = 0;
1126 device
->num_speakers
= 1;
1127 device
->lfe_channel
= -1;
1130 case DSSPEAKER_STEREO
:
1131 case DSSPEAKER_HEADPHONE
:
1132 device
->speaker_angles
[0] = M_PI
/180.0f
* -90.0f
;
1133 device
->speaker_angles
[1] = M_PI
/180.0f
* 90.0f
;
1134 device
->speaker_num
[0] = 0; /* Left */
1135 device
->speaker_num
[1] = 1; /* Right */
1136 device
->num_speakers
= 2;
1137 device
->lfe_channel
= -1;
1140 case DSSPEAKER_QUAD
:
1141 device
->speaker_angles
[0] = M_PI
/180.0f
* -135.0f
;
1142 device
->speaker_angles
[1] = M_PI
/180.0f
* -45.0f
;
1143 device
->speaker_angles
[2] = M_PI
/180.0f
* 45.0f
;
1144 device
->speaker_angles
[3] = M_PI
/180.0f
* 135.0f
;
1145 device
->speaker_num
[0] = 2; /* Rear left */
1146 device
->speaker_num
[1] = 0; /* Front left */
1147 device
->speaker_num
[2] = 1; /* Front right */
1148 device
->speaker_num
[3] = 3; /* Rear right */
1149 device
->num_speakers
= 4;
1150 device
->lfe_channel
= -1;
1153 case DSSPEAKER_5POINT1_BACK
:
1154 device
->speaker_angles
[0] = M_PI
/180.0f
* -135.0f
;
1155 device
->speaker_angles
[1] = M_PI
/180.0f
* -45.0f
;
1156 device
->speaker_angles
[2] = M_PI
/180.0f
* 0.0f
;
1157 device
->speaker_angles
[3] = M_PI
/180.0f
* 45.0f
;
1158 device
->speaker_angles
[4] = M_PI
/180.0f
* 135.0f
;
1159 device
->speaker_angles
[5] = 9999.0f
;
1160 device
->speaker_num
[0] = 4; /* Rear left */
1161 device
->speaker_num
[1] = 0; /* Front left */
1162 device
->speaker_num
[2] = 2; /* Front centre */
1163 device
->speaker_num
[3] = 1; /* Front right */
1164 device
->speaker_num
[4] = 5; /* Rear right */
1165 device
->speaker_num
[5] = 3; /* LFE */
1166 device
->num_speakers
= 6;
1167 device
->lfe_channel
= 3;
1170 case DSSPEAKER_5POINT1_SURROUND
:
1171 device
->speaker_angles
[0] = M_PI
/180.0f
* -90.0f
;
1172 device
->speaker_angles
[1] = M_PI
/180.0f
* -30.0f
;
1173 device
->speaker_angles
[2] = M_PI
/180.0f
* 0.0f
;
1174 device
->speaker_angles
[3] = M_PI
/180.0f
* 30.0f
;
1175 device
->speaker_angles
[4] = M_PI
/180.0f
* 90.0f
;
1176 device
->speaker_angles
[5] = 9999.0f
;
1177 device
->speaker_num
[0] = 4; /* Rear left */
1178 device
->speaker_num
[1] = 0; /* Front left */
1179 device
->speaker_num
[2] = 2; /* Front centre */
1180 device
->speaker_num
[3] = 1; /* Front right */
1181 device
->speaker_num
[4] = 5; /* Rear right */
1182 device
->speaker_num
[5] = 3; /* LFE */
1183 device
->num_speakers
= 6;
1184 device
->lfe_channel
= 3;
1188 WARN("unknown speaker_config %u\n", device
->speaker_config
);