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 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 HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(
186 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex
188 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
190 TRACE("(%p,%p)\n",This,wfex);
191 /* This method is not available on secondary buffers */
192 WARN("invalid call\n");
193 return DSERR_INVALIDCALL;
196 static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
197 LPDIRECTSOUNDBUFFER8 iface,LONG vol
199 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
201 HRESULT hres = DS_OK;
203 TRACE("(%p,%d)\n",This,vol);
205 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
206 WARN("control unavailable: This->dsbd.dwFlags = 0x%08x\n", This->dsbd.dwFlags);
207 return DSERR_CONTROLUNAVAIL;
210 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
211 WARN("invalid parameter: vol = %d\n", vol);
212 return DSERR_INVALIDPARAM;
216 RtlAcquireResourceExclusive(&This->lock, TRUE);
218 if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) {
219 oldVol = This->ds3db_lVolume;
220 This->ds3db_lVolume = vol;
222 /* recalc 3d volume, which in turn recalcs the pans */
223 DSOUND_Calc3DBuffer(This);
225 oldVol = This->volpan.lVolume;
226 This->volpan.lVolume = vol;
228 DSOUND_RecalcVolPan(&(This->volpan));
233 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
235 WARN("IDsDriverBuffer_SetVolumePan failed\n");
239 RtlReleaseResource(&This->lock);
245 static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(
246 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
248 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
249 TRACE("(%p,%p)\n",This,vol);
251 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
252 WARN("control unavailable\n");
253 return DSERR_CONTROLUNAVAIL;
257 WARN("invalid parameter: vol == NULL\n");
258 return DSERR_INVALIDPARAM;
261 *vol = This->volpan.lVolume;
266 static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
267 LPDIRECTSOUNDBUFFER8 iface,DWORD freq
269 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
272 TRACE("(%p,%d)\n",This,freq);
274 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
275 WARN("control unavailable\n");
276 return DSERR_CONTROLUNAVAIL;
279 if (freq == DSBFREQUENCY_ORIGINAL)
280 freq = This->pwfx->nSamplesPerSec;
282 if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX)) {
283 WARN("invalid parameter: freq = %d\n", freq);
284 return DSERR_INVALIDPARAM;
288 RtlAcquireResourceExclusive(&This->lock, TRUE);
290 oldFreq = This->freq;
292 if (freq != oldFreq) {
293 This->freqAdjust = ((DWORD64)This->freq << DSOUND_FREQSHIFT) / This->device->pwfx->nSamplesPerSec;
294 This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;
295 DSOUND_RecalcFormat(This);
296 DSOUND_MixToTemporary(This, 0, This->buflen, FALSE);
299 RtlReleaseResource(&This->lock);
305 static HRESULT WINAPI IDirectSoundBufferImpl_Play(
306 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
308 HRESULT hres = DS_OK;
309 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
310 TRACE("(%p,%08x,%08x,%08x)\n",This,reserved1,reserved2,flags);
313 RtlAcquireResourceExclusive(&This->lock, TRUE);
315 This->playflags = flags;
316 if (This->state == STATE_STOPPED && !This->hwbuf) {
318 This->state = STATE_STARTING;
319 } else if (This->state == STATE_STOPPING)
320 This->state = STATE_PLAYING;
322 hres = IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
324 WARN("IDsDriverBuffer_Play failed\n");
326 This->state = STATE_PLAYING;
329 RtlReleaseResource(&This->lock);
335 static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
337 HRESULT hres = DS_OK;
338 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
339 TRACE("(%p)\n",This);
342 RtlAcquireResourceExclusive(&This->lock, TRUE);
344 if (This->state == STATE_PLAYING)
345 This->state = STATE_STOPPING;
346 else if (This->state == STATE_STARTING)
348 This->state = STATE_STOPPED;
349 DSOUND_CheckEvent(This, 0, 0);
352 hres = IDsDriverBuffer_Stop(This->hwbuf);
354 WARN("IDsDriverBuffer_Stop failed\n");
356 This->state = STATE_STOPPED;
359 RtlReleaseResource(&This->lock);
365 static ULONG WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
367 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
368 ULONG ref = InterlockedIncrement(&(This->ref));
369 TRACE("(%p) ref was %d\n", This, ref - 1);
373 static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
375 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
376 ULONG ref = InterlockedDecrement(&(This->ref));
377 TRACE("(%p) ref was %d\n", This, ref + 1);
380 DirectSoundDevice_RemoveBuffer(This->device, This);
381 RtlDeleteResource(&This->lock);
384 IDsDriverBuffer_Release(This->hwbuf);
385 if (!This->hwbuf || (This->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY)) {
387 list_remove(&This->entry);
388 if (This->buffer->ref==0) {
389 HeapFree(GetProcessHeap(),0,This->buffer->memory);
390 HeapFree(GetProcessHeap(),0,This->buffer);
394 HeapFree(GetProcessHeap(), 0, This->tmp_buffer);
395 HeapFree(GetProcessHeap(), 0, This->notifies);
396 HeapFree(GetProcessHeap(), 0, This->pwfx);
397 HeapFree(GetProcessHeap(), 0, This);
399 TRACE("(%p) released\n", This);
404 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
405 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
408 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
409 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
411 RtlAcquireResourceShared(&This->lock, TRUE);
413 hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
415 WARN("IDsDriverBuffer_GetPosition failed\n");
419 DWORD pos = This->sec_mixpos;
422 if (pos >= This->buflen){
423 FIXME("Bad play position. playpos: %d, buflen: %d\n", pos, This->buflen);
432 if (writepos && This->state != STATE_STOPPED && (!This->hwbuf || !(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDWRITELEAD))) {
433 /* apply the documented 10ms lead to writepos */
434 *writepos += This->writelead;
435 *writepos %= This->buflen;
437 RtlReleaseResource(&This->lock);
439 TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n",
440 playpos?*playpos:-1, writepos?*writepos:-1, This->buflen, This, GetTickCount());
445 static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
446 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
448 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
449 TRACE("(%p,%p), thread is %04x\n",This,status,GetCurrentThreadId());
451 if (status == NULL) {
452 WARN("invalid parameter: status = NULL\n");
453 return DSERR_INVALIDPARAM;
457 RtlAcquireResourceShared(&This->lock, TRUE);
458 if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
459 *status |= DSBSTATUS_PLAYING;
460 if (This->playflags & DSBPLAY_LOOPING)
461 *status |= DSBSTATUS_LOOPING;
463 RtlReleaseResource(&This->lock);
465 TRACE("status=%x\n", *status);
470 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
471 LPDIRECTSOUNDBUFFER8 iface,
477 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
478 TRACE("(%p,%p,%d,%p)\n",This,lpwf,wfsize,wfwritten);
480 size = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
482 if (lpwf) { /* NULL is valid */
483 if (wfsize >= size) {
484 CopyMemory(lpwf,This->pwfx,size);
488 WARN("invalid parameter: wfsize too small\n");
489 CopyMemory(lpwf,This->pwfx,wfsize);
492 return DSERR_INVALIDPARAM;
496 *wfwritten = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
498 WARN("invalid parameter: wfwritten == NULL\n");
499 return DSERR_INVALIDPARAM;
506 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
507 LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID *lplpaudioptr1,LPDWORD audiobytes1,LPVOID *lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
509 HRESULT hres = DS_OK;
510 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
512 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n",
525 return DSERR_INVALIDPARAM;
527 /* when this flag is set, writecursor is meaningless and must be calculated */
528 if (flags & DSBLOCK_FROMWRITECURSOR) {
529 /* GetCurrentPosition does too much magic to duplicate here */
530 hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writecursor);
532 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
537 /* when this flag is set, writebytes is meaningless and must be set */
538 if (flags & DSBLOCK_ENTIREBUFFER)
539 writebytes = This->buflen;
541 if (writecursor >= This->buflen) {
542 WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
543 writecursor, This->buflen);
544 return DSERR_INVALIDPARAM;
547 if (writebytes > This->buflen) {
548 WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
549 writebytes, This->buflen);
550 return DSERR_INVALIDPARAM;
554 RtlAcquireResourceShared(&This->lock, TRUE);
556 if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
557 hres = IDsDriverBuffer_Lock(This->hwbuf,
558 lplpaudioptr1, audiobytes1,
559 lplpaudioptr2, audiobytes2,
560 writecursor, writebytes,
563 WARN("IDsDriverBuffer_Lock failed\n");
564 RtlReleaseResource(&This->lock);
568 if (writecursor+writebytes <= This->buflen) {
569 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
570 if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)
571 WARN("Overwriting mixing position, case 1\n");
572 *audiobytes1 = writebytes;
574 *(LPBYTE*)lplpaudioptr2 = NULL;
577 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n",
578 *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
579 TRACE("->%d.0\n",writebytes);
581 DWORD remainder = writebytes + writecursor - This->buflen;
582 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
583 *audiobytes1 = This->buflen-writecursor;
584 if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)
585 WARN("Overwriting mixing position, case 2\n");
587 *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
589 *audiobytes2 = writebytes-(This->buflen-writecursor);
590 if (audiobytes2 && This->sec_mixpos < remainder && This->state == STATE_PLAYING)
591 WARN("Overwriting mixing position, case 3\n");
592 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
596 RtlReleaseResource(&This->lock);
602 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
603 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
605 HRESULT hres = DS_OK;
606 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
608 TRACE("(%p,%d)\n",This,newpos);
611 RtlAcquireResourceExclusive(&This->lock, TRUE);
613 oldpos = This->sec_mixpos;
615 /* start mixing from this new location instead */
616 newpos %= This->buflen;
617 newpos -= newpos%This->pwfx->nBlockAlign;
618 This->sec_mixpos = newpos;
620 /* at this point, do not attempt to reset buffers, mess with primary mix position,
621 or anything like that to reduce latancy. The data already prebuffered cannot be changed */
623 /* position HW buffer if applicable, else just start mixing from new location instead */
625 hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
627 WARN("IDsDriverBuffer_SetPosition failed\n");
629 else if (oldpos != newpos)
630 /* FIXME: Perhaps add a call to DSOUND_MixToTemporary here? Not sure it's needed */
631 This->buf_mixpos = DSOUND_secpos_to_bufpos(This, newpos, 0, NULL);
633 RtlReleaseResource(&This->lock);
639 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
640 LPDIRECTSOUNDBUFFER8 iface,LONG pan
642 HRESULT hres = DS_OK;
643 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
645 TRACE("(%p,%d)\n",This,pan);
647 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
648 WARN("invalid parameter: pan = %d\n", pan);
649 return DSERR_INVALIDPARAM;
652 /* You cannot use both pan and 3D controls */
653 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
654 (This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
655 WARN("control unavailable\n");
656 return DSERR_CONTROLUNAVAIL;
660 RtlAcquireResourceExclusive(&This->lock, TRUE);
662 if (This->volpan.lPan != pan) {
663 This->volpan.lPan = pan;
664 DSOUND_RecalcVolPan(&(This->volpan));
667 hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
669 WARN("IDsDriverBuffer_SetVolumePan failed\n");
673 RtlReleaseResource(&This->lock);
679 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
680 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
682 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
683 TRACE("(%p,%p)\n",This,pan);
685 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
686 WARN("control unavailable\n");
687 return DSERR_CONTROLUNAVAIL;
691 WARN("invalid parameter: pan = NULL\n");
692 return DSERR_INVALIDPARAM;
695 *pan = This->volpan.lPan;
700 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
701 LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
703 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface, *iter;
704 HRESULT hres = DS_OK;
706 TRACE("(%p,%p,%d,%p,%d)\n", This,p1,x1,p2,x2);
709 RtlAcquireResourceShared(&This->lock, TRUE);
711 if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
712 hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
714 WARN("IDsDriverBuffer_Unlock failed\n");
717 RtlReleaseResource(&This->lock);
723 if (!This->hwbuf && (x1 || x2))
725 RtlAcquireResourceShared(&This->device->buffer_list_lock, TRUE);
726 LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers, IDirectSoundBufferImpl, entry )
728 RtlAcquireResourceShared(&iter->lock, TRUE);
731 if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen)
732 hres = DSERR_INVALIDPARAM;
734 DSOUND_MixToTemporary(iter, (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory, x1, FALSE);
737 DSOUND_MixToTemporary(iter, 0, x2, FALSE);
738 RtlReleaseResource(&iter->lock);
740 RtlReleaseResource(&This->device->buffer_list_lock);
746 static HRESULT WINAPI IDirectSoundBufferImpl_Restore(
747 LPDIRECTSOUNDBUFFER8 iface
749 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
750 FIXME("(%p):stub\n",This);
754 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
755 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
757 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
758 TRACE("(%p,%p)\n",This,freq);
761 WARN("invalid parameter: freq = NULL\n");
762 return DSERR_INVALIDPARAM;
766 TRACE("-> %d\n", *freq);
771 static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(
772 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
774 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
777 FIXME("(%p,%u,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
780 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
782 WARN("control unavailable\n");
783 return DSERR_CONTROLUNAVAIL;
786 static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(
787 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
789 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
792 FIXME("(%p,%08u,%u,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
795 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
797 WARN("control unavailable\n");
798 return DSERR_CONTROLUNAVAIL;
801 static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(
802 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
804 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
806 FIXME("(%p,%s,%u,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
808 WARN("control unavailable\n");
809 return DSERR_CONTROLUNAVAIL;
812 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
813 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
815 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
816 WARN("(%p) already initialized\n", This);
817 return DSERR_ALREADYINITIALIZED;
820 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
821 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
823 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
824 TRACE("(%p)->(%p)\n",This,caps);
827 WARN("invalid parameter: caps == NULL\n");
828 return DSERR_INVALIDPARAM;
831 if (caps->dwSize < sizeof(*caps)) {
832 WARN("invalid parameter: caps->dwSize = %d\n",caps->dwSize);
833 return DSERR_INVALIDPARAM;
836 caps->dwFlags = This->dsbd.dwFlags;
837 if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
838 else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
840 caps->dwBufferBytes = This->buflen;
842 /* According to windows, this is zero*/
843 caps->dwUnlockTransferRate = 0;
844 caps->dwPlayCpuOverhead = 0;
849 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
850 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
852 IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
854 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
857 WARN("invalid parameter\n");
861 *ppobj = NULL; /* assume failure */
863 if ( IsEqualGUID(riid, &IID_IUnknown) ||
864 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
865 IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
866 if (!This->secondary)
867 SecondaryBufferImpl_Create(This, &(This->secondary));
868 if (This->secondary) {
869 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)This->secondary);
870 *ppobj = This->secondary;
873 WARN("IID_IDirectSoundBuffer\n");
874 return E_NOINTERFACE;
877 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
879 IDirectSoundNotifyImpl_Create(This, &(This->notify));
881 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
882 *ppobj = This->notify;
885 WARN("IID_IDirectSoundNotify\n");
886 return E_NOINTERFACE;
889 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
891 IDirectSound3DBufferImpl_Create(This, &(This->ds3db));
893 IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->ds3db);
894 *ppobj = This->ds3db;
897 WARN("IID_IDirectSound3DBuffer\n");
898 return E_NOINTERFACE;
901 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
902 ERR("app requested IDirectSound3DListener on secondary buffer\n");
903 return E_NOINTERFACE;
906 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
908 IKsBufferPropertySetImpl_Create(This, &(This->iks));
910 IKsPropertySet_AddRef((LPKSPROPERTYSET)This->iks);
914 WARN("IID_IKsPropertySet\n");
915 return E_NOINTERFACE;
918 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
920 return E_NOINTERFACE;
923 static const IDirectSoundBuffer8Vtbl dsbvt =
925 IDirectSoundBufferImpl_QueryInterface,
926 IDirectSoundBufferImpl_AddRef,
927 IDirectSoundBufferImpl_Release,
928 IDirectSoundBufferImpl_GetCaps,
929 IDirectSoundBufferImpl_GetCurrentPosition,
930 IDirectSoundBufferImpl_GetFormat,
931 IDirectSoundBufferImpl_GetVolume,
932 IDirectSoundBufferImpl_GetPan,
933 IDirectSoundBufferImpl_GetFrequency,
934 IDirectSoundBufferImpl_GetStatus,
935 IDirectSoundBufferImpl_Initialize,
936 IDirectSoundBufferImpl_Lock,
937 IDirectSoundBufferImpl_Play,
938 IDirectSoundBufferImpl_SetCurrentPosition,
939 IDirectSoundBufferImpl_SetFormat,
940 IDirectSoundBufferImpl_SetVolume,
941 IDirectSoundBufferImpl_SetPan,
942 IDirectSoundBufferImpl_SetFrequency,
943 IDirectSoundBufferImpl_Stop,
944 IDirectSoundBufferImpl_Unlock,
945 IDirectSoundBufferImpl_Restore,
946 IDirectSoundBufferImpl_SetFX,
947 IDirectSoundBufferImpl_AcquireResources,
948 IDirectSoundBufferImpl_GetObjectInPath
951 HRESULT IDirectSoundBufferImpl_Create(
952 DirectSoundDevice * device,
953 IDirectSoundBufferImpl **pdsb,
954 LPCDSBUFFERDESC dsbd)
956 IDirectSoundBufferImpl *dsb;
957 LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
960 int use_hw, alloc_size, cp_size;
961 TRACE("(%p,%p,%p)\n",device,pdsb,dsbd);
963 if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
964 WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd->dwBufferBytes);
966 return DSERR_INVALIDPARAM; /* FIXME: which error? */
969 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
972 WARN("out of memory\n");
974 return DSERR_OUTOFMEMORY;
977 TRACE("Created buffer at %p\n", dsb);
981 dsb->device = device;
982 dsb->lpVtbl = &dsbvt;
985 /* size depends on version */
986 CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
988 /* variable sized struct so calculate size based on format */
989 if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
990 alloc_size = sizeof(WAVEFORMATEX);
991 cp_size = sizeof(PCMWAVEFORMAT);
993 alloc_size = cp_size = sizeof(WAVEFORMATEX) + wfex->cbSize;
995 dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,alloc_size);
996 if (dsb->pwfx == NULL) {
997 WARN("out of memory\n");
998 HeapFree(GetProcessHeap(),0,dsb);
1000 return DSERR_OUTOFMEMORY;
1003 CopyMemory(dsb->pwfx, wfex, cp_size);
1005 if (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign)
1006 dsb->buflen = dsbd->dwBufferBytes +
1007 (dsbd->lpwfxFormat->nBlockAlign -
1008 (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign));
1010 dsb->buflen = dsbd->dwBufferBytes;
1012 dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
1014 dsb->notifies = NULL;
1015 dsb->nrofnotifies = 0;
1018 /* Check necessary hardware mixing capabilities */
1019 if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
1020 else capf |= DSCAPS_SECONDARYMONO;
1021 if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
1022 else capf |= DSCAPS_SECONDARY8BIT;
1024 use_hw = !!(dsbd->dwFlags & DSBCAPS_LOCHARDWARE);
1025 TRACE("use_hw = %d, capf = 0x%08x, device->drvcaps.dwFlags = 0x%08x\n", use_hw, capf, device->drvcaps.dwFlags);
1026 if (use_hw && ((device->drvcaps.dwFlags & capf) != capf || !device->driver))
1029 WARN("Format not supported for hardware buffer\n");
1030 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1031 HeapFree(GetProcessHeap(),0,dsb);
1033 if ((device->drvcaps.dwFlags & capf) != capf)
1034 return DSERR_BADFORMAT;
1035 return DSERR_GENERIC;
1038 /* FIXME: check hardware sample rate mixing capabilities */
1039 /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
1040 /* FIXME: check whether any hardware buffers are left */
1041 /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
1043 /* Allocate an empty buffer */
1044 dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
1045 if (dsb->buffer == NULL) {
1046 WARN("out of memory\n");
1047 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1048 HeapFree(GetProcessHeap(),0,dsb);
1050 return DSERR_OUTOFMEMORY;
1053 /* Allocate system memory for buffer if applicable */
1054 if ((device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
1055 dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
1056 if (dsb->buffer->memory == NULL) {
1057 WARN("out of memory\n");
1058 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1059 HeapFree(GetProcessHeap(),0,dsb->buffer);
1060 HeapFree(GetProcessHeap(),0,dsb);
1062 return DSERR_OUTOFMEMORY;
1066 /* Allocate the hardware buffer */
1068 err = IDsDriver_CreateSoundBuffer(device->driver,wfex,dsbd->dwFlags,0,
1069 &(dsb->buflen),&(dsb->buffer->memory),
1070 (LPVOID*)&(dsb->hwbuf));
1073 WARN("Failed to create hardware secondary buffer: %08x\n", err);
1074 if (device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY)
1075 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1076 HeapFree(GetProcessHeap(),0,dsb->buffer);
1077 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1078 HeapFree(GetProcessHeap(),0,dsb);
1080 return DSERR_GENERIC;
1084 dsb->buffer->ref = 1;
1085 list_init(&dsb->buffer->buffers);
1086 list_add_head(&dsb->buffer->buffers, &dsb->entry);
1087 FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);
1089 /* It's not necessary to initialize values to zero since */
1090 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1091 dsb->buf_mixpos = dsb->sec_mixpos = 0;
1092 dsb->state = STATE_STOPPED;
1094 dsb->freqAdjust = ((DWORD64)dsb->freq << DSOUND_FREQSHIFT) / device->pwfx->nSamplesPerSec;
1095 dsb->nAvgBytesPerSec = dsb->freq *
1096 dsbd->lpwfxFormat->nBlockAlign;
1098 /* calculate fragment size and write lead */
1099 DSOUND_RecalcFormat(dsb);
1101 if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
1102 dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
1103 dsb->ds3db_ds3db.vPosition.x = 0.0;
1104 dsb->ds3db_ds3db.vPosition.y = 0.0;
1105 dsb->ds3db_ds3db.vPosition.z = 0.0;
1106 dsb->ds3db_ds3db.vVelocity.x = 0.0;
1107 dsb->ds3db_ds3db.vVelocity.y = 0.0;
1108 dsb->ds3db_ds3db.vVelocity.z = 0.0;
1109 dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1110 dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1111 dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
1112 dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
1113 dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
1114 dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1115 dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1116 dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1117 dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
1119 dsb->ds3db_need_recalc = FALSE;
1120 DSOUND_Calc3DBuffer(dsb);
1122 DSOUND_RecalcVolPan(&(dsb->volpan));
1124 RtlInitializeResource(&dsb->lock);
1126 /* register buffer if not primary */
1127 if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
1128 err = DirectSoundDevice_AddBuffer(device, dsb);
1130 HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
1131 HeapFree(GetProcessHeap(),0,dsb->buffer);
1132 RtlDeleteResource(&dsb->lock);
1133 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1134 HeapFree(GetProcessHeap(),0,dsb);
1143 HRESULT IDirectSoundBufferImpl_Destroy(
1144 IDirectSoundBufferImpl *pdsb)
1146 TRACE("(%p)\n",pdsb);
1148 /* This keeps the *_Destroy functions from possibly deleting
1149 * this object until it is ready to be deleted */
1150 IDirectSoundBufferImpl_AddRef((LPDIRECTSOUNDBUFFER8)pdsb);
1153 WARN("iks not NULL\n");
1154 IKsBufferPropertySetImpl_Destroy(pdsb->iks);
1159 WARN("ds3db not NULL\n");
1160 IDirectSound3DBufferImpl_Destroy(pdsb->ds3db);
1165 WARN("notify not NULL\n");
1166 IDirectSoundNotifyImpl_Destroy(pdsb->notify);
1167 pdsb->notify = NULL;
1170 if (pdsb->secondary) {
1171 WARN("dsb not NULL\n");
1172 SecondaryBufferImpl_Destroy(pdsb->secondary);
1173 pdsb->secondary = NULL;
1176 while (IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);
1181 HRESULT IDirectSoundBufferImpl_Duplicate(
1182 DirectSoundDevice *device,
1183 IDirectSoundBufferImpl **ppdsb,
1184 IDirectSoundBufferImpl *pdsb)
1186 IDirectSoundBufferImpl *dsb;
1187 HRESULT hres = DS_OK;
1189 TRACE("(%p,%p,%p)\n", device, pdsb, pdsb);
1191 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
1194 WARN("out of memory\n");
1196 return DSERR_OUTOFMEMORY;
1199 CopyMemory(dsb, pdsb, sizeof(IDirectSoundBufferImpl));
1202 TRACE("duplicating hardware buffer\n");
1204 hres = IDsDriver_DuplicateSoundBuffer(device->driver, pdsb->hwbuf,
1205 (LPVOID *)&dsb->hwbuf);
1207 WARN("IDsDriver_DuplicateSoundBuffer failed (%08x)\n", hres);
1208 HeapFree(GetProcessHeap(),0,dsb);
1215 list_add_head(&dsb->buffer->buffers, &dsb->entry);
1217 dsb->state = STATE_STOPPED;
1218 dsb->buf_mixpos = dsb->sec_mixpos = 0;
1219 dsb->device = device;
1221 dsb->iks = NULL; /* FIXME? */
1222 dsb->secondary = NULL;
1223 dsb->tmp_buffer = NULL;
1224 DSOUND_RecalcFormat(dsb);
1225 DSOUND_MixToTemporary(dsb, 0, dsb->buflen, FALSE);
1227 /* variable sized struct so calculate size based on format */
1228 size = sizeof(WAVEFORMATEX) + pdsb->pwfx->cbSize;
1230 dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
1231 if (dsb->pwfx == NULL) {
1232 WARN("out of memory\n");
1233 HeapFree(GetProcessHeap(),0,dsb->buffer);
1234 HeapFree(GetProcessHeap(),0,dsb);
1236 return DSERR_OUTOFMEMORY;
1239 CopyMemory(dsb->pwfx, pdsb->pwfx, size);
1241 RtlInitializeResource(&dsb->lock);
1243 /* register buffer */
1244 hres = DirectSoundDevice_AddBuffer(device, dsb);
1245 if (hres != DS_OK) {
1246 RtlDeleteResource(&dsb->lock);
1247 HeapFree(GetProcessHeap(),0,dsb->tmp_buffer);
1248 HeapFree(GetProcessHeap(),0,dsb->buffer);
1249 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1250 HeapFree(GetProcessHeap(),0,dsb);
1258 /*******************************************************************************
1262 static HRESULT WINAPI SecondaryBufferImpl_QueryInterface(
1263 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj)
1265 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1266 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
1268 return IDirectSoundBufferImpl_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb,riid,ppobj);
1271 static ULONG WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
1273 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1274 ULONG ref = InterlockedIncrement(&(This->ref));
1275 TRACE("(%p) ref was %d\n", This, ref - 1);
1279 static ULONG WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
1281 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1283 TRACE("(%p)\n", This);
1284 ref = InterlockedDecrement(&(This->ref));
1285 TRACE("ref was %d\n", ref + 1);
1288 This->dsb->secondary = NULL;
1289 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
1290 HeapFree(GetProcessHeap(), 0, This);
1291 TRACE("(%p) released\n", This);
1296 static HRESULT WINAPI SecondaryBufferImpl_GetCaps(
1297 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps)
1299 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1300 TRACE("(%p)->(%p)\n",This,caps);
1302 return IDirectSoundBufferImpl_GetCaps((LPDIRECTSOUNDBUFFER8)This->dsb,caps);
1305 static HRESULT WINAPI SecondaryBufferImpl_GetCurrentPosition(
1306 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos)
1308 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1309 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
1311 return IDirectSoundBufferImpl_GetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,playpos,writepos);
1314 static HRESULT WINAPI SecondaryBufferImpl_GetFormat(
1315 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten)
1317 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1318 TRACE("(%p,%p,%d,%p)\n",This,lpwf,wfsize,wfwritten);
1320 return IDirectSoundBufferImpl_GetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,lpwf,wfsize,wfwritten);
1323 static HRESULT WINAPI SecondaryBufferImpl_GetVolume(
1324 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol)
1326 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1327 TRACE("(%p,%p)\n",This,vol);
1329 return IDirectSoundBufferImpl_GetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1332 static HRESULT WINAPI SecondaryBufferImpl_GetPan(
1333 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan)
1335 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1336 TRACE("(%p,%p)\n",This,pan);
1338 return IDirectSoundBufferImpl_GetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1341 static HRESULT WINAPI SecondaryBufferImpl_GetFrequency(
1342 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq)
1344 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1345 TRACE("(%p,%p)\n",This,freq);
1347 return IDirectSoundBufferImpl_GetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1350 static HRESULT WINAPI SecondaryBufferImpl_GetStatus(
1351 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status)
1353 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1354 TRACE("(%p,%p)\n",This,status);
1356 return IDirectSoundBufferImpl_GetStatus((LPDIRECTSOUNDBUFFER8)This->dsb,status);
1359 static HRESULT WINAPI SecondaryBufferImpl_Initialize(
1360 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd)
1362 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1363 TRACE("(%p,%p,%p)\n",This,dsound,dbsd);
1365 return IDirectSoundBufferImpl_Initialize((LPDIRECTSOUNDBUFFER8)This->dsb,dsound,dbsd);
1368 static HRESULT WINAPI SecondaryBufferImpl_Lock(
1369 LPDIRECTSOUNDBUFFER8 iface,
1372 LPVOID *lplpaudioptr1,
1373 LPDWORD audiobytes1,
1374 LPVOID *lplpaudioptr2,
1375 LPDWORD audiobytes2,
1378 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1379 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x)\n",
1380 This,writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1382 return IDirectSoundBufferImpl_Lock((LPDIRECTSOUNDBUFFER8)This->dsb,
1383 writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
1386 static HRESULT WINAPI SecondaryBufferImpl_Play(
1387 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags)
1389 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1390 TRACE("(%p,%08x,%08x,%08x)\n",This,reserved1,reserved2,flags);
1392 return IDirectSoundBufferImpl_Play((LPDIRECTSOUNDBUFFER8)This->dsb,reserved1,reserved2,flags);
1395 static HRESULT WINAPI SecondaryBufferImpl_SetCurrentPosition(
1396 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos)
1398 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1399 TRACE("(%p,%d)\n",This,newpos);
1401 return IDirectSoundBufferImpl_SetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,newpos);
1404 static HRESULT WINAPI SecondaryBufferImpl_SetFormat(
1405 LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex)
1407 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1408 TRACE("(%p,%p)\n",This,wfex);
1410 return IDirectSoundBufferImpl_SetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,wfex);
1413 static HRESULT WINAPI SecondaryBufferImpl_SetVolume(
1414 LPDIRECTSOUNDBUFFER8 iface,LONG vol)
1416 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1417 TRACE("(%p,%d)\n",This,vol);
1419 return IDirectSoundBufferImpl_SetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
1422 static HRESULT WINAPI SecondaryBufferImpl_SetPan(
1423 LPDIRECTSOUNDBUFFER8 iface,LONG pan)
1425 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1426 TRACE("(%p,%d)\n",This,pan);
1428 return IDirectSoundBufferImpl_SetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
1431 static HRESULT WINAPI SecondaryBufferImpl_SetFrequency(
1432 LPDIRECTSOUNDBUFFER8 iface,DWORD freq)
1434 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1435 TRACE("(%p,%d)\n",This,freq);
1437 return IDirectSoundBufferImpl_SetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
1440 static HRESULT WINAPI SecondaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
1442 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1443 TRACE("(%p)\n",This);
1445 return IDirectSoundBufferImpl_Stop((LPDIRECTSOUNDBUFFER8)This->dsb);
1448 static HRESULT WINAPI SecondaryBufferImpl_Unlock(
1449 LPDIRECTSOUNDBUFFER8 iface,
1450 LPVOID lpvAudioPtr1,
1451 DWORD dwAudioBytes1,
1452 LPVOID lpvAudioPtr2,
1453 DWORD dwAudioBytes2)
1455 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1456 TRACE("(%p,%p,%d,%p,%d)\n",
1457 This, lpvAudioPtr1, dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1459 return IDirectSoundBufferImpl_Unlock((LPDIRECTSOUNDBUFFER8)This->dsb,
1460 lpvAudioPtr1,dwAudioBytes1,lpvAudioPtr2,dwAudioBytes2);
1463 static HRESULT WINAPI SecondaryBufferImpl_Restore(
1464 LPDIRECTSOUNDBUFFER8 iface)
1466 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1467 TRACE("(%p)\n",This);
1469 return IDirectSoundBufferImpl_Restore((LPDIRECTSOUNDBUFFER8)This->dsb);
1472 static HRESULT WINAPI SecondaryBufferImpl_SetFX(
1473 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes)
1475 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1476 TRACE("(%p,%u,%p,%p)\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1478 return IDirectSoundBufferImpl_SetFX((LPDIRECTSOUNDBUFFER8)This->dsb,dwEffectsCount,pDSFXDesc,pdwResultCodes);
1481 static HRESULT WINAPI SecondaryBufferImpl_AcquireResources(
1482 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes)
1484 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1485 TRACE("(%p,%08u,%u,%p)\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
1487 return IDirectSoundBufferImpl_AcquireResources((LPDIRECTSOUNDBUFFER8)This->dsb,dwFlags,dwEffectsCount,pdwResultCodes);
1490 static HRESULT WINAPI SecondaryBufferImpl_GetObjectInPath(
1491 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject)
1493 SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
1494 TRACE("(%p,%s,%u,%s,%p)\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
1496 return IDirectSoundBufferImpl_GetObjectInPath((LPDIRECTSOUNDBUFFER8)This->dsb,rguidObject,dwIndex,rguidInterface,ppObject);
1499 static const IDirectSoundBuffer8Vtbl sbvt =
1501 SecondaryBufferImpl_QueryInterface,
1502 SecondaryBufferImpl_AddRef,
1503 SecondaryBufferImpl_Release,
1504 SecondaryBufferImpl_GetCaps,
1505 SecondaryBufferImpl_GetCurrentPosition,
1506 SecondaryBufferImpl_GetFormat,
1507 SecondaryBufferImpl_GetVolume,
1508 SecondaryBufferImpl_GetPan,
1509 SecondaryBufferImpl_GetFrequency,
1510 SecondaryBufferImpl_GetStatus,
1511 SecondaryBufferImpl_Initialize,
1512 SecondaryBufferImpl_Lock,
1513 SecondaryBufferImpl_Play,
1514 SecondaryBufferImpl_SetCurrentPosition,
1515 SecondaryBufferImpl_SetFormat,
1516 SecondaryBufferImpl_SetVolume,
1517 SecondaryBufferImpl_SetPan,
1518 SecondaryBufferImpl_SetFrequency,
1519 SecondaryBufferImpl_Stop,
1520 SecondaryBufferImpl_Unlock,
1521 SecondaryBufferImpl_Restore,
1522 SecondaryBufferImpl_SetFX,
1523 SecondaryBufferImpl_AcquireResources,
1524 SecondaryBufferImpl_GetObjectInPath
1527 HRESULT SecondaryBufferImpl_Create(
1528 IDirectSoundBufferImpl *dsb,
1529 SecondaryBufferImpl **psb)
1531 SecondaryBufferImpl *sb;
1532 TRACE("(%p,%p)\n",dsb,psb);
1534 sb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*sb));
1537 WARN("out of memory\n");
1539 return DSERR_OUTOFMEMORY;
1545 IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
1550 static HRESULT SecondaryBufferImpl_Destroy(
1551 SecondaryBufferImpl *pdsb)
1553 TRACE("(%p)\n",pdsb);
1555 while (SecondaryBufferImpl_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);