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
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
31 #include "wine/debug.h"
34 #include "dsound_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
38 /*******************************************************************************
41 static HRESULT WINAPI IDirectSoundNotifyImpl_QueryInterface(
42 LPDIRECTSOUNDNOTIFY iface,REFIID riid,LPVOID *ppobj
44 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
45 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
47 if (This->dsb == NULL) {
48 WARN("invalid parameter\n");
52 return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER)This->dsb, riid, ppobj);
55 static ULONG WINAPI IDirectSoundNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
57 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
58 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
59 return InterlockedIncrement(&(This->ref));
62 static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface) {
63 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
66 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
68 ref = InterlockedDecrement(&(This->ref));
70 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)This->dsb);
71 This->dsb->notify = NULL;
72 HeapFree(GetProcessHeap(),0,This);
73 TRACE("(%p) released\n",This);
78 static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
79 LPDIRECTSOUNDNOTIFY iface,DWORD howmuch,LPCDSBPOSITIONNOTIFY notify
81 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
82 TRACE("(%p,0x%08lx,%p)\n",This,howmuch,notify);
84 if (howmuch > 0 && notify == NULL) {
85 WARN("invalid parameter: notify == NULL\n");
86 return DSERR_INVALIDPARAM;
89 if (TRACE_ON(dsound)) {
91 for (i=0;i<howmuch;i++)
92 TRACE("notify at %ld to 0x%08lx\n",
93 notify[i].dwOffset,(DWORD)notify[i].hEventNotify);
96 if (This->dsb->hwnotify) {
98 hres = IDsDriverNotify_SetNotificationPositions(This->dsb->hwnotify, howmuch, notify);
100 WARN("IDsDriverNotify_SetNotificationPositions failed\n");
102 } else if (howmuch > 0) {
103 /* Make an internal copy of the caller-supplied array.
104 * Replace the existing copy if one is already present. */
105 if (This->dsb->notifies)
106 This->dsb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
107 This->dsb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
109 This->dsb->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
110 howmuch * sizeof(DSBPOSITIONNOTIFY));
112 if (This->dsb->notifies == NULL) {
113 WARN("out of memory\n");
114 return DSERR_OUTOFMEMORY;
116 CopyMemory(This->dsb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
117 This->dsb->nrofnotifies = howmuch;
119 HeapFree(GetProcessHeap(), 0, This->dsb->notifies);
120 This->dsb->notifies = NULL;
121 This->dsb->nrofnotifies = 0;
127 IDirectSoundNotifyVtbl dsnvt =
129 IDirectSoundNotifyImpl_QueryInterface,
130 IDirectSoundNotifyImpl_AddRef,
131 IDirectSoundNotifyImpl_Release,
132 IDirectSoundNotifyImpl_SetNotificationPositions,
135 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
136 IDirectSoundBufferImpl * dsb,
137 IDirectSoundNotifyImpl **pdsn)
139 IDirectSoundNotifyImpl * dsn;
140 TRACE("(%p,%p)\n",dsb,pdsn);
142 dsn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dsn));
145 WARN("out of memory\n");
146 return DSERR_OUTOFMEMORY;
150 dsn->lpVtbl = &dsnvt;
153 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
159 HRESULT WINAPI IDirectSoundNotifyImpl_Destroy(
160 IDirectSoundNotifyImpl *pdsn)
162 TRACE("(%p)\n",pdsn);
164 while (IDirectSoundNotifyImpl_Release((LPDIRECTSOUNDNOTIFY)pdsn) > 0);
169 /*******************************************************************************
173 static HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(
174 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex
176 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
178 TRACE("(%p,%p)\n",This,wfex);
179 /* This method is not available on secondary buffers */
180 WARN("invalid call\n");
181 return DSERR_INVALIDCALL;
184 static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
185 LPDIRECTSOUNDBUFFER8 iface,LONG vol
187 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
189 HRESULT hres = DS_OK;
191 TRACE("(%p,%ld)\n",This,vol);
193 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
194 WARN("control unavailable: This->dsbd.dwFlags = 0x%08lx\n", This->dsbd.dwFlags);
195 return DSERR_CONTROLUNAVAIL;
198 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
199 WARN("invalid parameter: vol = %ld\n", vol);
200 return DSERR_INVALIDPARAM;
204 EnterCriticalSection(&(This->lock));
206 if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) {
207 oldVol = This->ds3db_lVolume;
208 This->ds3db_lVolume = vol;
210 oldVol = This->volpan.lVolume;
211 This->volpan.lVolume = vol;
213 DSOUND_RecalcVolPan(&(This->volpan));
218 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
220 WARN("IDsDriverBuffer_SetVolumePan failed\n");
222 DSOUND_ForceRemix(This);
225 LeaveCriticalSection(&(This->lock));
231 static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(
232 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
234 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
235 TRACE("(%p,%p)\n",This,vol);
237 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
238 WARN("control unavailable\n");
239 return DSERR_CONTROLUNAVAIL;
243 WARN("invalid parameter: vol == NULL\n");
244 return DSERR_INVALIDPARAM;
247 *vol = This->volpan.lVolume;
252 static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
253 LPDIRECTSOUNDBUFFER8 iface,DWORD freq
255 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
258 TRACE("(%p,%ld)\n",This,freq);
260 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
261 WARN("control unavailable\n");
262 return DSERR_CONTROLUNAVAIL;
265 if (freq == DSBFREQUENCY_ORIGINAL)
266 freq = This->pwfx->nSamplesPerSec;
268 if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX)) {
269 WARN("invalid parameter: freq = %ld\n", freq);
270 return DSERR_INVALIDPARAM;
274 EnterCriticalSection(&(This->lock));
276 oldFreq = This->freq;
278 if (freq != oldFreq) {
279 This->freqAdjust = (freq << DSOUND_FREQSHIFT) / This->dsound->pwfx->nSamplesPerSec;
280 This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;
281 DSOUND_RecalcFormat(This);
283 DSOUND_ForceRemix(This);
286 LeaveCriticalSection(&(This->lock));
292 static HRESULT WINAPI IDirectSoundBufferImpl_Play(
293 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
295 HRESULT hres = DS_OK;
296 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
297 TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
300 EnterCriticalSection(&(This->lock));
302 This->playflags = flags;
303 if (This->state == STATE_STOPPED) {
305 This->startpos = This->buf_mixpos;
306 This->state = STATE_STARTING;
307 } else if (This->state == STATE_STOPPING)
308 This->state = STATE_PLAYING;
310 hres = IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
312 WARN("IDsDriverBuffer_Play failed\n");
314 This->state = STATE_PLAYING;
317 LeaveCriticalSection(&(This->lock));
323 static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
325 HRESULT hres = DS_OK;
326 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
327 TRACE("(%p)\n",This);
330 EnterCriticalSection(&(This->lock));
332 if (This->state == STATE_PLAYING)
333 This->state = STATE_STOPPING;
334 else if (This->state == STATE_STARTING)
335 This->state = STATE_STOPPED;
337 hres = IDsDriverBuffer_Stop(This->hwbuf);
339 WARN("IDsDriverBuffer_Stop failed\n");
341 This->state = STATE_STOPPED;
343 DSOUND_CheckEvent(This, 0);
345 LeaveCriticalSection(&(This->lock));
351 static ULONG WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
353 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
354 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
355 return InterlockedIncrement(&(This->ref));
358 static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
360 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
363 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
365 ref = InterlockedDecrement(&(This->ref));
369 DSOUND_RemoveBuffer(This->dsound, This);
371 This->lock.DebugInfo->Spare[1] = 0;
372 DeleteCriticalSection(&(This->lock));
375 IDsDriverBuffer_Release(This->hwbuf);
376 if (This->dsound->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
378 if (This->buffer->ref==0) {
379 HeapFree(GetProcessHeap(),0,This->buffer->memory);
380 HeapFree(GetProcessHeap(),0,This->buffer);
385 if (This->buffer->ref==0) {
386 HeapFree(GetProcessHeap(),0,This->buffer->memory);
387 HeapFree(GetProcessHeap(),0,This->buffer);
391 HeapFree(GetProcessHeap(), 0, This->notifies);
392 HeapFree(GetProcessHeap(), 0, This->pwfx);
393 HeapFree(GetProcessHeap(),0,This);
395 TRACE("(%p) released\n",This);
399 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
400 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix)
404 TRACE("primary playpos=%ld, mixpos=%ld\n", pplay, pmix);
405 TRACE("this mixpos=%ld, time=%ld\n", bmix, GetTickCount());
407 /* the actual primary play position (pplay) is always behind last mixed (pmix),
408 * unless the computer is too slow or something */
409 /* we need to know how far away we are from there */
410 #if 0 /* we'll never fill the primary entirely */
412 if ((state == STATE_PLAYING) || (state == STATE_STOPPING)) {
413 /* wow, the software mixer is really doing well,
414 * seems the entire primary buffer is filled! */
415 pmix += This->dsound->buflen;
417 /* else: the primary buffer is not playing, so probably empty */
420 if (pmix < pplay) pmix += This->dsound->buflen; /* wraparound */
422 /* detect buffer underrun */
423 if (pwrite < pplay) pwrite += This->dsound->buflen; /* wraparound */
425 if (pmix > (ds_snd_queue_max * This->dsound->fraglen + pwrite + This->dsound->writelead)) {
426 WARN("detected an underrun: primary queue was %ld\n",pmix);
429 /* divide the offset by its sample size */
430 pmix /= This->dsound->pwfx->nBlockAlign;
431 TRACE("primary back-samples=%ld\n",pmix);
432 /* adjust for our frequency */
433 pmix = (pmix * This->freqAdjust) >> DSOUND_FREQSHIFT;
434 /* multiply by our own sample size */
435 pmix *= This->pwfx->nBlockAlign;
436 TRACE("this back-offset=%ld\n", pmix);
437 /* subtract from our last mixed position */
439 while (bplay < pmix) bplay += This->buflen; /* wraparound */
441 if (This->leadin && ((bplay < This->startpos) || (bplay > bmix))) {
442 /* seems we haven't started playing yet */
443 TRACE("this still in lead-in phase\n");
444 bplay = This->startpos;
446 /* return the result */
450 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
451 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
454 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
455 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
457 hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
459 WARN("IDsDriverBuffer_GetPosition failed\n");
463 if (playpos && (This->state != STATE_PLAYING)) {
464 /* we haven't been merged into the primary buffer (yet) */
465 *playpos = This->buf_mixpos;
466 } else if (playpos) {
467 DWORD pplay, pwrite, lplay, splay, pstate;
468 /* let's get this exact; first, recursively call GetPosition on the primary */
469 EnterCriticalSection(&(This->dsound->mixlock));
470 if (DSOUND_PrimaryGetPosition(This->dsound, &pplay, &pwrite) != DS_OK)
471 WARN("DSOUND_PrimaryGetPosition failed\n");
472 /* detect HEL mode underrun */
473 pstate = This->dsound->state;
474 if (!(This->dsound->hwbuf || This->dsound->pwqueue)) {
475 TRACE("detected an underrun\n");
477 if (pstate == STATE_PLAYING)
478 pstate = STATE_STARTING;
479 else if (pstate == STATE_STOPPING)
480 pstate = STATE_STOPPED;
482 /* get data for ourselves while we still have the lock */
483 pstate &= This->state;
484 lplay = This->primary_mixpos;
485 splay = This->buf_mixpos;
486 if ((This->dsbd.dwFlags & DSBCAPS_GETCURRENTPOSITION2) || This->dsound->hwbuf) {
487 /* calculate play position using this */
488 *playpos = DSOUND_CalcPlayPosition(This, pstate, pplay, pwrite, lplay, splay);
490 /* (unless the app isn't using GETCURRENTPOSITION2) */
491 /* don't know exactly how this should be handled...
492 * the docs says that play cursor is reported as directly
493 * behind write cursor, hmm... */
494 /* let's just do what might work for Half-Life */
496 wp = (This->dsound->pwplay + ds_hel_margin) * This->dsound->fraglen;
497 wp %= This->dsound->buflen;
498 *playpos = DSOUND_CalcPlayPosition(This, pstate, wp, pwrite, lplay, splay);
500 LeaveCriticalSection(&(This->dsound->mixlock));
503 *writepos = This->buf_mixpos;
506 if (This->state != STATE_STOPPED) {
507 /* apply the documented 10ms lead to writepos */
508 *writepos += This->writelead;
510 *writepos %= This->buflen;
513 This->last_playpos = *playpos;
514 TRACE("playpos = %ld, writepos = %ld (%p, time=%ld)\n", playpos?*playpos:0, writepos?*writepos:0, This, GetTickCount());
518 static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
519 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
521 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
522 TRACE("(%p,%p), thread is %04lx\n",This,status,GetCurrentThreadId());
524 if (status == NULL) {
525 WARN("invalid parameter: status = NULL\n");
526 return DSERR_INVALIDPARAM;
530 if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
531 *status |= DSBSTATUS_PLAYING;
532 if (This->playflags & DSBPLAY_LOOPING)
533 *status |= DSBSTATUS_LOOPING;
536 TRACE("status=%lx\n", *status);
541 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
542 LPDIRECTSOUNDBUFFER8 iface,
548 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
549 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
551 size = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
553 if (lpwf) { /* NULL is valid */
554 if (wfsize >= size) {
555 CopyMemory(lpwf,This->pwfx,size);
559 WARN("invalid parameter: wfsize to small\n");
562 return DSERR_INVALIDPARAM;
566 *wfwritten = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
568 WARN("invalid parameter: wfwritten == NULL\n");
569 return DSERR_INVALIDPARAM;
576 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
577 LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
579 HRESULT hres = DS_OK;
580 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
582 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n",
594 if (flags & DSBLOCK_FROMWRITECURSOR) {
596 /* GetCurrentPosition does too much magic to duplicate here */
597 hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writepos);
599 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
602 writecursor += writepos;
604 writecursor %= This->buflen;
605 if (flags & DSBLOCK_ENTIREBUFFER)
606 writebytes = This->buflen;
607 if (writebytes > This->buflen)
608 writebytes = This->buflen;
610 EnterCriticalSection(&(This->lock));
612 if ((writebytes == This->buflen) &&
613 ((This->state == STATE_STARTING) ||
614 (This->state == STATE_PLAYING)))
615 /* some games, like Half-Life, try to be clever (not) and
616 * keep one secondary buffer, and mix sounds into it itself,
617 * locking the entire buffer every time... so we can just forget
618 * about tracking the last-written-to-position... */
619 This->probably_valid_to = (DWORD)-1;
621 This->probably_valid_to = writecursor;
623 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
624 hres = IDsDriverBuffer_Lock(This->hwbuf,
625 lplpaudioptr1, audiobytes1,
626 lplpaudioptr2, audiobytes2,
627 writecursor, writebytes,
630 WARN("IDsDriverBuffer_Lock failed\n");
631 LeaveCriticalSection(&(This->lock));
636 if (writecursor+writebytes <= This->buflen) {
637 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
638 *audiobytes1 = writebytes;
640 *(LPBYTE*)lplpaudioptr2 = NULL;
643 TRACE("->%ld.0\n",writebytes);
645 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
646 *audiobytes1 = This->buflen-writecursor;
648 *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
650 *audiobytes2 = writebytes-(This->buflen-writecursor);
651 TRACE("->%ld.%ld\n",*audiobytes1,audiobytes2?*audiobytes2:0);
653 if (This->state == STATE_PLAYING) {
654 /* if the segment between playpos and buf_mixpos is touched,
655 * we need to cancel some mixing */
656 /* we'll assume that the app always calls GetCurrentPosition before
657 * locking a playing buffer, so that last_playpos is up-to-date */
658 if (This->buf_mixpos >= This->last_playpos) {
659 if (This->buf_mixpos > writecursor &&
660 This->last_playpos < writecursor+writebytes)
663 if (This->buf_mixpos > writecursor ||
664 This->last_playpos < writecursor+writebytes)
668 TRACE("locking prebuffered region, ouch\n");
669 DSOUND_MixCancelAt(This, writecursor);
674 LeaveCriticalSection(&(This->lock));
678 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
679 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
681 HRESULT hres = DS_OK;
682 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
683 TRACE("(%p,%ld)\n",This,newpos);
686 EnterCriticalSection(&(This->lock));
688 newpos %= This->buflen;
689 This->buf_mixpos = newpos;
691 hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
693 WARN("IDsDriverBuffer_SetPosition failed\n");
696 LeaveCriticalSection(&(This->lock));
702 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
703 LPDIRECTSOUNDBUFFER8 iface,LONG pan
705 HRESULT hres = DS_OK;
706 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
708 TRACE("(%p,%ld)\n",This,pan);
710 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
711 WARN("invalid parameter: pan = %ld\n", pan);
712 return DSERR_INVALIDPARAM;
715 /* You cannot use both pan and 3D controls */
716 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
717 (This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
718 WARN("control unavailable\n");
719 return DSERR_CONTROLUNAVAIL;
723 EnterCriticalSection(&(This->lock));
725 if (This->volpan.lPan != pan) {
726 This->volpan.lPan = pan;
727 DSOUND_RecalcVolPan(&(This->volpan));
730 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
732 WARN("IDsDriverBuffer_SetVolumePan failed\n");
734 DSOUND_ForceRemix(This);
737 LeaveCriticalSection(&(This->lock));
743 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
744 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
746 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
747 TRACE("(%p,%p)\n",This,pan);
749 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
750 WARN("control unavailable\n");
751 return DSERR_CONTROLUNAVAIL;
755 WARN("invalid parameter: pan = NULL\n");
756 return DSERR_INVALIDPARAM;
759 *pan = This->volpan.lPan;
764 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
765 LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
767 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
768 DWORD probably_valid_to;
769 HRESULT hres = DS_OK;
771 TRACE("(%p,%p,%ld,%p,%ld)\n", This,p1,x1,p2,x2);
774 EnterCriticalSection(&(This->lock));
776 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
777 hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
779 WARN("IDsDriverBuffer_Unlock failed\n");
783 if (p2) probably_valid_to = (((LPBYTE)p2)-This->buffer->memory) + x2;
784 else probably_valid_to = (((LPBYTE)p1)-This->buffer->memory) + x1;
785 probably_valid_to %= This->buflen;
786 if ((probably_valid_to == 0) && ((x1+x2) == This->buflen) &&
787 ((This->state == STATE_STARTING) ||
788 (This->state == STATE_PLAYING)))
789 /* see IDirectSoundBufferImpl_Lock */
790 probably_valid_to = (DWORD)-1;
791 This->probably_valid_to = probably_valid_to;
794 LeaveCriticalSection(&(This->lock));
797 TRACE("probably_valid_to=%ld\n", This->probably_valid_to);
801 static HRESULT WINAPI IDirectSoundBufferImpl_Restore(
802 LPDIRECTSOUNDBUFFER8 iface
804 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
805 FIXME("(%p):stub\n",This);
809 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
810 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
812 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
813 TRACE("(%p,%p)\n",This,freq);
816 WARN("invalid parameter: freq = NULL\n");
817 return DSERR_INVALIDPARAM;
821 TRACE("-> %ld\n", *freq);
826 static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(
827 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
829 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
832 FIXME("(%p,%lu,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
835 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
837 WARN("control unavailable\n");
838 return DSERR_CONTROLUNAVAIL;
841 static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(
842 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
844 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
847 FIXME("(%p,%08lu,%lu,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
850 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
852 WARN("control unavailable\n");
853 return DSERR_CONTROLUNAVAIL;
856 static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(
857 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
859 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
861 FIXME("(%p,%s,%lu,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
863 WARN("control unavailable\n");
864 return DSERR_CONTROLUNAVAIL;
867 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
868 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
870 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
871 FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
872 DPRINTF("Re-Init!!!\n");
873 WARN("already initialized\n");
874 return DSERR_ALREADYINITIALIZED;
877 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
878 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
880 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
881 TRACE("(%p)->(%p)\n",This,caps);
884 WARN("invalid parameter: caps == NULL\n");
885 return DSERR_INVALIDPARAM;
888 if (caps->dwSize < sizeof(*caps)) {
889 WARN("invalid parameter: caps->dwSize = %ld < %d\n",caps->dwSize, sizeof(*caps));
890 return DSERR_INVALIDPARAM;
893 caps->dwFlags = This->dsbd.dwFlags;
894 if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
895 else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
897 caps->dwBufferBytes = This->buflen;
899 /* This value represents the speed of the "unlock" command.
900 As unlock is quite fast (it does not do anything), I put
901 4096 ko/s = 4 Mo / s */
902 /* FIXME: hwbuf speed */
903 caps->dwUnlockTransferRate = 4096;
904 caps->dwPlayCpuOverhead = 0;
909 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
910 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
912 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
914 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
917 WARN("invalid parameter\n");
921 *ppobj = NULL; /* assume failure */
923 if ( IsEqualGUID(riid, &IID_IUnknown) ||
924 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
925 IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
927 SecondaryBufferImpl_Create(This, &(This->dsb));
929 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)This->dsb);
933 WARN("IID_IDirectSoundBuffer\n");
934 return E_NOINTERFACE;
937 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
939 IDirectSoundNotifyImpl_Create(This, &(This->notify));
941 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
942 *ppobj = This->notify;
945 WARN("IID_IDirectSoundNotify\n");
946 return E_NOINTERFACE;
949 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
951 IDirectSound3DBufferImpl_Create(This, &(This->ds3db));
953 IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->ds3db);
954 *ppobj = This->ds3db;
957 WARN("IID_IDirectSound3DBuffer\n");
958 return E_NOINTERFACE;
961 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
962 ERR("app requested IDirectSound3DListener on secondary buffer\n");
963 return E_NOINTERFACE;
966 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
968 IKsBufferPropertySetImpl_Create(This, &(This->iks));
970 IKsPropertySet_AddRef((LPKSPROPERTYSET)This->iks);
974 WARN("IID_IKsPropertySet\n");
975 return E_NOINTERFACE;
978 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
980 return E_NOINTERFACE;
983 static IDirectSoundBuffer8Vtbl dsbvt =
985 IDirectSoundBufferImpl_QueryInterface,
986 IDirectSoundBufferImpl_AddRef,
987 IDirectSoundBufferImpl_Release,
988 IDirectSoundBufferImpl_GetCaps,
989 IDirectSoundBufferImpl_GetCurrentPosition,
990 IDirectSoundBufferImpl_GetFormat,
991 IDirectSoundBufferImpl_GetVolume,
992 IDirectSoundBufferImpl_GetPan,
993 IDirectSoundBufferImpl_GetFrequency,
994 IDirectSoundBufferImpl_GetStatus,
995 IDirectSoundBufferImpl_Initialize,
996 IDirectSoundBufferImpl_Lock,
997 IDirectSoundBufferImpl_Play,
998 IDirectSoundBufferImpl_SetCurrentPosition,
999 IDirectSoundBufferImpl_SetFormat,
1000 IDirectSoundBufferImpl_SetVolume,
1001 IDirectSoundBufferImpl_SetPan,
1002 IDirectSoundBufferImpl_SetFrequency,
1003 IDirectSoundBufferImpl_Stop,
1004 IDirectSoundBufferImpl_Unlock,
1005 IDirectSoundBufferImpl_Restore,
1006 IDirectSoundBufferImpl_SetFX,
1007 IDirectSoundBufferImpl_AcquireResources,
1008 IDirectSoundBufferImpl_GetObjectInPath
1011 HRESULT WINAPI IDirectSoundBufferImpl_Create(
1012 IDirectSoundImpl *ds,
1013 IDirectSoundBufferImpl **pdsb,
1014 LPCDSBUFFERDESC dsbd)
1016 IDirectSoundBufferImpl *dsb;
1017 LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
1018 HRESULT err = DS_OK;
1020 int use_hw, alloc_size, cp_size;
1021 TRACE("(%p,%p,%p)\n",ds,pdsb,dsbd);
1023 if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
1024 WARN("invalid parameter: dsbd->dwBufferBytes = %ld\n", dsbd->dwBufferBytes);
1026 return DSERR_INVALIDPARAM; /* FIXME: which error? */
1029 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
1032 WARN("out of memory\n");
1034 return DSERR_OUTOFMEMORY;
1037 TRACE("Created buffer at %p\n", dsb);
1042 dsb->lpVtbl = &dsbvt;
1045 /* size depends on version */
1046 CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
1048 /* variable sized struct so calculate size based on format */
1049 if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
1050 alloc_size = sizeof(WAVEFORMATEX);
1051 cp_size = sizeof(PCMWAVEFORMAT);
1053 alloc_size = cp_size = sizeof(WAVEFORMATEX) + wfex->cbSize;
1055 dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,alloc_size);
1056 if (dsb->pwfx == NULL) {
1057 WARN("out of memory\n");
1058 HeapFree(GetProcessHeap(),0,dsb);
1060 return DSERR_OUTOFMEMORY;
1063 CopyMemory(dsb->pwfx, wfex, cp_size);
1065 dsb->buflen = dsbd->dwBufferBytes;
1066 dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
1069 dsb->notifies = NULL;
1070 dsb->nrofnotifies = 0;
1073 /* Check necessary hardware mixing capabilities */
1074 if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
1075 else capf |= DSCAPS_SECONDARYMONO;
1076 if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
1077 else capf |= DSCAPS_SECONDARY8BIT;
1079 use_hw = (ds->drvcaps.dwFlags & capf) == capf;
1080 TRACE("use_hw = 0x%08x, capf = 0x%08lx, ds->drvcaps.dwFlags = 0x%08lx\n", use_hw, capf, ds->drvcaps.dwFlags);
1082 /* FIXME: check hardware sample rate mixing capabilities */
1083 /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
1084 /* FIXME: check whether any hardware buffers are left */
1085 /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
1087 /* Allocate system memory if applicable */
1088 if ((ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
1089 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1090 if (dsb->buffer == NULL) {
1091 WARN("out of memory\n");
1092 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1093 HeapFree(GetProcessHeap(),0,dsb);
1095 return DSERR_OUTOFMEMORY;
1098 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1099 if (dsb->buffer->memory == NULL) {
1100 WARN("out of memory\n");
1101 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1102 HeapFree(GetProcessHeap(),0,dsb->buffer);
1103 HeapFree(GetProcessHeap(),0,dsb);
1105 return DSERR_OUTOFMEMORY;
1107 dsb->buffer->ref = 1;
1110 /* Allocate the hardware buffer */
1112 err = IDsDriver_CreateSoundBuffer(ds->driver,wfex,dsbd->dwFlags,0,
1113 &(dsb->buflen),&(dsb->buffer->memory),
1114 (LPVOID*)&(dsb->hwbuf));
1115 /* fall back to software buffer on failure */
1117 TRACE("IDsDriver_CreateSoundBuffer failed, falling back to software buffer\n");
1119 if (ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
1120 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1121 if (dsb->buffer == NULL) {
1122 WARN("out of memory\n");
1123 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1124 HeapFree(GetProcessHeap(),0,dsb);
1126 return DSERR_OUTOFMEMORY;
1129 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1130 if (dsb->buffer->memory == NULL) {
1131 WARN("out of memory\n");
1132 HeapFree(GetProcessHeap(),0,dsb->buffer);
1133 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1134 HeapFree(GetProcessHeap(),0,dsb);
1136 return DSERR_OUTOFMEMORY;
1138 dsb->buffer->ref = 1;
1144 /* calculate fragment size and write lead */
1145 DSOUND_RecalcFormat(dsb);
1147 /* It's not necessary to initialize values to zero since */
1148 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1150 dsb->buf_mixpos = 0;
1151 dsb->state = STATE_STOPPED;
1153 dsb->freqAdjust = (dsb->freq << DSOUND_FREQSHIFT) /
1154 ds->pwfx->nSamplesPerSec;
1155 dsb->nAvgBytesPerSec = dsb->freq *
1156 dsbd->lpwfxFormat->nBlockAlign;
1158 if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
1159 dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
1160 dsb->ds3db_ds3db.vPosition.x = 0.0;
1161 dsb->ds3db_ds3db.vPosition.y = 0.0;
1162 dsb->ds3db_ds3db.vPosition.z = 0.0;
1163 dsb->ds3db_ds3db.vVelocity.x = 0.0;
1164 dsb->ds3db_ds3db.vVelocity.y = 0.0;
1165 dsb->ds3db_ds3db.vVelocity.z = 0.0;
1166 dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1167 dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1168 dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
1169 dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
1170 dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
1171 dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1172 dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1173 dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1174 dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
1176 dsb->ds3db_need_recalc = FALSE;
1177 DSOUND_Calc3DBuffer(dsb);
1179 DSOUND_RecalcVolPan(&(dsb->volpan));
1181 InitializeCriticalSection(&(dsb->lock));
1182 dsb->lock.DebugInfo->Spare[1] = (DWORD)"DSOUNDBUFFER_lock";
1184 /* register buffer if not primary */
1185 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1186 err = DSOUND_AddBuffer(ds, dsb);
1188 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1189 HeapFree(GetProcessHeap(),0,dsb->buffer);
1190 dsb->lock.DebugInfo->Spare[1] = 0;
1191 DeleteCriticalSection(&(dsb->lock));
1192 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1193 HeapFree(GetProcessHeap(),0,dsb);
1202 HRESULT WINAPI IDirectSoundBufferImpl_Destroy(
1203 IDirectSoundBufferImpl *pdsb)
1205 TRACE("(%p)\n",pdsb);
1207 /* This keeps the *_Destroy functions from possibly deleting
1208 * this object until it is ready to be deleted */
1209 IDirectSoundBufferImpl_AddRef((LPDIRECTSOUNDBUFFER8)pdsb);
1212 WARN("iks not NULL\n");
1213 IKsBufferPropertySetImpl_Destroy(pdsb->iks);
1218 WARN("ds3db not NULL\n");
1219 IDirectSound3DBufferImpl_Destroy(pdsb->ds3db);
1224 WARN("notify not NULL\n");
1225 IDirectSoundNotifyImpl_Destroy(pdsb->notify);
1226 pdsb->notify = NULL;
1230 WARN("dsb not NULL\n");
1231 SecondaryBufferImpl_Destroy(pdsb->dsb);
1235 while (IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);
1240 /*******************************************************************************
1244 static HRESULT WINAPI SecondaryBufferImpl_QueryInterface(
1245 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj)
1247 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1248 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
1250 return IDirectSoundBufferImpl_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb,riid,ppobj);
1253 static ULONG WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
1255 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
1256 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1257 return InterlockedIncrement(&(This->ref));
1260 static ULONG WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
1262 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
1264 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1266 ref = InterlockedDecrement(&(This->ref));
1268 This->dsb->dsb = NULL;
1269 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
1270 HeapFree(GetProcessHeap(),0,This);
1271 TRACE("(%p) released\n",This);
1276 static HRESULT WINAPI SecondaryBufferImpl_GetCaps(
1277 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps)
1279 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1280 TRACE("(%p)->(%p)\n",This,caps);
1282 return IDirectSoundBufferImpl_GetCaps((LPDIRECTSOUNDBUFFER8)This->dsb,caps);
1285 static HRESULT WINAPI SecondaryBufferImpl_GetCurrentPosition(
1286 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos)
1288 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1289 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
1291 return IDirectSoundBufferImpl_GetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,playpos,writepos);
1294 static HRESULT WINAPI SecondaryBufferImpl_GetFormat(
1295 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten)
1297 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1298 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
1300 return IDirectSoundBufferImpl_GetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,lpwf,wfsize,wfwritten);
1303 static HRESULT WINAPI SecondaryBufferImpl_GetVolume(
1304 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol)
1306 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1307 TRACE("(%p,%p)\n",This,vol);
1309 return IDirectSoundBufferImpl_GetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1312 static HRESULT WINAPI SecondaryBufferImpl_GetPan(
1313 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan)
1315 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1316 TRACE("(%p,%p)\n",This,pan);
1318 return IDirectSoundBufferImpl_GetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1321 static HRESULT WINAPI SecondaryBufferImpl_GetFrequency(
1322 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq)
1324 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1325 TRACE("(%p,%p)\n",This,freq);
1327 return IDirectSoundBufferImpl_GetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1330 static HRESULT WINAPI SecondaryBufferImpl_GetStatus(
1331 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status)
1333 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1334 TRACE("(%p,%p)\n",This,status);
1336 return IDirectSoundBufferImpl_GetStatus((LPDIRECTSOUNDBUFFER8)This->dsb,status);
1339 static HRESULT WINAPI SecondaryBufferImpl_Initialize(
1340 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd)
1342 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1343 TRACE("(%p,%p,%p)\n",This,dsound,dbsd);
1345 return IDirectSoundBufferImpl_Initialize((LPDIRECTSOUNDBUFFER8)This->dsb,dsound,dbsd);
1348 static HRESULT WINAPI SecondaryBufferImpl_Lock(
1349 LPDIRECTSOUNDBUFFER8 iface,
1352 LPVOID lplpaudioptr1,
1353 LPDWORD audiobytes1,
1354 LPVOID lplpaudioptr2,
1355 LPDWORD audiobytes2,
1358 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1359 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx)\n",
1360 This,writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1362 return IDirectSoundBufferImpl_Lock((LPDIRECTSOUNDBUFFER8)This->dsb,
1363 writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1366 static HRESULT WINAPI SecondaryBufferImpl_Play(
1367 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags)
1369 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1370 TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
1372 return IDirectSoundBufferImpl_Play((LPDIRECTSOUNDBUFFER8)This->dsb,reserved1,reserved2,flags);
1375 static HRESULT WINAPI SecondaryBufferImpl_SetCurrentPosition(
1376 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos)
1378 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1379 TRACE("(%p,%ld)\n",This,newpos);
1381 return IDirectSoundBufferImpl_SetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,newpos);
1384 static HRESULT WINAPI SecondaryBufferImpl_SetFormat(
1385 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex)
1387 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1388 TRACE("(%p,%p)\n",This,wfex);
1390 return IDirectSoundBufferImpl_SetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,wfex);
1393 static HRESULT WINAPI SecondaryBufferImpl_SetVolume(
1394 LPDIRECTSOUNDBUFFER8 iface,LONG vol)
1396 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1397 TRACE("(%p,%ld)\n",This,vol);
1399 return IDirectSoundBufferImpl_SetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1402 static HRESULT WINAPI SecondaryBufferImpl_SetPan(
1403 LPDIRECTSOUNDBUFFER8 iface,LONG pan)
1405 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1406 TRACE("(%p,%ld)\n",This,pan);
1408 return IDirectSoundBufferImpl_SetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1411 static HRESULT WINAPI SecondaryBufferImpl_SetFrequency(
1412 LPDIRECTSOUNDBUFFER8 iface,DWORD freq)
1414 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1415 TRACE("(%p,%ld)\n",This,freq);
1417 return IDirectSoundBufferImpl_SetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1420 static HRESULT WINAPI SecondaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
1422 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1423 TRACE("(%p)\n",This);
1425 return IDirectSoundBufferImpl_Stop((LPDIRECTSOUNDBUFFER8)This->dsb);
1428 static HRESULT WINAPI SecondaryBufferImpl_Unlock(
1429 LPDIRECTSOUNDBUFFER8 iface,
1430 LPVOID lpvAudioPtr1,
1431 DWORD dwAudioBytes1,
1432 LPVOID lpvAudioPtr2,
1433 DWORD dwAudioBytes2)
1435 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1436 TRACE("(%p,%p,%ld,%p,%ld)\n",
1437 This, lpvAudioPtr1, dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1439 return IDirectSoundBufferImpl_Unlock((LPDIRECTSOUNDBUFFER8)This->dsb,
1440 lpvAudioPtr1,dwAudioBytes1,lpvAudioPtr2,dwAudioBytes2);
1443 static HRESULT WINAPI SecondaryBufferImpl_Restore(
1444 LPDIRECTSOUNDBUFFER8 iface)
1446 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1447 TRACE("(%p)\n",This);
1449 return IDirectSoundBufferImpl_Restore((LPDIRECTSOUNDBUFFER8)This->dsb);
1452 static HRESULT WINAPI SecondaryBufferImpl_SetFX(
1453 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes)
1455 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1456 TRACE("(%p,%lu,%p,%p)\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1458 return IDirectSoundBufferImpl_SetFX((LPDIRECTSOUNDBUFFER8)This->dsb,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1461 static HRESULT WINAPI SecondaryBufferImpl_AcquireResources(
1462 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes)
1464 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1465 TRACE("(%p,%08lu,%lu,%p)\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
1467 return IDirectSoundBufferImpl_AcquireResources((LPDIRECTSOUNDBUFFER8)This->dsb,dwFlags,dwEffectsCount,pdwResultCodes);
1470 static HRESULT WINAPI SecondaryBufferImpl_GetObjectInPath(
1471 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject)
1473 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1474 TRACE("(%p,%s,%lu,%s,%p)\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
1476 return IDirectSoundBufferImpl_GetObjectInPath((LPDIRECTSOUNDBUFFER8)This->dsb,rguidObject,dwIndex,rguidInterface,ppObject);
1479 static IDirectSoundBuffer8Vtbl sbvt =
1481 SecondaryBufferImpl_QueryInterface,
1482 SecondaryBufferImpl_AddRef,
1483 SecondaryBufferImpl_Release,
1484 SecondaryBufferImpl_GetCaps,
1485 SecondaryBufferImpl_GetCurrentPosition,
1486 SecondaryBufferImpl_GetFormat,
1487 SecondaryBufferImpl_GetVolume,
1488 SecondaryBufferImpl_GetPan,
1489 SecondaryBufferImpl_GetFrequency,
1490 SecondaryBufferImpl_GetStatus,
1491 SecondaryBufferImpl_Initialize,
1492 SecondaryBufferImpl_Lock,
1493 SecondaryBufferImpl_Play,
1494 SecondaryBufferImpl_SetCurrentPosition,
1495 SecondaryBufferImpl_SetFormat,
1496 SecondaryBufferImpl_SetVolume,
1497 SecondaryBufferImpl_SetPan,
1498 SecondaryBufferImpl_SetFrequency,
1499 SecondaryBufferImpl_Stop,
1500 SecondaryBufferImpl_Unlock,
1501 SecondaryBufferImpl_Restore,
1502 SecondaryBufferImpl_SetFX,
1503 SecondaryBufferImpl_AcquireResources,
1504 SecondaryBufferImpl_GetObjectInPath
1507 HRESULT WINAPI SecondaryBufferImpl_Create(
1508 IDirectSoundBufferImpl *dsb,
1509 SecondaryBufferImpl **psb)
1511 SecondaryBufferImpl *sb;
1512 TRACE("(%p,%p)\n",dsb,psb);
1514 sb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*sb));
1517 WARN("out of memory\n");
1519 return DSERR_OUTOFMEMORY;
1525 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
1530 HRESULT WINAPI SecondaryBufferImpl_Destroy(
1531 SecondaryBufferImpl *pdsb)
1533 TRACE("(%p)\n",pdsb);
1535 while (SecondaryBufferImpl_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);