secur32/tests: Use importlib for functions available since Windows XP.
[wine.git] / dlls / dsound / dsound.c
blobe8c10a70a2801f9f0a65c6ddbde85586838f0237
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);
236 HeapFree(GetProcessHeap(), 0, device->tmp_buffer);
237 HeapFree(GetProcessHeap(), 0, device->cp_buffer);
238 HeapFree(GetProcessHeap(), 0, device->buffer);
239 RtlDeleteResource(&device->buffer_list_lock);
240 device->mixlock.DebugInfo->Spare[0] = 0;
241 DeleteCriticalSection(&device->mixlock);
242 HeapFree(GetProcessHeap(),0,device);
243 TRACE("(%p) released\n", 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: %08x\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 = 16;
377 device->drvcaps.dwMaxHwMixingStaticBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
378 device->drvcaps.dwMaxHwMixingStreamingBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
379 device->drvcaps.dwFreeHwMixingAllBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
380 device->drvcaps.dwFreeHwMixingStaticBuffers = device->drvcaps.dwMaxHwMixingStaticBuffers;
381 device->drvcaps.dwFreeHwMixingStreamingBuffers = device->drvcaps.dwMaxHwMixingStreamingBuffers;
383 ZeroMemory(&device->volpan, sizeof(device->volpan));
385 device->thread_finished = CreateEventW(0, 0, 0, 0);
386 device->thread = CreateThread(0, 0, DSOUND_mixthread, device, 0, 0);
387 SetThreadPriority(device->thread, THREAD_PRIORITY_TIME_CRITICAL);
389 *ppDevice = device;
390 list_add_tail(&DSOUND_renderers, &device->entry);
392 LeaveCriticalSection(&DSOUND_renderers_lock);
394 return hr;
397 static HRESULT DirectSoundDevice_CreateSoundBuffer(
398 DirectSoundDevice * device,
399 LPCDSBUFFERDESC dsbd,
400 LPLPDIRECTSOUNDBUFFER ppdsb,
401 LPUNKNOWN lpunk,
402 BOOL from8)
404 HRESULT hres = DS_OK;
405 TRACE("(%p,%p,%p,%p)\n",device,dsbd,ppdsb,lpunk);
407 if (device == NULL) {
408 WARN("not initialized\n");
409 return DSERR_UNINITIALIZED;
412 if (dsbd == NULL) {
413 WARN("invalid parameter: dsbd == NULL\n");
414 return DSERR_INVALIDPARAM;
417 if (dsbd->dwSize != sizeof(DSBUFFERDESC) &&
418 dsbd->dwSize != sizeof(DSBUFFERDESC1)) {
419 WARN("invalid parameter: dsbd\n");
420 return DSERR_INVALIDPARAM;
423 if (ppdsb == NULL) {
424 WARN("invalid parameter: ppdsb == NULL\n");
425 return DSERR_INVALIDPARAM;
427 *ppdsb = NULL;
429 if (TRACE_ON(dsound)) {
430 TRACE("(structsize=%d)\n",dsbd->dwSize);
431 TRACE("(flags=0x%08x:\n",dsbd->dwFlags);
432 _dump_DSBCAPS(dsbd->dwFlags);
433 TRACE(")\n");
434 TRACE("(bufferbytes=%d)\n",dsbd->dwBufferBytes);
435 TRACE("(lpwfxFormat=%p)\n",dsbd->lpwfxFormat);
438 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) &&
439 dsbd->dwFlags & DSBCAPS_LOCHARDWARE &&
440 device->drvcaps.dwFreeHwMixingAllBuffers == 0)
442 WARN("ran out of emulated hardware buffers\n");
443 return DSERR_ALLOCATED;
446 if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
447 if (dsbd->lpwfxFormat != NULL) {
448 WARN("invalid parameter: dsbd->lpwfxFormat must be NULL for "
449 "primary buffer\n");
450 return DSERR_INVALIDPARAM;
453 if (device->primary) {
454 WARN("Primary Buffer already created\n");
455 IDirectSoundBuffer8_AddRef(&device->primary->IDirectSoundBuffer8_iface);
456 *ppdsb = (IDirectSoundBuffer *)&device->primary->IDirectSoundBuffer8_iface;
457 } else {
458 hres = primarybuffer_create(device, &device->primary, dsbd);
459 if (device->primary) {
460 *ppdsb = (IDirectSoundBuffer*)&device->primary->IDirectSoundBuffer8_iface;
461 device->primary->dsbd.dwFlags &= ~(DSBCAPS_LOCHARDWARE | DSBCAPS_LOCSOFTWARE);
462 device->primary->dsbd.dwFlags |= DSBCAPS_LOCSOFTWARE;
463 } else
464 WARN("primarybuffer_create() failed\n");
466 } else {
467 if (dsbd->lpwfxFormat == NULL) {
468 WARN("invalid parameter: dsbd->lpwfxFormat can't be NULL for "
469 "secondary buffer\n");
470 return DSERR_INVALIDPARAM;
473 if(dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_PCM &&
474 dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_IEEE_FLOAT &&
475 dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_EXTENSIBLE) {
476 WARN("We can't mix this format: 0x%x\n", dsbd->lpwfxFormat->wFormatTag);
477 return E_NOTIMPL;
480 if(dsbd->lpwfxFormat->wBitsPerSample < 8 || dsbd->lpwfxFormat->wBitsPerSample % 8 != 0 ||
481 dsbd->lpwfxFormat->nChannels == 0 || dsbd->lpwfxFormat->nSamplesPerSec == 0 ||
482 dsbd->lpwfxFormat->nAvgBytesPerSec == 0 ||
483 dsbd->lpwfxFormat->nBlockAlign != dsbd->lpwfxFormat->nChannels * dsbd->lpwfxFormat->wBitsPerSample / 8) {
484 WARN("Format inconsistency\n");
485 return DSERR_INVALIDPARAM;
488 if (dsbd->lpwfxFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
490 WAVEFORMATEXTENSIBLE *pwfxe = (WAVEFORMATEXTENSIBLE*)dsbd->lpwfxFormat;
492 /* check if cbSize is at least 22 bytes */
493 if (pwfxe->Format.cbSize < (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)))
495 WARN("Too small a cbSize %u\n", pwfxe->Format.cbSize);
496 return DSERR_INVALIDPARAM;
499 /* cbSize should be 22 bytes, with one possible exception */
500 if (pwfxe->Format.cbSize > (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)) &&
501 !((IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM) || IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) &&
502 pwfxe->Format.cbSize == sizeof(WAVEFORMATEXTENSIBLE)))
504 WARN("Too big a cbSize %u\n", pwfxe->Format.cbSize);
505 return DSERR_CONTROLUNAVAIL;
508 if ((!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) && (!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)))
510 if (!IsEqualGUID(&pwfxe->SubFormat, &GUID_NULL))
511 FIXME("SubFormat %s not supported right now.\n", debugstr_guid(&pwfxe->SubFormat));
512 return DSERR_INVALIDPARAM;
514 if (pwfxe->Samples.wValidBitsPerSample > dsbd->lpwfxFormat->wBitsPerSample)
516 WARN("Samples.wValidBitsPerSample(%d) > Format.wBitsPerSample (%d)\n", pwfxe->Samples.wValidBitsPerSample, pwfxe->Format.wBitsPerSample);
517 return DSERR_INVALIDPARAM;
519 if (pwfxe->Samples.wValidBitsPerSample && pwfxe->Samples.wValidBitsPerSample < dsbd->lpwfxFormat->wBitsPerSample)
521 WARN("Non-packed formats may not function : %d/%d\n", pwfxe->Samples.wValidBitsPerSample, dsbd->lpwfxFormat->wBitsPerSample);
525 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
526 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
527 dsbd->lpwfxFormat->wFormatTag, dsbd->lpwfxFormat->nChannels,
528 dsbd->lpwfxFormat->nSamplesPerSec,
529 dsbd->lpwfxFormat->nAvgBytesPerSec,
530 dsbd->lpwfxFormat->nBlockAlign,
531 dsbd->lpwfxFormat->wBitsPerSample, dsbd->lpwfxFormat->cbSize);
533 if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->lpwfxFormat->nChannels != 1)) {
534 WARN("invalid parameter: 3D buffer format must be mono\n");
535 return DSERR_INVALIDPARAM;
538 if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->dwFlags & DSBCAPS_CTRLPAN)) {
539 WARN("invalid parameter: DSBCAPS_CTRL3D and DSBCAPS_CTRLPAN cannot be used together\n");
540 return DSERR_INVALIDPARAM;
543 hres = secondarybuffer_create(device, dsbd, ppdsb);
544 if (SUCCEEDED(hres)) {
545 if (dsbd->dwFlags & DSBCAPS_LOCHARDWARE)
546 device->drvcaps.dwFreeHwMixingAllBuffers--;
547 } else
548 WARN("IDirectSoundBufferImpl_Create failed\n");
551 return hres;
554 static HRESULT DirectSoundDevice_DuplicateSoundBuffer(
555 DirectSoundDevice * device,
556 LPDIRECTSOUNDBUFFER psb,
557 LPLPDIRECTSOUNDBUFFER ppdsb)
559 HRESULT hres = DS_OK;
560 IDirectSoundBufferImpl* dsb;
561 TRACE("(%p,%p,%p)\n",device,psb,ppdsb);
563 if (device == NULL) {
564 WARN("not initialized\n");
565 return DSERR_UNINITIALIZED;
568 if (psb == NULL) {
569 WARN("invalid parameter: psb == NULL\n");
570 return DSERR_INVALIDPARAM;
573 if (ppdsb == NULL) {
574 WARN("invalid parameter: ppdsb == NULL\n");
575 return DSERR_INVALIDPARAM;
578 /* make sure we have a secondary buffer */
579 if (psb == (IDirectSoundBuffer *)&device->primary->IDirectSoundBuffer8_iface) {
580 WARN("trying to duplicate primary buffer\n");
581 *ppdsb = NULL;
582 return DSERR_INVALIDCALL;
585 /* duplicate the actual buffer implementation */
586 hres = IDirectSoundBufferImpl_Duplicate(device, &dsb, (IDirectSoundBufferImpl*)psb);
587 if (hres == DS_OK)
588 *ppdsb = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface;
589 else
590 WARN("IDirectSoundBufferImpl_Duplicate failed\n");
592 return hres;
596 * Add secondary buffer to buffer list.
597 * Gets exclusive access to buffer for writing.
599 HRESULT DirectSoundDevice_AddBuffer(
600 DirectSoundDevice * device,
601 IDirectSoundBufferImpl * pDSB)
603 IDirectSoundBufferImpl **newbuffers;
604 HRESULT hr = DS_OK;
606 TRACE("(%p, %p)\n", device, pDSB);
608 RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
610 if (device->buffers)
611 newbuffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
612 else
613 newbuffers = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
615 if (newbuffers) {
616 device->buffers = newbuffers;
617 device->buffers[device->nrofbuffers] = pDSB;
618 device->nrofbuffers++;
619 TRACE("buffer count is now %d\n", device->nrofbuffers);
620 } else {
621 ERR("out of memory for buffer list! Current buffer count is %d\n", device->nrofbuffers);
622 hr = DSERR_OUTOFMEMORY;
625 RtlReleaseResource(&(device->buffer_list_lock));
627 return hr;
631 * Remove secondary buffer from buffer list.
632 * Gets exclusive access to buffer for writing.
634 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBufferImpl * pDSB)
636 int i;
638 TRACE("(%p, %p)\n", device, pDSB);
640 RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
642 if (device->nrofbuffers == 1) {
643 assert(device->buffers[0] == pDSB);
644 HeapFree(GetProcessHeap(), 0, device->buffers);
645 device->buffers = NULL;
646 } else {
647 for (i = 0; i < device->nrofbuffers; i++) {
648 if (device->buffers[i] == pDSB) {
649 /* Put the last buffer of the list in the (now empty) position */
650 device->buffers[i] = device->buffers[device->nrofbuffers - 1];
651 break;
655 device->nrofbuffers--;
656 TRACE("buffer count is now %d\n", device->nrofbuffers);
658 RtlReleaseResource(&(device->buffer_list_lock));
661 /*******************************************************************************
662 * IUnknown Implementation for DirectSound
665 static void directsound_destroy(IDirectSoundImpl *This)
667 if (This->device)
668 DirectSoundDevice_Release(This->device);
669 HeapFree(GetProcessHeap(),0,This);
670 TRACE("(%p) released\n", This);
673 static inline IDirectSoundImpl *impl_from_IUnknown(IUnknown *iface)
675 return CONTAINING_RECORD(iface, IDirectSoundImpl, IUnknown_inner);
678 static HRESULT WINAPI IUnknownImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
680 IDirectSoundImpl *This = impl_from_IUnknown(iface);
682 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
684 if (!ppv) {
685 WARN("invalid parameter\n");
686 return E_INVALIDARG;
688 *ppv = NULL;
690 if (IsEqualIID(riid, &IID_IUnknown))
691 *ppv = &This->IUnknown_inner;
692 else if (IsEqualIID(riid, &IID_IDirectSound) ||
693 (IsEqualIID(riid, &IID_IDirectSound8) && This->has_ds8))
694 *ppv = &This->IDirectSound8_iface;
695 else {
696 WARN("unknown IID %s\n", debugstr_guid(riid));
697 return E_NOINTERFACE;
700 IUnknown_AddRef((IUnknown*)*ppv);
701 return S_OK;
704 static ULONG WINAPI IUnknownImpl_AddRef(IUnknown *iface)
706 IDirectSoundImpl *This = impl_from_IUnknown(iface);
707 ULONG ref = InterlockedIncrement(&This->ref);
709 TRACE("(%p) ref=%d\n", This, ref);
711 if(ref == 1)
712 InterlockedIncrement(&This->numIfaces);
714 return ref;
717 static ULONG WINAPI IUnknownImpl_Release(IUnknown *iface)
719 IDirectSoundImpl *This = impl_from_IUnknown(iface);
720 ULONG ref = InterlockedDecrement(&This->ref);
722 TRACE("(%p) ref=%d\n", This, ref);
724 if (!ref && !InterlockedDecrement(&This->numIfaces))
725 directsound_destroy(This);
727 return ref;
730 static const IUnknownVtbl unk_vtbl =
732 IUnknownImpl_QueryInterface,
733 IUnknownImpl_AddRef,
734 IUnknownImpl_Release
737 /*******************************************************************************
738 * IDirectSound and IDirectSound8 Implementation
740 static inline IDirectSoundImpl *impl_from_IDirectSound8(IDirectSound8 *iface)
742 return CONTAINING_RECORD(iface, IDirectSoundImpl, IDirectSound8_iface);
745 static HRESULT WINAPI IDirectSound8Impl_QueryInterface(IDirectSound8 *iface, REFIID riid,
746 void **ppv)
748 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
749 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
750 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
753 static ULONG WINAPI IDirectSound8Impl_AddRef(IDirectSound8 *iface)
755 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
756 ULONG ref = InterlockedIncrement(&This->refds);
758 TRACE("(%p) refds=%d\n", This, ref);
760 if(ref == 1)
761 InterlockedIncrement(&This->numIfaces);
763 return ref;
766 static ULONG WINAPI IDirectSound8Impl_Release(IDirectSound8 *iface)
768 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
769 ULONG ref = InterlockedDecrement(&(This->refds));
771 TRACE("(%p) refds=%d\n", This, ref);
773 if (!ref && !InterlockedDecrement(&This->numIfaces))
774 directsound_destroy(This);
776 return ref;
779 static HRESULT WINAPI IDirectSound8Impl_CreateSoundBuffer(IDirectSound8 *iface,
780 const DSBUFFERDESC *dsbd, IDirectSoundBuffer **ppdsb, IUnknown *lpunk)
782 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
783 TRACE("(%p,%p,%p,%p)\n", This, dsbd, ppdsb, lpunk);
784 return DirectSoundDevice_CreateSoundBuffer(This->device, dsbd, ppdsb, lpunk, This->has_ds8);
787 static HRESULT WINAPI IDirectSound8Impl_GetCaps(IDirectSound8 *iface, DSCAPS *dscaps)
789 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
791 TRACE("(%p, %p)\n", This, dscaps);
793 if (!This->device) {
794 WARN("not initialized\n");
795 return DSERR_UNINITIALIZED;
797 if (!dscaps) {
798 WARN("invalid parameter: dscaps = NULL\n");
799 return DSERR_INVALIDPARAM;
801 if (dscaps->dwSize < sizeof(*dscaps)) {
802 WARN("invalid parameter: dscaps->dwSize = %d\n", dscaps->dwSize);
803 return DSERR_INVALIDPARAM;
806 dscaps->dwFlags = This->device->drvcaps.dwFlags;
807 dscaps->dwMinSecondarySampleRate = This->device->drvcaps.dwMinSecondarySampleRate;
808 dscaps->dwMaxSecondarySampleRate = This->device->drvcaps.dwMaxSecondarySampleRate;
809 dscaps->dwPrimaryBuffers = This->device->drvcaps.dwPrimaryBuffers;
810 dscaps->dwMaxHwMixingAllBuffers = This->device->drvcaps.dwMaxHwMixingAllBuffers;
811 dscaps->dwMaxHwMixingStaticBuffers = This->device->drvcaps.dwMaxHwMixingStaticBuffers;
812 dscaps->dwMaxHwMixingStreamingBuffers = This->device->drvcaps.dwMaxHwMixingStreamingBuffers;
813 dscaps->dwFreeHwMixingAllBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
814 dscaps->dwFreeHwMixingStaticBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
815 dscaps->dwFreeHwMixingStreamingBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
817 dscaps->dwMaxHw3DAllBuffers = This->device->drvcaps.dwMaxHw3DAllBuffers;
818 dscaps->dwMaxHw3DStaticBuffers = This->device->drvcaps.dwMaxHw3DStaticBuffers;
819 dscaps->dwMaxHw3DStreamingBuffers = This->device->drvcaps.dwMaxHw3DStreamingBuffers;
820 dscaps->dwFreeHw3DAllBuffers = This->device->drvcaps.dwFreeHw3DAllBuffers;
821 dscaps->dwFreeHw3DStaticBuffers = This->device->drvcaps.dwFreeHw3DStaticBuffers;
822 dscaps->dwFreeHw3DStreamingBuffers = This->device->drvcaps.dwFreeHw3DStreamingBuffers;
823 dscaps->dwTotalHwMemBytes = This->device->drvcaps.dwTotalHwMemBytes;
824 dscaps->dwFreeHwMemBytes = This->device->drvcaps.dwFreeHwMemBytes;
825 dscaps->dwMaxContigFreeHwMemBytes = This->device->drvcaps.dwMaxContigFreeHwMemBytes;
826 dscaps->dwUnlockTransferRateHwBuffers = This->device->drvcaps.dwUnlockTransferRateHwBuffers;
827 dscaps->dwPlayCpuOverheadSwBuffers = This->device->drvcaps.dwPlayCpuOverheadSwBuffers;
829 if (TRACE_ON(dsound)) {
830 TRACE("(flags=0x%08x:\n", dscaps->dwFlags);
831 _dump_DSCAPS(dscaps->dwFlags);
832 TRACE(")\n");
835 return DS_OK;
838 static HRESULT WINAPI IDirectSound8Impl_DuplicateSoundBuffer(IDirectSound8 *iface,
839 IDirectSoundBuffer *psb, IDirectSoundBuffer **ppdsb)
841 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
842 TRACE("(%p,%p,%p)\n", This, psb, ppdsb);
843 return DirectSoundDevice_DuplicateSoundBuffer(This->device, psb, ppdsb);
846 static HRESULT WINAPI IDirectSound8Impl_SetCooperativeLevel(IDirectSound8 *iface, HWND hwnd,
847 DWORD level)
849 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
850 DirectSoundDevice *device = This->device;
851 HRESULT hr = S_OK;
853 TRACE("(%p,%p,%s)\n", This, hwnd, dumpCooperativeLevel(level));
855 if (!device) {
856 WARN("not initialized\n");
857 return DSERR_UNINITIALIZED;
860 if (level == DSSCL_PRIORITY || level == DSSCL_EXCLUSIVE) {
861 WARN("level=%s not fully supported\n",
862 level==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
865 RtlAcquireResourceExclusive(&device->buffer_list_lock, TRUE);
866 EnterCriticalSection(&device->mixlock);
867 if ((level == DSSCL_WRITEPRIMARY) != (device->priolevel == DSSCL_WRITEPRIMARY))
868 hr = DSOUND_ReopenDevice(device, level == DSSCL_WRITEPRIMARY);
869 if (SUCCEEDED(hr))
870 device->priolevel = level;
871 LeaveCriticalSection(&device->mixlock);
872 RtlReleaseResource(&device->buffer_list_lock);
873 return hr;
876 static HRESULT WINAPI IDirectSound8Impl_Compact(IDirectSound8 *iface)
878 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
880 TRACE("(%p)\n", This);
882 if (!This->device) {
883 WARN("not initialized\n");
884 return DSERR_UNINITIALIZED;
887 if (This->device->priolevel < DSSCL_PRIORITY) {
888 WARN("incorrect priority level\n");
889 return DSERR_PRIOLEVELNEEDED;
891 return DS_OK;
894 static HRESULT WINAPI IDirectSound8Impl_GetSpeakerConfig(IDirectSound8 *iface, DWORD *config)
896 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
898 TRACE("(%p, %p)\n", This, config);
900 if (!This->device) {
901 WARN("not initialized\n");
902 return DSERR_UNINITIALIZED;
904 if (!config) {
905 WARN("invalid parameter: config == NULL\n");
906 return DSERR_INVALIDPARAM;
909 WARN("not fully functional\n");
910 *config = This->device->speaker_config;
911 return DS_OK;
914 static HRESULT WINAPI IDirectSound8Impl_SetSpeakerConfig(IDirectSound8 *iface, DWORD config)
916 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
918 TRACE("(%p,0x%08x)\n", This, config);
920 if (!This->device) {
921 WARN("not initialized\n");
922 return DSERR_UNINITIALIZED;
925 /* NOP on Vista and above */
927 return DS_OK;
930 static HRESULT WINAPI IDirectSound8Impl_Initialize(IDirectSound8 *iface, const GUID *lpcGuid)
932 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
933 TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
934 return DirectSoundDevice_Initialize(&This->device, lpcGuid);
937 static HRESULT WINAPI IDirectSound8Impl_VerifyCertification(IDirectSound8 *iface, DWORD *certified)
939 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
941 TRACE("(%p, %p)\n", This, certified);
943 if (!This->device) {
944 WARN("not initialized\n");
945 return DSERR_UNINITIALIZED;
948 if (This->device->drvcaps.dwFlags & DSCAPS_CERTIFIED)
949 *certified = DS_CERTIFIED;
950 else
951 *certified = DS_UNCERTIFIED;
953 return DS_OK;
956 static const IDirectSound8Vtbl ds8_vtbl =
958 IDirectSound8Impl_QueryInterface,
959 IDirectSound8Impl_AddRef,
960 IDirectSound8Impl_Release,
961 IDirectSound8Impl_CreateSoundBuffer,
962 IDirectSound8Impl_GetCaps,
963 IDirectSound8Impl_DuplicateSoundBuffer,
964 IDirectSound8Impl_SetCooperativeLevel,
965 IDirectSound8Impl_Compact,
966 IDirectSound8Impl_GetSpeakerConfig,
967 IDirectSound8Impl_SetSpeakerConfig,
968 IDirectSound8Impl_Initialize,
969 IDirectSound8Impl_VerifyCertification
972 HRESULT IDirectSoundImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_ds8)
974 IDirectSoundImpl *obj;
975 HRESULT hr;
977 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
979 *ppv = NULL;
980 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj));
981 if (!obj) {
982 WARN("out of memory\n");
983 return DSERR_OUTOFMEMORY;
986 setup_dsound_options();
988 obj->IUnknown_inner.lpVtbl = &unk_vtbl;
989 obj->IDirectSound8_iface.lpVtbl = &ds8_vtbl;
990 obj->ref = 1;
991 obj->refds = 0;
992 obj->numIfaces = 1;
993 obj->device = NULL;
994 obj->has_ds8 = has_ds8;
996 /* COM aggregation supported only internally */
997 if (outer_unk)
998 obj->outer_unk = outer_unk;
999 else
1000 obj->outer_unk = &obj->IUnknown_inner;
1002 hr = IUnknown_QueryInterface(&obj->IUnknown_inner, riid, ppv);
1003 IUnknown_Release(&obj->IUnknown_inner);
1005 return hr;
1008 HRESULT DSOUND_Create(REFIID riid, void **ppv)
1010 return IDirectSoundImpl_Create(NULL, riid, ppv, FALSE);
1013 HRESULT DSOUND_Create8(REFIID riid, void **ppv)
1015 return IDirectSoundImpl_Create(NULL, riid, ppv, TRUE);
1018 /*******************************************************************************
1019 * DirectSoundCreate (DSOUND.1)
1021 * Creates and initializes a DirectSound interface.
1023 * PARAMS
1024 * lpcGUID [I] Address of the GUID that identifies the sound device.
1025 * ppDS [O] Address of a variable to receive the interface pointer.
1026 * pUnkOuter [I] Must be NULL.
1028 * RETURNS
1029 * Success: DS_OK
1030 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1031 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1033 HRESULT WINAPI DirectSoundCreate(
1034 LPCGUID lpcGUID,
1035 LPDIRECTSOUND *ppDS,
1036 IUnknown *pUnkOuter)
1038 HRESULT hr;
1039 LPDIRECTSOUND pDS;
1041 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
1043 if (ppDS == NULL) {
1044 WARN("invalid parameter: ppDS == NULL\n");
1045 return DSERR_INVALIDPARAM;
1048 if (pUnkOuter != NULL) {
1049 WARN("invalid parameter: pUnkOuter != NULL\n");
1050 *ppDS = 0;
1051 return DSERR_INVALIDPARAM;
1054 hr = DSOUND_Create(&IID_IDirectSound, (void **)&pDS);
1055 if (hr == DS_OK) {
1056 hr = IDirectSound_Initialize(pDS, lpcGUID);
1057 if (hr != DS_OK) {
1058 if (hr != DSERR_ALREADYINITIALIZED) {
1059 IDirectSound_Release(pDS);
1060 pDS = 0;
1061 } else
1062 hr = DS_OK;
1066 *ppDS = pDS;
1068 return hr;
1071 /*******************************************************************************
1072 * DirectSoundCreate8 (DSOUND.11)
1074 * Creates and initializes a DirectSound8 interface.
1076 * PARAMS
1077 * lpcGUID [I] Address of the GUID that identifies the sound device.
1078 * ppDS [O] Address of a variable to receive the interface pointer.
1079 * pUnkOuter [I] Must be NULL.
1081 * RETURNS
1082 * Success: DS_OK
1083 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1084 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1086 HRESULT WINAPI DirectSoundCreate8(
1087 LPCGUID lpcGUID,
1088 LPDIRECTSOUND8 *ppDS,
1089 IUnknown *pUnkOuter)
1091 HRESULT hr;
1092 LPDIRECTSOUND8 pDS;
1094 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
1096 if (ppDS == NULL) {
1097 WARN("invalid parameter: ppDS == NULL\n");
1098 return DSERR_INVALIDPARAM;
1101 if (pUnkOuter != NULL) {
1102 WARN("invalid parameter: pUnkOuter != NULL\n");
1103 *ppDS = 0;
1104 return DSERR_INVALIDPARAM;
1107 hr = DSOUND_Create8(&IID_IDirectSound8, (void **)&pDS);
1108 if (hr == DS_OK) {
1109 hr = IDirectSound8_Initialize(pDS, lpcGUID);
1110 if (hr != DS_OK) {
1111 if (hr != DSERR_ALREADYINITIALIZED) {
1112 IDirectSound8_Release(pDS);
1113 pDS = 0;
1114 } else
1115 hr = DS_OK;
1119 *ppDS = pDS;
1121 return hr;
1124 void DSOUND_ParseSpeakerConfig(DirectSoundDevice *device)
1126 switch (DSSPEAKER_CONFIG(device->speaker_config)) {
1127 case DSSPEAKER_MONO:
1128 device->speaker_angles[0] = M_PI/180.0f * 0.0f;
1129 device->speaker_num[0] = 0;
1130 device->num_speakers = 1;
1131 device->lfe_channel = -1;
1132 break;
1134 case DSSPEAKER_STEREO:
1135 case DSSPEAKER_HEADPHONE:
1136 device->speaker_angles[0] = M_PI/180.0f * -90.0f;
1137 device->speaker_angles[1] = M_PI/180.0f * 90.0f;
1138 device->speaker_num[0] = 0; /* Left */
1139 device->speaker_num[1] = 1; /* Right */
1140 device->num_speakers = 2;
1141 device->lfe_channel = -1;
1142 break;
1144 case DSSPEAKER_QUAD:
1145 device->speaker_angles[0] = M_PI/180.0f * -135.0f;
1146 device->speaker_angles[1] = M_PI/180.0f * -45.0f;
1147 device->speaker_angles[2] = M_PI/180.0f * 45.0f;
1148 device->speaker_angles[3] = M_PI/180.0f * 135.0f;
1149 device->speaker_num[0] = 2; /* Rear left */
1150 device->speaker_num[1] = 0; /* Front left */
1151 device->speaker_num[2] = 1; /* Front right */
1152 device->speaker_num[3] = 3; /* Rear right */
1153 device->num_speakers = 4;
1154 device->lfe_channel = -1;
1155 break;
1157 case DSSPEAKER_5POINT1_BACK:
1158 device->speaker_angles[0] = M_PI/180.0f * -135.0f;
1159 device->speaker_angles[1] = M_PI/180.0f * -45.0f;
1160 device->speaker_angles[2] = M_PI/180.0f * 0.0f;
1161 device->speaker_angles[3] = M_PI/180.0f * 45.0f;
1162 device->speaker_angles[4] = M_PI/180.0f * 135.0f;
1163 device->speaker_angles[5] = 9999.0f;
1164 device->speaker_num[0] = 4; /* Rear left */
1165 device->speaker_num[1] = 0; /* Front left */
1166 device->speaker_num[2] = 2; /* Front centre */
1167 device->speaker_num[3] = 1; /* Front right */
1168 device->speaker_num[4] = 5; /* Rear right */
1169 device->speaker_num[5] = 3; /* LFE */
1170 device->num_speakers = 6;
1171 device->lfe_channel = 3;
1172 break;
1174 case DSSPEAKER_5POINT1_SURROUND:
1175 device->speaker_angles[0] = M_PI/180.0f * -90.0f;
1176 device->speaker_angles[1] = M_PI/180.0f * -30.0f;
1177 device->speaker_angles[2] = M_PI/180.0f * 0.0f;
1178 device->speaker_angles[3] = M_PI/180.0f * 30.0f;
1179 device->speaker_angles[4] = M_PI/180.0f * 90.0f;
1180 device->speaker_angles[5] = 9999.0f;
1181 device->speaker_num[0] = 4; /* Rear left */
1182 device->speaker_num[1] = 0; /* Front left */
1183 device->speaker_num[2] = 2; /* Front centre */
1184 device->speaker_num[3] = 1; /* Front right */
1185 device->speaker_num[4] = 5; /* Rear right */
1186 device->speaker_num[5] = 3; /* LFE */
1187 device->num_speakers = 6;
1188 device->lfe_channel = 3;
1189 break;
1191 default:
1192 WARN("unknown speaker_config %u\n", device->speaker_config);