hhctrl.ocx: Open a specific topic when requested.
[wine/multimedia.git] / dlls / dsound / primary.c
blob7243cc6c7327daa97189dae69bc72e1134598853
1 /* DirectSound
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
21 * TODO:
22 * When PrimarySetFormat (via ReopenDevice or PrimaryOpen) fails,
23 * it leaves dsound in unusable (not really open) state.
26 #include <stdarg.h>
28 #define COBJMACROS
29 #define NONAMELESSSTRUCT
30 #define NONAMELESSUNION
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "mmsystem.h"
35 #include "winternl.h"
36 #include "mmddk.h"
37 #include "wine/debug.h"
38 #include "dsound.h"
39 #include "dsound_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
43 /** Calculate how long a fragment length of about 10 ms should be in frames
45 * nSamplesPerSec: Frequency rate in samples per second
46 * nBlockAlign: Size of a single blockalign
48 * Returns:
49 * Size in bytes of a single fragment
51 DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign)
53 /* Given a timer delay of 10ms, the fragment size is approximately:
54 * fraglen = (nSamplesPerSec * 10 / 1000) * nBlockAlign
55 * ==> fraglen = (nSamplesPerSec / 100) * nBlockSize
57 * ALSA uses buffers that are powers of 2. Because of this, fraglen
58 * is rounded up to the nearest power of 2:
61 if (nSamplesPerSec <= 12800)
62 return 128 * nBlockAlign;
64 if (nSamplesPerSec <= 25600)
65 return 256 * nBlockAlign;
67 if (nSamplesPerSec <= 51200)
68 return 512 * nBlockAlign;
70 return 1024 * nBlockAlign;
73 static void DSOUND_RecalcPrimary(DirectSoundDevice *device)
75 TRACE("(%p)\n", device);
77 device->fraglen = DSOUND_fraglen(device->pwfx->nSamplesPerSec, device->pwfx->nBlockAlign);
78 device->helfrags = device->buflen / device->fraglen;
79 TRACE("fraglen=%d helfrags=%d\n", device->fraglen, device->helfrags);
81 /* calculate the 10ms write lead */
82 device->writelead = (device->pwfx->nSamplesPerSec / 100) * device->pwfx->nBlockAlign;
85 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
87 HRESULT hres;
89 TRACE("(%p, %d)\n", device, forcewave);
91 if(device->client){
92 IAudioClient_Release(device->client);
93 device->client = NULL;
95 if(device->render){
96 IAudioRenderClient_Release(device->render);
97 device->render = NULL;
99 if(device->clock){
100 IAudioClock_Release(device->clock);
101 device->clock = NULL;
103 if(device->volume){
104 IAudioStreamVolume_Release(device->volume);
105 device->volume = NULL;
108 hres = IMMDevice_Activate(device->mmdevice, &IID_IAudioClient,
109 CLSCTX_INPROC_SERVER, NULL, (void **)&device->client);
110 if(FAILED(hres)){
111 WARN("Activate failed: %08x\n", hres);
112 return hres;
115 /* buffer size = 200 * 100000 (100 ns) = 2.0 seconds */
116 hres = IAudioClient_Initialize(device->client,
117 AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST,
118 200 * 100000, 50000, device->pwfx, NULL);
119 if(FAILED(hres)){
120 IAudioClient_Release(device->client);
121 device->client = NULL;
122 WARN("Initialize failed: %08x\n", hres);
123 return hres;
126 hres = IAudioClient_GetService(device->client, &IID_IAudioRenderClient,
127 (void**)&device->render);
128 if(FAILED(hres)){
129 IAudioClient_Release(device->client);
130 device->client = NULL;
131 WARN("GetService failed: %08x\n", hres);
132 return hres;
135 hres = IAudioClient_GetService(device->client, &IID_IAudioClock,
136 (void**)&device->clock);
137 if(FAILED(hres)){
138 IAudioClient_Release(device->client);
139 IAudioRenderClient_Release(device->render);
140 device->client = NULL;
141 device->render = NULL;
142 WARN("GetService failed: %08x\n", hres);
143 return hres;
146 hres = IAudioClient_GetService(device->client, &IID_IAudioStreamVolume,
147 (void**)&device->volume);
148 if(FAILED(hres)){
149 IAudioClient_Release(device->client);
150 IAudioRenderClient_Release(device->render);
151 IAudioClock_Release(device->clock);
152 device->client = NULL;
153 device->render = NULL;
154 device->clock = NULL;
155 WARN("GetService failed: %08x\n", hres);
156 return hres;
159 return S_OK;
162 static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device)
164 DWORD buflen;
165 LPBYTE newbuf;
167 TRACE("(%p)\n", device);
169 /* on original windows, the buffer it set to a fixed size, no matter what the settings are.
170 on windows this size is always fixed (tested on win-xp) */
171 if (!device->buflen)
172 device->buflen = ds_hel_buflen;
173 buflen = device->buflen;
174 buflen -= buflen % device->pwfx->nBlockAlign;
175 device->buflen = buflen;
177 device->mix_buffer_len = DSOUND_bufpos_to_mixpos(device, device->buflen);
178 device->mix_buffer = HeapAlloc(GetProcessHeap(), 0, device->mix_buffer_len);
179 if (!device->mix_buffer)
180 return DSERR_OUTOFMEMORY;
182 if (device->state == STATE_PLAYING) device->state = STATE_STARTING;
183 else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED;
185 TRACE("desired buflen=%d, old buffer=%p\n", buflen, device->buffer);
187 /* reallocate emulated primary buffer */
188 if (device->buffer)
189 newbuf = HeapReAlloc(GetProcessHeap(),0,device->buffer, buflen);
190 else
191 newbuf = HeapAlloc(GetProcessHeap(),0, buflen);
193 if (!newbuf) {
194 ERR("failed to allocate primary buffer\n");
195 return DSERR_OUTOFMEMORY;
196 /* but the old buffer might still exist and must be re-prepared */
199 DSOUND_RecalcPrimary(device);
201 device->buffer = newbuf;
203 TRACE("fraglen=%d\n", device->fraglen);
205 device->mixfunction = mixfunctions[device->pwfx->wBitsPerSample/8 - 1];
206 device->normfunction = normfunctions[device->pwfx->wBitsPerSample/8 - 1];
207 FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0);
208 FillMemory(device->mix_buffer, device->mix_buffer_len, 0);
209 device->last_pos_bytes = device->pwplay = device->pwqueue = device->playpos = device->mixpos = 0;
210 return DS_OK;
214 static void DSOUND_PrimaryClose(DirectSoundDevice *device)
216 HRESULT hr;
218 TRACE("(%p)\n", device);
220 device->pwqueue = (DWORD)-1; /* resetting queues */
222 if(device->client){
223 hr = IAudioClient_Stop(device->client);
224 if(FAILED(hr))
225 WARN("Stop failed: %08x\n", hr);
228 /* clear the queue */
229 device->pwqueue = 0;
232 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device)
234 HRESULT err = DS_OK;
235 TRACE("(%p)\n", device);
237 device->buflen = ds_hel_buflen;
238 err = DSOUND_PrimaryOpen(device);
240 if (err != DS_OK) {
241 WARN("DSOUND_PrimaryOpen failed\n");
242 return err;
245 device->state = STATE_STOPPED;
246 return DS_OK;
249 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device)
251 TRACE("(%p)\n", device);
253 /* **** */
254 EnterCriticalSection(&(device->mixlock));
256 DSOUND_PrimaryClose(device);
257 HeapFree(GetProcessHeap(),0,device->pwfx);
258 device->pwfx=NULL;
260 LeaveCriticalSection(&(device->mixlock));
261 /* **** */
263 return DS_OK;
266 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device)
268 HRESULT hr;
270 TRACE("(%p)\n", device);
272 hr = IAudioClient_Start(device->client);
273 if(FAILED(hr)){
274 WARN("Start failed: %08x\n", hr);
275 return hr;
278 return DS_OK;
281 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device)
283 HRESULT hr;
285 TRACE("(%p)\n", device);
287 hr = IAudioClient_Stop(device->client);
288 if(FAILED(hr)){
289 WARN("Stop failed: %08x\n", hr);
290 return hr;
293 return DS_OK;
296 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos)
298 TRACE("(%p,%p,%p)\n", device, playpos, writepos);
300 TRACE("pwplay=%i, pwqueue=%i\n", device->pwplay, device->pwqueue);
302 /* check if playpos was requested */
303 if (playpos)
304 /* use the cached play position */
305 *playpos = device->pwplay * device->fraglen;
307 /* check if writepos was requested */
308 if (writepos)
309 /* the writepos is the first non-queued position */
310 *writepos = ((device->pwplay + device->pwqueue) % device->helfrags) * device->fraglen;
312 TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:-1, writepos?*writepos:-1, device, GetTickCount());
313 return DS_OK;
316 static DWORD DSOUND_GetFormatSize(LPCWAVEFORMATEX wfex)
318 if (wfex->wFormatTag == WAVE_FORMAT_PCM)
319 return sizeof(WAVEFORMATEX);
320 else
321 return sizeof(WAVEFORMATEX) + wfex->cbSize;
324 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex)
326 DWORD size = DSOUND_GetFormatSize(wfex);
327 LPWAVEFORMATEX pwfx = HeapAlloc(GetProcessHeap(),0,size);
328 if (pwfx == NULL) {
329 WARN("out of memory\n");
330 } else if (wfex->wFormatTag != WAVE_FORMAT_PCM) {
331 CopyMemory(pwfx, wfex, size);
332 } else {
333 CopyMemory(pwfx, wfex, sizeof(PCMWAVEFORMAT));
334 pwfx->cbSize=0;
335 if (pwfx->nBlockAlign != pwfx->nChannels * pwfx->wBitsPerSample/8) {
336 WARN("Fixing bad nBlockAlign (%u)\n", pwfx->nBlockAlign);
337 pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample/8;
339 if (pwfx->nAvgBytesPerSec != pwfx->nSamplesPerSec * pwfx->nBlockAlign) {
340 WARN("Fixing bad nAvgBytesPerSec (%u)\n", pwfx->nAvgBytesPerSec);
341 pwfx->nAvgBytesPerSec = pwfx->nSamplesPerSec * pwfx->nBlockAlign;
344 return pwfx;
347 HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX passed_fmt)
349 HRESULT err = DSERR_BUFFERLOST;
350 int i;
351 WAVEFORMATEX *old_fmt;
352 WAVEFORMATEXTENSIBLE *fmtex;
353 BOOL forced = (device->priolevel == DSSCL_WRITEPRIMARY);
355 TRACE("(%p,%p)\n", device, passed_fmt);
357 if (device->priolevel == DSSCL_NORMAL) {
358 WARN("failed priority check!\n");
359 return DSERR_PRIOLEVELNEEDED;
362 /* Let's be pedantic! */
363 if (passed_fmt == NULL) {
364 WARN("invalid parameter: passed_fmt==NULL!\n");
365 return DSERR_INVALIDPARAM;
367 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
368 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
369 passed_fmt->wFormatTag, passed_fmt->nChannels, passed_fmt->nSamplesPerSec,
370 passed_fmt->nAvgBytesPerSec, passed_fmt->nBlockAlign,
371 passed_fmt->wBitsPerSample, passed_fmt->cbSize);
373 /* **** */
374 RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
375 EnterCriticalSection(&(device->mixlock));
377 old_fmt = device->pwfx;
378 device->pwfx = DSOUND_CopyFormat(passed_fmt);
379 fmtex = (WAVEFORMATEXTENSIBLE *)device->pwfx;
380 if (device->pwfx == NULL) {
381 device->pwfx = old_fmt;
382 old_fmt = NULL;
383 err = DSERR_OUTOFMEMORY;
384 goto done;
387 DSOUND_PrimaryClose(device);
389 err = DSOUND_ReopenDevice(device, FALSE);
390 if(SUCCEEDED(err))
391 goto opened;
393 /* requested format failed, so try others */
394 if(device->pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT){
395 device->pwfx->wFormatTag = WAVE_FORMAT_PCM;
396 device->pwfx->wBitsPerSample = 32;
397 device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
398 device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
400 err = DSOUND_ReopenDevice(device, FALSE);
401 if(SUCCEEDED(err))
402 goto opened;
405 if(device->pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
406 IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)){
407 fmtex->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
408 device->pwfx->wBitsPerSample = 32;
409 device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
410 device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
412 err = DSOUND_ReopenDevice(device, FALSE);
413 if(SUCCEEDED(err))
414 goto opened;
417 device->pwfx->wBitsPerSample = 32;
418 device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
419 device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
420 err = DSOUND_ReopenDevice(device, FALSE);
421 if(SUCCEEDED(err))
422 goto opened;
424 device->pwfx->wBitsPerSample = 16;
425 device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
426 device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
427 err = DSOUND_ReopenDevice(device, FALSE);
428 if(SUCCEEDED(err))
429 goto opened;
431 device->pwfx->wBitsPerSample = 8;
432 device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
433 device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
434 err = DSOUND_ReopenDevice(device, FALSE);
435 if(SUCCEEDED(err))
436 goto opened;
438 device->pwfx->nChannels = (passed_fmt->nChannels == 2) ? 1 : 2;
439 device->pwfx->wBitsPerSample = passed_fmt->wBitsPerSample;
440 device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
441 device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
442 err = DSOUND_ReopenDevice(device, FALSE);
443 if(SUCCEEDED(err))
444 goto opened;
446 device->pwfx->wBitsPerSample = 32;
447 device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
448 device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
449 err = DSOUND_ReopenDevice(device, FALSE);
450 if(SUCCEEDED(err))
451 goto opened;
453 device->pwfx->wBitsPerSample = 16;
454 device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
455 device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
456 err = DSOUND_ReopenDevice(device, FALSE);
457 if(SUCCEEDED(err))
458 goto opened;
460 device->pwfx->wBitsPerSample = 8;
461 device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
462 device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
463 err = DSOUND_ReopenDevice(device, FALSE);
464 if(SUCCEEDED(err))
465 goto opened;
467 WARN("No formats could be opened\n");
468 goto done;
470 opened:
471 err = DSOUND_PrimaryOpen(device);
472 if (err != DS_OK) {
473 WARN("DSOUND_PrimaryOpen failed\n");
474 goto done;
477 if (passed_fmt->nSamplesPerSec/100 != device->pwfx->nSamplesPerSec/100 && forced && device->buffer)
479 DSOUND_PrimaryClose(device);
480 device->pwfx->nSamplesPerSec = passed_fmt->nSamplesPerSec;
481 err = DSOUND_ReopenDevice(device, TRUE);
482 if (FAILED(err))
483 WARN("DSOUND_ReopenDevice(2) failed: %08x\n", err);
484 else if (FAILED((err = DSOUND_PrimaryOpen(device))))
485 WARN("DSOUND_PrimaryOpen(2) failed: %08x\n", err);
488 device->mix_buffer_len = DSOUND_bufpos_to_mixpos(device, device->buflen);
489 device->mix_buffer = HeapReAlloc(GetProcessHeap(), 0, device->mix_buffer, device->mix_buffer_len);
490 FillMemory(device->mix_buffer, device->mix_buffer_len, 0);
491 device->mixfunction = mixfunctions[device->pwfx->wBitsPerSample/8 - 1];
492 device->normfunction = normfunctions[device->pwfx->wBitsPerSample/8 - 1];
494 if (old_fmt->nSamplesPerSec != device->pwfx->nSamplesPerSec ||
495 old_fmt->wBitsPerSample != device->pwfx->wBitsPerSample ||
496 old_fmt->nChannels != device->pwfx->nChannels) {
497 IDirectSoundBufferImpl** dsb = device->buffers;
498 for (i = 0; i < device->nrofbuffers; i++, dsb++) {
499 /* **** */
500 RtlAcquireResourceExclusive(&(*dsb)->lock, TRUE);
502 (*dsb)->freqAdjust = ((DWORD64)(*dsb)->freq << DSOUND_FREQSHIFT) / device->pwfx->nSamplesPerSec;
503 DSOUND_RecalcFormat((*dsb));
504 DSOUND_MixToTemporary((*dsb), 0, (*dsb)->buflen, FALSE);
505 (*dsb)->primary_mixpos = 0;
507 RtlReleaseResource(&(*dsb)->lock);
508 /* **** */
512 done:
513 LeaveCriticalSection(&(device->mixlock));
514 RtlReleaseResource(&(device->buffer_list_lock));
515 /* **** */
517 HeapFree(GetProcessHeap(), 0, old_fmt);
518 return err;
521 /*******************************************************************************
522 * PrimaryBuffer
524 static inline IDirectSoundBufferImpl *impl_from_IDirectSoundBuffer(IDirectSoundBuffer *iface)
526 /* IDirectSoundBuffer and IDirectSoundBuffer8 use the same iface. */
527 return CONTAINING_RECORD(iface, IDirectSoundBufferImpl, IDirectSoundBuffer8_iface);
530 /* This sets this format for the <em>Primary Buffer Only</em> */
531 /* See file:///cdrom/sdk52/docs/worddoc/dsound.doc page 120 */
532 static HRESULT WINAPI PrimaryBufferImpl_SetFormat(
533 LPDIRECTSOUNDBUFFER iface,
534 LPCWAVEFORMATEX wfex)
536 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
537 TRACE("(%p,%p)\n", iface, wfex);
538 return primarybuffer_SetFormat(This->device, wfex);
541 static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
542 LPDIRECTSOUNDBUFFER iface,LONG vol
544 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
545 DirectSoundDevice *device = This->device;
546 HRESULT hr;
547 float lvol, rvol;
549 TRACE("(%p,%d)\n", iface, vol);
551 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
552 WARN("control unavailable\n");
553 return DSERR_CONTROLUNAVAIL;
556 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
557 WARN("invalid parameter: vol = %d\n", vol);
558 return DSERR_INVALIDPARAM;
561 /* **** */
562 EnterCriticalSection(&device->mixlock);
564 hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol);
565 if(FAILED(hr)){
566 LeaveCriticalSection(&device->mixlock);
567 WARN("GetChannelVolume failed: %08x\n", hr);
568 return hr;
571 if(device->pwfx->nChannels > 1){
572 hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol);
573 if(FAILED(hr)){
574 LeaveCriticalSection(&device->mixlock);
575 WARN("GetChannelVolume failed: %08x\n", hr);
576 return hr;
578 }else
579 rvol = 1;
581 device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF));
582 device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF));
584 DSOUND_AmpFactorToVolPan(&device->volpan);
585 if (vol != device->volpan.lVolume) {
586 device->volpan.lVolume=vol;
587 DSOUND_RecalcVolPan(&device->volpan);
588 lvol = (float)((DWORD)(device->volpan.dwTotalLeftAmpFactor & 0xFFFF) / (float)0xFFFF);
589 hr = IAudioStreamVolume_SetChannelVolume(device->volume, 0, lvol);
590 if(FAILED(hr)){
591 LeaveCriticalSection(&device->mixlock);
592 WARN("SetChannelVolume failed: %08x\n", hr);
593 return hr;
596 if(device->pwfx->nChannels > 1){
597 rvol = (float)((DWORD)(device->volpan.dwTotalRightAmpFactor & 0xFFFF) / (float)0xFFFF);
598 hr = IAudioStreamVolume_SetChannelVolume(device->volume, 1, rvol);
599 if(FAILED(hr)){
600 LeaveCriticalSection(&device->mixlock);
601 WARN("SetChannelVolume failed: %08x\n", hr);
602 return hr;
607 LeaveCriticalSection(&(device->mixlock));
608 /* **** */
610 return DS_OK;
613 static HRESULT WINAPI PrimaryBufferImpl_GetVolume(
614 LPDIRECTSOUNDBUFFER iface,LPLONG vol
616 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
617 DirectSoundDevice *device = This->device;
618 float lvol, rvol;
619 HRESULT hr;
620 TRACE("(%p,%p)\n", iface, vol);
622 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
623 WARN("control unavailable\n");
624 return DSERR_CONTROLUNAVAIL;
627 if (vol == NULL) {
628 WARN("invalid parameter: vol = NULL\n");
629 return DSERR_INVALIDPARAM;
632 EnterCriticalSection(&device->mixlock);
634 hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol);
635 if(FAILED(hr)){
636 LeaveCriticalSection(&device->mixlock);
637 WARN("GetChannelVolume failed: %08x\n", hr);
638 return hr;
641 if(device->pwfx->nChannels > 1){
642 hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol);
643 if(FAILED(hr)){
644 LeaveCriticalSection(&device->mixlock);
645 WARN("GetChannelVolume failed: %08x\n", hr);
646 return hr;
648 }else
649 rvol = 1;
651 device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF));
652 device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF));
654 DSOUND_AmpFactorToVolPan(&device->volpan);
655 *vol = device->volpan.lVolume;
657 LeaveCriticalSection(&device->mixlock);
659 return DS_OK;
662 static HRESULT WINAPI PrimaryBufferImpl_SetFrequency(
663 LPDIRECTSOUNDBUFFER iface,DWORD freq
665 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
666 TRACE("(%p,%d)\n",This,freq);
668 /* You cannot set the frequency of the primary buffer */
669 WARN("control unavailable\n");
670 return DSERR_CONTROLUNAVAIL;
673 static HRESULT WINAPI PrimaryBufferImpl_Play(
674 LPDIRECTSOUNDBUFFER iface,DWORD reserved1,DWORD reserved2,DWORD flags
676 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
677 DirectSoundDevice *device = This->device;
678 TRACE("(%p,%08x,%08x,%08x)\n", iface, reserved1, reserved2, flags);
680 if (!(flags & DSBPLAY_LOOPING)) {
681 WARN("invalid parameter: flags = %08x\n", flags);
682 return DSERR_INVALIDPARAM;
685 /* **** */
686 EnterCriticalSection(&(device->mixlock));
688 if (device->state == STATE_STOPPED)
689 device->state = STATE_STARTING;
690 else if (device->state == STATE_STOPPING)
691 device->state = STATE_PLAYING;
693 LeaveCriticalSection(&(device->mixlock));
694 /* **** */
696 return DS_OK;
699 static HRESULT WINAPI PrimaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER iface)
701 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
702 DirectSoundDevice *device = This->device;
703 TRACE("(%p)\n", iface);
705 /* **** */
706 EnterCriticalSection(&(device->mixlock));
708 if (device->state == STATE_PLAYING)
709 device->state = STATE_STOPPING;
710 else if (device->state == STATE_STARTING)
711 device->state = STATE_STOPPED;
713 LeaveCriticalSection(&(device->mixlock));
714 /* **** */
716 return DS_OK;
719 static ULONG WINAPI PrimaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER iface)
721 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
722 ULONG ref = InterlockedIncrement(&(This->ref));
723 TRACE("(%p) ref was %d\n", This, ref - 1);
724 if(ref == 1)
725 InterlockedIncrement(&This->numIfaces);
726 return ref;
729 void primarybuffer_destroy(IDirectSoundBufferImpl *This)
731 This->device->primary = NULL;
732 HeapFree(GetProcessHeap(), 0, This);
733 TRACE("(%p) released\n", This);
736 static ULONG WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER iface)
738 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
739 DWORD ref = InterlockedDecrement(&(This->ref));
740 TRACE("(%p) ref was %d\n", This, ref + 1);
742 if (!ref && !InterlockedDecrement(&This->numIfaces))
743 primarybuffer_destroy(This);
744 return ref;
747 static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(
748 LPDIRECTSOUNDBUFFER iface,LPDWORD playpos,LPDWORD writepos
750 HRESULT hres;
751 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
752 DirectSoundDevice *device = This->device;
753 TRACE("(%p,%p,%p)\n", iface, playpos, writepos);
755 /* **** */
756 EnterCriticalSection(&(device->mixlock));
758 hres = DSOUND_PrimaryGetPosition(device, playpos, writepos);
759 if (hres != DS_OK) {
760 WARN("DSOUND_PrimaryGetPosition failed\n");
761 LeaveCriticalSection(&(device->mixlock));
762 return hres;
764 if (writepos) {
765 if (device->state != STATE_STOPPED)
766 /* apply the documented 10ms lead to writepos */
767 *writepos += device->writelead;
768 while (*writepos >= device->buflen) *writepos -= device->buflen;
771 LeaveCriticalSection(&(device->mixlock));
772 /* **** */
774 TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:0, writepos?*writepos:0, device, GetTickCount());
775 return DS_OK;
778 static HRESULT WINAPI PrimaryBufferImpl_GetStatus(
779 LPDIRECTSOUNDBUFFER iface,LPDWORD status
781 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
782 DirectSoundDevice *device = This->device;
783 TRACE("(%p,%p)\n", iface, status);
785 if (status == NULL) {
786 WARN("invalid parameter: status == NULL\n");
787 return DSERR_INVALIDPARAM;
790 *status = 0;
791 if ((device->state == STATE_STARTING) ||
792 (device->state == STATE_PLAYING))
793 *status |= DSBSTATUS_PLAYING | DSBSTATUS_LOOPING;
795 TRACE("status=%x\n", *status);
796 return DS_OK;
800 static HRESULT WINAPI PrimaryBufferImpl_GetFormat(
801 LPDIRECTSOUNDBUFFER iface,
802 LPWAVEFORMATEX lpwf,
803 DWORD wfsize,
804 LPDWORD wfwritten)
806 DWORD size;
807 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
808 DirectSoundDevice *device = This->device;
809 TRACE("(%p,%p,%d,%p)\n", iface, lpwf, wfsize, wfwritten);
811 size = sizeof(WAVEFORMATEX) + device->pwfx->cbSize;
813 if (lpwf) { /* NULL is valid */
814 if (wfsize >= size) {
815 CopyMemory(lpwf,device->pwfx,size);
816 if (wfwritten)
817 *wfwritten = size;
818 } else {
819 WARN("invalid parameter: wfsize too small\n");
820 if (wfwritten)
821 *wfwritten = 0;
822 return DSERR_INVALIDPARAM;
824 } else {
825 if (wfwritten)
826 *wfwritten = sizeof(WAVEFORMATEX) + device->pwfx->cbSize;
827 else {
828 WARN("invalid parameter: wfwritten == NULL\n");
829 return DSERR_INVALIDPARAM;
833 return DS_OK;
836 static HRESULT WINAPI PrimaryBufferImpl_Lock(
837 LPDIRECTSOUNDBUFFER iface,DWORD writecursor,DWORD writebytes,LPVOID *lplpaudioptr1,LPDWORD audiobytes1,LPVOID *lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
839 HRESULT hres;
840 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
841 DirectSoundDevice *device = This->device;
842 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n",
843 iface,
844 writecursor,
845 writebytes,
846 lplpaudioptr1,
847 audiobytes1,
848 lplpaudioptr2,
849 audiobytes2,
850 flags,
851 GetTickCount()
854 if (!audiobytes1)
855 return DSERR_INVALIDPARAM;
857 if (device->priolevel != DSSCL_WRITEPRIMARY) {
858 WARN("failed priority check!\n");
859 return DSERR_PRIOLEVELNEEDED;
862 /* when this flag is set, writecursor is meaningless and must be calculated */
863 if (flags & DSBLOCK_FROMWRITECURSOR) {
864 /* GetCurrentPosition does too much magic to duplicate here */
865 hres = IDirectSoundBuffer_GetCurrentPosition(iface, NULL, &writecursor);
866 if (hres != DS_OK) {
867 WARN("IDirectSoundBuffer_GetCurrentPosition failed\n");
868 return hres;
872 /* when this flag is set, writebytes is meaningless and must be set */
873 if (flags & DSBLOCK_ENTIREBUFFER)
874 writebytes = device->buflen;
876 if (writecursor >= device->buflen) {
877 WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
878 writecursor, device->buflen);
879 return DSERR_INVALIDPARAM;
882 if (writebytes > device->buflen) {
883 WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
884 writebytes, device->buflen);
885 return DSERR_INVALIDPARAM;
888 if (writecursor+writebytes <= device->buflen) {
889 *(LPBYTE*)lplpaudioptr1 = device->buffer+writecursor;
890 *audiobytes1 = writebytes;
891 if (lplpaudioptr2)
892 *(LPBYTE*)lplpaudioptr2 = NULL;
893 if (audiobytes2)
894 *audiobytes2 = 0;
895 TRACE("->%d.0\n",writebytes);
896 } else {
897 *(LPBYTE*)lplpaudioptr1 = device->buffer+writecursor;
898 *audiobytes1 = device->buflen-writecursor;
899 if (lplpaudioptr2)
900 *(LPBYTE*)lplpaudioptr2 = device->buffer;
901 if (audiobytes2)
902 *audiobytes2 = writebytes-(device->buflen-writecursor);
903 TRACE("->%d.%d\n",*audiobytes1,audiobytes2?*audiobytes2:0);
905 return DS_OK;
908 static HRESULT WINAPI PrimaryBufferImpl_SetCurrentPosition(
909 LPDIRECTSOUNDBUFFER iface,DWORD newpos
911 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
912 TRACE("(%p,%d)\n",This,newpos);
914 /* You cannot set the position of the primary buffer */
915 WARN("invalid call\n");
916 return DSERR_INVALIDCALL;
919 static HRESULT WINAPI PrimaryBufferImpl_SetPan(
920 LPDIRECTSOUNDBUFFER iface,LONG pan
922 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
923 DirectSoundDevice *device = This->device;
924 float lvol, rvol;
925 HRESULT hr;
926 TRACE("(%p,%d)\n", iface, pan);
928 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
929 WARN("control unavailable\n");
930 return DSERR_CONTROLUNAVAIL;
933 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
934 WARN("invalid parameter: pan = %d\n", pan);
935 return DSERR_INVALIDPARAM;
938 /* **** */
939 EnterCriticalSection(&device->mixlock);
941 hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol);
942 if(FAILED(hr)){
943 LeaveCriticalSection(&device->mixlock);
944 WARN("GetChannelVolume failed: %08x\n", hr);
945 return hr;
948 if(device->pwfx->nChannels > 1){
949 hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol);
950 if(FAILED(hr)){
951 LeaveCriticalSection(&device->mixlock);
952 WARN("GetChannelVolume failed: %08x\n", hr);
953 return hr;
955 }else
956 rvol = 1;
958 device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF));
959 device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF));
961 DSOUND_AmpFactorToVolPan(&device->volpan);
962 if (pan != device->volpan.lPan) {
963 device->volpan.lPan=pan;
964 DSOUND_RecalcVolPan(&device->volpan);
966 lvol = (float)((DWORD)(device->volpan.dwTotalLeftAmpFactor & 0xFFFF) / (float)0xFFFF);
967 hr = IAudioStreamVolume_SetChannelVolume(device->volume, 0, lvol);
968 if(FAILED(hr)){
969 LeaveCriticalSection(&device->mixlock);
970 WARN("SetChannelVolume failed: %08x\n", hr);
971 return hr;
974 if(device->pwfx->nChannels > 1){
975 rvol = (float)((DWORD)(device->volpan.dwTotalRightAmpFactor & 0xFFFF) / (float)0xFFFF);
976 hr = IAudioStreamVolume_SetChannelVolume(device->volume, 1, rvol);
977 if(FAILED(hr)){
978 LeaveCriticalSection(&device->mixlock);
979 WARN("SetChannelVolume failed: %08x\n", hr);
980 return hr;
985 LeaveCriticalSection(&device->mixlock);
986 /* **** */
988 return DS_OK;
991 static HRESULT WINAPI PrimaryBufferImpl_GetPan(
992 LPDIRECTSOUNDBUFFER iface,LPLONG pan
994 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
995 DirectSoundDevice *device = This->device;
996 float lvol, rvol;
997 HRESULT hr;
998 TRACE("(%p,%p)\n", iface, pan);
1000 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
1001 WARN("control unavailable\n");
1002 return DSERR_CONTROLUNAVAIL;
1005 if (pan == NULL) {
1006 WARN("invalid parameter: pan == NULL\n");
1007 return DSERR_INVALIDPARAM;
1010 EnterCriticalSection(&device->mixlock);
1012 hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol);
1013 if(FAILED(hr)){
1014 LeaveCriticalSection(&device->mixlock);
1015 WARN("GetChannelVolume failed: %08x\n", hr);
1016 return hr;
1019 if(device->pwfx->nChannels > 1){
1020 hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol);
1021 if(FAILED(hr)){
1022 LeaveCriticalSection(&device->mixlock);
1023 WARN("GetChannelVolume failed: %08x\n", hr);
1024 return hr;
1026 }else
1027 rvol = 1;
1029 device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF));
1030 device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF));
1032 DSOUND_AmpFactorToVolPan(&device->volpan);
1033 *pan = device->volpan.lPan;
1035 LeaveCriticalSection(&device->mixlock);
1037 return DS_OK;
1040 static HRESULT WINAPI PrimaryBufferImpl_Unlock(
1041 LPDIRECTSOUNDBUFFER iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
1043 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
1044 DirectSoundDevice *device = This->device;
1045 TRACE("(%p,%p,%d,%p,%d)\n", iface, p1, x1, p2, x2);
1047 if (device->priolevel != DSSCL_WRITEPRIMARY) {
1048 WARN("failed priority check!\n");
1049 return DSERR_PRIOLEVELNEEDED;
1052 if((p1 && ((BYTE*)p1 < device->buffer ||
1053 (BYTE*)p1 >= device->buffer + device->buflen)) ||
1054 (p2 && ((BYTE*)p2 < device->buffer ||
1055 (BYTE*)p2 >= device->buffer + device->buflen)))
1056 return DSERR_INVALIDPARAM;
1058 return DS_OK;
1061 static HRESULT WINAPI PrimaryBufferImpl_Restore(
1062 LPDIRECTSOUNDBUFFER iface
1064 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
1065 FIXME("(%p):stub\n",This);
1066 return DS_OK;
1069 static HRESULT WINAPI PrimaryBufferImpl_GetFrequency(
1070 LPDIRECTSOUNDBUFFER iface,LPDWORD freq
1072 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
1073 DirectSoundDevice *device = This->device;
1074 TRACE("(%p,%p)\n", iface, freq);
1076 if (freq == NULL) {
1077 WARN("invalid parameter: freq == NULL\n");
1078 return DSERR_INVALIDPARAM;
1081 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
1082 WARN("control unavailable\n");
1083 return DSERR_CONTROLUNAVAIL;
1086 *freq = device->pwfx->nSamplesPerSec;
1087 TRACE("-> %d\n", *freq);
1089 return DS_OK;
1092 static HRESULT WINAPI PrimaryBufferImpl_Initialize(
1093 LPDIRECTSOUNDBUFFER iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
1095 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
1096 WARN("(%p) already initialized\n", This);
1097 return DSERR_ALREADYINITIALIZED;
1100 static HRESULT WINAPI PrimaryBufferImpl_GetCaps(
1101 LPDIRECTSOUNDBUFFER iface,LPDSBCAPS caps
1103 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
1104 DirectSoundDevice *device = This->device;
1105 TRACE("(%p,%p)\n", iface, caps);
1107 if (caps == NULL) {
1108 WARN("invalid parameter: caps == NULL\n");
1109 return DSERR_INVALIDPARAM;
1112 if (caps->dwSize < sizeof(*caps)) {
1113 WARN("invalid parameter: caps->dwSize = %d\n", caps->dwSize);
1114 return DSERR_INVALIDPARAM;
1117 caps->dwFlags = This->dsbd.dwFlags;
1118 caps->dwBufferBytes = device->buflen;
1120 /* Windows reports these as zero */
1121 caps->dwUnlockTransferRate = 0;
1122 caps->dwPlayCpuOverhead = 0;
1124 return DS_OK;
1127 static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(
1128 LPDIRECTSOUNDBUFFER iface,REFIID riid,LPVOID *ppobj
1130 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
1131 DirectSoundDevice *device = This->device;
1132 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
1134 if (ppobj == NULL) {
1135 WARN("invalid parameter\n");
1136 return E_INVALIDARG;
1139 *ppobj = NULL; /* assume failure */
1141 if ( IsEqualGUID(riid, &IID_IUnknown) ||
1142 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ) {
1143 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)This);
1144 *ppobj = This;
1145 return S_OK;
1148 /* DirectSoundBuffer and DirectSoundBuffer8 are different and */
1149 /* a primary buffer can't have a DirectSoundBuffer8 interface */
1150 if ( IsEqualGUID( &IID_IDirectSoundBuffer8, riid ) ) {
1151 WARN("app requested DirectSoundBuffer8 on primary buffer\n");
1152 return E_NOINTERFACE;
1155 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
1156 ERR("app requested IDirectSoundNotify on primary buffer\n");
1157 /* FIXME: should we support this? */
1158 return E_NOINTERFACE;
1161 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
1162 ERR("app requested IDirectSound3DBuffer on primary buffer\n");
1163 return E_NOINTERFACE;
1166 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
1167 if (!device->listener)
1168 IDirectSound3DListenerImpl_Create(device, &device->listener);
1169 if (device->listener) {
1170 *ppobj = device->listener;
1171 IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)*ppobj);
1172 return S_OK;
1175 WARN("IID_IDirectSound3DListener failed\n");
1176 return E_NOINTERFACE;
1179 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
1180 FIXME("app requested IKsPropertySet on primary buffer\n");
1181 return E_NOINTERFACE;
1184 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
1185 return E_NOINTERFACE;
1188 static const IDirectSoundBufferVtbl dspbvt =
1190 PrimaryBufferImpl_QueryInterface,
1191 PrimaryBufferImpl_AddRef,
1192 PrimaryBufferImpl_Release,
1193 PrimaryBufferImpl_GetCaps,
1194 PrimaryBufferImpl_GetCurrentPosition,
1195 PrimaryBufferImpl_GetFormat,
1196 PrimaryBufferImpl_GetVolume,
1197 PrimaryBufferImpl_GetPan,
1198 PrimaryBufferImpl_GetFrequency,
1199 PrimaryBufferImpl_GetStatus,
1200 PrimaryBufferImpl_Initialize,
1201 PrimaryBufferImpl_Lock,
1202 PrimaryBufferImpl_Play,
1203 PrimaryBufferImpl_SetCurrentPosition,
1204 PrimaryBufferImpl_SetFormat,
1205 PrimaryBufferImpl_SetVolume,
1206 PrimaryBufferImpl_SetPan,
1207 PrimaryBufferImpl_SetFrequency,
1208 PrimaryBufferImpl_Stop,
1209 PrimaryBufferImpl_Unlock,
1210 PrimaryBufferImpl_Restore
1213 HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
1214 const DSBUFFERDESC *dsbd)
1216 IDirectSoundBufferImpl *dsb;
1217 TRACE("%p,%p,%p)\n",device,ppdsb,dsbd);
1219 if (dsbd->lpwfxFormat) {
1220 WARN("invalid parameter: dsbd->lpwfxFormat != NULL\n");
1221 *ppdsb = NULL;
1222 return DSERR_INVALIDPARAM;
1225 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
1227 if (dsb == NULL) {
1228 WARN("out of memory\n");
1229 *ppdsb = NULL;
1230 return DSERR_OUTOFMEMORY;
1233 dsb->ref = 1;
1234 dsb->numIfaces = 1;
1235 dsb->device = device;
1236 dsb->IDirectSoundBuffer8_iface.lpVtbl = (IDirectSoundBuffer8Vtbl *)&dspbvt;
1237 dsb->dsbd = *dsbd;
1239 TRACE("Created primary buffer at %p\n", dsb);
1240 TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
1241 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
1242 device->pwfx->wFormatTag, device->pwfx->nChannels,
1243 device->pwfx->nSamplesPerSec, device->pwfx->nAvgBytesPerSec,
1244 device->pwfx->nBlockAlign, device->pwfx->wBitsPerSample,
1245 device->pwfx->cbSize);
1247 *ppdsb = dsb;
1248 return S_OK;