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 ULONG ref = InterlockedIncrement(&(This->ref));
59 TRACE("(%p) ref was %ld\n", This, ref - 1);
63 static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface)
65 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
66 ULONG ref = InterlockedDecrement(&(This->ref));
67 TRACE("(%p) ref was %ld\n", This, ref + 1);
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 ULONG ref = InterlockedIncrement(&(This->ref));
355 TRACE("(%p) ref was %ld\n", This, ref - 1);
359 static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
361 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
362 ULONG ref = InterlockedDecrement(&(This->ref));
363 TRACE("(%p) ref was %ld\n", This, ref + 1);
366 DSOUND_RemoveBuffer(This->dsound, This);
368 This->lock.DebugInfo->Spare[1] = 0;
369 DeleteCriticalSection(&(This->lock));
372 IDsDriverBuffer_Release(This->hwbuf);
373 if (This->dsound->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
375 if (This->buffer->ref==0) {
376 HeapFree(GetProcessHeap(),0,This->buffer->memory);
377 HeapFree(GetProcessHeap(),0,This->buffer);
382 if (This->buffer->ref==0) {
383 HeapFree(GetProcessHeap(),0,This->buffer->memory);
384 HeapFree(GetProcessHeap(),0,This->buffer);
388 HeapFree(GetProcessHeap(), 0, This->notifies);
389 HeapFree(GetProcessHeap(), 0, This->pwfx);
390 HeapFree(GetProcessHeap(), 0, This);
392 TRACE("(%p) released\n", This);
397 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
398 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix)
402 TRACE("primary playpos=%ld, mixpos=%ld\n", pplay, pmix);
403 TRACE("this mixpos=%ld, time=%ld\n", bmix, GetTickCount());
405 /* the actual primary play position (pplay) is always behind last mixed (pmix),
406 * unless the computer is too slow or something */
407 /* we need to know how far away we are from there */
408 #if 0 /* we'll never fill the primary entirely */
410 if ((state == STATE_PLAYING) || (state == STATE_STOPPING)) {
411 /* wow, the software mixer is really doing well,
412 * seems the entire primary buffer is filled! */
413 pmix += This->dsound->buflen;
415 /* else: the primary buffer is not playing, so probably empty */
418 if (pmix < pplay) pmix += This->dsound->buflen; /* wraparound */
420 /* detect buffer underrun */
421 if (pwrite < pplay) pwrite += This->dsound->buflen; /* wraparound */
423 if (pmix > (ds_snd_queue_max * This->dsound->fraglen + pwrite + This->dsound->writelead)) {
424 WARN("detected an underrun: primary queue was %ld\n",pmix);
427 /* divide the offset by its sample size */
428 pmix /= This->dsound->pwfx->nBlockAlign;
429 TRACE("primary back-samples=%ld\n",pmix);
430 /* adjust for our frequency */
431 pmix = (pmix * This->freqAdjust) >> DSOUND_FREQSHIFT;
432 /* multiply by our own sample size */
433 pmix *= This->pwfx->nBlockAlign;
434 TRACE("this back-offset=%ld\n", pmix);
435 /* subtract from our last mixed position */
437 while (bplay < pmix) bplay += This->buflen; /* wraparound */
439 if (This->leadin && ((bplay < This->startpos) || (bplay > bmix))) {
440 /* seems we haven't started playing yet */
441 TRACE("this still in lead-in phase\n");
442 bplay = This->startpos;
444 /* return the result */
448 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
449 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
452 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
453 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
455 hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
457 WARN("IDsDriverBuffer_GetPosition failed\n");
461 if (playpos && (This->state != STATE_PLAYING)) {
462 /* we haven't been merged into the primary buffer (yet) */
463 *playpos = This->buf_mixpos;
464 } else if (playpos) {
465 DWORD pplay, pwrite, lplay, splay, pstate;
466 /* let's get this exact; first, recursively call GetPosition on the primary */
467 EnterCriticalSection(&(This->dsound->mixlock));
468 if (DSOUND_PrimaryGetPosition(This->dsound, &pplay, &pwrite) != DS_OK)
469 WARN("DSOUND_PrimaryGetPosition failed\n");
470 /* detect HEL mode underrun */
471 pstate = This->dsound->state;
472 if (!(This->dsound->hwbuf || This->dsound->pwqueue)) {
473 TRACE("detected an underrun\n");
475 if (pstate == STATE_PLAYING)
476 pstate = STATE_STARTING;
477 else if (pstate == STATE_STOPPING)
478 pstate = STATE_STOPPED;
480 /* get data for ourselves while we still have the lock */
481 pstate &= This->state;
482 lplay = This->primary_mixpos;
483 splay = This->buf_mixpos;
484 if ((This->dsbd.dwFlags & DSBCAPS_GETCURRENTPOSITION2) || This->dsound->hwbuf) {
485 /* calculate play position using this */
486 *playpos = DSOUND_CalcPlayPosition(This, pstate, pplay, pwrite, lplay, splay);
488 /* (unless the app isn't using GETCURRENTPOSITION2) */
489 /* don't know exactly how this should be handled...
490 * the docs says that play cursor is reported as directly
491 * behind write cursor, hmm... */
492 /* let's just do what might work for Half-Life */
494 wp = (This->dsound->pwplay + ds_hel_margin) * This->dsound->fraglen;
495 wp %= This->dsound->buflen;
496 *playpos = DSOUND_CalcPlayPosition(This, pstate, wp, pwrite, lplay, splay);
498 LeaveCriticalSection(&(This->dsound->mixlock));
501 *writepos = This->buf_mixpos;
504 if (This->state != STATE_STOPPED) {
505 /* apply the documented 10ms lead to writepos */
506 *writepos += This->writelead;
508 *writepos %= This->buflen;
511 This->last_playpos = *playpos;
512 TRACE("playpos = %ld, writepos = %ld (%p, time=%ld)\n", playpos?*playpos:0, writepos?*writepos:0, This, GetTickCount());
516 static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
517 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
519 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
520 TRACE("(%p,%p), thread is %04lx\n",This,status,GetCurrentThreadId());
522 if (status == NULL) {
523 WARN("invalid parameter: status = NULL\n");
524 return DSERR_INVALIDPARAM;
528 if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
529 *status |= DSBSTATUS_PLAYING;
530 if (This->playflags & DSBPLAY_LOOPING)
531 *status |= DSBSTATUS_LOOPING;
534 TRACE("status=%lx\n", *status);
539 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
540 LPDIRECTSOUNDBUFFER8 iface,
546 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
547 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
549 size = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
551 if (lpwf) { /* NULL is valid */
552 if (wfsize >= size) {
553 CopyMemory(lpwf,This->pwfx,size);
557 WARN("invalid parameter: wfsize to small\n");
560 return DSERR_INVALIDPARAM;
564 *wfwritten = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
566 WARN("invalid parameter: wfwritten == NULL\n");
567 return DSERR_INVALIDPARAM;
574 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
575 LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
577 HRESULT hres = DS_OK;
578 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
580 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n",
592 if (flags & DSBLOCK_FROMWRITECURSOR) {
594 /* GetCurrentPosition does too much magic to duplicate here */
595 hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writepos);
597 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
600 writecursor += writepos;
602 writecursor %= This->buflen;
603 if (flags & DSBLOCK_ENTIREBUFFER)
604 writebytes = This->buflen;
605 if (writebytes > This->buflen)
606 writebytes = This->buflen;
608 EnterCriticalSection(&(This->lock));
610 if ((writebytes == This->buflen) &&
611 ((This->state == STATE_STARTING) ||
612 (This->state == STATE_PLAYING)))
613 /* some games, like Half-Life, try to be clever (not) and
614 * keep one secondary buffer, and mix sounds into it itself,
615 * locking the entire buffer every time... so we can just forget
616 * about tracking the last-written-to-position... */
617 This->probably_valid_to = (DWORD)-1;
619 This->probably_valid_to = writecursor;
621 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
622 hres = IDsDriverBuffer_Lock(This->hwbuf,
623 lplpaudioptr1, audiobytes1,
624 lplpaudioptr2, audiobytes2,
625 writecursor, writebytes,
628 WARN("IDsDriverBuffer_Lock failed\n");
629 LeaveCriticalSection(&(This->lock));
634 if (writecursor+writebytes <= This->buflen) {
635 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
636 *audiobytes1 = writebytes;
638 *(LPBYTE*)lplpaudioptr2 = NULL;
641 TRACE("->%ld.0\n",writebytes);
643 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
644 *audiobytes1 = This->buflen-writecursor;
646 *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
648 *audiobytes2 = writebytes-(This->buflen-writecursor);
649 TRACE("->%ld.%ld\n",*audiobytes1,audiobytes2?*audiobytes2:0);
651 if (This->state == STATE_PLAYING) {
652 /* if the segment between playpos and buf_mixpos is touched,
653 * we need to cancel some mixing */
654 /* we'll assume that the app always calls GetCurrentPosition before
655 * locking a playing buffer, so that last_playpos is up-to-date */
656 if (This->buf_mixpos >= This->last_playpos) {
657 if (This->buf_mixpos > writecursor &&
658 This->last_playpos < writecursor+writebytes)
661 if (This->buf_mixpos > writecursor ||
662 This->last_playpos < writecursor+writebytes)
666 TRACE("locking prebuffered region, ouch\n");
667 DSOUND_MixCancelAt(This, writecursor);
672 LeaveCriticalSection(&(This->lock));
676 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
677 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
679 HRESULT hres = DS_OK;
680 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
681 TRACE("(%p,%ld)\n",This,newpos);
684 EnterCriticalSection(&(This->lock));
686 newpos %= This->buflen;
687 This->buf_mixpos = newpos;
689 hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
691 WARN("IDsDriverBuffer_SetPosition failed\n");
694 LeaveCriticalSection(&(This->lock));
700 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
701 LPDIRECTSOUNDBUFFER8 iface,LONG pan
703 HRESULT hres = DS_OK;
704 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
706 TRACE("(%p,%ld)\n",This,pan);
708 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
709 WARN("invalid parameter: pan = %ld\n", pan);
710 return DSERR_INVALIDPARAM;
713 /* You cannot use both pan and 3D controls */
714 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
715 (This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
716 WARN("control unavailable\n");
717 return DSERR_CONTROLUNAVAIL;
721 EnterCriticalSection(&(This->lock));
723 if (This->volpan.lPan != pan) {
724 This->volpan.lPan = pan;
725 DSOUND_RecalcVolPan(&(This->volpan));
728 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
730 WARN("IDsDriverBuffer_SetVolumePan failed\n");
732 DSOUND_ForceRemix(This);
735 LeaveCriticalSection(&(This->lock));
741 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
742 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
744 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
745 TRACE("(%p,%p)\n",This,pan);
747 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
748 WARN("control unavailable\n");
749 return DSERR_CONTROLUNAVAIL;
753 WARN("invalid parameter: pan = NULL\n");
754 return DSERR_INVALIDPARAM;
757 *pan = This->volpan.lPan;
762 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
763 LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
765 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
766 DWORD probably_valid_to;
767 HRESULT hres = DS_OK;
769 TRACE("(%p,%p,%ld,%p,%ld)\n", This,p1,x1,p2,x2);
772 EnterCriticalSection(&(This->lock));
774 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
775 hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
777 WARN("IDsDriverBuffer_Unlock failed\n");
781 if (p2) probably_valid_to = (((LPBYTE)p2)-This->buffer->memory) + x2;
782 else probably_valid_to = (((LPBYTE)p1)-This->buffer->memory) + x1;
783 probably_valid_to %= This->buflen;
784 if ((probably_valid_to == 0) && ((x1+x2) == This->buflen) &&
785 ((This->state == STATE_STARTING) ||
786 (This->state == STATE_PLAYING)))
787 /* see IDirectSoundBufferImpl_Lock */
788 probably_valid_to = (DWORD)-1;
789 This->probably_valid_to = probably_valid_to;
792 LeaveCriticalSection(&(This->lock));
795 TRACE("probably_valid_to=%ld\n", This->probably_valid_to);
799 static HRESULT WINAPI IDirectSoundBufferImpl_Restore(
800 LPDIRECTSOUNDBUFFER8 iface
802 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
803 FIXME("(%p):stub\n",This);
807 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
808 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
810 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
811 TRACE("(%p,%p)\n",This,freq);
814 WARN("invalid parameter: freq = NULL\n");
815 return DSERR_INVALIDPARAM;
819 TRACE("-> %ld\n", *freq);
824 static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(
825 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
827 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
830 FIXME("(%p,%lu,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
833 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
835 WARN("control unavailable\n");
836 return DSERR_CONTROLUNAVAIL;
839 static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(
840 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
842 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
845 FIXME("(%p,%08lu,%lu,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
848 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
850 WARN("control unavailable\n");
851 return DSERR_CONTROLUNAVAIL;
854 static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(
855 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
857 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
859 FIXME("(%p,%s,%lu,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
861 WARN("control unavailable\n");
862 return DSERR_CONTROLUNAVAIL;
865 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
866 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
868 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
869 FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
870 DPRINTF("Re-Init!!!\n");
871 WARN("already initialized\n");
872 return DSERR_ALREADYINITIALIZED;
875 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
876 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
878 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
879 TRACE("(%p)->(%p)\n",This,caps);
882 WARN("invalid parameter: caps == NULL\n");
883 return DSERR_INVALIDPARAM;
886 if (caps->dwSize < sizeof(*caps)) {
887 WARN("invalid parameter: caps->dwSize = %ld < %d\n",caps->dwSize, sizeof(*caps));
888 return DSERR_INVALIDPARAM;
891 caps->dwFlags = This->dsbd.dwFlags;
892 if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
893 else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
895 caps->dwBufferBytes = This->buflen;
897 /* This value represents the speed of the "unlock" command.
898 As unlock is quite fast (it does not do anything), I put
899 4096 ko/s = 4 Mo / s */
900 /* FIXME: hwbuf speed */
901 caps->dwUnlockTransferRate = 4096;
902 caps->dwPlayCpuOverhead = 0;
907 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
908 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
910 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
912 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
915 WARN("invalid parameter\n");
919 *ppobj = NULL; /* assume failure */
921 if ( IsEqualGUID(riid, &IID_IUnknown) ||
922 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
923 IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
925 SecondaryBufferImpl_Create(This, &(This->dsb));
927 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)This->dsb);
931 WARN("IID_IDirectSoundBuffer\n");
932 return E_NOINTERFACE;
935 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
937 IDirectSoundNotifyImpl_Create(This, &(This->notify));
939 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
940 *ppobj = This->notify;
943 WARN("IID_IDirectSoundNotify\n");
944 return E_NOINTERFACE;
947 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
949 IDirectSound3DBufferImpl_Create(This, &(This->ds3db));
951 IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->ds3db);
952 *ppobj = This->ds3db;
955 WARN("IID_IDirectSound3DBuffer\n");
956 return E_NOINTERFACE;
959 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
960 ERR("app requested IDirectSound3DListener on secondary buffer\n");
961 return E_NOINTERFACE;
964 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
966 IKsBufferPropertySetImpl_Create(This, &(This->iks));
968 IKsPropertySet_AddRef((LPKSPROPERTYSET)This->iks);
972 WARN("IID_IKsPropertySet\n");
973 return E_NOINTERFACE;
976 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
978 return E_NOINTERFACE;
981 static IDirectSoundBuffer8Vtbl dsbvt =
983 IDirectSoundBufferImpl_QueryInterface,
984 IDirectSoundBufferImpl_AddRef,
985 IDirectSoundBufferImpl_Release,
986 IDirectSoundBufferImpl_GetCaps,
987 IDirectSoundBufferImpl_GetCurrentPosition,
988 IDirectSoundBufferImpl_GetFormat,
989 IDirectSoundBufferImpl_GetVolume,
990 IDirectSoundBufferImpl_GetPan,
991 IDirectSoundBufferImpl_GetFrequency,
992 IDirectSoundBufferImpl_GetStatus,
993 IDirectSoundBufferImpl_Initialize,
994 IDirectSoundBufferImpl_Lock,
995 IDirectSoundBufferImpl_Play,
996 IDirectSoundBufferImpl_SetCurrentPosition,
997 IDirectSoundBufferImpl_SetFormat,
998 IDirectSoundBufferImpl_SetVolume,
999 IDirectSoundBufferImpl_SetPan,
1000 IDirectSoundBufferImpl_SetFrequency,
1001 IDirectSoundBufferImpl_Stop,
1002 IDirectSoundBufferImpl_Unlock,
1003 IDirectSoundBufferImpl_Restore,
1004 IDirectSoundBufferImpl_SetFX,
1005 IDirectSoundBufferImpl_AcquireResources,
1006 IDirectSoundBufferImpl_GetObjectInPath
1009 HRESULT WINAPI IDirectSoundBufferImpl_Create(
1010 IDirectSoundImpl *ds,
1011 IDirectSoundBufferImpl **pdsb,
1012 LPCDSBUFFERDESC dsbd)
1014 IDirectSoundBufferImpl *dsb;
1015 LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
1016 HRESULT err = DS_OK;
1018 int use_hw, alloc_size, cp_size;
1019 TRACE("(%p,%p,%p)\n",ds,pdsb,dsbd);
1021 if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
1022 WARN("invalid parameter: dsbd->dwBufferBytes = %ld\n", dsbd->dwBufferBytes);
1024 return DSERR_INVALIDPARAM; /* FIXME: which error? */
1027 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
1030 WARN("out of memory\n");
1032 return DSERR_OUTOFMEMORY;
1035 TRACE("Created buffer at %p\n", dsb);
1040 dsb->lpVtbl = &dsbvt;
1043 /* size depends on version */
1044 CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
1046 /* variable sized struct so calculate size based on format */
1047 if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
1048 alloc_size = sizeof(WAVEFORMATEX);
1049 cp_size = sizeof(PCMWAVEFORMAT);
1051 alloc_size = cp_size = sizeof(WAVEFORMATEX) + wfex->cbSize;
1053 dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,alloc_size);
1054 if (dsb->pwfx == NULL) {
1055 WARN("out of memory\n");
1056 HeapFree(GetProcessHeap(),0,dsb);
1058 return DSERR_OUTOFMEMORY;
1061 CopyMemory(dsb->pwfx, wfex, cp_size);
1063 if (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign)
1064 dsb->buflen = dsbd->dwBufferBytes +
1065 (dsbd->lpwfxFormat->nBlockAlign -
1066 (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign));
1068 dsb->buflen = dsbd->dwBufferBytes;
1070 dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
1072 dsb->notifies = NULL;
1073 dsb->nrofnotifies = 0;
1076 /* Check necessary hardware mixing capabilities */
1077 if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
1078 else capf |= DSCAPS_SECONDARYMONO;
1079 if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
1080 else capf |= DSCAPS_SECONDARY8BIT;
1082 use_hw = (ds->drvcaps.dwFlags & capf) == capf;
1083 TRACE("use_hw = 0x%08x, capf = 0x%08lx, ds->drvcaps.dwFlags = 0x%08lx\n", use_hw, capf, ds->drvcaps.dwFlags);
1085 /* FIXME: check hardware sample rate mixing capabilities */
1086 /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
1087 /* FIXME: check whether any hardware buffers are left */
1088 /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
1090 /* Allocate an empty buffer */
1091 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1092 if (dsb->buffer == NULL) {
1093 WARN("out of memory\n");
1094 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1095 HeapFree(GetProcessHeap(),0,dsb);
1097 return DSERR_OUTOFMEMORY;
1100 /* Allocate system memory for buffer if applicable */
1101 if ((ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
1102 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1103 if (dsb->buffer->memory == NULL) {
1104 WARN("out of memory\n");
1105 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1106 HeapFree(GetProcessHeap(),0,dsb->buffer);
1107 HeapFree(GetProcessHeap(),0,dsb);
1109 return DSERR_OUTOFMEMORY;
1111 dsb->buffer->ref = 1;
1112 FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);
1115 /* Allocate the hardware buffer */
1117 err = IDsDriver_CreateSoundBuffer(ds->driver,wfex,dsbd->dwFlags,0,
1118 &(dsb->buflen),&(dsb->buffer->memory),
1119 (LPVOID*)&(dsb->hwbuf));
1120 /* fall back to software buffer on failure */
1122 TRACE("IDsDriver_CreateSoundBuffer failed, falling back to software buffer\n");
1124 if (ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
1125 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1126 if (dsb->buffer->memory == NULL) {
1127 WARN("out of memory\n");
1128 HeapFree(GetProcessHeap(),0,dsb->buffer);
1129 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1130 HeapFree(GetProcessHeap(),0,dsb);
1132 return DSERR_OUTOFMEMORY;
1134 dsb->buffer->ref = 1;
1135 FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);
1141 /* calculate fragment size and write lead */
1142 DSOUND_RecalcFormat(dsb);
1144 /* It's not necessary to initialize values to zero since */
1145 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1147 dsb->buf_mixpos = 0;
1148 dsb->state = STATE_STOPPED;
1150 dsb->freqAdjust = (dsb->freq << DSOUND_FREQSHIFT) /
1151 ds->pwfx->nSamplesPerSec;
1152 dsb->nAvgBytesPerSec = dsb->freq *
1153 dsbd->lpwfxFormat->nBlockAlign;
1155 if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
1156 dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
1157 dsb->ds3db_ds3db.vPosition.x = 0.0;
1158 dsb->ds3db_ds3db.vPosition.y = 0.0;
1159 dsb->ds3db_ds3db.vPosition.z = 0.0;
1160 dsb->ds3db_ds3db.vVelocity.x = 0.0;
1161 dsb->ds3db_ds3db.vVelocity.y = 0.0;
1162 dsb->ds3db_ds3db.vVelocity.z = 0.0;
1163 dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1164 dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1165 dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
1166 dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
1167 dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
1168 dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1169 dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1170 dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1171 dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
1173 dsb->ds3db_need_recalc = FALSE;
1174 DSOUND_Calc3DBuffer(dsb);
1176 DSOUND_RecalcVolPan(&(dsb->volpan));
1178 InitializeCriticalSection(&(dsb->lock));
1179 dsb->lock.DebugInfo->Spare[1] = (DWORD)"DSOUNDBUFFER_lock";
1181 /* register buffer if not primary */
1182 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1183 err = DSOUND_AddBuffer(ds, dsb);
1185 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1186 HeapFree(GetProcessHeap(),0,dsb->buffer);
1187 dsb->lock.DebugInfo->Spare[1] = 0;
1188 DeleteCriticalSection(&(dsb->lock));
1189 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1190 HeapFree(GetProcessHeap(),0,dsb);
1199 HRESULT WINAPI IDirectSoundBufferImpl_Destroy(
1200 IDirectSoundBufferImpl *pdsb)
1202 TRACE("(%p)\n",pdsb);
1204 /* This keeps the *_Destroy functions from possibly deleting
1205 * this object until it is ready to be deleted */
1206 IDirectSoundBufferImpl_AddRef((LPDIRECTSOUNDBUFFER8)pdsb);
1209 WARN("iks not NULL\n");
1210 IKsBufferPropertySetImpl_Destroy(pdsb->iks);
1215 WARN("ds3db not NULL\n");
1216 IDirectSound3DBufferImpl_Destroy(pdsb->ds3db);
1221 WARN("notify not NULL\n");
1222 IDirectSoundNotifyImpl_Destroy(pdsb->notify);
1223 pdsb->notify = NULL;
1227 WARN("dsb not NULL\n");
1228 SecondaryBufferImpl_Destroy(pdsb->dsb);
1232 while (IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);
1237 /*******************************************************************************
1241 static HRESULT WINAPI SecondaryBufferImpl_QueryInterface(
1242 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj)
1244 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1245 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
1247 return IDirectSoundBufferImpl_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb,riid,ppobj);
1250 static ULONG WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
1252 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
1253 ULONG ref = InterlockedIncrement(&(This->ref));
1254 TRACE("(%p) ref was %ld\n", This, ref - 1);
1258 static ULONG WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
1260 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
1261 ULONG ref = InterlockedDecrement(&(This->ref));
1262 TRACE("(%p) ref was %ld\n", This, ref + 1);
1265 This->dsb->dsb = NULL;
1266 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
1267 HeapFree(GetProcessHeap(), 0, This);
1268 TRACE("(%p) released\n", This);
1273 static HRESULT WINAPI SecondaryBufferImpl_GetCaps(
1274 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps)
1276 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1277 TRACE("(%p)->(%p)\n",This,caps);
1279 return IDirectSoundBufferImpl_GetCaps((LPDIRECTSOUNDBUFFER8)This->dsb,caps);
1282 static HRESULT WINAPI SecondaryBufferImpl_GetCurrentPosition(
1283 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos)
1285 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1286 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
1288 return IDirectSoundBufferImpl_GetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,playpos,writepos);
1291 static HRESULT WINAPI SecondaryBufferImpl_GetFormat(
1292 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten)
1294 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1295 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
1297 return IDirectSoundBufferImpl_GetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,lpwf,wfsize,wfwritten);
1300 static HRESULT WINAPI SecondaryBufferImpl_GetVolume(
1301 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol)
1303 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1304 TRACE("(%p,%p)\n",This,vol);
1306 return IDirectSoundBufferImpl_GetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1309 static HRESULT WINAPI SecondaryBufferImpl_GetPan(
1310 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan)
1312 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1313 TRACE("(%p,%p)\n",This,pan);
1315 return IDirectSoundBufferImpl_GetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1318 static HRESULT WINAPI SecondaryBufferImpl_GetFrequency(
1319 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq)
1321 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1322 TRACE("(%p,%p)\n",This,freq);
1324 return IDirectSoundBufferImpl_GetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1327 static HRESULT WINAPI SecondaryBufferImpl_GetStatus(
1328 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status)
1330 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1331 TRACE("(%p,%p)\n",This,status);
1333 return IDirectSoundBufferImpl_GetStatus((LPDIRECTSOUNDBUFFER8)This->dsb,status);
1336 static HRESULT WINAPI SecondaryBufferImpl_Initialize(
1337 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd)
1339 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1340 TRACE("(%p,%p,%p)\n",This,dsound,dbsd);
1342 return IDirectSoundBufferImpl_Initialize((LPDIRECTSOUNDBUFFER8)This->dsb,dsound,dbsd);
1345 static HRESULT WINAPI SecondaryBufferImpl_Lock(
1346 LPDIRECTSOUNDBUFFER8 iface,
1349 LPVOID lplpaudioptr1,
1350 LPDWORD audiobytes1,
1351 LPVOID lplpaudioptr2,
1352 LPDWORD audiobytes2,
1355 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1356 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx)\n",
1357 This,writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1359 return IDirectSoundBufferImpl_Lock((LPDIRECTSOUNDBUFFER8)This->dsb,
1360 writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1363 static HRESULT WINAPI SecondaryBufferImpl_Play(
1364 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags)
1366 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1367 TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
1369 return IDirectSoundBufferImpl_Play((LPDIRECTSOUNDBUFFER8)This->dsb,reserved1,reserved2,flags);
1372 static HRESULT WINAPI SecondaryBufferImpl_SetCurrentPosition(
1373 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos)
1375 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1376 TRACE("(%p,%ld)\n",This,newpos);
1378 return IDirectSoundBufferImpl_SetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,newpos);
1381 static HRESULT WINAPI SecondaryBufferImpl_SetFormat(
1382 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex)
1384 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1385 TRACE("(%p,%p)\n",This,wfex);
1387 return IDirectSoundBufferImpl_SetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,wfex);
1390 static HRESULT WINAPI SecondaryBufferImpl_SetVolume(
1391 LPDIRECTSOUNDBUFFER8 iface,LONG vol)
1393 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1394 TRACE("(%p,%ld)\n",This,vol);
1396 return IDirectSoundBufferImpl_SetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1399 static HRESULT WINAPI SecondaryBufferImpl_SetPan(
1400 LPDIRECTSOUNDBUFFER8 iface,LONG pan)
1402 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1403 TRACE("(%p,%ld)\n",This,pan);
1405 return IDirectSoundBufferImpl_SetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1408 static HRESULT WINAPI SecondaryBufferImpl_SetFrequency(
1409 LPDIRECTSOUNDBUFFER8 iface,DWORD freq)
1411 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1412 TRACE("(%p,%ld)\n",This,freq);
1414 return IDirectSoundBufferImpl_SetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1417 static HRESULT WINAPI SecondaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
1419 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1420 TRACE("(%p)\n",This);
1422 return IDirectSoundBufferImpl_Stop((LPDIRECTSOUNDBUFFER8)This->dsb);
1425 static HRESULT WINAPI SecondaryBufferImpl_Unlock(
1426 LPDIRECTSOUNDBUFFER8 iface,
1427 LPVOID lpvAudioPtr1,
1428 DWORD dwAudioBytes1,
1429 LPVOID lpvAudioPtr2,
1430 DWORD dwAudioBytes2)
1432 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1433 TRACE("(%p,%p,%ld,%p,%ld)\n",
1434 This, lpvAudioPtr1, dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1436 return IDirectSoundBufferImpl_Unlock((LPDIRECTSOUNDBUFFER8)This->dsb,
1437 lpvAudioPtr1,dwAudioBytes1,lpvAudioPtr2,dwAudioBytes2);
1440 static HRESULT WINAPI SecondaryBufferImpl_Restore(
1441 LPDIRECTSOUNDBUFFER8 iface)
1443 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1444 TRACE("(%p)\n",This);
1446 return IDirectSoundBufferImpl_Restore((LPDIRECTSOUNDBUFFER8)This->dsb);
1449 static HRESULT WINAPI SecondaryBufferImpl_SetFX(
1450 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes)
1452 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1453 TRACE("(%p,%lu,%p,%p)\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1455 return IDirectSoundBufferImpl_SetFX((LPDIRECTSOUNDBUFFER8)This->dsb,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1458 static HRESULT WINAPI SecondaryBufferImpl_AcquireResources(
1459 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes)
1461 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1462 TRACE("(%p,%08lu,%lu,%p)\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
1464 return IDirectSoundBufferImpl_AcquireResources((LPDIRECTSOUNDBUFFER8)This->dsb,dwFlags,dwEffectsCount,pdwResultCodes);
1467 static HRESULT WINAPI SecondaryBufferImpl_GetObjectInPath(
1468 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject)
1470 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1471 TRACE("(%p,%s,%lu,%s,%p)\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
1473 return IDirectSoundBufferImpl_GetObjectInPath((LPDIRECTSOUNDBUFFER8)This->dsb,rguidObject,dwIndex,rguidInterface,ppObject);
1476 static IDirectSoundBuffer8Vtbl sbvt =
1478 SecondaryBufferImpl_QueryInterface,
1479 SecondaryBufferImpl_AddRef,
1480 SecondaryBufferImpl_Release,
1481 SecondaryBufferImpl_GetCaps,
1482 SecondaryBufferImpl_GetCurrentPosition,
1483 SecondaryBufferImpl_GetFormat,
1484 SecondaryBufferImpl_GetVolume,
1485 SecondaryBufferImpl_GetPan,
1486 SecondaryBufferImpl_GetFrequency,
1487 SecondaryBufferImpl_GetStatus,
1488 SecondaryBufferImpl_Initialize,
1489 SecondaryBufferImpl_Lock,
1490 SecondaryBufferImpl_Play,
1491 SecondaryBufferImpl_SetCurrentPosition,
1492 SecondaryBufferImpl_SetFormat,
1493 SecondaryBufferImpl_SetVolume,
1494 SecondaryBufferImpl_SetPan,
1495 SecondaryBufferImpl_SetFrequency,
1496 SecondaryBufferImpl_Stop,
1497 SecondaryBufferImpl_Unlock,
1498 SecondaryBufferImpl_Restore,
1499 SecondaryBufferImpl_SetFX,
1500 SecondaryBufferImpl_AcquireResources,
1501 SecondaryBufferImpl_GetObjectInPath
1504 HRESULT WINAPI SecondaryBufferImpl_Create(
1505 IDirectSoundBufferImpl *dsb,
1506 SecondaryBufferImpl **psb)
1508 SecondaryBufferImpl *sb;
1509 TRACE("(%p,%p)\n",dsb,psb);
1511 sb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*sb));
1514 WARN("out of memory\n");
1516 return DSERR_OUTOFMEMORY;
1522 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
1527 HRESULT WINAPI SecondaryBufferImpl_Destroy(
1528 SecondaryBufferImpl *pdsb)
1530 TRACE("(%p)\n",pdsb);
1532 while (SecondaryBufferImpl_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);