oleaut32: Remove unnecessary consts.
[wine.git] / dlls / dsound / dsound.c
bloba8b20b1dd1512d181f27585b623384ede17cdab8
1 /* DirectSound
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
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <math.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winuser.h"
33 #include "winternl.h"
34 #include "mmddk.h"
35 #include "wingdi.h"
36 #include "mmreg.h"
37 #include "ks.h"
38 #include "ksmedia.h"
39 #include "wine/debug.h"
40 #include "dsound.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;
51 BOOL has_ds8;
52 } IDirectSoundImpl;
54 static const char * dumpCooperativeLevel(DWORD level)
56 #define LE(x) case x: return #x
57 switch (level) {
58 LE(DSSCL_NORMAL);
59 LE(DSSCL_PRIORITY);
60 LE(DSSCL_EXCLUSIVE);
61 LE(DSSCL_WRITEPRIMARY);
63 #undef LE
64 return wine_dbg_sprintf("Unknown(%08x)", level);
67 static void _dump_DSCAPS(DWORD xmask) {
68 struct {
69 DWORD mask;
70 const char *name;
71 } flags[] = {
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)
78 FE(DSCAPS_EMULDRIVER)
79 FE(DSCAPS_CERTIFIED)
80 FE(DSCAPS_SECONDARYMONO)
81 FE(DSCAPS_SECONDARYSTEREO)
82 FE(DSCAPS_SECONDARY8BIT)
83 FE(DSCAPS_SECONDARY16BIT)
84 #undef FE
86 unsigned int i;
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) {
94 struct {
95 DWORD mask;
96 const char *name;
97 } flags[] = {
98 #define FE(x) { x, #x },
99 FE(DSBCAPS_PRIMARYBUFFER)
100 FE(DSBCAPS_STATIC)
101 FE(DSBCAPS_LOCHARDWARE)
102 FE(DSBCAPS_LOCSOFTWARE)
103 FE(DSBCAPS_CTRL3D)
104 FE(DSBCAPS_CTRLFREQUENCY)
105 FE(DSBCAPS_CTRLPAN)
106 FE(DSBCAPS_CTRLVOLUME)
107 FE(DSBCAPS_CTRLPOSITIONNOTIFY)
108 FE(DSBCAPS_STICKYFOCUS)
109 FE(DSBCAPS_GLOBALFOCUS)
110 FE(DSBCAPS_GETCURRENTPOSITION2)
111 FE(DSBCAPS_MUTE3DATMAXDISTANCE)
112 #undef FE
114 unsigned int i;
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 /*******************************************************************************
122 * DirectSoundDevice
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;
136 device->ref = 1;
137 device->priolevel = DSSCL_NORMAL;
138 device->stopped = 1;
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));
184 *ppDevice = device;
186 return DS_OK;
189 static ULONG DirectSoundDevice_AddRef(DirectSoundDevice * device)
191 ULONG ref = InterlockedIncrement(&(device->ref));
192 TRACE("(%p) ref was %d\n", device, ref - 1);
193 return ref;
196 static ULONG DirectSoundDevice_Release(DirectSoundDevice * device)
198 HRESULT hr;
199 ULONG ref = InterlockedDecrement(&(device->ref));
200 TRACE("(%p) ref was %u\n", device, ref + 1);
201 if (!ref) {
202 int i;
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);
224 if (hr != DS_OK)
225 WARN("DSOUND_PrimaryDestroy failed\n");
227 if(device->client) {
228 IAudioClient_Stop(device->client);
229 IAudioClient_Release(device->client);
231 if(device->render)
232 IAudioRenderClient_Release(device->render);
233 if(device->volume)
234 IAudioStreamVolume_Release(device->volume);
235 if(device->mmdevice)
236 IMMDevice_Release(device->mmdevice);
237 HeapFree(GetProcessHeap(), 0, device->tmp_buffer);
238 HeapFree(GetProcessHeap(), 0, device->cp_buffer);
239 HeapFree(GetProcessHeap(), 0, device->buffer);
240 RtlDeleteResource(&device->buffer_list_lock);
241 device->mixlock.DebugInfo->Spare[0] = 0;
242 DeleteCriticalSection(&device->mixlock);
243 HeapFree(GetProcessHeap(),0,device);
244 TRACE("(%p) released\n", device);
246 return ref;
249 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
250 DWORD depth, WORD channels)
252 WAVEFORMATEX fmt, *junk;
253 HRESULT hr;
255 fmt.wFormatTag = WAVE_FORMAT_PCM;
256 fmt.nChannels = channels;
257 fmt.nSamplesPerSec = rate;
258 fmt.wBitsPerSample = depth;
259 fmt.nBlockAlign = (channels * depth) / 8;
260 fmt.nAvgBytesPerSec = rate * fmt.nBlockAlign;
261 fmt.cbSize = 0;
263 hr = IAudioClient_IsFormatSupported(client, AUDCLNT_SHAREMODE_SHARED, &fmt, &junk);
264 if(SUCCEEDED(hr))
265 CoTaskMemFree(junk);
267 return hr == S_OK;
270 static HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGUID lpcGUID)
272 HRESULT hr = DS_OK;
273 GUID devGUID;
274 DirectSoundDevice *device;
275 IMMDevice *mmdevice;
277 TRACE("(%p,%s)\n",ppDevice,debugstr_guid(lpcGUID));
279 if (*ppDevice != NULL) {
280 WARN("already initialized\n");
281 return DSERR_ALREADYINITIALIZED;
284 /* Default device? */
285 if (!lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL))
286 lpcGUID = &DSDEVID_DefaultPlayback;
288 if(IsEqualGUID(lpcGUID, &DSDEVID_DefaultCapture) ||
289 IsEqualGUID(lpcGUID, &DSDEVID_DefaultVoiceCapture))
290 return DSERR_NODRIVER;
292 if (GetDeviceID(lpcGUID, &devGUID) != DS_OK) {
293 WARN("invalid parameter: lpcGUID\n");
294 return DSERR_INVALIDPARAM;
297 hr = get_mmdevice(eRender, &devGUID, &mmdevice);
298 if(FAILED(hr))
299 return hr;
301 EnterCriticalSection(&DSOUND_renderers_lock);
303 LIST_FOR_EACH_ENTRY(device, &DSOUND_renderers, DirectSoundDevice, entry){
304 if(IsEqualGUID(&device->guid, &devGUID)){
305 IMMDevice_Release(mmdevice);
306 DirectSoundDevice_AddRef(device);
307 *ppDevice = device;
308 LeaveCriticalSection(&DSOUND_renderers_lock);
309 return DS_OK;
313 hr = DirectSoundDevice_Create(&device);
314 if(FAILED(hr)){
315 WARN("DirectSoundDevice_Create failed\n");
316 IMMDevice_Release(mmdevice);
317 LeaveCriticalSection(&DSOUND_renderers_lock);
318 return hr;
321 device->mmdevice = mmdevice;
322 device->guid = devGUID;
323 device->sleepev = CreateEventW(0, 0, 0, 0);
324 device->buflen = ds_hel_buflen;
326 hr = DSOUND_ReopenDevice(device, FALSE);
327 if (FAILED(hr))
329 HeapFree(GetProcessHeap(), 0, device);
330 LeaveCriticalSection(&DSOUND_renderers_lock);
331 IMMDevice_Release(mmdevice);
332 WARN("DSOUND_ReopenDevice failed: %08x\n", hr);
333 return hr;
336 ZeroMemory(&device->drvcaps, sizeof(device->drvcaps));
338 if(DSOUND_check_supported(device->client, 11025, 8, 1) ||
339 DSOUND_check_supported(device->client, 22050, 8, 1) ||
340 DSOUND_check_supported(device->client, 44100, 8, 1) ||
341 DSOUND_check_supported(device->client, 48000, 8, 1) ||
342 DSOUND_check_supported(device->client, 96000, 8, 1))
343 device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARYMONO;
345 if(DSOUND_check_supported(device->client, 11025, 16, 1) ||
346 DSOUND_check_supported(device->client, 22050, 16, 1) ||
347 DSOUND_check_supported(device->client, 44100, 16, 1) ||
348 DSOUND_check_supported(device->client, 48000, 16, 1) ||
349 DSOUND_check_supported(device->client, 96000, 16, 1))
350 device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT | DSCAPS_PRIMARYMONO;
352 if(DSOUND_check_supported(device->client, 11025, 8, 2) ||
353 DSOUND_check_supported(device->client, 22050, 8, 2) ||
354 DSOUND_check_supported(device->client, 44100, 8, 2) ||
355 DSOUND_check_supported(device->client, 48000, 8, 2) ||
356 DSOUND_check_supported(device->client, 96000, 8, 2))
357 device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARYSTEREO;
359 if(DSOUND_check_supported(device->client, 11025, 16, 2) ||
360 DSOUND_check_supported(device->client, 22050, 16, 2) ||
361 DSOUND_check_supported(device->client, 44100, 16, 2) ||
362 DSOUND_check_supported(device->client, 48000, 16, 2) ||
363 DSOUND_check_supported(device->client, 96000, 16, 2))
364 device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT | DSCAPS_PRIMARYSTEREO;
366 /* the dsound mixer supports all of the following */
367 device->drvcaps.dwFlags |= DSCAPS_SECONDARY8BIT | DSCAPS_SECONDARY16BIT;
368 device->drvcaps.dwFlags |= DSCAPS_SECONDARYMONO | DSCAPS_SECONDARYSTEREO;
369 device->drvcaps.dwFlags |= DSCAPS_CONTINUOUSRATE;
371 /* pretend that the driver is certified */
372 device->drvcaps.dwFlags |= DSCAPS_CERTIFIED;
374 device->drvcaps.dwPrimaryBuffers = 1;
375 device->drvcaps.dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
376 device->drvcaps.dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
377 device->drvcaps.dwMaxHwMixingAllBuffers = 16;
378 device->drvcaps.dwMaxHwMixingStaticBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
379 device->drvcaps.dwMaxHwMixingStreamingBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
380 device->drvcaps.dwFreeHwMixingAllBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
381 device->drvcaps.dwFreeHwMixingStaticBuffers = device->drvcaps.dwMaxHwMixingStaticBuffers;
382 device->drvcaps.dwFreeHwMixingStreamingBuffers = device->drvcaps.dwMaxHwMixingStreamingBuffers;
384 ZeroMemory(&device->volpan, sizeof(device->volpan));
386 device->thread_finished = CreateEventW(0, 0, 0, 0);
387 device->thread = CreateThread(0, 0, DSOUND_mixthread, device, 0, 0);
388 SetThreadPriority(device->thread, THREAD_PRIORITY_TIME_CRITICAL);
390 *ppDevice = device;
391 list_add_tail(&DSOUND_renderers, &device->entry);
393 LeaveCriticalSection(&DSOUND_renderers_lock);
395 return hr;
398 static HRESULT DirectSoundDevice_CreateSoundBuffer(
399 DirectSoundDevice * device,
400 LPCDSBUFFERDESC dsbd,
401 LPLPDIRECTSOUNDBUFFER ppdsb,
402 LPUNKNOWN lpunk,
403 BOOL from8)
405 HRESULT hres = DS_OK;
406 TRACE("(%p,%p,%p,%p)\n",device,dsbd,ppdsb,lpunk);
408 if (device == NULL) {
409 WARN("not initialized\n");
410 return DSERR_UNINITIALIZED;
413 if (dsbd == NULL) {
414 WARN("invalid parameter: dsbd == NULL\n");
415 return DSERR_INVALIDPARAM;
418 if (dsbd->dwSize != sizeof(DSBUFFERDESC) &&
419 dsbd->dwSize != sizeof(DSBUFFERDESC1)) {
420 WARN("invalid parameter: dsbd\n");
421 return DSERR_INVALIDPARAM;
424 if (ppdsb == NULL) {
425 WARN("invalid parameter: ppdsb == NULL\n");
426 return DSERR_INVALIDPARAM;
428 *ppdsb = NULL;
430 if (TRACE_ON(dsound)) {
431 TRACE("(structsize=%d)\n",dsbd->dwSize);
432 TRACE("(flags=0x%08x:\n",dsbd->dwFlags);
433 _dump_DSBCAPS(dsbd->dwFlags);
434 TRACE(")\n");
435 TRACE("(bufferbytes=%d)\n",dsbd->dwBufferBytes);
436 TRACE("(lpwfxFormat=%p)\n",dsbd->lpwfxFormat);
439 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) &&
440 dsbd->dwFlags & DSBCAPS_LOCHARDWARE &&
441 device->drvcaps.dwFreeHwMixingAllBuffers == 0)
443 WARN("ran out of emulated hardware buffers\n");
444 return DSERR_ALLOCATED;
447 if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
448 if (dsbd->lpwfxFormat != NULL) {
449 WARN("invalid parameter: dsbd->lpwfxFormat must be NULL for "
450 "primary buffer\n");
451 return DSERR_INVALIDPARAM;
454 if (device->primary) {
455 WARN("Primary Buffer already created\n");
456 IDirectSoundBuffer8_AddRef(&device->primary->IDirectSoundBuffer8_iface);
457 *ppdsb = (IDirectSoundBuffer *)&device->primary->IDirectSoundBuffer8_iface;
458 } else {
459 hres = primarybuffer_create(device, &device->primary, dsbd);
460 if (device->primary) {
461 *ppdsb = (IDirectSoundBuffer*)&device->primary->IDirectSoundBuffer8_iface;
462 device->primary->dsbd.dwFlags &= ~(DSBCAPS_LOCHARDWARE | DSBCAPS_LOCSOFTWARE);
463 device->primary->dsbd.dwFlags |= DSBCAPS_LOCSOFTWARE;
464 } else
465 WARN("primarybuffer_create() failed\n");
467 } else {
468 if (dsbd->lpwfxFormat == NULL) {
469 WARN("invalid parameter: dsbd->lpwfxFormat can't be NULL for "
470 "secondary buffer\n");
471 return DSERR_INVALIDPARAM;
474 if(dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_PCM &&
475 dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_IEEE_FLOAT &&
476 dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_EXTENSIBLE) {
477 WARN("We can't mix this format: 0x%x\n", dsbd->lpwfxFormat->wFormatTag);
478 return E_NOTIMPL;
481 if(dsbd->lpwfxFormat->wBitsPerSample < 8 || dsbd->lpwfxFormat->wBitsPerSample % 8 != 0 ||
482 dsbd->lpwfxFormat->nChannels == 0 || dsbd->lpwfxFormat->nSamplesPerSec == 0 ||
483 dsbd->lpwfxFormat->nAvgBytesPerSec == 0 ||
484 dsbd->lpwfxFormat->nBlockAlign != dsbd->lpwfxFormat->nChannels * dsbd->lpwfxFormat->wBitsPerSample / 8) {
485 WARN("Format inconsistency\n");
486 return DSERR_INVALIDPARAM;
489 if (dsbd->lpwfxFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
491 WAVEFORMATEXTENSIBLE *pwfxe = (WAVEFORMATEXTENSIBLE*)dsbd->lpwfxFormat;
493 /* check if cbSize is at least 22 bytes */
494 if (pwfxe->Format.cbSize < (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)))
496 WARN("Too small a cbSize %u\n", pwfxe->Format.cbSize);
497 return DSERR_INVALIDPARAM;
500 /* cbSize should be 22 bytes, with one possible exception */
501 if (pwfxe->Format.cbSize > (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)) &&
502 !((IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM) || IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) &&
503 pwfxe->Format.cbSize == sizeof(WAVEFORMATEXTENSIBLE)))
505 WARN("Too big a cbSize %u\n", pwfxe->Format.cbSize);
506 return DSERR_CONTROLUNAVAIL;
509 if ((!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) && (!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)))
511 if (!IsEqualGUID(&pwfxe->SubFormat, &GUID_NULL))
512 FIXME("SubFormat %s not supported right now.\n", debugstr_guid(&pwfxe->SubFormat));
513 return DSERR_INVALIDPARAM;
515 if (pwfxe->Samples.wValidBitsPerSample > dsbd->lpwfxFormat->wBitsPerSample)
517 WARN("Samples.wValidBitsPerSample(%d) > Format.wBitsPerSample (%d)\n", pwfxe->Samples.wValidBitsPerSample, pwfxe->Format.wBitsPerSample);
518 return DSERR_INVALIDPARAM;
520 if (pwfxe->Samples.wValidBitsPerSample && pwfxe->Samples.wValidBitsPerSample < dsbd->lpwfxFormat->wBitsPerSample)
522 WARN("Non-packed formats may not function : %d/%d\n", pwfxe->Samples.wValidBitsPerSample, dsbd->lpwfxFormat->wBitsPerSample);
526 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
527 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
528 dsbd->lpwfxFormat->wFormatTag, dsbd->lpwfxFormat->nChannels,
529 dsbd->lpwfxFormat->nSamplesPerSec,
530 dsbd->lpwfxFormat->nAvgBytesPerSec,
531 dsbd->lpwfxFormat->nBlockAlign,
532 dsbd->lpwfxFormat->wBitsPerSample, dsbd->lpwfxFormat->cbSize);
534 if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->lpwfxFormat->nChannels != 1)) {
535 WARN("invalid parameter: 3D buffer format must be mono\n");
536 return DSERR_INVALIDPARAM;
539 if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->dwFlags & DSBCAPS_CTRLPAN)) {
540 WARN("invalid parameter: DSBCAPS_CTRL3D and DSBCAPS_CTRLPAN cannot be used together\n");
541 return DSERR_INVALIDPARAM;
544 hres = secondarybuffer_create(device, dsbd, ppdsb);
545 if (SUCCEEDED(hres)) {
546 if (dsbd->dwFlags & DSBCAPS_LOCHARDWARE)
547 device->drvcaps.dwFreeHwMixingAllBuffers--;
548 } else
549 WARN("IDirectSoundBufferImpl_Create failed\n");
552 return hres;
555 static HRESULT DirectSoundDevice_DuplicateSoundBuffer(
556 DirectSoundDevice * device,
557 LPDIRECTSOUNDBUFFER psb,
558 LPLPDIRECTSOUNDBUFFER ppdsb)
560 HRESULT hres = DS_OK;
561 IDirectSoundBufferImpl* dsb;
562 TRACE("(%p,%p,%p)\n",device,psb,ppdsb);
564 if (device == NULL) {
565 WARN("not initialized\n");
566 return DSERR_UNINITIALIZED;
569 if (psb == NULL) {
570 WARN("invalid parameter: psb == NULL\n");
571 return DSERR_INVALIDPARAM;
574 if (ppdsb == NULL) {
575 WARN("invalid parameter: ppdsb == NULL\n");
576 return DSERR_INVALIDPARAM;
579 /* make sure we have a secondary buffer */
580 if (psb == (IDirectSoundBuffer *)&device->primary->IDirectSoundBuffer8_iface) {
581 WARN("trying to duplicate primary buffer\n");
582 *ppdsb = NULL;
583 return DSERR_INVALIDCALL;
586 /* duplicate the actual buffer implementation */
587 hres = IDirectSoundBufferImpl_Duplicate(device, &dsb, (IDirectSoundBufferImpl*)psb);
588 if (hres == DS_OK)
589 *ppdsb = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface;
590 else
591 WARN("IDirectSoundBufferImpl_Duplicate failed\n");
593 return hres;
597 * Add secondary buffer to buffer list.
598 * Gets exclusive access to buffer for writing.
600 HRESULT DirectSoundDevice_AddBuffer(
601 DirectSoundDevice * device,
602 IDirectSoundBufferImpl * pDSB)
604 IDirectSoundBufferImpl **newbuffers;
605 HRESULT hr = DS_OK;
607 TRACE("(%p, %p)\n", device, pDSB);
609 RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
611 if (device->buffers)
612 newbuffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
613 else
614 newbuffers = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
616 if (newbuffers) {
617 device->buffers = newbuffers;
618 device->buffers[device->nrofbuffers] = pDSB;
619 device->nrofbuffers++;
620 TRACE("buffer count is now %d\n", device->nrofbuffers);
621 } else {
622 ERR("out of memory for buffer list! Current buffer count is %d\n", device->nrofbuffers);
623 hr = DSERR_OUTOFMEMORY;
626 RtlReleaseResource(&(device->buffer_list_lock));
628 return hr;
632 * Remove secondary buffer from buffer list.
633 * Gets exclusive access to buffer for writing.
635 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBufferImpl * pDSB)
637 int i;
639 TRACE("(%p, %p)\n", device, pDSB);
641 RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
643 if (device->nrofbuffers == 1) {
644 assert(device->buffers[0] == pDSB);
645 HeapFree(GetProcessHeap(), 0, device->buffers);
646 device->buffers = NULL;
647 } else {
648 for (i = 0; i < device->nrofbuffers; i++) {
649 if (device->buffers[i] == pDSB) {
650 /* Put the last buffer of the list in the (now empty) position */
651 device->buffers[i] = device->buffers[device->nrofbuffers - 1];
652 break;
656 device->nrofbuffers--;
657 TRACE("buffer count is now %d\n", device->nrofbuffers);
659 RtlReleaseResource(&(device->buffer_list_lock));
662 /*******************************************************************************
663 * IUnknown Implementation for DirectSound
666 static void directsound_destroy(IDirectSoundImpl *This)
668 if (This->device)
669 DirectSoundDevice_Release(This->device);
670 HeapFree(GetProcessHeap(),0,This);
671 TRACE("(%p) released\n", This);
674 static inline IDirectSoundImpl *impl_from_IUnknown(IUnknown *iface)
676 return CONTAINING_RECORD(iface, IDirectSoundImpl, IUnknown_inner);
679 static HRESULT WINAPI IUnknownImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
681 IDirectSoundImpl *This = impl_from_IUnknown(iface);
683 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
685 if (!ppv) {
686 WARN("invalid parameter\n");
687 return E_INVALIDARG;
689 *ppv = NULL;
691 if (IsEqualIID(riid, &IID_IUnknown))
692 *ppv = &This->IUnknown_inner;
693 else if (IsEqualIID(riid, &IID_IDirectSound) ||
694 (IsEqualIID(riid, &IID_IDirectSound8) && This->has_ds8))
695 *ppv = &This->IDirectSound8_iface;
696 else {
697 WARN("unknown IID %s\n", debugstr_guid(riid));
698 return E_NOINTERFACE;
701 IUnknown_AddRef((IUnknown*)*ppv);
702 return S_OK;
705 static ULONG WINAPI IUnknownImpl_AddRef(IUnknown *iface)
707 IDirectSoundImpl *This = impl_from_IUnknown(iface);
708 ULONG ref = InterlockedIncrement(&This->ref);
710 TRACE("(%p) ref=%d\n", This, ref);
712 if(ref == 1)
713 InterlockedIncrement(&This->numIfaces);
715 return ref;
718 static ULONG WINAPI IUnknownImpl_Release(IUnknown *iface)
720 IDirectSoundImpl *This = impl_from_IUnknown(iface);
721 ULONG ref = InterlockedDecrement(&This->ref);
723 TRACE("(%p) ref=%d\n", This, ref);
725 if (!ref && !InterlockedDecrement(&This->numIfaces))
726 directsound_destroy(This);
728 return ref;
731 static const IUnknownVtbl unk_vtbl =
733 IUnknownImpl_QueryInterface,
734 IUnknownImpl_AddRef,
735 IUnknownImpl_Release
738 /*******************************************************************************
739 * IDirectSound and IDirectSound8 Implementation
741 static inline IDirectSoundImpl *impl_from_IDirectSound8(IDirectSound8 *iface)
743 return CONTAINING_RECORD(iface, IDirectSoundImpl, IDirectSound8_iface);
746 static HRESULT WINAPI IDirectSound8Impl_QueryInterface(IDirectSound8 *iface, REFIID riid,
747 void **ppv)
749 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
750 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
751 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
754 static ULONG WINAPI IDirectSound8Impl_AddRef(IDirectSound8 *iface)
756 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
757 ULONG ref = InterlockedIncrement(&This->refds);
759 TRACE("(%p) refds=%d\n", This, ref);
761 if(ref == 1)
762 InterlockedIncrement(&This->numIfaces);
764 return ref;
767 static ULONG WINAPI IDirectSound8Impl_Release(IDirectSound8 *iface)
769 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
770 ULONG ref = InterlockedDecrement(&(This->refds));
772 TRACE("(%p) refds=%d\n", This, ref);
774 if (!ref && !InterlockedDecrement(&This->numIfaces))
775 directsound_destroy(This);
777 return ref;
780 static HRESULT WINAPI IDirectSound8Impl_CreateSoundBuffer(IDirectSound8 *iface,
781 const DSBUFFERDESC *dsbd, IDirectSoundBuffer **ppdsb, IUnknown *lpunk)
783 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
784 TRACE("(%p,%p,%p,%p)\n", This, dsbd, ppdsb, lpunk);
785 return DirectSoundDevice_CreateSoundBuffer(This->device, dsbd, ppdsb, lpunk, This->has_ds8);
788 static HRESULT WINAPI IDirectSound8Impl_GetCaps(IDirectSound8 *iface, DSCAPS *dscaps)
790 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
792 TRACE("(%p, %p)\n", This, dscaps);
794 if (!This->device) {
795 WARN("not initialized\n");
796 return DSERR_UNINITIALIZED;
798 if (!dscaps) {
799 WARN("invalid parameter: dscaps = NULL\n");
800 return DSERR_INVALIDPARAM;
802 if (dscaps->dwSize < sizeof(*dscaps)) {
803 WARN("invalid parameter: dscaps->dwSize = %d\n", dscaps->dwSize);
804 return DSERR_INVALIDPARAM;
807 dscaps->dwFlags = This->device->drvcaps.dwFlags;
808 dscaps->dwMinSecondarySampleRate = This->device->drvcaps.dwMinSecondarySampleRate;
809 dscaps->dwMaxSecondarySampleRate = This->device->drvcaps.dwMaxSecondarySampleRate;
810 dscaps->dwPrimaryBuffers = This->device->drvcaps.dwPrimaryBuffers;
811 dscaps->dwMaxHwMixingAllBuffers = This->device->drvcaps.dwMaxHwMixingAllBuffers;
812 dscaps->dwMaxHwMixingStaticBuffers = This->device->drvcaps.dwMaxHwMixingStaticBuffers;
813 dscaps->dwMaxHwMixingStreamingBuffers = This->device->drvcaps.dwMaxHwMixingStreamingBuffers;
814 dscaps->dwFreeHwMixingAllBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
815 dscaps->dwFreeHwMixingStaticBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
816 dscaps->dwFreeHwMixingStreamingBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
818 dscaps->dwMaxHw3DAllBuffers = This->device->drvcaps.dwMaxHw3DAllBuffers;
819 dscaps->dwMaxHw3DStaticBuffers = This->device->drvcaps.dwMaxHw3DStaticBuffers;
820 dscaps->dwMaxHw3DStreamingBuffers = This->device->drvcaps.dwMaxHw3DStreamingBuffers;
821 dscaps->dwFreeHw3DAllBuffers = This->device->drvcaps.dwFreeHw3DAllBuffers;
822 dscaps->dwFreeHw3DStaticBuffers = This->device->drvcaps.dwFreeHw3DStaticBuffers;
823 dscaps->dwFreeHw3DStreamingBuffers = This->device->drvcaps.dwFreeHw3DStreamingBuffers;
824 dscaps->dwTotalHwMemBytes = This->device->drvcaps.dwTotalHwMemBytes;
825 dscaps->dwFreeHwMemBytes = This->device->drvcaps.dwFreeHwMemBytes;
826 dscaps->dwMaxContigFreeHwMemBytes = This->device->drvcaps.dwMaxContigFreeHwMemBytes;
827 dscaps->dwUnlockTransferRateHwBuffers = This->device->drvcaps.dwUnlockTransferRateHwBuffers;
828 dscaps->dwPlayCpuOverheadSwBuffers = This->device->drvcaps.dwPlayCpuOverheadSwBuffers;
830 if (TRACE_ON(dsound)) {
831 TRACE("(flags=0x%08x:\n", dscaps->dwFlags);
832 _dump_DSCAPS(dscaps->dwFlags);
833 TRACE(")\n");
836 return DS_OK;
839 static HRESULT WINAPI IDirectSound8Impl_DuplicateSoundBuffer(IDirectSound8 *iface,
840 IDirectSoundBuffer *psb, IDirectSoundBuffer **ppdsb)
842 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
843 TRACE("(%p,%p,%p)\n", This, psb, ppdsb);
844 return DirectSoundDevice_DuplicateSoundBuffer(This->device, psb, ppdsb);
847 static HRESULT WINAPI IDirectSound8Impl_SetCooperativeLevel(IDirectSound8 *iface, HWND hwnd,
848 DWORD level)
850 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
851 DirectSoundDevice *device = This->device;
852 HRESULT hr = S_OK;
854 TRACE("(%p,%p,%s)\n", This, hwnd, dumpCooperativeLevel(level));
856 if (!device) {
857 WARN("not initialized\n");
858 return DSERR_UNINITIALIZED;
861 if (level == DSSCL_PRIORITY || level == DSSCL_EXCLUSIVE) {
862 WARN("level=%s not fully supported\n",
863 level==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
866 RtlAcquireResourceExclusive(&device->buffer_list_lock, TRUE);
867 EnterCriticalSection(&device->mixlock);
868 if ((level == DSSCL_WRITEPRIMARY) != (device->priolevel == DSSCL_WRITEPRIMARY))
869 hr = DSOUND_ReopenDevice(device, level == DSSCL_WRITEPRIMARY);
870 if (SUCCEEDED(hr))
871 device->priolevel = level;
872 LeaveCriticalSection(&device->mixlock);
873 RtlReleaseResource(&device->buffer_list_lock);
874 return hr;
877 static HRESULT WINAPI IDirectSound8Impl_Compact(IDirectSound8 *iface)
879 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
881 TRACE("(%p)\n", This);
883 if (!This->device) {
884 WARN("not initialized\n");
885 return DSERR_UNINITIALIZED;
888 if (This->device->priolevel < DSSCL_PRIORITY) {
889 WARN("incorrect priority level\n");
890 return DSERR_PRIOLEVELNEEDED;
892 return DS_OK;
895 static HRESULT WINAPI IDirectSound8Impl_GetSpeakerConfig(IDirectSound8 *iface, DWORD *config)
897 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
899 TRACE("(%p, %p)\n", This, config);
901 if (!This->device) {
902 WARN("not initialized\n");
903 return DSERR_UNINITIALIZED;
905 if (!config) {
906 WARN("invalid parameter: config == NULL\n");
907 return DSERR_INVALIDPARAM;
910 WARN("not fully functional\n");
911 *config = This->device->speaker_config;
912 return DS_OK;
915 static HRESULT WINAPI IDirectSound8Impl_SetSpeakerConfig(IDirectSound8 *iface, DWORD config)
917 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
919 TRACE("(%p,0x%08x)\n", This, config);
921 if (!This->device) {
922 WARN("not initialized\n");
923 return DSERR_UNINITIALIZED;
926 /* NOP on Vista and above */
928 return DS_OK;
931 static HRESULT WINAPI IDirectSound8Impl_Initialize(IDirectSound8 *iface, const GUID *lpcGuid)
933 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
934 TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
935 return DirectSoundDevice_Initialize(&This->device, lpcGuid);
938 static HRESULT WINAPI IDirectSound8Impl_VerifyCertification(IDirectSound8 *iface, DWORD *certified)
940 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
942 TRACE("(%p, %p)\n", This, certified);
944 if (!This->device) {
945 WARN("not initialized\n");
946 return DSERR_UNINITIALIZED;
949 if (This->device->drvcaps.dwFlags & DSCAPS_CERTIFIED)
950 *certified = DS_CERTIFIED;
951 else
952 *certified = DS_UNCERTIFIED;
954 return DS_OK;
957 static const IDirectSound8Vtbl ds8_vtbl =
959 IDirectSound8Impl_QueryInterface,
960 IDirectSound8Impl_AddRef,
961 IDirectSound8Impl_Release,
962 IDirectSound8Impl_CreateSoundBuffer,
963 IDirectSound8Impl_GetCaps,
964 IDirectSound8Impl_DuplicateSoundBuffer,
965 IDirectSound8Impl_SetCooperativeLevel,
966 IDirectSound8Impl_Compact,
967 IDirectSound8Impl_GetSpeakerConfig,
968 IDirectSound8Impl_SetSpeakerConfig,
969 IDirectSound8Impl_Initialize,
970 IDirectSound8Impl_VerifyCertification
973 HRESULT IDirectSoundImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_ds8)
975 IDirectSoundImpl *obj;
976 HRESULT hr;
978 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
980 *ppv = NULL;
981 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj));
982 if (!obj) {
983 WARN("out of memory\n");
984 return DSERR_OUTOFMEMORY;
987 setup_dsound_options();
989 obj->IUnknown_inner.lpVtbl = &unk_vtbl;
990 obj->IDirectSound8_iface.lpVtbl = &ds8_vtbl;
991 obj->ref = 1;
992 obj->refds = 0;
993 obj->numIfaces = 1;
994 obj->device = NULL;
995 obj->has_ds8 = has_ds8;
997 /* COM aggregation supported only internally */
998 if (outer_unk)
999 obj->outer_unk = outer_unk;
1000 else
1001 obj->outer_unk = &obj->IUnknown_inner;
1003 hr = IUnknown_QueryInterface(&obj->IUnknown_inner, riid, ppv);
1004 IUnknown_Release(&obj->IUnknown_inner);
1006 return hr;
1009 HRESULT DSOUND_Create(REFIID riid, void **ppv)
1011 return IDirectSoundImpl_Create(NULL, riid, ppv, FALSE);
1014 HRESULT DSOUND_Create8(REFIID riid, void **ppv)
1016 return IDirectSoundImpl_Create(NULL, riid, ppv, TRUE);
1019 /*******************************************************************************
1020 * DirectSoundCreate (DSOUND.1)
1022 * Creates and initializes a DirectSound interface.
1024 * PARAMS
1025 * lpcGUID [I] Address of the GUID that identifies the sound device.
1026 * ppDS [O] Address of a variable to receive the interface pointer.
1027 * pUnkOuter [I] Must be NULL.
1029 * RETURNS
1030 * Success: DS_OK
1031 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1032 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1034 HRESULT WINAPI DirectSoundCreate(
1035 LPCGUID lpcGUID,
1036 LPDIRECTSOUND *ppDS,
1037 IUnknown *pUnkOuter)
1039 HRESULT hr;
1040 LPDIRECTSOUND pDS;
1042 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
1044 if (ppDS == NULL) {
1045 WARN("invalid parameter: ppDS == NULL\n");
1046 return DSERR_INVALIDPARAM;
1049 if (pUnkOuter != NULL) {
1050 WARN("invalid parameter: pUnkOuter != NULL\n");
1051 *ppDS = 0;
1052 return DSERR_INVALIDPARAM;
1055 hr = DSOUND_Create(&IID_IDirectSound, (void **)&pDS);
1056 if (hr == DS_OK) {
1057 hr = IDirectSound_Initialize(pDS, lpcGUID);
1058 if (hr != DS_OK) {
1059 if (hr != DSERR_ALREADYINITIALIZED) {
1060 IDirectSound_Release(pDS);
1061 pDS = 0;
1062 } else
1063 hr = DS_OK;
1067 *ppDS = pDS;
1069 return hr;
1072 /*******************************************************************************
1073 * DirectSoundCreate8 (DSOUND.11)
1075 * Creates and initializes a DirectSound8 interface.
1077 * PARAMS
1078 * lpcGUID [I] Address of the GUID that identifies the sound device.
1079 * ppDS [O] Address of a variable to receive the interface pointer.
1080 * pUnkOuter [I] Must be NULL.
1082 * RETURNS
1083 * Success: DS_OK
1084 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1085 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1087 HRESULT WINAPI DirectSoundCreate8(
1088 LPCGUID lpcGUID,
1089 LPDIRECTSOUND8 *ppDS,
1090 IUnknown *pUnkOuter)
1092 HRESULT hr;
1093 LPDIRECTSOUND8 pDS;
1095 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
1097 if (ppDS == NULL) {
1098 WARN("invalid parameter: ppDS == NULL\n");
1099 return DSERR_INVALIDPARAM;
1102 if (pUnkOuter != NULL) {
1103 WARN("invalid parameter: pUnkOuter != NULL\n");
1104 *ppDS = 0;
1105 return DSERR_INVALIDPARAM;
1108 hr = DSOUND_Create8(&IID_IDirectSound8, (void **)&pDS);
1109 if (hr == DS_OK) {
1110 hr = IDirectSound8_Initialize(pDS, lpcGUID);
1111 if (hr != DS_OK) {
1112 if (hr != DSERR_ALREADYINITIALIZED) {
1113 IDirectSound8_Release(pDS);
1114 pDS = 0;
1115 } else
1116 hr = DS_OK;
1120 *ppDS = pDS;
1122 return hr;
1125 void DSOUND_ParseSpeakerConfig(DirectSoundDevice *device)
1127 switch (DSSPEAKER_CONFIG(device->speaker_config)) {
1128 case DSSPEAKER_MONO:
1129 device->speaker_angles[0] = M_PI/180.0f * 0.0f;
1130 device->speaker_num[0] = 0;
1131 device->num_speakers = 1;
1132 device->lfe_channel = -1;
1133 break;
1135 case DSSPEAKER_STEREO:
1136 case DSSPEAKER_HEADPHONE:
1137 device->speaker_angles[0] = M_PI/180.0f * -90.0f;
1138 device->speaker_angles[1] = M_PI/180.0f * 90.0f;
1139 device->speaker_num[0] = 0; /* Left */
1140 device->speaker_num[1] = 1; /* Right */
1141 device->num_speakers = 2;
1142 device->lfe_channel = -1;
1143 break;
1145 case DSSPEAKER_QUAD:
1146 device->speaker_angles[0] = M_PI/180.0f * -135.0f;
1147 device->speaker_angles[1] = M_PI/180.0f * -45.0f;
1148 device->speaker_angles[2] = M_PI/180.0f * 45.0f;
1149 device->speaker_angles[3] = M_PI/180.0f * 135.0f;
1150 device->speaker_num[0] = 2; /* Rear left */
1151 device->speaker_num[1] = 0; /* Front left */
1152 device->speaker_num[2] = 1; /* Front right */
1153 device->speaker_num[3] = 3; /* Rear right */
1154 device->num_speakers = 4;
1155 device->lfe_channel = -1;
1156 break;
1158 case DSSPEAKER_5POINT1_BACK:
1159 device->speaker_angles[0] = M_PI/180.0f * -135.0f;
1160 device->speaker_angles[1] = M_PI/180.0f * -45.0f;
1161 device->speaker_angles[2] = M_PI/180.0f * 0.0f;
1162 device->speaker_angles[3] = M_PI/180.0f * 45.0f;
1163 device->speaker_angles[4] = M_PI/180.0f * 135.0f;
1164 device->speaker_angles[5] = 9999.0f;
1165 device->speaker_num[0] = 4; /* Rear left */
1166 device->speaker_num[1] = 0; /* Front left */
1167 device->speaker_num[2] = 2; /* Front centre */
1168 device->speaker_num[3] = 1; /* Front right */
1169 device->speaker_num[4] = 5; /* Rear right */
1170 device->speaker_num[5] = 3; /* LFE */
1171 device->num_speakers = 6;
1172 device->lfe_channel = 3;
1173 break;
1175 case DSSPEAKER_5POINT1_SURROUND:
1176 device->speaker_angles[0] = M_PI/180.0f * -90.0f;
1177 device->speaker_angles[1] = M_PI/180.0f * -30.0f;
1178 device->speaker_angles[2] = M_PI/180.0f * 0.0f;
1179 device->speaker_angles[3] = M_PI/180.0f * 30.0f;
1180 device->speaker_angles[4] = M_PI/180.0f * 90.0f;
1181 device->speaker_angles[5] = 9999.0f;
1182 device->speaker_num[0] = 4; /* Rear left */
1183 device->speaker_num[1] = 0; /* Front left */
1184 device->speaker_num[2] = 2; /* Front centre */
1185 device->speaker_num[3] = 1; /* Front right */
1186 device->speaker_num[4] = 5; /* Rear right */
1187 device->speaker_num[5] = 3; /* LFE */
1188 device->num_speakers = 6;
1189 device->lfe_channel = 3;
1190 break;
1192 default:
1193 WARN("unknown speaker_config %u\n", device->speaker_config);