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 HRESULT
DSOUND_ReopenDevice(DirectSoundDevice
*device
, BOOL forcewave
)
64 REFERENCE_TIME prebuf_rt
;
67 TRACE("(%p, %d)\n", device
, forcewave
);
70 IAudioClient_Release(device
->client
);
71 device
->client
= NULL
;
74 IAudioRenderClient_Release(device
->render
);
75 device
->render
= NULL
;
78 IAudioClock_Release(device
->clock
);
82 IAudioStreamVolume_Release(device
->volume
);
83 device
->volume
= NULL
;
86 hres
= IMMDevice_Activate(device
->mmdevice
, &IID_IAudioClient
,
87 CLSCTX_INPROC_SERVER
, NULL
, (void **)&device
->client
);
89 WARN("Activate failed: %08x\n", hres
);
93 prebuf_frames
= device
->prebuf
* DSOUND_fraglen(device
) / device
->pwfx
->nBlockAlign
;
94 prebuf_rt
= (10000000 * (UINT64
)prebuf_frames
) / device
->pwfx
->nSamplesPerSec
;
96 hres
= IAudioClient_Initialize(device
->client
,
97 AUDCLNT_SHAREMODE_SHARED
, AUDCLNT_STREAMFLAGS_NOPERSIST
,
98 prebuf_rt
, 0, device
->pwfx
, NULL
);
100 IAudioClient_Release(device
->client
);
101 device
->client
= NULL
;
102 WARN("Initialize failed: %08x\n", hres
);
106 hres
= IAudioClient_GetService(device
->client
, &IID_IAudioRenderClient
,
107 (void**)&device
->render
);
109 IAudioClient_Release(device
->client
);
110 device
->client
= NULL
;
111 WARN("GetService failed: %08x\n", hres
);
115 hres
= IAudioClient_GetService(device
->client
, &IID_IAudioClock
,
116 (void**)&device
->clock
);
118 IAudioClient_Release(device
->client
);
119 IAudioRenderClient_Release(device
->render
);
120 device
->client
= NULL
;
121 device
->render
= NULL
;
122 WARN("GetService failed: %08x\n", hres
);
126 hres
= IAudioClient_GetService(device
->client
, &IID_IAudioStreamVolume
,
127 (void**)&device
->volume
);
129 IAudioClient_Release(device
->client
);
130 IAudioRenderClient_Release(device
->render
);
131 IAudioClock_Release(device
->clock
);
132 device
->client
= NULL
;
133 device
->render
= NULL
;
134 device
->clock
= NULL
;
135 WARN("GetService failed: %08x\n", hres
);
142 static HRESULT
DSOUND_PrimaryOpen(DirectSoundDevice
*device
)
146 TRACE("(%p)\n", device
);
148 device
->fraglen
= DSOUND_fraglen(device
);
150 /* on original windows, the buffer it set to a fixed size, no matter what the settings are.
151 on windows this size is always fixed (tested on win-xp) */
153 device
->buflen
= ds_hel_buflen
;
154 device
->buflen
-= device
->buflen
% device
->pwfx
->nBlockAlign
;
155 while(device
->buflen
< device
->fraglen
* device
->prebuf
){
156 device
->buflen
+= ds_hel_buflen
;
157 device
->buflen
-= device
->buflen
% device
->pwfx
->nBlockAlign
;
160 device
->helfrags
= device
->buflen
/ device
->fraglen
;
162 device
->mix_buffer_len
= DSOUND_bufpos_to_mixpos(device
, device
->buflen
);
163 device
->mix_buffer
= HeapAlloc(GetProcessHeap(), 0, device
->mix_buffer_len
);
164 if (!device
->mix_buffer
)
165 return DSERR_OUTOFMEMORY
;
167 if (device
->state
== STATE_PLAYING
) device
->state
= STATE_STARTING
;
168 else if (device
->state
== STATE_STOPPING
) device
->state
= STATE_STOPPED
;
170 /* reallocate emulated primary buffer */
172 newbuf
= HeapReAlloc(GetProcessHeap(),0,device
->buffer
, device
->buflen
);
174 newbuf
= HeapAlloc(GetProcessHeap(),0, device
->buflen
);
177 ERR("failed to allocate primary buffer\n");
178 return DSERR_OUTOFMEMORY
;
179 /* but the old buffer might still exist and must be re-prepared */
182 device
->writelead
= (device
->pwfx
->nSamplesPerSec
/ 100) * device
->pwfx
->nBlockAlign
;
184 device
->buffer
= newbuf
;
186 TRACE("buflen: %u, fraglen: %u, helfrags: %u, mix_buffer_len: %u\n",
187 device
->buflen
, device
->fraglen
, device
->helfrags
, device
->mix_buffer_len
);
189 device
->mixfunction
= mixfunctions
[device
->pwfx
->wBitsPerSample
/8 - 1];
190 device
->normfunction
= normfunctions
[device
->pwfx
->wBitsPerSample
/8 - 1];
191 FillMemory(device
->buffer
, device
->buflen
, (device
->pwfx
->wBitsPerSample
== 8) ? 128 : 0);
192 FillMemory(device
->mix_buffer
, device
->mix_buffer_len
, 0);
193 device
->last_pos_bytes
= device
->playing_offs_bytes
= device
->in_mmdev_bytes
= device
->playpos
= device
->mixpos
= 0;
198 static void DSOUND_PrimaryClose(DirectSoundDevice
*device
)
202 TRACE("(%p)\n", device
);
205 hr
= IAudioClient_Stop(device
->client
);
207 WARN("Stop failed: %08x\n", hr
);
210 /* clear the queue */
211 device
->in_mmdev_bytes
= 0;
214 HRESULT
DSOUND_PrimaryCreate(DirectSoundDevice
*device
)
217 TRACE("(%p)\n", device
);
219 device
->buflen
= ds_hel_buflen
;
220 err
= DSOUND_PrimaryOpen(device
);
223 WARN("DSOUND_PrimaryOpen failed\n");
227 device
->state
= STATE_STOPPED
;
231 HRESULT
DSOUND_PrimaryDestroy(DirectSoundDevice
*device
)
233 TRACE("(%p)\n", device
);
236 EnterCriticalSection(&(device
->mixlock
));
238 DSOUND_PrimaryClose(device
);
240 if(device
->primary
&& (device
->primary
->ref
|| device
->primary
->numIfaces
))
241 WARN("Destroying primary buffer while references held (%u %u)\n", device
->primary
->ref
, device
->primary
->numIfaces
);
243 HeapFree(GetProcessHeap(), 0, device
->primary
);
244 device
->primary
= NULL
;
246 HeapFree(GetProcessHeap(),0,device
->pwfx
);
249 LeaveCriticalSection(&(device
->mixlock
));
255 HRESULT
DSOUND_PrimaryPlay(DirectSoundDevice
*device
)
259 TRACE("(%p)\n", device
);
261 hr
= IAudioClient_Start(device
->client
);
263 WARN("Start failed: %08x\n", hr
);
270 HRESULT
DSOUND_PrimaryStop(DirectSoundDevice
*device
)
274 TRACE("(%p)\n", device
);
276 hr
= IAudioClient_Stop(device
->client
);
278 WARN("Stop failed: %08x\n", hr
);
285 HRESULT
DSOUND_PrimaryGetPosition(DirectSoundDevice
*device
, LPDWORD playpos
, LPDWORD writepos
)
287 TRACE("(%p,%p,%p)\n", device
, playpos
, writepos
);
289 /* check if playpos was requested */
291 *playpos
= device
->playing_offs_bytes
;
293 /* check if writepos was requested */
295 /* the writepos is the first non-queued position */
296 *writepos
= (device
->playing_offs_bytes
+ device
->in_mmdev_bytes
) % device
->buflen
;
298 TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos
?*playpos
:-1, writepos
?*writepos
:-1, device
, GetTickCount());
302 static DWORD
DSOUND_GetFormatSize(LPCWAVEFORMATEX wfex
)
304 if (wfex
->wFormatTag
== WAVE_FORMAT_PCM
)
305 return sizeof(WAVEFORMATEX
);
307 return sizeof(WAVEFORMATEX
) + wfex
->cbSize
;
310 LPWAVEFORMATEX
DSOUND_CopyFormat(LPCWAVEFORMATEX wfex
)
312 DWORD size
= DSOUND_GetFormatSize(wfex
);
313 LPWAVEFORMATEX pwfx
= HeapAlloc(GetProcessHeap(),0,size
);
315 WARN("out of memory\n");
316 } else if (wfex
->wFormatTag
!= WAVE_FORMAT_PCM
) {
317 CopyMemory(pwfx
, wfex
, size
);
319 CopyMemory(pwfx
, wfex
, sizeof(PCMWAVEFORMAT
));
321 if (pwfx
->nBlockAlign
!= pwfx
->nChannels
* pwfx
->wBitsPerSample
/8) {
322 WARN("Fixing bad nBlockAlign (%u)\n", pwfx
->nBlockAlign
);
323 pwfx
->nBlockAlign
= pwfx
->nChannels
* pwfx
->wBitsPerSample
/8;
325 if (pwfx
->nAvgBytesPerSec
!= pwfx
->nSamplesPerSec
* pwfx
->nBlockAlign
) {
326 WARN("Fixing bad nAvgBytesPerSec (%u)\n", pwfx
->nAvgBytesPerSec
);
327 pwfx
->nAvgBytesPerSec
= pwfx
->nSamplesPerSec
* pwfx
->nBlockAlign
;
333 HRESULT
primarybuffer_SetFormat(DirectSoundDevice
*device
, LPCWAVEFORMATEX passed_fmt
)
335 HRESULT err
= DSERR_BUFFERLOST
;
337 WAVEFORMATEX
*old_fmt
;
338 WAVEFORMATEXTENSIBLE
*fmtex
, *passed_fmtex
= (WAVEFORMATEXTENSIBLE
*)passed_fmt
;
339 BOOL forced
= (device
->priolevel
== DSSCL_WRITEPRIMARY
);
341 TRACE("(%p,%p)\n", device
, passed_fmt
);
343 if (device
->priolevel
== DSSCL_NORMAL
) {
344 WARN("failed priority check!\n");
345 return DSERR_PRIOLEVELNEEDED
;
348 /* Let's be pedantic! */
349 if (passed_fmt
== NULL
) {
350 WARN("invalid parameter: passed_fmt==NULL!\n");
351 return DSERR_INVALIDPARAM
;
353 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
354 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
355 passed_fmt
->wFormatTag
, passed_fmt
->nChannels
, passed_fmt
->nSamplesPerSec
,
356 passed_fmt
->nAvgBytesPerSec
, passed_fmt
->nBlockAlign
,
357 passed_fmt
->wBitsPerSample
, passed_fmt
->cbSize
);
359 if(passed_fmt
->wBitsPerSample
< 8 || passed_fmt
->wBitsPerSample
% 8 != 0 ||
360 passed_fmt
->nChannels
== 0 || passed_fmt
->nSamplesPerSec
== 0 ||
361 passed_fmt
->nAvgBytesPerSec
== 0 ||
362 passed_fmt
->nBlockAlign
!= passed_fmt
->nChannels
* passed_fmt
->wBitsPerSample
/ 8)
363 return DSERR_INVALIDPARAM
;
365 if(passed_fmt
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
366 if(passed_fmtex
->Samples
.wValidBitsPerSample
> passed_fmtex
->Format
.wBitsPerSample
)
367 return DSERR_INVALIDPARAM
;
371 RtlAcquireResourceExclusive(&(device
->buffer_list_lock
), TRUE
);
372 EnterCriticalSection(&(device
->mixlock
));
374 old_fmt
= device
->pwfx
;
375 device
->pwfx
= DSOUND_CopyFormat(passed_fmt
);
376 fmtex
= (WAVEFORMATEXTENSIBLE
*)device
->pwfx
;
377 if (device
->pwfx
== NULL
) {
378 device
->pwfx
= old_fmt
;
380 err
= DSERR_OUTOFMEMORY
;
384 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
){
385 if(fmtex
->Samples
.wValidBitsPerSample
== 0){
386 TRACE("Correcting 0 valid bits per sample\n");
387 fmtex
->Samples
.wValidBitsPerSample
= fmtex
->Format
.wBitsPerSample
;
391 DSOUND_PrimaryClose(device
);
393 err
= DSOUND_ReopenDevice(device
, FALSE
);
397 /* requested format failed, so try others */
398 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_IEEE_FLOAT
){
399 device
->pwfx
->wFormatTag
= WAVE_FORMAT_PCM
;
400 device
->pwfx
->wBitsPerSample
= 32;
401 device
->pwfx
->nAvgBytesPerSec
= passed_fmt
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
;
402 device
->pwfx
->nBlockAlign
= passed_fmt
->nChannels
* (device
->pwfx
->wBitsPerSample
/ 8);
404 err
= DSOUND_ReopenDevice(device
, FALSE
);
409 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
&&
410 IsEqualGUID(&fmtex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)){
411 fmtex
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
412 device
->pwfx
->wBitsPerSample
= 32;
413 device
->pwfx
->nAvgBytesPerSec
= passed_fmt
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
;
414 device
->pwfx
->nBlockAlign
= passed_fmt
->nChannels
* (device
->pwfx
->wBitsPerSample
/ 8);
416 err
= DSOUND_ReopenDevice(device
, FALSE
);
421 device
->pwfx
->wBitsPerSample
= 32;
422 device
->pwfx
->nAvgBytesPerSec
= passed_fmt
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
;
423 device
->pwfx
->nBlockAlign
= passed_fmt
->nChannels
* (device
->pwfx
->wBitsPerSample
/ 8);
424 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
425 fmtex
->Samples
.wValidBitsPerSample
= device
->pwfx
->wBitsPerSample
;
426 err
= DSOUND_ReopenDevice(device
, FALSE
);
430 device
->pwfx
->wBitsPerSample
= 16;
431 device
->pwfx
->nAvgBytesPerSec
= passed_fmt
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
;
432 device
->pwfx
->nBlockAlign
= passed_fmt
->nChannels
* (device
->pwfx
->wBitsPerSample
/ 8);
433 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
434 fmtex
->Samples
.wValidBitsPerSample
= device
->pwfx
->wBitsPerSample
;
435 err
= DSOUND_ReopenDevice(device
, FALSE
);
439 device
->pwfx
->wBitsPerSample
= 8;
440 device
->pwfx
->nAvgBytesPerSec
= passed_fmt
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
;
441 device
->pwfx
->nBlockAlign
= passed_fmt
->nChannels
* (device
->pwfx
->wBitsPerSample
/ 8);
442 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
443 fmtex
->Samples
.wValidBitsPerSample
= device
->pwfx
->wBitsPerSample
;
444 err
= DSOUND_ReopenDevice(device
, FALSE
);
448 device
->pwfx
->nChannels
= (passed_fmt
->nChannels
== 2) ? 1 : 2;
449 device
->pwfx
->wBitsPerSample
= passed_fmt
->wBitsPerSample
;
450 device
->pwfx
->nAvgBytesPerSec
= passed_fmt
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
;
451 device
->pwfx
->nBlockAlign
= passed_fmt
->nChannels
* (device
->pwfx
->wBitsPerSample
/ 8);
452 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
453 fmtex
->Samples
.wValidBitsPerSample
= device
->pwfx
->wBitsPerSample
;
454 err
= DSOUND_ReopenDevice(device
, FALSE
);
458 device
->pwfx
->wBitsPerSample
= 32;
459 device
->pwfx
->nAvgBytesPerSec
= passed_fmt
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
;
460 device
->pwfx
->nBlockAlign
= passed_fmt
->nChannels
* (device
->pwfx
->wBitsPerSample
/ 8);
461 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
462 fmtex
->Samples
.wValidBitsPerSample
= device
->pwfx
->wBitsPerSample
;
463 err
= DSOUND_ReopenDevice(device
, FALSE
);
467 device
->pwfx
->wBitsPerSample
= 16;
468 device
->pwfx
->nAvgBytesPerSec
= passed_fmt
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
;
469 device
->pwfx
->nBlockAlign
= passed_fmt
->nChannels
* (device
->pwfx
->wBitsPerSample
/ 8);
470 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
471 fmtex
->Samples
.wValidBitsPerSample
= device
->pwfx
->wBitsPerSample
;
472 err
= DSOUND_ReopenDevice(device
, FALSE
);
476 device
->pwfx
->wBitsPerSample
= 8;
477 device
->pwfx
->nAvgBytesPerSec
= passed_fmt
->nSamplesPerSec
* device
->pwfx
->nBlockAlign
;
478 device
->pwfx
->nBlockAlign
= passed_fmt
->nChannels
* (device
->pwfx
->wBitsPerSample
/ 8);
479 if(device
->pwfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
480 fmtex
->Samples
.wValidBitsPerSample
= device
->pwfx
->wBitsPerSample
;
481 err
= DSOUND_ReopenDevice(device
, FALSE
);
485 WARN("No formats could be opened\n");
489 err
= DSOUND_PrimaryOpen(device
);
491 WARN("DSOUND_PrimaryOpen failed\n");
495 if (passed_fmt
->nSamplesPerSec
/100 != device
->pwfx
->nSamplesPerSec
/100 && forced
&& device
->buffer
)
497 DSOUND_PrimaryClose(device
);
498 device
->pwfx
->nSamplesPerSec
= passed_fmt
->nSamplesPerSec
;
499 err
= DSOUND_ReopenDevice(device
, TRUE
);
501 WARN("DSOUND_ReopenDevice(2) failed: %08x\n", err
);
502 else if (FAILED((err
= DSOUND_PrimaryOpen(device
))))
503 WARN("DSOUND_PrimaryOpen(2) failed: %08x\n", err
);
506 device
->mix_buffer_len
= DSOUND_bufpos_to_mixpos(device
, device
->buflen
);
507 device
->mix_buffer
= HeapReAlloc(GetProcessHeap(), 0, device
->mix_buffer
, device
->mix_buffer_len
);
508 FillMemory(device
->mix_buffer
, device
->mix_buffer_len
, 0);
509 device
->mixfunction
= mixfunctions
[device
->pwfx
->wBitsPerSample
/8 - 1];
510 device
->normfunction
= normfunctions
[device
->pwfx
->wBitsPerSample
/8 - 1];
512 if (old_fmt
->nSamplesPerSec
!= device
->pwfx
->nSamplesPerSec
||
513 old_fmt
->wBitsPerSample
!= device
->pwfx
->wBitsPerSample
||
514 old_fmt
->nChannels
!= device
->pwfx
->nChannels
) {
515 IDirectSoundBufferImpl
** dsb
= device
->buffers
;
516 for (i
= 0; i
< device
->nrofbuffers
; i
++, dsb
++) {
518 RtlAcquireResourceExclusive(&(*dsb
)->lock
, TRUE
);
520 (*dsb
)->freqAdjust
= (*dsb
)->freq
/ (float)device
->pwfx
->nSamplesPerSec
;
521 DSOUND_RecalcFormat((*dsb
));
522 (*dsb
)->primary_mixpos
= 0;
524 RtlReleaseResource(&(*dsb
)->lock
);
530 LeaveCriticalSection(&(device
->mixlock
));
531 RtlReleaseResource(&(device
->buffer_list_lock
));
534 HeapFree(GetProcessHeap(), 0, old_fmt
);
538 /*******************************************************************************
541 static inline IDirectSoundBufferImpl
*impl_from_IDirectSoundBuffer(IDirectSoundBuffer
*iface
)
543 /* IDirectSoundBuffer and IDirectSoundBuffer8 use the same iface. */
544 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSoundBuffer8_iface
);
547 /* This sets this format for the primary buffer only */
548 static HRESULT WINAPI
PrimaryBufferImpl_SetFormat(IDirectSoundBuffer
*iface
,
549 const WAVEFORMATEX
*wfex
)
551 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
552 TRACE("(%p,%p)\n", iface
, wfex
);
553 return primarybuffer_SetFormat(This
->device
, wfex
);
556 static HRESULT WINAPI
PrimaryBufferImpl_SetVolume(IDirectSoundBuffer
*iface
, LONG vol
)
558 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
559 DirectSoundDevice
*device
= This
->device
;
563 TRACE("(%p,%d)\n", iface
, vol
);
565 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
566 WARN("control unavailable\n");
567 return DSERR_CONTROLUNAVAIL
;
570 if ((vol
> DSBVOLUME_MAX
) || (vol
< DSBVOLUME_MIN
)) {
571 WARN("invalid parameter: vol = %d\n", vol
);
572 return DSERR_INVALIDPARAM
;
576 EnterCriticalSection(&device
->mixlock
);
578 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 0, &lvol
);
580 LeaveCriticalSection(&device
->mixlock
);
581 WARN("GetChannelVolume failed: %08x\n", hr
);
585 if(device
->pwfx
->nChannels
> 1){
586 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 1, &rvol
);
588 LeaveCriticalSection(&device
->mixlock
);
589 WARN("GetChannelVolume failed: %08x\n", hr
);
595 device
->volpan
.dwTotalLeftAmpFactor
= ((UINT16
)(lvol
* (DWORD
)0xFFFF));
596 device
->volpan
.dwTotalRightAmpFactor
= ((UINT16
)(rvol
* (DWORD
)0xFFFF));
598 DSOUND_AmpFactorToVolPan(&device
->volpan
);
599 if (vol
!= device
->volpan
.lVolume
) {
600 device
->volpan
.lVolume
=vol
;
601 DSOUND_RecalcVolPan(&device
->volpan
);
602 lvol
= (float)((DWORD
)(device
->volpan
.dwTotalLeftAmpFactor
& 0xFFFF) / (float)0xFFFF);
603 hr
= IAudioStreamVolume_SetChannelVolume(device
->volume
, 0, lvol
);
605 LeaveCriticalSection(&device
->mixlock
);
606 WARN("SetChannelVolume failed: %08x\n", hr
);
610 if(device
->pwfx
->nChannels
> 1){
611 rvol
= (float)((DWORD
)(device
->volpan
.dwTotalRightAmpFactor
& 0xFFFF) / (float)0xFFFF);
612 hr
= IAudioStreamVolume_SetChannelVolume(device
->volume
, 1, rvol
);
614 LeaveCriticalSection(&device
->mixlock
);
615 WARN("SetChannelVolume failed: %08x\n", hr
);
621 LeaveCriticalSection(&(device
->mixlock
));
627 static HRESULT WINAPI
PrimaryBufferImpl_GetVolume(IDirectSoundBuffer
*iface
, LONG
*vol
)
629 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
630 DirectSoundDevice
*device
= This
->device
;
633 TRACE("(%p,%p)\n", iface
, vol
);
635 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
636 WARN("control unavailable\n");
637 return DSERR_CONTROLUNAVAIL
;
641 WARN("invalid parameter: vol = NULL\n");
642 return DSERR_INVALIDPARAM
;
645 EnterCriticalSection(&device
->mixlock
);
647 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 0, &lvol
);
649 LeaveCriticalSection(&device
->mixlock
);
650 WARN("GetChannelVolume failed: %08x\n", hr
);
654 if(device
->pwfx
->nChannels
> 1){
655 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 1, &rvol
);
657 LeaveCriticalSection(&device
->mixlock
);
658 WARN("GetChannelVolume failed: %08x\n", hr
);
664 device
->volpan
.dwTotalLeftAmpFactor
= ((UINT16
)(lvol
* (DWORD
)0xFFFF));
665 device
->volpan
.dwTotalRightAmpFactor
= ((UINT16
)(rvol
* (DWORD
)0xFFFF));
667 DSOUND_AmpFactorToVolPan(&device
->volpan
);
668 *vol
= device
->volpan
.lVolume
;
670 LeaveCriticalSection(&device
->mixlock
);
675 static HRESULT WINAPI
PrimaryBufferImpl_SetFrequency(IDirectSoundBuffer
*iface
, DWORD freq
)
677 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
678 TRACE("(%p,%d)\n",This
,freq
);
680 /* You cannot set the frequency of the primary buffer */
681 WARN("control unavailable\n");
682 return DSERR_CONTROLUNAVAIL
;
685 static HRESULT WINAPI
PrimaryBufferImpl_Play(IDirectSoundBuffer
*iface
, DWORD reserved1
,
686 DWORD reserved2
, DWORD flags
)
688 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
689 DirectSoundDevice
*device
= This
->device
;
690 TRACE("(%p,%08x,%08x,%08x)\n", iface
, reserved1
, reserved2
, flags
);
692 if (!(flags
& DSBPLAY_LOOPING
)) {
693 WARN("invalid parameter: flags = %08x\n", flags
);
694 return DSERR_INVALIDPARAM
;
698 EnterCriticalSection(&(device
->mixlock
));
700 if (device
->state
== STATE_STOPPED
)
701 device
->state
= STATE_STARTING
;
702 else if (device
->state
== STATE_STOPPING
)
703 device
->state
= STATE_PLAYING
;
705 LeaveCriticalSection(&(device
->mixlock
));
711 static HRESULT WINAPI
PrimaryBufferImpl_Stop(IDirectSoundBuffer
*iface
)
713 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
714 DirectSoundDevice
*device
= This
->device
;
715 TRACE("(%p)\n", iface
);
718 EnterCriticalSection(&(device
->mixlock
));
720 if (device
->state
== STATE_PLAYING
)
721 device
->state
= STATE_STOPPING
;
722 else if (device
->state
== STATE_STARTING
)
723 device
->state
= STATE_STOPPED
;
725 LeaveCriticalSection(&(device
->mixlock
));
731 static ULONG WINAPI
PrimaryBufferImpl_AddRef(IDirectSoundBuffer
*iface
)
733 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
734 ULONG ref
= InterlockedIncrement(&(This
->ref
));
735 TRACE("(%p) ref was %d\n", This
, ref
- 1);
737 InterlockedIncrement(&This
->numIfaces
);
741 /* Decreases *out by 1 to no less than 0.
742 * Returns the new value of *out. */
743 LONG
capped_refcount_dec(LONG
*out
)
750 oldref
= InterlockedCompareExchange(out
, ref
- 1, ref
);
751 } while(oldref
!= ref
);
755 static ULONG WINAPI
PrimaryBufferImpl_Release(IDirectSoundBuffer
*iface
)
757 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
760 ref
= capped_refcount_dec(&This
->ref
);
762 capped_refcount_dec(&This
->numIfaces
);
764 TRACE("(%p) primary ref is now %d\n", This
, ref
);
769 static HRESULT WINAPI
PrimaryBufferImpl_GetCurrentPosition(IDirectSoundBuffer
*iface
,
770 DWORD
*playpos
, DWORD
*writepos
)
773 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
774 DirectSoundDevice
*device
= This
->device
;
775 TRACE("(%p,%p,%p)\n", iface
, playpos
, writepos
);
778 EnterCriticalSection(&(device
->mixlock
));
780 hres
= DSOUND_PrimaryGetPosition(device
, playpos
, writepos
);
782 WARN("DSOUND_PrimaryGetPosition failed\n");
783 LeaveCriticalSection(&(device
->mixlock
));
787 if (device
->state
!= STATE_STOPPED
)
788 /* apply the documented 10ms lead to writepos */
789 *writepos
+= device
->writelead
;
790 while (*writepos
>= device
->buflen
) *writepos
-= device
->buflen
;
793 LeaveCriticalSection(&(device
->mixlock
));
796 TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos
?*playpos
:0, writepos
?*writepos
:0, device
, GetTickCount());
800 static HRESULT WINAPI
PrimaryBufferImpl_GetStatus(IDirectSoundBuffer
*iface
, DWORD
*status
)
802 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
803 DirectSoundDevice
*device
= This
->device
;
804 TRACE("(%p,%p)\n", iface
, status
);
806 if (status
== NULL
) {
807 WARN("invalid parameter: status == NULL\n");
808 return DSERR_INVALIDPARAM
;
812 if ((device
->state
== STATE_STARTING
) ||
813 (device
->state
== STATE_PLAYING
))
814 *status
|= DSBSTATUS_PLAYING
| DSBSTATUS_LOOPING
;
816 TRACE("status=%x\n", *status
);
821 static HRESULT WINAPI
PrimaryBufferImpl_GetFormat(IDirectSoundBuffer
*iface
, WAVEFORMATEX
*lpwf
,
822 DWORD wfsize
, DWORD
*wfwritten
)
825 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
826 DirectSoundDevice
*device
= This
->device
;
827 TRACE("(%p,%p,%d,%p)\n", iface
, lpwf
, wfsize
, wfwritten
);
829 size
= sizeof(WAVEFORMATEX
) + device
->pwfx
->cbSize
;
831 if (lpwf
) { /* NULL is valid */
832 if (wfsize
>= size
) {
833 CopyMemory(lpwf
,device
->pwfx
,size
);
837 WARN("invalid parameter: wfsize too small\n");
840 return DSERR_INVALIDPARAM
;
844 *wfwritten
= sizeof(WAVEFORMATEX
) + device
->pwfx
->cbSize
;
846 WARN("invalid parameter: wfwritten == NULL\n");
847 return DSERR_INVALIDPARAM
;
854 static HRESULT WINAPI
PrimaryBufferImpl_Lock(IDirectSoundBuffer
*iface
, DWORD writecursor
,
855 DWORD writebytes
, void **lplpaudioptr1
, DWORD
*audiobytes1
, void **lplpaudioptr2
,
856 DWORD
*audiobytes2
, DWORD flags
)
859 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
860 DirectSoundDevice
*device
= This
->device
;
861 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n",
874 return DSERR_INVALIDPARAM
;
876 if (device
->priolevel
!= DSSCL_WRITEPRIMARY
) {
877 WARN("failed priority check!\n");
878 return DSERR_PRIOLEVELNEEDED
;
881 /* when this flag is set, writecursor is meaningless and must be calculated */
882 if (flags
& DSBLOCK_FROMWRITECURSOR
) {
883 /* GetCurrentPosition does too much magic to duplicate here */
884 hres
= IDirectSoundBuffer_GetCurrentPosition(iface
, NULL
, &writecursor
);
886 WARN("IDirectSoundBuffer_GetCurrentPosition failed\n");
891 /* when this flag is set, writebytes is meaningless and must be set */
892 if (flags
& DSBLOCK_ENTIREBUFFER
)
893 writebytes
= device
->buflen
;
895 if (writecursor
>= device
->buflen
) {
896 WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
897 writecursor
, device
->buflen
);
898 return DSERR_INVALIDPARAM
;
901 if (writebytes
> device
->buflen
) {
902 WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
903 writebytes
, device
->buflen
);
904 return DSERR_INVALIDPARAM
;
907 if (writecursor
+writebytes
<= device
->buflen
) {
908 *(LPBYTE
*)lplpaudioptr1
= device
->buffer
+writecursor
;
909 *audiobytes1
= writebytes
;
911 *(LPBYTE
*)lplpaudioptr2
= NULL
;
914 TRACE("->%d.0\n",writebytes
);
916 *(LPBYTE
*)lplpaudioptr1
= device
->buffer
+writecursor
;
917 *audiobytes1
= device
->buflen
-writecursor
;
919 *(LPBYTE
*)lplpaudioptr2
= device
->buffer
;
921 *audiobytes2
= writebytes
-(device
->buflen
-writecursor
);
922 TRACE("->%d.%d\n",*audiobytes1
,audiobytes2
?*audiobytes2
:0);
927 static HRESULT WINAPI
PrimaryBufferImpl_SetCurrentPosition(IDirectSoundBuffer
*iface
, DWORD newpos
)
929 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
930 TRACE("(%p,%d)\n",This
,newpos
);
932 /* You cannot set the position of the primary buffer */
933 WARN("invalid call\n");
934 return DSERR_INVALIDCALL
;
937 static HRESULT WINAPI
PrimaryBufferImpl_SetPan(IDirectSoundBuffer
*iface
, LONG pan
)
939 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
940 DirectSoundDevice
*device
= This
->device
;
943 TRACE("(%p,%d)\n", iface
, pan
);
945 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
946 WARN("control unavailable\n");
947 return DSERR_CONTROLUNAVAIL
;
950 if ((pan
> DSBPAN_RIGHT
) || (pan
< DSBPAN_LEFT
)) {
951 WARN("invalid parameter: pan = %d\n", pan
);
952 return DSERR_INVALIDPARAM
;
956 EnterCriticalSection(&device
->mixlock
);
958 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 0, &lvol
);
960 LeaveCriticalSection(&device
->mixlock
);
961 WARN("GetChannelVolume failed: %08x\n", hr
);
965 if(device
->pwfx
->nChannels
> 1){
966 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 1, &rvol
);
968 LeaveCriticalSection(&device
->mixlock
);
969 WARN("GetChannelVolume failed: %08x\n", hr
);
975 device
->volpan
.dwTotalLeftAmpFactor
= ((UINT16
)(lvol
* (DWORD
)0xFFFF));
976 device
->volpan
.dwTotalRightAmpFactor
= ((UINT16
)(rvol
* (DWORD
)0xFFFF));
978 DSOUND_AmpFactorToVolPan(&device
->volpan
);
979 if (pan
!= device
->volpan
.lPan
) {
980 device
->volpan
.lPan
=pan
;
981 DSOUND_RecalcVolPan(&device
->volpan
);
983 lvol
= (float)((DWORD
)(device
->volpan
.dwTotalLeftAmpFactor
& 0xFFFF) / (float)0xFFFF);
984 hr
= IAudioStreamVolume_SetChannelVolume(device
->volume
, 0, lvol
);
986 LeaveCriticalSection(&device
->mixlock
);
987 WARN("SetChannelVolume failed: %08x\n", hr
);
991 if(device
->pwfx
->nChannels
> 1){
992 rvol
= (float)((DWORD
)(device
->volpan
.dwTotalRightAmpFactor
& 0xFFFF) / (float)0xFFFF);
993 hr
= IAudioStreamVolume_SetChannelVolume(device
->volume
, 1, rvol
);
995 LeaveCriticalSection(&device
->mixlock
);
996 WARN("SetChannelVolume failed: %08x\n", hr
);
1002 LeaveCriticalSection(&device
->mixlock
);
1008 static HRESULT WINAPI
PrimaryBufferImpl_GetPan(IDirectSoundBuffer
*iface
, LONG
*pan
)
1010 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1011 DirectSoundDevice
*device
= This
->device
;
1014 TRACE("(%p,%p)\n", iface
, pan
);
1016 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
1017 WARN("control unavailable\n");
1018 return DSERR_CONTROLUNAVAIL
;
1022 WARN("invalid parameter: pan == NULL\n");
1023 return DSERR_INVALIDPARAM
;
1026 EnterCriticalSection(&device
->mixlock
);
1028 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 0, &lvol
);
1030 LeaveCriticalSection(&device
->mixlock
);
1031 WARN("GetChannelVolume failed: %08x\n", hr
);
1035 if(device
->pwfx
->nChannels
> 1){
1036 hr
= IAudioStreamVolume_GetChannelVolume(device
->volume
, 1, &rvol
);
1038 LeaveCriticalSection(&device
->mixlock
);
1039 WARN("GetChannelVolume failed: %08x\n", hr
);
1045 device
->volpan
.dwTotalLeftAmpFactor
= ((UINT16
)(lvol
* (DWORD
)0xFFFF));
1046 device
->volpan
.dwTotalRightAmpFactor
= ((UINT16
)(rvol
* (DWORD
)0xFFFF));
1048 DSOUND_AmpFactorToVolPan(&device
->volpan
);
1049 *pan
= device
->volpan
.lPan
;
1051 LeaveCriticalSection(&device
->mixlock
);
1056 static HRESULT WINAPI
PrimaryBufferImpl_Unlock(IDirectSoundBuffer
*iface
, void *p1
, DWORD x1
,
1059 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1060 DirectSoundDevice
*device
= This
->device
;
1061 TRACE("(%p,%p,%d,%p,%d)\n", iface
, p1
, x1
, p2
, x2
);
1063 if (device
->priolevel
!= DSSCL_WRITEPRIMARY
) {
1064 WARN("failed priority check!\n");
1065 return DSERR_PRIOLEVELNEEDED
;
1068 if((p1
&& ((BYTE
*)p1
< device
->buffer
||
1069 (BYTE
*)p1
>= device
->buffer
+ device
->buflen
)) ||
1070 (p2
&& ((BYTE
*)p2
< device
->buffer
||
1071 (BYTE
*)p2
>= device
->buffer
+ device
->buflen
)))
1072 return DSERR_INVALIDPARAM
;
1077 static HRESULT WINAPI
PrimaryBufferImpl_Restore(IDirectSoundBuffer
*iface
)
1079 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1080 FIXME("(%p):stub\n",This
);
1084 static HRESULT WINAPI
PrimaryBufferImpl_GetFrequency(IDirectSoundBuffer
*iface
, DWORD
*freq
)
1086 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1087 DirectSoundDevice
*device
= This
->device
;
1088 TRACE("(%p,%p)\n", iface
, freq
);
1091 WARN("invalid parameter: freq == NULL\n");
1092 return DSERR_INVALIDPARAM
;
1095 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLFREQUENCY
)) {
1096 WARN("control unavailable\n");
1097 return DSERR_CONTROLUNAVAIL
;
1100 *freq
= device
->pwfx
->nSamplesPerSec
;
1101 TRACE("-> %d\n", *freq
);
1106 static HRESULT WINAPI
PrimaryBufferImpl_Initialize(IDirectSoundBuffer
*iface
, IDirectSound
*dsound
,
1107 const DSBUFFERDESC
*dbsd
)
1109 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1110 WARN("(%p) already initialized\n", This
);
1111 return DSERR_ALREADYINITIALIZED
;
1114 static HRESULT WINAPI
PrimaryBufferImpl_GetCaps(IDirectSoundBuffer
*iface
, DSBCAPS
*caps
)
1116 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1117 DirectSoundDevice
*device
= This
->device
;
1118 TRACE("(%p,%p)\n", iface
, caps
);
1121 WARN("invalid parameter: caps == NULL\n");
1122 return DSERR_INVALIDPARAM
;
1125 if (caps
->dwSize
< sizeof(*caps
)) {
1126 WARN("invalid parameter: caps->dwSize = %d\n", caps
->dwSize
);
1127 return DSERR_INVALIDPARAM
;
1130 caps
->dwFlags
= This
->dsbd
.dwFlags
;
1131 caps
->dwBufferBytes
= device
->buflen
;
1133 /* Windows reports these as zero */
1134 caps
->dwUnlockTransferRate
= 0;
1135 caps
->dwPlayCpuOverhead
= 0;
1140 static HRESULT WINAPI
PrimaryBufferImpl_QueryInterface(IDirectSoundBuffer
*iface
, REFIID riid
,
1143 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer(iface
);
1145 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(riid
), ppobj
);
1147 if (ppobj
== NULL
) {
1148 WARN("invalid parameter\n");
1149 return E_INVALIDARG
;
1152 *ppobj
= NULL
; /* assume failure */
1154 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
1155 IsEqualGUID(riid
, &IID_IDirectSoundBuffer
) ) {
1156 IDirectSoundBuffer_AddRef(iface
);
1161 /* DirectSoundBuffer and DirectSoundBuffer8 are different and */
1162 /* a primary buffer can't have a DirectSoundBuffer8 interface */
1163 if ( IsEqualGUID( &IID_IDirectSoundBuffer8
, riid
) ) {
1164 WARN("app requested DirectSoundBuffer8 on primary buffer\n");
1165 return E_NOINTERFACE
;
1168 if ( IsEqualGUID( &IID_IDirectSoundNotify
, riid
) ) {
1169 ERR("app requested IDirectSoundNotify on primary buffer\n");
1170 /* FIXME: should we support this? */
1171 return E_NOINTERFACE
;
1174 if ( IsEqualGUID( &IID_IDirectSound3DBuffer
, riid
) ) {
1175 ERR("app requested IDirectSound3DBuffer on primary buffer\n");
1176 return E_NOINTERFACE
;
1179 if ( IsEqualGUID( &IID_IDirectSound3DListener
, riid
) ) {
1180 *ppobj
= &This
->IDirectSound3DListener_iface
;
1181 IDirectSound3DListener_AddRef(&This
->IDirectSound3DListener_iface
);
1185 if ( IsEqualGUID( &IID_IKsPropertySet
, riid
) ) {
1186 *ppobj
= &This
->IKsPropertySet_iface
;
1187 IKsPropertySet_AddRef(&This
->IKsPropertySet_iface
);
1191 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
1192 return E_NOINTERFACE
;
1195 static const IDirectSoundBufferVtbl dspbvt
=
1197 PrimaryBufferImpl_QueryInterface
,
1198 PrimaryBufferImpl_AddRef
,
1199 PrimaryBufferImpl_Release
,
1200 PrimaryBufferImpl_GetCaps
,
1201 PrimaryBufferImpl_GetCurrentPosition
,
1202 PrimaryBufferImpl_GetFormat
,
1203 PrimaryBufferImpl_GetVolume
,
1204 PrimaryBufferImpl_GetPan
,
1205 PrimaryBufferImpl_GetFrequency
,
1206 PrimaryBufferImpl_GetStatus
,
1207 PrimaryBufferImpl_Initialize
,
1208 PrimaryBufferImpl_Lock
,
1209 PrimaryBufferImpl_Play
,
1210 PrimaryBufferImpl_SetCurrentPosition
,
1211 PrimaryBufferImpl_SetFormat
,
1212 PrimaryBufferImpl_SetVolume
,
1213 PrimaryBufferImpl_SetPan
,
1214 PrimaryBufferImpl_SetFrequency
,
1215 PrimaryBufferImpl_Stop
,
1216 PrimaryBufferImpl_Unlock
,
1217 PrimaryBufferImpl_Restore
1220 HRESULT
primarybuffer_create(DirectSoundDevice
*device
, IDirectSoundBufferImpl
**ppdsb
,
1221 const DSBUFFERDESC
*dsbd
)
1223 IDirectSoundBufferImpl
*dsb
;
1224 TRACE("%p,%p,%p)\n",device
,ppdsb
,dsbd
);
1226 if (dsbd
->lpwfxFormat
) {
1227 WARN("invalid parameter: dsbd->lpwfxFormat != NULL\n");
1229 return DSERR_INVALIDPARAM
;
1232 dsb
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(*dsb
));
1235 WARN("out of memory\n");
1237 return DSERR_OUTOFMEMORY
;
1244 dsb
->device
= device
;
1245 dsb
->IDirectSoundBuffer8_iface
.lpVtbl
= (IDirectSoundBuffer8Vtbl
*)&dspbvt
;
1246 dsb
->IDirectSound3DListener_iface
.lpVtbl
= &ds3dlvt
;
1247 dsb
->IKsPropertySet_iface
.lpVtbl
= &iksbvt
;
1250 /* IDirectSound3DListener */
1251 device
->ds3dl
.dwSize
= sizeof(DS3DLISTENER
);
1252 device
->ds3dl
.vPosition
.x
= 0.0;
1253 device
->ds3dl
.vPosition
.y
= 0.0;
1254 device
->ds3dl
.vPosition
.z
= 0.0;
1255 device
->ds3dl
.vVelocity
.x
= 0.0;
1256 device
->ds3dl
.vVelocity
.y
= 0.0;
1257 device
->ds3dl
.vVelocity
.z
= 0.0;
1258 device
->ds3dl
.vOrientFront
.x
= 0.0;
1259 device
->ds3dl
.vOrientFront
.y
= 0.0;
1260 device
->ds3dl
.vOrientFront
.z
= 1.0;
1261 device
->ds3dl
.vOrientTop
.x
= 0.0;
1262 device
->ds3dl
.vOrientTop
.y
= 1.0;
1263 device
->ds3dl
.vOrientTop
.z
= 0.0;
1264 device
->ds3dl
.flDistanceFactor
= DS3D_DEFAULTDISTANCEFACTOR
;
1265 device
->ds3dl
.flRolloffFactor
= DS3D_DEFAULTROLLOFFFACTOR
;
1266 device
->ds3dl
.flDopplerFactor
= DS3D_DEFAULTDOPPLERFACTOR
;
1267 device
->ds3dl_need_recalc
= TRUE
;
1269 TRACE("Created primary buffer at %p\n", dsb
);
1270 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
1271 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
1272 device
->pwfx
->wFormatTag
, device
->pwfx
->nChannels
,
1273 device
->pwfx
->nSamplesPerSec
, device
->pwfx
->nAvgBytesPerSec
,
1274 device
->pwfx
->nBlockAlign
, device
->pwfx
->wBitsPerSample
,
1275 device
->pwfx
->cbSize
);
1277 IDirectSoundBuffer_AddRef(&dsb
->IDirectSoundBuffer8_iface
);