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
32 #include "wine/debug.h"
35 #include "dsound_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
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 This->dsb->notify = NULL;
86 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)This->dsb);
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 HeapFree(GetProcessHeap(), 0, This->dsb->notifies);
121 This->dsb->notifies = HeapAlloc(GetProcessHeap(), 0,
122 howmuch * sizeof(DSBPOSITIONNOTIFY));
124 if (This->dsb->notifies == NULL) {
125 WARN("out of memory\n");
126 return DSERR_OUTOFMEMORY;
128 CopyMemory(This->dsb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
129 This->dsb->nrofnotifies = howmuch;
131 HeapFree(GetProcessHeap(), 0, This->dsb->notifies);
132 This->dsb->notifies = NULL;
133 This->dsb->nrofnotifies = 0;
139 static const IDirectSoundNotifyVtbl dsnvt =
141 IDirectSoundNotifyImpl_QueryInterface,
142 IDirectSoundNotifyImpl_AddRef,
143 IDirectSoundNotifyImpl_Release,
144 IDirectSoundNotifyImpl_SetNotificationPositions,
147 static HRESULT IDirectSoundNotifyImpl_Create(
148 IDirectSoundBufferImpl * dsb,
149 IDirectSoundNotifyImpl **pdsn)
151 IDirectSoundNotifyImpl * dsn;
152 TRACE("(%p,%p)\n",dsb,pdsn);
154 dsn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*dsn));
157 WARN("out of memory\n");
158 return DSERR_OUTOFMEMORY;
162 dsn->lpVtbl = &dsnvt;
165 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
171 static HRESULT IDirectSoundNotifyImpl_Destroy(
172 IDirectSoundNotifyImpl *pdsn)
174 TRACE("(%p)\n",pdsn);
176 while (IDirectSoundNotifyImpl_Release((LPDIRECTSOUNDNOTIFY)pdsn) > 0);
181 /*******************************************************************************
185 static inline IDirectSoundBufferImpl *impl_from_IDirectSoundBuffer8(IDirectSoundBuffer8 *iface)
187 return CONTAINING_RECORD(iface, IDirectSoundBufferImpl, IDirectSoundBuffer8_iface);
190 static HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(IDirectSoundBuffer8 *iface,
191 LPCWAVEFORMATEX wfex)
193 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
195 TRACE("(%p,%p)\n",This,wfex);
196 /* This method is not available on secondary buffers */
197 WARN("invalid call\n");
198 return DSERR_INVALIDCALL;
201 static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(IDirectSoundBuffer8 *iface, LONG vol)
203 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
206 HRESULT hres = DS_OK;
208 TRACE("(%p,%d)\n",This,vol);
210 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
211 WARN("control unavailable: This->dsbd.dwFlags = 0x%08x\n", This->dsbd.dwFlags);
212 return DSERR_CONTROLUNAVAIL;
215 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
216 WARN("invalid parameter: vol = %d\n", vol);
217 return DSERR_INVALIDPARAM;
221 RtlAcquireResourceExclusive(&This->lock, TRUE);
223 if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) {
224 oldVol = This->ds3db_lVolume;
225 This->ds3db_lVolume = vol;
227 /* recalc 3d volume, which in turn recalcs the pans */
228 DSOUND_Calc3DBuffer(This);
230 oldVol = This->volpan.lVolume;
231 This->volpan.lVolume = vol;
233 DSOUND_RecalcVolPan(&(This->volpan));
238 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
240 WARN("IDsDriverBuffer_SetVolumePan failed\n");
244 RtlReleaseResource(&This->lock);
250 static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(IDirectSoundBuffer8 *iface, LONG *vol)
252 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
254 TRACE("(%p,%p)\n",This,vol);
256 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
257 WARN("control unavailable\n");
258 return DSERR_CONTROLUNAVAIL;
262 WARN("invalid parameter: vol == NULL\n");
263 return DSERR_INVALIDPARAM;
266 *vol = This->volpan.lVolume;
271 static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8 *iface, DWORD freq)
273 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
276 TRACE("(%p,%d)\n",This,freq);
278 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
279 WARN("control unavailable\n");
280 return DSERR_CONTROLUNAVAIL;
283 if (freq == DSBFREQUENCY_ORIGINAL)
284 freq = This->pwfx->nSamplesPerSec;
286 if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX)) {
287 WARN("invalid parameter: freq = %d\n", freq);
288 return DSERR_INVALIDPARAM;
292 RtlAcquireResourceExclusive(&This->lock, TRUE);
294 oldFreq = This->freq;
296 if (freq != oldFreq) {
297 This->freqAdjust = ((DWORD64)This->freq << DSOUND_FREQSHIFT) / This->device->pwfx->nSamplesPerSec;
298 This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;
299 DSOUND_RecalcFormat(This);
300 DSOUND_MixToTemporary(This, 0, This->buflen, FALSE);
303 RtlReleaseResource(&This->lock);
309 static HRESULT WINAPI IDirectSoundBufferImpl_Play(IDirectSoundBuffer8 *iface, DWORD reserved1,
310 DWORD reserved2, DWORD flags)
312 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
313 HRESULT hres = DS_OK;
315 TRACE("(%p,%08x,%08x,%08x)\n",This,reserved1,reserved2,flags);
318 RtlAcquireResourceExclusive(&This->lock, TRUE);
320 This->playflags = flags;
321 if (This->state == STATE_STOPPED && !This->hwbuf) {
323 This->state = STATE_STARTING;
324 } else if (This->state == STATE_STOPPING)
325 This->state = STATE_PLAYING;
327 hres = IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
329 WARN("IDsDriverBuffer_Play failed\n");
331 This->state = STATE_PLAYING;
334 RtlReleaseResource(&This->lock);
340 static HRESULT WINAPI IDirectSoundBufferImpl_Stop(IDirectSoundBuffer8 *iface)
342 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
343 HRESULT hres = DS_OK;
345 TRACE("(%p)\n",This);
348 RtlAcquireResourceExclusive(&This->lock, TRUE);
350 if (This->state == STATE_PLAYING)
351 This->state = STATE_STOPPING;
352 else if (This->state == STATE_STARTING)
354 This->state = STATE_STOPPED;
355 DSOUND_CheckEvent(This, 0, 0);
358 hres = IDsDriverBuffer_Stop(This->hwbuf);
360 WARN("IDsDriverBuffer_Stop failed\n");
362 This->state = STATE_STOPPED;
365 RtlReleaseResource(&This->lock);
371 static ULONG WINAPI IDirectSoundBufferImpl_AddRef(IDirectSoundBuffer8 *iface)
373 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
374 ULONG ref = InterlockedIncrement(&This->ref);
376 TRACE("(%p) ref was %d\n", This, ref - 1);
379 InterlockedIncrement(&This->numIfaces);
384 static ULONG WINAPI IDirectSoundBufferImpl_Release(IDirectSoundBuffer8 *iface)
386 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
387 ULONG ref = InterlockedDecrement(&This->ref);
389 TRACE("(%p) ref was %d\n", This, ref + 1);
391 if (!ref && !InterlockedDecrement(&This->numIfaces))
392 secondarybuffer_destroy(This);
397 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuffer8 *iface,
398 DWORD *playpos, DWORD *writepos)
400 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
403 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
405 RtlAcquireResourceShared(&This->lock, TRUE);
407 hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
409 WARN("IDsDriverBuffer_GetPosition failed\n");
413 DWORD pos = This->sec_mixpos;
416 if (pos >= This->buflen){
417 FIXME("Bad play position. playpos: %d, buflen: %d\n", pos, This->buflen);
426 if (writepos && This->state != STATE_STOPPED && (!This->hwbuf || !(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDWRITELEAD))) {
427 /* apply the documented 10ms lead to writepos */
428 *writepos += This->writelead;
429 *writepos %= This->buflen;
431 RtlReleaseResource(&This->lock);
433 TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n",
434 playpos?*playpos:-1, writepos?*writepos:-1, This->buflen, This, GetTickCount());
439 static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(IDirectSoundBuffer8 *iface, DWORD *status)
441 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
443 TRACE("(%p,%p), thread is %04x\n",This,status,GetCurrentThreadId());
445 if (status == NULL) {
446 WARN("invalid parameter: status = NULL\n");
447 return DSERR_INVALIDPARAM;
451 RtlAcquireResourceShared(&This->lock, TRUE);
452 if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
453 *status |= DSBSTATUS_PLAYING;
454 if (This->playflags & DSBPLAY_LOOPING)
455 *status |= DSBSTATUS_LOOPING;
457 RtlReleaseResource(&This->lock);
459 TRACE("status=%x\n", *status);
464 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(IDirectSoundBuffer8 *iface,
465 LPWAVEFORMATEX lpwf, DWORD wfsize, DWORD *wfwritten)
467 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
470 TRACE("(%p,%p,%d,%p)\n",This,lpwf,wfsize,wfwritten);
472 size = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
474 if (lpwf) { /* NULL is valid */
475 if (wfsize >= size) {
476 CopyMemory(lpwf,This->pwfx,size);
480 WARN("invalid parameter: wfsize too small\n");
481 CopyMemory(lpwf,This->pwfx,wfsize);
484 return DSERR_INVALIDPARAM;
488 *wfwritten = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
490 WARN("invalid parameter: wfwritten == NULL\n");
491 return DSERR_INVALIDPARAM;
498 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8 *iface, DWORD writecursor,
499 DWORD writebytes, void **lplpaudioptr1, DWORD *audiobytes1, void **lplpaudioptr2,
500 DWORD *audiobytes2, DWORD flags)
502 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
503 HRESULT hres = DS_OK;
505 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n", This, writecursor, writebytes, lplpaudioptr1,
506 audiobytes1, lplpaudioptr2, audiobytes2, flags, GetTickCount());
509 return DSERR_INVALIDPARAM;
511 /* when this flag is set, writecursor is meaningless and must be calculated */
512 if (flags & DSBLOCK_FROMWRITECURSOR) {
513 /* GetCurrentPosition does too much magic to duplicate here */
514 hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writecursor);
516 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
521 /* when this flag is set, writebytes is meaningless and must be set */
522 if (flags & DSBLOCK_ENTIREBUFFER)
523 writebytes = This->buflen;
525 if (writecursor >= This->buflen) {
526 WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
527 writecursor, This->buflen);
528 return DSERR_INVALIDPARAM;
531 if (writebytes > This->buflen) {
532 WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
533 writebytes, This->buflen);
534 return DSERR_INVALIDPARAM;
538 RtlAcquireResourceShared(&This->lock, TRUE);
540 if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
541 hres = IDsDriverBuffer_Lock(This->hwbuf,
542 lplpaudioptr1, audiobytes1,
543 lplpaudioptr2, audiobytes2,
544 writecursor, writebytes,
547 WARN("IDsDriverBuffer_Lock failed\n");
548 RtlReleaseResource(&This->lock);
552 if (writecursor+writebytes <= This->buflen) {
553 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
554 if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)
555 WARN("Overwriting mixing position, case 1\n");
556 *audiobytes1 = writebytes;
558 *(LPBYTE*)lplpaudioptr2 = NULL;
561 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n",
562 *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
563 TRACE("->%d.0\n",writebytes);
565 DWORD remainder = writebytes + writecursor - This->buflen;
566 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
567 *audiobytes1 = This->buflen-writecursor;
568 if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)
569 WARN("Overwriting mixing position, case 2\n");
571 *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
573 *audiobytes2 = writebytes-(This->buflen-writecursor);
574 if (audiobytes2 && This->sec_mixpos < remainder && This->state == STATE_PLAYING)
575 WARN("Overwriting mixing position, case 3\n");
576 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
580 RtlReleaseResource(&This->lock);
586 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuffer8 *iface,
589 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
590 HRESULT hres = DS_OK;
593 TRACE("(%p,%d)\n",This,newpos);
596 RtlAcquireResourceExclusive(&This->lock, TRUE);
598 oldpos = This->sec_mixpos;
600 /* start mixing from this new location instead */
601 newpos %= This->buflen;
602 newpos -= newpos%This->pwfx->nBlockAlign;
603 This->sec_mixpos = newpos;
605 /* at this point, do not attempt to reset buffers, mess with primary mix position,
606 or anything like that to reduce latency. The data already prebuffered cannot be changed */
608 /* position HW buffer if applicable, else just start mixing from new location instead */
610 hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
612 WARN("IDsDriverBuffer_SetPosition failed\n");
614 else if (oldpos != newpos)
615 /* FIXME: Perhaps add a call to DSOUND_MixToTemporary here? Not sure it's needed */
616 This->buf_mixpos = DSOUND_secpos_to_bufpos(This, newpos, 0, NULL);
618 RtlReleaseResource(&This->lock);
624 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(IDirectSoundBuffer8 *iface, LONG pan)
626 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
627 HRESULT hres = DS_OK;
629 TRACE("(%p,%d)\n",This,pan);
631 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
632 WARN("invalid parameter: pan = %d\n", pan);
633 return DSERR_INVALIDPARAM;
636 /* You cannot use both pan and 3D controls */
637 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
638 (This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
639 WARN("control unavailable\n");
640 return DSERR_CONTROLUNAVAIL;
644 RtlAcquireResourceExclusive(&This->lock, TRUE);
646 if (This->volpan.lPan != pan) {
647 This->volpan.lPan = pan;
648 DSOUND_RecalcVolPan(&(This->volpan));
651 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
653 WARN("IDsDriverBuffer_SetVolumePan failed\n");
657 RtlReleaseResource(&This->lock);
663 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(IDirectSoundBuffer8 *iface, LONG *pan)
665 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
667 TRACE("(%p,%p)\n",This,pan);
669 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
670 WARN("control unavailable\n");
671 return DSERR_CONTROLUNAVAIL;
675 WARN("invalid parameter: pan = NULL\n");
676 return DSERR_INVALIDPARAM;
679 *pan = This->volpan.lPan;
684 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8 *iface, void *p1, DWORD x1,
687 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface), *iter;
688 HRESULT hres = DS_OK;
690 TRACE("(%p,%p,%d,%p,%d)\n", This,p1,x1,p2,x2);
693 RtlAcquireResourceShared(&This->lock, TRUE);
695 if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
696 hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
698 WARN("IDsDriverBuffer_Unlock failed\n");
701 RtlReleaseResource(&This->lock);
707 if (!This->hwbuf && (x1 || x2))
709 RtlAcquireResourceShared(&This->device->buffer_list_lock, TRUE);
710 LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers, IDirectSoundBufferImpl, entry )
712 RtlAcquireResourceShared(&iter->lock, TRUE);
715 if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen)
716 hres = DSERR_INVALIDPARAM;
718 DSOUND_MixToTemporary(iter, (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory, x1, FALSE);
721 DSOUND_MixToTemporary(iter, 0, x2, FALSE);
722 RtlReleaseResource(&iter->lock);
724 RtlReleaseResource(&This->device->buffer_list_lock);
730 static HRESULT WINAPI IDirectSoundBufferImpl_Restore(IDirectSoundBuffer8 *iface)
732 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
734 FIXME("(%p):stub\n",This);
738 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(IDirectSoundBuffer8 *iface, DWORD *freq)
740 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
742 TRACE("(%p,%p)\n",This,freq);
745 WARN("invalid parameter: freq = NULL\n");
746 return DSERR_INVALIDPARAM;
750 TRACE("-> %d\n", *freq);
755 static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(IDirectSoundBuffer8 *iface, DWORD dwEffectsCount,
756 LPDSEFFECTDESC pDSFXDesc, DWORD *pdwResultCodes)
758 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
761 FIXME("(%p,%u,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
764 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
766 WARN("control unavailable\n");
767 return DSERR_CONTROLUNAVAIL;
770 static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(IDirectSoundBuffer8 *iface,
771 DWORD dwFlags, DWORD dwEffectsCount, DWORD *pdwResultCodes)
773 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
776 FIXME("(%p,%08u,%u,%p): stub, faking success\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
779 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
781 WARN("control unavailable\n");
785 static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(IDirectSoundBuffer8 *iface,
786 REFGUID rguidObject, DWORD dwIndex, REFGUID rguidInterface, void **ppObject)
788 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
790 FIXME("(%p,%s,%u,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
792 WARN("control unavailable\n");
793 return DSERR_CONTROLUNAVAIL;
796 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(IDirectSoundBuffer8 *iface,
797 IDirectSound *dsound, LPCDSBUFFERDESC dbsd)
799 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
801 WARN("(%p) already initialized\n", This);
802 return DSERR_ALREADYINITIALIZED;
805 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(IDirectSoundBuffer8 *iface, LPDSBCAPS caps)
807 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
809 TRACE("(%p)->(%p)\n",This,caps);
812 WARN("invalid parameter: caps == NULL\n");
813 return DSERR_INVALIDPARAM;
816 if (caps->dwSize < sizeof(*caps)) {
817 WARN("invalid parameter: caps->dwSize = %d\n",caps->dwSize);
818 return DSERR_INVALIDPARAM;
821 caps->dwFlags = This->dsbd.dwFlags;
822 if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
823 else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
825 caps->dwBufferBytes = This->buflen;
827 /* According to windows, this is zero*/
828 caps->dwUnlockTransferRate = 0;
829 caps->dwPlayCpuOverhead = 0;
834 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(IDirectSoundBuffer8 *iface, REFIID riid,
837 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
839 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
842 WARN("invalid parameter\n");
846 *ppobj = NULL; /* assume failure */
848 if ( IsEqualGUID(riid, &IID_IUnknown) ||
849 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
850 IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
851 IDirectSoundBuffer8_AddRef(iface);
856 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
858 IDirectSoundNotifyImpl_Create(This, &(This->notify));
860 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
861 *ppobj = This->notify;
864 WARN("IID_IDirectSoundNotify\n");
865 return E_NOINTERFACE;
868 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
870 IDirectSound3DBufferImpl_Create(This, &(This->ds3db));
872 IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->ds3db);
873 *ppobj = This->ds3db;
876 WARN("IID_IDirectSound3DBuffer\n");
877 return E_NOINTERFACE;
880 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
881 ERR("app requested IDirectSound3DListener on secondary buffer\n");
882 return E_NOINTERFACE;
885 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
887 IKsBufferPropertySetImpl_Create(This, &(This->iks));
889 IKsPropertySet_AddRef((LPKSPROPERTYSET)This->iks);
893 WARN("IID_IKsPropertySet\n");
894 return E_NOINTERFACE;
897 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
899 return E_NOINTERFACE;
902 static const IDirectSoundBuffer8Vtbl dsbvt =
904 IDirectSoundBufferImpl_QueryInterface,
905 IDirectSoundBufferImpl_AddRef,
906 IDirectSoundBufferImpl_Release,
907 IDirectSoundBufferImpl_GetCaps,
908 IDirectSoundBufferImpl_GetCurrentPosition,
909 IDirectSoundBufferImpl_GetFormat,
910 IDirectSoundBufferImpl_GetVolume,
911 IDirectSoundBufferImpl_GetPan,
912 IDirectSoundBufferImpl_GetFrequency,
913 IDirectSoundBufferImpl_GetStatus,
914 IDirectSoundBufferImpl_Initialize,
915 IDirectSoundBufferImpl_Lock,
916 IDirectSoundBufferImpl_Play,
917 IDirectSoundBufferImpl_SetCurrentPosition,
918 IDirectSoundBufferImpl_SetFormat,
919 IDirectSoundBufferImpl_SetVolume,
920 IDirectSoundBufferImpl_SetPan,
921 IDirectSoundBufferImpl_SetFrequency,
922 IDirectSoundBufferImpl_Stop,
923 IDirectSoundBufferImpl_Unlock,
924 IDirectSoundBufferImpl_Restore,
925 IDirectSoundBufferImpl_SetFX,
926 IDirectSoundBufferImpl_AcquireResources,
927 IDirectSoundBufferImpl_GetObjectInPath
930 HRESULT IDirectSoundBufferImpl_Create(
931 DirectSoundDevice * device,
932 IDirectSoundBufferImpl **pdsb,
933 LPCDSBUFFERDESC dsbd)
935 IDirectSoundBufferImpl *dsb;
936 LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
940 TRACE("(%p,%p,%p)\n",device,pdsb,dsbd);
942 if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
943 WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd->dwBufferBytes);
945 return DSERR_INVALIDPARAM; /* FIXME: which error? */
948 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
951 WARN("out of memory\n");
953 return DSERR_OUTOFMEMORY;
956 TRACE("Created buffer at %p\n", dsb);
960 dsb->device = device;
961 dsb->IDirectSoundBuffer8_iface.lpVtbl = &dsbvt;
964 /* size depends on version */
965 CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
967 dsb->pwfx = DSOUND_CopyFormat(wfex);
968 if (dsb->pwfx == NULL) {
969 HeapFree(GetProcessHeap(),0,dsb);
971 return DSERR_OUTOFMEMORY;
974 if (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign)
975 dsb->buflen = dsbd->dwBufferBytes +
976 (dsbd->lpwfxFormat->nBlockAlign -
977 (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign));
979 dsb->buflen = dsbd->dwBufferBytes;
981 dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
983 dsb->notifies = NULL;
984 dsb->nrofnotifies = 0;
987 /* Check necessary hardware mixing capabilities */
988 if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
989 else capf |= DSCAPS_SECONDARYMONO;
990 if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
991 else capf |= DSCAPS_SECONDARY8BIT;
993 use_hw = !!(dsbd->dwFlags & DSBCAPS_LOCHARDWARE);
994 TRACE("use_hw = %d, capf = 0x%08x, device->drvcaps.dwFlags = 0x%08x\n", use_hw, capf, device->drvcaps.dwFlags);
995 if (use_hw && ((device->drvcaps.dwFlags & capf) != capf || !device->driver))
998 WARN("Format not supported for hardware buffer\n");
999 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1000 HeapFree(GetProcessHeap(),0,dsb);
1002 if ((device->drvcaps.dwFlags & capf) != capf)
1003 return DSERR_BADFORMAT;
1004 return DSERR_GENERIC;
1007 /* FIXME: check hardware sample rate mixing capabilities */
1008 /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
1009 /* FIXME: check whether any hardware buffers are left */
1010 /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
1012 /* Allocate an empty buffer */
1013 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1014 if (dsb->buffer == NULL) {
1015 WARN("out of memory\n");
1016 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1017 HeapFree(GetProcessHeap(),0,dsb);
1019 return DSERR_OUTOFMEMORY;
1022 /* Allocate system memory for buffer if applicable */
1023 if ((device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
1024 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1025 if (dsb->buffer->memory == NULL) {
1026 WARN("out of memory\n");
1027 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1028 HeapFree(GetProcessHeap(),0,dsb->buffer);
1029 HeapFree(GetProcessHeap(),0,dsb);
1031 return DSERR_OUTOFMEMORY;
1035 /* Allocate the hardware buffer */
1037 err = IDsDriver_CreateSoundBuffer(device->driver,wfex,dsbd->dwFlags,0,
1038 &(dsb->buflen),&(dsb->buffer->memory),
1039 (LPVOID*)&(dsb->hwbuf));
1042 WARN("Failed to create hardware secondary buffer: %08x\n", err);
1043 if (device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY)
1044 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1045 HeapFree(GetProcessHeap(),0,dsb->buffer);
1046 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1047 HeapFree(GetProcessHeap(),0,dsb);
1049 return DSERR_GENERIC;
1053 dsb->buffer->ref = 1;
1054 list_init(&dsb->buffer->buffers);
1055 list_add_head(&dsb->buffer->buffers, &dsb->entry);
1056 FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);
1058 /* It's not necessary to initialize values to zero since */
1059 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1060 dsb->buf_mixpos = dsb->sec_mixpos = 0;
1061 dsb->state = STATE_STOPPED;
1063 dsb->freqAdjust = ((DWORD64)dsb->freq << DSOUND_FREQSHIFT) / device->pwfx->nSamplesPerSec;
1064 dsb->nAvgBytesPerSec = dsb->freq *
1065 dsbd->lpwfxFormat->nBlockAlign;
1067 /* calculate fragment size and write lead */
1068 DSOUND_RecalcFormat(dsb);
1070 if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
1071 dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
1072 dsb->ds3db_ds3db.vPosition.x = 0.0;
1073 dsb->ds3db_ds3db.vPosition.y = 0.0;
1074 dsb->ds3db_ds3db.vPosition.z = 0.0;
1075 dsb->ds3db_ds3db.vVelocity.x = 0.0;
1076 dsb->ds3db_ds3db.vVelocity.y = 0.0;
1077 dsb->ds3db_ds3db.vVelocity.z = 0.0;
1078 dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1079 dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1080 dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
1081 dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
1082 dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
1083 dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1084 dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1085 dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1086 dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
1088 dsb->ds3db_need_recalc = FALSE;
1089 DSOUND_Calc3DBuffer(dsb);
1091 DSOUND_RecalcVolPan(&(dsb->volpan));
1093 RtlInitializeResource(&dsb->lock);
1095 /* register buffer if not primary */
1096 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1097 err = DirectSoundDevice_AddBuffer(device, dsb);
1099 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1100 HeapFree(GetProcessHeap(),0,dsb->buffer);
1101 RtlDeleteResource(&dsb->lock);
1102 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1103 HeapFree(GetProcessHeap(),0,dsb);
1112 void secondarybuffer_destroy(IDirectSoundBufferImpl *This)
1114 DirectSoundDevice_RemoveBuffer(This->device, This);
1115 RtlDeleteResource(&This->lock);
1118 IDsDriverBuffer_Release(This->hwbuf);
1119 if (!This->hwbuf || (This->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY)) {
1120 This->buffer->ref--;
1121 list_remove(&This->entry);
1122 if (This->buffer->ref == 0) {
1123 HeapFree(GetProcessHeap(), 0, This->buffer->memory);
1124 HeapFree(GetProcessHeap(), 0, This->buffer);
1128 HeapFree(GetProcessHeap(), 0, This->tmp_buffer);
1129 HeapFree(GetProcessHeap(), 0, This->notifies);
1130 HeapFree(GetProcessHeap(), 0, This->pwfx);
1131 HeapFree(GetProcessHeap(), 0, This);
1133 TRACE("(%p) released\n", This);
1136 HRESULT IDirectSoundBufferImpl_Destroy(
1137 IDirectSoundBufferImpl *pdsb)
1139 TRACE("(%p)\n",pdsb);
1141 /* This keeps the *_Destroy functions from possibly deleting
1142 * this object until it is ready to be deleted */
1143 InterlockedIncrement(&pdsb->numIfaces);
1146 WARN("iks not NULL\n");
1147 IKsBufferPropertySetImpl_Destroy(pdsb->iks);
1152 WARN("ds3db not NULL\n");
1153 IDirectSound3DBufferImpl_Destroy(pdsb->ds3db);
1158 WARN("notify not NULL\n");
1159 IDirectSoundNotifyImpl_Destroy(pdsb->notify);
1160 pdsb->notify = NULL;
1163 secondarybuffer_destroy(pdsb);
1168 HRESULT IDirectSoundBufferImpl_Duplicate(
1169 DirectSoundDevice *device,
1170 IDirectSoundBufferImpl **ppdsb,
1171 IDirectSoundBufferImpl *pdsb)
1173 IDirectSoundBufferImpl *dsb;
1174 HRESULT hres = DS_OK;
1175 TRACE("(%p,%p,%p)\n", device, ppdsb, pdsb);
1177 dsb = HeapAlloc(GetProcessHeap(),0,sizeof(*dsb));
1179 WARN("out of memory\n");
1181 return DSERR_OUTOFMEMORY;
1183 CopyMemory(dsb, pdsb, sizeof(*dsb));
1185 dsb->pwfx = DSOUND_CopyFormat(pdsb->pwfx);
1186 if (dsb->pwfx == NULL) {
1187 HeapFree(GetProcessHeap(),0,dsb);
1189 return DSERR_OUTOFMEMORY;
1193 TRACE("duplicating hardware buffer\n");
1195 hres = IDsDriver_DuplicateSoundBuffer(device->driver, pdsb->hwbuf,
1196 (LPVOID *)&dsb->hwbuf);
1198 WARN("IDsDriver_DuplicateSoundBuffer failed (%08x)\n", hres);
1199 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1200 HeapFree(GetProcessHeap(),0,dsb);
1207 list_add_head(&dsb->buffer->buffers, &dsb->entry);
1210 dsb->state = STATE_STOPPED;
1211 dsb->buf_mixpos = dsb->sec_mixpos = 0;
1213 dsb->notifies = NULL;
1214 dsb->nrofnotifies = 0;
1215 dsb->device = device;
1217 dsb->iks = NULL; /* FIXME? */
1218 dsb->tmp_buffer = NULL;
1219 DSOUND_RecalcFormat(dsb);
1220 DSOUND_MixToTemporary(dsb, 0, dsb->buflen, FALSE);
1222 RtlInitializeResource(&dsb->lock);
1224 /* register buffer */
1225 hres = DirectSoundDevice_AddBuffer(device, dsb);
1226 if (hres != DS_OK) {
1227 RtlDeleteResource(&dsb->lock);
1228 HeapFree(GetProcessHeap(),0,dsb->tmp_buffer);
1229 list_remove(&dsb->entry);
1231 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1232 HeapFree(GetProcessHeap(),0,dsb);
1240 /*******************************************************************************
1241 * IKsBufferPropertySet
1244 /* IUnknown methods */
1245 static HRESULT WINAPI IKsBufferPropertySetImpl_QueryInterface(
1246 LPKSPROPERTYSET iface,
1250 IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
1251 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
1253 return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb, riid, ppobj);
1256 static ULONG WINAPI IKsBufferPropertySetImpl_AddRef(LPKSPROPERTYSET iface)
1258 IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
1259 ULONG ref = InterlockedIncrement(&(This->ref));
1260 TRACE("(%p) ref was %d\n", This, ref - 1);
1264 static ULONG WINAPI IKsBufferPropertySetImpl_Release(LPKSPROPERTYSET iface)
1266 IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
1267 ULONG ref = InterlockedDecrement(&(This->ref));
1268 TRACE("(%p) ref was %d\n", This, ref + 1);
1272 IDirectSoundBuffer_Release((LPDIRECTSOUND3DBUFFER)This->dsb);
1273 HeapFree(GetProcessHeap(), 0, This);
1274 TRACE("(%p) released\n", This);
1279 static HRESULT WINAPI IKsBufferPropertySetImpl_Get(
1280 LPKSPROPERTYSET iface,
1281 REFGUID guidPropSet,
1283 LPVOID pInstanceData,
1284 ULONG cbInstanceData,
1287 PULONG pcbReturned )
1289 IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
1290 PIDSDRIVERPROPERTYSET ps;
1291 TRACE("(iface=%p,guidPropSet=%s,dwPropID=%d,pInstanceData=%p,cbInstanceData=%d,pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
1292 This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData,pcbReturned);
1294 if (This->dsb->hwbuf) {
1295 IDsDriver_QueryInterface(This->dsb->hwbuf, &IID_IDsDriverPropertySet, (void **)&ps);
1301 prop.s.Set = *guidPropSet;
1302 prop.s.Id = dwPropID;
1303 prop.s.Flags = 0; /* unused */
1304 prop.s.InstanceId = (ULONG)This->dsb->device;
1307 hres = IDsDriverPropertySet_Get(ps, &prop, pInstanceData, cbInstanceData, pPropData, cbPropData, pcbReturned);
1309 IDsDriverPropertySet_Release(ps);
1315 return E_PROP_ID_UNSUPPORTED;
1318 static HRESULT WINAPI IKsBufferPropertySetImpl_Set(
1319 LPKSPROPERTYSET iface,
1320 REFGUID guidPropSet,
1322 LPVOID pInstanceData,
1323 ULONG cbInstanceData,
1327 IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
1328 PIDSDRIVERPROPERTYSET ps;
1329 TRACE("(%p,%s,%d,%p,%d,%p,%d)\n",This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData);
1331 if (This->dsb->hwbuf) {
1332 IDsDriver_QueryInterface(This->dsb->hwbuf, &IID_IDsDriverPropertySet, (void **)&ps);
1338 prop.s.Set = *guidPropSet;
1339 prop.s.Id = dwPropID;
1340 prop.s.Flags = 0; /* unused */
1341 prop.s.InstanceId = (ULONG)This->dsb->device;
1342 hres = IDsDriverPropertySet_Set(ps,&prop,pInstanceData,cbInstanceData,pPropData,cbPropData);
1344 IDsDriverPropertySet_Release(ps);
1350 return E_PROP_ID_UNSUPPORTED;
1353 static HRESULT WINAPI IKsBufferPropertySetImpl_QuerySupport(
1354 LPKSPROPERTYSET iface,
1355 REFGUID guidPropSet,
1357 PULONG pTypeSupport )
1359 IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
1360 PIDSDRIVERPROPERTYSET ps;
1361 TRACE("(%p,%s,%d,%p)\n",This,debugstr_guid(guidPropSet),dwPropID,pTypeSupport);
1363 if (This->dsb->hwbuf) {
1364 IDsDriver_QueryInterface(This->dsb->hwbuf, &IID_IDsDriverPropertySet, (void **)&ps);
1369 hres = IDsDriverPropertySet_QuerySupport(ps,guidPropSet, dwPropID,pTypeSupport);
1371 IDsDriverPropertySet_Release(ps);
1377 return E_PROP_ID_UNSUPPORTED;
1380 static const IKsPropertySetVtbl iksbvt = {
1381 IKsBufferPropertySetImpl_QueryInterface,
1382 IKsBufferPropertySetImpl_AddRef,
1383 IKsBufferPropertySetImpl_Release,
1384 IKsBufferPropertySetImpl_Get,
1385 IKsBufferPropertySetImpl_Set,
1386 IKsBufferPropertySetImpl_QuerySupport
1389 HRESULT IKsBufferPropertySetImpl_Create(
1390 IDirectSoundBufferImpl *dsb,
1391 IKsBufferPropertySetImpl **piks)
1393 IKsBufferPropertySetImpl *iks;
1394 TRACE("(%p,%p)\n",dsb,piks);
1397 iks = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*iks));
1399 WARN("out of memory\n");
1401 return DSERR_OUTOFMEMORY;
1407 iks->lpVtbl = &iksbvt;
1409 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
1415 HRESULT IKsBufferPropertySetImpl_Destroy(
1416 IKsBufferPropertySetImpl *piks)
1418 TRACE("(%p)\n",piks);
1420 while (IKsBufferPropertySetImpl_Release((LPKSPROPERTYSET)piks) > 0);