ddraw/tests: Move the capability tests for enumerated devices.
[wine.git] / dlls / dsound / dsound.c
blobf2aea64eeeda29321981592ac6b7fcc0c34bc016
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 "mmddk.h"
34 #include "wingdi.h"
35 #include "mmreg.h"
36 #include "ks.h"
37 #include "ksmedia.h"
38 #include "wine/debug.h"
39 #include "dsound.h"
40 #include "dsound_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
44 typedef struct IDirectSoundImpl {
45 IUnknown IUnknown_inner;
46 IDirectSound8 IDirectSound8_iface;
47 IUnknown *outer_unk; /* internal */
48 LONG ref, refds, numIfaces;
49 DirectSoundDevice *device;
50 BOOL has_ds8;
51 } IDirectSoundImpl;
53 static const char * dumpCooperativeLevel(DWORD level)
55 #define LE(x) case x: return #x
56 switch (level) {
57 LE(DSSCL_NORMAL);
58 LE(DSSCL_PRIORITY);
59 LE(DSSCL_EXCLUSIVE);
60 LE(DSSCL_WRITEPRIMARY);
62 #undef LE
63 return wine_dbg_sprintf("Unknown(%08lx)", level);
66 static void _dump_DSCAPS(DWORD xmask) {
67 struct {
68 DWORD mask;
69 const char *name;
70 } flags[] = {
71 #define FE(x) { x, #x },
72 FE(DSCAPS_PRIMARYMONO)
73 FE(DSCAPS_PRIMARYSTEREO)
74 FE(DSCAPS_PRIMARY8BIT)
75 FE(DSCAPS_PRIMARY16BIT)
76 FE(DSCAPS_CONTINUOUSRATE)
77 FE(DSCAPS_EMULDRIVER)
78 FE(DSCAPS_CERTIFIED)
79 FE(DSCAPS_SECONDARYMONO)
80 FE(DSCAPS_SECONDARYSTEREO)
81 FE(DSCAPS_SECONDARY8BIT)
82 FE(DSCAPS_SECONDARY16BIT)
83 #undef FE
85 unsigned int i;
87 for (i = 0; i < ARRAY_SIZE(flags); i++)
88 if ((flags[i].mask & xmask) == flags[i].mask)
89 TRACE("%s ",flags[i].name);
92 static void _dump_DSBCAPS(DWORD xmask) {
93 struct {
94 DWORD mask;
95 const char *name;
96 } flags[] = {
97 #define FE(x) { x, #x },
98 FE(DSBCAPS_PRIMARYBUFFER)
99 FE(DSBCAPS_STATIC)
100 FE(DSBCAPS_LOCHARDWARE)
101 FE(DSBCAPS_LOCSOFTWARE)
102 FE(DSBCAPS_CTRL3D)
103 FE(DSBCAPS_CTRLFREQUENCY)
104 FE(DSBCAPS_CTRLPAN)
105 FE(DSBCAPS_CTRLVOLUME)
106 FE(DSBCAPS_CTRLPOSITIONNOTIFY)
107 FE(DSBCAPS_CTRLFX)
108 FE(DSBCAPS_STICKYFOCUS)
109 FE(DSBCAPS_GLOBALFOCUS)
110 FE(DSBCAPS_GETCURRENTPOSITION2)
111 FE(DSBCAPS_MUTE3DATMAXDISTANCE)
112 FE(DSBCAPS_LOCDEFER)
113 #undef FE
115 unsigned int i;
117 for (i = 0; i < ARRAY_SIZE(flags); i++)
118 if ((flags[i].mask & xmask) == flags[i].mask)
119 TRACE("%s ",flags[i].name);
122 /*******************************************************************************
123 * DirectSoundDevice
125 static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice)
127 DirectSoundDevice * device;
128 TRACE("(%p)\n", ppDevice);
130 /* Allocate memory */
131 device = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DirectSoundDevice));
132 if (device == NULL) {
133 WARN("out of memory\n");
134 return DSERR_OUTOFMEMORY;
137 device->ref = 1;
138 device->priolevel = DSSCL_NORMAL;
139 device->stopped = 1;
140 device->speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO, DSSPEAKER_GEOMETRY_WIDE);
142 DSOUND_ParseSpeakerConfig(device);
144 /* 3D listener initial parameters */
145 device->ds3dl.dwSize = sizeof(DS3DLISTENER);
146 device->ds3dl.vPosition.x = 0.0;
147 device->ds3dl.vPosition.y = 0.0;
148 device->ds3dl.vPosition.z = 0.0;
149 device->ds3dl.vVelocity.x = 0.0;
150 device->ds3dl.vVelocity.y = 0.0;
151 device->ds3dl.vVelocity.z = 0.0;
152 device->ds3dl.vOrientFront.x = 0.0;
153 device->ds3dl.vOrientFront.y = 0.0;
154 device->ds3dl.vOrientFront.z = 1.0;
155 device->ds3dl.vOrientTop.x = 0.0;
156 device->ds3dl.vOrientTop.y = 1.0;
157 device->ds3dl.vOrientTop.z = 0.0;
158 device->ds3dl.flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
159 device->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
160 device->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
162 device->guid = GUID_NULL;
164 /* Set default wave format (may need it for waveOutOpen) */
165 device->primary_pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEFORMATEXTENSIBLE));
166 if (!device->primary_pwfx) {
167 WARN("out of memory\n");
168 HeapFree(GetProcessHeap(),0,device);
169 return DSERR_OUTOFMEMORY;
172 device->primary_pwfx->wFormatTag = WAVE_FORMAT_PCM;
173 device->primary_pwfx->nSamplesPerSec = 22050;
174 device->primary_pwfx->wBitsPerSample = 8;
175 device->primary_pwfx->nChannels = 2;
176 device->primary_pwfx->nBlockAlign = device->primary_pwfx->wBitsPerSample * device->primary_pwfx->nChannels / 8;
177 device->primary_pwfx->nAvgBytesPerSec = device->primary_pwfx->nSamplesPerSec * device->primary_pwfx->nBlockAlign;
178 device->primary_pwfx->cbSize = 0;
180 InitializeCriticalSection(&(device->mixlock));
181 device->mixlock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DirectSoundDevice.mixlock");
183 InitializeSRWLock(&device->buffer_list_lock);
185 *ppDevice = device;
187 return DS_OK;
190 static ULONG DirectSoundDevice_AddRef(DirectSoundDevice * device)
192 ULONG ref = InterlockedIncrement(&(device->ref));
193 TRACE("(%p) ref %ld\n", device, ref);
194 return ref;
197 static ULONG DirectSoundDevice_Release(DirectSoundDevice * device)
199 HRESULT hr;
200 ULONG ref = InterlockedDecrement(&(device->ref));
201 TRACE("(%p) ref %ld\n", device, ref);
202 if (!ref) {
203 int i;
205 SetEvent(device->sleepev);
206 if (device->thread) {
207 WaitForSingleObject(device->thread, INFINITE);
208 CloseHandle(device->thread);
211 EnterCriticalSection(&DSOUND_renderers_lock);
212 list_remove(&device->entry);
213 LeaveCriticalSection(&DSOUND_renderers_lock);
215 /* It is allowed to release this object even when buffers are playing */
216 if (device->buffers) {
217 WARN("%d secondary buffers not released\n", device->nrofbuffers);
218 for( i=0;i<device->nrofbuffers;i++)
219 secondarybuffer_destroy(device->buffers[i]);
222 hr = DSOUND_PrimaryDestroy(device);
223 if (hr != DS_OK)
224 WARN("DSOUND_PrimaryDestroy failed\n");
226 if(device->client) {
227 IAudioClient_Stop(device->client);
228 IAudioClient_Release(device->client);
230 if(device->render)
231 IAudioRenderClient_Release(device->render);
232 if(device->volume)
233 IAudioStreamVolume_Release(device->volume);
234 if(device->mmdevice)
235 IMMDevice_Release(device->mmdevice);
236 CloseHandle(device->sleepev);
237 HeapFree(GetProcessHeap(), 0, device->tmp_buffer);
238 HeapFree(GetProcessHeap(), 0, device->cp_buffer);
239 HeapFree(GetProcessHeap(), 0, device->buffer);
240 device->mixlock.DebugInfo->Spare[0] = 0;
241 DeleteCriticalSection(&device->mixlock);
242 TRACE("(%p) released\n", device);
243 HeapFree(GetProcessHeap(),0,device);
245 return ref;
248 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
249 DWORD depth, WORD channels)
251 WAVEFORMATEX fmt, *junk;
252 HRESULT hr;
254 fmt.wFormatTag = WAVE_FORMAT_PCM;
255 fmt.nChannels = channels;
256 fmt.nSamplesPerSec = rate;
257 fmt.wBitsPerSample = depth;
258 fmt.nBlockAlign = (channels * depth) / 8;
259 fmt.nAvgBytesPerSec = rate * fmt.nBlockAlign;
260 fmt.cbSize = 0;
262 hr = IAudioClient_IsFormatSupported(client, AUDCLNT_SHAREMODE_SHARED, &fmt, &junk);
263 if(SUCCEEDED(hr))
264 CoTaskMemFree(junk);
266 return hr == S_OK;
269 static HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGUID lpcGUID)
271 HRESULT hr = DS_OK;
272 GUID devGUID;
273 DirectSoundDevice *device;
274 IMMDevice *mmdevice;
276 TRACE("(%p,%s)\n",ppDevice,debugstr_guid(lpcGUID));
278 if (*ppDevice != NULL) {
279 WARN("already initialized\n");
280 return DSERR_ALREADYINITIALIZED;
283 /* Default device? */
284 if (!lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL))
285 lpcGUID = &DSDEVID_DefaultPlayback;
287 if(IsEqualGUID(lpcGUID, &DSDEVID_DefaultCapture) ||
288 IsEqualGUID(lpcGUID, &DSDEVID_DefaultVoiceCapture))
289 return DSERR_NODRIVER;
291 if (GetDeviceID(lpcGUID, &devGUID) != DS_OK) {
292 WARN("invalid parameter: lpcGUID\n");
293 return DSERR_INVALIDPARAM;
296 hr = get_mmdevice(eRender, &devGUID, &mmdevice);
297 if(FAILED(hr))
298 return hr;
300 EnterCriticalSection(&DSOUND_renderers_lock);
302 LIST_FOR_EACH_ENTRY(device, &DSOUND_renderers, DirectSoundDevice, entry){
303 if(IsEqualGUID(&device->guid, &devGUID)){
304 IMMDevice_Release(mmdevice);
305 DirectSoundDevice_AddRef(device);
306 *ppDevice = device;
307 LeaveCriticalSection(&DSOUND_renderers_lock);
308 return DS_OK;
312 hr = DirectSoundDevice_Create(&device);
313 if(FAILED(hr)){
314 WARN("DirectSoundDevice_Create failed\n");
315 IMMDevice_Release(mmdevice);
316 LeaveCriticalSection(&DSOUND_renderers_lock);
317 return hr;
320 device->mmdevice = mmdevice;
321 device->guid = devGUID;
322 device->sleepev = CreateEventW(0, 0, 0, 0);
323 device->buflen = ds_hel_buflen;
325 hr = DSOUND_ReopenDevice(device, FALSE);
326 if (FAILED(hr))
328 HeapFree(GetProcessHeap(), 0, device);
329 LeaveCriticalSection(&DSOUND_renderers_lock);
330 IMMDevice_Release(mmdevice);
331 WARN("DSOUND_ReopenDevice failed: %08lx\n", hr);
332 return hr;
335 ZeroMemory(&device->drvcaps, sizeof(device->drvcaps));
337 if(DSOUND_check_supported(device->client, 11025, 8, 1) ||
338 DSOUND_check_supported(device->client, 22050, 8, 1) ||
339 DSOUND_check_supported(device->client, 44100, 8, 1) ||
340 DSOUND_check_supported(device->client, 48000, 8, 1) ||
341 DSOUND_check_supported(device->client, 96000, 8, 1))
342 device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARYMONO;
344 if(DSOUND_check_supported(device->client, 11025, 16, 1) ||
345 DSOUND_check_supported(device->client, 22050, 16, 1) ||
346 DSOUND_check_supported(device->client, 44100, 16, 1) ||
347 DSOUND_check_supported(device->client, 48000, 16, 1) ||
348 DSOUND_check_supported(device->client, 96000, 16, 1))
349 device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT | DSCAPS_PRIMARYMONO;
351 if(DSOUND_check_supported(device->client, 11025, 8, 2) ||
352 DSOUND_check_supported(device->client, 22050, 8, 2) ||
353 DSOUND_check_supported(device->client, 44100, 8, 2) ||
354 DSOUND_check_supported(device->client, 48000, 8, 2) ||
355 DSOUND_check_supported(device->client, 96000, 8, 2))
356 device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARYSTEREO;
358 if(DSOUND_check_supported(device->client, 11025, 16, 2) ||
359 DSOUND_check_supported(device->client, 22050, 16, 2) ||
360 DSOUND_check_supported(device->client, 44100, 16, 2) ||
361 DSOUND_check_supported(device->client, 48000, 16, 2) ||
362 DSOUND_check_supported(device->client, 96000, 16, 2))
363 device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT | DSCAPS_PRIMARYSTEREO;
365 /* the dsound mixer supports all of the following */
366 device->drvcaps.dwFlags |= DSCAPS_SECONDARY8BIT | DSCAPS_SECONDARY16BIT;
367 device->drvcaps.dwFlags |= DSCAPS_SECONDARYMONO | DSCAPS_SECONDARYSTEREO;
368 device->drvcaps.dwFlags |= DSCAPS_CONTINUOUSRATE;
370 /* pretend that the driver is certified */
371 device->drvcaps.dwFlags |= DSCAPS_CERTIFIED;
373 device->drvcaps.dwPrimaryBuffers = 1;
374 device->drvcaps.dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
375 device->drvcaps.dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
376 device->drvcaps.dwMaxHwMixingAllBuffers = 1;
377 device->drvcaps.dwMaxHwMixingStaticBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
378 device->drvcaps.dwMaxHwMixingStreamingBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
379 device->drvcaps.dwFreeHwMixingAllBuffers = 0;
380 device->drvcaps.dwFreeHwMixingStaticBuffers = 0;
381 device->drvcaps.dwFreeHwMixingStreamingBuffers = 0;
383 ZeroMemory(&device->volpan, sizeof(device->volpan));
385 device->thread = CreateThread(0, 0, DSOUND_mixthread, device, 0, 0);
386 SetThreadPriority(device->thread, THREAD_PRIORITY_TIME_CRITICAL);
388 *ppDevice = device;
389 list_add_tail(&DSOUND_renderers, &device->entry);
391 LeaveCriticalSection(&DSOUND_renderers_lock);
393 return hr;
396 static HRESULT DirectSoundDevice_CreateSoundBuffer(
397 DirectSoundDevice * device,
398 LPCDSBUFFERDESC dsbd,
399 LPLPDIRECTSOUNDBUFFER ppdsb,
400 LPUNKNOWN lpunk,
401 BOOL from8)
403 HRESULT hres = DS_OK;
404 TRACE("(%p,%p,%p,%p)\n",device,dsbd,ppdsb,lpunk);
406 if (device == NULL) {
407 WARN("not initialized\n");
408 return DSERR_UNINITIALIZED;
411 if (dsbd == NULL) {
412 WARN("invalid parameter: dsbd == NULL\n");
413 return DSERR_INVALIDPARAM;
416 if (dsbd->dwSize != sizeof(DSBUFFERDESC) &&
417 dsbd->dwSize != sizeof(DSBUFFERDESC1)) {
418 WARN("invalid parameter: dsbd\n");
419 return DSERR_INVALIDPARAM;
422 if (ppdsb == NULL) {
423 WARN("invalid parameter: ppdsb == NULL\n");
424 return DSERR_INVALIDPARAM;
426 *ppdsb = NULL;
428 if (TRACE_ON(dsound)) {
429 TRACE("(structsize=%ld)\n",dsbd->dwSize);
430 TRACE("(flags=0x%08lx:\n",dsbd->dwFlags);
431 _dump_DSBCAPS(dsbd->dwFlags);
432 TRACE(")\n");
433 TRACE("(bufferbytes=%ld)\n",dsbd->dwBufferBytes);
434 TRACE("(lpwfxFormat=%p)\n",dsbd->lpwfxFormat);
437 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) &&
438 dsbd->dwFlags & DSBCAPS_LOCHARDWARE)
440 WARN("unable to create hardware buffer\n");
441 return DSERR_UNSUPPORTED;
444 if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
445 if (dsbd->lpwfxFormat != NULL) {
446 WARN("invalid parameter: dsbd->lpwfxFormat must be NULL for "
447 "primary buffer\n");
448 return DSERR_INVALIDPARAM;
451 if (dsbd->dwFlags & DSBCAPS_CTRLFX)
453 WARN("Invalid parameter DSBCAPS_CTRLFX\n");
454 return DSERR_INVALIDPARAM;
457 if (device->primary) {
458 WARN("Primary Buffer already created\n");
459 IDirectSoundBuffer8_AddRef(&device->primary->IDirectSoundBuffer8_iface);
460 *ppdsb = (IDirectSoundBuffer *)&device->primary->IDirectSoundBuffer8_iface;
461 } else {
462 hres = primarybuffer_create(device, &device->primary, dsbd);
463 if (device->primary) {
464 *ppdsb = (IDirectSoundBuffer*)&device->primary->IDirectSoundBuffer8_iface;
465 device->primary->dsbd.dwFlags &= ~(DSBCAPS_LOCHARDWARE | DSBCAPS_LOCSOFTWARE);
466 device->primary->dsbd.dwFlags |= DSBCAPS_LOCSOFTWARE;
467 } else
468 WARN("primarybuffer_create() failed\n");
470 } else {
471 if (dsbd->lpwfxFormat == NULL) {
472 WARN("invalid parameter: dsbd->lpwfxFormat can't be NULL for "
473 "secondary buffer\n");
474 return DSERR_INVALIDPARAM;
477 if(dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_PCM &&
478 dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_IEEE_FLOAT &&
479 dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_EXTENSIBLE) {
480 WARN("We can't mix this format: 0x%x\n", dsbd->lpwfxFormat->wFormatTag);
481 return E_NOTIMPL;
484 if(dsbd->lpwfxFormat->wBitsPerSample < 8 || dsbd->lpwfxFormat->wBitsPerSample % 8 != 0 ||
485 dsbd->lpwfxFormat->nChannels == 0 || dsbd->lpwfxFormat->nSamplesPerSec == 0 ||
486 dsbd->lpwfxFormat->nAvgBytesPerSec == 0 ||
487 dsbd->lpwfxFormat->nBlockAlign != dsbd->lpwfxFormat->nChannels * dsbd->lpwfxFormat->wBitsPerSample / 8) {
488 WARN("Format inconsistency\n");
489 return DSERR_INVALIDPARAM;
492 if (dsbd->lpwfxFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
494 WAVEFORMATEXTENSIBLE *pwfxe = (WAVEFORMATEXTENSIBLE*)dsbd->lpwfxFormat;
496 /* check if cbSize is at least 22 bytes */
497 if (pwfxe->Format.cbSize < (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)))
499 WARN("Too small a cbSize %u\n", pwfxe->Format.cbSize);
500 return DSERR_INVALIDPARAM;
503 /* cbSize should be 22 bytes, with one possible exception */
504 if (pwfxe->Format.cbSize > (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)) &&
505 !((IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM) || IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) &&
506 pwfxe->Format.cbSize == sizeof(WAVEFORMATEXTENSIBLE)))
508 WARN("Too big a cbSize %u\n", pwfxe->Format.cbSize);
509 return DSERR_CONTROLUNAVAIL;
512 if ((!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) && (!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)))
514 if (!IsEqualGUID(&pwfxe->SubFormat, &GUID_NULL))
515 FIXME("SubFormat %s not supported right now.\n", debugstr_guid(&pwfxe->SubFormat));
516 return DSERR_INVALIDPARAM;
518 if (pwfxe->Samples.wValidBitsPerSample > dsbd->lpwfxFormat->wBitsPerSample)
520 WARN("Samples.wValidBitsPerSample(%d) > Format.wBitsPerSample (%d)\n", pwfxe->Samples.wValidBitsPerSample, pwfxe->Format.wBitsPerSample);
521 return DSERR_INVALIDPARAM;
523 if (pwfxe->Samples.wValidBitsPerSample && pwfxe->Samples.wValidBitsPerSample < dsbd->lpwfxFormat->wBitsPerSample)
525 WARN("Non-packed formats may not function : %d/%d\n", pwfxe->Samples.wValidBitsPerSample, dsbd->lpwfxFormat->wBitsPerSample);
529 TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
530 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
531 dsbd->lpwfxFormat->wFormatTag, dsbd->lpwfxFormat->nChannels,
532 dsbd->lpwfxFormat->nSamplesPerSec,
533 dsbd->lpwfxFormat->nAvgBytesPerSec,
534 dsbd->lpwfxFormat->nBlockAlign,
535 dsbd->lpwfxFormat->wBitsPerSample, dsbd->lpwfxFormat->cbSize);
537 if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->lpwfxFormat->nChannels != 1)) {
538 WARN("invalid parameter: 3D buffer format must be mono\n");
539 return DSERR_INVALIDPARAM;
542 if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->dwFlags & DSBCAPS_CTRLPAN)) {
543 WARN("invalid parameter: DSBCAPS_CTRL3D and DSBCAPS_CTRLPAN cannot be used together\n");
544 return DSERR_INVALIDPARAM;
547 hres = secondarybuffer_create(device, dsbd, ppdsb);
548 if (SUCCEEDED(hres)) {
549 if (dsbd->dwFlags & DSBCAPS_LOCHARDWARE)
550 device->drvcaps.dwFreeHwMixingAllBuffers--;
551 } else
552 WARN("IDirectSoundBufferImpl_Create failed\n");
555 return hres;
558 static HRESULT DirectSoundDevice_DuplicateSoundBuffer(
559 DirectSoundDevice * device,
560 LPDIRECTSOUNDBUFFER psb,
561 LPLPDIRECTSOUNDBUFFER ppdsb)
563 HRESULT hres = DS_OK;
564 IDirectSoundBufferImpl* dsb;
565 TRACE("(%p,%p,%p)\n",device,psb,ppdsb);
567 if (device == NULL) {
568 WARN("not initialized\n");
569 return DSERR_UNINITIALIZED;
572 if (psb == NULL) {
573 WARN("invalid parameter: psb == NULL\n");
574 return DSERR_INVALIDPARAM;
577 if (ppdsb == NULL) {
578 WARN("invalid parameter: ppdsb == NULL\n");
579 return DSERR_INVALIDPARAM;
582 /* make sure we have a secondary buffer */
583 if (psb == (IDirectSoundBuffer *)&device->primary->IDirectSoundBuffer8_iface) {
584 WARN("trying to duplicate primary buffer\n");
585 *ppdsb = NULL;
586 return DSERR_INVALIDCALL;
589 /* duplicate the actual buffer implementation */
590 hres = IDirectSoundBufferImpl_Duplicate(device, &dsb, (IDirectSoundBufferImpl*)psb);
591 if (hres == DS_OK)
592 *ppdsb = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface;
593 else
594 WARN("IDirectSoundBufferImpl_Duplicate failed\n");
596 return hres;
600 * Add secondary buffer to buffer list.
601 * Gets exclusive access to buffer for writing.
603 HRESULT DirectSoundDevice_AddBuffer(
604 DirectSoundDevice * device,
605 IDirectSoundBufferImpl * pDSB)
607 IDirectSoundBufferImpl **newbuffers;
608 HRESULT hr = DS_OK;
610 TRACE("(%p, %p)\n", device, pDSB);
612 AcquireSRWLockExclusive(&device->buffer_list_lock);
614 if (device->buffers)
615 newbuffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
616 else
617 newbuffers = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
619 if (newbuffers) {
620 device->buffers = newbuffers;
621 device->buffers[device->nrofbuffers] = pDSB;
622 device->nrofbuffers++;
623 TRACE("buffer count is now %d\n", device->nrofbuffers);
624 } else {
625 ERR("out of memory for buffer list! Current buffer count is %d\n", device->nrofbuffers);
626 hr = DSERR_OUTOFMEMORY;
629 ReleaseSRWLockExclusive(&device->buffer_list_lock);
631 return hr;
635 * Remove secondary buffer from buffer list.
636 * Gets exclusive access to buffer for writing.
638 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBufferImpl * pDSB)
640 int i;
642 TRACE("(%p, %p)\n", device, pDSB);
644 AcquireSRWLockExclusive(&device->buffer_list_lock);
646 if (device->nrofbuffers == 1) {
647 assert(device->buffers[0] == pDSB);
648 HeapFree(GetProcessHeap(), 0, device->buffers);
649 device->buffers = NULL;
650 } else {
651 for (i = 0; i < device->nrofbuffers; i++) {
652 if (device->buffers[i] == pDSB) {
653 /* Put the last buffer of the list in the (now empty) position */
654 device->buffers[i] = device->buffers[device->nrofbuffers - 1];
655 break;
659 device->nrofbuffers--;
660 TRACE("buffer count is now %d\n", device->nrofbuffers);
662 ReleaseSRWLockExclusive(&device->buffer_list_lock);
665 /*******************************************************************************
666 * IUnknown Implementation for DirectSound
669 static void directsound_destroy(IDirectSoundImpl *This)
671 if (This->device)
672 DirectSoundDevice_Release(This->device);
673 TRACE("(%p) released\n", This);
674 HeapFree(GetProcessHeap(),0,This);
677 static inline IDirectSoundImpl *impl_from_IUnknown(IUnknown *iface)
679 return CONTAINING_RECORD(iface, IDirectSoundImpl, IUnknown_inner);
682 static HRESULT WINAPI IUnknownImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
684 IDirectSoundImpl *This = impl_from_IUnknown(iface);
686 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
688 if (!ppv) {
689 WARN("invalid parameter\n");
690 return E_INVALIDARG;
692 *ppv = NULL;
694 if (IsEqualIID(riid, &IID_IUnknown))
695 *ppv = &This->IUnknown_inner;
696 else if (IsEqualIID(riid, &IID_IDirectSound) ||
697 (IsEqualIID(riid, &IID_IDirectSound8) && This->has_ds8))
698 *ppv = &This->IDirectSound8_iface;
699 else {
700 WARN("unknown IID %s\n", debugstr_guid(riid));
701 return E_NOINTERFACE;
704 IUnknown_AddRef((IUnknown*)*ppv);
705 return S_OK;
708 static ULONG WINAPI IUnknownImpl_AddRef(IUnknown *iface)
710 IDirectSoundImpl *This = impl_from_IUnknown(iface);
711 ULONG ref = InterlockedIncrement(&This->ref);
713 TRACE("(%p) ref=%ld\n", This, ref);
715 if(ref == 1)
716 InterlockedIncrement(&This->numIfaces);
718 return ref;
721 static ULONG WINAPI IUnknownImpl_Release(IUnknown *iface)
723 IDirectSoundImpl *This = impl_from_IUnknown(iface);
724 ULONG ref = InterlockedDecrement(&This->ref);
726 TRACE("(%p) ref=%ld\n", This, ref);
728 if (!ref && !InterlockedDecrement(&This->numIfaces))
729 directsound_destroy(This);
731 return ref;
734 static const IUnknownVtbl unk_vtbl =
736 IUnknownImpl_QueryInterface,
737 IUnknownImpl_AddRef,
738 IUnknownImpl_Release
741 /*******************************************************************************
742 * IDirectSound and IDirectSound8 Implementation
744 static inline IDirectSoundImpl *impl_from_IDirectSound8(IDirectSound8 *iface)
746 return CONTAINING_RECORD(iface, IDirectSoundImpl, IDirectSound8_iface);
749 static HRESULT WINAPI IDirectSound8Impl_QueryInterface(IDirectSound8 *iface, REFIID riid,
750 void **ppv)
752 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
753 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
754 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
757 static ULONG WINAPI IDirectSound8Impl_AddRef(IDirectSound8 *iface)
759 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
760 ULONG ref = InterlockedIncrement(&This->refds);
762 TRACE("(%p) refds=%ld\n", This, ref);
764 if(ref == 1)
765 InterlockedIncrement(&This->numIfaces);
767 return ref;
770 static ULONG WINAPI IDirectSound8Impl_Release(IDirectSound8 *iface)
772 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
773 ULONG ref = InterlockedDecrement(&(This->refds));
775 TRACE("(%p) refds=%ld\n", This, ref);
777 if (!ref && !InterlockedDecrement(&This->numIfaces))
778 directsound_destroy(This);
780 return ref;
783 static HRESULT WINAPI IDirectSound8Impl_CreateSoundBuffer(IDirectSound8 *iface,
784 const DSBUFFERDESC *dsbd, IDirectSoundBuffer **ppdsb, IUnknown *lpunk)
786 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
787 TRACE("(%p,%p,%p,%p)\n", This, dsbd, ppdsb, lpunk);
788 return DirectSoundDevice_CreateSoundBuffer(This->device, dsbd, ppdsb, lpunk, This->has_ds8);
791 static HRESULT WINAPI IDirectSound8Impl_GetCaps(IDirectSound8 *iface, DSCAPS *dscaps)
793 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
795 TRACE("(%p, %p)\n", This, dscaps);
797 if (!This->device) {
798 WARN("not initialized\n");
799 return DSERR_UNINITIALIZED;
801 if (!dscaps) {
802 WARN("invalid parameter: dscaps = NULL\n");
803 return DSERR_INVALIDPARAM;
805 if (dscaps->dwSize < sizeof(*dscaps)) {
806 WARN("invalid parameter: dscaps->dwSize = %ld\n", dscaps->dwSize);
807 return DSERR_INVALIDPARAM;
810 dscaps->dwFlags = This->device->drvcaps.dwFlags;
811 dscaps->dwMinSecondarySampleRate = This->device->drvcaps.dwMinSecondarySampleRate;
812 dscaps->dwMaxSecondarySampleRate = This->device->drvcaps.dwMaxSecondarySampleRate;
813 dscaps->dwPrimaryBuffers = This->device->drvcaps.dwPrimaryBuffers;
814 dscaps->dwMaxHwMixingAllBuffers = This->device->drvcaps.dwMaxHwMixingAllBuffers;
815 dscaps->dwMaxHwMixingStaticBuffers = This->device->drvcaps.dwMaxHwMixingStaticBuffers;
816 dscaps->dwMaxHwMixingStreamingBuffers = This->device->drvcaps.dwMaxHwMixingStreamingBuffers;
817 dscaps->dwFreeHwMixingAllBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
818 dscaps->dwFreeHwMixingStaticBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
819 dscaps->dwFreeHwMixingStreamingBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
821 dscaps->dwMaxHw3DAllBuffers = This->device->drvcaps.dwMaxHw3DAllBuffers;
822 dscaps->dwMaxHw3DStaticBuffers = This->device->drvcaps.dwMaxHw3DStaticBuffers;
823 dscaps->dwMaxHw3DStreamingBuffers = This->device->drvcaps.dwMaxHw3DStreamingBuffers;
824 dscaps->dwFreeHw3DAllBuffers = This->device->drvcaps.dwFreeHw3DAllBuffers;
825 dscaps->dwFreeHw3DStaticBuffers = This->device->drvcaps.dwFreeHw3DStaticBuffers;
826 dscaps->dwFreeHw3DStreamingBuffers = This->device->drvcaps.dwFreeHw3DStreamingBuffers;
827 dscaps->dwTotalHwMemBytes = This->device->drvcaps.dwTotalHwMemBytes;
828 dscaps->dwFreeHwMemBytes = This->device->drvcaps.dwFreeHwMemBytes;
829 dscaps->dwMaxContigFreeHwMemBytes = This->device->drvcaps.dwMaxContigFreeHwMemBytes;
830 dscaps->dwUnlockTransferRateHwBuffers = This->device->drvcaps.dwUnlockTransferRateHwBuffers;
831 dscaps->dwPlayCpuOverheadSwBuffers = This->device->drvcaps.dwPlayCpuOverheadSwBuffers;
833 if (TRACE_ON(dsound)) {
834 TRACE("(flags=0x%08lx:\n", dscaps->dwFlags);
835 _dump_DSCAPS(dscaps->dwFlags);
836 TRACE(")\n");
839 return DS_OK;
842 static HRESULT WINAPI IDirectSound8Impl_DuplicateSoundBuffer(IDirectSound8 *iface,
843 IDirectSoundBuffer *psb, IDirectSoundBuffer **ppdsb)
845 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
846 TRACE("(%p,%p,%p)\n", This, psb, ppdsb);
847 return DirectSoundDevice_DuplicateSoundBuffer(This->device, psb, ppdsb);
850 static HRESULT WINAPI IDirectSound8Impl_SetCooperativeLevel(IDirectSound8 *iface, HWND hwnd,
851 DWORD level)
853 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
854 DirectSoundDevice *device = This->device;
855 HRESULT hr = S_OK;
857 TRACE("(%p,%p,%s)\n", This, hwnd, dumpCooperativeLevel(level));
859 if (!device) {
860 WARN("not initialized\n");
861 return DSERR_UNINITIALIZED;
864 if (level == DSSCL_PRIORITY || level == DSSCL_EXCLUSIVE) {
865 WARN("level=%s not fully supported\n",
866 level==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
869 AcquireSRWLockExclusive(&device->buffer_list_lock);
870 EnterCriticalSection(&device->mixlock);
871 if ((level == DSSCL_WRITEPRIMARY) != (device->priolevel == DSSCL_WRITEPRIMARY))
872 hr = DSOUND_ReopenDevice(device, level == DSSCL_WRITEPRIMARY);
873 if (SUCCEEDED(hr))
874 device->priolevel = level;
875 LeaveCriticalSection(&device->mixlock);
876 ReleaseSRWLockExclusive(&device->buffer_list_lock);
877 return hr;
880 static HRESULT WINAPI IDirectSound8Impl_Compact(IDirectSound8 *iface)
882 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
884 TRACE("(%p)\n", This);
886 if (!This->device) {
887 WARN("not initialized\n");
888 return DSERR_UNINITIALIZED;
891 if (This->device->priolevel < DSSCL_PRIORITY) {
892 WARN("incorrect priority level\n");
893 return DSERR_PRIOLEVELNEEDED;
895 return DS_OK;
898 static HRESULT WINAPI IDirectSound8Impl_GetSpeakerConfig(IDirectSound8 *iface, DWORD *config)
900 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
902 TRACE("(%p, %p)\n", This, config);
904 if (!This->device) {
905 WARN("not initialized\n");
906 return DSERR_UNINITIALIZED;
908 if (!config) {
909 WARN("invalid parameter: config == NULL\n");
910 return DSERR_INVALIDPARAM;
913 WARN("not fully functional\n");
914 *config = This->device->speaker_config;
915 return DS_OK;
918 static HRESULT WINAPI IDirectSound8Impl_SetSpeakerConfig(IDirectSound8 *iface, DWORD config)
920 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
922 TRACE("(%p,0x%08lx)\n", This, config);
924 if (!This->device) {
925 WARN("not initialized\n");
926 return DSERR_UNINITIALIZED;
929 /* NOP on Vista and above */
931 return DS_OK;
934 static HRESULT WINAPI IDirectSound8Impl_Initialize(IDirectSound8 *iface, const GUID *lpcGuid)
936 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
937 TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
938 return DirectSoundDevice_Initialize(&This->device, lpcGuid);
941 static HRESULT WINAPI IDirectSound8Impl_VerifyCertification(IDirectSound8 *iface, DWORD *certified)
943 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
945 TRACE("(%p, %p)\n", This, certified);
947 if (!This->device) {
948 WARN("not initialized\n");
949 return DSERR_UNINITIALIZED;
952 if (This->device->drvcaps.dwFlags & DSCAPS_CERTIFIED)
953 *certified = DS_CERTIFIED;
954 else
955 *certified = DS_UNCERTIFIED;
957 return DS_OK;
960 static const IDirectSound8Vtbl ds8_vtbl =
962 IDirectSound8Impl_QueryInterface,
963 IDirectSound8Impl_AddRef,
964 IDirectSound8Impl_Release,
965 IDirectSound8Impl_CreateSoundBuffer,
966 IDirectSound8Impl_GetCaps,
967 IDirectSound8Impl_DuplicateSoundBuffer,
968 IDirectSound8Impl_SetCooperativeLevel,
969 IDirectSound8Impl_Compact,
970 IDirectSound8Impl_GetSpeakerConfig,
971 IDirectSound8Impl_SetSpeakerConfig,
972 IDirectSound8Impl_Initialize,
973 IDirectSound8Impl_VerifyCertification
976 HRESULT IDirectSoundImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_ds8)
978 IDirectSoundImpl *obj;
979 HRESULT hr;
981 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
983 *ppv = NULL;
984 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj));
985 if (!obj) {
986 WARN("out of memory\n");
987 return DSERR_OUTOFMEMORY;
990 setup_dsound_options();
992 obj->IUnknown_inner.lpVtbl = &unk_vtbl;
993 obj->IDirectSound8_iface.lpVtbl = &ds8_vtbl;
994 obj->ref = 1;
995 obj->refds = 0;
996 obj->numIfaces = 1;
997 obj->device = NULL;
998 obj->has_ds8 = has_ds8;
1000 /* COM aggregation supported only internally */
1001 if (outer_unk)
1002 obj->outer_unk = outer_unk;
1003 else
1004 obj->outer_unk = &obj->IUnknown_inner;
1006 hr = IUnknown_QueryInterface(&obj->IUnknown_inner, riid, ppv);
1007 IUnknown_Release(&obj->IUnknown_inner);
1009 return hr;
1012 HRESULT DSOUND_Create(REFIID riid, void **ppv)
1014 return IDirectSoundImpl_Create(NULL, riid, ppv, FALSE);
1017 HRESULT DSOUND_Create8(REFIID riid, void **ppv)
1019 return IDirectSoundImpl_Create(NULL, riid, ppv, TRUE);
1022 /*******************************************************************************
1023 * DirectSoundCreate (DSOUND.1)
1025 * Creates and initializes a DirectSound interface.
1027 * PARAMS
1028 * lpcGUID [I] Address of the GUID that identifies the sound device.
1029 * ppDS [O] Address of a variable to receive the interface pointer.
1030 * pUnkOuter [I] Must be NULL.
1032 * RETURNS
1033 * Success: DS_OK
1034 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1035 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1037 HRESULT WINAPI DirectSoundCreate(
1038 LPCGUID lpcGUID,
1039 LPDIRECTSOUND *ppDS,
1040 IUnknown *pUnkOuter)
1042 HRESULT hr;
1043 LPDIRECTSOUND pDS;
1045 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
1047 if (ppDS == NULL) {
1048 WARN("invalid parameter: ppDS == NULL\n");
1049 return DSERR_INVALIDPARAM;
1052 if (pUnkOuter != NULL) {
1053 WARN("invalid parameter: pUnkOuter != NULL\n");
1054 *ppDS = 0;
1055 return DSERR_INVALIDPARAM;
1058 hr = DSOUND_Create(&IID_IDirectSound, (void **)&pDS);
1059 if (hr == DS_OK) {
1060 hr = IDirectSound_Initialize(pDS, lpcGUID);
1061 if (hr != DS_OK) {
1062 if (hr != DSERR_ALREADYINITIALIZED) {
1063 IDirectSound_Release(pDS);
1064 pDS = 0;
1065 } else
1066 hr = DS_OK;
1070 *ppDS = pDS;
1072 return hr;
1075 /*******************************************************************************
1076 * DirectSoundCreate8 (DSOUND.11)
1078 * Creates and initializes a DirectSound8 interface.
1080 * PARAMS
1081 * lpcGUID [I] Address of the GUID that identifies the sound device.
1082 * ppDS [O] Address of a variable to receive the interface pointer.
1083 * pUnkOuter [I] Must be NULL.
1085 * RETURNS
1086 * Success: DS_OK
1087 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1088 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1090 HRESULT WINAPI DirectSoundCreate8(
1091 LPCGUID lpcGUID,
1092 LPDIRECTSOUND8 *ppDS,
1093 IUnknown *pUnkOuter)
1095 HRESULT hr;
1096 LPDIRECTSOUND8 pDS;
1098 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
1100 if (ppDS == NULL) {
1101 WARN("invalid parameter: ppDS == NULL\n");
1102 return DSERR_INVALIDPARAM;
1105 if (pUnkOuter != NULL) {
1106 WARN("invalid parameter: pUnkOuter != NULL\n");
1107 *ppDS = 0;
1108 return DSERR_INVALIDPARAM;
1111 hr = DSOUND_Create8(&IID_IDirectSound8, (void **)&pDS);
1112 if (hr == DS_OK) {
1113 hr = IDirectSound8_Initialize(pDS, lpcGUID);
1114 if (hr != DS_OK) {
1115 if (hr != DSERR_ALREADYINITIALIZED) {
1116 IDirectSound8_Release(pDS);
1117 pDS = 0;
1118 } else
1119 hr = DS_OK;
1123 *ppDS = pDS;
1125 return hr;
1128 void DSOUND_ParseSpeakerConfig(DirectSoundDevice *device)
1130 switch (DSSPEAKER_CONFIG(device->speaker_config)) {
1131 case DSSPEAKER_MONO:
1132 device->speaker_angles[0] = M_PI/180.0f * 0.0f;
1133 device->speaker_num[0] = 0;
1134 device->num_speakers = 1;
1135 device->lfe_channel = -1;
1136 break;
1138 case DSSPEAKER_STEREO:
1139 case DSSPEAKER_HEADPHONE:
1140 device->speaker_angles[0] = M_PI/180.0f * -90.0f;
1141 device->speaker_angles[1] = M_PI/180.0f * 90.0f;
1142 device->speaker_num[0] = 0; /* Left */
1143 device->speaker_num[1] = 1; /* Right */
1144 device->num_speakers = 2;
1145 device->lfe_channel = -1;
1146 break;
1148 case DSSPEAKER_QUAD:
1149 device->speaker_angles[0] = M_PI/180.0f * -135.0f;
1150 device->speaker_angles[1] = M_PI/180.0f * -45.0f;
1151 device->speaker_angles[2] = M_PI/180.0f * 45.0f;
1152 device->speaker_angles[3] = M_PI/180.0f * 135.0f;
1153 device->speaker_num[0] = 2; /* Rear left */
1154 device->speaker_num[1] = 0; /* Front left */
1155 device->speaker_num[2] = 1; /* Front right */
1156 device->speaker_num[3] = 3; /* Rear right */
1157 device->num_speakers = 4;
1158 device->lfe_channel = -1;
1159 break;
1161 case DSSPEAKER_5POINT1_BACK:
1162 device->speaker_angles[0] = M_PI/180.0f * -135.0f;
1163 device->speaker_angles[1] = M_PI/180.0f * -45.0f;
1164 device->speaker_angles[2] = M_PI/180.0f * 0.0f;
1165 device->speaker_angles[3] = M_PI/180.0f * 45.0f;
1166 device->speaker_angles[4] = M_PI/180.0f * 135.0f;
1167 device->speaker_angles[5] = 9999.0f;
1168 device->speaker_num[0] = 4; /* Rear left */
1169 device->speaker_num[1] = 0; /* Front left */
1170 device->speaker_num[2] = 2; /* Front centre */
1171 device->speaker_num[3] = 1; /* Front right */
1172 device->speaker_num[4] = 5; /* Rear right */
1173 device->speaker_num[5] = 3; /* LFE */
1174 device->num_speakers = 6;
1175 device->lfe_channel = 3;
1176 break;
1178 case DSSPEAKER_5POINT1_SURROUND:
1179 device->speaker_angles[0] = M_PI/180.0f * -90.0f;
1180 device->speaker_angles[1] = M_PI/180.0f * -30.0f;
1181 device->speaker_angles[2] = M_PI/180.0f * 0.0f;
1182 device->speaker_angles[3] = M_PI/180.0f * 30.0f;
1183 device->speaker_angles[4] = M_PI/180.0f * 90.0f;
1184 device->speaker_angles[5] = 9999.0f;
1185 device->speaker_num[0] = 4; /* Rear left */
1186 device->speaker_num[1] = 0; /* Front left */
1187 device->speaker_num[2] = 2; /* Front centre */
1188 device->speaker_num[3] = 1; /* Front right */
1189 device->speaker_num[4] = 5; /* Rear right */
1190 device->speaker_num[5] = 3; /* LFE */
1191 device->num_speakers = 6;
1192 device->lfe_channel = 3;
1193 break;
1195 default:
1196 WARN("unknown speaker_config %lu\n", device->speaker_config);