TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / dsound / dsound.c
blobfb9fd667b4862c5bfa02d0900e96bd4bc38221e4
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 device->drvcaps.dwPrimaryBuffers = 1;
371 device->drvcaps.dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
372 device->drvcaps.dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
373 device->drvcaps.dwMaxHwMixingAllBuffers = 16;
374 device->drvcaps.dwMaxHwMixingStaticBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
375 device->drvcaps.dwMaxHwMixingStreamingBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
376 device->drvcaps.dwFreeHwMixingAllBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
377 device->drvcaps.dwFreeHwMixingStaticBuffers = device->drvcaps.dwMaxHwMixingStaticBuffers;
378 device->drvcaps.dwFreeHwMixingStreamingBuffers = device->drvcaps.dwMaxHwMixingStreamingBuffers;
380 ZeroMemory(&device->volpan, sizeof(device->volpan));
382 device->thread_finished = CreateEventW(0, 0, 0, 0);
383 device->thread = CreateThread(0, 0, DSOUND_mixthread, device, 0, 0);
384 SetThreadPriority(device->thread, THREAD_PRIORITY_TIME_CRITICAL);
386 *ppDevice = device;
387 list_add_tail(&DSOUND_renderers, &device->entry);
389 LeaveCriticalSection(&DSOUND_renderers_lock);
391 return hr;
394 static HRESULT DirectSoundDevice_CreateSoundBuffer(
395 DirectSoundDevice * device,
396 LPCDSBUFFERDESC dsbd,
397 LPLPDIRECTSOUNDBUFFER ppdsb,
398 LPUNKNOWN lpunk,
399 BOOL from8)
401 HRESULT hres = DS_OK;
402 TRACE("(%p,%p,%p,%p)\n",device,dsbd,ppdsb,lpunk);
404 if (device == NULL) {
405 WARN("not initialized\n");
406 return DSERR_UNINITIALIZED;
409 if (dsbd == NULL) {
410 WARN("invalid parameter: dsbd == NULL\n");
411 return DSERR_INVALIDPARAM;
414 if (dsbd->dwSize != sizeof(DSBUFFERDESC) &&
415 dsbd->dwSize != sizeof(DSBUFFERDESC1)) {
416 WARN("invalid parameter: dsbd\n");
417 return DSERR_INVALIDPARAM;
420 if (ppdsb == NULL) {
421 WARN("invalid parameter: ppdsb == NULL\n");
422 return DSERR_INVALIDPARAM;
424 *ppdsb = NULL;
426 if (TRACE_ON(dsound)) {
427 TRACE("(structsize=%d)\n",dsbd->dwSize);
428 TRACE("(flags=0x%08x:\n",dsbd->dwFlags);
429 _dump_DSBCAPS(dsbd->dwFlags);
430 TRACE(")\n");
431 TRACE("(bufferbytes=%d)\n",dsbd->dwBufferBytes);
432 TRACE("(lpwfxFormat=%p)\n",dsbd->lpwfxFormat);
435 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) &&
436 dsbd->dwFlags & DSBCAPS_LOCHARDWARE &&
437 device->drvcaps.dwFreeHwMixingAllBuffers == 0)
439 WARN("ran out of emulated hardware buffers\n");
440 return DSERR_ALLOCATED;
443 if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
444 if (dsbd->lpwfxFormat != NULL) {
445 WARN("invalid parameter: dsbd->lpwfxFormat must be NULL for "
446 "primary buffer\n");
447 return DSERR_INVALIDPARAM;
450 if (device->primary) {
451 WARN("Primary Buffer already created\n");
452 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)(device->primary));
453 *ppdsb = (LPDIRECTSOUNDBUFFER)(device->primary);
454 } else {
455 hres = primarybuffer_create(device, &device->primary, dsbd);
456 if (device->primary) {
457 *ppdsb = (IDirectSoundBuffer*)&device->primary->IDirectSoundBuffer8_iface;
458 device->primary->dsbd.dwFlags &= ~(DSBCAPS_LOCHARDWARE | DSBCAPS_LOCSOFTWARE);
459 device->primary->dsbd.dwFlags |= DSBCAPS_LOCSOFTWARE;
460 } else
461 WARN("primarybuffer_create() failed\n");
463 } else {
464 if (dsbd->lpwfxFormat == NULL) {
465 WARN("invalid parameter: dsbd->lpwfxFormat can't be NULL for "
466 "secondary buffer\n");
467 return DSERR_INVALIDPARAM;
470 if(dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_PCM &&
471 dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_IEEE_FLOAT &&
472 dsbd->lpwfxFormat->wFormatTag != WAVE_FORMAT_EXTENSIBLE) {
473 WARN("We can't mix this format: 0x%x\n", dsbd->lpwfxFormat->wFormatTag);
474 return E_NOTIMPL;
477 if(dsbd->lpwfxFormat->wBitsPerSample < 8 || dsbd->lpwfxFormat->wBitsPerSample % 8 != 0 ||
478 dsbd->lpwfxFormat->nChannels == 0 || dsbd->lpwfxFormat->nSamplesPerSec == 0 ||
479 dsbd->lpwfxFormat->nAvgBytesPerSec == 0 ||
480 dsbd->lpwfxFormat->nBlockAlign != dsbd->lpwfxFormat->nChannels * dsbd->lpwfxFormat->wBitsPerSample / 8) {
481 WARN("Format inconsistency\n");
482 return DSERR_INVALIDPARAM;
485 if (dsbd->lpwfxFormat->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
487 WAVEFORMATEXTENSIBLE *pwfxe = (WAVEFORMATEXTENSIBLE*)dsbd->lpwfxFormat;
489 /* check if cbSize is at least 22 bytes */
490 if (pwfxe->Format.cbSize < (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)))
492 WARN("Too small a cbSize %u\n", pwfxe->Format.cbSize);
493 return DSERR_INVALIDPARAM;
496 /* cbSize should be 22 bytes, with one possible exception */
497 if (pwfxe->Format.cbSize > (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)) &&
498 !((IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM) || IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) &&
499 pwfxe->Format.cbSize == sizeof(WAVEFORMATEXTENSIBLE)))
501 WARN("Too big a cbSize %u\n", pwfxe->Format.cbSize);
502 return DSERR_CONTROLUNAVAIL;
505 if ((!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) && (!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)))
507 if (!IsEqualGUID(&pwfxe->SubFormat, &GUID_NULL))
508 FIXME("SubFormat %s not supported right now.\n", debugstr_guid(&pwfxe->SubFormat));
509 return DSERR_INVALIDPARAM;
511 if (pwfxe->Samples.wValidBitsPerSample > dsbd->lpwfxFormat->wBitsPerSample)
513 WARN("Samples.wValidBitsPerSample(%d) > Format.wBitsPerSample (%d)\n", pwfxe->Samples.wValidBitsPerSample, pwfxe->Format.wBitsPerSample);
514 return DSERR_INVALIDPARAM;
516 if (pwfxe->Samples.wValidBitsPerSample && pwfxe->Samples.wValidBitsPerSample < dsbd->lpwfxFormat->wBitsPerSample)
518 WARN("Non-packed formats may not function : %d/%d\n", pwfxe->Samples.wValidBitsPerSample, dsbd->lpwfxFormat->wBitsPerSample);
522 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
523 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
524 dsbd->lpwfxFormat->wFormatTag, dsbd->lpwfxFormat->nChannels,
525 dsbd->lpwfxFormat->nSamplesPerSec,
526 dsbd->lpwfxFormat->nAvgBytesPerSec,
527 dsbd->lpwfxFormat->nBlockAlign,
528 dsbd->lpwfxFormat->wBitsPerSample, dsbd->lpwfxFormat->cbSize);
530 if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->lpwfxFormat->nChannels != 1)) {
531 WARN("invalid parameter: 3D buffer format must be mono\n");
532 return DSERR_INVALIDPARAM;
535 if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->dwFlags & DSBCAPS_CTRLPAN)) {
536 WARN("invalid parameter: DSBCAPS_CTRL3D and DSBCAPS_CTRLPAN cannot be used together\n");
537 return DSERR_INVALIDPARAM;
540 hres = secondarybuffer_create(device, dsbd, ppdsb);
541 if (SUCCEEDED(hres)) {
542 if (dsbd->dwFlags & DSBCAPS_LOCHARDWARE)
543 device->drvcaps.dwFreeHwMixingAllBuffers--;
544 } else
545 WARN("IDirectSoundBufferImpl_Create failed\n");
548 return hres;
551 static HRESULT DirectSoundDevice_DuplicateSoundBuffer(
552 DirectSoundDevice * device,
553 LPDIRECTSOUNDBUFFER psb,
554 LPLPDIRECTSOUNDBUFFER ppdsb)
556 HRESULT hres = DS_OK;
557 IDirectSoundBufferImpl* dsb;
558 TRACE("(%p,%p,%p)\n",device,psb,ppdsb);
560 if (device == NULL) {
561 WARN("not initialized\n");
562 return DSERR_UNINITIALIZED;
565 if (psb == NULL) {
566 WARN("invalid parameter: psb == NULL\n");
567 return DSERR_INVALIDPARAM;
570 if (ppdsb == NULL) {
571 WARN("invalid parameter: ppdsb == NULL\n");
572 return DSERR_INVALIDPARAM;
575 /* make sure we have a secondary buffer */
576 if (psb == (IDirectSoundBuffer *)&device->primary->IDirectSoundBuffer8_iface) {
577 WARN("trying to duplicate primary buffer\n");
578 *ppdsb = NULL;
579 return DSERR_INVALIDCALL;
582 /* duplicate the actual buffer implementation */
583 hres = IDirectSoundBufferImpl_Duplicate(device, &dsb, (IDirectSoundBufferImpl*)psb);
584 if (hres == DS_OK)
585 *ppdsb = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface;
586 else
587 WARN("IDirectSoundBufferImpl_Duplicate failed\n");
589 return hres;
593 * Add secondary buffer to buffer list.
594 * Gets exclusive access to buffer for writing.
596 HRESULT DirectSoundDevice_AddBuffer(
597 DirectSoundDevice * device,
598 IDirectSoundBufferImpl * pDSB)
600 IDirectSoundBufferImpl **newbuffers;
601 HRESULT hr = DS_OK;
603 TRACE("(%p, %p)\n", device, pDSB);
605 RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
607 if (device->buffers)
608 newbuffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
609 else
610 newbuffers = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
612 if (newbuffers) {
613 device->buffers = newbuffers;
614 device->buffers[device->nrofbuffers] = pDSB;
615 device->nrofbuffers++;
616 TRACE("buffer count is now %d\n", device->nrofbuffers);
617 } else {
618 ERR("out of memory for buffer list! Current buffer count is %d\n", device->nrofbuffers);
619 hr = DSERR_OUTOFMEMORY;
622 RtlReleaseResource(&(device->buffer_list_lock));
624 return hr;
628 * Remove secondary buffer from buffer list.
629 * Gets exclusive access to buffer for writing.
631 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBufferImpl * pDSB)
633 int i;
635 TRACE("(%p, %p)\n", device, pDSB);
637 RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
639 if (device->nrofbuffers == 1) {
640 assert(device->buffers[0] == pDSB);
641 HeapFree(GetProcessHeap(), 0, device->buffers);
642 device->buffers = NULL;
643 } else {
644 for (i = 0; i < device->nrofbuffers; i++) {
645 if (device->buffers[i] == pDSB) {
646 /* Put the last buffer of the list in the (now empty) position */
647 device->buffers[i] = device->buffers[device->nrofbuffers - 1];
648 break;
652 device->nrofbuffers--;
653 TRACE("buffer count is now %d\n", device->nrofbuffers);
655 RtlReleaseResource(&(device->buffer_list_lock));
658 /*******************************************************************************
659 * IUnknown Implementation for DirectSound
662 static void directsound_destroy(IDirectSoundImpl *This)
664 if (This->device)
665 DirectSoundDevice_Release(This->device);
666 HeapFree(GetProcessHeap(),0,This);
667 TRACE("(%p) released\n", This);
670 static inline IDirectSoundImpl *impl_from_IUnknown(IUnknown *iface)
672 return CONTAINING_RECORD(iface, IDirectSoundImpl, IUnknown_inner);
675 static HRESULT WINAPI IUnknownImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
677 IDirectSoundImpl *This = impl_from_IUnknown(iface);
679 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
681 if (!ppv) {
682 WARN("invalid parameter\n");
683 return E_INVALIDARG;
685 *ppv = NULL;
687 if (IsEqualIID(riid, &IID_IUnknown))
688 *ppv = &This->IUnknown_inner;
689 else if (IsEqualIID(riid, &IID_IDirectSound) ||
690 (IsEqualIID(riid, &IID_IDirectSound8) && This->has_ds8))
691 *ppv = &This->IDirectSound8_iface;
692 else {
693 WARN("unknown IID %s\n", debugstr_guid(riid));
694 return E_NOINTERFACE;
697 IUnknown_AddRef((IUnknown*)*ppv);
698 return S_OK;
701 static ULONG WINAPI IUnknownImpl_AddRef(IUnknown *iface)
703 IDirectSoundImpl *This = impl_from_IUnknown(iface);
704 ULONG ref = InterlockedIncrement(&This->ref);
706 TRACE("(%p) ref=%d\n", This, ref);
708 if(ref == 1)
709 InterlockedIncrement(&This->numIfaces);
711 return ref;
714 static ULONG WINAPI IUnknownImpl_Release(IUnknown *iface)
716 IDirectSoundImpl *This = impl_from_IUnknown(iface);
717 ULONG ref = InterlockedDecrement(&This->ref);
719 TRACE("(%p) ref=%d\n", This, ref);
721 if (!ref && !InterlockedDecrement(&This->numIfaces))
722 directsound_destroy(This);
724 return ref;
727 static const IUnknownVtbl unk_vtbl =
729 IUnknownImpl_QueryInterface,
730 IUnknownImpl_AddRef,
731 IUnknownImpl_Release
734 /*******************************************************************************
735 * IDirectSound and IDirectSound8 Implementation
737 static inline IDirectSoundImpl *impl_from_IDirectSound8(IDirectSound8 *iface)
739 return CONTAINING_RECORD(iface, IDirectSoundImpl, IDirectSound8_iface);
742 static HRESULT WINAPI IDirectSound8Impl_QueryInterface(IDirectSound8 *iface, REFIID riid,
743 void **ppv)
745 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
746 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
747 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
750 static ULONG WINAPI IDirectSound8Impl_AddRef(IDirectSound8 *iface)
752 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
753 ULONG ref = InterlockedIncrement(&This->refds);
755 TRACE("(%p) refds=%d\n", This, ref);
757 if(ref == 1)
758 InterlockedIncrement(&This->numIfaces);
760 return ref;
763 static ULONG WINAPI IDirectSound8Impl_Release(IDirectSound8 *iface)
765 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
766 ULONG ref = InterlockedDecrement(&(This->refds));
768 TRACE("(%p) refds=%d\n", This, ref);
770 if (!ref && !InterlockedDecrement(&This->numIfaces))
771 directsound_destroy(This);
773 return ref;
776 static HRESULT WINAPI IDirectSound8Impl_CreateSoundBuffer(IDirectSound8 *iface,
777 const DSBUFFERDESC *dsbd, IDirectSoundBuffer **ppdsb, IUnknown *lpunk)
779 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
780 TRACE("(%p,%p,%p,%p)\n", This, dsbd, ppdsb, lpunk);
781 return DirectSoundDevice_CreateSoundBuffer(This->device, dsbd, ppdsb, lpunk, This->has_ds8);
784 static HRESULT WINAPI IDirectSound8Impl_GetCaps(IDirectSound8 *iface, DSCAPS *dscaps)
786 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
788 TRACE("(%p, %p)\n", This, dscaps);
790 if (!This->device) {
791 WARN("not initialized\n");
792 return DSERR_UNINITIALIZED;
794 if (!dscaps) {
795 WARN("invalid parameter: dscaps = NULL\n");
796 return DSERR_INVALIDPARAM;
798 if (dscaps->dwSize < sizeof(*dscaps)) {
799 WARN("invalid parameter: dscaps->dwSize = %d\n", dscaps->dwSize);
800 return DSERR_INVALIDPARAM;
803 dscaps->dwFlags = This->device->drvcaps.dwFlags;
804 dscaps->dwMinSecondarySampleRate = This->device->drvcaps.dwMinSecondarySampleRate;
805 dscaps->dwMaxSecondarySampleRate = This->device->drvcaps.dwMaxSecondarySampleRate;
806 dscaps->dwPrimaryBuffers = This->device->drvcaps.dwPrimaryBuffers;
807 dscaps->dwMaxHwMixingAllBuffers = This->device->drvcaps.dwMaxHwMixingAllBuffers;
808 dscaps->dwMaxHwMixingStaticBuffers = This->device->drvcaps.dwMaxHwMixingStaticBuffers;
809 dscaps->dwMaxHwMixingStreamingBuffers = This->device->drvcaps.dwMaxHwMixingStreamingBuffers;
810 dscaps->dwFreeHwMixingAllBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
811 dscaps->dwFreeHwMixingStaticBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
812 dscaps->dwFreeHwMixingStreamingBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
814 dscaps->dwMaxHw3DAllBuffers = This->device->drvcaps.dwMaxHw3DAllBuffers;
815 dscaps->dwMaxHw3DStaticBuffers = This->device->drvcaps.dwMaxHw3DStaticBuffers;
816 dscaps->dwMaxHw3DStreamingBuffers = This->device->drvcaps.dwMaxHw3DStreamingBuffers;
817 dscaps->dwFreeHw3DAllBuffers = This->device->drvcaps.dwFreeHw3DAllBuffers;
818 dscaps->dwFreeHw3DStaticBuffers = This->device->drvcaps.dwFreeHw3DStaticBuffers;
819 dscaps->dwFreeHw3DStreamingBuffers = This->device->drvcaps.dwFreeHw3DStreamingBuffers;
820 dscaps->dwTotalHwMemBytes = This->device->drvcaps.dwTotalHwMemBytes;
821 dscaps->dwFreeHwMemBytes = This->device->drvcaps.dwFreeHwMemBytes;
822 dscaps->dwMaxContigFreeHwMemBytes = This->device->drvcaps.dwMaxContigFreeHwMemBytes;
823 dscaps->dwUnlockTransferRateHwBuffers = This->device->drvcaps.dwUnlockTransferRateHwBuffers;
824 dscaps->dwPlayCpuOverheadSwBuffers = This->device->drvcaps.dwPlayCpuOverheadSwBuffers;
826 if (TRACE_ON(dsound)) {
827 TRACE("(flags=0x%08x:\n", dscaps->dwFlags);
828 _dump_DSCAPS(dscaps->dwFlags);
829 TRACE(")\n");
832 return DS_OK;
835 static HRESULT WINAPI IDirectSound8Impl_DuplicateSoundBuffer(IDirectSound8 *iface,
836 IDirectSoundBuffer *psb, IDirectSoundBuffer **ppdsb)
838 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
839 TRACE("(%p,%p,%p)\n", This, psb, ppdsb);
840 return DirectSoundDevice_DuplicateSoundBuffer(This->device, psb, ppdsb);
843 static HRESULT WINAPI IDirectSound8Impl_SetCooperativeLevel(IDirectSound8 *iface, HWND hwnd,
844 DWORD level)
846 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
847 DirectSoundDevice *device = This->device;
848 HRESULT hr = S_OK;
850 TRACE("(%p,%p,%s)\n", This, hwnd, dumpCooperativeLevel(level));
852 if (!device) {
853 WARN("not initialized\n");
854 return DSERR_UNINITIALIZED;
857 if (level == DSSCL_PRIORITY || level == DSSCL_EXCLUSIVE) {
858 WARN("level=%s not fully supported\n",
859 level==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
862 RtlAcquireResourceExclusive(&device->buffer_list_lock, TRUE);
863 EnterCriticalSection(&device->mixlock);
864 if ((level == DSSCL_WRITEPRIMARY) != (device->priolevel == DSSCL_WRITEPRIMARY))
865 hr = DSOUND_ReopenDevice(device, level == DSSCL_WRITEPRIMARY);
866 if (SUCCEEDED(hr))
867 device->priolevel = level;
868 LeaveCriticalSection(&device->mixlock);
869 RtlReleaseResource(&device->buffer_list_lock);
870 return hr;
873 static HRESULT WINAPI IDirectSound8Impl_Compact(IDirectSound8 *iface)
875 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
877 TRACE("(%p)\n", This);
879 if (!This->device) {
880 WARN("not initialized\n");
881 return DSERR_UNINITIALIZED;
884 if (This->device->priolevel < DSSCL_PRIORITY) {
885 WARN("incorrect priority level\n");
886 return DSERR_PRIOLEVELNEEDED;
888 return DS_OK;
891 static HRESULT WINAPI IDirectSound8Impl_GetSpeakerConfig(IDirectSound8 *iface, DWORD *config)
893 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
895 TRACE("(%p, %p)\n", This, config);
897 if (!This->device) {
898 WARN("not initialized\n");
899 return DSERR_UNINITIALIZED;
901 if (!config) {
902 WARN("invalid parameter: config == NULL\n");
903 return DSERR_INVALIDPARAM;
906 WARN("not fully functional\n");
907 *config = This->device->speaker_config;
908 return DS_OK;
911 static HRESULT WINAPI IDirectSound8Impl_SetSpeakerConfig(IDirectSound8 *iface, DWORD config)
913 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
915 TRACE("(%p,0x%08x)\n", This, config);
917 if (!This->device) {
918 WARN("not initialized\n");
919 return DSERR_UNINITIALIZED;
922 /* NOP on Vista and above */
924 return DS_OK;
927 static HRESULT WINAPI IDirectSound8Impl_Initialize(IDirectSound8 *iface, const GUID *lpcGuid)
929 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
930 TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
931 return DirectSoundDevice_Initialize(&This->device, lpcGuid);
934 static HRESULT WINAPI IDirectSound8Impl_VerifyCertification(IDirectSound8 *iface, DWORD *certified)
936 IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
938 TRACE("(%p, %p)\n", This, certified);
940 if (!This->device) {
941 WARN("not initialized\n");
942 return DSERR_UNINITIALIZED;
945 if (This->device->drvcaps.dwFlags & DSCAPS_CERTIFIED)
946 *certified = DS_CERTIFIED;
947 else
948 *certified = DS_UNCERTIFIED;
950 return DS_OK;
953 static const IDirectSound8Vtbl ds8_vtbl =
955 IDirectSound8Impl_QueryInterface,
956 IDirectSound8Impl_AddRef,
957 IDirectSound8Impl_Release,
958 IDirectSound8Impl_CreateSoundBuffer,
959 IDirectSound8Impl_GetCaps,
960 IDirectSound8Impl_DuplicateSoundBuffer,
961 IDirectSound8Impl_SetCooperativeLevel,
962 IDirectSound8Impl_Compact,
963 IDirectSound8Impl_GetSpeakerConfig,
964 IDirectSound8Impl_SetSpeakerConfig,
965 IDirectSound8Impl_Initialize,
966 IDirectSound8Impl_VerifyCertification
969 HRESULT IDirectSoundImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_ds8)
971 IDirectSoundImpl *obj;
972 HRESULT hr;
974 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
976 *ppv = NULL;
977 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj));
978 if (!obj) {
979 WARN("out of memory\n");
980 return DSERR_OUTOFMEMORY;
983 setup_dsound_options();
985 obj->IUnknown_inner.lpVtbl = &unk_vtbl;
986 obj->IDirectSound8_iface.lpVtbl = &ds8_vtbl;
987 obj->ref = 1;
988 obj->refds = 0;
989 obj->numIfaces = 1;
990 obj->device = NULL;
991 obj->has_ds8 = has_ds8;
993 /* COM aggregation supported only internally */
994 if (outer_unk)
995 obj->outer_unk = outer_unk;
996 else
997 obj->outer_unk = &obj->IUnknown_inner;
999 hr = IUnknown_QueryInterface(&obj->IUnknown_inner, riid, ppv);
1000 IUnknown_Release(&obj->IUnknown_inner);
1002 return hr;
1005 HRESULT DSOUND_Create(REFIID riid, void **ppv)
1007 return IDirectSoundImpl_Create(NULL, riid, ppv, FALSE);
1010 HRESULT DSOUND_Create8(REFIID riid, void **ppv)
1012 return IDirectSoundImpl_Create(NULL, riid, ppv, TRUE);
1015 /*******************************************************************************
1016 * DirectSoundCreate (DSOUND.1)
1018 * Creates and initializes a DirectSound interface.
1020 * PARAMS
1021 * lpcGUID [I] Address of the GUID that identifies the sound device.
1022 * ppDS [O] Address of a variable to receive the interface pointer.
1023 * pUnkOuter [I] Must be NULL.
1025 * RETURNS
1026 * Success: DS_OK
1027 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1028 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1030 HRESULT WINAPI DirectSoundCreate(
1031 LPCGUID lpcGUID,
1032 LPDIRECTSOUND *ppDS,
1033 IUnknown *pUnkOuter)
1035 HRESULT hr;
1036 LPDIRECTSOUND pDS;
1038 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
1040 if (ppDS == NULL) {
1041 WARN("invalid parameter: ppDS == NULL\n");
1042 return DSERR_INVALIDPARAM;
1045 if (pUnkOuter != NULL) {
1046 WARN("invalid parameter: pUnkOuter != NULL\n");
1047 *ppDS = 0;
1048 return DSERR_INVALIDPARAM;
1051 hr = DSOUND_Create(&IID_IDirectSound, (void **)&pDS);
1052 if (hr == DS_OK) {
1053 hr = IDirectSound_Initialize(pDS, lpcGUID);
1054 if (hr != DS_OK) {
1055 if (hr != DSERR_ALREADYINITIALIZED) {
1056 IDirectSound_Release(pDS);
1057 pDS = 0;
1058 } else
1059 hr = DS_OK;
1063 *ppDS = pDS;
1065 return hr;
1068 /*******************************************************************************
1069 * DirectSoundCreate8 (DSOUND.11)
1071 * Creates and initializes a DirectSound8 interface.
1073 * PARAMS
1074 * lpcGUID [I] Address of the GUID that identifies the sound device.
1075 * ppDS [O] Address of a variable to receive the interface pointer.
1076 * pUnkOuter [I] Must be NULL.
1078 * RETURNS
1079 * Success: DS_OK
1080 * Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
1081 * DSERR_NODRIVER, DSERR_OUTOFMEMORY
1083 HRESULT WINAPI DirectSoundCreate8(
1084 LPCGUID lpcGUID,
1085 LPDIRECTSOUND8 *ppDS,
1086 IUnknown *pUnkOuter)
1088 HRESULT hr;
1089 LPDIRECTSOUND8 pDS;
1091 TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
1093 if (ppDS == NULL) {
1094 WARN("invalid parameter: ppDS == NULL\n");
1095 return DSERR_INVALIDPARAM;
1098 if (pUnkOuter != NULL) {
1099 WARN("invalid parameter: pUnkOuter != NULL\n");
1100 *ppDS = 0;
1101 return DSERR_INVALIDPARAM;
1104 hr = DSOUND_Create8(&IID_IDirectSound8, (void **)&pDS);
1105 if (hr == DS_OK) {
1106 hr = IDirectSound8_Initialize(pDS, lpcGUID);
1107 if (hr != DS_OK) {
1108 if (hr != DSERR_ALREADYINITIALIZED) {
1109 IDirectSound8_Release(pDS);
1110 pDS = 0;
1111 } else
1112 hr = DS_OK;
1116 *ppDS = pDS;
1118 return hr;
1121 void DSOUND_ParseSpeakerConfig(DirectSoundDevice *device)
1123 switch (DSSPEAKER_CONFIG(device->speaker_config)) {
1124 case DSSPEAKER_MONO:
1125 device->speaker_angles[0] = M_PI/180.0f * 0.0f;
1126 device->speaker_num[0] = 0;
1127 device->num_speakers = 1;
1128 device->lfe_channel = -1;
1129 break;
1131 case DSSPEAKER_STEREO:
1132 case DSSPEAKER_HEADPHONE:
1133 device->speaker_angles[0] = M_PI/180.0f * -90.0f;
1134 device->speaker_angles[1] = M_PI/180.0f * 90.0f;
1135 device->speaker_num[0] = 0; /* Left */
1136 device->speaker_num[1] = 1; /* Right */
1137 device->num_speakers = 2;
1138 device->lfe_channel = -1;
1139 break;
1141 case DSSPEAKER_QUAD:
1142 device->speaker_angles[0] = M_PI/180.0f * -135.0f;
1143 device->speaker_angles[1] = M_PI/180.0f * -45.0f;
1144 device->speaker_angles[2] = M_PI/180.0f * 45.0f;
1145 device->speaker_angles[3] = M_PI/180.0f * 135.0f;
1146 device->speaker_num[0] = 2; /* Rear left */
1147 device->speaker_num[1] = 0; /* Front left */
1148 device->speaker_num[2] = 1; /* Front right */
1149 device->speaker_num[3] = 3; /* Rear right */
1150 device->num_speakers = 4;
1151 device->lfe_channel = -1;
1152 break;
1154 case DSSPEAKER_5POINT1_BACK:
1155 device->speaker_angles[0] = M_PI/180.0f * -135.0f;
1156 device->speaker_angles[1] = M_PI/180.0f * -45.0f;
1157 device->speaker_angles[2] = M_PI/180.0f * 0.0f;
1158 device->speaker_angles[3] = M_PI/180.0f * 45.0f;
1159 device->speaker_angles[4] = M_PI/180.0f * 135.0f;
1160 device->speaker_angles[5] = 9999.0f;
1161 device->speaker_num[0] = 4; /* Rear left */
1162 device->speaker_num[1] = 0; /* Front left */
1163 device->speaker_num[2] = 2; /* Front centre */
1164 device->speaker_num[3] = 1; /* Front right */
1165 device->speaker_num[4] = 5; /* Rear right */
1166 device->speaker_num[5] = 3; /* LFE */
1167 device->num_speakers = 6;
1168 device->lfe_channel = 3;
1169 break;
1171 case DSSPEAKER_5POINT1_SURROUND:
1172 device->speaker_angles[0] = M_PI/180.0f * -90.0f;
1173 device->speaker_angles[1] = M_PI/180.0f * -30.0f;
1174 device->speaker_angles[2] = M_PI/180.0f * 0.0f;
1175 device->speaker_angles[3] = M_PI/180.0f * 30.0f;
1176 device->speaker_angles[4] = M_PI/180.0f * 90.0f;
1177 device->speaker_angles[5] = 9999.0f;
1178 device->speaker_num[0] = 4; /* Rear left */
1179 device->speaker_num[1] = 0; /* Front left */
1180 device->speaker_num[2] = 2; /* Front centre */
1181 device->speaker_num[3] = 1; /* Front right */
1182 device->speaker_num[4] = 5; /* Rear right */
1183 device->speaker_num[5] = 3; /* LFE */
1184 device->num_speakers = 6;
1185 device->lfe_channel = 3;
1186 break;
1188 default:
1189 WARN("unknown speaker_config %u\n", device->speaker_config);