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 ICOM_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) {
72 ICOM_THIS(IDirectSoundNotifyImpl,iface);
75 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
77 ref = InterlockedIncrement(&(This->ref));
81 static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface) {
82 ICOM_THIS(IDirectSoundNotifyImpl,iface);
85 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
87 ref = InterlockedDecrement(&(This->ref));
89 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)This->dsb);
90 This->dsb->notify = NULL;
91 HeapFree(GetProcessHeap(),0,This);
92 TRACE("(%p) released\n",This);
97 static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
98 LPDIRECTSOUNDNOTIFY iface,DWORD howmuch,LPCDSBPOSITIONNOTIFY notify
100 ICOM_THIS(IDirectSoundNotifyImpl,iface);
101 TRACE("(%p,0x%08lx,%p)\n",This,howmuch,notify);
103 if (howmuch > 0 && notify == NULL) {
104 WARN("invalid parameter: notify == NULL\n");
105 return DSERR_INVALIDPARAM;
108 if (TRACE_ON(dsound)) {
110 for (i=0;i<howmuch;i++)
111 TRACE("notify at %ld to 0x%08lx\n",
112 notify[i].dwOffset,(DWORD)notify[i].hEventNotify);
115 if (This->dsb->hwnotify) {
117 hres = IDsDriverNotify_SetNotificationPositions(This->dsb->hwnotify, howmuch, notify);
119 WARN("IDsDriverNotify_SetNotificationPositions failed\n");
121 } else if (howmuch > 0) {
122 /* Make an internal copy of the caller-supplied array.
123 * Replace the existing copy if one is already present. */
124 if (This->dsb->notifies)
125 This->dsb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
126 This->dsb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
128 This->dsb->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
129 howmuch * sizeof(DSBPOSITIONNOTIFY));
131 if (This->dsb->notifies == NULL) {
132 WARN("out of memory\n");
133 return DSERR_OUTOFMEMORY;
135 memcpy(This->dsb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
136 This->dsb->nrofnotifies = howmuch;
138 if (This->dsb->notifies) {
139 HeapFree(GetProcessHeap(), 0, This->dsb->notifies);
140 This->dsb->notifies = NULL;
142 This->dsb->nrofnotifies = 0;
148 ICOM_VTABLE(IDirectSoundNotify) dsnvt =
150 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
151 IDirectSoundNotifyImpl_QueryInterface,
152 IDirectSoundNotifyImpl_AddRef,
153 IDirectSoundNotifyImpl_Release,
154 IDirectSoundNotifyImpl_SetNotificationPositions,
157 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
158 IDirectSoundBufferImpl * dsb,
159 IDirectSoundNotifyImpl **pdsn)
161 IDirectSoundNotifyImpl * dsn;
162 TRACE("(%p,%p)\n",dsb,pdsn);
164 dsn = (IDirectSoundNotifyImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dsn));
167 WARN("out of memory\n");
168 return DSERR_OUTOFMEMORY;
172 dsn->lpVtbl = &dsnvt;
175 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
181 /*******************************************************************************
185 static HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(
186 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex
188 ICOM_THIS(IDirectSoundBufferImpl,iface);
190 TRACE("(%p,%p)\n",This,wfex);
191 /* This method is not available on secondary buffers */
192 WARN("invalid call\n");
193 return DSERR_INVALIDCALL;
196 static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
197 LPDIRECTSOUNDBUFFER8 iface,LONG vol
199 ICOM_THIS(IDirectSoundBufferImpl,iface);
202 TRACE("(%p,%ld)\n",This,vol);
204 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
205 WARN("control unavailable: This->dsbd.dwFlags = 0x%08lx\n", This->dsbd.dwFlags);
206 return DSERR_CONTROLUNAVAIL;
209 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
210 WARN("invalid parameter: vol = %ld\n", vol);
211 return DSERR_INVALIDPARAM;
215 EnterCriticalSection(&(This->lock));
217 if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) {
218 oldVol = This->ds3db_lVolume;
219 This->ds3db_lVolume = vol;
221 oldVol = This->volpan.lVolume;
222 This->volpan.lVolume = vol;
224 DSOUND_RecalcVolPan(&(This->volpan));
230 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
232 WARN("IDsDriverBuffer_SetVolumePan failed\n");
234 DSOUND_ForceRemix(This);
237 LeaveCriticalSection(&(This->lock));
243 static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(
244 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
246 ICOM_THIS(IDirectSoundBufferImpl,iface);
247 TRACE("(%p,%p)\n",This,vol);
249 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
250 WARN("control unavailable\n");
251 return DSERR_CONTROLUNAVAIL;
255 WARN("invalid parameter: vol == NULL\n");
256 return DSERR_INVALIDPARAM;
259 *vol = This->volpan.lVolume;
264 static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
265 LPDIRECTSOUNDBUFFER8 iface,DWORD freq
267 ICOM_THIS(IDirectSoundBufferImpl,iface);
270 TRACE("(%p,%ld)\n",This,freq);
272 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
273 WARN("control unavailable\n");
274 return DSERR_CONTROLUNAVAIL;
277 if (freq == DSBFREQUENCY_ORIGINAL)
278 freq = This->wfx.nSamplesPerSec;
280 if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX)) {
281 WARN("invalid parameter: freq = %ld\n", freq);
282 return DSERR_INVALIDPARAM;
286 EnterCriticalSection(&(This->lock));
288 oldFreq = This->freq;
290 if (freq != oldFreq) {
291 This->freqAdjust = (freq << DSOUND_FREQSHIFT) / This->dsound->wfx.nSamplesPerSec;
292 This->nAvgBytesPerSec = freq * This->wfx.nBlockAlign;
293 DSOUND_RecalcFormat(This);
295 DSOUND_ForceRemix(This);
298 LeaveCriticalSection(&(This->lock));
304 static HRESULT WINAPI IDirectSoundBufferImpl_Play(
305 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
307 HRESULT hres = DS_OK;
308 ICOM_THIS(IDirectSoundBufferImpl,iface);
309 TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
312 EnterCriticalSection(&(This->lock));
314 This->playflags = flags;
315 if (This->state == STATE_STOPPED) {
317 This->startpos = This->buf_mixpos;
318 This->state = STATE_STARTING;
319 } else if (This->state == STATE_STOPPING)
320 This->state = STATE_PLAYING;
322 hres = IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
324 WARN("IDsDriverBuffer_Play failed\n");
326 This->state = STATE_PLAYING;
329 LeaveCriticalSection(&(This->lock));
335 static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
337 HRESULT hres = DS_OK;
338 ICOM_THIS(IDirectSoundBufferImpl,iface);
339 TRACE("(%p)\n",This);
342 EnterCriticalSection(&(This->lock));
344 if (This->state == STATE_PLAYING)
345 This->state = STATE_STOPPING;
346 else if (This->state == STATE_STARTING)
347 This->state = STATE_STOPPED;
349 hres = IDsDriverBuffer_Stop(This->hwbuf);
351 WARN("IDsDriverBuffer_Stop failed\n");
353 This->state = STATE_STOPPED;
355 DSOUND_CheckEvent(This, 0);
357 LeaveCriticalSection(&(This->lock));
363 static DWORD WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface) {
364 ICOM_THIS(IDirectSoundBufferImpl,iface);
367 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
369 ref = InterlockedIncrement(&(This->ref));
371 FIXME("thread-safety alert! AddRef-ing with a zero refcount!\n");
376 static DWORD WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface) {
377 ICOM_THIS(IDirectSoundBufferImpl,iface);
381 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
383 ref = InterlockedDecrement(&(This->ref));
386 RtlAcquireResourceExclusive(&(This->dsound->lock), TRUE);
387 for (i=0;i<This->dsound->nrofbuffers;i++)
388 if (This->dsound->buffers[i] == This)
390 if (i < This->dsound->nrofbuffers) {
391 /* Put the last buffer of the list in the (now empty) position */
392 This->dsound->buffers[i] = This->dsound->buffers[This->dsound->nrofbuffers - 1];
393 This->dsound->nrofbuffers--;
394 This->dsound->buffers = HeapReAlloc(GetProcessHeap(),0,This->dsound->buffers,sizeof(LPDIRECTSOUNDBUFFER8)*This->dsound->nrofbuffers);
395 TRACE("(%p) buffer count is now %d\n", This, This->dsound->nrofbuffers);
396 IDirectSound_Release((LPDIRECTSOUND)This->dsound);
398 RtlReleaseResource(&(This->dsound->lock));
400 DeleteCriticalSection(&(This->lock));
403 IDsDriverBuffer_Release(This->hwbuf);
404 if (This->dsound->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
406 if (This->buffer->ref==0) {
407 HeapFree(GetProcessHeap(),0,This->buffer->memory);
408 HeapFree(GetProcessHeap(),0,This->buffer);
413 if (This->buffer->ref==0) {
414 HeapFree(GetProcessHeap(),0,This->buffer->memory);
415 HeapFree(GetProcessHeap(),0,This->buffer);
419 if (This->notifies != NULL)
420 HeapFree(GetProcessHeap(), 0, This->notifies);
422 HeapFree(GetProcessHeap(),0,This);
424 TRACE("(%p) released\n",This);
428 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
429 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix)
433 TRACE("primary playpos=%ld, mixpos=%ld\n", pplay, pmix);
434 TRACE("this mixpos=%ld, time=%ld\n", bmix, GetTickCount());
436 /* the actual primary play position (pplay) is always behind last mixed (pmix),
437 * unless the computer is too slow or something */
438 /* we need to know how far away we are from there */
439 #if 0 /* we'll never fill the primary entirely */
441 if ((state == STATE_PLAYING) || (state == STATE_STOPPING)) {
442 /* wow, the software mixer is really doing well,
443 * seems the entire primary buffer is filled! */
444 pmix += This->dsound->buflen;
446 /* else: the primary buffer is not playing, so probably empty */
449 if (pmix < pplay) pmix += This->dsound->buflen; /* wraparound */
451 /* detect buffer underrun */
452 if (pwrite < pplay) pwrite += This->dsound->buflen; /* wraparound */
454 if (pmix > (ds_snd_queue_max * This->dsound->fraglen + pwrite + This->dsound->writelead)) {
455 WARN("detected an underrun: primary queue was %ld\n",pmix);
458 /* divide the offset by its sample size */
459 pmix /= This->dsound->wfx.nBlockAlign;
460 TRACE("primary back-samples=%ld\n",pmix);
461 /* adjust for our frequency */
462 pmix = (pmix * This->freqAdjust) >> DSOUND_FREQSHIFT;
463 /* multiply by our own sample size */
464 pmix *= This->wfx.nBlockAlign;
465 TRACE("this back-offset=%ld\n", pmix);
466 /* subtract from our last mixed position */
468 while (bplay < pmix) bplay += This->buflen; /* wraparound */
470 if (This->leadin && ((bplay < This->startpos) || (bplay > bmix))) {
471 /* seems we haven't started playing yet */
472 TRACE("this still in lead-in phase\n");
473 bplay = This->startpos;
475 /* return the result */
479 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
480 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
483 ICOM_THIS(IDirectSoundBufferImpl,iface);
484 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
486 hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
488 WARN("IDsDriverBuffer_GetPosition failed\n");
493 if (playpos && (This->state != STATE_PLAYING)) {
494 /* we haven't been merged into the primary buffer (yet) */
495 *playpos = This->buf_mixpos;
498 DWORD pplay, pwrite, lplay, splay, pstate;
499 /* let's get this exact; first, recursively call GetPosition on the primary */
500 EnterCriticalSection(&(This->dsound->mixlock));
501 if (DSOUND_PrimaryGetPosition(This->dsound, &pplay, &pwrite) != DS_OK)
502 WARN("DSOUND_PrimaryGetPosition failed\n");
503 /* detect HEL mode underrun */
504 pstate = This->dsound->state;
505 if (!(This->dsound->hwbuf || This->dsound->pwqueue)) {
506 TRACE("detected an underrun\n");
508 if (pstate == STATE_PLAYING)
509 pstate = STATE_STARTING;
510 else if (pstate == STATE_STOPPING)
511 pstate = STATE_STOPPED;
513 /* get data for ourselves while we still have the lock */
514 pstate &= This->state;
515 lplay = This->primary_mixpos;
516 splay = This->buf_mixpos;
517 if ((This->dsbd.dwFlags & DSBCAPS_GETCURRENTPOSITION2) || This->dsound->hwbuf) {
518 /* calculate play position using this */
519 *playpos = DSOUND_CalcPlayPosition(This, pstate, pplay, pwrite, lplay, splay);
521 /* (unless the app isn't using GETCURRENTPOSITION2) */
522 /* don't know exactly how this should be handled...
523 * the docs says that play cursor is reported as directly
524 * behind write cursor, hmm... */
525 /* let's just do what might work for Half-Life */
527 wp = (This->dsound->pwplay + ds_hel_margin) * This->dsound->fraglen;
528 while (wp >= This->dsound->buflen)
529 wp -= This->dsound->buflen;
530 *playpos = DSOUND_CalcPlayPosition(This, pstate, wp, pwrite, lplay, splay);
532 LeaveCriticalSection(&(This->dsound->mixlock));
534 if (writepos) *writepos = This->buf_mixpos;
537 if (This->state != STATE_STOPPED)
538 /* apply the documented 10ms lead to writepos */
539 *writepos += This->writelead;
540 while (*writepos >= This->buflen) *writepos -= This->buflen;
542 if (playpos) This->last_playpos = *playpos;
543 TRACE("playpos = %ld, writepos = %ld (%p, time=%ld)\n", playpos?*playpos:0, writepos?*writepos:0, This, GetTickCount());
547 static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
548 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
550 ICOM_THIS(IDirectSoundBufferImpl,iface);
551 TRACE("(%p,%p), thread is %04lx\n",This,status,GetCurrentThreadId());
553 if (status == NULL) {
554 WARN("invalid parameter: status = NULL\n");
555 return DSERR_INVALIDPARAM;
559 if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
560 *status |= DSBSTATUS_PLAYING;
561 if (This->playflags & DSBPLAY_LOOPING)
562 *status |= DSBSTATUS_LOOPING;
565 TRACE("status=%lx\n", *status);
570 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
571 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten
573 ICOM_THIS(IDirectSoundBufferImpl,iface);
574 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
576 if (wfsize>sizeof(This->wfx))
577 wfsize = sizeof(This->wfx);
578 if (lpwf) { /* NULL is valid */
579 memcpy(lpwf,&(This->wfx),wfsize);
584 *wfwritten = sizeof(This->wfx);
586 WARN("invalid parameter: wfwritten == NULL\n");
587 return DSERR_INVALIDPARAM;
594 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
595 LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
597 HRESULT hres = DS_OK;
598 ICOM_THIS(IDirectSoundBufferImpl,iface);
600 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n",
612 if (flags & DSBLOCK_FROMWRITECURSOR) {
614 /* GetCurrentPosition does too much magic to duplicate here */
615 hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writepos);
617 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
620 writecursor += writepos;
622 while (writecursor >= This->buflen)
623 writecursor -= This->buflen;
624 if (flags & DSBLOCK_ENTIREBUFFER)
625 writebytes = This->buflen;
626 if (writebytes > This->buflen)
627 writebytes = This->buflen;
629 assert(audiobytes1!=audiobytes2);
630 assert(lplpaudioptr1!=lplpaudioptr2);
632 EnterCriticalSection(&(This->lock));
634 if ((writebytes == This->buflen) &&
635 ((This->state == STATE_STARTING) ||
636 (This->state == STATE_PLAYING)))
637 /* some games, like Half-Life, try to be clever (not) and
638 * keep one secondary buffer, and mix sounds into it itself,
639 * locking the entire buffer every time... so we can just forget
640 * about tracking the last-written-to-position... */
641 This->probably_valid_to = (DWORD)-1;
643 This->probably_valid_to = writecursor;
645 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
646 hres = IDsDriverBuffer_Lock(This->hwbuf,
647 lplpaudioptr1, audiobytes1,
648 lplpaudioptr2, audiobytes2,
649 writecursor, writebytes,
652 WARN("IDsDriverBuffer_Lock failed\n");
653 LeaveCriticalSection(&(This->lock));
658 if (writecursor+writebytes <= This->buflen) {
659 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
660 *audiobytes1 = writebytes;
662 *(LPBYTE*)lplpaudioptr2 = NULL;
665 TRACE("->%ld.0\n",writebytes);
667 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
668 *audiobytes1 = This->buflen-writecursor;
670 *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
672 *audiobytes2 = writebytes-(This->buflen-writecursor);
673 TRACE("->%ld.%ld\n",*audiobytes1,audiobytes2?*audiobytes2:0);
675 if (This->state == STATE_PLAYING) {
676 /* if the segment between playpos and buf_mixpos is touched,
677 * we need to cancel some mixing */
678 /* we'll assume that the app always calls GetCurrentPosition before
679 * locking a playing buffer, so that last_playpos is up-to-date */
680 if (This->buf_mixpos >= This->last_playpos) {
681 if (This->buf_mixpos > writecursor &&
682 This->last_playpos < writecursor+writebytes)
686 if (This->buf_mixpos > writecursor ||
687 This->last_playpos < writecursor+writebytes)
691 TRACE("locking prebuffered region, ouch\n");
692 DSOUND_MixCancelAt(This, writecursor);
697 LeaveCriticalSection(&(This->lock));
701 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
702 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
704 HRESULT hres = DS_OK;
705 ICOM_THIS(IDirectSoundBufferImpl,iface);
706 TRACE("(%p,%ld)\n",This,newpos);
709 EnterCriticalSection(&(This->lock));
711 while (newpos >= This->buflen)
712 newpos -= This->buflen;
713 This->buf_mixpos = newpos;
715 hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
717 WARN("IDsDriverBuffer_SetPosition failed\n");
720 LeaveCriticalSection(&(This->lock));
726 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
727 LPDIRECTSOUNDBUFFER8 iface,LONG pan
729 HRESULT hres = DS_OK;
730 ICOM_THIS(IDirectSoundBufferImpl,iface);
733 TRACE("(%p,%ld)\n",This,pan);
735 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
736 WARN("invalid parameter: pan = %ld\n", pan);
737 return DSERR_INVALIDPARAM;
740 /* You cannot use both pan and 3D controls */
741 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
742 (This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
743 WARN("control unavailable\n");
744 return DSERR_CONTROLUNAVAIL;
748 EnterCriticalSection(&(This->lock));
750 oldPan = This->volpan.lPan;
751 This->volpan.lPan = pan;
754 DSOUND_RecalcVolPan(&(This->volpan));
757 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
759 WARN("IDsDriverBuffer_SetVolumePan failed\n");
761 DSOUND_ForceRemix(This);
764 LeaveCriticalSection(&(This->lock));
770 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
771 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
773 ICOM_THIS(IDirectSoundBufferImpl,iface);
774 TRACE("(%p,%p)\n",This,pan);
776 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
777 WARN("control unavailable\n");
778 return DSERR_CONTROLUNAVAIL;
782 WARN("invalid parameter: pan = NULL\n");
783 return DSERR_INVALIDPARAM;
786 *pan = This->volpan.lPan;
791 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
792 LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
794 ICOM_THIS(IDirectSoundBufferImpl,iface);
795 DWORD probably_valid_to;
797 TRACE("(%p,%p,%ld,%p,%ld)\n", This,p1,x1,p2,x2);
799 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
801 hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
803 WARN("IDsDriverBuffer_Unlock failed\n");
808 if (p2) probably_valid_to = (((LPBYTE)p2)-This->buffer->memory) + x2;
809 else probably_valid_to = (((LPBYTE)p1)-This->buffer->memory) + x1;
810 while (probably_valid_to >= This->buflen)
811 probably_valid_to -= This->buflen;
812 if ((probably_valid_to == 0) && ((x1+x2) == This->buflen) &&
813 ((This->state == STATE_STARTING) ||
814 (This->state == STATE_PLAYING)))
815 /* see IDirectSoundBufferImpl_Lock */
816 probably_valid_to = (DWORD)-1;
817 This->probably_valid_to = probably_valid_to;
822 static HRESULT WINAPI IDirectSoundBufferImpl_Restore(
823 LPDIRECTSOUNDBUFFER8 iface
825 ICOM_THIS(IDirectSoundBufferImpl,iface);
826 FIXME("(%p):stub\n",This);
830 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
831 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
833 ICOM_THIS(IDirectSoundBufferImpl,iface);
834 TRACE("(%p,%p)\n",This,freq);
837 WARN("invalid parameter: freq = NULL\n");
838 return DSERR_INVALIDPARAM;
842 TRACE("-> %ld\n", *freq);
847 static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(
848 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
850 ICOM_THIS(IDirectSoundBufferImpl,iface);
853 FIXME("(%p,%lu,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
856 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
858 WARN("control unavailable\n");
859 return DSERR_CONTROLUNAVAIL;
862 static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(
863 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
865 ICOM_THIS(IDirectSoundBufferImpl,iface);
868 FIXME("(%p,%08lu,%lu,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
871 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
873 WARN("control unavailable\n");
874 return DSERR_CONTROLUNAVAIL;
877 static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(
878 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
880 ICOM_THIS(IDirectSoundBufferImpl,iface);
882 FIXME("(%p,%s,%lu,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
884 WARN("control unavailable\n");
885 return DSERR_CONTROLUNAVAIL;
888 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
889 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND8 dsound,LPCDSBUFFERDESC dbsd
891 ICOM_THIS(IDirectSoundBufferImpl,iface);
892 FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
893 DPRINTF("Re-Init!!!\n");
894 WARN("already initialized\n");
895 return DSERR_ALREADYINITIALIZED;
898 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
899 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
901 ICOM_THIS(IDirectSoundBufferImpl,iface);
902 TRACE("(%p)->(%p)\n",This,caps);
905 WARN("invalid parameter: caps == NULL\n");
906 return DSERR_INVALIDPARAM;
909 if (caps->dwSize < sizeof(*caps)) {
910 WARN("invalid parameter: caps->dwSize = %ld < %d\n",caps->dwSize, sizeof(*caps));
911 return DSERR_INVALIDPARAM;
914 caps->dwFlags = This->dsbd.dwFlags;
915 if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
916 else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
918 caps->dwBufferBytes = This->buflen;
920 /* This value represents the speed of the "unlock" command.
921 As unlock is quite fast (it does not do anything), I put
922 4096 ko/s = 4 Mo / s */
923 /* FIXME: hwbuf speed */
924 caps->dwUnlockTransferRate = 4096;
925 caps->dwPlayCpuOverhead = 0;
930 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
931 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
933 ICOM_THIS(IDirectSoundBufferImpl,iface);
935 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
938 WARN("invalid parameter\n");
942 *ppobj = NULL; /* assume failure */
944 if ( IsEqualGUID(riid, &IID_IUnknown) ||
945 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
946 IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
948 SecondaryBufferImpl_Create(This, &(This->dsb));
950 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)This->dsb);
954 WARN("IID_IDirectSoundBuffer\n");
955 return E_NOINTERFACE;
958 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ||
959 IsEqualGUID( &IID_IDirectSoundNotify8, riid ) ) {
961 IDirectSoundNotifyImpl_Create(This, &(This->notify));
963 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
964 *ppobj = This->notify;
967 WARN("IID_IDirectSoundNotify\n");
968 return E_NOINTERFACE;
971 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
973 IDirectSound3DBufferImpl_Create(This, &(This->ds3db));
975 IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->ds3db);
976 *ppobj = This->ds3db;
979 WARN("IID_IDirectSound3DBuffer\n");
980 return E_NOINTERFACE;
983 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
984 ERR("app requested IDirectSound3DListener on secondary buffer\n");
985 return E_NOINTERFACE;
988 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
989 /* only supported on hardware 3D secondary buffers */
990 if (!(This->dsbd.dwFlags & DSBCAPS_PRIMARYBUFFER) &&
991 (This->dsbd.dwFlags & DSBCAPS_CTRL3D) &&
992 (This->hwbuf != NULL) ) {
994 IKsBufferPropertySetImpl_Create(This, &(This->iks));
996 IKsPropertySet_AddRef((LPKSPROPERTYSET)*ppobj);
1001 WARN("IID_IKsPropertySet\n");
1002 return E_NOINTERFACE;
1005 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
1007 return E_NOINTERFACE;
1010 static ICOM_VTABLE(IDirectSoundBuffer8) dsbvt =
1012 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1013 IDirectSoundBufferImpl_QueryInterface,
1014 IDirectSoundBufferImpl_AddRef,
1015 IDirectSoundBufferImpl_Release,
1016 IDirectSoundBufferImpl_GetCaps,
1017 IDirectSoundBufferImpl_GetCurrentPosition,
1018 IDirectSoundBufferImpl_GetFormat,
1019 IDirectSoundBufferImpl_GetVolume,
1020 IDirectSoundBufferImpl_GetPan,
1021 IDirectSoundBufferImpl_GetFrequency,
1022 IDirectSoundBufferImpl_GetStatus,
1023 IDirectSoundBufferImpl_Initialize,
1024 IDirectSoundBufferImpl_Lock,
1025 IDirectSoundBufferImpl_Play,
1026 IDirectSoundBufferImpl_SetCurrentPosition,
1027 IDirectSoundBufferImpl_SetFormat,
1028 IDirectSoundBufferImpl_SetVolume,
1029 IDirectSoundBufferImpl_SetPan,
1030 IDirectSoundBufferImpl_SetFrequency,
1031 IDirectSoundBufferImpl_Stop,
1032 IDirectSoundBufferImpl_Unlock,
1033 IDirectSoundBufferImpl_Restore,
1034 IDirectSoundBufferImpl_SetFX,
1035 IDirectSoundBufferImpl_AcquireResources,
1036 IDirectSoundBufferImpl_GetObjectInPath
1039 HRESULT WINAPI IDirectSoundBufferImpl_Create(
1040 IDirectSoundImpl *ds,
1041 IDirectSoundBufferImpl **pdsb,
1042 LPCDSBUFFERDESC dsbd)
1044 IDirectSoundBufferImpl *dsb;
1045 LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
1046 HRESULT err = DS_OK;
1049 TRACE("(%p,%p,%p)\n",ds,pdsb,dsbd);
1051 if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
1052 WARN("invalid parameter: dsbd->dwBufferBytes = %ld\n", dsbd->dwBufferBytes);
1054 return DSERR_INVALIDPARAM; /* FIXME: which error? */
1057 dsb = (IDirectSoundBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
1060 WARN("out of memory\n");
1062 return DSERR_OUTOFMEMORY;
1067 dsb->lpVtbl = &dsbvt;
1070 memcpy(&dsb->dsbd, dsbd, sizeof(*dsbd));
1072 memcpy(&dsb->wfx, wfex, sizeof(dsb->wfx));
1074 TRACE("Created buffer at %p\n", dsb);
1076 dsb->buflen = dsbd->dwBufferBytes;
1077 dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
1080 dsb->notifies = NULL;
1081 dsb->nrofnotifies = 0;
1084 /* Check necessary hardware mixing capabilities */
1085 if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
1086 else capf |= DSCAPS_SECONDARYMONO;
1087 if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
1088 else capf |= DSCAPS_SECONDARY8BIT;
1090 use_hw = (ds->drvcaps.dwFlags & capf) == capf;
1091 TRACE("use_hw = 0x%08x, capf = 0x%08lx, ds->drvcaps.dwFlags = 0x%08lx\n", use_hw, capf, ds->drvcaps.dwFlags);
1093 /* FIXME: check hardware sample rate mixing capabilities */
1094 /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
1095 /* FIXME: check whether any hardware buffers are left */
1096 /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
1098 /* Allocate system memory if applicable */
1099 if ((ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
1100 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1101 if (dsb->buffer == NULL) {
1102 WARN("out of memory\n");
1103 HeapFree(GetProcessHeap(),0,dsb);
1105 return DSERR_OUTOFMEMORY;
1108 dsb->buffer->memory = (LPBYTE)HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1109 if (dsb->buffer->memory == NULL) {
1110 WARN("out of memory\n");
1111 HeapFree(GetProcessHeap(),0,dsb->buffer);
1112 HeapFree(GetProcessHeap(),0,dsb);
1114 return DSERR_OUTOFMEMORY;
1116 dsb->buffer->ref = 1;
1119 /* Allocate the hardware buffer */
1121 err = IDsDriver_CreateSoundBuffer(ds->driver,wfex,dsbd->dwFlags,0,
1122 &(dsb->buflen),&(dsb->buffer->memory),
1123 (LPVOID*)&(dsb->hwbuf));
1124 /* fall back to software buffer on failure */
1126 TRACE("IDsDriver_CreateSoundBuffer failed, falling back to software buffer\n");
1128 if (ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
1129 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1130 if (dsb->buffer == NULL) {
1131 WARN("out of memory\n");
1132 HeapFree(GetProcessHeap(),0,dsb);
1134 return DSERR_OUTOFMEMORY;
1137 dsb->buffer->memory = (LPBYTE)HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1138 if (dsb->buffer->memory == NULL) {
1139 WARN("out of memory\n");
1140 HeapFree(GetProcessHeap(),0,dsb->buffer);
1141 HeapFree(GetProcessHeap(),0,dsb);
1143 return DSERR_OUTOFMEMORY;
1145 dsb->buffer->ref = 1;
1150 /* calculate fragment size and write lead */
1151 DSOUND_RecalcFormat(dsb);
1153 /* It's not necessary to initialize values to zero since */
1154 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1156 dsb->buf_mixpos = 0;
1157 dsb->state = STATE_STOPPED;
1159 dsb->freqAdjust = (dsb->freq << DSOUND_FREQSHIFT) /
1160 ds->wfx.nSamplesPerSec;
1161 dsb->nAvgBytesPerSec = dsb->freq *
1162 dsbd->lpwfxFormat->nBlockAlign;
1164 if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
1165 dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
1166 dsb->ds3db_ds3db.vPosition.x = 0.0;
1167 dsb->ds3db_ds3db.vPosition.y = 0.0;
1168 dsb->ds3db_ds3db.vPosition.z = 0.0;
1169 dsb->ds3db_ds3db.vVelocity.x = 0.0;
1170 dsb->ds3db_ds3db.vVelocity.y = 0.0;
1171 dsb->ds3db_ds3db.vVelocity.z = 0.0;
1172 dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1173 dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1174 dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
1175 dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
1176 dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
1177 dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1178 dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1179 dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1180 dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
1182 dsb->ds3db_need_recalc = FALSE;
1183 DSOUND_Calc3DBuffer(dsb);
1185 DSOUND_RecalcVolPan(&(dsb->volpan));
1187 InitializeCriticalSection(&(dsb->lock));
1189 /* register buffer */
1190 RtlAcquireResourceExclusive(&(ds->lock), TRUE);
1191 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1192 IDirectSoundBufferImpl **newbuffers;
1194 newbuffers = (IDirectSoundBufferImpl**)HeapReAlloc(GetProcessHeap(),0,ds->buffers,sizeof(IDirectSoundBufferImpl*)*(ds->nrofbuffers+1));
1196 newbuffers = (IDirectSoundBufferImpl**)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(ds->nrofbuffers+1));
1199 ds->buffers = newbuffers;
1200 ds->buffers[ds->nrofbuffers] = dsb;
1202 TRACE("buffer count is now %d\n", ds->nrofbuffers);
1204 ERR("out of memory for buffer list! Current buffer count is %d\n", ds->nrofbuffers);
1205 if (dsb->buffer->memory)
1206 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1208 HeapFree(GetProcessHeap(),0,dsb->buffer);
1209 DeleteCriticalSection(&(dsb->lock));
1210 RtlReleaseResource(&(ds->lock));
1211 HeapFree(GetProcessHeap(),0,dsb);
1213 return DSERR_OUTOFMEMORY;
1216 RtlReleaseResource(&(ds->lock));
1217 IDirectSound8_AddRef((LPDIRECTSOUND8)ds);
1222 /*******************************************************************************
1226 static HRESULT WINAPI SecondaryBufferImpl_QueryInterface(
1227 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj)
1229 ICOM_THIS(SecondaryBufferImpl,iface);
1230 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
1232 return IDirectSoundBufferImpl_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb,riid,ppobj);
1235 static DWORD WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
1237 ICOM_THIS(IDirectSoundBufferImpl,iface);
1239 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1241 ref = InterlockedIncrement(&(This->ref));
1243 FIXME("thread-safety alert! AddRef-ing with a zero refcount!\n");
1248 static DWORD WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
1250 ICOM_THIS(IDirectSoundBufferImpl,iface);
1252 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1254 ref = InterlockedDecrement(&(This->ref));
1256 This->dsb->dsb = NULL;
1257 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
1258 HeapFree(GetProcessHeap(),0,This);
1259 TRACE("(%p) released\n",This);
1264 static HRESULT WINAPI SecondaryBufferImpl_GetCaps(
1265 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps)
1267 ICOM_THIS(SecondaryBufferImpl,iface);
1268 TRACE("(%p)->(%p)\n",This,caps);
1270 return IDirectSoundBufferImpl_GetCaps((LPDIRECTSOUNDBUFFER8)This->dsb,caps);
1273 static HRESULT WINAPI SecondaryBufferImpl_GetCurrentPosition(
1274 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos)
1276 ICOM_THIS(SecondaryBufferImpl,iface);
1277 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
1279 return IDirectSoundBufferImpl_GetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,playpos,writepos);
1282 static HRESULT WINAPI SecondaryBufferImpl_GetFormat(
1283 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten)
1285 ICOM_THIS(SecondaryBufferImpl,iface);
1286 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
1288 return IDirectSoundBufferImpl_GetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,lpwf,wfsize,wfwritten);
1291 static HRESULT WINAPI SecondaryBufferImpl_GetVolume(
1292 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol)
1294 ICOM_THIS(SecondaryBufferImpl,iface);
1295 TRACE("(%p,%p)\n",This,vol);
1297 return IDirectSoundBufferImpl_GetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1300 static HRESULT WINAPI SecondaryBufferImpl_GetPan(
1301 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan)
1303 ICOM_THIS(SecondaryBufferImpl,iface);
1304 TRACE("(%p,%p)\n",This,pan);
1306 return IDirectSoundBufferImpl_GetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1309 static HRESULT WINAPI SecondaryBufferImpl_GetFrequency(
1310 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq)
1312 ICOM_THIS(SecondaryBufferImpl,iface);
1313 TRACE("(%p,%p)\n",This,freq);
1315 return IDirectSoundBufferImpl_GetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1318 static HRESULT WINAPI SecondaryBufferImpl_GetStatus(
1319 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status)
1321 ICOM_THIS(SecondaryBufferImpl,iface);
1322 TRACE("(%p,%p)\n",This,status);
1324 return IDirectSoundBufferImpl_GetStatus((LPDIRECTSOUNDBUFFER8)This->dsb,status);
1327 static HRESULT WINAPI SecondaryBufferImpl_Initialize(
1328 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND8 dsound,LPCDSBUFFERDESC dbsd)
1330 ICOM_THIS(SecondaryBufferImpl,iface);
1331 TRACE("(%p,%p,%p)\n",This,dsound,dbsd);
1333 return IDirectSoundBufferImpl_Initialize((LPDIRECTSOUNDBUFFER8)This->dsb,dsound,dbsd);
1336 static HRESULT WINAPI SecondaryBufferImpl_Lock(
1337 LPDIRECTSOUNDBUFFER8 iface,
1340 LPVOID lplpaudioptr1,
1341 LPDWORD audiobytes1,
1342 LPVOID lplpaudioptr2,
1343 LPDWORD audiobytes2,
1346 ICOM_THIS(SecondaryBufferImpl,iface);
1347 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx)\n",
1348 This,writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1350 return IDirectSoundBufferImpl_Lock((LPDIRECTSOUNDBUFFER8)This->dsb,
1351 writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1354 static HRESULT WINAPI SecondaryBufferImpl_Play(
1355 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags)
1357 ICOM_THIS(SecondaryBufferImpl,iface);
1358 TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
1360 return IDirectSoundBufferImpl_Play((LPDIRECTSOUNDBUFFER8)This->dsb,reserved1,reserved2,flags);
1363 static HRESULT WINAPI SecondaryBufferImpl_SetCurrentPosition(
1364 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos)
1366 ICOM_THIS(SecondaryBufferImpl,iface);
1367 TRACE("(%p,%ld)\n",This,newpos);
1369 return IDirectSoundBufferImpl_SetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,newpos);
1372 static HRESULT WINAPI SecondaryBufferImpl_SetFormat(
1373 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex)
1375 ICOM_THIS(SecondaryBufferImpl,iface);
1376 TRACE("(%p,%p)\n",This,wfex);
1378 return IDirectSoundBufferImpl_SetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,wfex);
1381 static HRESULT WINAPI SecondaryBufferImpl_SetVolume(
1382 LPDIRECTSOUNDBUFFER8 iface,LONG vol)
1384 ICOM_THIS(SecondaryBufferImpl,iface);
1385 TRACE("(%p,%ld)\n",This,vol);
1387 return IDirectSoundBufferImpl_SetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1390 static HRESULT WINAPI SecondaryBufferImpl_SetPan(
1391 LPDIRECTSOUNDBUFFER8 iface,LONG pan)
1393 ICOM_THIS(SecondaryBufferImpl,iface);
1394 TRACE("(%p,%ld)\n",This,pan);
1396 return IDirectSoundBufferImpl_SetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1399 static HRESULT WINAPI SecondaryBufferImpl_SetFrequency(
1400 LPDIRECTSOUNDBUFFER8 iface,DWORD freq)
1402 ICOM_THIS(SecondaryBufferImpl,iface);
1403 TRACE("(%p,%ld)\n",This,freq);
1405 return IDirectSoundBufferImpl_SetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1408 static HRESULT WINAPI SecondaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
1410 ICOM_THIS(SecondaryBufferImpl,iface);
1411 TRACE("(%p)\n",This);
1413 return IDirectSoundBufferImpl_Stop((LPDIRECTSOUNDBUFFER8)This->dsb);
1416 static HRESULT WINAPI SecondaryBufferImpl_Unlock(
1417 LPDIRECTSOUNDBUFFER8 iface,
1418 LPVOID lpvAudioPtr1,
1419 DWORD dwAudioBytes1,
1420 LPVOID lpvAudioPtr2,
1421 DWORD dwAudioBytes2)
1423 ICOM_THIS(SecondaryBufferImpl,iface);
1424 TRACE("(%p,%p,%ld,%p,%ld)\n",
1425 This, lpvAudioPtr1, dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1427 return IDirectSoundBufferImpl_Unlock((LPDIRECTSOUNDBUFFER8)This->dsb,
1428 lpvAudioPtr1,dwAudioBytes1,lpvAudioPtr2,dwAudioBytes2);
1431 static HRESULT WINAPI SecondaryBufferImpl_Restore(
1432 LPDIRECTSOUNDBUFFER8 iface)
1434 ICOM_THIS(SecondaryBufferImpl,iface);
1435 TRACE("(%p)\n",This);
1437 return IDirectSoundBufferImpl_Restore((LPDIRECTSOUNDBUFFER8)This->dsb);
1440 static HRESULT WINAPI SecondaryBufferImpl_SetFX(
1441 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes)
1443 ICOM_THIS(SecondaryBufferImpl,iface);
1444 TRACE("(%p,%lu,%p,%p)\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1446 return IDirectSoundBufferImpl_SetFX((LPDIRECTSOUNDBUFFER8)This->dsb,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1449 static HRESULT WINAPI SecondaryBufferImpl_AcquireResources(
1450 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes)
1452 ICOM_THIS(SecondaryBufferImpl,iface);
1453 TRACE("(%p,%08lu,%lu,%p)\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
1455 return IDirectSoundBufferImpl_AcquireResources((LPDIRECTSOUNDBUFFER8)This->dsb,dwFlags,dwEffectsCount,pdwResultCodes);
1458 static HRESULT WINAPI SecondaryBufferImpl_GetObjectInPath(
1459 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject)
1461 ICOM_THIS(SecondaryBufferImpl,iface);
1462 TRACE("(%p,%s,%lu,%s,%p)\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
1464 return IDirectSoundBufferImpl_GetObjectInPath((LPDIRECTSOUNDBUFFER8)This->dsb,rguidObject,dwIndex,rguidInterface,ppObject);
1467 static ICOM_VTABLE(IDirectSoundBuffer8) sbvt =
1469 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1470 SecondaryBufferImpl_QueryInterface,
1471 SecondaryBufferImpl_AddRef,
1472 SecondaryBufferImpl_Release,
1473 SecondaryBufferImpl_GetCaps,
1474 SecondaryBufferImpl_GetCurrentPosition,
1475 SecondaryBufferImpl_GetFormat,
1476 SecondaryBufferImpl_GetVolume,
1477 SecondaryBufferImpl_GetPan,
1478 SecondaryBufferImpl_GetFrequency,
1479 SecondaryBufferImpl_GetStatus,
1480 SecondaryBufferImpl_Initialize,
1481 SecondaryBufferImpl_Lock,
1482 SecondaryBufferImpl_Play,
1483 SecondaryBufferImpl_SetCurrentPosition,
1484 SecondaryBufferImpl_SetFormat,
1485 SecondaryBufferImpl_SetVolume,
1486 SecondaryBufferImpl_SetPan,
1487 SecondaryBufferImpl_SetFrequency,
1488 SecondaryBufferImpl_Stop,
1489 SecondaryBufferImpl_Unlock,
1490 SecondaryBufferImpl_Restore,
1491 SecondaryBufferImpl_SetFX,
1492 SecondaryBufferImpl_AcquireResources,
1493 SecondaryBufferImpl_GetObjectInPath
1496 HRESULT WINAPI SecondaryBufferImpl_Create(
1497 IDirectSoundBufferImpl *dsb,
1498 SecondaryBufferImpl **psb)
1500 SecondaryBufferImpl *sb;
1501 TRACE("(%p,%p)\n",dsb,psb);
1503 sb = (SecondaryBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*sb));
1506 WARN("out of memory\n");
1508 return DSERR_OUTOFMEMORY;
1514 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)dsb);