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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSSTRUCT
25 #define NONAMELESSUNION
31 #include "wine/debug.h"
34 #include "dsound_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
38 static HRESULT SecondaryBufferImpl_Destroy(SecondaryBufferImpl *pdsb);
40 /*******************************************************************************
44 struct IDirectSoundNotifyImpl
47 const IDirectSoundNotifyVtbl *lpVtbl;
49 IDirectSoundBufferImpl* dsb;
52 static HRESULT IDirectSoundNotifyImpl_Create(IDirectSoundBufferImpl *dsb,
53 IDirectSoundNotifyImpl **pdsn);
54 static HRESULT IDirectSoundNotifyImpl_Destroy(IDirectSoundNotifyImpl *pdsn);
56 static HRESULT WINAPI IDirectSoundNotifyImpl_QueryInterface(
57 LPDIRECTSOUNDNOTIFY iface,REFIID riid,LPVOID *ppobj
59 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
60 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
62 if (This->dsb == NULL) {
63 WARN("invalid parameter\n");
67 return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER)This->dsb, riid, ppobj);
70 static ULONG WINAPI IDirectSoundNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
72 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
73 ULONG ref = InterlockedIncrement(&(This->ref));
74 TRACE("(%p) ref was %d\n", This, ref - 1);
78 static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface)
80 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
81 ULONG ref = InterlockedDecrement(&(This->ref));
82 TRACE("(%p) ref was %d\n", This, ref + 1);
85 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)This->dsb);
86 This->dsb->notify = NULL;
87 HeapFree(GetProcessHeap(), 0, This);
88 TRACE("(%p) released\n", This);
93 static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
94 LPDIRECTSOUNDNOTIFY iface,DWORD howmuch,LPCDSBPOSITIONNOTIFY notify
96 IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
97 TRACE("(%p,0x%08x,%p)\n",This,howmuch,notify);
99 if (howmuch > 0 && notify == NULL) {
100 WARN("invalid parameter: notify == NULL\n");
101 return DSERR_INVALIDPARAM;
104 if (TRACE_ON(dsound)) {
106 for (i=0;i<howmuch;i++)
107 TRACE("notify at %d to %p\n",
108 notify[i].dwOffset,notify[i].hEventNotify);
111 if (This->dsb->hwnotify) {
113 hres = IDsDriverNotify_SetNotificationPositions(This->dsb->hwnotify, howmuch, notify);
115 WARN("IDsDriverNotify_SetNotificationPositions failed\n");
117 } else if (howmuch > 0) {
118 /* Make an internal copy of the caller-supplied array.
119 * Replace the existing copy if one is already present. */
120 if (This->dsb->notifies)
121 This->dsb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
122 This->dsb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
124 This->dsb->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
125 howmuch * sizeof(DSBPOSITIONNOTIFY));
127 if (This->dsb->notifies == NULL) {
128 WARN("out of memory\n");
129 return DSERR_OUTOFMEMORY;
131 CopyMemory(This->dsb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
132 This->dsb->nrofnotifies = howmuch;
134 HeapFree(GetProcessHeap(), 0, This->dsb->notifies);
135 This->dsb->notifies = NULL;
136 This->dsb->nrofnotifies = 0;
142 static const IDirectSoundNotifyVtbl dsnvt =
144 IDirectSoundNotifyImpl_QueryInterface,
145 IDirectSoundNotifyImpl_AddRef,
146 IDirectSoundNotifyImpl_Release,
147 IDirectSoundNotifyImpl_SetNotificationPositions,
150 static HRESULT IDirectSoundNotifyImpl_Create(
151 IDirectSoundBufferImpl * dsb,
152 IDirectSoundNotifyImpl **pdsn)
154 IDirectSoundNotifyImpl * dsn;
155 TRACE("(%p,%p)\n",dsb,pdsn);
157 dsn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dsn));
160 WARN("out of memory\n");
161 return DSERR_OUTOFMEMORY;
165 dsn->lpVtbl = &dsnvt;
168 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
174 static HRESULT IDirectSoundNotifyImpl_Destroy(
175 IDirectSoundNotifyImpl *pdsn)
177 TRACE("(%p)\n",pdsn);
179 while (IDirectSoundNotifyImpl_Release((LPDIRECTSOUNDNOTIFY)pdsn) > 0);
184 /*******************************************************************************
188 static HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(
189 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex
191 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
193 TRACE("(%p,%p)\n",This,wfex);
194 /* This method is not available on secondary buffers */
195 WARN("invalid call\n");
196 return DSERR_INVALIDCALL;
199 static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
200 LPDIRECTSOUNDBUFFER8 iface,LONG vol
202 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
204 HRESULT hres = DS_OK;
206 TRACE("(%p,%d)\n",This,vol);
208 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
209 WARN("control unavailable: This->dsbd.dwFlags = 0x%08x\n", This->dsbd.dwFlags);
210 return DSERR_CONTROLUNAVAIL;
213 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
214 WARN("invalid parameter: vol = %d\n", vol);
215 return DSERR_INVALIDPARAM;
219 RtlAcquireResourceExclusive(&This->lock, TRUE);
221 if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) {
222 oldVol = This->ds3db_lVolume;
223 This->ds3db_lVolume = vol;
225 /* recalc 3d volume, which in turn recalcs the pans */
226 DSOUND_Calc3DBuffer(This);
228 oldVol = This->volpan.lVolume;
229 This->volpan.lVolume = vol;
231 DSOUND_RecalcVolPan(&(This->volpan));
236 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
238 WARN("IDsDriverBuffer_SetVolumePan failed\n");
242 RtlReleaseResource(&This->lock);
248 static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(
249 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
251 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
252 TRACE("(%p,%p)\n",This,vol);
254 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
255 WARN("control unavailable\n");
256 return DSERR_CONTROLUNAVAIL;
260 WARN("invalid parameter: vol == NULL\n");
261 return DSERR_INVALIDPARAM;
264 *vol = This->volpan.lVolume;
269 static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
270 LPDIRECTSOUNDBUFFER8 iface,DWORD freq
272 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
275 TRACE("(%p,%d)\n",This,freq);
277 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
278 WARN("control unavailable\n");
279 return DSERR_CONTROLUNAVAIL;
282 if (freq == DSBFREQUENCY_ORIGINAL)
283 freq = This->pwfx->nSamplesPerSec;
285 if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX)) {
286 WARN("invalid parameter: freq = %d\n", freq);
287 return DSERR_INVALIDPARAM;
291 RtlAcquireResourceExclusive(&This->lock, TRUE);
293 oldFreq = This->freq;
295 if (freq != oldFreq) {
296 This->freqAdjust = (freq << DSOUND_FREQSHIFT) / This->device->pwfx->nSamplesPerSec;
297 This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;
298 DSOUND_RecalcFormat(This);
301 RtlReleaseResource(&This->lock);
307 static HRESULT WINAPI IDirectSoundBufferImpl_Play(
308 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
310 HRESULT hres = DS_OK;
311 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
312 TRACE("(%p,%08x,%08x,%08x)\n",This,reserved1,reserved2,flags);
315 RtlAcquireResourceExclusive(&This->lock, TRUE);
317 This->playflags = flags;
318 if (This->state == STATE_STOPPED) {
320 This->startpos = This->buf_mixpos;
321 This->state = STATE_STARTING;
322 } else if (This->state == STATE_STOPPING)
323 This->state = STATE_PLAYING;
325 hres = IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
327 WARN("IDsDriverBuffer_Play failed\n");
329 This->state = STATE_PLAYING;
332 RtlReleaseResource(&This->lock);
338 static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
340 HRESULT hres = DS_OK;
341 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
342 TRACE("(%p)\n",This);
345 RtlAcquireResourceExclusive(&This->lock, TRUE);
347 if (This->state == STATE_PLAYING)
348 This->state = STATE_STOPPING;
349 else if (This->state == STATE_STARTING)
350 This->state = STATE_STOPPED;
352 hres = IDsDriverBuffer_Stop(This->hwbuf);
354 WARN("IDsDriverBuffer_Stop failed\n");
356 This->state = STATE_STOPPED;
358 DSOUND_CheckEvent(This, 0, 0);
360 RtlReleaseResource(&This->lock);
366 static ULONG WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
368 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
369 ULONG ref = InterlockedIncrement(&(This->ref));
370 TRACE("(%p) ref was %d\n", This, ref - 1);
374 static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
376 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
377 ULONG ref = InterlockedDecrement(&(This->ref));
378 TRACE("(%p) ref was %d\n", This, ref + 1);
381 DirectSoundDevice_RemoveBuffer(This->device, This);
383 RtlDeleteResource(&This->lock);
386 IDsDriverBuffer_Release(This->hwbuf);
387 if (This->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
389 if (This->buffer->ref==0) {
390 HeapFree(GetProcessHeap(),0,This->buffer->memory);
391 HeapFree(GetProcessHeap(),0,This->buffer);
396 if (This->buffer->ref==0) {
397 HeapFree(GetProcessHeap(),0,This->buffer->memory);
398 HeapFree(GetProcessHeap(),0,This->buffer);
402 HeapFree(GetProcessHeap(), 0, This->notifies);
403 HeapFree(GetProcessHeap(), 0, This->pwfx);
404 HeapFree(GetProcessHeap(), 0, This);
406 TRACE("(%p) released\n", This);
411 static DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This)
413 DWORD bplay = This->buf_mixpos;
415 /* check for lead-in */
416 if (This->leadin && ((bplay < This->startpos) || (bplay > This->buf_mixpos))) {
417 /* seems we haven't started playing yet */
418 TRACE("this still in lead-in phase\n");
419 bplay = This->startpos;
423 if (bplay >= This->buflen){
424 FIXME("Bad play position. bplay: %d, buflen: %d\n", bplay, This->buflen);
425 bplay %= This->buflen;
428 /* return the result */
432 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
433 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
436 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
437 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
439 hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
441 WARN("IDsDriverBuffer_GetPosition failed\n");
445 if (playpos && (This->state != STATE_PLAYING))
446 /* we haven't been merged into the primary buffer (yet) */
447 *playpos = This->buf_mixpos;
449 *playpos = DSOUND_CalcPlayPosition(This);
451 *writepos = (playpos ? *playpos : This->buf_mixpos);
454 if (This->state != STATE_STOPPED) {
455 /* apply the documented 10ms lead to writepos */
456 *writepos += This->writelead;
458 *writepos %= This->buflen;
461 TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n",
462 playpos?*playpos:-1, writepos?*writepos:-1, This->buflen, This, GetTickCount());
467 static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
468 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
470 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
471 TRACE("(%p,%p), thread is %04x\n",This,status,GetCurrentThreadId());
473 if (status == NULL) {
474 WARN("invalid parameter: status = NULL\n");
475 return DSERR_INVALIDPARAM;
479 if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
480 *status |= DSBSTATUS_PLAYING;
481 if (This->playflags & DSBPLAY_LOOPING)
482 *status |= DSBSTATUS_LOOPING;
485 TRACE("status=%x\n", *status);
490 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
491 LPDIRECTSOUNDBUFFER8 iface,
497 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
498 TRACE("(%p,%p,%d,%p)\n",This,lpwf,wfsize,wfwritten);
500 size = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
502 if (lpwf) { /* NULL is valid */
503 if (wfsize >= size) {
504 CopyMemory(lpwf,This->pwfx,size);
508 WARN("invalid parameter: wfsize too small\n");
511 return DSERR_INVALIDPARAM;
515 *wfwritten = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
517 WARN("invalid parameter: wfwritten == NULL\n");
518 return DSERR_INVALIDPARAM;
525 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
526 LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID *lplpaudioptr1,LPDWORD audiobytes1,LPVOID *lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
528 HRESULT hres = DS_OK;
529 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
531 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n",
543 /* when this flag is set, writecursor is meaningless and must be calculated */
544 if (flags & DSBLOCK_FROMWRITECURSOR) {
545 /* GetCurrentPosition does too much magic to duplicate here */
546 hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writecursor);
548 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
553 /* when this flag is set, writebytes is meaningless and must be set */
554 if (flags & DSBLOCK_ENTIREBUFFER)
555 writebytes = This->buflen;
557 if (writecursor >= This->buflen) {
558 WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
559 writecursor, This->buflen);
560 return DSERR_INVALIDPARAM;
563 if (writebytes > This->buflen) {
564 WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
565 writebytes, This->buflen);
566 return DSERR_INVALIDPARAM;
570 RtlAcquireResourceShared(&This->lock, TRUE);
572 if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
573 hres = IDsDriverBuffer_Lock(This->hwbuf,
574 lplpaudioptr1, audiobytes1,
575 lplpaudioptr2, audiobytes2,
576 writecursor, writebytes,
579 WARN("IDsDriverBuffer_Lock failed\n");
580 RtlReleaseResource(&This->lock);
584 if (writecursor+writebytes <= This->buflen) {
585 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
586 *audiobytes1 = writebytes;
588 *(LPBYTE*)lplpaudioptr2 = NULL;
591 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n",
592 *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
593 TRACE("->%d.0\n",writebytes);
595 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
596 *audiobytes1 = This->buflen-writecursor;
598 *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
600 *audiobytes2 = writebytes-(This->buflen-writecursor);
601 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
605 RtlReleaseResource(&This->lock);
611 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
612 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
614 HRESULT hres = DS_OK;
615 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
616 TRACE("(%p,%d)\n",This,newpos);
619 RtlAcquireResourceExclusive(&This->lock, TRUE);
621 /* start mixing from this new location instead */
622 newpos %= This->buflen;
623 newpos -= newpos%This->pwfx->nBlockAlign;
624 This->buf_mixpos = newpos;
626 /* at this point, do not attempt to reset buffers, mess with primary mix position,
627 or anything like that to reduce latancy. The data already prebuffered cannot be changed */
629 /* position HW buffer if applicable */
631 hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
633 WARN("IDsDriverBuffer_SetPosition failed\n");
636 RtlReleaseResource(&This->lock);
642 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
643 LPDIRECTSOUNDBUFFER8 iface,LONG pan
645 HRESULT hres = DS_OK;
646 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
648 TRACE("(%p,%d)\n",This,pan);
650 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
651 WARN("invalid parameter: pan = %d\n", pan);
652 return DSERR_INVALIDPARAM;
655 /* You cannot use both pan and 3D controls */
656 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
657 (This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
658 WARN("control unavailable\n");
659 return DSERR_CONTROLUNAVAIL;
663 RtlAcquireResourceExclusive(&This->lock, TRUE);
665 if (This->volpan.lPan != pan) {
666 This->volpan.lPan = pan;
667 DSOUND_RecalcVolPan(&(This->volpan));
670 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
672 WARN("IDsDriverBuffer_SetVolumePan failed\n");
676 RtlReleaseResource(&This->lock);
682 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
683 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
685 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
686 TRACE("(%p,%p)\n",This,pan);
688 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
689 WARN("control unavailable\n");
690 return DSERR_CONTROLUNAVAIL;
694 WARN("invalid parameter: pan = NULL\n");
695 return DSERR_INVALIDPARAM;
698 *pan = This->volpan.lPan;
703 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
704 LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
706 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
707 HRESULT hres = DS_OK;
709 TRACE("(%p,%p,%d,%p,%d)\n", This,p1,x1,p2,x2);
712 RtlAcquireResourceShared(&This->lock, TRUE);
714 if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
715 hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
717 WARN("IDsDriverBuffer_Unlock failed\n");
720 RtlReleaseResource(&This->lock);
726 static HRESULT WINAPI IDirectSoundBufferImpl_Restore(
727 LPDIRECTSOUNDBUFFER8 iface
729 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
730 FIXME("(%p):stub\n",This);
734 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
735 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
737 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
738 TRACE("(%p,%p)\n",This,freq);
741 WARN("invalid parameter: freq = NULL\n");
742 return DSERR_INVALIDPARAM;
746 TRACE("-> %d\n", *freq);
751 static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(
752 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
754 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
757 FIXME("(%p,%u,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
760 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
762 WARN("control unavailable\n");
763 return DSERR_CONTROLUNAVAIL;
766 static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(
767 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
769 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
772 FIXME("(%p,%08u,%u,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
775 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
777 WARN("control unavailable\n");
778 return DSERR_CONTROLUNAVAIL;
781 static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(
782 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
784 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
786 FIXME("(%p,%s,%u,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
788 WARN("control unavailable\n");
789 return DSERR_CONTROLUNAVAIL;
792 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
793 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
795 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
796 FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
797 DPRINTF("Re-Init!!!\n");
798 WARN("already initialized\n");
799 return DSERR_ALREADYINITIALIZED;
802 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
803 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
805 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
806 TRACE("(%p)->(%p)\n",This,caps);
809 WARN("invalid parameter: caps == NULL\n");
810 return DSERR_INVALIDPARAM;
813 if (caps->dwSize < sizeof(*caps)) {
814 WARN("invalid parameter: caps->dwSize = %d\n",caps->dwSize);
815 return DSERR_INVALIDPARAM;
818 caps->dwFlags = This->dsbd.dwFlags;
819 if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
820 else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
822 caps->dwBufferBytes = This->buflen;
824 /* According to windows, this is zero*/
825 caps->dwUnlockTransferRate = 0;
826 caps->dwPlayCpuOverhead = 0;
831 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
832 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
834 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
836 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
839 WARN("invalid parameter\n");
843 *ppobj = NULL; /* assume failure */
845 if ( IsEqualGUID(riid, &IID_IUnknown) ||
846 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
847 IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
848 if (!This->secondary)
849 SecondaryBufferImpl_Create(This, &(This->secondary));
850 if (This->secondary) {
851 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)This->secondary);
852 *ppobj = This->secondary;
855 WARN("IID_IDirectSoundBuffer\n");
856 return E_NOINTERFACE;
859 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
861 IDirectSoundNotifyImpl_Create(This, &(This->notify));
863 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
864 *ppobj = This->notify;
867 WARN("IID_IDirectSoundNotify\n");
868 return E_NOINTERFACE;
871 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
873 IDirectSound3DBufferImpl_Create(This, &(This->ds3db));
875 IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->ds3db);
876 *ppobj = This->ds3db;
879 WARN("IID_IDirectSound3DBuffer\n");
880 return E_NOINTERFACE;
883 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
884 ERR("app requested IDirectSound3DListener on secondary buffer\n");
885 return E_NOINTERFACE;
888 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
890 IKsBufferPropertySetImpl_Create(This, &(This->iks));
892 IKsPropertySet_AddRef((LPKSPROPERTYSET)This->iks);
896 WARN("IID_IKsPropertySet\n");
897 return E_NOINTERFACE;
900 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
902 return E_NOINTERFACE;
905 static const IDirectSoundBuffer8Vtbl dsbvt =
907 IDirectSoundBufferImpl_QueryInterface,
908 IDirectSoundBufferImpl_AddRef,
909 IDirectSoundBufferImpl_Release,
910 IDirectSoundBufferImpl_GetCaps,
911 IDirectSoundBufferImpl_GetCurrentPosition,
912 IDirectSoundBufferImpl_GetFormat,
913 IDirectSoundBufferImpl_GetVolume,
914 IDirectSoundBufferImpl_GetPan,
915 IDirectSoundBufferImpl_GetFrequency,
916 IDirectSoundBufferImpl_GetStatus,
917 IDirectSoundBufferImpl_Initialize,
918 IDirectSoundBufferImpl_Lock,
919 IDirectSoundBufferImpl_Play,
920 IDirectSoundBufferImpl_SetCurrentPosition,
921 IDirectSoundBufferImpl_SetFormat,
922 IDirectSoundBufferImpl_SetVolume,
923 IDirectSoundBufferImpl_SetPan,
924 IDirectSoundBufferImpl_SetFrequency,
925 IDirectSoundBufferImpl_Stop,
926 IDirectSoundBufferImpl_Unlock,
927 IDirectSoundBufferImpl_Restore,
928 IDirectSoundBufferImpl_SetFX,
929 IDirectSoundBufferImpl_AcquireResources,
930 IDirectSoundBufferImpl_GetObjectInPath
933 HRESULT IDirectSoundBufferImpl_Create(
934 DirectSoundDevice * device,
935 IDirectSoundBufferImpl **pdsb,
936 LPCDSBUFFERDESC dsbd)
938 IDirectSoundBufferImpl *dsb;
939 LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
942 int use_hw, alloc_size, cp_size;
943 TRACE("(%p,%p,%p)\n",device,pdsb,dsbd);
945 if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
946 WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd->dwBufferBytes);
948 return DSERR_INVALIDPARAM; /* FIXME: which error? */
951 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
954 WARN("out of memory\n");
956 return DSERR_OUTOFMEMORY;
959 TRACE("Created buffer at %p\n", dsb);
963 dsb->device = device;
964 dsb->lpVtbl = &dsbvt;
967 /* size depends on version */
968 CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
970 /* variable sized struct so calculate size based on format */
971 if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
972 alloc_size = sizeof(WAVEFORMATEX);
973 cp_size = sizeof(PCMWAVEFORMAT);
975 alloc_size = cp_size = sizeof(WAVEFORMATEX) + wfex->cbSize;
977 dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,alloc_size);
978 if (dsb->pwfx == NULL) {
979 WARN("out of memory\n");
980 HeapFree(GetProcessHeap(),0,dsb);
982 return DSERR_OUTOFMEMORY;
985 CopyMemory(dsb->pwfx, wfex, cp_size);
987 if (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign)
988 dsb->buflen = dsbd->dwBufferBytes +
989 (dsbd->lpwfxFormat->nBlockAlign -
990 (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign));
992 dsb->buflen = dsbd->dwBufferBytes;
994 dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
996 dsb->notifies = NULL;
997 dsb->nrofnotifies = 0;
1000 /* Check necessary hardware mixing capabilities */
1001 if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
1002 else capf |= DSCAPS_SECONDARYMONO;
1003 if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
1004 else capf |= DSCAPS_SECONDARY8BIT;
1006 use_hw = (device->drvcaps.dwFlags & capf) == capf;
1007 TRACE("use_hw = 0x%08x, capf = 0x%08x, device->drvcaps.dwFlags = 0x%08x\n", use_hw, capf, device->drvcaps.dwFlags);
1009 /* FIXME: check hardware sample rate mixing capabilities */
1010 /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
1011 /* FIXME: check whether any hardware buffers are left */
1012 /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
1014 /* Allocate an empty buffer */
1015 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1016 if (dsb->buffer == NULL) {
1017 WARN("out of memory\n");
1018 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1019 HeapFree(GetProcessHeap(),0,dsb);
1021 return DSERR_OUTOFMEMORY;
1024 /* Allocate system memory for buffer if applicable */
1025 if ((device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
1026 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1027 if (dsb->buffer->memory == NULL) {
1028 WARN("out of memory\n");
1029 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1030 HeapFree(GetProcessHeap(),0,dsb->buffer);
1031 HeapFree(GetProcessHeap(),0,dsb);
1033 return DSERR_OUTOFMEMORY;
1035 dsb->buffer->ref = 1;
1036 FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);
1039 /* Allocate the hardware buffer */
1041 err = IDsDriver_CreateSoundBuffer(device->driver,wfex,dsbd->dwFlags,0,
1042 &(dsb->buflen),&(dsb->buffer->memory),
1043 (LPVOID*)&(dsb->hwbuf));
1044 /* fall back to software buffer on failure */
1046 TRACE("IDsDriver_CreateSoundBuffer failed, falling back to software buffer\n");
1048 if (device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
1049 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1050 if (dsb->buffer->memory == NULL) {
1051 WARN("out of memory\n");
1052 HeapFree(GetProcessHeap(),0,dsb->buffer);
1053 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1054 HeapFree(GetProcessHeap(),0,dsb);
1056 return DSERR_OUTOFMEMORY;
1058 dsb->buffer->ref = 1;
1059 FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);
1065 /* calculate fragment size and write lead */
1066 DSOUND_RecalcFormat(dsb);
1068 /* It's not necessary to initialize values to zero since */
1069 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1070 dsb->buf_mixpos = 0;
1071 dsb->state = STATE_STOPPED;
1073 dsb->freqAdjust = (dsb->freq << DSOUND_FREQSHIFT) /
1074 device->pwfx->nSamplesPerSec;
1075 dsb->nAvgBytesPerSec = dsb->freq *
1076 dsbd->lpwfxFormat->nBlockAlign;
1078 if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
1079 dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
1080 dsb->ds3db_ds3db.vPosition.x = 0.0;
1081 dsb->ds3db_ds3db.vPosition.y = 0.0;
1082 dsb->ds3db_ds3db.vPosition.z = 0.0;
1083 dsb->ds3db_ds3db.vVelocity.x = 0.0;
1084 dsb->ds3db_ds3db.vVelocity.y = 0.0;
1085 dsb->ds3db_ds3db.vVelocity.z = 0.0;
1086 dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1087 dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1088 dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
1089 dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
1090 dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
1091 dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1092 dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1093 dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1094 dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
1096 dsb->ds3db_need_recalc = FALSE;
1097 DSOUND_Calc3DBuffer(dsb);
1099 DSOUND_RecalcVolPan(&(dsb->volpan));
1101 RtlInitializeResource(&dsb->lock);
1103 /* register buffer if not primary */
1104 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1105 err = DirectSoundDevice_AddBuffer(device, dsb);
1107 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1108 HeapFree(GetProcessHeap(),0,dsb->buffer);
1109 RtlDeleteResource(&dsb->lock);
1110 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1111 HeapFree(GetProcessHeap(),0,dsb);
1120 HRESULT IDirectSoundBufferImpl_Destroy(
1121 IDirectSoundBufferImpl *pdsb)
1123 TRACE("(%p)\n",pdsb);
1125 /* This keeps the *_Destroy functions from possibly deleting
1126 * this object until it is ready to be deleted */
1127 IDirectSoundBufferImpl_AddRef((LPDIRECTSOUNDBUFFER8)pdsb);
1130 WARN("iks not NULL\n");
1131 IKsBufferPropertySetImpl_Destroy(pdsb->iks);
1136 WARN("ds3db not NULL\n");
1137 IDirectSound3DBufferImpl_Destroy(pdsb->ds3db);
1142 WARN("notify not NULL\n");
1143 IDirectSoundNotifyImpl_Destroy(pdsb->notify);
1144 pdsb->notify = NULL;
1147 if (pdsb->secondary) {
1148 WARN("dsb not NULL\n");
1149 SecondaryBufferImpl_Destroy(pdsb->secondary);
1150 pdsb->secondary = NULL;
1153 while (IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);
1158 HRESULT IDirectSoundBufferImpl_Duplicate(
1159 DirectSoundDevice *device,
1160 IDirectSoundBufferImpl **ppdsb,
1161 IDirectSoundBufferImpl *pdsb)
1163 IDirectSoundBufferImpl *dsb;
1164 HRESULT hres = DS_OK;
1166 TRACE("(%p,%p,%p)\n", device, pdsb, pdsb);
1168 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
1171 WARN("out of memory\n");
1173 return DSERR_OUTOFMEMORY;
1176 CopyMemory(dsb, pdsb, sizeof(IDirectSoundBufferImpl));
1179 TRACE("duplicating hardware buffer\n");
1181 hres = IDsDriver_DuplicateSoundBuffer(device->driver, pdsb->hwbuf,
1182 (LPVOID *)&dsb->hwbuf);
1183 if (hres != DS_OK) {
1184 TRACE("IDsDriver_DuplicateSoundBuffer failed, falling back to "
1185 "software buffer\n");
1187 /* allocate buffer */
1188 if (device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
1189 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1190 if (dsb->buffer == NULL) {
1191 WARN("out of memory\n");
1192 HeapFree(GetProcessHeap(),0,dsb);
1194 return DSERR_OUTOFMEMORY;
1197 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1198 if (dsb->buffer->memory == NULL) {
1199 WARN("out of memory\n");
1200 HeapFree(GetProcessHeap(),0,dsb->buffer);
1201 HeapFree(GetProcessHeap(),0,dsb);
1203 return DSERR_OUTOFMEMORY;
1205 dsb->buffer->ref = 1;
1207 /* FIXME: copy buffer ? */
1216 dsb->state = STATE_STOPPED;
1217 dsb->buf_mixpos = 0;
1218 dsb->device = device;
1220 dsb->iks = NULL; /* FIXME? */
1221 dsb->secondary = NULL;
1223 /* variable sized struct so calculate size based on format */
1224 size = sizeof(WAVEFORMATEX) + pdsb->pwfx->cbSize;
1226 dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
1227 if (dsb->pwfx == NULL) {
1228 WARN("out of memory\n");
1229 HeapFree(GetProcessHeap(),0,dsb->buffer);
1230 HeapFree(GetProcessHeap(),0,dsb);
1232 return DSERR_OUTOFMEMORY;
1235 CopyMemory(dsb->pwfx, pdsb->pwfx, size);
1237 RtlInitializeResource(&dsb->lock);
1239 /* register buffer */
1240 hres = DirectSoundDevice_AddBuffer(device, dsb);
1241 if (hres != DS_OK) {
1242 RtlDeleteResource(&dsb->lock);
1243 HeapFree(GetProcessHeap(),0,dsb->buffer);
1244 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1245 HeapFree(GetProcessHeap(),0,dsb);
1253 /*******************************************************************************
1257 static HRESULT WINAPI SecondaryBufferImpl_QueryInterface(
1258 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj)
1260 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1261 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
1263 return IDirectSoundBufferImpl_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb,riid,ppobj);
1266 static ULONG WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
1268 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1269 ULONG ref = InterlockedIncrement(&(This->ref));
1270 TRACE("(%p) ref was %d\n", This, ref - 1);
1274 static ULONG WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
1276 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1278 TRACE("(%p)\n", This);
1279 ref = InterlockedDecrement(&(This->ref));
1280 TRACE("ref was %d\n", ref + 1);
1283 This->dsb->secondary = NULL;
1284 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
1285 HeapFree(GetProcessHeap(), 0, This);
1286 TRACE("(%p) released\n", This);
1291 static HRESULT WINAPI SecondaryBufferImpl_GetCaps(
1292 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps)
1294 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1295 TRACE("(%p)->(%p)\n",This,caps);
1297 return IDirectSoundBufferImpl_GetCaps((LPDIRECTSOUNDBUFFER8)This->dsb,caps);
1300 static HRESULT WINAPI SecondaryBufferImpl_GetCurrentPosition(
1301 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos)
1303 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1304 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
1306 return IDirectSoundBufferImpl_GetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,playpos,writepos);
1309 static HRESULT WINAPI SecondaryBufferImpl_GetFormat(
1310 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten)
1312 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1313 TRACE("(%p,%p,%d,%p)\n",This,lpwf,wfsize,wfwritten);
1315 return IDirectSoundBufferImpl_GetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,lpwf,wfsize,wfwritten);
1318 static HRESULT WINAPI SecondaryBufferImpl_GetVolume(
1319 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol)
1321 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1322 TRACE("(%p,%p)\n",This,vol);
1324 return IDirectSoundBufferImpl_GetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1327 static HRESULT WINAPI SecondaryBufferImpl_GetPan(
1328 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan)
1330 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1331 TRACE("(%p,%p)\n",This,pan);
1333 return IDirectSoundBufferImpl_GetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1336 static HRESULT WINAPI SecondaryBufferImpl_GetFrequency(
1337 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq)
1339 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1340 TRACE("(%p,%p)\n",This,freq);
1342 return IDirectSoundBufferImpl_GetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1345 static HRESULT WINAPI SecondaryBufferImpl_GetStatus(
1346 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status)
1348 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1349 TRACE("(%p,%p)\n",This,status);
1351 return IDirectSoundBufferImpl_GetStatus((LPDIRECTSOUNDBUFFER8)This->dsb,status);
1354 static HRESULT WINAPI SecondaryBufferImpl_Initialize(
1355 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd)
1357 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1358 TRACE("(%p,%p,%p)\n",This,dsound,dbsd);
1360 return IDirectSoundBufferImpl_Initialize((LPDIRECTSOUNDBUFFER8)This->dsb,dsound,dbsd);
1363 static HRESULT WINAPI SecondaryBufferImpl_Lock(
1364 LPDIRECTSOUNDBUFFER8 iface,
1367 LPVOID *lplpaudioptr1,
1368 LPDWORD audiobytes1,
1369 LPVOID *lplpaudioptr2,
1370 LPDWORD audiobytes2,
1373 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1374 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x)\n",
1375 This,writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1377 return IDirectSoundBufferImpl_Lock((LPDIRECTSOUNDBUFFER8)This->dsb,
1378 writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1381 static HRESULT WINAPI SecondaryBufferImpl_Play(
1382 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags)
1384 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1385 TRACE("(%p,%08x,%08x,%08x)\n",This,reserved1,reserved2,flags);
1387 return IDirectSoundBufferImpl_Play((LPDIRECTSOUNDBUFFER8)This->dsb,reserved1,reserved2,flags);
1390 static HRESULT WINAPI SecondaryBufferImpl_SetCurrentPosition(
1391 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos)
1393 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1394 TRACE("(%p,%d)\n",This,newpos);
1396 return IDirectSoundBufferImpl_SetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,newpos);
1399 static HRESULT WINAPI SecondaryBufferImpl_SetFormat(
1400 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex)
1402 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1403 TRACE("(%p,%p)\n",This,wfex);
1405 return IDirectSoundBufferImpl_SetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,wfex);
1408 static HRESULT WINAPI SecondaryBufferImpl_SetVolume(
1409 LPDIRECTSOUNDBUFFER8 iface,LONG vol)
1411 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1412 TRACE("(%p,%d)\n",This,vol);
1414 return IDirectSoundBufferImpl_SetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1417 static HRESULT WINAPI SecondaryBufferImpl_SetPan(
1418 LPDIRECTSOUNDBUFFER8 iface,LONG pan)
1420 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1421 TRACE("(%p,%d)\n",This,pan);
1423 return IDirectSoundBufferImpl_SetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1426 static HRESULT WINAPI SecondaryBufferImpl_SetFrequency(
1427 LPDIRECTSOUNDBUFFER8 iface,DWORD freq)
1429 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1430 TRACE("(%p,%d)\n",This,freq);
1432 return IDirectSoundBufferImpl_SetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1435 static HRESULT WINAPI SecondaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
1437 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1438 TRACE("(%p)\n",This);
1440 return IDirectSoundBufferImpl_Stop((LPDIRECTSOUNDBUFFER8)This->dsb);
1443 static HRESULT WINAPI SecondaryBufferImpl_Unlock(
1444 LPDIRECTSOUNDBUFFER8 iface,
1445 LPVOID lpvAudioPtr1,
1446 DWORD dwAudioBytes1,
1447 LPVOID lpvAudioPtr2,
1448 DWORD dwAudioBytes2)
1450 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1451 TRACE("(%p,%p,%d,%p,%d)\n",
1452 This, lpvAudioPtr1, dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1454 return IDirectSoundBufferImpl_Unlock((LPDIRECTSOUNDBUFFER8)This->dsb,
1455 lpvAudioPtr1,dwAudioBytes1,lpvAudioPtr2,dwAudioBytes2);
1458 static HRESULT WINAPI SecondaryBufferImpl_Restore(
1459 LPDIRECTSOUNDBUFFER8 iface)
1461 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1462 TRACE("(%p)\n",This);
1464 return IDirectSoundBufferImpl_Restore((LPDIRECTSOUNDBUFFER8)This->dsb);
1467 static HRESULT WINAPI SecondaryBufferImpl_SetFX(
1468 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes)
1470 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1471 TRACE("(%p,%u,%p,%p)\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1473 return IDirectSoundBufferImpl_SetFX((LPDIRECTSOUNDBUFFER8)This->dsb,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1476 static HRESULT WINAPI SecondaryBufferImpl_AcquireResources(
1477 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes)
1479 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1480 TRACE("(%p,%08u,%u,%p)\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
1482 return IDirectSoundBufferImpl_AcquireResources((LPDIRECTSOUNDBUFFER8)This->dsb,dwFlags,dwEffectsCount,pdwResultCodes);
1485 static HRESULT WINAPI SecondaryBufferImpl_GetObjectInPath(
1486 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject)
1488 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1489 TRACE("(%p,%s,%u,%s,%p)\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
1491 return IDirectSoundBufferImpl_GetObjectInPath((LPDIRECTSOUNDBUFFER8)This->dsb,rguidObject,dwIndex,rguidInterface,ppObject);
1494 static const IDirectSoundBuffer8Vtbl sbvt =
1496 SecondaryBufferImpl_QueryInterface,
1497 SecondaryBufferImpl_AddRef,
1498 SecondaryBufferImpl_Release,
1499 SecondaryBufferImpl_GetCaps,
1500 SecondaryBufferImpl_GetCurrentPosition,
1501 SecondaryBufferImpl_GetFormat,
1502 SecondaryBufferImpl_GetVolume,
1503 SecondaryBufferImpl_GetPan,
1504 SecondaryBufferImpl_GetFrequency,
1505 SecondaryBufferImpl_GetStatus,
1506 SecondaryBufferImpl_Initialize,
1507 SecondaryBufferImpl_Lock,
1508 SecondaryBufferImpl_Play,
1509 SecondaryBufferImpl_SetCurrentPosition,
1510 SecondaryBufferImpl_SetFormat,
1511 SecondaryBufferImpl_SetVolume,
1512 SecondaryBufferImpl_SetPan,
1513 SecondaryBufferImpl_SetFrequency,
1514 SecondaryBufferImpl_Stop,
1515 SecondaryBufferImpl_Unlock,
1516 SecondaryBufferImpl_Restore,
1517 SecondaryBufferImpl_SetFX,
1518 SecondaryBufferImpl_AcquireResources,
1519 SecondaryBufferImpl_GetObjectInPath
1522 HRESULT SecondaryBufferImpl_Create(
1523 IDirectSoundBufferImpl *dsb,
1524 SecondaryBufferImpl **psb)
1526 SecondaryBufferImpl *sb;
1527 TRACE("(%p,%p)\n",dsb,psb);
1529 sb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*sb));
1532 WARN("out of memory\n");
1534 return DSERR_OUTOFMEMORY;
1540 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
1545 static HRESULT SecondaryBufferImpl_Destroy(
1546 SecondaryBufferImpl *pdsb)
1548 TRACE("(%p)\n",pdsb);
1550 while (SecondaryBufferImpl_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);