3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2002 TransGaming Technologies, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * When PrimarySetFormat (via ReopenDevice or PrimaryOpen) fails,
23 * it leaves dsound in unusable (not really open) state.
29 #define NONAMELESSSTRUCT
30 #define NONAMELESSUNION
37 #include "wine/debug.h"
39 #include "dsound_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
43 static DWORD
DSOUND_fraglen(DirectSoundDevice
*device
)
45 REFERENCE_TIME period
;
49 hr
= IAudioClient_GetDevicePeriod(device
->client
, &period
, NULL
);
51 /* just guess at 10ms */
52 WARN("GetDevicePeriod failed: %08x\n", hr
);
53 ret
= MulDiv(device
->pwfx
->nBlockAlign
, device
->pwfx
->nSamplesPerSec
, 100);
55 ret
= MulDiv(device
->pwfx
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
, period
, 10000000);
57 ret
-= ret
% device
->pwfx
->nBlockAlign
;
61 static HRESULT
DSOUND_WaveFormat(DirectSoundDevice
*device
, IAudioClient
*client
,
62 BOOL forcewave
, WAVEFORMATEX
**wfx
)
64 WAVEFORMATEXTENSIBLE
*retwfe
= NULL
;
69 WAVEFORMATEXTENSIBLE
*mixwfe
;
70 hr
= IAudioClient_GetMixFormat(client
, (WAVEFORMATEX
**)&mixwfe
);
75 if (mixwfe
->Format
.nChannels
> 2) {
78 FIXME("Limiting channels to 2 due to lack of multichannel support\n");
80 mixwfe
->Format
.nChannels
= 2;
81 mixwfe
->Format
.nBlockAlign
= mixwfe
->Format
.nChannels
* mixwfe
->Format
.wBitsPerSample
/ 8;
82 mixwfe
->Format
.nAvgBytesPerSec
= mixwfe
->Format
.nSamplesPerSec
* mixwfe
->Format
.nBlockAlign
;
83 mixwfe
->dwChannelMask
= SPEAKER_FRONT_LEFT
| SPEAKER_FRONT_RIGHT
;
86 if (!IsEqualGUID(&mixwfe
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)) {
87 WAVEFORMATEXTENSIBLE testwfe
= *mixwfe
;
89 testwfe
.SubFormat
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
90 testwfe
.Samples
.wValidBitsPerSample
= testwfe
.Format
.wBitsPerSample
= 32;
91 testwfe
.Format
.nBlockAlign
= testwfe
.Format
.nChannels
* testwfe
.Format
.wBitsPerSample
/ 8;
92 testwfe
.Format
.nAvgBytesPerSec
= testwfe
.Format
.nSamplesPerSec
* testwfe
.Format
.nBlockAlign
;
94 if (FAILED(IAudioClient_IsFormatSupported(client
, AUDCLNT_SHAREMODE_SHARED
, &testwfe
.Format
, (WAVEFORMATEX
**)&retwfe
)))
95 w
= DSOUND_CopyFormat(&mixwfe
->Format
);
97 w
= DSOUND_CopyFormat(&retwfe
->Format
);
99 w
= DSOUND_CopyFormat(&testwfe
.Format
);
100 CoTaskMemFree(retwfe
);
103 w
= DSOUND_CopyFormat(&mixwfe
->Format
);
104 CoTaskMemFree(mixwfe
);
105 } else if (device
->primary_pwfx
->wFormatTag
== WAVE_FORMAT_PCM
||
106 device
->primary_pwfx
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
) {
107 WAVEFORMATEX
*wi
= device
->primary_pwfx
;
108 WAVEFORMATEXTENSIBLE
*wfe
;
110 /* Convert to WAVEFORMATEXTENSIBLE */
111 w
= HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEFORMATEXTENSIBLE
));
112 wfe
= (WAVEFORMATEXTENSIBLE
*)w
;
114 return DSERR_OUTOFMEMORY
;
117 w
->wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
118 w
->cbSize
= sizeof(*wfe
) - sizeof(*w
);
119 w
->nBlockAlign
= w
->nChannels
* w
->wBitsPerSample
/ 8;
120 w
->nAvgBytesPerSec
= w
->nSamplesPerSec
* w
->nBlockAlign
;
122 wfe
->dwChannelMask
= 0;
123 if (wi
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
) {
124 w
->wBitsPerSample
= 32;
125 wfe
->SubFormat
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
127 wfe
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
128 wfe
->Samples
.wValidBitsPerSample
= w
->wBitsPerSample
;
130 w
= DSOUND_CopyFormat(device
->primary_pwfx
);
133 return DSERR_OUTOFMEMORY
;
135 hr
= IAudioClient_IsFormatSupported(client
, AUDCLNT_SHAREMODE_SHARED
, w
, (WAVEFORMATEX
**)&retwfe
);
137 memcpy(w
, retwfe
, sizeof(WAVEFORMATEX
) + retwfe
->Format
.cbSize
);
138 CoTaskMemFree(retwfe
);
141 WARN("IsFormatSupported failed: %08x\n", hr
);
142 HeapFree(GetProcessHeap(), 0, w
);
149 HRESULT
DSOUND_ReopenDevice(DirectSoundDevice
*device
, BOOL forcewave
)
152 REFERENCE_TIME prebuf_rt
;
153 WAVEFORMATEX
*wfx
= NULL
;
155 REFERENCE_TIME period
;
158 TRACE("(%p, %d)\n", device
, forcewave
);
161 IAudioClient_Release(device
->client
);
162 device
->client
= NULL
;
165 IAudioRenderClient_Release(device
->render
);
166 device
->render
= NULL
;
169 IAudioClock_Release(device
->clock
);
170 device
->clock
= NULL
;
173 IAudioStreamVolume_Release(device
->volume
);
174 device
->volume
= NULL
;
177 hres
= IMMDevice_Activate(device
->mmdevice
, &IID_IAudioClient
,
178 CLSCTX_INPROC_SERVER
, NULL
, (void **)&device
->client
);
180 WARN("Activate failed: %08x\n", hres
);
184 hres
= DSOUND_WaveFormat(device
, device
->client
, forcewave
, &wfx
);
186 IAudioClient_Release(device
->client
);
187 device
->client
= NULL
;
190 HeapFree(GetProcessHeap(), 0, device
->pwfx
);
193 prebuf_frames
= device
->prebuf
* DSOUND_fraglen(device
) / device
->pwfx
->nBlockAlign
;
194 prebuf_rt
= (10000000 * (UINT64
)prebuf_frames
) / device
->pwfx
->nSamplesPerSec
;
196 hres
= IAudioClient_Initialize(device
->client
,
197 AUDCLNT_SHAREMODE_SHARED
, AUDCLNT_STREAMFLAGS_NOPERSIST
|
198 AUDCLNT_STREAMFLAGS_EVENTCALLBACK
, prebuf_rt
, 0, device
->pwfx
, NULL
);
200 IAudioClient_Release(device
->client
);
201 device
->client
= NULL
;
202 WARN("Initialize failed: %08x\n", hres
);
205 IAudioClient_SetEventHandle(device
->client
, device
->sleepev
);
207 hres
= IAudioClient_GetService(device
->client
, &IID_IAudioRenderClient
,
208 (void**)&device
->render
);
210 IAudioClient_Release(device
->client
);
211 device
->client
= NULL
;
212 WARN("GetService failed: %08x\n", hres
);
216 hres
= IAudioClient_GetService(device
->client
, &IID_IAudioClock
,
217 (void**)&device
->clock
);
219 IAudioClient_Release(device
->client
);
220 IAudioRenderClient_Release(device
->render
);
221 device
->client
= NULL
;
222 device
->render
= NULL
;
223 WARN("GetService failed: %08x\n", hres
);
227 hres
= IAudioClient_GetService(device
->client
, &IID_IAudioStreamVolume
,
228 (void**)&device
->volume
);
230 IAudioClient_Release(device
->client
);
231 IAudioRenderClient_Release(device
->render
);
232 IAudioClock_Release(device
->clock
);
233 device
->client
= NULL
;
234 device
->render
= NULL
;
235 device
->clock
= NULL
;
236 WARN("GetService failed: %08x\n", hres
);
240 /* Now kick off the timer so the event fires periodically */
241 hres
= IAudioClient_Start(device
->client
);
243 WARN("starting failed with %08x\n", hres
);
245 hres
= IAudioClient_GetStreamLatency(device
->client
, &period
);
247 WARN("GetStreamLatency failed with %08x\n", hres
);
250 period_ms
= (period
+ 9999) / 10000;
251 TRACE("period %u ms fraglen %u prebuf %u\n", period_ms
, device
->fraglen
, device
->prebuf
);
254 device
->sleeptime
= 5;
256 device
->sleeptime
= period_ms
* 5 / 2;
261 HRESULT
DSOUND_PrimaryOpen(DirectSoundDevice
*device
)
263 IDirectSoundBufferImpl
** dsb
= device
->buffers
;
267 TRACE("(%p)\n", device
);
269 device
->fraglen
= DSOUND_fraglen(device
);
271 /* on original windows, the buffer it set to a fixed size, no matter what the settings are.
272 on windows this size is always fixed (tested on win-xp) */
274 device
->buflen
= ds_hel_buflen
;
275 device
->buflen
-= device
->buflen
% device
->pwfx
->nBlockAlign
;
276 while(device
->buflen
< device
->fraglen
* device
->prebuf
){
277 device
->buflen
+= ds_hel_buflen
;
278 device
->buflen
-= device
->buflen
% device
->pwfx
->nBlockAlign
;
281 HeapFree(GetProcessHeap(), 0, device
->mix_buffer
);
282 device
->mix_buffer_len
= (device
->buflen
/ (device
->pwfx
->wBitsPerSample
/ 8)) * sizeof(float);
283 device
->mix_buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, device
->mix_buffer_len
);
284 if (!device
->mix_buffer
)
285 return DSERR_OUTOFMEMORY
;
287 if (device
->state
== STATE_PLAYING
) device
->state
= STATE_STARTING
;
288 else if (device
->state
== STATE_STOPPING
) device
->state
= STATE_STOPPED
;
290 /* reallocate emulated primary buffer */
292 newbuf
= HeapReAlloc(GetProcessHeap(),0,device
->buffer
, device
->buflen
);
294 newbuf
= HeapAlloc(GetProcessHeap(),0, device
->buflen
);
297 ERR("failed to allocate primary buffer\n");
298 return DSERR_OUTOFMEMORY
;
299 /* but the old buffer might still exist and must be re-prepared */
302 device
->writelead
= (device
->pwfx
->nSamplesPerSec
/ 100) * device
->pwfx
->nBlockAlign
;
304 device
->buffer
= newbuf
;
306 TRACE("buflen: %u, fraglen: %u, mix_buffer_len: %u\n",
307 device
->buflen
, device
->fraglen
, device
->mix_buffer_len
);
309 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
||
310 (device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
311 IsEqualGUID(&((WAVEFORMATEXTENSIBLE
*)device
->pwfx
)->SubFormat
,
312 &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)))
313 device
->normfunction
= normfunctions
[4];
315 device
->normfunction
= normfunctions
[device
->pwfx
->wBitsPerSample
/8 - 1];
317 FillMemory(device
->buffer
, device
->buflen
, (device
->pwfx
->wBitsPerSample
== 8) ? 128 : 0);
318 FillMemory(device
->mix_buffer
, device
->mix_buffer_len
, 0);
321 if (device
->pwfx
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
||
322 (device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
323 IsEqualGUID(&((WAVEFORMATEXTENSIBLE
*)device
->pwfx
)->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)))
324 device
->normfunction
= normfunctions
[4];
326 device
->normfunction
= normfunctions
[device
->pwfx
->wBitsPerSample
/8 - 1];
328 for (i
= 0; i
< device
->nrofbuffers
; i
++) {
329 RtlAcquireResourceExclusive(&dsb
[i
]->lock
, TRUE
);
330 DSOUND_RecalcFormat(dsb
[i
]);
331 RtlReleaseResource(&dsb
[i
]->lock
);
338 static void DSOUND_PrimaryClose(DirectSoundDevice
*device
)
342 TRACE("(%p)\n", device
);
345 hr
= IAudioClient_Stop(device
->client
);
347 WARN("Stop failed: %08x\n", hr
);
350 /* clear the queue */
351 device
->in_mmdev_bytes
= 0;
354 HRESULT
DSOUND_PrimaryCreate(DirectSoundDevice
*device
)
357 TRACE("(%p)\n", device
);
359 device
->buflen
= ds_hel_buflen
;
360 err
= DSOUND_PrimaryOpen(device
);
363 WARN("DSOUND_PrimaryOpen failed\n");
367 device
->state
= STATE_STOPPED
;
371 HRESULT
DSOUND_PrimaryDestroy(DirectSoundDevice
*device
)
373 TRACE("(%p)\n", device
);
376 EnterCriticalSection(&(device
->mixlock
));
378 DSOUND_PrimaryClose(device
);
380 if(device
->primary
&& (device
->primary
->ref
|| device
->primary
->numIfaces
))
381 WARN("Destroying primary buffer while references held (%u %u)\n", device
->primary
->ref
, device
->primary
->numIfaces
);
383 HeapFree(GetProcessHeap(), 0, device
->primary
);
384 device
->primary
= NULL
;
386 HeapFree(GetProcessHeap(),0,device
->primary_pwfx
);
387 HeapFree(GetProcessHeap(),0,device
->pwfx
);
390 LeaveCriticalSection(&(device
->mixlock
));
396 HRESULT
DSOUND_PrimaryPlay(DirectSoundDevice
*device
)
400 TRACE("(%p)\n", device
);
402 hr
= IAudioClient_Start(device
->client
);
403 if(FAILED(hr
) && hr
!= AUDCLNT_E_NOT_STOPPED
){
404 WARN("Start failed: %08x\n", hr
);
411 HRESULT
DSOUND_PrimaryStop(DirectSoundDevice
*device
)
415 TRACE("(%p)\n", device
);
417 hr
= IAudioClient_Stop(device
->client
);
419 WARN("Stop failed: %08x\n", hr
);
426 HRESULT
DSOUND_PrimaryGetPosition(DirectSoundDevice
*device
, LPDWORD playpos
, LPDWORD writepos
)
428 TRACE("(%p,%p,%p)\n", device
, playpos
, writepos
);
430 /* check if playpos was requested */
432 *playpos
= device
->playing_offs_bytes
;
434 /* check if writepos was requested */
436 /* the writepos is the first non-queued position */
437 *writepos
= (device
->playing_offs_bytes
+ device
->in_mmdev_bytes
) % device
->buflen
;
439 TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos
?*playpos
:-1, writepos
?*writepos
:-1, device
, GetTickCount());
443 WAVEFORMATEX
*DSOUND_CopyFormat(const WAVEFORMATEX
*wfex
)
446 if(wfex
->wFormatTag
== WAVE_FORMAT_PCM
){
447 pwfx
= HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEFORMATEX
));
448 CopyMemory(pwfx
, wfex
, sizeof(PCMWAVEFORMAT
));
451 pwfx
= HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEFORMATEX
) + wfex
->cbSize
);
452 CopyMemory(pwfx
, wfex
, sizeof(WAVEFORMATEX
) + wfex
->cbSize
);
455 if(pwfx
->wFormatTag
== WAVE_FORMAT_PCM
||
456 (pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
457 IsEqualGUID(&((const WAVEFORMATEXTENSIBLE
*)pwfx
)->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)))
458 pwfx
->nBlockAlign
= (pwfx
->nChannels
* pwfx
->wBitsPerSample
) / 8;
463 HRESULT
primarybuffer_SetFormat(DirectSoundDevice
*device
, LPCWAVEFORMATEX passed_fmt
)
466 WAVEFORMATEX
*old_fmt
;
467 WAVEFORMATEXTENSIBLE
*fmtex
, *passed_fmtex
= (WAVEFORMATEXTENSIBLE
*)passed_fmt
;
468 BOOL forced
= (device
->priolevel
== DSSCL_WRITEPRIMARY
);
470 TRACE("(%p,%p)\n", device
, passed_fmt
);
472 if (device
->priolevel
== DSSCL_NORMAL
) {
473 WARN("failed priority check!\n");
474 return DSERR_PRIOLEVELNEEDED
;
477 /* Let's be pedantic! */
478 if (passed_fmt
== NULL
) {
479 WARN("invalid parameter: passed_fmt==NULL!\n");
480 return DSERR_INVALIDPARAM
;
482 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
483 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
484 passed_fmt
->wFormatTag
, passed_fmt
->nChannels
, passed_fmt
->nSamplesPerSec
,
485 passed_fmt
->nAvgBytesPerSec
, passed_fmt
->nBlockAlign
,
486 passed_fmt
->wBitsPerSample
, passed_fmt
->cbSize
);
488 if(passed_fmt
->wBitsPerSample
< 8 || passed_fmt
->wBitsPerSample
% 8 != 0 ||
489 passed_fmt
->nChannels
== 0 || passed_fmt
->nSamplesPerSec
== 0 ||
490 passed_fmt
->nAvgBytesPerSec
== 0 ||
491 passed_fmt
->nBlockAlign
!= passed_fmt
->nChannels
* passed_fmt
->wBitsPerSample
/ 8)
492 return DSERR_INVALIDPARAM
;
494 if(passed_fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
495 if(passed_fmtex
->Samples
.wValidBitsPerSample
> passed_fmtex
->Format
.wBitsPerSample
)
496 return DSERR_INVALIDPARAM
;
500 RtlAcquireResourceExclusive(&(device
->buffer_list_lock
), TRUE
);
501 EnterCriticalSection(&(device
->mixlock
));
503 if (device
->priolevel
== DSSCL_WRITEPRIMARY
) {
504 old_fmt
= device
->primary_pwfx
;
505 device
->primary_pwfx
= DSOUND_CopyFormat(passed_fmt
);
506 fmtex
= (WAVEFORMATEXTENSIBLE
*)device
->primary_pwfx
;
507 if (device
->primary_pwfx
== NULL
) {
508 err
= DSERR_OUTOFMEMORY
;
512 if (fmtex
->Format
.wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
513 fmtex
->Samples
.wValidBitsPerSample
== 0) {
514 TRACE("Correcting 0 valid bits per sample\n");
515 fmtex
->Samples
.wValidBitsPerSample
= fmtex
->Format
.wBitsPerSample
;
518 DSOUND_PrimaryClose(device
);
520 err
= DSOUND_ReopenDevice(device
, forced
);
522 ERR("No formats could be opened\n");
526 err
= DSOUND_PrimaryOpen(device
);
528 ERR("DSOUND_PrimaryOpen failed\n");
534 device
->primary_pwfx
= old_fmt
;
536 HeapFree(GetProcessHeap(), 0, old_fmt
);
538 HeapFree(GetProcessHeap(), 0, device
->primary_pwfx
);
539 device
->primary_pwfx
= DSOUND_CopyFormat(passed_fmt
);
543 LeaveCriticalSection(&(device
->mixlock
));
544 RtlReleaseResource(&(device
->buffer_list_lock
));
550 /*******************************************************************************
553 static inline IDirectSoundBufferImpl
*impl_from_IDirectSoundBuffer(IDirectSoundBuffer
*iface
)
555 /* IDirectSoundBuffer and IDirectSoundBuffer8 use the same iface. */
556 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSoundBuffer8_iface
);
559 /* This sets this format for the primary buffer only */
560 static HRESULT WINAPI
PrimaryBufferImpl_SetFormat(IDirectSoundBuffer
*iface
,
561 const WAVEFORMATEX
*wfex
)
563 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
564 TRACE("(%p,%p)\n", iface
, wfex
);
565 return primarybuffer_SetFormat(This
->device
, wfex
);
568 static HRESULT WINAPI
PrimaryBufferImpl_SetVolume(IDirectSoundBuffer
*iface
, LONG vol
)
570 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
571 DirectSoundDevice
*device
= This
->device
;
575 TRACE("(%p,%d)\n", iface
, vol
);
577 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
578 WARN("control unavailable\n");
579 return DSERR_CONTROLUNAVAIL
;
582 if ((vol
> DSBVOLUME_MAX
) || (vol
< DSBVOLUME_MIN
)) {
583 WARN("invalid parameter: vol = %d\n", vol
);
584 return DSERR_INVALIDPARAM
;
588 EnterCriticalSection(&device
->mixlock
);
590 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 0, &lvol
);
592 LeaveCriticalSection(&device
->mixlock
);
593 WARN("GetChannelVolume failed: %08x\n", hr
);
597 if(device
->pwfx
->nChannels
> 1){
598 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 1, &rvol
);
600 LeaveCriticalSection(&device
->mixlock
);
601 WARN("GetChannelVolume failed: %08x\n", hr
);
607 device
->volpan
.dwTotalLeftAmpFactor
= ((UINT16
)(lvol
* (DWORD
)0xFFFF));
608 device
->volpan
.dwTotalRightAmpFactor
= ((UINT16
)(rvol
* (DWORD
)0xFFFF));
610 DSOUND_AmpFactorToVolPan(&device
->volpan
);
611 if (vol
!= device
->volpan
.lVolume
) {
612 device
->volpan
.lVolume
=vol
;
613 DSOUND_RecalcVolPan(&device
->volpan
);
614 lvol
= (float)((DWORD
)(device
->volpan
.dwTotalLeftAmpFactor
& 0xFFFF) / (float)0xFFFF);
615 hr
= IAudioStreamVolume_SetChannelVolume(device
->volume
, 0, lvol
);
617 LeaveCriticalSection(&device
->mixlock
);
618 WARN("SetChannelVolume failed: %08x\n", hr
);
622 if(device
->pwfx
->nChannels
> 1){
623 rvol
= (float)((DWORD
)(device
->volpan
.dwTotalRightAmpFactor
& 0xFFFF) / (float)0xFFFF);
624 hr
= IAudioStreamVolume_SetChannelVolume(device
->volume
, 1, rvol
);
626 LeaveCriticalSection(&device
->mixlock
);
627 WARN("SetChannelVolume failed: %08x\n", hr
);
633 LeaveCriticalSection(&(device
->mixlock
));
639 static HRESULT WINAPI
PrimaryBufferImpl_GetVolume(IDirectSoundBuffer
*iface
, LONG
*vol
)
641 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
642 DirectSoundDevice
*device
= This
->device
;
645 TRACE("(%p,%p)\n", iface
, vol
);
647 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
648 WARN("control unavailable\n");
649 return DSERR_CONTROLUNAVAIL
;
653 WARN("invalid parameter: vol = NULL\n");
654 return DSERR_INVALIDPARAM
;
657 EnterCriticalSection(&device
->mixlock
);
659 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 0, &lvol
);
661 LeaveCriticalSection(&device
->mixlock
);
662 WARN("GetChannelVolume failed: %08x\n", hr
);
666 if(device
->pwfx
->nChannels
> 1){
667 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 1, &rvol
);
669 LeaveCriticalSection(&device
->mixlock
);
670 WARN("GetChannelVolume failed: %08x\n", hr
);
676 device
->volpan
.dwTotalLeftAmpFactor
= ((UINT16
)(lvol
* (DWORD
)0xFFFF));
677 device
->volpan
.dwTotalRightAmpFactor
= ((UINT16
)(rvol
* (DWORD
)0xFFFF));
679 DSOUND_AmpFactorToVolPan(&device
->volpan
);
680 *vol
= device
->volpan
.lVolume
;
682 LeaveCriticalSection(&device
->mixlock
);
687 static HRESULT WINAPI
PrimaryBufferImpl_SetFrequency(IDirectSoundBuffer
*iface
, DWORD freq
)
689 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
690 TRACE("(%p,%d)\n",This
,freq
);
692 /* You cannot set the frequency of the primary buffer */
693 WARN("control unavailable\n");
694 return DSERR_CONTROLUNAVAIL
;
697 static HRESULT WINAPI
PrimaryBufferImpl_Play(IDirectSoundBuffer
*iface
, DWORD reserved1
,
698 DWORD reserved2
, DWORD flags
)
700 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
701 DirectSoundDevice
*device
= This
->device
;
702 TRACE("(%p,%08x,%08x,%08x)\n", iface
, reserved1
, reserved2
, flags
);
704 if (!(flags
& DSBPLAY_LOOPING
)) {
705 WARN("invalid parameter: flags = %08x\n", flags
);
706 return DSERR_INVALIDPARAM
;
710 EnterCriticalSection(&(device
->mixlock
));
712 if (device
->state
== STATE_STOPPED
)
713 device
->state
= STATE_STARTING
;
714 else if (device
->state
== STATE_STOPPING
)
715 device
->state
= STATE_PLAYING
;
717 LeaveCriticalSection(&(device
->mixlock
));
723 static HRESULT WINAPI
PrimaryBufferImpl_Stop(IDirectSoundBuffer
*iface
)
725 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
726 DirectSoundDevice
*device
= This
->device
;
727 TRACE("(%p)\n", iface
);
730 EnterCriticalSection(&(device
->mixlock
));
732 if (device
->state
== STATE_PLAYING
)
733 device
->state
= STATE_STOPPING
;
734 else if (device
->state
== STATE_STARTING
)
735 device
->state
= STATE_STOPPED
;
737 LeaveCriticalSection(&(device
->mixlock
));
743 static ULONG WINAPI
PrimaryBufferImpl_AddRef(IDirectSoundBuffer
*iface
)
745 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
746 ULONG ref
= InterlockedIncrement(&(This
->ref
));
747 TRACE("(%p) ref was %d\n", This
, ref
- 1);
749 InterlockedIncrement(&This
->numIfaces
);
753 /* Decreases *out by 1 to no less than 0.
754 * Returns the new value of *out. */
755 LONG
capped_refcount_dec(LONG
*out
)
762 oldref
= InterlockedCompareExchange(out
, ref
- 1, ref
);
763 } while(oldref
!= ref
);
767 static ULONG WINAPI
PrimaryBufferImpl_Release(IDirectSoundBuffer
*iface
)
769 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
772 ref
= capped_refcount_dec(&This
->ref
);
774 capped_refcount_dec(&This
->numIfaces
);
776 TRACE("(%p) primary ref is now %d\n", This
, ref
);
781 static HRESULT WINAPI
PrimaryBufferImpl_GetCurrentPosition(IDirectSoundBuffer
*iface
,
782 DWORD
*playpos
, DWORD
*writepos
)
785 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
786 DirectSoundDevice
*device
= This
->device
;
787 TRACE("(%p,%p,%p)\n", iface
, playpos
, writepos
);
790 EnterCriticalSection(&(device
->mixlock
));
792 hres
= DSOUND_PrimaryGetPosition(device
, playpos
, writepos
);
794 WARN("DSOUND_PrimaryGetPosition failed\n");
795 LeaveCriticalSection(&(device
->mixlock
));
799 if (device
->state
!= STATE_STOPPED
)
800 /* apply the documented 10ms lead to writepos */
801 *writepos
+= device
->writelead
;
802 while (*writepos
>= device
->buflen
) *writepos
-= device
->buflen
;
805 LeaveCriticalSection(&(device
->mixlock
));
808 TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos
?*playpos
:0, writepos
?*writepos
:0, device
, GetTickCount());
812 static HRESULT WINAPI
PrimaryBufferImpl_GetStatus(IDirectSoundBuffer
*iface
, DWORD
*status
)
814 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
815 DirectSoundDevice
*device
= This
->device
;
816 TRACE("(%p,%p)\n", iface
, status
);
818 if (status
== NULL
) {
819 WARN("invalid parameter: status == NULL\n");
820 return DSERR_INVALIDPARAM
;
824 if ((device
->state
== STATE_STARTING
) ||
825 (device
->state
== STATE_PLAYING
))
826 *status
|= DSBSTATUS_PLAYING
| DSBSTATUS_LOOPING
;
828 TRACE("status=%x\n", *status
);
833 static HRESULT WINAPI
PrimaryBufferImpl_GetFormat(IDirectSoundBuffer
*iface
, WAVEFORMATEX
*lpwf
,
834 DWORD wfsize
, DWORD
*wfwritten
)
837 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
838 DirectSoundDevice
*device
= This
->device
;
839 TRACE("(%p,%p,%d,%p)\n", iface
, lpwf
, wfsize
, wfwritten
);
841 size
= sizeof(WAVEFORMATEX
) + device
->primary_pwfx
->cbSize
;
843 if (lpwf
) { /* NULL is valid */
844 if (wfsize
>= size
) {
845 CopyMemory(lpwf
,device
->primary_pwfx
,size
);
849 WARN("invalid parameter: wfsize too small\n");
852 return DSERR_INVALIDPARAM
;
856 *wfwritten
= sizeof(WAVEFORMATEX
) + device
->primary_pwfx
->cbSize
;
858 WARN("invalid parameter: wfwritten == NULL\n");
859 return DSERR_INVALIDPARAM
;
866 static HRESULT WINAPI
PrimaryBufferImpl_Lock(IDirectSoundBuffer
*iface
, DWORD writecursor
,
867 DWORD writebytes
, void **lplpaudioptr1
, DWORD
*audiobytes1
, void **lplpaudioptr2
,
868 DWORD
*audiobytes2
, DWORD flags
)
871 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
872 DirectSoundDevice
*device
= This
->device
;
873 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n",
886 return DSERR_INVALIDPARAM
;
888 if (device
->priolevel
!= DSSCL_WRITEPRIMARY
) {
889 WARN("failed priority check!\n");
890 return DSERR_PRIOLEVELNEEDED
;
893 /* when this flag is set, writecursor is meaningless and must be calculated */
894 if (flags
& DSBLOCK_FROMWRITECURSOR
) {
895 /* GetCurrentPosition does too much magic to duplicate here */
896 hres
= IDirectSoundBuffer_GetCurrentPosition(iface
, NULL
, &writecursor
);
898 WARN("IDirectSoundBuffer_GetCurrentPosition failed\n");
903 /* when this flag is set, writebytes is meaningless and must be set */
904 if (flags
& DSBLOCK_ENTIREBUFFER
)
905 writebytes
= device
->buflen
;
907 if (writecursor
>= device
->buflen
) {
908 WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
909 writecursor
, device
->buflen
);
910 return DSERR_INVALIDPARAM
;
913 if (writebytes
> device
->buflen
) {
914 WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
915 writebytes
, device
->buflen
);
916 return DSERR_INVALIDPARAM
;
919 if (writecursor
+writebytes
<= device
->buflen
) {
920 *(LPBYTE
*)lplpaudioptr1
= device
->buffer
+writecursor
;
921 *audiobytes1
= writebytes
;
923 *(LPBYTE
*)lplpaudioptr2
= NULL
;
926 TRACE("->%d.0\n",writebytes
);
928 *(LPBYTE
*)lplpaudioptr1
= device
->buffer
+writecursor
;
929 *audiobytes1
= device
->buflen
-writecursor
;
931 *(LPBYTE
*)lplpaudioptr2
= device
->buffer
;
933 *audiobytes2
= writebytes
-(device
->buflen
-writecursor
);
934 TRACE("->%d.%d\n",*audiobytes1
,audiobytes2
?*audiobytes2
:0);
939 static HRESULT WINAPI
PrimaryBufferImpl_SetCurrentPosition(IDirectSoundBuffer
*iface
, DWORD newpos
)
941 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
942 TRACE("(%p,%d)\n",This
,newpos
);
944 /* You cannot set the position of the primary buffer */
945 WARN("invalid call\n");
946 return DSERR_INVALIDCALL
;
949 static HRESULT WINAPI
PrimaryBufferImpl_SetPan(IDirectSoundBuffer
*iface
, LONG pan
)
951 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
952 DirectSoundDevice
*device
= This
->device
;
955 TRACE("(%p,%d)\n", iface
, pan
);
957 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
958 WARN("control unavailable\n");
959 return DSERR_CONTROLUNAVAIL
;
962 if ((pan
> DSBPAN_RIGHT
) || (pan
< DSBPAN_LEFT
)) {
963 WARN("invalid parameter: pan = %d\n", pan
);
964 return DSERR_INVALIDPARAM
;
968 EnterCriticalSection(&device
->mixlock
);
970 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 0, &lvol
);
972 LeaveCriticalSection(&device
->mixlock
);
973 WARN("GetChannelVolume failed: %08x\n", hr
);
977 if(device
->pwfx
->nChannels
> 1){
978 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 1, &rvol
);
980 LeaveCriticalSection(&device
->mixlock
);
981 WARN("GetChannelVolume failed: %08x\n", hr
);
987 device
->volpan
.dwTotalLeftAmpFactor
= ((UINT16
)(lvol
* (DWORD
)0xFFFF));
988 device
->volpan
.dwTotalRightAmpFactor
= ((UINT16
)(rvol
* (DWORD
)0xFFFF));
990 DSOUND_AmpFactorToVolPan(&device
->volpan
);
991 if (pan
!= device
->volpan
.lPan
) {
992 device
->volpan
.lPan
=pan
;
993 DSOUND_RecalcVolPan(&device
->volpan
);
995 lvol
= (float)((DWORD
)(device
->volpan
.dwTotalLeftAmpFactor
& 0xFFFF) / (float)0xFFFF);
996 hr
= IAudioStreamVolume_SetChannelVolume(device
->volume
, 0, lvol
);
998 LeaveCriticalSection(&device
->mixlock
);
999 WARN("SetChannelVolume failed: %08x\n", hr
);
1003 if(device
->pwfx
->nChannels
> 1){
1004 rvol
= (float)((DWORD
)(device
->volpan
.dwTotalRightAmpFactor
& 0xFFFF) / (float)0xFFFF);
1005 hr
= IAudioStreamVolume_SetChannelVolume(device
->volume
, 1, rvol
);
1007 LeaveCriticalSection(&device
->mixlock
);
1008 WARN("SetChannelVolume failed: %08x\n", hr
);
1014 LeaveCriticalSection(&device
->mixlock
);
1020 static HRESULT WINAPI
PrimaryBufferImpl_GetPan(IDirectSoundBuffer
*iface
, LONG
*pan
)
1022 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1023 DirectSoundDevice
*device
= This
->device
;
1026 TRACE("(%p,%p)\n", iface
, pan
);
1028 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
1029 WARN("control unavailable\n");
1030 return DSERR_CONTROLUNAVAIL
;
1034 WARN("invalid parameter: pan == NULL\n");
1035 return DSERR_INVALIDPARAM
;
1038 EnterCriticalSection(&device
->mixlock
);
1040 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 0, &lvol
);
1042 LeaveCriticalSection(&device
->mixlock
);
1043 WARN("GetChannelVolume failed: %08x\n", hr
);
1047 if(device
->pwfx
->nChannels
> 1){
1048 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 1, &rvol
);
1050 LeaveCriticalSection(&device
->mixlock
);
1051 WARN("GetChannelVolume failed: %08x\n", hr
);
1057 device
->volpan
.dwTotalLeftAmpFactor
= ((UINT16
)(lvol
* (DWORD
)0xFFFF));
1058 device
->volpan
.dwTotalRightAmpFactor
= ((UINT16
)(rvol
* (DWORD
)0xFFFF));
1060 DSOUND_AmpFactorToVolPan(&device
->volpan
);
1061 *pan
= device
->volpan
.lPan
;
1063 LeaveCriticalSection(&device
->mixlock
);
1068 static HRESULT WINAPI
PrimaryBufferImpl_Unlock(IDirectSoundBuffer
*iface
, void *p1
, DWORD x1
,
1071 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1072 DirectSoundDevice
*device
= This
->device
;
1073 TRACE("(%p,%p,%d,%p,%d)\n", iface
, p1
, x1
, p2
, x2
);
1075 if (device
->priolevel
!= DSSCL_WRITEPRIMARY
) {
1076 WARN("failed priority check!\n");
1077 return DSERR_PRIOLEVELNEEDED
;
1080 if ((p1
&& ((BYTE
*)p1
< device
->buffer
|| (BYTE
*)p1
>= device
->buffer
+ device
->buflen
)) ||
1081 (p2
&& ((BYTE
*)p2
< device
->buffer
|| (BYTE
*)p2
>= device
->buffer
+ device
->buflen
)))
1082 return DSERR_INVALIDPARAM
;
1087 static HRESULT WINAPI
PrimaryBufferImpl_Restore(IDirectSoundBuffer
*iface
)
1089 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1090 FIXME("(%p):stub\n",This
);
1094 static HRESULT WINAPI
PrimaryBufferImpl_GetFrequency(IDirectSoundBuffer
*iface
, DWORD
*freq
)
1096 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1097 DirectSoundDevice
*device
= This
->device
;
1098 TRACE("(%p,%p)\n", iface
, freq
);
1101 WARN("invalid parameter: freq == NULL\n");
1102 return DSERR_INVALIDPARAM
;
1105 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLFREQUENCY
)) {
1106 WARN("control unavailable\n");
1107 return DSERR_CONTROLUNAVAIL
;
1110 *freq
= device
->pwfx
->nSamplesPerSec
;
1111 TRACE("-> %d\n", *freq
);
1116 static HRESULT WINAPI
PrimaryBufferImpl_Initialize(IDirectSoundBuffer
*iface
, IDirectSound
*dsound
,
1117 const DSBUFFERDESC
*dbsd
)
1119 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1120 WARN("(%p) already initialized\n", This
);
1121 return DSERR_ALREADYINITIALIZED
;
1124 static HRESULT WINAPI
PrimaryBufferImpl_GetCaps(IDirectSoundBuffer
*iface
, DSBCAPS
*caps
)
1126 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1127 DirectSoundDevice
*device
= This
->device
;
1128 TRACE("(%p,%p)\n", iface
, caps
);
1131 WARN("invalid parameter: caps == NULL\n");
1132 return DSERR_INVALIDPARAM
;
1135 if (caps
->dwSize
< sizeof(*caps
)) {
1136 WARN("invalid parameter: caps->dwSize = %d\n", caps
->dwSize
);
1137 return DSERR_INVALIDPARAM
;
1140 caps
->dwFlags
= This
->dsbd
.dwFlags
;
1141 caps
->dwBufferBytes
= device
->buflen
;
1143 /* Windows reports these as zero */
1144 caps
->dwUnlockTransferRate
= 0;
1145 caps
->dwPlayCpuOverhead
= 0;
1150 static HRESULT WINAPI
PrimaryBufferImpl_QueryInterface(IDirectSoundBuffer
*iface
, REFIID riid
,
1153 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1155 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(riid
), ppobj
);
1157 if (ppobj
== NULL
) {
1158 WARN("invalid parameter\n");
1159 return E_INVALIDARG
;
1162 *ppobj
= NULL
; /* assume failure */
1164 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
1165 IsEqualGUID(riid
, &IID_IDirectSoundBuffer
) ) {
1166 IDirectSoundBuffer_AddRef(iface
);
1171 /* DirectSoundBuffer and DirectSoundBuffer8 are different and */
1172 /* a primary buffer can't have a DirectSoundBuffer8 interface */
1173 if ( IsEqualGUID( &IID_IDirectSoundBuffer8
, riid
) ) {
1174 WARN("app requested DirectSoundBuffer8 on primary buffer\n");
1175 return E_NOINTERFACE
;
1178 if ( IsEqualGUID( &IID_IDirectSoundNotify
, riid
) ) {
1179 ERR("app requested IDirectSoundNotify on primary buffer\n");
1180 /* FIXME: should we support this? */
1181 return E_NOINTERFACE
;
1184 if ( IsEqualGUID( &IID_IDirectSound3DBuffer
, riid
) ) {
1185 ERR("app requested IDirectSound3DBuffer on primary buffer\n");
1186 return E_NOINTERFACE
;
1189 if ( IsEqualGUID( &IID_IDirectSound3DListener
, riid
) ) {
1190 *ppobj
= &This
->IDirectSound3DListener_iface
;
1191 IDirectSound3DListener_AddRef(&This
->IDirectSound3DListener_iface
);
1195 if ( IsEqualGUID( &IID_IKsPropertySet
, riid
) ) {
1196 *ppobj
= &This
->IKsPropertySet_iface
;
1197 IKsPropertySet_AddRef(&This
->IKsPropertySet_iface
);
1201 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
1202 return E_NOINTERFACE
;
1205 static const IDirectSoundBufferVtbl dspbvt
=
1207 PrimaryBufferImpl_QueryInterface
,
1208 PrimaryBufferImpl_AddRef
,
1209 PrimaryBufferImpl_Release
,
1210 PrimaryBufferImpl_GetCaps
,
1211 PrimaryBufferImpl_GetCurrentPosition
,
1212 PrimaryBufferImpl_GetFormat
,
1213 PrimaryBufferImpl_GetVolume
,
1214 PrimaryBufferImpl_GetPan
,
1215 PrimaryBufferImpl_GetFrequency
,
1216 PrimaryBufferImpl_GetStatus
,
1217 PrimaryBufferImpl_Initialize
,
1218 PrimaryBufferImpl_Lock
,
1219 PrimaryBufferImpl_Play
,
1220 PrimaryBufferImpl_SetCurrentPosition
,
1221 PrimaryBufferImpl_SetFormat
,
1222 PrimaryBufferImpl_SetVolume
,
1223 PrimaryBufferImpl_SetPan
,
1224 PrimaryBufferImpl_SetFrequency
,
1225 PrimaryBufferImpl_Stop
,
1226 PrimaryBufferImpl_Unlock
,
1227 PrimaryBufferImpl_Restore
1230 HRESULT
primarybuffer_create(DirectSoundDevice
*device
, IDirectSoundBufferImpl
**ppdsb
,
1231 const DSBUFFERDESC
*dsbd
)
1233 IDirectSoundBufferImpl
*dsb
;
1234 TRACE("%p,%p,%p)\n",device
,ppdsb
,dsbd
);
1236 if (dsbd
->lpwfxFormat
) {
1237 WARN("invalid parameter: dsbd->lpwfxFormat != NULL\n");
1239 return DSERR_INVALIDPARAM
;
1242 dsb
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(*dsb
));
1245 WARN("out of memory\n");
1247 return DSERR_OUTOFMEMORY
;
1254 dsb
->device
= device
;
1255 dsb
->IDirectSoundBuffer8_iface
.lpVtbl
= (IDirectSoundBuffer8Vtbl
*)&dspbvt
;
1256 dsb
->IDirectSound3DListener_iface
.lpVtbl
= &ds3dlvt
;
1257 dsb
->IKsPropertySet_iface
.lpVtbl
= &iksbvt
;
1260 /* IDirectSound3DListener */
1261 device
->ds3dl
.dwSize
= sizeof(DS3DLISTENER
);
1262 device
->ds3dl
.vPosition
.x
= 0.0;
1263 device
->ds3dl
.vPosition
.y
= 0.0;
1264 device
->ds3dl
.vPosition
.z
= 0.0;
1265 device
->ds3dl
.vVelocity
.x
= 0.0;
1266 device
->ds3dl
.vVelocity
.y
= 0.0;
1267 device
->ds3dl
.vVelocity
.z
= 0.0;
1268 device
->ds3dl
.vOrientFront
.x
= 0.0;
1269 device
->ds3dl
.vOrientFront
.y
= 0.0;
1270 device
->ds3dl
.vOrientFront
.z
= 1.0;
1271 device
->ds3dl
.vOrientTop
.x
= 0.0;
1272 device
->ds3dl
.vOrientTop
.y
= 1.0;
1273 device
->ds3dl
.vOrientTop
.z
= 0.0;
1274 device
->ds3dl
.flDistanceFactor
= DS3D_DEFAULTDISTANCEFACTOR
;
1275 device
->ds3dl
.flRolloffFactor
= DS3D_DEFAULTROLLOFFFACTOR
;
1276 device
->ds3dl
.flDopplerFactor
= DS3D_DEFAULTDOPPLERFACTOR
;
1277 device
->ds3dl_need_recalc
= TRUE
;
1279 TRACE("Created primary buffer at %p\n", dsb
);
1280 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
1281 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
1282 device
->pwfx
->wFormatTag
, device
->pwfx
->nChannels
,
1283 device
->pwfx
->nSamplesPerSec
, device
->pwfx
->nAvgBytesPerSec
,
1284 device
->pwfx
->nBlockAlign
, device
->pwfx
->wBitsPerSample
,
1285 device
->pwfx
->cbSize
);
1287 IDirectSoundBuffer_AddRef(&dsb
->IDirectSoundBuffer8_iface
);