3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2001 TransGaming Technologies, Inc.
6 * Copyright 2002-2003 Rok Mandeljc <rok.mandeljc@gimb.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Most thread locking is complete. There may be a few race
24 * conditions still lurking.
26 * Tested with a Soundblaster clone, a Gravis UltraSound Classic,
27 * and a Turtle Beach Tropez+.
30 * Implement SetCooperativeLevel properly (need to address focus issues)
31 * Implement DirectSound3DBuffers (stubs in place)
32 * Use hardware 3D support if available
33 * Add critical section locking inside Release and AddRef methods
34 * Handle static buffers - put those in hardware, non-static not in hardware
35 * Hardware DuplicateSoundBuffer
36 * Proper volume calculation, and setting volume in HEL primary buffer
37 * Optimize WINMM and negotiate fragment size, decrease DS_HEL_MARGIN
40 #include "dsound_private.h"
42 /* default velocity of sound in the air */
43 #define DEFAULT_VELOCITY 340
45 /*******************************************************************************
49 /* scalar product (I believe it's called dot product in English) */
50 static inline D3DVALUE
ScalarProduct (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
53 c
= (a
->x
*b
->x
) + (a
->y
*b
->y
) + (a
->z
*b
->z
);
54 TRACE("(%f,%f,%f) * (%f,%f,%f) = %f)\n", a
->x
, a
->y
, a
->z
, b
->x
, b
->y
,
59 /* vector product (I believe it's called cross product in English */
60 static inline D3DVECTOR
VectorProduct (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
63 c
.x
= (a
->y
*b
->z
) - (a
->z
*b
->y
);
64 c
.y
= (a
->z
*b
->x
) - (a
->x
*b
->z
);
65 c
.z
= (a
->x
*b
->y
) - (a
->y
*b
->x
);
66 TRACE("(%f,%f,%f) x (%f,%f,%f) = (%f,%f,%f)\n", a
->x
, a
->y
, a
->z
, b
->x
, b
->y
,
71 /* magnitude (length) of vector */
72 static inline D3DVALUE
VectorMagnitude (const D3DVECTOR
*a
)
75 l
= sqrt (ScalarProduct (a
, a
));
76 TRACE("|(%f,%f,%f)| = %f\n", a
->x
, a
->y
, a
->z
, l
);
80 /* conversion between radians and degrees */
81 static inline D3DVALUE
RadToDeg (D3DVALUE angle
)
84 newangle
= angle
* (360/(2*M_PI
));
85 TRACE("%f rad = %f deg\n", angle
, newangle
);
89 /* angle between vectors - rad version */
90 static inline D3DVALUE
AngleBetweenVectorsRad (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
92 D3DVALUE la
, lb
, product
, angle
, cos
;
93 /* definition of scalar product: a*b = |a|*|b|*cos... therefore: */
94 product
= ScalarProduct (a
,b
);
95 la
= VectorMagnitude (a
);
96 lb
= VectorMagnitude (b
);
100 cos
= product
/(la
*lb
);
102 TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians (%f degrees)\n", a
->x
, a
->y
, a
->z
, b
->x
,
103 b
->y
, b
->z
, angle
, RadToDeg(angle
));
107 static inline D3DVALUE
AngleBetweenVectorsDeg (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
109 return RadToDeg(AngleBetweenVectorsRad(a
, b
));
112 /* calculates vector between two points */
113 static inline D3DVECTOR
VectorBetweenTwoPoints (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
119 TRACE("A (%f,%f,%f), B (%f,%f,%f), AB = (%f,%f,%f)\n", a
->x
, a
->y
, a
->z
, b
->x
, b
->y
,
120 b
->z
, c
.x
, c
.y
, c
.z
);
124 /* calculates the length of vector's projection on another vector */
125 static inline D3DVALUE
ProjectVector (const D3DVECTOR
*a
, const D3DVECTOR
*p
)
127 D3DVALUE prod
, result
;
128 prod
= ScalarProduct(a
, p
);
129 result
= prod
/VectorMagnitude(p
);
130 TRACE("length projection of (%f,%f,%f) on (%f,%f,%f) = %f\n", a
->x
, a
->y
, a
->z
, p
->x
,
135 /*******************************************************************************
136 * 3D Buffer and Listener mixing
139 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
)
141 /* volume, at which the sound will be played after all calcs. */
142 D3DVALUE lVolume
= 0;
143 /* stuff for distance related stuff calc. */
145 D3DVALUE flDistance
= 0;
146 /* panning related stuff */
149 /* doppler shift related stuff */
153 /* initial buffer volume */
154 lVolume
= dsb
->ds3db_lVolume
;
156 switch (dsb
->ds3db_ds3db
.dwMode
)
158 case DS3DMODE_DISABLE
:
159 TRACE("3D processing disabled\n");
160 /* this one is here only to eliminate annoying warning message */
161 DSOUND_RecalcVolPan (&dsb
->volpan
);
163 case DS3DMODE_NORMAL
:
164 TRACE("Normal 3D processing mode\n");
165 /* we need to calculate distance between buffer and listener*/
166 vDistance
= VectorBetweenTwoPoints(&dsb
->ds3db_ds3db
.vPosition
, &dsb
->device
->ds3dl
.vPosition
);
167 flDistance
= VectorMagnitude (&vDistance
);
169 case DS3DMODE_HEADRELATIVE
:
170 TRACE("Head-relative 3D processing mode\n");
171 /* distance between buffer and listener is same as buffer's position */
172 flDistance
= VectorMagnitude (&dsb
->ds3db_ds3db
.vPosition
);
176 if (flDistance
> dsb
->ds3db_ds3db
.flMaxDistance
)
178 /* some apps don't want you to hear too distant sounds... */
179 if (dsb
->dsbd
.dwFlags
& DSBCAPS_MUTE3DATMAXDISTANCE
)
181 dsb
->volpan
.lVolume
= DSBVOLUME_MIN
;
182 DSOUND_RecalcVolPan (&dsb
->volpan
);
183 /* i guess mixing here would be a waste of power */
187 flDistance
= dsb
->ds3db_ds3db
.flMaxDistance
;
190 if (flDistance
< dsb
->ds3db_ds3db
.flMinDistance
)
191 flDistance
= dsb
->ds3db_ds3db
.flMinDistance
;
193 /* attenuation proportional to the distance squared, converted to millibels as in lVolume*/
194 lVolume
-= log10(flDistance
/dsb
->ds3db_ds3db
.flMinDistance
* flDistance
/dsb
->ds3db_ds3db
.flMinDistance
)*1000;
195 TRACE("dist. att: Distance = %f, MinDistance = %f => adjusting volume %d to %f\n", flDistance
, dsb
->ds3db_ds3db
.flMinDistance
, dsb
->ds3db_lVolume
, lVolume
);
198 /* sometimes it happens that vConeOrientation vector = (0,0,0); in this case angle is "nan" and it's useless*/
199 if (dsb
->ds3db_ds3db
.vConeOrientation
.x
== 0 && dsb
->ds3db_ds3db
.vConeOrientation
.y
== 0 && dsb
->ds3db_ds3db
.vConeOrientation
.z
== 0)
201 TRACE("conning: cones not set\n");
205 /* calculate angle */
206 flAngle
= AngleBetweenVectorsDeg(&dsb
->ds3db_ds3db
.vConeOrientation
, &vDistance
);
207 /* if by any chance it happens that OutsideConeAngle = InsideConeAngle (that means that conning has no effect) */
208 if (dsb
->ds3db_ds3db
.dwInsideConeAngle
!= dsb
->ds3db_ds3db
.dwOutsideConeAngle
)
210 /* my test show that for my way of calc., we need only half of angles */
211 DWORD dwInsideConeAngle
= dsb
->ds3db_ds3db
.dwInsideConeAngle
/2;
212 DWORD dwOutsideConeAngle
= dsb
->ds3db_ds3db
.dwOutsideConeAngle
/2;
213 if (dwOutsideConeAngle
== dwInsideConeAngle
)
214 ++dwOutsideConeAngle
;
217 if (flAngle
< dwInsideConeAngle
)
218 flAngle
= dwInsideConeAngle
;
219 /* min (app defined) volume */
220 if (flAngle
> dwOutsideConeAngle
)
221 flAngle
= dwOutsideConeAngle
;
222 /* this probably isn't the right thing, but it's ok for the time being */
223 lVolume
+= ((dsb
->ds3db_ds3db
.lConeOutsideVolume
)/((dwOutsideConeAngle
) - (dwInsideConeAngle
))) * flAngle
;
225 TRACE("conning: Angle = %f deg; InsideConeAngle(/2) = %d deg; OutsideConeAngle(/2) = %d deg; ConeOutsideVolume = %d => adjusting volume to %f\n",
226 flAngle
, dsb
->ds3db_ds3db
.dwInsideConeAngle
/2, dsb
->ds3db_ds3db
.dwOutsideConeAngle
/2, dsb
->ds3db_ds3db
.lConeOutsideVolume
, lVolume
);
228 dsb
->volpan
.lVolume
= lVolume
;
231 if (dsb
->device
->ds3dl
.vPosition
.x
== dsb
->ds3db_ds3db
.vPosition
.x
&&
232 dsb
->device
->ds3dl
.vPosition
.y
== dsb
->ds3db_ds3db
.vPosition
.y
&&
233 dsb
->device
->ds3dl
.vPosition
.z
== dsb
->ds3db_ds3db
.vPosition
.z
) {
234 dsb
->volpan
.lPan
= 0;
239 vDistance
= VectorBetweenTwoPoints(&dsb
->device
->ds3dl
.vPosition
, &dsb
->ds3db_ds3db
.vPosition
);
240 vLeft
= VectorProduct(&dsb
->device
->ds3dl
.vOrientFront
, &dsb
->device
->ds3dl
.vOrientTop
);
241 flAngle
= AngleBetweenVectorsRad(&vLeft
, &vDistance
);
242 /* for now, we'll use "linear formula" (which is probably incorrect); if someone has it in book, correct it */
243 dsb
->volpan
.lPan
= 10000*2*flAngle
/M_PI
- 10000;
245 TRACE("panning: Angle = %f rad, lPan = %d\n", flAngle
, dsb
->volpan
.lPan
);
247 /* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */
250 D3DVALUE flFreq
, flBufferVel
, flListenerVel
;
252 if (!VectorMagnitude(&dsb
->ds3db_ds3db
.vVelocity
) && !VectorMagnitude(&dsb
->device
->ds3dl
.vVelocity
))
254 TRACE("doppler: Buffer and Listener don't have velocities\n");
256 else if (!(dsb
->ds3db_ds3db
.vVelocity
.x
== dsb
->device
->ds3dl
.vVelocity
.x
&&
257 dsb
->ds3db_ds3db
.vVelocity
.y
== dsb
->device
->ds3dl
.vVelocity
.y
&&
258 dsb
->ds3db_ds3db
.vVelocity
.z
== dsb
->device
->ds3dl
.vVelocity
.z
))
260 /* calculate length of ds3db_ds3db.vVelocity component which causes Doppler Effect
261 NOTE: if buffer moves TOWARDS the listener, it's velocity component is NEGATIVE
262 if buffer moves AWAY from listener, it's velocity component is POSITIVE */
263 flBufferVel
= ProjectVector(&dsb
->ds3db_ds3db
.vVelocity
, &vDistance
);
264 /* calculate length of ds3dl.vVelocity component which causes Doppler Effect
265 NOTE: if listener moves TOWARDS the buffer, it's velocity component is POSITIVE
266 if listener moves AWAY from buffer, it's velocity component is NEGATIVE */
267 flListenerVel
= ProjectVector(&dsb
->device
->ds3dl
.vVelocity
, &vDistance
);
268 /* formula taken from Gianicoli D.: Physics, 4th edition: */
269 /* FIXME: replace dsb->freq with appropriate frequency ! */
270 flFreq
= dsb
->freq
* ((DEFAULT_VELOCITY
+ flListenerVel
)/(DEFAULT_VELOCITY
+ flBufferVel
));
271 TRACE("doppler: Buffer velocity (component) = %f, Listener velocity (component) = %f => Doppler shift: %d Hz -> %f Hz\n",
272 flBufferVel
, flListenerVel
, dsb
->freq
, flFreq
);
273 /* FIXME: replace following line with correct frequency setting ! */
275 DSOUND_RecalcFormat(dsb
);
280 DSOUND_RecalcVolPan(&dsb
->volpan
);
283 static void DSOUND_Mix3DBuffer(IDirectSoundBufferImpl
*dsb
)
287 DSOUND_Calc3DBuffer(dsb
);
290 static void DSOUND_ChangeListener(IDirectSoundBufferImpl
*ds3dl
)
293 TRACE("(%p)\n",ds3dl
);
294 for (i
= 0; i
< ds3dl
->device
->nrofbuffers
; i
++)
296 /* check if this buffer is waiting for recalculation */
297 if (ds3dl
->device
->buffers
[i
]->ds3db_need_recalc
)
299 DSOUND_Mix3DBuffer(ds3dl
->device
->buffers
[i
]);
304 /*******************************************************************************
305 * IDirectSound3DBuffer
307 static inline IDirectSoundBufferImpl
*impl_from_IDirectSound3DBuffer(IDirectSound3DBuffer
*iface
)
309 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSound3DBuffer_iface
);
312 /* IUnknown methods */
313 static HRESULT WINAPI
IDirectSound3DBufferImpl_QueryInterface(IDirectSound3DBuffer
*iface
,
314 REFIID riid
, void **ppobj
)
316 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
318 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
320 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
323 static ULONG WINAPI
IDirectSound3DBufferImpl_AddRef(IDirectSound3DBuffer
*iface
)
325 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
326 ULONG ref
= InterlockedIncrement(&This
->ref3D
);
328 TRACE("(%p) ref was %d\n", This
, ref
- 1);
331 InterlockedIncrement(&This
->numIfaces
);
336 static ULONG WINAPI
IDirectSound3DBufferImpl_Release(IDirectSound3DBuffer
*iface
)
338 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
339 ULONG ref
= InterlockedDecrement(&This
->ref3D
);
341 TRACE("(%p) ref was %d\n", This
, ref
+ 1);
343 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
344 secondarybuffer_destroy(This
);
349 /* IDirectSound3DBuffer methods */
350 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetAllParameters(IDirectSound3DBuffer
*iface
,
351 DS3DBUFFER
*lpDs3dBuffer
)
353 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
355 TRACE("(%p,%p)\n",This
,lpDs3dBuffer
);
357 if (lpDs3dBuffer
== NULL
) {
358 WARN("invalid parameter: lpDs3dBuffer == NULL\n");
359 return DSERR_INVALIDPARAM
;
362 if (lpDs3dBuffer
->dwSize
< sizeof(*lpDs3dBuffer
)) {
363 WARN("invalid parameter: lpDs3dBuffer->dwSize = %d\n",lpDs3dBuffer
->dwSize
);
364 return DSERR_INVALIDPARAM
;
367 TRACE("returning: all parameters\n");
368 *lpDs3dBuffer
= This
->ds3db_ds3db
;
372 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetConeAngles(IDirectSound3DBuffer
*iface
,
373 DWORD
*lpdwInsideConeAngle
, DWORD
*lpdwOutsideConeAngle
)
375 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
377 TRACE("returning: Inside Cone Angle = %d degrees; Outside Cone Angle = %d degrees\n",
378 This
->ds3db_ds3db
.dwInsideConeAngle
, This
->ds3db_ds3db
.dwOutsideConeAngle
);
379 *lpdwInsideConeAngle
= This
->ds3db_ds3db
.dwInsideConeAngle
;
380 *lpdwOutsideConeAngle
= This
->ds3db_ds3db
.dwOutsideConeAngle
;
384 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetConeOrientation(IDirectSound3DBuffer
*iface
,
385 D3DVECTOR
*lpvConeOrientation
)
387 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
389 TRACE("returning: Cone Orientation vector = (%f,%f,%f)\n",
390 This
->ds3db_ds3db
.vConeOrientation
.x
,
391 This
->ds3db_ds3db
.vConeOrientation
.y
,
392 This
->ds3db_ds3db
.vConeOrientation
.z
);
393 *lpvConeOrientation
= This
->ds3db_ds3db
.vConeOrientation
;
397 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetConeOutsideVolume(IDirectSound3DBuffer
*iface
,
398 LONG
*lplConeOutsideVolume
)
400 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
402 TRACE("returning: Cone Outside Volume = %d\n", This
->ds3db_ds3db
.lConeOutsideVolume
);
403 *lplConeOutsideVolume
= This
->ds3db_ds3db
.lConeOutsideVolume
;
407 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetMaxDistance(IDirectSound3DBuffer
*iface
,
408 D3DVALUE
*lpfMaxDistance
)
410 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
412 TRACE("returning: Max Distance = %f\n", This
->ds3db_ds3db
.flMaxDistance
);
413 *lpfMaxDistance
= This
->ds3db_ds3db
.flMaxDistance
;
417 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetMinDistance(IDirectSound3DBuffer
*iface
,
418 D3DVALUE
*lpfMinDistance
)
420 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
422 TRACE("returning: Min Distance = %f\n", This
->ds3db_ds3db
.flMinDistance
);
423 *lpfMinDistance
= This
->ds3db_ds3db
.flMinDistance
;
427 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetMode(IDirectSound3DBuffer
*iface
,
430 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
432 TRACE("returning: Mode = %d\n", This
->ds3db_ds3db
.dwMode
);
433 *lpdwMode
= This
->ds3db_ds3db
.dwMode
;
437 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetPosition(IDirectSound3DBuffer
*iface
,
438 D3DVECTOR
*lpvPosition
)
440 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
442 TRACE("returning: Position vector = (%f,%f,%f)\n", This
->ds3db_ds3db
.vPosition
.x
,
443 This
->ds3db_ds3db
.vPosition
.y
, This
->ds3db_ds3db
.vPosition
.z
);
444 *lpvPosition
= This
->ds3db_ds3db
.vPosition
;
448 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetVelocity(IDirectSound3DBuffer
*iface
,
449 D3DVECTOR
*lpvVelocity
)
451 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
453 TRACE("returning: Velocity vector = (%f,%f,%f)\n", This
->ds3db_ds3db
.vVelocity
.x
,
454 This
->ds3db_ds3db
.vVelocity
.y
, This
->ds3db_ds3db
.vVelocity
.z
);
455 *lpvVelocity
= This
->ds3db_ds3db
.vVelocity
;
459 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetAllParameters(IDirectSound3DBuffer
*iface
,
460 const DS3DBUFFER
*lpcDs3dBuffer
, DWORD dwApply
)
462 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
463 DWORD status
= DSERR_INVALIDPARAM
;
465 TRACE("(%p,%p,%x)\n",iface
,lpcDs3dBuffer
,dwApply
);
467 if (lpcDs3dBuffer
== NULL
) {
468 WARN("invalid parameter: lpcDs3dBuffer == NULL\n");
472 if (lpcDs3dBuffer
->dwSize
!= sizeof(DS3DBUFFER
)) {
473 WARN("invalid parameter: lpcDs3dBuffer->dwSize = %d\n", lpcDs3dBuffer
->dwSize
);
477 TRACE("setting: all parameters; dwApply = %d\n", dwApply
);
478 This
->ds3db_ds3db
= *lpcDs3dBuffer
;
480 if (dwApply
== DS3D_IMMEDIATE
)
482 DSOUND_Mix3DBuffer(This
);
484 This
->ds3db_need_recalc
= TRUE
;
490 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetConeAngles(IDirectSound3DBuffer
*iface
,
491 DWORD dwInsideConeAngle
, DWORD dwOutsideConeAngle
, DWORD dwApply
)
493 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
495 TRACE("setting: Inside Cone Angle = %d; Outside Cone Angle = %d; dwApply = %d\n",
496 dwInsideConeAngle
, dwOutsideConeAngle
, dwApply
);
497 This
->ds3db_ds3db
.dwInsideConeAngle
= dwInsideConeAngle
;
498 This
->ds3db_ds3db
.dwOutsideConeAngle
= dwOutsideConeAngle
;
499 if (dwApply
== DS3D_IMMEDIATE
)
500 DSOUND_Mix3DBuffer(This
);
501 This
->ds3db_need_recalc
= TRUE
;
505 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetConeOrientation(IDirectSound3DBuffer
*iface
,
506 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
508 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
510 TRACE("setting: Cone Orientation vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
511 This
->ds3db_ds3db
.vConeOrientation
.x
= x
;
512 This
->ds3db_ds3db
.vConeOrientation
.y
= y
;
513 This
->ds3db_ds3db
.vConeOrientation
.z
= z
;
514 if (dwApply
== DS3D_IMMEDIATE
)
516 This
->ds3db_need_recalc
= FALSE
;
517 DSOUND_Mix3DBuffer(This
);
519 This
->ds3db_need_recalc
= TRUE
;
523 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetConeOutsideVolume(IDirectSound3DBuffer
*iface
,
524 LONG lConeOutsideVolume
, DWORD dwApply
)
526 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
528 TRACE("setting: ConeOutsideVolume = %d; dwApply = %d\n", lConeOutsideVolume
, dwApply
);
529 This
->ds3db_ds3db
.lConeOutsideVolume
= lConeOutsideVolume
;
530 if (dwApply
== DS3D_IMMEDIATE
)
532 This
->ds3db_need_recalc
= FALSE
;
533 DSOUND_Mix3DBuffer(This
);
535 This
->ds3db_need_recalc
= TRUE
;
539 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetMaxDistance(IDirectSound3DBuffer
*iface
,
540 D3DVALUE fMaxDistance
, DWORD dwApply
)
542 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
544 TRACE("setting: MaxDistance = %f; dwApply = %d\n", fMaxDistance
, dwApply
);
545 This
->ds3db_ds3db
.flMaxDistance
= fMaxDistance
;
546 if (dwApply
== DS3D_IMMEDIATE
)
548 This
->ds3db_need_recalc
= FALSE
;
549 DSOUND_Mix3DBuffer(This
);
551 This
->ds3db_need_recalc
= TRUE
;
555 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetMinDistance(IDirectSound3DBuffer
*iface
,
556 D3DVALUE fMinDistance
, DWORD dwApply
)
558 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
560 TRACE("setting: MinDistance = %f; dwApply = %d\n", fMinDistance
, dwApply
);
561 This
->ds3db_ds3db
.flMinDistance
= fMinDistance
;
562 if (dwApply
== DS3D_IMMEDIATE
)
564 This
->ds3db_need_recalc
= FALSE
;
565 DSOUND_Mix3DBuffer(This
);
567 This
->ds3db_need_recalc
= TRUE
;
571 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetMode(IDirectSound3DBuffer
*iface
, DWORD dwMode
,
574 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
576 TRACE("setting: Mode = %d; dwApply = %d\n", dwMode
, dwApply
);
577 This
->ds3db_ds3db
.dwMode
= dwMode
;
578 if (dwApply
== DS3D_IMMEDIATE
)
580 This
->ds3db_need_recalc
= FALSE
;
581 DSOUND_Mix3DBuffer(This
);
583 This
->ds3db_need_recalc
= TRUE
;
587 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetPosition(IDirectSound3DBuffer
*iface
, D3DVALUE x
,
588 D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
590 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
592 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
593 This
->ds3db_ds3db
.vPosition
.x
= x
;
594 This
->ds3db_ds3db
.vPosition
.y
= y
;
595 This
->ds3db_ds3db
.vPosition
.z
= z
;
596 if (dwApply
== DS3D_IMMEDIATE
)
598 This
->ds3db_need_recalc
= FALSE
;
599 DSOUND_Mix3DBuffer(This
);
601 This
->ds3db_need_recalc
= TRUE
;
605 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetVelocity(IDirectSound3DBuffer
*iface
,
606 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
608 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
610 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
611 This
->ds3db_ds3db
.vVelocity
.x
= x
;
612 This
->ds3db_ds3db
.vVelocity
.y
= y
;
613 This
->ds3db_ds3db
.vVelocity
.z
= z
;
614 if (dwApply
== DS3D_IMMEDIATE
)
616 This
->ds3db_need_recalc
= FALSE
;
617 DSOUND_Mix3DBuffer(This
);
619 This
->ds3db_need_recalc
= TRUE
;
623 const IDirectSound3DBufferVtbl ds3dbvt
=
625 /* IUnknown methods */
626 IDirectSound3DBufferImpl_QueryInterface
,
627 IDirectSound3DBufferImpl_AddRef
,
628 IDirectSound3DBufferImpl_Release
,
629 /* IDirectSound3DBuffer methods */
630 IDirectSound3DBufferImpl_GetAllParameters
,
631 IDirectSound3DBufferImpl_GetConeAngles
,
632 IDirectSound3DBufferImpl_GetConeOrientation
,
633 IDirectSound3DBufferImpl_GetConeOutsideVolume
,
634 IDirectSound3DBufferImpl_GetMaxDistance
,
635 IDirectSound3DBufferImpl_GetMinDistance
,
636 IDirectSound3DBufferImpl_GetMode
,
637 IDirectSound3DBufferImpl_GetPosition
,
638 IDirectSound3DBufferImpl_GetVelocity
,
639 IDirectSound3DBufferImpl_SetAllParameters
,
640 IDirectSound3DBufferImpl_SetConeAngles
,
641 IDirectSound3DBufferImpl_SetConeOrientation
,
642 IDirectSound3DBufferImpl_SetConeOutsideVolume
,
643 IDirectSound3DBufferImpl_SetMaxDistance
,
644 IDirectSound3DBufferImpl_SetMinDistance
,
645 IDirectSound3DBufferImpl_SetMode
,
646 IDirectSound3DBufferImpl_SetPosition
,
647 IDirectSound3DBufferImpl_SetVelocity
,
651 /*******************************************************************************
652 * IDirectSound3DListener
654 static inline IDirectSoundBufferImpl
*impl_from_IDirectSound3DListener(IDirectSound3DListener
*iface
)
656 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSound3DListener_iface
);
660 /* IUnknown methods */
661 static HRESULT WINAPI
IDirectSound3DListenerImpl_QueryInterface(IDirectSound3DListener
*iface
,
662 REFIID riid
, void **ppobj
)
664 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
666 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(riid
), ppobj
);
668 return IDirectSoundBuffer_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
671 static ULONG WINAPI
IDirectSound3DListenerImpl_AddRef(IDirectSound3DListener
*iface
)
673 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
674 ULONG ref
= InterlockedIncrement(&This
->ref3D
);
676 TRACE("(%p) ref was %d\n", This
, ref
- 1);
679 InterlockedIncrement(&This
->numIfaces
);
684 static ULONG WINAPI
IDirectSound3DListenerImpl_Release(IDirectSound3DListener
*iface
)
686 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
689 ref
= capped_refcount_dec(&This
->ref3D
);
691 capped_refcount_dec(&This
->numIfaces
);
693 TRACE("(%p) ref is now %d\n", This
, ref
);
698 /* IDirectSound3DListener methods */
699 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetAllParameter(IDirectSound3DListener
*iface
,
700 DS3DLISTENER
*lpDS3DL
)
702 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
704 TRACE("(%p,%p)\n",This
,lpDS3DL
);
706 if (lpDS3DL
== NULL
) {
707 WARN("invalid parameter: lpDS3DL == NULL\n");
708 return DSERR_INVALIDPARAM
;
711 if (lpDS3DL
->dwSize
< sizeof(*lpDS3DL
)) {
712 WARN("invalid parameter: lpDS3DL->dwSize = %d\n",lpDS3DL
->dwSize
);
713 return DSERR_INVALIDPARAM
;
716 TRACE("returning: all parameters\n");
717 *lpDS3DL
= This
->device
->ds3dl
;
721 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetDistanceFactor(IDirectSound3DListener
*iface
,
722 D3DVALUE
*lpfDistanceFactor
)
724 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
726 TRACE("returning: Distance Factor = %f\n", This
->device
->ds3dl
.flDistanceFactor
);
727 *lpfDistanceFactor
= This
->device
->ds3dl
.flDistanceFactor
;
731 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetDopplerFactor(IDirectSound3DListener
*iface
,
732 D3DVALUE
*lpfDopplerFactor
)
734 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
736 TRACE("returning: Doppler Factor = %f\n", This
->device
->ds3dl
.flDopplerFactor
);
737 *lpfDopplerFactor
= This
->device
->ds3dl
.flDopplerFactor
;
741 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetOrientation(IDirectSound3DListener
*iface
,
742 D3DVECTOR
*lpvOrientFront
, D3DVECTOR
*lpvOrientTop
)
744 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
746 TRACE("returning: OrientFront vector = (%f,%f,%f); OrientTop vector = (%f,%f,%f)\n", This
->device
->ds3dl
.vOrientFront
.x
,
747 This
->device
->ds3dl
.vOrientFront
.y
, This
->device
->ds3dl
.vOrientFront
.z
, This
->device
->ds3dl
.vOrientTop
.x
, This
->device
->ds3dl
.vOrientTop
.y
,
748 This
->device
->ds3dl
.vOrientTop
.z
);
749 *lpvOrientFront
= This
->device
->ds3dl
.vOrientFront
;
750 *lpvOrientTop
= This
->device
->ds3dl
.vOrientTop
;
754 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetPosition(IDirectSound3DListener
*iface
,
755 D3DVECTOR
*lpvPosition
)
757 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
759 TRACE("returning: Position vector = (%f,%f,%f)\n", This
->device
->ds3dl
.vPosition
.x
, This
->device
->ds3dl
.vPosition
.y
, This
->device
->ds3dl
.vPosition
.z
);
760 *lpvPosition
= This
->device
->ds3dl
.vPosition
;
764 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetRolloffFactor(IDirectSound3DListener
*iface
,
765 D3DVALUE
*lpfRolloffFactor
)
767 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
769 TRACE("returning: RolloffFactor = %f\n", This
->device
->ds3dl
.flRolloffFactor
);
770 *lpfRolloffFactor
= This
->device
->ds3dl
.flRolloffFactor
;
774 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetVelocity(IDirectSound3DListener
*iface
,
775 D3DVECTOR
*lpvVelocity
)
777 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
779 TRACE("returning: Velocity vector = (%f,%f,%f)\n", This
->device
->ds3dl
.vVelocity
.x
, This
->device
->ds3dl
.vVelocity
.y
, This
->device
->ds3dl
.vVelocity
.z
);
780 *lpvVelocity
= This
->device
->ds3dl
.vVelocity
;
784 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetAllParameters(IDirectSound3DListener
*iface
,
785 const DS3DLISTENER
*lpcDS3DL
, DWORD dwApply
)
787 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
789 TRACE("setting: all parameters; dwApply = %d\n", dwApply
);
790 This
->device
->ds3dl
= *lpcDS3DL
;
791 if (dwApply
== DS3D_IMMEDIATE
)
793 This
->device
->ds3dl_need_recalc
= FALSE
;
794 DSOUND_ChangeListener(This
);
796 This
->device
->ds3dl_need_recalc
= TRUE
;
800 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetDistanceFactor(IDirectSound3DListener
*iface
,
801 D3DVALUE fDistanceFactor
, DWORD dwApply
)
803 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
805 TRACE("setting: Distance Factor = %f; dwApply = %d\n", fDistanceFactor
, dwApply
);
806 This
->device
->ds3dl
.flDistanceFactor
= fDistanceFactor
;
807 if (dwApply
== DS3D_IMMEDIATE
)
809 This
->device
->ds3dl_need_recalc
= FALSE
;
810 DSOUND_ChangeListener(This
);
812 This
->device
->ds3dl_need_recalc
= TRUE
;
816 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetDopplerFactor(IDirectSound3DListener
*iface
,
817 D3DVALUE fDopplerFactor
, DWORD dwApply
)
819 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
821 TRACE("setting: Doppler Factor = %f; dwApply = %d\n", fDopplerFactor
, dwApply
);
822 This
->device
->ds3dl
.flDopplerFactor
= fDopplerFactor
;
823 if (dwApply
== DS3D_IMMEDIATE
)
825 This
->device
->ds3dl_need_recalc
= FALSE
;
826 DSOUND_ChangeListener(This
);
828 This
->device
->ds3dl_need_recalc
= TRUE
;
832 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetOrientation(IDirectSound3DListener
*iface
,
833 D3DVALUE xFront
, D3DVALUE yFront
, D3DVALUE zFront
, D3DVALUE xTop
, D3DVALUE yTop
,
834 D3DVALUE zTop
, DWORD dwApply
)
836 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
838 TRACE("setting: Front vector = (%f,%f,%f); Top vector = (%f,%f,%f); dwApply = %d\n",
839 xFront
, yFront
, zFront
, xTop
, yTop
, zTop
, dwApply
);
840 This
->device
->ds3dl
.vOrientFront
.x
= xFront
;
841 This
->device
->ds3dl
.vOrientFront
.y
= yFront
;
842 This
->device
->ds3dl
.vOrientFront
.z
= zFront
;
843 This
->device
->ds3dl
.vOrientTop
.x
= xTop
;
844 This
->device
->ds3dl
.vOrientTop
.y
= yTop
;
845 This
->device
->ds3dl
.vOrientTop
.z
= zTop
;
846 if (dwApply
== DS3D_IMMEDIATE
)
848 This
->device
->ds3dl_need_recalc
= FALSE
;
849 DSOUND_ChangeListener(This
);
851 This
->device
->ds3dl_need_recalc
= TRUE
;
855 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetPosition(IDirectSound3DListener
*iface
,
856 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
858 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
860 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
861 This
->device
->ds3dl
.vPosition
.x
= x
;
862 This
->device
->ds3dl
.vPosition
.y
= y
;
863 This
->device
->ds3dl
.vPosition
.z
= z
;
864 if (dwApply
== DS3D_IMMEDIATE
)
866 This
->device
->ds3dl_need_recalc
= FALSE
;
867 DSOUND_ChangeListener(This
);
869 This
->device
->ds3dl_need_recalc
= TRUE
;
873 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetRolloffFactor(IDirectSound3DListener
*iface
,
874 D3DVALUE fRolloffFactor
, DWORD dwApply
)
876 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
878 TRACE("setting: Rolloff Factor = %f; dwApply = %d\n", fRolloffFactor
, dwApply
);
879 This
->device
->ds3dl
.flRolloffFactor
= fRolloffFactor
;
880 if (dwApply
== DS3D_IMMEDIATE
)
882 This
->device
->ds3dl_need_recalc
= FALSE
;
883 DSOUND_ChangeListener(This
);
885 This
->device
->ds3dl_need_recalc
= TRUE
;
889 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetVelocity(IDirectSound3DListener
*iface
,
890 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
892 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
894 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
895 This
->device
->ds3dl
.vVelocity
.x
= x
;
896 This
->device
->ds3dl
.vVelocity
.y
= y
;
897 This
->device
->ds3dl
.vVelocity
.z
= z
;
898 if (dwApply
== DS3D_IMMEDIATE
)
900 This
->device
->ds3dl_need_recalc
= FALSE
;
901 DSOUND_ChangeListener(This
);
903 This
->device
->ds3dl_need_recalc
= TRUE
;
907 static HRESULT WINAPI
IDirectSound3DListenerImpl_CommitDeferredSettings(IDirectSound3DListener
*iface
)
909 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
912 DSOUND_ChangeListener(This
);
916 const IDirectSound3DListenerVtbl ds3dlvt
=
918 /* IUnknown methods */
919 IDirectSound3DListenerImpl_QueryInterface
,
920 IDirectSound3DListenerImpl_AddRef
,
921 IDirectSound3DListenerImpl_Release
,
922 /* IDirectSound3DListener methods */
923 IDirectSound3DListenerImpl_GetAllParameter
,
924 IDirectSound3DListenerImpl_GetDistanceFactor
,
925 IDirectSound3DListenerImpl_GetDopplerFactor
,
926 IDirectSound3DListenerImpl_GetOrientation
,
927 IDirectSound3DListenerImpl_GetPosition
,
928 IDirectSound3DListenerImpl_GetRolloffFactor
,
929 IDirectSound3DListenerImpl_GetVelocity
,
930 IDirectSound3DListenerImpl_SetAllParameters
,
931 IDirectSound3DListenerImpl_SetDistanceFactor
,
932 IDirectSound3DListenerImpl_SetDopplerFactor
,
933 IDirectSound3DListenerImpl_SetOrientation
,
934 IDirectSound3DListenerImpl_SetPosition
,
935 IDirectSound3DListenerImpl_SetRolloffFactor
,
936 IDirectSound3DListenerImpl_SetVelocity
,
937 IDirectSound3DListenerImpl_CommitDeferredSettings
,