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
31 #include "wine/debug.h"
33 #include "dsound_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
38 /*******************************************************************************
42 static inline struct IDirectSoundBufferImpl
*impl_from_IDirectSoundNotify(IDirectSoundNotify
*iface
)
44 return CONTAINING_RECORD(iface
, struct IDirectSoundBufferImpl
, IDirectSoundNotify_iface
);
47 static HRESULT WINAPI
IDirectSoundNotifyImpl_QueryInterface(IDirectSoundNotify
*iface
, REFIID riid
,
50 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundNotify(iface
);
52 TRACE("(%p,%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
54 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
57 static ULONG WINAPI
IDirectSoundNotifyImpl_AddRef(IDirectSoundNotify
*iface
)
59 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundNotify(iface
);
60 ULONG ref
= InterlockedIncrement(&This
->refn
);
62 TRACE("(%p) ref %ld\n", This
, ref
);
65 InterlockedIncrement(&This
->numIfaces
);
70 static ULONG WINAPI
IDirectSoundNotifyImpl_Release(IDirectSoundNotify
*iface
)
72 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundNotify(iface
);
73 ULONG ref
= InterlockedDecrement(&This
->refn
);
75 TRACE("(%p) ref %ld\n", This
, ref
);
77 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
78 secondarybuffer_destroy(This
);
83 static int __cdecl
notify_compar(const void *l
, const void *r
)
85 const DSBPOSITIONNOTIFY
*left
= l
;
86 const DSBPOSITIONNOTIFY
*right
= r
;
88 /* place DSBPN_OFFSETSTOP at the start of the sorted array */
89 if(left
->dwOffset
== DSBPN_OFFSETSTOP
){
90 if(right
->dwOffset
!= DSBPN_OFFSETSTOP
)
92 }else if(right
->dwOffset
== DSBPN_OFFSETSTOP
)
95 if(left
->dwOffset
== right
->dwOffset
)
98 if(left
->dwOffset
< right
->dwOffset
)
104 static void commit_next_chunk(IDirectSoundBufferImpl
*dsb
)
106 void *dstbuff
= dsb
->committedbuff
, *srcbuff
= dsb
->buffer
->memory
;
107 DWORD srcoff
= dsb
->sec_mixpos
, srcsize
= dsb
->buflen
, cpysize
= dsb
->writelead
;
109 if(dsb
->state
!= STATE_PLAYING
)
112 if(cpysize
> srcsize
- srcoff
) {
113 DWORD overflow
= cpysize
- (srcsize
- srcoff
);
114 memcpy(dstbuff
, (BYTE
*)srcbuff
+ srcoff
, srcsize
- srcoff
);
115 memcpy((BYTE
*)dstbuff
+ (srcsize
- srcoff
), srcbuff
, overflow
);
117 memcpy(dstbuff
, (BYTE
*)srcbuff
+ srcoff
, cpysize
);
120 dsb
->use_committed
= TRUE
;
121 dsb
->committed_mixpos
= 0;
122 TRACE("committing %lu bytes from offset %lu\n", dsb
->writelead
, dsb
->sec_mixpos
);
125 static HRESULT WINAPI
IDirectSoundNotifyImpl_SetNotificationPositions(IDirectSoundNotify
*iface
,
126 DWORD howmuch
, const DSBPOSITIONNOTIFY
*notify
)
128 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundNotify(iface
);
130 TRACE("(%p,0x%08lx,%p)\n",This
,howmuch
,notify
);
132 if (howmuch
> 0 && notify
== NULL
) {
133 WARN("invalid parameter: notify == NULL\n");
134 return DSERR_INVALIDPARAM
;
137 if (TRACE_ON(dsound
)) {
139 for (i
=0;i
<howmuch
;i
++)
140 TRACE("notify at %ld to %p\n",
141 notify
[i
].dwOffset
,notify
[i
].hEventNotify
);
145 /* Make an internal copy of the caller-supplied array.
146 * Replace the existing copy if one is already present. */
147 free(This
->notifies
);
148 This
->notifies
= malloc(howmuch
* sizeof(DSBPOSITIONNOTIFY
));
150 if (This
->notifies
== NULL
) {
151 WARN("out of memory\n");
152 return DSERR_OUTOFMEMORY
;
154 CopyMemory(This
->notifies
, notify
, howmuch
* sizeof(DSBPOSITIONNOTIFY
));
155 This
->nrofnotifies
= howmuch
;
156 qsort(This
->notifies
, howmuch
, sizeof(DSBPOSITIONNOTIFY
), notify_compar
);
158 free(This
->notifies
);
159 This
->notifies
= NULL
;
160 This
->nrofnotifies
= 0;
166 static const IDirectSoundNotifyVtbl dsnvt
=
168 IDirectSoundNotifyImpl_QueryInterface
,
169 IDirectSoundNotifyImpl_AddRef
,
170 IDirectSoundNotifyImpl_Release
,
171 IDirectSoundNotifyImpl_SetNotificationPositions
,
174 /*******************************************************************************
178 static inline IDirectSoundBufferImpl
*impl_from_IDirectSoundBuffer8(IDirectSoundBuffer8
*iface
)
180 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSoundBuffer8_iface
);
183 static inline BOOL
is_primary_buffer(IDirectSoundBufferImpl
*This
)
185 return (This
->dsbd
.dwFlags
& DSBCAPS_PRIMARYBUFFER
) != 0;
188 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFormat(IDirectSoundBuffer8
*iface
,
189 LPCWAVEFORMATEX wfex
)
191 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
193 TRACE("(%p,%p)\n", iface
, wfex
);
195 if (is_primary_buffer(This
))
196 return primarybuffer_SetFormat(This
->device
, wfex
);
198 WARN("not available for secondary buffers.\n");
199 return DSERR_INVALIDCALL
;
203 static HRESULT WINAPI
IDirectSoundBufferImpl_SetVolume(IDirectSoundBuffer8
*iface
, LONG vol
)
205 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
208 HRESULT hres
= DS_OK
;
210 TRACE("(%p,%ld)\n",This
,vol
);
212 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
213 WARN("control unavailable: This->dsbd.dwFlags = 0x%08lx\n", This
->dsbd
.dwFlags
);
214 return DSERR_CONTROLUNAVAIL
;
217 if ((vol
> DSBVOLUME_MAX
) || (vol
< DSBVOLUME_MIN
)) {
218 WARN("invalid parameter: vol = %ld\n", vol
);
219 return DSERR_INVALIDPARAM
;
222 AcquireSRWLockExclusive(&This
->lock
);
224 if (This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) {
225 oldVol
= This
->ds3db_lVolume
;
226 This
->ds3db_lVolume
= vol
;
228 /* recalc 3d volume, which in turn recalcs the pans */
229 DSOUND_Calc3DBuffer(This
);
231 oldVol
= This
->volpan
.lVolume
;
232 This
->volpan
.lVolume
= vol
;
234 DSOUND_RecalcVolPan(&(This
->volpan
));
237 ReleaseSRWLockExclusive(&This
->lock
);
242 static HRESULT WINAPI
IDirectSoundBufferImpl_GetVolume(IDirectSoundBuffer8
*iface
, LONG
*vol
)
244 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
246 TRACE("(%p,%p)\n",This
,vol
);
248 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
249 WARN("control unavailable\n");
250 return DSERR_CONTROLUNAVAIL
;
254 WARN("invalid parameter: vol == NULL\n");
255 return DSERR_INVALIDPARAM
;
258 *vol
= This
->volpan
.lVolume
;
263 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8
*iface
, DWORD freq
)
265 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
268 TRACE("(%p,%ld)\n",This
,freq
);
270 if (is_primary_buffer(This
)) {
271 WARN("not available for primary buffers.\n");
272 return DSERR_CONTROLUNAVAIL
;
275 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLFREQUENCY
)) {
276 WARN("control unavailable\n");
277 return DSERR_CONTROLUNAVAIL
;
280 if (freq
== DSBFREQUENCY_ORIGINAL
)
281 freq
= This
->pwfx
->nSamplesPerSec
;
283 if ((freq
< DSBFREQUENCY_MIN
) || (freq
> DSBFREQUENCY_MAX
)) {
284 WARN("invalid parameter: freq = %ld\n", freq
);
285 return DSERR_INVALIDPARAM
;
288 AcquireSRWLockExclusive(&This
->lock
);
290 if (This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) {
291 oldFreq
= This
->ds3db_freq
;
292 This
->ds3db_freq
= freq
;
294 DSOUND_Calc3DBuffer(This
);
296 oldFreq
= This
->freq
;
299 DSOUND_RecalcFormat(This
);
302 ReleaseSRWLockExclusive(&This
->lock
);
307 static HRESULT WINAPI
IDirectSoundBufferImpl_Play(IDirectSoundBuffer8
*iface
, DWORD reserved1
,
308 DWORD reserved2
, DWORD flags
)
310 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
311 HRESULT hres
= DS_OK
;
314 TRACE("(%p,%08lx,%08lx,%08lx)\n",This
,reserved1
,reserved2
,flags
);
316 AcquireSRWLockExclusive(&This
->lock
);
318 This
->playflags
= flags
;
319 if (This
->state
== STATE_STOPPED
) {
321 This
->state
= STATE_STARTING
;
324 for (i
= 0; i
< This
->num_filters
; i
++) {
325 IMediaObject_Discontinuity(This
->filters
[i
].obj
, 0);
328 ReleaseSRWLockExclusive(&This
->lock
);
333 static HRESULT WINAPI
IDirectSoundBufferImpl_Stop(IDirectSoundBuffer8
*iface
)
335 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
336 HRESULT hres
= DS_OK
;
338 TRACE("(%p)\n",This
);
340 AcquireSRWLockExclusive(&This
->lock
);
342 if (This
->state
== STATE_PLAYING
|| This
->state
== STATE_STARTING
)
344 This
->state
= STATE_STOPPED
;
345 This
->use_committed
= FALSE
;
346 This
->committed_mixpos
= 0;
347 DSOUND_CheckEvent(This
, 0, 0);
350 ReleaseSRWLockExclusive(&This
->lock
);
355 static ULONG WINAPI
IDirectSoundBufferImpl_AddRef(IDirectSoundBuffer8
*iface
)
357 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
358 ULONG ref
= InterlockedIncrement(&This
->ref
);
360 TRACE("(%p) ref %ld\n", This
, ref
);
363 InterlockedIncrement(&This
->numIfaces
);
368 static ULONG WINAPI
IDirectSoundBufferImpl_Release(IDirectSoundBuffer8
*iface
)
370 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
373 if (is_primary_buffer(This
)){
374 ref
= capped_refcount_dec(&This
->ref
);
376 capped_refcount_dec(&This
->numIfaces
);
377 TRACE("(%p) ref %ld\n", This
, ref
);
381 ref
= InterlockedDecrement(&This
->ref
);
382 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
383 secondarybuffer_destroy(This
);
385 TRACE("(%p) ref %ld\n", This
, ref
);
390 static HRESULT WINAPI
IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuffer8
*iface
,
391 DWORD
*playpos
, DWORD
*writepos
)
393 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
396 TRACE("(%p,%p,%p)\n",This
,playpos
,writepos
);
398 AcquireSRWLockShared(&This
->lock
);
400 pos
= This
->sec_mixpos
;
403 if (pos
>= This
->buflen
){
404 FIXME("Bad play position. playpos: %ld, buflen: %ld\n", pos
, This
->buflen
);
413 if (writepos
&& This
->state
!= STATE_STOPPED
) {
414 /* apply the documented 10ms lead to writepos */
415 *writepos
+= This
->writelead
;
416 *writepos
%= This
->buflen
;
419 ReleaseSRWLockShared(&This
->lock
);
421 TRACE("playpos = %ld, writepos = %ld, buflen=%ld (%p, time=%ld)\n",
422 playpos
?*playpos
:-1, writepos
?*writepos
:-1, This
->buflen
, This
, GetTickCount());
427 static HRESULT WINAPI
IDirectSoundBufferImpl_GetStatus(IDirectSoundBuffer8
*iface
, DWORD
*status
)
429 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
431 TRACE("(%p,%p)\n",This
,status
);
433 if (status
== NULL
) {
434 WARN("invalid parameter: status = NULL\n");
435 return DSERR_INVALIDPARAM
;
439 AcquireSRWLockShared(&This
->lock
);
440 if ((This
->state
== STATE_STARTING
) || (This
->state
== STATE_PLAYING
)) {
441 *status
|= DSBSTATUS_PLAYING
;
442 if (This
->playflags
& DSBPLAY_LOOPING
)
443 *status
|= DSBSTATUS_LOOPING
;
445 if (This
->dsbd
.dwFlags
& DSBCAPS_LOCDEFER
)
446 *status
|= DSBSTATUS_LOCSOFTWARE
;
447 ReleaseSRWLockShared(&This
->lock
);
449 TRACE("status=%lx\n", *status
);
454 static HRESULT WINAPI
IDirectSoundBufferImpl_GetFormat(IDirectSoundBuffer8
*iface
,
455 LPWAVEFORMATEX lpwf
, DWORD wfsize
, DWORD
*wfwritten
)
457 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
460 TRACE("(%p,%p,%ld,%p)\n",This
,lpwf
,wfsize
,wfwritten
);
462 size
= sizeof(WAVEFORMATEX
) + This
->pwfx
->cbSize
;
464 if (lpwf
) { /* NULL is valid */
465 if (wfsize
>= size
) {
466 CopyMemory(lpwf
,This
->pwfx
,size
);
470 WARN("invalid parameter: wfsize too small\n");
471 CopyMemory(lpwf
,This
->pwfx
,wfsize
);
474 return DSERR_INVALIDPARAM
;
478 *wfwritten
= sizeof(WAVEFORMATEX
) + This
->pwfx
->cbSize
;
480 WARN("invalid parameter: wfwritten == NULL\n");
481 return DSERR_INVALIDPARAM
;
488 static HRESULT WINAPI
IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8
*iface
, DWORD writecursor
,
489 DWORD writebytes
, void **lplpaudioptr1
, DWORD
*audiobytes1
, void **lplpaudioptr2
,
490 DWORD
*audiobytes2
, DWORD flags
)
492 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
493 HRESULT hres
= DS_OK
;
495 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n", This
, writecursor
, writebytes
, lplpaudioptr1
,
496 audiobytes1
, lplpaudioptr2
, audiobytes2
, flags
, GetTickCount());
499 return DSERR_INVALIDPARAM
;
501 /* when this flag is set, writecursor is meaningless and must be calculated */
502 if (flags
& DSBLOCK_FROMWRITECURSOR
) {
503 /* GetCurrentPosition does too much magic to duplicate here */
504 hres
= IDirectSoundBufferImpl_GetCurrentPosition(iface
, NULL
, &writecursor
);
506 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
511 /* when this flag is set, writebytes is meaningless and must be set */
512 if (flags
& DSBLOCK_ENTIREBUFFER
)
513 writebytes
= This
->buflen
;
515 if (writecursor
>= This
->buflen
) {
516 WARN("Invalid parameter, writecursor: %lu >= buflen: %lu\n",
517 writecursor
, This
->buflen
);
518 return DSERR_INVALIDPARAM
;
521 if (writebytes
> This
->buflen
) {
522 WARN("Invalid parameter, writebytes: %lu > buflen: %lu\n",
523 writebytes
, This
->buflen
);
524 return DSERR_INVALIDPARAM
;
527 AcquireSRWLockShared(&This
->lock
);
529 if (writecursor
+writebytes
<= This
->buflen
) {
530 *(LPBYTE
*)lplpaudioptr1
= This
->buffer
->memory
+writecursor
;
531 if (This
->sec_mixpos
>= writecursor
&& This
->sec_mixpos
< writecursor
+ writebytes
&& This
->state
== STATE_PLAYING
) {
532 WARN("Overwriting mixing position, case 1\n");
533 commit_next_chunk(This
);
535 *audiobytes1
= writebytes
;
537 *(LPBYTE
*)lplpaudioptr2
= NULL
;
540 TRACE("Locked %p(%li bytes) and %p(%li bytes) writecursor=%ld\n",
541 *(LPBYTE
*)lplpaudioptr1
, *audiobytes1
, lplpaudioptr2
? *(LPBYTE
*)lplpaudioptr2
: NULL
, audiobytes2
? *audiobytes2
: 0, writecursor
);
542 TRACE("->%ld.0\n",writebytes
);
543 This
->buffer
->lockedbytes
+= writebytes
;
545 DWORD remainder
= writebytes
+ writecursor
- This
->buflen
;
546 *(LPBYTE
*)lplpaudioptr1
= This
->buffer
->memory
+writecursor
;
547 *audiobytes1
= This
->buflen
-writecursor
;
548 This
->buffer
->lockedbytes
+= *audiobytes1
;
549 if (This
->sec_mixpos
>= writecursor
&& This
->sec_mixpos
< writecursor
+ writebytes
&& This
->state
== STATE_PLAYING
) {
550 WARN("Overwriting mixing position, case 2\n");
551 commit_next_chunk(This
);
554 *(LPBYTE
*)lplpaudioptr2
= This
->buffer
->memory
;
556 *audiobytes2
= writebytes
-(This
->buflen
-writecursor
);
557 This
->buffer
->lockedbytes
+= *audiobytes2
;
559 if (audiobytes2
&& This
->sec_mixpos
< remainder
&& This
->state
== STATE_PLAYING
) {
560 WARN("Overwriting mixing position, case 3\n");
561 commit_next_chunk(This
);
563 TRACE("Locked %p(%li bytes) and %p(%li bytes) writecursor=%ld\n", *(LPBYTE
*)lplpaudioptr1
, *audiobytes1
, lplpaudioptr2
? *(LPBYTE
*)lplpaudioptr2
: NULL
, audiobytes2
? *audiobytes2
: 0, writecursor
);
566 ReleaseSRWLockShared(&This
->lock
);
571 static HRESULT WINAPI
IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuffer8
*iface
,
574 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
575 HRESULT hres
= DS_OK
;
577 TRACE("(%p,%ld)\n",This
,newpos
);
579 AcquireSRWLockExclusive(&This
->lock
);
581 /* start mixing from this new location instead */
582 newpos
%= This
->buflen
;
583 newpos
-= newpos
%This
->pwfx
->nBlockAlign
;
584 This
->sec_mixpos
= newpos
;
586 This
->use_committed
= FALSE
;
587 This
->committed_mixpos
= 0;
589 /* at this point, do not attempt to reset buffers, mess with primary mix position,
590 or anything like that to reduce latency. The data already prebuffered cannot be changed */
592 ReleaseSRWLockExclusive(&This
->lock
);
597 static HRESULT WINAPI
IDirectSoundBufferImpl_SetPan(IDirectSoundBuffer8
*iface
, LONG pan
)
599 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
600 HRESULT hres
= DS_OK
;
602 TRACE("(%p,%ld)\n",This
,pan
);
604 if ((pan
> DSBPAN_RIGHT
) || (pan
< DSBPAN_LEFT
)) {
605 WARN("invalid parameter: pan = %ld\n", pan
);
606 return DSERR_INVALIDPARAM
;
609 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
610 WARN("control unavailable\n");
611 return DSERR_CONTROLUNAVAIL
;
614 AcquireSRWLockExclusive(&This
->lock
);
616 if (This
->volpan
.lPan
!= pan
) {
617 This
->volpan
.lPan
= pan
;
618 DSOUND_RecalcVolPan(&(This
->volpan
));
621 ReleaseSRWLockExclusive(&This
->lock
);
626 static HRESULT WINAPI
IDirectSoundBufferImpl_GetPan(IDirectSoundBuffer8
*iface
, LONG
*pan
)
628 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
630 TRACE("(%p,%p)\n",This
,pan
);
632 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
633 WARN("control unavailable\n");
634 return DSERR_CONTROLUNAVAIL
;
638 WARN("invalid parameter: pan = NULL\n");
639 return DSERR_INVALIDPARAM
;
642 *pan
= This
->volpan
.lPan
;
647 static HRESULT WINAPI
IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8
*iface
, void *p1
, DWORD x1
,
650 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
), *iter
;
651 HRESULT hres
= DS_OK
;
653 TRACE("(%p,%p,%ld,%p,%ld)\n", This
,p1
,x1
,p2
,x2
);
658 if((p1
&& ((BYTE
*)p1
< This
->buffer
->memory
|| (BYTE
*)p1
>= This
->buffer
->memory
+ This
->buflen
)) ||
659 (p2
&& ((BYTE
*)p2
< This
->buffer
->memory
|| (BYTE
*)p2
>= This
->buffer
->memory
+ This
->buflen
)))
660 return DSERR_INVALIDPARAM
;
664 AcquireSRWLockShared(&This
->device
->buffer_list_lock
);
665 LIST_FOR_EACH_ENTRY(iter
, &This
->buffer
->buffers
, IDirectSoundBufferImpl
, entry
)
667 AcquireSRWLockShared(&iter
->lock
);
670 if(x1
+ (DWORD_PTR
)p1
- (DWORD_PTR
)iter
->buffer
->memory
> iter
->buflen
)
671 hres
= DSERR_INVALIDPARAM
;
673 iter
->buffer
->lockedbytes
-= x1
;
678 if(x2
+ (DWORD_PTR
)p2
- (DWORD_PTR
)iter
->buffer
->memory
> iter
->buflen
)
679 hres
= DSERR_INVALIDPARAM
;
681 iter
->buffer
->lockedbytes
-= x2
;
683 ReleaseSRWLockShared(&iter
->lock
);
685 ReleaseSRWLockShared(&This
->device
->buffer_list_lock
);
691 static HRESULT WINAPI
IDirectSoundBufferImpl_Restore(IDirectSoundBuffer8
*iface
)
693 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
695 FIXME("(%p):stub\n",This
);
699 static HRESULT WINAPI
IDirectSoundBufferImpl_GetFrequency(IDirectSoundBuffer8
*iface
, DWORD
*freq
)
701 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
703 TRACE("(%p,%p)\n",This
,freq
);
706 WARN("invalid parameter: freq = NULL\n");
707 return DSERR_INVALIDPARAM
;
710 *freq
= (This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) ? This
->ds3db_freq
: This
->freq
;
711 TRACE("-> %ld\n", *freq
);
716 static const char* dump_DSFX_guid(const DSEFFECTDESC
*desc
)
718 #define FE(guid) if (IsEqualGUID(&guid, &desc->guidDSFXClass)) return #guid
719 FE(GUID_DSFX_STANDARD_GARGLE
);
720 FE(GUID_DSFX_STANDARD_CHORUS
);
721 FE(GUID_DSFX_STANDARD_FLANGER
);
722 FE(GUID_DSFX_STANDARD_ECHO
);
723 FE(GUID_DSFX_STANDARD_DISTORTION
);
724 FE(GUID_DSFX_STANDARD_COMPRESSOR
);
725 FE(GUID_DSFX_STANDARD_PARAMEQ
);
726 FE(GUID_DSFX_STANDARD_I3DL2REVERB
);
727 FE(GUID_DSFX_WAVES_REVERB
);
730 return debugstr_guid(&desc
->guidDSFXClass
);
733 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFX(IDirectSoundBuffer8
*iface
, DWORD dwEffectsCount
,
734 LPDSEFFECTDESC pDSFXDesc
, DWORD
*pdwResultCodes
)
736 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
743 TRACE("(%p,%lu,%p,%p)\n", This
, dwEffectsCount
, pDSFXDesc
, pdwResultCodes
);
746 for (u
=0; u
<dwEffectsCount
; u
++) pdwResultCodes
[u
] = DSFXR_UNKNOWN
;
748 if ((dwEffectsCount
> 0 && !pDSFXDesc
) ||
749 (dwEffectsCount
== 0 && (pDSFXDesc
|| pdwResultCodes
))
753 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLFX
)) {
754 WARN("attempted to call SetFX on buffer without DSBCAPS_CTRLFX\n");
755 return DSERR_CONTROLUNAVAIL
;
758 if (This
->state
!= STATE_STOPPED
)
759 return DSERR_INVALIDCALL
;
761 if (This
->buffer
->lockedbytes
> 0)
762 return DSERR_INVALIDCALL
;
764 if (dwEffectsCount
== 0) {
765 if (This
->num_filters
> 0) {
766 for (u
= 0; u
< This
->num_filters
; u
++) {
767 IMediaObject_Release(This
->filters
[u
].obj
);
771 This
->filters
= NULL
;
772 This
->num_filters
= 0;
778 filters
= malloc(dwEffectsCount
* sizeof(DSFilter
));
780 WARN("out of memory\n");
781 return DSERR_OUTOFMEMORY
;
786 wfx
.wFormatTag
= WAVE_FORMAT_IEEE_FLOAT
;
787 wfx
.nChannels
= This
->pwfx
->nChannels
;
788 wfx
.nSamplesPerSec
= This
->pwfx
->nSamplesPerSec
;
789 wfx
.wBitsPerSample
= sizeof(float) * 8;
790 wfx
.nBlockAlign
= (wfx
.nChannels
* wfx
.wBitsPerSample
)/8;
791 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
792 wfx
.cbSize
= sizeof(wfx
);
794 dmt
.majortype
= KSDATAFORMAT_TYPE_AUDIO
;
795 dmt
.subtype
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
796 dmt
.bFixedSizeSamples
= TRUE
;
797 dmt
.bTemporalCompression
= FALSE
;
798 dmt
.lSampleSize
= sizeof(float) * This
->pwfx
->nChannels
/ 8;
799 dmt
.formattype
= FORMAT_WaveFormatEx
;
801 dmt
.cbFormat
= sizeof(WAVEFORMATEX
);
802 dmt
.pbFormat
= (BYTE
*)&wfx
;
804 for (u
= 0; u
< dwEffectsCount
; u
++) {
805 TRACE("%ld: 0x%08lx, %s\n", u
, pDSFXDesc
[u
].dwFlags
, dump_DSFX_guid(&pDSFXDesc
[u
]));
807 hr2
= CoCreateInstance(&pDSFXDesc
[u
].guidDSFXClass
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMediaObject
, (LPVOID
*)&filters
[u
].obj
);
809 if (SUCCEEDED(hr2
)) {
810 hr2
= IMediaObject_SetInputType(filters
[u
].obj
, 0, &dmt
, 0);
812 WARN("Could not set DMO input type\n");
815 if (SUCCEEDED(hr2
)) {
816 hr2
= IMediaObject_SetOutputType(filters
[u
].obj
, 0, &dmt
, 0);
818 WARN("Could not set DMO output type\n");
826 pdwResultCodes
[u
] = (hr2
== REGDB_E_CLASSNOTREG
) ? DSFXR_UNKNOWN
: DSFXR_FAILED
;
829 pdwResultCodes
[u
] = DSFXR_LOCSOFTWARE
;
834 for (u
= 0; u
< dwEffectsCount
; u
++) {
836 pdwResultCodes
[u
] = (pdwResultCodes
[u
] != DSFXR_UNKNOWN
) ? DSFXR_PRESENT
: DSFXR_UNKNOWN
;
839 IMediaObject_Release(filters
[u
].obj
);
844 if (This
->num_filters
> 0) {
845 for (u
= 0; u
< This
->num_filters
; u
++) {
846 IMediaObject_Release(This
->filters
[u
].obj
);
847 if (This
->filters
[u
].inplace
) IMediaObjectInPlace_Release(This
->filters
[u
].inplace
);
852 for (u
= 0; u
< dwEffectsCount
; u
++) {
853 memcpy(&filters
[u
].guid
, &pDSFXDesc
[u
].guidDSFXClass
, sizeof(GUID
));
854 if (FAILED(IMediaObject_QueryInterface(filters
[u
].obj
, &IID_IMediaObjectInPlace
, (void*)&filters
[u
].inplace
)))
855 filters
[u
].inplace
= NULL
;
858 This
->filters
= filters
;
859 This
->num_filters
= dwEffectsCount
;
865 static HRESULT WINAPI
IDirectSoundBufferImpl_AcquireResources(IDirectSoundBuffer8
*iface
,
866 DWORD dwFlags
, DWORD dwEffectsCount
, DWORD
*pdwResultCodes
)
868 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
871 FIXME("(%p,%08lu,%lu,%p): stub, faking success\n",This
,dwFlags
,dwEffectsCount
,pdwResultCodes
);
874 for (u
=0; u
<dwEffectsCount
; u
++) pdwResultCodes
[u
] = DSFXR_UNKNOWN
;
876 WARN("control unavailable\n");
880 static HRESULT WINAPI
IDirectSoundBufferImpl_GetObjectInPath(IDirectSoundBuffer8
*iface
,
881 REFGUID clsid
, DWORD index
, REFGUID iid
, void **out
)
883 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
886 TRACE("(%p,%s,%lu,%s,%p)\n", This
, debugstr_guid(clsid
), index
, debugstr_guid(iid
), out
);
891 for (i
= 0; i
< This
->num_filters
; i
++)
893 if (IsEqualGUID(clsid
, &This
->filters
[i
].guid
) || IsEqualGUID(clsid
, &GUID_All_Objects
))
895 if (count
++ == index
)
896 return IMediaObject_QueryInterface(This
->filters
[i
].obj
, iid
, out
);
899 return DSERR_OBJECTNOTFOUND
;
902 static HRESULT WINAPI
IDirectSoundBufferImpl_Initialize(IDirectSoundBuffer8
*iface
,
903 IDirectSound
*dsound
, LPCDSBUFFERDESC dbsd
)
905 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
907 WARN("(%p) already initialized\n", This
);
908 return DSERR_ALREADYINITIALIZED
;
911 static HRESULT WINAPI
IDirectSoundBufferImpl_GetCaps(IDirectSoundBuffer8
*iface
, LPDSBCAPS caps
)
913 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
915 TRACE("(%p)->(%p)\n",This
,caps
);
918 WARN("invalid parameter: caps == NULL\n");
919 return DSERR_INVALIDPARAM
;
922 if (caps
->dwSize
< sizeof(*caps
)) {
923 WARN("invalid parameter: caps->dwSize = %ld\n",caps
->dwSize
);
924 return DSERR_INVALIDPARAM
;
927 caps
->dwFlags
= This
->dsbd
.dwFlags
;
928 caps
->dwFlags
|= DSBCAPS_LOCSOFTWARE
;
930 caps
->dwBufferBytes
= This
->buflen
;
932 /* According to windows, this is zero*/
933 caps
->dwUnlockTransferRate
= 0;
934 caps
->dwPlayCpuOverhead
= 0;
939 static HRESULT WINAPI
IDirectSoundBufferImpl_QueryInterface(IDirectSoundBuffer8
*iface
, REFIID riid
,
942 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
944 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
947 WARN("invalid parameter\n");
951 *ppobj
= NULL
; /* assume failure */
953 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
954 IsEqualGUID(riid
, &IID_IDirectSoundBuffer
) ||
955 IsEqualGUID(riid
, &IID_IDirectSoundBuffer8
) ) {
956 IDirectSoundBuffer8_AddRef(iface
);
961 if ( IsEqualGUID( &IID_IDirectSoundNotify
, riid
) ) {
962 if(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPOSITIONNOTIFY
) {
963 IDirectSoundNotify_AddRef(&This
->IDirectSoundNotify_iface
);
964 *ppobj
= &This
->IDirectSoundNotify_iface
;
968 TRACE( "App requested IDirectSoundNotify without DSBCAPS_CTRLPOSITIONNOTIFY flag.\n");
969 return E_NOINTERFACE
;
972 if ( IsEqualGUID( &IID_IDirectSound3DBuffer
, riid
) ) {
973 if(This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
){
974 IDirectSound3DBuffer_AddRef(&This
->IDirectSound3DBuffer_iface
);
975 *ppobj
= &This
->IDirectSound3DBuffer_iface
;
978 TRACE("app requested IDirectSound3DBuffer on non-3D secondary buffer\n");
979 return E_NOINTERFACE
;
982 if ( IsEqualGUID( &IID_IDirectSound3DListener
, riid
) ) {
983 ERR("app requested IDirectSound3DListener on secondary buffer\n");
984 return E_NOINTERFACE
;
987 if ( IsEqualGUID( &IID_IKsPropertySet
, riid
) ) {
988 IKsPropertySet_AddRef(&This
->IKsPropertySet_iface
);
989 *ppobj
= &This
->IKsPropertySet_iface
;
993 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
995 return E_NOINTERFACE
;
998 static const IDirectSoundBuffer8Vtbl dsbvt
=
1000 IDirectSoundBufferImpl_QueryInterface
,
1001 IDirectSoundBufferImpl_AddRef
,
1002 IDirectSoundBufferImpl_Release
,
1003 IDirectSoundBufferImpl_GetCaps
,
1004 IDirectSoundBufferImpl_GetCurrentPosition
,
1005 IDirectSoundBufferImpl_GetFormat
,
1006 IDirectSoundBufferImpl_GetVolume
,
1007 IDirectSoundBufferImpl_GetPan
,
1008 IDirectSoundBufferImpl_GetFrequency
,
1009 IDirectSoundBufferImpl_GetStatus
,
1010 IDirectSoundBufferImpl_Initialize
,
1011 IDirectSoundBufferImpl_Lock
,
1012 IDirectSoundBufferImpl_Play
,
1013 IDirectSoundBufferImpl_SetCurrentPosition
,
1014 IDirectSoundBufferImpl_SetFormat
,
1015 IDirectSoundBufferImpl_SetVolume
,
1016 IDirectSoundBufferImpl_SetPan
,
1017 IDirectSoundBufferImpl_SetFrequency
,
1018 IDirectSoundBufferImpl_Stop
,
1019 IDirectSoundBufferImpl_Unlock
,
1020 IDirectSoundBufferImpl_Restore
,
1021 IDirectSoundBufferImpl_SetFX
,
1022 IDirectSoundBufferImpl_AcquireResources
,
1023 IDirectSoundBufferImpl_GetObjectInPath
1026 HRESULT
secondarybuffer_create(DirectSoundDevice
*device
, const DSBUFFERDESC
*dsbd
,
1027 IDirectSoundBuffer
**buffer
)
1029 IDirectSoundBufferImpl
*dsb
;
1030 LPWAVEFORMATEX wfex
= dsbd
->lpwfxFormat
;
1031 HRESULT err
= DS_OK
;
1035 TRACE("(%p,%p,%p)\n", device
, dsbd
, buffer
);
1037 if (dsbd
->dwBufferBytes
< DSBSIZE_MIN
|| dsbd
->dwBufferBytes
> DSBSIZE_MAX
) {
1038 WARN("invalid parameter: dsbd->dwBufferBytes = %ld\n", dsbd
->dwBufferBytes
);
1039 return DSERR_INVALIDPARAM
; /* FIXME: which error? */
1042 dsb
= calloc(1, sizeof(*dsb
));
1045 return DSERR_OUTOFMEMORY
;
1047 TRACE("Created buffer at %p\n", dsb
);
1054 dsb
->device
= device
;
1055 dsb
->IDirectSoundBuffer8_iface
.lpVtbl
= &dsbvt
;
1056 dsb
->IDirectSoundNotify_iface
.lpVtbl
= &dsnvt
;
1057 dsb
->IDirectSound3DBuffer_iface
.lpVtbl
= &ds3dbvt
;
1058 dsb
->IKsPropertySet_iface
.lpVtbl
= &iksbvt
;
1060 /* size depends on version */
1061 CopyMemory(&dsb
->dsbd
, dsbd
, dsbd
->dwSize
);
1063 dsb
->pwfx
= DSOUND_CopyFormat(wfex
);
1065 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1066 return DSERR_OUTOFMEMORY
;
1069 if (dsbd
->dwBufferBytes
% dsbd
->lpwfxFormat
->nBlockAlign
)
1070 dsb
->buflen
= dsbd
->dwBufferBytes
+
1071 (dsbd
->lpwfxFormat
->nBlockAlign
-
1072 (dsbd
->dwBufferBytes
% dsbd
->lpwfxFormat
->nBlockAlign
));
1074 dsb
->buflen
= dsbd
->dwBufferBytes
;
1076 dsb
->freq
= dsbd
->lpwfxFormat
->nSamplesPerSec
;
1077 dsb
->notifies
= NULL
;
1078 dsb
->nrofnotifies
= 0;
1080 /* Check necessary hardware mixing capabilities */
1081 if (wfex
->nChannels
==2) capf
|= DSCAPS_SECONDARYSTEREO
;
1082 else capf
|= DSCAPS_SECONDARYMONO
;
1083 if (wfex
->wBitsPerSample
==16) capf
|= DSCAPS_SECONDARY16BIT
;
1084 else capf
|= DSCAPS_SECONDARY8BIT
;
1086 TRACE("capf = 0x%08lx, device->drvcaps.dwFlags = 0x%08lx\n", capf
, device
->drvcaps
.dwFlags
);
1088 /* Allocate an empty buffer */
1089 bufsize
= (sizeof(*(dsb
->buffer
)) + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
1090 dsb
->buffer
= malloc(bufsize
+ dsb
->buflen
);
1092 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1093 return DSERR_OUTOFMEMORY
;
1096 /* Allocate system memory for buffer */
1097 dsb
->buffer
->memory
= (BYTE
*)dsb
->buffer
+ bufsize
;
1099 dsb
->buffer
->ref
= 1;
1100 dsb
->buffer
->lockedbytes
= 0;
1101 list_init(&dsb
->buffer
->buffers
);
1102 list_add_head(&dsb
->buffer
->buffers
, &dsb
->entry
);
1103 FillMemory(dsb
->buffer
->memory
, dsb
->buflen
, dsbd
->lpwfxFormat
->wBitsPerSample
== 8 ? 128 : 0);
1105 /* It's not necessary to initialize values to zero since */
1106 /* we allocated this structure with calloc... */
1107 dsb
->sec_mixpos
= 0;
1108 dsb
->state
= STATE_STOPPED
;
1110 if (dsb
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) {
1111 dsb
->ds3db_ds3db
.dwSize
= sizeof(DS3DBUFFER
);
1112 dsb
->ds3db_ds3db
.vPosition
.x
= 0.0;
1113 dsb
->ds3db_ds3db
.vPosition
.y
= 0.0;
1114 dsb
->ds3db_ds3db
.vPosition
.z
= 0.0;
1115 dsb
->ds3db_ds3db
.vVelocity
.x
= 0.0;
1116 dsb
->ds3db_ds3db
.vVelocity
.y
= 0.0;
1117 dsb
->ds3db_ds3db
.vVelocity
.z
= 0.0;
1118 dsb
->ds3db_ds3db
.dwInsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1119 dsb
->ds3db_ds3db
.dwOutsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1120 dsb
->ds3db_ds3db
.vConeOrientation
.x
= 0.0;
1121 dsb
->ds3db_ds3db
.vConeOrientation
.y
= 0.0;
1122 dsb
->ds3db_ds3db
.vConeOrientation
.z
= 0.0;
1123 dsb
->ds3db_ds3db
.lConeOutsideVolume
= DS3D_DEFAULTCONEOUTSIDEVOLUME
;
1124 dsb
->ds3db_ds3db
.flMinDistance
= DS3D_DEFAULTMINDISTANCE
;
1125 dsb
->ds3db_ds3db
.flMaxDistance
= DS3D_DEFAULTMAXDISTANCE
;
1126 dsb
->ds3db_ds3db
.dwMode
= DS3DMODE_NORMAL
;
1128 dsb
->ds3db_freq
= dsbd
->lpwfxFormat
->nSamplesPerSec
;
1130 dsb
->ds3db_need_recalc
= FALSE
;
1131 DSOUND_Calc3DBuffer(dsb
);
1133 DSOUND_RecalcVolPan(&(dsb
->volpan
));
1135 /* calculate fragment size and write lead */
1136 DSOUND_RecalcFormat(dsb
);
1139 dsb
->committedbuff
= malloc(dsb
->maxwritelead
);
1140 if(!dsb
->committedbuff
) {
1141 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1142 return DSERR_OUTOFMEMORY
;
1145 InitializeSRWLock(&dsb
->lock
);
1147 /* register buffer */
1148 err
= DirectSoundDevice_AddBuffer(device
, dsb
);
1150 *buffer
= (IDirectSoundBuffer
*)&dsb
->IDirectSoundBuffer8_iface
;
1152 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1157 void secondarybuffer_destroy(IDirectSoundBufferImpl
*This
)
1159 ULONG ref
= InterlockedIncrement(&This
->numIfaces
);
1162 WARN("Destroying buffer with %lu in use interfaces\n", ref
- 1);
1164 if (This
->dsbd
.dwFlags
& DSBCAPS_LOCHARDWARE
)
1165 This
->device
->drvcaps
.dwFreeHwMixingAllBuffers
++;
1167 DirectSoundDevice_RemoveBuffer(This
->device
, This
);
1169 This
->buffer
->ref
--;
1170 list_remove(&This
->entry
);
1171 if (This
->buffer
->ref
== 0)
1174 free(This
->notifies
);
1176 free(This
->committedbuff
);
1178 if (This
->filters
) {
1180 for (i
= 0; i
< This
->num_filters
; i
++) {
1181 IMediaObject_Release(This
->filters
[i
].obj
);
1182 if (This
->filters
[i
].inplace
) IMediaObjectInPlace_Release(This
->filters
[i
].inplace
);
1184 free(This
->filters
);
1187 TRACE("(%p) released\n", This
);
1192 BOOL
secondarybuffer_is_audible(IDirectSoundBufferImpl
*This
)
1195 for (i
= 0; i
< This
->device
->pwfx
->nChannels
; i
++) {
1196 if (This
->volpan
.dwTotalAmpFactor
[i
] != 0)
1203 HRESULT
IDirectSoundBufferImpl_Duplicate(
1204 DirectSoundDevice
*device
,
1205 IDirectSoundBufferImpl
**ppdsb
,
1206 IDirectSoundBufferImpl
*pdsb
)
1208 IDirectSoundBufferImpl
*dsb
;
1209 HRESULT hres
= DS_OK
;
1210 VOID
*committedbuff
;
1211 TRACE("(%p,%p,%p)\n", device
, ppdsb
, pdsb
);
1213 dsb
= malloc(sizeof(*dsb
));
1215 WARN("out of memory\n");
1217 return DSERR_OUTOFMEMORY
;
1220 committedbuff
= malloc(pdsb
->maxwritelead
);
1221 if (committedbuff
== NULL
) {
1224 return DSERR_OUTOFMEMORY
;
1227 AcquireSRWLockShared(&pdsb
->lock
);
1229 CopyMemory(dsb
, pdsb
, sizeof(*dsb
));
1231 dsb
->pwfx
= DSOUND_CopyFormat(pdsb
->pwfx
);
1233 ReleaseSRWLockShared(&pdsb
->lock
);
1235 if (dsb
->pwfx
== NULL
) {
1236 free(committedbuff
);
1239 return DSERR_OUTOFMEMORY
;
1243 list_add_head(&dsb
->buffer
->buffers
, &dsb
->entry
);
1249 dsb
->state
= STATE_STOPPED
;
1250 dsb
->sec_mixpos
= 0;
1251 dsb
->notifies
= NULL
;
1252 dsb
->nrofnotifies
= 0;
1253 dsb
->device
= device
;
1254 dsb
->committedbuff
= committedbuff
;
1255 dsb
->use_committed
= FALSE
;
1256 dsb
->committed_mixpos
= 0;
1257 DSOUND_RecalcFormat(dsb
);
1259 InitializeSRWLock(&dsb
->lock
);
1261 /* register buffer */
1262 hres
= DirectSoundDevice_AddBuffer(device
, dsb
);
1263 if (hres
!= DS_OK
) {
1264 list_remove(&dsb
->entry
);
1267 free(dsb
->committedbuff
);
1271 IDirectSoundBuffer8_AddRef(&dsb
->IDirectSoundBuffer8_iface
);
1277 /*******************************************************************************
1281 static inline IDirectSoundBufferImpl
*impl_from_IKsPropertySet(IKsPropertySet
*iface
)
1283 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IKsPropertySet_iface
);
1286 /* IUnknown methods */
1287 static HRESULT WINAPI
IKsPropertySetImpl_QueryInterface(IKsPropertySet
*iface
, REFIID riid
,
1290 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1292 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
1294 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
1297 static ULONG WINAPI
IKsPropertySetImpl_AddRef(IKsPropertySet
*iface
)
1299 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1300 ULONG ref
= InterlockedIncrement(&This
->refiks
);
1302 TRACE("(%p) ref %ld\n", This
, ref
);
1305 InterlockedIncrement(&This
->numIfaces
);
1310 static ULONG WINAPI
IKsPropertySetImpl_Release(IKsPropertySet
*iface
)
1312 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1315 if (is_primary_buffer(This
)){
1316 ref
= capped_refcount_dec(&This
->refiks
);
1318 capped_refcount_dec(&This
->numIfaces
);
1319 TRACE("(%p) ref %ld\n", This
, ref
);
1323 ref
= InterlockedDecrement(&This
->refiks
);
1324 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
1325 secondarybuffer_destroy(This
);
1327 TRACE("(%p) ref %ld\n", This
, ref
);
1332 static HRESULT WINAPI
IKsPropertySetImpl_Get(IKsPropertySet
*iface
, REFGUID guidPropSet
,
1333 ULONG dwPropID
, void *pInstanceData
, ULONG cbInstanceData
, void *pPropData
,
1334 ULONG cbPropData
, ULONG
*pcbReturned
)
1336 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1338 TRACE("(iface=%p,guidPropSet=%s,dwPropID=%ld,pInstanceData=%p,cbInstanceData=%ld,pPropData=%p,cbPropData=%ld,pcbReturned=%p)\n",
1339 This
,debugstr_guid(guidPropSet
),dwPropID
,pInstanceData
,cbInstanceData
,pPropData
,cbPropData
,pcbReturned
);
1341 return E_PROP_ID_UNSUPPORTED
;
1344 static HRESULT WINAPI
IKsPropertySetImpl_Set(IKsPropertySet
*iface
, REFGUID guidPropSet
,
1345 ULONG dwPropID
, void *pInstanceData
, ULONG cbInstanceData
, void *pPropData
,
1348 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1350 TRACE("(%p,%s,%ld,%p,%ld,%p,%ld)\n",This
,debugstr_guid(guidPropSet
),dwPropID
,pInstanceData
,cbInstanceData
,pPropData
,cbPropData
);
1352 return E_PROP_ID_UNSUPPORTED
;
1355 static HRESULT WINAPI
IKsPropertySetImpl_QuerySupport(IKsPropertySet
*iface
, REFGUID guidPropSet
,
1356 ULONG dwPropID
, ULONG
*pTypeSupport
)
1358 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1360 TRACE("(%p,%s,%ld,%p)\n",This
,debugstr_guid(guidPropSet
),dwPropID
,pTypeSupport
);
1362 return E_PROP_ID_UNSUPPORTED
;
1365 const IKsPropertySetVtbl iksbvt
= {
1366 IKsPropertySetImpl_QueryInterface
,
1367 IKsPropertySetImpl_AddRef
,
1368 IKsPropertySetImpl_Release
,
1369 IKsPropertySetImpl_Get
,
1370 IKsPropertySetImpl_Set
,
1371 IKsPropertySetImpl_QuerySupport