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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/types.h>
27 #include <sys/fcntl.h>
35 #define NONAMELESSSTRUCT
36 #define NONAMELESSUNION
46 #include "wine/windef16.h"
47 #include "wine/debug.h"
50 #include "dsound_private.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
54 /*******************************************************************************
57 static HRESULT WINAPI IDirectSoundNotifyImpl_QueryInterface(
58 LPDIRECTSOUNDNOTIFY iface,REFIID riid,LPVOID *ppobj
60 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
61 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
63 if (This->dsb == NULL) {
64 WARN("invalid parameter\n");
68 return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER)This->dsb, riid, ppobj);
71 static ULONG WINAPI IDirectSoundNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
73 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
74 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
75 return InterlockedIncrement(&(This->ref));
78 static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface) {
79 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
82 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
84 ref = InterlockedDecrement(&(This->ref));
86 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)This->dsb);
87 This->dsb->notify = NULL;
88 HeapFree(GetProcessHeap(),0,This);
89 TRACE("(%p) released\n",This);
94 static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
95 LPDIRECTSOUNDNOTIFY iface,DWORD howmuch,LPCDSBPOSITIONNOTIFY notify
97 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
98 TRACE("(%p,0x%08lx,%p)\n",This,howmuch,notify);
100 if (howmuch > 0 && notify == NULL) {
101 WARN("invalid parameter: notify == NULL\n");
102 return DSERR_INVALIDPARAM;
105 if (TRACE_ON(dsound)) {
107 for (i=0;i<howmuch;i++)
108 TRACE("notify at %ld to 0x%08lx\n",
109 notify[i].dwOffset,(DWORD)notify[i].hEventNotify);
112 if (This->dsb->hwnotify) {
114 hres = IDsDriverNotify_SetNotificationPositions(This->dsb->hwnotify, howmuch, notify);
116 WARN("IDsDriverNotify_SetNotificationPositions failed\n");
118 } else if (howmuch > 0) {
119 /* Make an internal copy of the caller-supplied array.
120 * Replace the existing copy if one is already present. */
121 if (This->dsb->notifies)
122 This->dsb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
123 This->dsb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
125 This->dsb->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
126 howmuch * sizeof(DSBPOSITIONNOTIFY));
128 if (This->dsb->notifies == NULL) {
129 WARN("out of memory\n");
130 return DSERR_OUTOFMEMORY;
132 memcpy(This->dsb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
133 This->dsb->nrofnotifies = howmuch;
135 HeapFree(GetProcessHeap(), 0, This->dsb->notifies);
136 This->dsb->notifies = NULL;
137 This->dsb->nrofnotifies = 0;
143 IDirectSoundNotifyVtbl dsnvt =
145 IDirectSoundNotifyImpl_QueryInterface,
146 IDirectSoundNotifyImpl_AddRef,
147 IDirectSoundNotifyImpl_Release,
148 IDirectSoundNotifyImpl_SetNotificationPositions,
151 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
152 IDirectSoundBufferImpl * dsb,
153 IDirectSoundNotifyImpl **pdsn)
155 IDirectSoundNotifyImpl * dsn;
156 TRACE("(%p,%p)\n",dsb,pdsn);
158 dsn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dsn));
161 WARN("out of memory\n");
162 return DSERR_OUTOFMEMORY;
166 dsn->lpVtbl = &dsnvt;
169 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
175 HRESULT WINAPI IDirectSoundNotifyImpl_Destroy(
176 IDirectSoundNotifyImpl *pdsn)
178 TRACE("(%p)\n",pdsn);
180 while (IDirectSoundNotifyImpl_Release((LPDIRECTSOUNDNOTIFY)pdsn) > 0);
185 /*******************************************************************************
189 static HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(
190 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex
192 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
194 TRACE("(%p,%p)\n",This,wfex);
195 /* This method is not available on secondary buffers */
196 WARN("invalid call\n");
197 return DSERR_INVALIDCALL;
200 static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
201 LPDIRECTSOUNDBUFFER8 iface,LONG vol
203 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
205 HRESULT hres = DS_OK;
207 TRACE("(%p,%ld)\n",This,vol);
209 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
210 WARN("control unavailable: This->dsbd.dwFlags = 0x%08lx\n", This->dsbd.dwFlags);
211 return DSERR_CONTROLUNAVAIL;
214 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
215 WARN("invalid parameter: vol = %ld\n", vol);
216 return DSERR_INVALIDPARAM;
220 EnterCriticalSection(&(This->lock));
222 if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) {
223 oldVol = This->ds3db_lVolume;
224 This->ds3db_lVolume = vol;
226 oldVol = This->volpan.lVolume;
227 This->volpan.lVolume = vol;
229 DSOUND_RecalcVolPan(&(This->volpan));
234 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
236 WARN("IDsDriverBuffer_SetVolumePan failed\n");
238 DSOUND_ForceRemix(This);
241 LeaveCriticalSection(&(This->lock));
247 static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(
248 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
250 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
251 TRACE("(%p,%p)\n",This,vol);
253 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
254 WARN("control unavailable\n");
255 return DSERR_CONTROLUNAVAIL;
259 WARN("invalid parameter: vol == NULL\n");
260 return DSERR_INVALIDPARAM;
263 *vol = This->volpan.lVolume;
268 static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
269 LPDIRECTSOUNDBUFFER8 iface,DWORD freq
271 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
274 TRACE("(%p,%ld)\n",This,freq);
276 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
277 WARN("control unavailable\n");
278 return DSERR_CONTROLUNAVAIL;
281 if (freq == DSBFREQUENCY_ORIGINAL)
282 freq = This->pwfx->nSamplesPerSec;
284 if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX)) {
285 WARN("invalid parameter: freq = %ld\n", freq);
286 return DSERR_INVALIDPARAM;
290 EnterCriticalSection(&(This->lock));
292 oldFreq = This->freq;
294 if (freq != oldFreq) {
295 This->freqAdjust = (freq << DSOUND_FREQSHIFT) / This->dsound->pwfx->nSamplesPerSec;
296 This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;
297 DSOUND_RecalcFormat(This);
299 DSOUND_ForceRemix(This);
302 LeaveCriticalSection(&(This->lock));
308 static HRESULT WINAPI IDirectSoundBufferImpl_Play(
309 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
311 HRESULT hres = DS_OK;
312 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
313 TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
316 EnterCriticalSection(&(This->lock));
318 This->playflags = flags;
319 if (This->state == STATE_STOPPED) {
321 This->startpos = This->buf_mixpos;
322 This->state = STATE_STARTING;
323 } else if (This->state == STATE_STOPPING)
324 This->state = STATE_PLAYING;
326 hres = IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
328 WARN("IDsDriverBuffer_Play failed\n");
330 This->state = STATE_PLAYING;
333 LeaveCriticalSection(&(This->lock));
339 static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
341 HRESULT hres = DS_OK;
342 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
343 TRACE("(%p)\n",This);
346 EnterCriticalSection(&(This->lock));
348 if (This->state == STATE_PLAYING)
349 This->state = STATE_STOPPING;
350 else if (This->state == STATE_STARTING)
351 This->state = STATE_STOPPED;
353 hres = IDsDriverBuffer_Stop(This->hwbuf);
355 WARN("IDsDriverBuffer_Stop failed\n");
357 This->state = STATE_STOPPED;
359 DSOUND_CheckEvent(This, 0);
361 LeaveCriticalSection(&(This->lock));
367 static ULONG WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
369 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
370 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
371 return InterlockedIncrement(&(This->ref));
374 static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
376 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
379 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
381 ref = InterlockedDecrement(&(This->ref));
385 DSOUND_RemoveBuffer(This->dsound, This);
387 This->lock.DebugInfo->Spare[1] = 0;
388 DeleteCriticalSection(&(This->lock));
391 IDsDriverBuffer_Release(This->hwbuf);
392 if (This->dsound->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
394 if (This->buffer->ref==0) {
395 HeapFree(GetProcessHeap(),0,This->buffer->memory);
396 HeapFree(GetProcessHeap(),0,This->buffer);
401 if (This->buffer->ref==0) {
402 HeapFree(GetProcessHeap(),0,This->buffer->memory);
403 HeapFree(GetProcessHeap(),0,This->buffer);
407 HeapFree(GetProcessHeap(), 0, This->notifies);
408 HeapFree(GetProcessHeap(), 0, This->pwfx);
409 HeapFree(GetProcessHeap(),0,This);
411 TRACE("(%p) released\n",This);
415 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
416 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix)
420 TRACE("primary playpos=%ld, mixpos=%ld\n", pplay, pmix);
421 TRACE("this mixpos=%ld, time=%ld\n", bmix, GetTickCount());
423 /* the actual primary play position (pplay) is always behind last mixed (pmix),
424 * unless the computer is too slow or something */
425 /* we need to know how far away we are from there */
426 #if 0 /* we'll never fill the primary entirely */
428 if ((state == STATE_PLAYING) || (state == STATE_STOPPING)) {
429 /* wow, the software mixer is really doing well,
430 * seems the entire primary buffer is filled! */
431 pmix += This->dsound->buflen;
433 /* else: the primary buffer is not playing, so probably empty */
436 if (pmix < pplay) pmix += This->dsound->buflen; /* wraparound */
438 /* detect buffer underrun */
439 if (pwrite < pplay) pwrite += This->dsound->buflen; /* wraparound */
441 if (pmix > (ds_snd_queue_max * This->dsound->fraglen + pwrite + This->dsound->writelead)) {
442 WARN("detected an underrun: primary queue was %ld\n",pmix);
445 /* divide the offset by its sample size */
446 pmix /= This->dsound->pwfx->nBlockAlign;
447 TRACE("primary back-samples=%ld\n",pmix);
448 /* adjust for our frequency */
449 pmix = (pmix * This->freqAdjust) >> DSOUND_FREQSHIFT;
450 /* multiply by our own sample size */
451 pmix *= This->pwfx->nBlockAlign;
452 TRACE("this back-offset=%ld\n", pmix);
453 /* subtract from our last mixed position */
455 while (bplay < pmix) bplay += This->buflen; /* wraparound */
457 if (This->leadin && ((bplay < This->startpos) || (bplay > bmix))) {
458 /* seems we haven't started playing yet */
459 TRACE("this still in lead-in phase\n");
460 bplay = This->startpos;
462 /* return the result */
466 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
467 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
470 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
471 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
473 hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
475 WARN("IDsDriverBuffer_GetPosition failed\n");
479 if (playpos && (This->state != STATE_PLAYING)) {
480 /* we haven't been merged into the primary buffer (yet) */
481 *playpos = This->buf_mixpos;
482 } else if (playpos) {
483 DWORD pplay, pwrite, lplay, splay, pstate;
484 /* let's get this exact; first, recursively call GetPosition on the primary */
485 EnterCriticalSection(&(This->dsound->mixlock));
486 if (DSOUND_PrimaryGetPosition(This->dsound, &pplay, &pwrite) != DS_OK)
487 WARN("DSOUND_PrimaryGetPosition failed\n");
488 /* detect HEL mode underrun */
489 pstate = This->dsound->state;
490 if (!(This->dsound->hwbuf || This->dsound->pwqueue)) {
491 TRACE("detected an underrun\n");
493 if (pstate == STATE_PLAYING)
494 pstate = STATE_STARTING;
495 else if (pstate == STATE_STOPPING)
496 pstate = STATE_STOPPED;
498 /* get data for ourselves while we still have the lock */
499 pstate &= This->state;
500 lplay = This->primary_mixpos;
501 splay = This->buf_mixpos;
502 if ((This->dsbd.dwFlags & DSBCAPS_GETCURRENTPOSITION2) || This->dsound->hwbuf) {
503 /* calculate play position using this */
504 *playpos = DSOUND_CalcPlayPosition(This, pstate, pplay, pwrite, lplay, splay);
506 /* (unless the app isn't using GETCURRENTPOSITION2) */
507 /* don't know exactly how this should be handled...
508 * the docs says that play cursor is reported as directly
509 * behind write cursor, hmm... */
510 /* let's just do what might work for Half-Life */
512 wp = (This->dsound->pwplay + ds_hel_margin) * This->dsound->fraglen;
513 wp %= This->dsound->buflen;
514 *playpos = DSOUND_CalcPlayPosition(This, pstate, wp, pwrite, lplay, splay);
516 LeaveCriticalSection(&(This->dsound->mixlock));
519 *writepos = This->buf_mixpos;
522 if (This->state != STATE_STOPPED) {
523 /* apply the documented 10ms lead to writepos */
524 *writepos += This->writelead;
526 *writepos %= This->buflen;
529 This->last_playpos = *playpos;
530 TRACE("playpos = %ld, writepos = %ld (%p, time=%ld)\n", playpos?*playpos:0, writepos?*writepos:0, This, GetTickCount());
534 static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
535 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
537 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
538 TRACE("(%p,%p), thread is %04lx\n",This,status,GetCurrentThreadId());
540 if (status == NULL) {
541 WARN("invalid parameter: status = NULL\n");
542 return DSERR_INVALIDPARAM;
546 if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
547 *status |= DSBSTATUS_PLAYING;
548 if (This->playflags & DSBPLAY_LOOPING)
549 *status |= DSBSTATUS_LOOPING;
552 TRACE("status=%lx\n", *status);
557 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
558 LPDIRECTSOUNDBUFFER8 iface,
564 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
565 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
567 size = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
569 if (lpwf) { /* NULL is valid */
570 if (wfsize >= size) {
571 memcpy(lpwf,This->pwfx,size);
575 WARN("invalid parameter: wfsize to small\n");
578 return DSERR_INVALIDPARAM;
582 *wfwritten = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
584 WARN("invalid parameter: wfwritten == NULL\n");
585 return DSERR_INVALIDPARAM;
592 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
593 LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
595 HRESULT hres = DS_OK;
596 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
598 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n",
610 if (flags & DSBLOCK_FROMWRITECURSOR) {
612 /* GetCurrentPosition does too much magic to duplicate here */
613 hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writepos);
615 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
618 writecursor += writepos;
620 writecursor %= This->buflen;
621 if (flags & DSBLOCK_ENTIREBUFFER)
622 writebytes = This->buflen;
623 if (writebytes > This->buflen)
624 writebytes = This->buflen;
626 EnterCriticalSection(&(This->lock));
628 if ((writebytes == This->buflen) &&
629 ((This->state == STATE_STARTING) ||
630 (This->state == STATE_PLAYING)))
631 /* some games, like Half-Life, try to be clever (not) and
632 * keep one secondary buffer, and mix sounds into it itself,
633 * locking the entire buffer every time... so we can just forget
634 * about tracking the last-written-to-position... */
635 This->probably_valid_to = (DWORD)-1;
637 This->probably_valid_to = writecursor;
639 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
640 hres = IDsDriverBuffer_Lock(This->hwbuf,
641 lplpaudioptr1, audiobytes1,
642 lplpaudioptr2, audiobytes2,
643 writecursor, writebytes,
646 WARN("IDsDriverBuffer_Lock failed\n");
647 LeaveCriticalSection(&(This->lock));
652 if (writecursor+writebytes <= This->buflen) {
653 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
654 *audiobytes1 = writebytes;
656 *(LPBYTE*)lplpaudioptr2 = NULL;
659 TRACE("->%ld.0\n",writebytes);
661 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
662 *audiobytes1 = This->buflen-writecursor;
664 *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
666 *audiobytes2 = writebytes-(This->buflen-writecursor);
667 TRACE("->%ld.%ld\n",*audiobytes1,audiobytes2?*audiobytes2:0);
669 if (This->state == STATE_PLAYING) {
670 /* if the segment between playpos and buf_mixpos is touched,
671 * we need to cancel some mixing */
672 /* we'll assume that the app always calls GetCurrentPosition before
673 * locking a playing buffer, so that last_playpos is up-to-date */
674 if (This->buf_mixpos >= This->last_playpos) {
675 if (This->buf_mixpos > writecursor &&
676 This->last_playpos < writecursor+writebytes)
679 if (This->buf_mixpos > writecursor ||
680 This->last_playpos < writecursor+writebytes)
684 TRACE("locking prebuffered region, ouch\n");
685 DSOUND_MixCancelAt(This, writecursor);
690 LeaveCriticalSection(&(This->lock));
694 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
695 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
697 HRESULT hres = DS_OK;
698 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
699 TRACE("(%p,%ld)\n",This,newpos);
702 EnterCriticalSection(&(This->lock));
704 newpos %= This->buflen;
705 This->buf_mixpos = newpos;
707 hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
709 WARN("IDsDriverBuffer_SetPosition failed\n");
712 LeaveCriticalSection(&(This->lock));
718 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
719 LPDIRECTSOUNDBUFFER8 iface,LONG pan
721 HRESULT hres = DS_OK;
722 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
724 TRACE("(%p,%ld)\n",This,pan);
726 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
727 WARN("invalid parameter: pan = %ld\n", pan);
728 return DSERR_INVALIDPARAM;
731 /* You cannot use both pan and 3D controls */
732 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
733 (This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
734 WARN("control unavailable\n");
735 return DSERR_CONTROLUNAVAIL;
739 EnterCriticalSection(&(This->lock));
741 if (This->volpan.lPan != pan) {
742 This->volpan.lPan = pan;
743 DSOUND_RecalcVolPan(&(This->volpan));
746 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
748 WARN("IDsDriverBuffer_SetVolumePan failed\n");
750 DSOUND_ForceRemix(This);
753 LeaveCriticalSection(&(This->lock));
759 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
760 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
762 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
763 TRACE("(%p,%p)\n",This,pan);
765 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
766 WARN("control unavailable\n");
767 return DSERR_CONTROLUNAVAIL;
771 WARN("invalid parameter: pan = NULL\n");
772 return DSERR_INVALIDPARAM;
775 *pan = This->volpan.lPan;
780 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
781 LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
783 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
784 DWORD probably_valid_to;
785 HRESULT hres = DS_OK;
787 TRACE("(%p,%p,%ld,%p,%ld)\n", This,p1,x1,p2,x2);
790 EnterCriticalSection(&(This->lock));
792 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
793 hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
795 WARN("IDsDriverBuffer_Unlock failed\n");
799 if (p2) probably_valid_to = (((LPBYTE)p2)-This->buffer->memory) + x2;
800 else probably_valid_to = (((LPBYTE)p1)-This->buffer->memory) + x1;
801 probably_valid_to %= This->buflen;
802 if ((probably_valid_to == 0) && ((x1+x2) == This->buflen) &&
803 ((This->state == STATE_STARTING) ||
804 (This->state == STATE_PLAYING)))
805 /* see IDirectSoundBufferImpl_Lock */
806 probably_valid_to = (DWORD)-1;
807 This->probably_valid_to = probably_valid_to;
810 LeaveCriticalSection(&(This->lock));
813 TRACE("probably_valid_to=%ld\n", This->probably_valid_to);
817 static HRESULT WINAPI IDirectSoundBufferImpl_Restore(
818 LPDIRECTSOUNDBUFFER8 iface
820 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
821 FIXME("(%p):stub\n",This);
825 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
826 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
828 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
829 TRACE("(%p,%p)\n",This,freq);
832 WARN("invalid parameter: freq = NULL\n");
833 return DSERR_INVALIDPARAM;
837 TRACE("-> %ld\n", *freq);
842 static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(
843 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
845 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
848 FIXME("(%p,%lu,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
851 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
853 WARN("control unavailable\n");
854 return DSERR_CONTROLUNAVAIL;
857 static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(
858 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
860 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
863 FIXME("(%p,%08lu,%lu,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
866 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
868 WARN("control unavailable\n");
869 return DSERR_CONTROLUNAVAIL;
872 static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(
873 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
875 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
877 FIXME("(%p,%s,%lu,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
879 WARN("control unavailable\n");
880 return DSERR_CONTROLUNAVAIL;
883 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
884 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
886 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
887 FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
888 DPRINTF("Re-Init!!!\n");
889 WARN("already initialized\n");
890 return DSERR_ALREADYINITIALIZED;
893 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
894 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
896 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
897 TRACE("(%p)->(%p)\n",This,caps);
900 WARN("invalid parameter: caps == NULL\n");
901 return DSERR_INVALIDPARAM;
904 if (caps->dwSize < sizeof(*caps)) {
905 WARN("invalid parameter: caps->dwSize = %ld < %d\n",caps->dwSize, sizeof(*caps));
906 return DSERR_INVALIDPARAM;
909 caps->dwFlags = This->dsbd.dwFlags;
910 if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
911 else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
913 caps->dwBufferBytes = This->buflen;
915 /* This value represents the speed of the "unlock" command.
916 As unlock is quite fast (it does not do anything), I put
917 4096 ko/s = 4 Mo / s */
918 /* FIXME: hwbuf speed */
919 caps->dwUnlockTransferRate = 4096;
920 caps->dwPlayCpuOverhead = 0;
925 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
926 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
928 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
930 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
933 WARN("invalid parameter\n");
937 *ppobj = NULL; /* assume failure */
939 if ( IsEqualGUID(riid, &IID_IUnknown) ||
940 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
941 IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
943 SecondaryBufferImpl_Create(This, &(This->dsb));
945 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)This->dsb);
949 WARN("IID_IDirectSoundBuffer\n");
950 return E_NOINTERFACE;
953 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
955 IDirectSoundNotifyImpl_Create(This, &(This->notify));
957 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
958 *ppobj = This->notify;
961 WARN("IID_IDirectSoundNotify\n");
962 return E_NOINTERFACE;
965 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
967 IDirectSound3DBufferImpl_Create(This, &(This->ds3db));
969 IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->ds3db);
970 *ppobj = This->ds3db;
973 WARN("IID_IDirectSound3DBuffer\n");
974 return E_NOINTERFACE;
977 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
978 ERR("app requested IDirectSound3DListener on secondary buffer\n");
979 return E_NOINTERFACE;
982 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
984 IKsBufferPropertySetImpl_Create(This, &(This->iks));
986 IKsPropertySet_AddRef((LPKSPROPERTYSET)This->iks);
990 WARN("IID_IKsPropertySet\n");
991 return E_NOINTERFACE;
994 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
996 return E_NOINTERFACE;
999 static IDirectSoundBuffer8Vtbl dsbvt =
1001 IDirectSoundBufferImpl_QueryInterface,
1002 IDirectSoundBufferImpl_AddRef,
1003 IDirectSoundBufferImpl_Release,
1004 IDirectSoundBufferImpl_GetCaps,
1005 IDirectSoundBufferImpl_GetCurrentPosition,
1006 IDirectSoundBufferImpl_GetFormat,
1007 IDirectSoundBufferImpl_GetVolume,
1008 IDirectSoundBufferImpl_GetPan,
1009 IDirectSoundBufferImpl_GetFrequency,
1010 IDirectSoundBufferImpl_GetStatus,
1011 IDirectSoundBufferImpl_Initialize,
1012 IDirectSoundBufferImpl_Lock,
1013 IDirectSoundBufferImpl_Play,
1014 IDirectSoundBufferImpl_SetCurrentPosition,
1015 IDirectSoundBufferImpl_SetFormat,
1016 IDirectSoundBufferImpl_SetVolume,
1017 IDirectSoundBufferImpl_SetPan,
1018 IDirectSoundBufferImpl_SetFrequency,
1019 IDirectSoundBufferImpl_Stop,
1020 IDirectSoundBufferImpl_Unlock,
1021 IDirectSoundBufferImpl_Restore,
1022 IDirectSoundBufferImpl_SetFX,
1023 IDirectSoundBufferImpl_AcquireResources,
1024 IDirectSoundBufferImpl_GetObjectInPath
1027 HRESULT WINAPI IDirectSoundBufferImpl_Create(
1028 IDirectSoundImpl *ds,
1029 IDirectSoundBufferImpl **pdsb,
1030 LPCDSBUFFERDESC dsbd)
1032 IDirectSoundBufferImpl *dsb;
1033 LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
1034 HRESULT err = DS_OK;
1036 int use_hw, alloc_size, cp_size;
1037 TRACE("(%p,%p,%p)\n",ds,pdsb,dsbd);
1039 if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
1040 WARN("invalid parameter: dsbd->dwBufferBytes = %ld\n", dsbd->dwBufferBytes);
1042 return DSERR_INVALIDPARAM; /* FIXME: which error? */
1045 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
1048 WARN("out of memory\n");
1050 return DSERR_OUTOFMEMORY;
1053 TRACE("Created buffer at %p\n", dsb);
1058 dsb->lpVtbl = &dsbvt;
1061 /* size depends on version */
1062 memcpy(&dsb->dsbd, dsbd, dsbd->dwSize);
1064 /* variable sized struct so calculate size based on format */
1065 if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
1066 alloc_size = sizeof(WAVEFORMATEX);
1067 cp_size = sizeof(PCMWAVEFORMAT);
1069 alloc_size = cp_size = sizeof(WAVEFORMATEX) + wfex->cbSize;
1071 dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,alloc_size);
1072 if (dsb->pwfx == NULL) {
1073 WARN("out of memory\n");
1074 HeapFree(GetProcessHeap(),0,dsb);
1076 return DSERR_OUTOFMEMORY;
1079 memcpy(dsb->pwfx, wfex, cp_size);
1081 dsb->buflen = dsbd->dwBufferBytes;
1082 dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
1085 dsb->notifies = NULL;
1086 dsb->nrofnotifies = 0;
1089 /* Check necessary hardware mixing capabilities */
1090 if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
1091 else capf |= DSCAPS_SECONDARYMONO;
1092 if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
1093 else capf |= DSCAPS_SECONDARY8BIT;
1095 use_hw = (ds->drvcaps.dwFlags & capf) == capf;
1096 TRACE("use_hw = 0x%08x, capf = 0x%08lx, ds->drvcaps.dwFlags = 0x%08lx\n", use_hw, capf, ds->drvcaps.dwFlags);
1098 /* FIXME: check hardware sample rate mixing capabilities */
1099 /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
1100 /* FIXME: check whether any hardware buffers are left */
1101 /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
1103 /* Allocate system memory if applicable */
1104 if ((ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
1105 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1106 if (dsb->buffer == NULL) {
1107 WARN("out of memory\n");
1108 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1109 HeapFree(GetProcessHeap(),0,dsb);
1111 return DSERR_OUTOFMEMORY;
1114 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1115 if (dsb->buffer->memory == NULL) {
1116 WARN("out of memory\n");
1117 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1118 HeapFree(GetProcessHeap(),0,dsb->buffer);
1119 HeapFree(GetProcessHeap(),0,dsb);
1121 return DSERR_OUTOFMEMORY;
1123 dsb->buffer->ref = 1;
1126 /* Allocate the hardware buffer */
1128 err = IDsDriver_CreateSoundBuffer(ds->driver,wfex,dsbd->dwFlags,0,
1129 &(dsb->buflen),&(dsb->buffer->memory),
1130 (LPVOID*)&(dsb->hwbuf));
1131 /* fall back to software buffer on failure */
1133 TRACE("IDsDriver_CreateSoundBuffer failed, falling back to software buffer\n");
1135 if (ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
1136 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1137 if (dsb->buffer == NULL) {
1138 WARN("out of memory\n");
1139 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1140 HeapFree(GetProcessHeap(),0,dsb);
1142 return DSERR_OUTOFMEMORY;
1145 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1146 if (dsb->buffer->memory == NULL) {
1147 WARN("out of memory\n");
1148 HeapFree(GetProcessHeap(),0,dsb->buffer);
1149 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1150 HeapFree(GetProcessHeap(),0,dsb);
1152 return DSERR_OUTOFMEMORY;
1154 dsb->buffer->ref = 1;
1160 /* calculate fragment size and write lead */
1161 DSOUND_RecalcFormat(dsb);
1163 /* It's not necessary to initialize values to zero since */
1164 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1166 dsb->buf_mixpos = 0;
1167 dsb->state = STATE_STOPPED;
1169 dsb->freqAdjust = (dsb->freq << DSOUND_FREQSHIFT) /
1170 ds->pwfx->nSamplesPerSec;
1171 dsb->nAvgBytesPerSec = dsb->freq *
1172 dsbd->lpwfxFormat->nBlockAlign;
1174 if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
1175 dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
1176 dsb->ds3db_ds3db.vPosition.x = 0.0;
1177 dsb->ds3db_ds3db.vPosition.y = 0.0;
1178 dsb->ds3db_ds3db.vPosition.z = 0.0;
1179 dsb->ds3db_ds3db.vVelocity.x = 0.0;
1180 dsb->ds3db_ds3db.vVelocity.y = 0.0;
1181 dsb->ds3db_ds3db.vVelocity.z = 0.0;
1182 dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1183 dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1184 dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
1185 dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
1186 dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
1187 dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1188 dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1189 dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1190 dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
1192 dsb->ds3db_need_recalc = FALSE;
1193 DSOUND_Calc3DBuffer(dsb);
1195 DSOUND_RecalcVolPan(&(dsb->volpan));
1197 InitializeCriticalSection(&(dsb->lock));
1198 dsb->lock.DebugInfo->Spare[1] = (DWORD)"DSOUNDBUFFER_lock";
1200 /* register buffer if not primary */
1201 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1202 err = DSOUND_AddBuffer(ds, dsb);
1204 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1205 HeapFree(GetProcessHeap(),0,dsb->buffer);
1206 dsb->lock.DebugInfo->Spare[1] = 0;
1207 DeleteCriticalSection(&(dsb->lock));
1208 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1209 HeapFree(GetProcessHeap(),0,dsb);
1218 HRESULT WINAPI IDirectSoundBufferImpl_Destroy(
1219 IDirectSoundBufferImpl *pdsb)
1221 TRACE("(%p)\n",pdsb);
1223 /* This keeps the *_Destroy functions from possibly deleting
1224 * this object until it is ready to be deleted */
1225 IDirectSoundBufferImpl_AddRef((LPDIRECTSOUNDBUFFER8)pdsb);
1228 WARN("iks not NULL\n");
1229 IKsBufferPropertySetImpl_Destroy(pdsb->iks);
1234 WARN("ds3db not NULL\n");
1235 IDirectSound3DBufferImpl_Destroy(pdsb->ds3db);
1240 WARN("notify not NULL\n");
1241 IDirectSoundNotifyImpl_Destroy(pdsb->notify);
1242 pdsb->notify = NULL;
1246 WARN("dsb not NULL\n");
1247 SecondaryBufferImpl_Destroy(pdsb->dsb);
1251 while (IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);
1256 /*******************************************************************************
1260 static HRESULT WINAPI SecondaryBufferImpl_QueryInterface(
1261 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj)
1263 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1264 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
1266 return IDirectSoundBufferImpl_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb,riid,ppobj);
1269 static ULONG WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
1271 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
1272 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1273 return InterlockedIncrement(&(This->ref));
1276 static ULONG WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
1278 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
1280 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1282 ref = InterlockedDecrement(&(This->ref));
1284 This->dsb->dsb = NULL;
1285 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
1286 HeapFree(GetProcessHeap(),0,This);
1287 TRACE("(%p) released\n",This);
1292 static HRESULT WINAPI SecondaryBufferImpl_GetCaps(
1293 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps)
1295 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1296 TRACE("(%p)->(%p)\n",This,caps);
1298 return IDirectSoundBufferImpl_GetCaps((LPDIRECTSOUNDBUFFER8)This->dsb,caps);
1301 static HRESULT WINAPI SecondaryBufferImpl_GetCurrentPosition(
1302 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos)
1304 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1305 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
1307 return IDirectSoundBufferImpl_GetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,playpos,writepos);
1310 static HRESULT WINAPI SecondaryBufferImpl_GetFormat(
1311 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten)
1313 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1314 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
1316 return IDirectSoundBufferImpl_GetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,lpwf,wfsize,wfwritten);
1319 static HRESULT WINAPI SecondaryBufferImpl_GetVolume(
1320 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol)
1322 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1323 TRACE("(%p,%p)\n",This,vol);
1325 return IDirectSoundBufferImpl_GetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1328 static HRESULT WINAPI SecondaryBufferImpl_GetPan(
1329 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan)
1331 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1332 TRACE("(%p,%p)\n",This,pan);
1334 return IDirectSoundBufferImpl_GetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1337 static HRESULT WINAPI SecondaryBufferImpl_GetFrequency(
1338 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq)
1340 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1341 TRACE("(%p,%p)\n",This,freq);
1343 return IDirectSoundBufferImpl_GetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1346 static HRESULT WINAPI SecondaryBufferImpl_GetStatus(
1347 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status)
1349 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1350 TRACE("(%p,%p)\n",This,status);
1352 return IDirectSoundBufferImpl_GetStatus((LPDIRECTSOUNDBUFFER8)This->dsb,status);
1355 static HRESULT WINAPI SecondaryBufferImpl_Initialize(
1356 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd)
1358 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1359 TRACE("(%p,%p,%p)\n",This,dsound,dbsd);
1361 return IDirectSoundBufferImpl_Initialize((LPDIRECTSOUNDBUFFER8)This->dsb,dsound,dbsd);
1364 static HRESULT WINAPI SecondaryBufferImpl_Lock(
1365 LPDIRECTSOUNDBUFFER8 iface,
1368 LPVOID lplpaudioptr1,
1369 LPDWORD audiobytes1,
1370 LPVOID lplpaudioptr2,
1371 LPDWORD audiobytes2,
1374 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1375 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx)\n",
1376 This,writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1378 return IDirectSoundBufferImpl_Lock((LPDIRECTSOUNDBUFFER8)This->dsb,
1379 writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1382 static HRESULT WINAPI SecondaryBufferImpl_Play(
1383 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags)
1385 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1386 TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
1388 return IDirectSoundBufferImpl_Play((LPDIRECTSOUNDBUFFER8)This->dsb,reserved1,reserved2,flags);
1391 static HRESULT WINAPI SecondaryBufferImpl_SetCurrentPosition(
1392 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos)
1394 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1395 TRACE("(%p,%ld)\n",This,newpos);
1397 return IDirectSoundBufferImpl_SetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,newpos);
1400 static HRESULT WINAPI SecondaryBufferImpl_SetFormat(
1401 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex)
1403 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1404 TRACE("(%p,%p)\n",This,wfex);
1406 return IDirectSoundBufferImpl_SetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,wfex);
1409 static HRESULT WINAPI SecondaryBufferImpl_SetVolume(
1410 LPDIRECTSOUNDBUFFER8 iface,LONG vol)
1412 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1413 TRACE("(%p,%ld)\n",This,vol);
1415 return IDirectSoundBufferImpl_SetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1418 static HRESULT WINAPI SecondaryBufferImpl_SetPan(
1419 LPDIRECTSOUNDBUFFER8 iface,LONG pan)
1421 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1422 TRACE("(%p,%ld)\n",This,pan);
1424 return IDirectSoundBufferImpl_SetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1427 static HRESULT WINAPI SecondaryBufferImpl_SetFrequency(
1428 LPDIRECTSOUNDBUFFER8 iface,DWORD freq)
1430 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1431 TRACE("(%p,%ld)\n",This,freq);
1433 return IDirectSoundBufferImpl_SetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1436 static HRESULT WINAPI SecondaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
1438 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1439 TRACE("(%p)\n",This);
1441 return IDirectSoundBufferImpl_Stop((LPDIRECTSOUNDBUFFER8)This->dsb);
1444 static HRESULT WINAPI SecondaryBufferImpl_Unlock(
1445 LPDIRECTSOUNDBUFFER8 iface,
1446 LPVOID lpvAudioPtr1,
1447 DWORD dwAudioBytes1,
1448 LPVOID lpvAudioPtr2,
1449 DWORD dwAudioBytes2)
1451 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1452 TRACE("(%p,%p,%ld,%p,%ld)\n",
1453 This, lpvAudioPtr1, dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1455 return IDirectSoundBufferImpl_Unlock((LPDIRECTSOUNDBUFFER8)This->dsb,
1456 lpvAudioPtr1,dwAudioBytes1,lpvAudioPtr2,dwAudioBytes2);
1459 static HRESULT WINAPI SecondaryBufferImpl_Restore(
1460 LPDIRECTSOUNDBUFFER8 iface)
1462 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1463 TRACE("(%p)\n",This);
1465 return IDirectSoundBufferImpl_Restore((LPDIRECTSOUNDBUFFER8)This->dsb);
1468 static HRESULT WINAPI SecondaryBufferImpl_SetFX(
1469 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes)
1471 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1472 TRACE("(%p,%lu,%p,%p)\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1474 return IDirectSoundBufferImpl_SetFX((LPDIRECTSOUNDBUFFER8)This->dsb,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1477 static HRESULT WINAPI SecondaryBufferImpl_AcquireResources(
1478 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes)
1480 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1481 TRACE("(%p,%08lu,%lu,%p)\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
1483 return IDirectSoundBufferImpl_AcquireResources((LPDIRECTSOUNDBUFFER8)This->dsb,dwFlags,dwEffectsCount,pdwResultCodes);
1486 static HRESULT WINAPI SecondaryBufferImpl_GetObjectInPath(
1487 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject)
1489 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1490 TRACE("(%p,%s,%lu,%s,%p)\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
1492 return IDirectSoundBufferImpl_GetObjectInPath((LPDIRECTSOUNDBUFFER8)This->dsb,rguidObject,dwIndex,rguidInterface,ppObject);
1495 static IDirectSoundBuffer8Vtbl sbvt =
1497 SecondaryBufferImpl_QueryInterface,
1498 SecondaryBufferImpl_AddRef,
1499 SecondaryBufferImpl_Release,
1500 SecondaryBufferImpl_GetCaps,
1501 SecondaryBufferImpl_GetCurrentPosition,
1502 SecondaryBufferImpl_GetFormat,
1503 SecondaryBufferImpl_GetVolume,
1504 SecondaryBufferImpl_GetPan,
1505 SecondaryBufferImpl_GetFrequency,
1506 SecondaryBufferImpl_GetStatus,
1507 SecondaryBufferImpl_Initialize,
1508 SecondaryBufferImpl_Lock,
1509 SecondaryBufferImpl_Play,
1510 SecondaryBufferImpl_SetCurrentPosition,
1511 SecondaryBufferImpl_SetFormat,
1512 SecondaryBufferImpl_SetVolume,
1513 SecondaryBufferImpl_SetPan,
1514 SecondaryBufferImpl_SetFrequency,
1515 SecondaryBufferImpl_Stop,
1516 SecondaryBufferImpl_Unlock,
1517 SecondaryBufferImpl_Restore,
1518 SecondaryBufferImpl_SetFX,
1519 SecondaryBufferImpl_AcquireResources,
1520 SecondaryBufferImpl_GetObjectInPath
1523 HRESULT WINAPI SecondaryBufferImpl_Create(
1524 IDirectSoundBufferImpl *dsb,
1525 SecondaryBufferImpl **psb)
1527 SecondaryBufferImpl *sb;
1528 TRACE("(%p,%p)\n",dsb,psb);
1530 sb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*sb));
1533 WARN("out of memory\n");
1535 return DSERR_OUTOFMEMORY;
1541 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
1546 HRESULT WINAPI SecondaryBufferImpl_Destroy(
1547 SecondaryBufferImpl *pdsb)
1549 TRACE("(%p)\n",pdsb);
1551 while (SecondaryBufferImpl_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);