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 IDirectSoundNotifyVtbl dsnvt =
150 IDirectSoundNotifyImpl_QueryInterface,
151 IDirectSoundNotifyImpl_AddRef,
152 IDirectSoundNotifyImpl_Release,
153 IDirectSoundNotifyImpl_SetNotificationPositions,
156 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
157 IDirectSoundBufferImpl * dsb,
158 IDirectSoundNotifyImpl **pdsn)
160 IDirectSoundNotifyImpl * dsn;
161 TRACE("(%p,%p)\n",dsb,pdsn);
163 dsn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dsn));
166 WARN("out of memory\n");
167 return DSERR_OUTOFMEMORY;
171 dsn->lpVtbl = &dsnvt;
174 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
180 HRESULT WINAPI IDirectSoundNotifyImpl_Destroy(
181 IDirectSoundNotifyImpl *pdsn)
183 TRACE("(%p)\n",pdsn);
185 while (IDirectSoundNotifyImpl_Release((LPDIRECTSOUNDNOTIFY)pdsn) > 0);
190 /*******************************************************************************
194 static HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(
195 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex
197 ICOM_THIS(IDirectSoundBufferImpl,iface);
199 TRACE("(%p,%p)\n",This,wfex);
200 /* This method is not available on secondary buffers */
201 WARN("invalid call\n");
202 return DSERR_INVALIDCALL;
205 static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
206 LPDIRECTSOUNDBUFFER8 iface,LONG vol
208 ICOM_THIS(IDirectSoundBufferImpl,iface);
211 TRACE("(%p,%ld)\n",This,vol);
213 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
214 WARN("control unavailable: This->dsbd.dwFlags = 0x%08lx\n", This->dsbd.dwFlags);
215 return DSERR_CONTROLUNAVAIL;
218 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
219 WARN("invalid parameter: vol = %ld\n", vol);
220 return DSERR_INVALIDPARAM;
224 EnterCriticalSection(&(This->lock));
226 if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) {
227 oldVol = This->ds3db_lVolume;
228 This->ds3db_lVolume = vol;
230 oldVol = This->volpan.lVolume;
231 This->volpan.lVolume = vol;
233 DSOUND_RecalcVolPan(&(This->volpan));
239 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
241 WARN("IDsDriverBuffer_SetVolumePan failed\n");
243 DSOUND_ForceRemix(This);
246 LeaveCriticalSection(&(This->lock));
252 static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(
253 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
255 ICOM_THIS(IDirectSoundBufferImpl,iface);
256 TRACE("(%p,%p)\n",This,vol);
258 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
259 WARN("control unavailable\n");
260 return DSERR_CONTROLUNAVAIL;
264 WARN("invalid parameter: vol == NULL\n");
265 return DSERR_INVALIDPARAM;
268 *vol = This->volpan.lVolume;
273 static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
274 LPDIRECTSOUNDBUFFER8 iface,DWORD freq
276 ICOM_THIS(IDirectSoundBufferImpl,iface);
279 TRACE("(%p,%ld)\n",This,freq);
281 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
282 WARN("control unavailable\n");
283 return DSERR_CONTROLUNAVAIL;
286 if (freq == DSBFREQUENCY_ORIGINAL)
287 freq = This->pwfx->nSamplesPerSec;
289 if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX)) {
290 WARN("invalid parameter: freq = %ld\n", freq);
291 return DSERR_INVALIDPARAM;
295 EnterCriticalSection(&(This->lock));
297 oldFreq = This->freq;
299 if (freq != oldFreq) {
300 This->freqAdjust = (freq << DSOUND_FREQSHIFT) / This->dsound->pwfx->nSamplesPerSec;
301 This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;
302 DSOUND_RecalcFormat(This);
304 DSOUND_ForceRemix(This);
307 LeaveCriticalSection(&(This->lock));
313 static HRESULT WINAPI IDirectSoundBufferImpl_Play(
314 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
316 HRESULT hres = DS_OK;
317 ICOM_THIS(IDirectSoundBufferImpl,iface);
318 TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
321 EnterCriticalSection(&(This->lock));
323 This->playflags = flags;
324 if (This->state == STATE_STOPPED) {
326 This->startpos = This->buf_mixpos;
327 This->state = STATE_STARTING;
328 } else if (This->state == STATE_STOPPING)
329 This->state = STATE_PLAYING;
331 hres = IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
333 WARN("IDsDriverBuffer_Play failed\n");
335 This->state = STATE_PLAYING;
338 LeaveCriticalSection(&(This->lock));
344 static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
346 HRESULT hres = DS_OK;
347 ICOM_THIS(IDirectSoundBufferImpl,iface);
348 TRACE("(%p)\n",This);
351 EnterCriticalSection(&(This->lock));
353 if (This->state == STATE_PLAYING)
354 This->state = STATE_STOPPING;
355 else if (This->state == STATE_STARTING)
356 This->state = STATE_STOPPED;
358 hres = IDsDriverBuffer_Stop(This->hwbuf);
360 WARN("IDsDriverBuffer_Stop failed\n");
362 This->state = STATE_STOPPED;
364 DSOUND_CheckEvent(This, 0);
366 LeaveCriticalSection(&(This->lock));
372 static DWORD WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface) {
373 ICOM_THIS(IDirectSoundBufferImpl,iface);
376 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
378 ref = InterlockedIncrement(&(This->ref));
380 FIXME("thread-safety alert! AddRef-ing with a zero refcount!\n");
385 static DWORD WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface) {
386 ICOM_THIS(IDirectSoundBufferImpl,iface);
390 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
392 ref = InterlockedDecrement(&(This->ref));
395 RtlAcquireResourceExclusive(&(This->dsound->lock), TRUE);
396 for (i=0;i<This->dsound->nrofbuffers;i++)
397 if (This->dsound->buffers[i] == This)
399 if (i < This->dsound->nrofbuffers) {
400 /* Put the last buffer of the list in the (now empty) position */
401 This->dsound->buffers[i] = This->dsound->buffers[This->dsound->nrofbuffers - 1];
402 This->dsound->nrofbuffers--;
403 This->dsound->buffers = HeapReAlloc(GetProcessHeap(),0,This->dsound->buffers,sizeof(LPDIRECTSOUNDBUFFER8)*This->dsound->nrofbuffers);
404 TRACE("(%p) buffer count is now %d\n", This, This->dsound->nrofbuffers);
406 if (This->dsound->nrofbuffers == 0) {
407 HeapFree(GetProcessHeap(),0,This->dsound->buffers);
408 This->dsound->buffers = NULL;
410 RtlReleaseResource(&(This->dsound->lock));
412 DeleteCriticalSection(&(This->lock));
415 IDsDriverBuffer_Release(This->hwbuf);
416 if (This->dsound->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
418 if (This->buffer->ref==0) {
419 HeapFree(GetProcessHeap(),0,This->buffer->memory);
420 HeapFree(GetProcessHeap(),0,This->buffer);
425 if (This->buffer->ref==0) {
426 HeapFree(GetProcessHeap(),0,This->buffer->memory);
427 HeapFree(GetProcessHeap(),0,This->buffer);
431 if (This->notifies != NULL)
432 HeapFree(GetProcessHeap(), 0, This->notifies);
435 HeapFree(GetProcessHeap(), 0, This->pwfx);
437 HeapFree(GetProcessHeap(),0,This);
439 TRACE("(%p) released\n",This);
443 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
444 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix)
448 TRACE("primary playpos=%ld, mixpos=%ld\n", pplay, pmix);
449 TRACE("this mixpos=%ld, time=%ld\n", bmix, GetTickCount());
451 /* the actual primary play position (pplay) is always behind last mixed (pmix),
452 * unless the computer is too slow or something */
453 /* we need to know how far away we are from there */
454 #if 0 /* we'll never fill the primary entirely */
456 if ((state == STATE_PLAYING) || (state == STATE_STOPPING)) {
457 /* wow, the software mixer is really doing well,
458 * seems the entire primary buffer is filled! */
459 pmix += This->dsound->buflen;
461 /* else: the primary buffer is not playing, so probably empty */
464 if (pmix < pplay) pmix += This->dsound->buflen; /* wraparound */
466 /* detect buffer underrun */
467 if (pwrite < pplay) pwrite += This->dsound->buflen; /* wraparound */
469 if (pmix > (ds_snd_queue_max * This->dsound->fraglen + pwrite + This->dsound->writelead)) {
470 WARN("detected an underrun: primary queue was %ld\n",pmix);
473 /* divide the offset by its sample size */
474 pmix /= This->dsound->pwfx->nBlockAlign;
475 TRACE("primary back-samples=%ld\n",pmix);
476 /* adjust for our frequency */
477 pmix = (pmix * This->freqAdjust) >> DSOUND_FREQSHIFT;
478 /* multiply by our own sample size */
479 pmix *= This->pwfx->nBlockAlign;
480 TRACE("this back-offset=%ld\n", pmix);
481 /* subtract from our last mixed position */
483 while (bplay < pmix) bplay += This->buflen; /* wraparound */
485 if (This->leadin && ((bplay < This->startpos) || (bplay > bmix))) {
486 /* seems we haven't started playing yet */
487 TRACE("this still in lead-in phase\n");
488 bplay = This->startpos;
490 /* return the result */
494 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
495 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
498 ICOM_THIS(IDirectSoundBufferImpl,iface);
499 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
501 hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
503 WARN("IDsDriverBuffer_GetPosition failed\n");
507 if (playpos && (This->state != STATE_PLAYING)) {
508 /* we haven't been merged into the primary buffer (yet) */
509 *playpos = This->buf_mixpos;
510 } else if (playpos) {
511 DWORD pplay, pwrite, lplay, splay, pstate;
512 /* let's get this exact; first, recursively call GetPosition on the primary */
513 EnterCriticalSection(&(This->dsound->mixlock));
514 if (DSOUND_PrimaryGetPosition(This->dsound, &pplay, &pwrite) != DS_OK)
515 WARN("DSOUND_PrimaryGetPosition failed\n");
516 /* detect HEL mode underrun */
517 pstate = This->dsound->state;
518 if (!(This->dsound->hwbuf || This->dsound->pwqueue)) {
519 TRACE("detected an underrun\n");
521 if (pstate == STATE_PLAYING)
522 pstate = STATE_STARTING;
523 else if (pstate == STATE_STOPPING)
524 pstate = STATE_STOPPED;
526 /* get data for ourselves while we still have the lock */
527 pstate &= This->state;
528 lplay = This->primary_mixpos;
529 splay = This->buf_mixpos;
530 if ((This->dsbd.dwFlags & DSBCAPS_GETCURRENTPOSITION2) || This->dsound->hwbuf) {
531 /* calculate play position using this */
532 *playpos = DSOUND_CalcPlayPosition(This, pstate, pplay, pwrite, lplay, splay);
534 /* (unless the app isn't using GETCURRENTPOSITION2) */
535 /* don't know exactly how this should be handled...
536 * the docs says that play cursor is reported as directly
537 * behind write cursor, hmm... */
538 /* let's just do what might work for Half-Life */
540 wp = (This->dsound->pwplay + ds_hel_margin) * This->dsound->fraglen;
541 wp %= This->dsound->buflen;
542 *playpos = DSOUND_CalcPlayPosition(This, pstate, wp, pwrite, lplay, splay);
544 LeaveCriticalSection(&(This->dsound->mixlock));
547 *writepos = This->buf_mixpos;
550 if (This->state != STATE_STOPPED) {
551 /* apply the documented 10ms lead to writepos */
552 *writepos += This->writelead;
554 *writepos %= This->buflen;
557 This->last_playpos = *playpos;
558 TRACE("playpos = %ld, writepos = %ld (%p, time=%ld)\n", playpos?*playpos:0, writepos?*writepos:0, This, GetTickCount());
562 static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
563 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
565 ICOM_THIS(IDirectSoundBufferImpl,iface);
566 TRACE("(%p,%p), thread is %04lx\n",This,status,GetCurrentThreadId());
568 if (status == NULL) {
569 WARN("invalid parameter: status = NULL\n");
570 return DSERR_INVALIDPARAM;
574 if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
575 *status |= DSBSTATUS_PLAYING;
576 if (This->playflags & DSBPLAY_LOOPING)
577 *status |= DSBSTATUS_LOOPING;
580 TRACE("status=%lx\n", *status);
585 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
586 LPDIRECTSOUNDBUFFER8 iface,
592 ICOM_THIS(IDirectSoundBufferImpl,iface);
593 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
595 size = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
597 if (lpwf) { /* NULL is valid */
598 if (wfsize >= size) {
599 memcpy(lpwf,This->pwfx,size);
603 WARN("invalid parameter: wfsize to small\n");
606 return DSERR_INVALIDPARAM;
610 *wfwritten = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
612 WARN("invalid parameter: wfwritten == NULL\n");
613 return DSERR_INVALIDPARAM;
620 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
621 LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
623 HRESULT hres = DS_OK;
624 ICOM_THIS(IDirectSoundBufferImpl,iface);
626 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n",
638 if (flags & DSBLOCK_FROMWRITECURSOR) {
640 /* GetCurrentPosition does too much magic to duplicate here */
641 hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writepos);
643 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
646 writecursor += writepos;
648 writecursor %= This->buflen;
649 if (flags & DSBLOCK_ENTIREBUFFER)
650 writebytes = This->buflen;
651 if (writebytes > This->buflen)
652 writebytes = This->buflen;
654 EnterCriticalSection(&(This->lock));
656 if ((writebytes == This->buflen) &&
657 ((This->state == STATE_STARTING) ||
658 (This->state == STATE_PLAYING)))
659 /* some games, like Half-Life, try to be clever (not) and
660 * keep one secondary buffer, and mix sounds into it itself,
661 * locking the entire buffer every time... so we can just forget
662 * about tracking the last-written-to-position... */
663 This->probably_valid_to = (DWORD)-1;
665 This->probably_valid_to = writecursor;
667 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
668 hres = IDsDriverBuffer_Lock(This->hwbuf,
669 lplpaudioptr1, audiobytes1,
670 lplpaudioptr2, audiobytes2,
671 writecursor, writebytes,
674 WARN("IDsDriverBuffer_Lock failed\n");
675 LeaveCriticalSection(&(This->lock));
680 if (writecursor+writebytes <= This->buflen) {
681 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
682 *audiobytes1 = writebytes;
684 *(LPBYTE*)lplpaudioptr2 = NULL;
687 TRACE("->%ld.0\n",writebytes);
689 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
690 *audiobytes1 = This->buflen-writecursor;
692 *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
694 *audiobytes2 = writebytes-(This->buflen-writecursor);
695 TRACE("->%ld.%ld\n",*audiobytes1,audiobytes2?*audiobytes2:0);
697 if (This->state == STATE_PLAYING) {
698 /* if the segment between playpos and buf_mixpos is touched,
699 * we need to cancel some mixing */
700 /* we'll assume that the app always calls GetCurrentPosition before
701 * locking a playing buffer, so that last_playpos is up-to-date */
702 if (This->buf_mixpos >= This->last_playpos) {
703 if (This->buf_mixpos > writecursor &&
704 This->last_playpos < writecursor+writebytes)
707 if (This->buf_mixpos > writecursor ||
708 This->last_playpos < writecursor+writebytes)
712 TRACE("locking prebuffered region, ouch\n");
713 DSOUND_MixCancelAt(This, writecursor);
718 LeaveCriticalSection(&(This->lock));
722 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
723 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
725 HRESULT hres = DS_OK;
726 ICOM_THIS(IDirectSoundBufferImpl,iface);
727 TRACE("(%p,%ld)\n",This,newpos);
730 EnterCriticalSection(&(This->lock));
732 newpos %= This->buflen;
733 This->buf_mixpos = newpos;
735 hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
737 WARN("IDsDriverBuffer_SetPosition failed\n");
740 LeaveCriticalSection(&(This->lock));
746 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
747 LPDIRECTSOUNDBUFFER8 iface,LONG pan
749 HRESULT hres = DS_OK;
750 ICOM_THIS(IDirectSoundBufferImpl,iface);
752 TRACE("(%p,%ld)\n",This,pan);
754 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
755 WARN("invalid parameter: pan = %ld\n", pan);
756 return DSERR_INVALIDPARAM;
759 /* You cannot use both pan and 3D controls */
760 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
761 (This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
762 WARN("control unavailable\n");
763 return DSERR_CONTROLUNAVAIL;
767 EnterCriticalSection(&(This->lock));
769 if (This->volpan.lPan != pan) {
770 This->volpan.lPan = pan;
771 DSOUND_RecalcVolPan(&(This->volpan));
774 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
776 WARN("IDsDriverBuffer_SetVolumePan failed\n");
778 DSOUND_ForceRemix(This);
781 LeaveCriticalSection(&(This->lock));
787 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
788 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
790 ICOM_THIS(IDirectSoundBufferImpl,iface);
791 TRACE("(%p,%p)\n",This,pan);
793 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
794 WARN("control unavailable\n");
795 return DSERR_CONTROLUNAVAIL;
799 WARN("invalid parameter: pan = NULL\n");
800 return DSERR_INVALIDPARAM;
803 *pan = This->volpan.lPan;
808 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
809 LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
811 ICOM_THIS(IDirectSoundBufferImpl,iface);
812 DWORD probably_valid_to;
814 TRACE("(%p,%p,%ld,%p,%ld)\n", This,p1,x1,p2,x2);
817 EnterCriticalSection(&(This->lock));
819 if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
821 hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
823 LeaveCriticalSection(&(This->lock));
824 WARN("IDsDriverBuffer_Unlock failed\n");
829 if (p2) probably_valid_to = (((LPBYTE)p2)-This->buffer->memory) + x2;
830 else probably_valid_to = (((LPBYTE)p1)-This->buffer->memory) + x1;
831 probably_valid_to %= This->buflen;
832 if ((probably_valid_to == 0) && ((x1+x2) == This->buflen) &&
833 ((This->state == STATE_STARTING) ||
834 (This->state == STATE_PLAYING)))
835 /* see IDirectSoundBufferImpl_Lock */
836 probably_valid_to = (DWORD)-1;
837 This->probably_valid_to = probably_valid_to;
839 LeaveCriticalSection(&(This->lock));
842 TRACE("probably_valid_to=%ld\n", This->probably_valid_to);
846 static HRESULT WINAPI IDirectSoundBufferImpl_Restore(
847 LPDIRECTSOUNDBUFFER8 iface
849 ICOM_THIS(IDirectSoundBufferImpl,iface);
850 FIXME("(%p):stub\n",This);
854 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
855 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
857 ICOM_THIS(IDirectSoundBufferImpl,iface);
858 TRACE("(%p,%p)\n",This,freq);
861 WARN("invalid parameter: freq = NULL\n");
862 return DSERR_INVALIDPARAM;
866 TRACE("-> %ld\n", *freq);
871 static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(
872 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
874 ICOM_THIS(IDirectSoundBufferImpl,iface);
877 FIXME("(%p,%lu,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
880 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
882 WARN("control unavailable\n");
883 return DSERR_CONTROLUNAVAIL;
886 static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(
887 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
889 ICOM_THIS(IDirectSoundBufferImpl,iface);
892 FIXME("(%p,%08lu,%lu,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
895 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
897 WARN("control unavailable\n");
898 return DSERR_CONTROLUNAVAIL;
901 static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(
902 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
904 ICOM_THIS(IDirectSoundBufferImpl,iface);
906 FIXME("(%p,%s,%lu,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
908 WARN("control unavailable\n");
909 return DSERR_CONTROLUNAVAIL;
912 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
913 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
915 ICOM_THIS(IDirectSoundBufferImpl,iface);
916 FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
917 DPRINTF("Re-Init!!!\n");
918 WARN("already initialized\n");
919 return DSERR_ALREADYINITIALIZED;
922 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
923 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
925 ICOM_THIS(IDirectSoundBufferImpl,iface);
926 TRACE("(%p)->(%p)\n",This,caps);
929 WARN("invalid parameter: caps == NULL\n");
930 return DSERR_INVALIDPARAM;
933 if (caps->dwSize < sizeof(*caps)) {
934 WARN("invalid parameter: caps->dwSize = %ld < %d\n",caps->dwSize, sizeof(*caps));
935 return DSERR_INVALIDPARAM;
938 caps->dwFlags = This->dsbd.dwFlags;
939 if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
940 else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
942 caps->dwBufferBytes = This->buflen;
944 /* This value represents the speed of the "unlock" command.
945 As unlock is quite fast (it does not do anything), I put
946 4096 ko/s = 4 Mo / s */
947 /* FIXME: hwbuf speed */
948 caps->dwUnlockTransferRate = 4096;
949 caps->dwPlayCpuOverhead = 0;
954 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
955 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
957 ICOM_THIS(IDirectSoundBufferImpl,iface);
959 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
962 WARN("invalid parameter\n");
966 *ppobj = NULL; /* assume failure */
968 if ( IsEqualGUID(riid, &IID_IUnknown) ||
969 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
970 IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
972 SecondaryBufferImpl_Create(This, &(This->dsb));
974 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)This->dsb);
978 WARN("IID_IDirectSoundBuffer\n");
979 return E_NOINTERFACE;
982 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ||
983 IsEqualGUID( &IID_IDirectSoundNotify8, riid ) ) {
985 IDirectSoundNotifyImpl_Create(This, &(This->notify));
987 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
988 *ppobj = This->notify;
991 WARN("IID_IDirectSoundNotify\n");
992 return E_NOINTERFACE;
995 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
997 IDirectSound3DBufferImpl_Create(This, &(This->ds3db));
999 IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->ds3db);
1000 *ppobj = This->ds3db;
1003 WARN("IID_IDirectSound3DBuffer\n");
1004 return E_NOINTERFACE;
1007 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
1008 ERR("app requested IDirectSound3DListener on secondary buffer\n");
1009 return E_NOINTERFACE;
1012 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
1013 /* only supported on hardware 3D secondary buffers */
1014 if (!(This->dsbd.dwFlags & DSBCAPS_PRIMARYBUFFER) &&
1015 (This->dsbd.dwFlags & DSBCAPS_CTRL3D) &&
1016 (This->hwbuf != NULL) ) {
1018 IKsBufferPropertySetImpl_Create(This, &(This->iks));
1020 IKsPropertySet_AddRef((LPKSPROPERTYSET)*ppobj);
1025 WARN("IID_IKsPropertySet\n");
1026 return E_NOINTERFACE;
1029 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
1031 return E_NOINTERFACE;
1034 static IDirectSoundBuffer8Vtbl dsbvt =
1036 IDirectSoundBufferImpl_QueryInterface,
1037 IDirectSoundBufferImpl_AddRef,
1038 IDirectSoundBufferImpl_Release,
1039 IDirectSoundBufferImpl_GetCaps,
1040 IDirectSoundBufferImpl_GetCurrentPosition,
1041 IDirectSoundBufferImpl_GetFormat,
1042 IDirectSoundBufferImpl_GetVolume,
1043 IDirectSoundBufferImpl_GetPan,
1044 IDirectSoundBufferImpl_GetFrequency,
1045 IDirectSoundBufferImpl_GetStatus,
1046 IDirectSoundBufferImpl_Initialize,
1047 IDirectSoundBufferImpl_Lock,
1048 IDirectSoundBufferImpl_Play,
1049 IDirectSoundBufferImpl_SetCurrentPosition,
1050 IDirectSoundBufferImpl_SetFormat,
1051 IDirectSoundBufferImpl_SetVolume,
1052 IDirectSoundBufferImpl_SetPan,
1053 IDirectSoundBufferImpl_SetFrequency,
1054 IDirectSoundBufferImpl_Stop,
1055 IDirectSoundBufferImpl_Unlock,
1056 IDirectSoundBufferImpl_Restore,
1057 IDirectSoundBufferImpl_SetFX,
1058 IDirectSoundBufferImpl_AcquireResources,
1059 IDirectSoundBufferImpl_GetObjectInPath
1062 HRESULT WINAPI IDirectSoundBufferImpl_Create(
1063 IDirectSoundImpl *ds,
1064 IDirectSoundBufferImpl **pdsb,
1065 LPCDSBUFFERDESC dsbd)
1067 IDirectSoundBufferImpl *dsb;
1068 LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
1069 HRESULT err = DS_OK;
1071 int use_hw, alloc_size, cp_size;
1072 TRACE("(%p,%p,%p)\n",ds,pdsb,dsbd);
1074 if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
1075 WARN("invalid parameter: dsbd->dwBufferBytes = %ld\n", dsbd->dwBufferBytes);
1077 return DSERR_INVALIDPARAM; /* FIXME: which error? */
1080 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
1083 WARN("out of memory\n");
1085 return DSERR_OUTOFMEMORY;
1088 TRACE("Created buffer at %p\n", dsb);
1093 dsb->lpVtbl = &dsbvt;
1096 /* size depends on version */
1097 memcpy(&dsb->dsbd, dsbd, dsbd->dwSize);
1099 /* variable sized struct so calculate size based on format */
1100 if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
1101 alloc_size = sizeof(WAVEFORMATEX);
1102 cp_size = sizeof(PCMWAVEFORMAT);
1104 alloc_size = cp_size = sizeof(WAVEFORMATEX) + wfex->cbSize;
1106 dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,alloc_size);
1107 if (dsb->pwfx == NULL) {
1108 WARN("out of memory\n");
1109 HeapFree(GetProcessHeap(),0,dsb);
1111 return DSERR_OUTOFMEMORY;
1114 memcpy(dsb->pwfx, wfex, cp_size);
1116 dsb->buflen = dsbd->dwBufferBytes;
1117 dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
1120 dsb->notifies = NULL;
1121 dsb->nrofnotifies = 0;
1124 /* Check necessary hardware mixing capabilities */
1125 if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
1126 else capf |= DSCAPS_SECONDARYMONO;
1127 if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
1128 else capf |= DSCAPS_SECONDARY8BIT;
1130 use_hw = (ds->drvcaps.dwFlags & capf) == capf;
1131 TRACE("use_hw = 0x%08x, capf = 0x%08lx, ds->drvcaps.dwFlags = 0x%08lx\n", use_hw, capf, ds->drvcaps.dwFlags);
1133 /* FIXME: check hardware sample rate mixing capabilities */
1134 /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
1135 /* FIXME: check whether any hardware buffers are left */
1136 /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
1138 /* Allocate system memory if applicable */
1139 if ((ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
1140 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1141 if (dsb->buffer == NULL) {
1142 WARN("out of memory\n");
1143 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1144 HeapFree(GetProcessHeap(),0,dsb);
1146 return DSERR_OUTOFMEMORY;
1149 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1150 if (dsb->buffer->memory == NULL) {
1151 WARN("out of memory\n");
1152 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1153 HeapFree(GetProcessHeap(),0,dsb->buffer);
1154 HeapFree(GetProcessHeap(),0,dsb);
1156 return DSERR_OUTOFMEMORY;
1158 dsb->buffer->ref = 1;
1161 /* Allocate the hardware buffer */
1163 err = IDsDriver_CreateSoundBuffer(ds->driver,wfex,dsbd->dwFlags,0,
1164 &(dsb->buflen),&(dsb->buffer->memory),
1165 (LPVOID*)&(dsb->hwbuf));
1166 /* fall back to software buffer on failure */
1168 TRACE("IDsDriver_CreateSoundBuffer failed, falling back to software buffer\n");
1170 if (ds->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
1171 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1172 if (dsb->buffer == NULL) {
1173 WARN("out of memory\n");
1174 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1175 HeapFree(GetProcessHeap(),0,dsb);
1177 return DSERR_OUTOFMEMORY;
1180 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1181 if (dsb->buffer->memory == NULL) {
1182 WARN("out of memory\n");
1183 HeapFree(GetProcessHeap(),0,dsb->buffer);
1184 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1185 HeapFree(GetProcessHeap(),0,dsb);
1187 return DSERR_OUTOFMEMORY;
1189 dsb->buffer->ref = 1;
1194 /* calculate fragment size and write lead */
1195 DSOUND_RecalcFormat(dsb);
1197 /* It's not necessary to initialize values to zero since */
1198 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1200 dsb->buf_mixpos = 0;
1201 dsb->state = STATE_STOPPED;
1203 dsb->freqAdjust = (dsb->freq << DSOUND_FREQSHIFT) /
1204 ds->pwfx->nSamplesPerSec;
1205 dsb->nAvgBytesPerSec = dsb->freq *
1206 dsbd->lpwfxFormat->nBlockAlign;
1208 if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
1209 dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
1210 dsb->ds3db_ds3db.vPosition.x = 0.0;
1211 dsb->ds3db_ds3db.vPosition.y = 0.0;
1212 dsb->ds3db_ds3db.vPosition.z = 0.0;
1213 dsb->ds3db_ds3db.vVelocity.x = 0.0;
1214 dsb->ds3db_ds3db.vVelocity.y = 0.0;
1215 dsb->ds3db_ds3db.vVelocity.z = 0.0;
1216 dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1217 dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1218 dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
1219 dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
1220 dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
1221 dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1222 dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1223 dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1224 dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
1226 dsb->ds3db_need_recalc = FALSE;
1227 DSOUND_Calc3DBuffer(dsb);
1229 DSOUND_RecalcVolPan(&(dsb->volpan));
1231 InitializeCriticalSection(&(dsb->lock));
1232 dsb->lock.DebugInfo->Spare[1] = (DWORD)"DSOUNDBUFFER_lock";
1234 /* register buffer */
1235 RtlAcquireResourceExclusive(&(ds->lock), TRUE);
1236 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1237 IDirectSoundBufferImpl **newbuffers;
1239 newbuffers = HeapReAlloc(GetProcessHeap(),0,ds->buffers,sizeof(IDirectSoundBufferImpl*)*(ds->nrofbuffers+1));
1241 newbuffers = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(ds->nrofbuffers+1));
1244 ds->buffers = newbuffers;
1245 ds->buffers[ds->nrofbuffers] = dsb;
1247 TRACE("buffer count is now %d\n", ds->nrofbuffers);
1249 ERR("out of memory for buffer list! Current buffer count is %d\n", ds->nrofbuffers);
1250 if (dsb->buffer->memory)
1251 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1253 HeapFree(GetProcessHeap(),0,dsb->buffer);
1254 DeleteCriticalSection(&(dsb->lock));
1255 RtlReleaseResource(&(ds->lock));
1256 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1257 HeapFree(GetProcessHeap(),0,dsb);
1259 return DSERR_OUTOFMEMORY;
1262 RtlReleaseResource(&(ds->lock));
1267 HRESULT WINAPI IDirectSoundBufferImpl_Destroy(
1268 IDirectSoundBufferImpl *pdsb)
1270 TRACE("(%p)\n",pdsb);
1272 /* This keeps the *_Destroy functions from possibly deleting
1273 * this object until it is ready to be deleted */
1274 IDirectSoundBufferImpl_AddRef((LPDIRECTSOUNDBUFFER8)pdsb);
1277 WARN("iks not NULL\n");
1278 IKsBufferPropertySetImpl_Destroy(pdsb->iks);
1283 WARN("ds3db not NULL\n");
1284 IDirectSound3DBufferImpl_Destroy(pdsb->ds3db);
1289 WARN("notify not NULL\n");
1290 IDirectSoundNotifyImpl_Destroy(pdsb->notify);
1291 pdsb->notify = NULL;
1295 WARN("dsb not NULL\n");
1296 SecondaryBufferImpl_Destroy(pdsb->dsb);
1300 while (IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);
1305 /*******************************************************************************
1309 static HRESULT WINAPI SecondaryBufferImpl_QueryInterface(
1310 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj)
1312 ICOM_THIS(SecondaryBufferImpl,iface);
1313 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
1315 return IDirectSoundBufferImpl_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb,riid,ppobj);
1318 static DWORD WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
1320 ICOM_THIS(IDirectSoundBufferImpl,iface);
1322 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1324 ref = InterlockedIncrement(&(This->ref));
1326 FIXME("thread-safety alert! AddRef-ing with a zero refcount!\n");
1331 static DWORD WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
1333 ICOM_THIS(IDirectSoundBufferImpl,iface);
1335 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1337 ref = InterlockedDecrement(&(This->ref));
1339 This->dsb->dsb = NULL;
1340 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
1341 HeapFree(GetProcessHeap(),0,This);
1342 TRACE("(%p) released\n",This);
1347 static HRESULT WINAPI SecondaryBufferImpl_GetCaps(
1348 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps)
1350 ICOM_THIS(SecondaryBufferImpl,iface);
1351 TRACE("(%p)->(%p)\n",This,caps);
1353 return IDirectSoundBufferImpl_GetCaps((LPDIRECTSOUNDBUFFER8)This->dsb,caps);
1356 static HRESULT WINAPI SecondaryBufferImpl_GetCurrentPosition(
1357 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos)
1359 ICOM_THIS(SecondaryBufferImpl,iface);
1360 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
1362 return IDirectSoundBufferImpl_GetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,playpos,writepos);
1365 static HRESULT WINAPI SecondaryBufferImpl_GetFormat(
1366 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten)
1368 ICOM_THIS(SecondaryBufferImpl,iface);
1369 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
1371 return IDirectSoundBufferImpl_GetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,lpwf,wfsize,wfwritten);
1374 static HRESULT WINAPI SecondaryBufferImpl_GetVolume(
1375 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol)
1377 ICOM_THIS(SecondaryBufferImpl,iface);
1378 TRACE("(%p,%p)\n",This,vol);
1380 return IDirectSoundBufferImpl_GetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1383 static HRESULT WINAPI SecondaryBufferImpl_GetPan(
1384 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan)
1386 ICOM_THIS(SecondaryBufferImpl,iface);
1387 TRACE("(%p,%p)\n",This,pan);
1389 return IDirectSoundBufferImpl_GetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1392 static HRESULT WINAPI SecondaryBufferImpl_GetFrequency(
1393 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq)
1395 ICOM_THIS(SecondaryBufferImpl,iface);
1396 TRACE("(%p,%p)\n",This,freq);
1398 return IDirectSoundBufferImpl_GetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1401 static HRESULT WINAPI SecondaryBufferImpl_GetStatus(
1402 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status)
1404 ICOM_THIS(SecondaryBufferImpl,iface);
1405 TRACE("(%p,%p)\n",This,status);
1407 return IDirectSoundBufferImpl_GetStatus((LPDIRECTSOUNDBUFFER8)This->dsb,status);
1410 static HRESULT WINAPI SecondaryBufferImpl_Initialize(
1411 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd)
1413 ICOM_THIS(SecondaryBufferImpl,iface);
1414 TRACE("(%p,%p,%p)\n",This,dsound,dbsd);
1416 return IDirectSoundBufferImpl_Initialize((LPDIRECTSOUNDBUFFER8)This->dsb,dsound,dbsd);
1419 static HRESULT WINAPI SecondaryBufferImpl_Lock(
1420 LPDIRECTSOUNDBUFFER8 iface,
1423 LPVOID lplpaudioptr1,
1424 LPDWORD audiobytes1,
1425 LPVOID lplpaudioptr2,
1426 LPDWORD audiobytes2,
1429 ICOM_THIS(SecondaryBufferImpl,iface);
1430 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx)\n",
1431 This,writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1433 return IDirectSoundBufferImpl_Lock((LPDIRECTSOUNDBUFFER8)This->dsb,
1434 writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1437 static HRESULT WINAPI SecondaryBufferImpl_Play(
1438 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags)
1440 ICOM_THIS(SecondaryBufferImpl,iface);
1441 TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
1443 return IDirectSoundBufferImpl_Play((LPDIRECTSOUNDBUFFER8)This->dsb,reserved1,reserved2,flags);
1446 static HRESULT WINAPI SecondaryBufferImpl_SetCurrentPosition(
1447 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos)
1449 ICOM_THIS(SecondaryBufferImpl,iface);
1450 TRACE("(%p,%ld)\n",This,newpos);
1452 return IDirectSoundBufferImpl_SetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,newpos);
1455 static HRESULT WINAPI SecondaryBufferImpl_SetFormat(
1456 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex)
1458 ICOM_THIS(SecondaryBufferImpl,iface);
1459 TRACE("(%p,%p)\n",This,wfex);
1461 return IDirectSoundBufferImpl_SetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,wfex);
1464 static HRESULT WINAPI SecondaryBufferImpl_SetVolume(
1465 LPDIRECTSOUNDBUFFER8 iface,LONG vol)
1467 ICOM_THIS(SecondaryBufferImpl,iface);
1468 TRACE("(%p,%ld)\n",This,vol);
1470 return IDirectSoundBufferImpl_SetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1473 static HRESULT WINAPI SecondaryBufferImpl_SetPan(
1474 LPDIRECTSOUNDBUFFER8 iface,LONG pan)
1476 ICOM_THIS(SecondaryBufferImpl,iface);
1477 TRACE("(%p,%ld)\n",This,pan);
1479 return IDirectSoundBufferImpl_SetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1482 static HRESULT WINAPI SecondaryBufferImpl_SetFrequency(
1483 LPDIRECTSOUNDBUFFER8 iface,DWORD freq)
1485 ICOM_THIS(SecondaryBufferImpl,iface);
1486 TRACE("(%p,%ld)\n",This,freq);
1488 return IDirectSoundBufferImpl_SetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1491 static HRESULT WINAPI SecondaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
1493 ICOM_THIS(SecondaryBufferImpl,iface);
1494 TRACE("(%p)\n",This);
1496 return IDirectSoundBufferImpl_Stop((LPDIRECTSOUNDBUFFER8)This->dsb);
1499 static HRESULT WINAPI SecondaryBufferImpl_Unlock(
1500 LPDIRECTSOUNDBUFFER8 iface,
1501 LPVOID lpvAudioPtr1,
1502 DWORD dwAudioBytes1,
1503 LPVOID lpvAudioPtr2,
1504 DWORD dwAudioBytes2)
1506 ICOM_THIS(SecondaryBufferImpl,iface);
1507 TRACE("(%p,%p,%ld,%p,%ld)\n",
1508 This, lpvAudioPtr1, dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1510 return IDirectSoundBufferImpl_Unlock((LPDIRECTSOUNDBUFFER8)This->dsb,
1511 lpvAudioPtr1,dwAudioBytes1,lpvAudioPtr2,dwAudioBytes2);
1514 static HRESULT WINAPI SecondaryBufferImpl_Restore(
1515 LPDIRECTSOUNDBUFFER8 iface)
1517 ICOM_THIS(SecondaryBufferImpl,iface);
1518 TRACE("(%p)\n",This);
1520 return IDirectSoundBufferImpl_Restore((LPDIRECTSOUNDBUFFER8)This->dsb);
1523 static HRESULT WINAPI SecondaryBufferImpl_SetFX(
1524 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes)
1526 ICOM_THIS(SecondaryBufferImpl,iface);
1527 TRACE("(%p,%lu,%p,%p)\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1529 return IDirectSoundBufferImpl_SetFX((LPDIRECTSOUNDBUFFER8)This->dsb,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1532 static HRESULT WINAPI SecondaryBufferImpl_AcquireResources(
1533 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes)
1535 ICOM_THIS(SecondaryBufferImpl,iface);
1536 TRACE("(%p,%08lu,%lu,%p)\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
1538 return IDirectSoundBufferImpl_AcquireResources((LPDIRECTSOUNDBUFFER8)This->dsb,dwFlags,dwEffectsCount,pdwResultCodes);
1541 static HRESULT WINAPI SecondaryBufferImpl_GetObjectInPath(
1542 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject)
1544 ICOM_THIS(SecondaryBufferImpl,iface);
1545 TRACE("(%p,%s,%lu,%s,%p)\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
1547 return IDirectSoundBufferImpl_GetObjectInPath((LPDIRECTSOUNDBUFFER8)This->dsb,rguidObject,dwIndex,rguidInterface,ppObject);
1550 static IDirectSoundBuffer8Vtbl sbvt =
1552 SecondaryBufferImpl_QueryInterface,
1553 SecondaryBufferImpl_AddRef,
1554 SecondaryBufferImpl_Release,
1555 SecondaryBufferImpl_GetCaps,
1556 SecondaryBufferImpl_GetCurrentPosition,
1557 SecondaryBufferImpl_GetFormat,
1558 SecondaryBufferImpl_GetVolume,
1559 SecondaryBufferImpl_GetPan,
1560 SecondaryBufferImpl_GetFrequency,
1561 SecondaryBufferImpl_GetStatus,
1562 SecondaryBufferImpl_Initialize,
1563 SecondaryBufferImpl_Lock,
1564 SecondaryBufferImpl_Play,
1565 SecondaryBufferImpl_SetCurrentPosition,
1566 SecondaryBufferImpl_SetFormat,
1567 SecondaryBufferImpl_SetVolume,
1568 SecondaryBufferImpl_SetPan,
1569 SecondaryBufferImpl_SetFrequency,
1570 SecondaryBufferImpl_Stop,
1571 SecondaryBufferImpl_Unlock,
1572 SecondaryBufferImpl_Restore,
1573 SecondaryBufferImpl_SetFX,
1574 SecondaryBufferImpl_AcquireResources,
1575 SecondaryBufferImpl_GetObjectInPath
1578 HRESULT WINAPI SecondaryBufferImpl_Create(
1579 IDirectSoundBufferImpl *dsb,
1580 SecondaryBufferImpl **psb)
1582 SecondaryBufferImpl *sb;
1583 TRACE("(%p,%p)\n",dsb,psb);
1585 sb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*sb));
1588 WARN("out of memory\n");
1590 return DSERR_OUTOFMEMORY;
1596 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
1601 HRESULT WINAPI SecondaryBufferImpl_Destroy(
1602 SecondaryBufferImpl *pdsb)
1604 TRACE("(%p)\n",pdsb);
1606 while (SecondaryBufferImpl_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);