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
41 #include <math.h> /* Insomnia - pow() function */
49 #include "wine/debug.h"
51 #include "dsound_private.h"
53 /* default velocity of sound in the air */
54 #define DEFAULT_VELOCITY 340
56 WINE_DEFAULT_DEBUG_CHANNEL(dsound3d
);
58 /*******************************************************************************
62 /* scalar product (I believe it's called dot product in English) */
63 static inline D3DVALUE
ScalarProduct (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
66 c
= (a
->x
*b
->x
) + (a
->y
*b
->y
) + (a
->z
*b
->z
);
67 TRACE("(%f,%f,%f) * (%f,%f,%f) = %f)\n", a
->x
, a
->y
, a
->z
, b
->x
, b
->y
,
72 /* vector product (I believe it's called cross product in English */
73 static inline D3DVECTOR
VectorProduct (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
76 c
.x
= (a
->y
*b
->z
) - (a
->z
*b
->y
);
77 c
.y
= (a
->z
*b
->x
) - (a
->x
*b
->z
);
78 c
.z
= (a
->x
*b
->y
) - (a
->y
*b
->x
);
79 TRACE("(%f,%f,%f) x (%f,%f,%f) = (%f,%f,%f)\n", a
->x
, a
->y
, a
->z
, b
->x
, b
->y
,
84 /* magnitude (length) of vector */
85 static inline D3DVALUE
VectorMagnitude (const D3DVECTOR
*a
)
88 l
= sqrt (ScalarProduct (a
, a
));
89 TRACE("|(%f,%f,%f)| = %f\n", a
->x
, a
->y
, a
->z
, l
);
93 /* conversion between radians and degrees */
94 static inline D3DVALUE
RadToDeg (D3DVALUE angle
)
97 newangle
= angle
* (360/(2*M_PI
));
98 TRACE("%f rad = %f deg\n", angle
, newangle
);
102 /* angle between vectors - rad version */
103 static inline D3DVALUE
AngleBetweenVectorsRad (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
105 D3DVALUE la
, lb
, product
, angle
, cos
;
106 /* definition of scalar product: a*b = |a|*|b|*cos... therefore: */
107 product
= ScalarProduct (a
,b
);
108 la
= VectorMagnitude (a
);
109 lb
= VectorMagnitude (b
);
113 cos
= product
/(la
*lb
);
116 }else if(cos
< -1.f
){
121 TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians (%f degrees)\n", a
->x
, a
->y
, a
->z
, b
->x
,
122 b
->y
, b
->z
, angle
, RadToDeg(angle
));
126 static inline D3DVALUE
AngleBetweenVectorsDeg (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
128 return RadToDeg(AngleBetweenVectorsRad(a
, b
));
131 /* calculates vector between two points */
132 static inline D3DVECTOR
VectorBetweenTwoPoints (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
138 TRACE("A (%f,%f,%f), B (%f,%f,%f), AB = (%f,%f,%f)\n", a
->x
, a
->y
, a
->z
, b
->x
, b
->y
,
139 b
->z
, c
.x
, c
.y
, c
.z
);
143 /* calculates the length of vector's projection on another vector */
144 static inline D3DVALUE
ProjectVector (const D3DVECTOR
*a
, const D3DVECTOR
*p
)
146 D3DVALUE prod
, result
;
147 prod
= ScalarProduct(a
, p
);
148 result
= prod
/VectorMagnitude(p
);
149 TRACE("length projection of (%f,%f,%f) on (%f,%f,%f) = %f\n", a
->x
, a
->y
, a
->z
, p
->x
,
154 /*******************************************************************************
155 * 3D Buffer and Listener mixing
158 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
)
160 /* volume, at which the sound will be played after all calcs. */
161 D3DVALUE lVolume
= 0;
162 /* stuff for distance related stuff calc. */
164 D3DVALUE flDistance
= 0;
165 /* panning related stuff */
166 D3DVALUE flAngle
, flAngle2
;
168 int i
, num_main_speakers
;
170 /* doppler shift related stuff */
174 /* initial buffer volume */
175 lVolume
= dsb
->ds3db_lVolume
;
177 switch (dsb
->ds3db_ds3db
.dwMode
)
179 case DS3DMODE_NORMAL
:
180 TRACE("Normal 3D processing mode\n");
181 /* we need to calculate distance between buffer and listener*/
182 vDistance
= VectorBetweenTwoPoints(&dsb
->device
->ds3dl
.vPosition
, &dsb
->ds3db_ds3db
.vPosition
);
183 flDistance
= VectorMagnitude (&vDistance
);
185 case DS3DMODE_HEADRELATIVE
:
186 TRACE("Head-relative 3D processing mode\n");
187 /* distance between buffer and listener is same as buffer's position */
188 vDistance
= dsb
->ds3db_ds3db
.vPosition
;
189 flDistance
= VectorMagnitude (&vDistance
);
192 TRACE("3D processing disabled\n");
193 /* this one is here only to eliminate annoying warning message */
194 dsb
->volpan
.lVolume
= dsb
->ds3db_lVolume
;
195 DSOUND_RecalcVolPan (&dsb
->volpan
);
199 if (flDistance
> dsb
->ds3db_ds3db
.flMaxDistance
)
201 /* some apps don't want you to hear too distant sounds... */
202 if (dsb
->dsbd
.dwFlags
& DSBCAPS_MUTE3DATMAXDISTANCE
)
204 dsb
->volpan
.lVolume
= DSBVOLUME_MIN
;
205 DSOUND_RecalcVolPan (&dsb
->volpan
);
206 /* i guess mixing here would be a waste of power */
210 flDistance
= dsb
->ds3db_ds3db
.flMaxDistance
;
213 if (flDistance
< dsb
->ds3db_ds3db
.flMinDistance
)
214 flDistance
= dsb
->ds3db_ds3db
.flMinDistance
;
216 flDistance
= dsb
->ds3db_ds3db
.flMinDistance
+ (flDistance
- dsb
->ds3db_ds3db
.flMinDistance
) * dsb
->device
->ds3dl
.flRolloffFactor
;
218 /* attenuation proportional to the distance squared, converted to millibels as in lVolume*/
219 lVolume
-= log10(flDistance
/dsb
->ds3db_ds3db
.flMinDistance
* flDistance
/dsb
->ds3db_ds3db
.flMinDistance
)*1000;
220 TRACE("dist. att: Distance = %f, MinDistance = %f => adjusting volume %d to %f\n", flDistance
, dsb
->ds3db_ds3db
.flMinDistance
, dsb
->ds3db_lVolume
, lVolume
);
223 /* sometimes it happens that vConeOrientation vector = (0,0,0); in this case angle is "nan" and it's useless*/
224 if (dsb
->ds3db_ds3db
.vConeOrientation
.x
== 0 && dsb
->ds3db_ds3db
.vConeOrientation
.y
== 0 && dsb
->ds3db_ds3db
.vConeOrientation
.z
== 0)
226 TRACE("conning: cones not set\n");
230 D3DVECTOR vDistanceInv
;
232 vDistanceInv
.x
= -vDistance
.x
;
233 vDistanceInv
.y
= -vDistance
.y
;
234 vDistanceInv
.z
= -vDistance
.z
;
236 /* calculate angle */
237 flAngle
= AngleBetweenVectorsDeg(&dsb
->ds3db_ds3db
.vConeOrientation
, &vDistanceInv
);
238 /* if by any chance it happens that OutsideConeAngle = InsideConeAngle (that means that conning has no effect) */
239 if (dsb
->ds3db_ds3db
.dwInsideConeAngle
!= dsb
->ds3db_ds3db
.dwOutsideConeAngle
)
241 /* my test show that for my way of calc., we need only half of angles */
242 DWORD dwInsideConeAngle
= dsb
->ds3db_ds3db
.dwInsideConeAngle
/2;
243 DWORD dwOutsideConeAngle
= dsb
->ds3db_ds3db
.dwOutsideConeAngle
/2;
244 if (dwOutsideConeAngle
== dwInsideConeAngle
)
245 ++dwOutsideConeAngle
;
248 if (flAngle
< dwInsideConeAngle
)
249 flAngle
= dwInsideConeAngle
;
250 /* min (app defined) volume */
251 if (flAngle
> dwOutsideConeAngle
)
252 flAngle
= dwOutsideConeAngle
;
253 /* this probably isn't the right thing, but it's ok for the time being */
254 lVolume
+= ((flAngle
- dwInsideConeAngle
)/(dwOutsideConeAngle
- dwInsideConeAngle
)) * dsb
->ds3db_ds3db
.lConeOutsideVolume
;
256 TRACE("conning: Angle = %f deg; InsideConeAngle(/2) = %d deg; OutsideConeAngle(/2) = %d deg; ConeOutsideVolume = %d => adjusting volume to %f\n",
257 flAngle
, dsb
->ds3db_ds3db
.dwInsideConeAngle
/2, dsb
->ds3db_ds3db
.dwOutsideConeAngle
/2, dsb
->ds3db_ds3db
.lConeOutsideVolume
, lVolume
);
259 dsb
->volpan
.lVolume
= lVolume
;
261 ingain
= pow(2.0, dsb
->volpan
.lVolume
/ 600.0) * 0xffff;
263 if (dsb
->device
->pwfx
->nChannels
== 1)
265 dsb
->volpan
.dwTotalAmpFactor
[0] = ingain
;
270 if (vDistance
.x
== 0.0f
&& vDistance
.y
== 0.0f
&& vDistance
.z
== 0.0f
)
274 vLeft
= VectorProduct(&dsb
->device
->ds3dl
.vOrientFront
, &dsb
->device
->ds3dl
.vOrientTop
);
275 /* To calculate angle to sound source we need to:
276 * 1) Get angle between vDistance and a plane on which angle to sound source should be 0.
277 * Such a plane is given by vectors vOrientFront and vOrientTop, and angle between vector
278 * and a plane equals to M_PI_2 - angle between vector and normal to this plane (vLeft in this case).
279 * 2) Determine if the source is behind or in front of us by calculating angle between vDistance
282 flAngle
= AngleBetweenVectorsRad(&vLeft
, &vDistance
);
283 flAngle2
= AngleBetweenVectorsRad(&dsb
->device
->ds3dl
.vOrientFront
, &vDistance
);
284 if (flAngle2
> M_PI_2
)
290 TRACE("panning: Angle = %f rad, lPan = %d\n", flAngle
, dsb
->volpan
.lPan
);
292 /* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */
295 D3DVALUE flFreq
, flBufferVel
, flListenerVel
;
297 if (!VectorMagnitude(&dsb
->ds3db_ds3db
.vVelocity
) && !VectorMagnitude(&dsb
->device
->ds3dl
.vVelocity
))
299 TRACE("doppler: Buffer and Listener don't have velocities\n");
301 else if (!(dsb
->ds3db_ds3db
.vVelocity
.x
== dsb
->device
->ds3dl
.vVelocity
.x
&&
302 dsb
->ds3db_ds3db
.vVelocity
.y
== dsb
->device
->ds3dl
.vVelocity
.y
&&
303 dsb
->ds3db_ds3db
.vVelocity
.z
== dsb
->device
->ds3dl
.vVelocity
.z
))
305 /* calculate length of ds3db_ds3db.vVelocity component which causes Doppler Effect
306 NOTE: if buffer moves TOWARDS the listener, its velocity component is NEGATIVE
307 if buffer moves AWAY from listener, its velocity component is POSITIVE */
308 flBufferVel
= ProjectVector(&dsb
->ds3db_ds3db
.vVelocity
, &vDistance
);
309 /* calculate length of ds3dl.vVelocity component which causes Doppler Effect
310 NOTE: if listener moves TOWARDS the buffer, its velocity component is POSITIVE
311 if listener moves AWAY from buffer, its velocity component is NEGATIVE */
312 flListenerVel
= ProjectVector(&dsb
->device
->ds3dl
.vVelocity
, &vDistance
);
313 /* formula taken from Gianicoli D.: Physics, 4th edition: */
314 /* FIXME: replace dsb->freq with appropriate frequency ! */
315 flFreq
= dsb
->freq
* ((DEFAULT_VELOCITY
+ flListenerVel
)/(DEFAULT_VELOCITY
+ flBufferVel
));
316 TRACE("doppler: Buffer velocity (component) = %f, Listener velocity (component) = %f => Doppler shift: %d Hz -> %f Hz\n",
317 flBufferVel
, flListenerVel
, dsb
->freq
, flFreq
);
318 /* FIXME: replace following line with correct frequency setting ! */
320 DSOUND_RecalcFormat(dsb
);
324 for (i
= 0; i
< dsb
->device
->pwfx
->nChannels
; i
++)
325 dsb
->volpan
.dwTotalAmpFactor
[i
] = 0;
327 num_main_speakers
= dsb
->device
->pwfx
->nChannels
;
329 if (dsb
->device
->lfe_channel
!= -1) {
330 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->lfe_channel
] = ingain
;
334 /* adapted from OpenAL's Alc/panning.c */
335 for (i
= 0; i
< num_main_speakers
- 1; i
++)
337 if(flAngle
>= dsb
->device
->speaker_angles
[i
] && flAngle
< dsb
->device
->speaker_angles
[i
+1])
339 /* Sound is between speakers i and i+1 */
340 a
= (flAngle
-dsb
->device
->speaker_angles
[i
]) / (dsb
->device
->speaker_angles
[i
+1]-dsb
->device
->speaker_angles
[i
]);
341 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->speaker_num
[i
]] = sqrtf(1.0f
-a
) * ingain
;
342 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->speaker_num
[i
+1]] = sqrtf(a
) * ingain
;
347 /* Sound is between last and first speakers */
348 if (flAngle
< dsb
->device
->speaker_angles
[0]) { flAngle
+= M_PI
*2.0f
; }
349 a
= (flAngle
-dsb
->device
->speaker_angles
[i
]) / (M_PI
*2.0f
+ dsb
->device
->speaker_angles
[0]-dsb
->device
->speaker_angles
[i
]);
350 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->speaker_num
[i
]] = sqrtf(1.0f
-a
) * ingain
;
351 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->speaker_num
[0]] = sqrtf(a
) * ingain
;
354 static void DSOUND_Mix3DBuffer(IDirectSoundBufferImpl
*dsb
)
358 DSOUND_Calc3DBuffer(dsb
);
361 static void DSOUND_ChangeListener(IDirectSoundBufferImpl
*ds3dl
)
364 TRACE("(%p)\n",ds3dl
);
365 for (i
= 0; i
< ds3dl
->device
->nrofbuffers
; i
++)
367 /* check if this buffer is waiting for recalculation */
368 if (ds3dl
->device
->buffers
[i
]->ds3db_need_recalc
)
370 DSOUND_Mix3DBuffer(ds3dl
->device
->buffers
[i
]);
375 /*******************************************************************************
376 * IDirectSound3DBuffer
378 static inline IDirectSoundBufferImpl
*impl_from_IDirectSound3DBuffer(IDirectSound3DBuffer
*iface
)
380 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSound3DBuffer_iface
);
383 /* IUnknown methods */
384 static HRESULT WINAPI
IDirectSound3DBufferImpl_QueryInterface(IDirectSound3DBuffer
*iface
,
385 REFIID riid
, void **ppobj
)
387 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
389 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
391 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
394 static ULONG WINAPI
IDirectSound3DBufferImpl_AddRef(IDirectSound3DBuffer
*iface
)
396 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
397 ULONG ref
= InterlockedIncrement(&This
->ref3D
);
399 TRACE("(%p) ref was %d\n", This
, ref
- 1);
402 InterlockedIncrement(&This
->numIfaces
);
407 static ULONG WINAPI
IDirectSound3DBufferImpl_Release(IDirectSound3DBuffer
*iface
)
409 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
410 ULONG ref
= InterlockedDecrement(&This
->ref3D
);
412 TRACE("(%p) ref was %d\n", This
, ref
+ 1);
414 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
415 secondarybuffer_destroy(This
);
420 /* IDirectSound3DBuffer methods */
421 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetAllParameters(IDirectSound3DBuffer
*iface
,
422 DS3DBUFFER
*lpDs3dBuffer
)
424 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
426 TRACE("(%p,%p)\n",This
,lpDs3dBuffer
);
428 if (lpDs3dBuffer
== NULL
) {
429 WARN("invalid parameter: lpDs3dBuffer == NULL\n");
430 return DSERR_INVALIDPARAM
;
433 if (lpDs3dBuffer
->dwSize
< sizeof(*lpDs3dBuffer
)) {
434 WARN("invalid parameter: lpDs3dBuffer->dwSize = %d\n",lpDs3dBuffer
->dwSize
);
435 return DSERR_INVALIDPARAM
;
438 TRACE("returning: all parameters\n");
439 *lpDs3dBuffer
= This
->ds3db_ds3db
;
443 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetConeAngles(IDirectSound3DBuffer
*iface
,
444 DWORD
*lpdwInsideConeAngle
, DWORD
*lpdwOutsideConeAngle
)
446 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
448 TRACE("returning: Inside Cone Angle = %d degrees; Outside Cone Angle = %d degrees\n",
449 This
->ds3db_ds3db
.dwInsideConeAngle
, This
->ds3db_ds3db
.dwOutsideConeAngle
);
450 *lpdwInsideConeAngle
= This
->ds3db_ds3db
.dwInsideConeAngle
;
451 *lpdwOutsideConeAngle
= This
->ds3db_ds3db
.dwOutsideConeAngle
;
455 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetConeOrientation(IDirectSound3DBuffer
*iface
,
456 D3DVECTOR
*lpvConeOrientation
)
458 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
460 TRACE("returning: Cone Orientation vector = (%f,%f,%f)\n",
461 This
->ds3db_ds3db
.vConeOrientation
.x
,
462 This
->ds3db_ds3db
.vConeOrientation
.y
,
463 This
->ds3db_ds3db
.vConeOrientation
.z
);
464 *lpvConeOrientation
= This
->ds3db_ds3db
.vConeOrientation
;
468 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetConeOutsideVolume(IDirectSound3DBuffer
*iface
,
469 LONG
*lplConeOutsideVolume
)
471 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
473 TRACE("returning: Cone Outside Volume = %d\n", This
->ds3db_ds3db
.lConeOutsideVolume
);
474 *lplConeOutsideVolume
= This
->ds3db_ds3db
.lConeOutsideVolume
;
478 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetMaxDistance(IDirectSound3DBuffer
*iface
,
479 D3DVALUE
*lpfMaxDistance
)
481 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
483 TRACE("returning: Max Distance = %f\n", This
->ds3db_ds3db
.flMaxDistance
);
484 *lpfMaxDistance
= This
->ds3db_ds3db
.flMaxDistance
;
488 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetMinDistance(IDirectSound3DBuffer
*iface
,
489 D3DVALUE
*lpfMinDistance
)
491 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
493 TRACE("returning: Min Distance = %f\n", This
->ds3db_ds3db
.flMinDistance
);
494 *lpfMinDistance
= This
->ds3db_ds3db
.flMinDistance
;
498 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetMode(IDirectSound3DBuffer
*iface
,
501 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
503 TRACE("returning: Mode = %d\n", This
->ds3db_ds3db
.dwMode
);
504 *lpdwMode
= This
->ds3db_ds3db
.dwMode
;
508 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetPosition(IDirectSound3DBuffer
*iface
,
509 D3DVECTOR
*lpvPosition
)
511 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
513 TRACE("returning: Position vector = (%f,%f,%f)\n", This
->ds3db_ds3db
.vPosition
.x
,
514 This
->ds3db_ds3db
.vPosition
.y
, This
->ds3db_ds3db
.vPosition
.z
);
515 *lpvPosition
= This
->ds3db_ds3db
.vPosition
;
519 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetVelocity(IDirectSound3DBuffer
*iface
,
520 D3DVECTOR
*lpvVelocity
)
522 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
524 TRACE("returning: Velocity vector = (%f,%f,%f)\n", This
->ds3db_ds3db
.vVelocity
.x
,
525 This
->ds3db_ds3db
.vVelocity
.y
, This
->ds3db_ds3db
.vVelocity
.z
);
526 *lpvVelocity
= This
->ds3db_ds3db
.vVelocity
;
530 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetAllParameters(IDirectSound3DBuffer
*iface
,
531 const DS3DBUFFER
*lpcDs3dBuffer
, DWORD dwApply
)
533 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
534 DWORD status
= DSERR_INVALIDPARAM
;
536 TRACE("(%p,%p,%x)\n",iface
,lpcDs3dBuffer
,dwApply
);
538 if (lpcDs3dBuffer
== NULL
) {
539 WARN("invalid parameter: lpcDs3dBuffer == NULL\n");
543 if (lpcDs3dBuffer
->dwSize
!= sizeof(DS3DBUFFER
)) {
544 WARN("invalid parameter: lpcDs3dBuffer->dwSize = %d\n", lpcDs3dBuffer
->dwSize
);
548 TRACE("setting: all parameters; dwApply = %d\n", dwApply
);
549 This
->ds3db_ds3db
= *lpcDs3dBuffer
;
551 if (dwApply
== DS3D_IMMEDIATE
)
553 DSOUND_Mix3DBuffer(This
);
555 This
->ds3db_need_recalc
= TRUE
;
561 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetConeAngles(IDirectSound3DBuffer
*iface
,
562 DWORD dwInsideConeAngle
, DWORD dwOutsideConeAngle
, DWORD dwApply
)
564 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
566 TRACE("setting: Inside Cone Angle = %d; Outside Cone Angle = %d; dwApply = %d\n",
567 dwInsideConeAngle
, dwOutsideConeAngle
, dwApply
);
568 This
->ds3db_ds3db
.dwInsideConeAngle
= dwInsideConeAngle
;
569 This
->ds3db_ds3db
.dwOutsideConeAngle
= dwOutsideConeAngle
;
570 if (dwApply
== DS3D_IMMEDIATE
)
571 DSOUND_Mix3DBuffer(This
);
572 This
->ds3db_need_recalc
= TRUE
;
576 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetConeOrientation(IDirectSound3DBuffer
*iface
,
577 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
579 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
581 TRACE("setting: Cone Orientation vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
582 This
->ds3db_ds3db
.vConeOrientation
.x
= x
;
583 This
->ds3db_ds3db
.vConeOrientation
.y
= y
;
584 This
->ds3db_ds3db
.vConeOrientation
.z
= z
;
585 if (dwApply
== DS3D_IMMEDIATE
)
587 This
->ds3db_need_recalc
= FALSE
;
588 DSOUND_Mix3DBuffer(This
);
590 This
->ds3db_need_recalc
= TRUE
;
594 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetConeOutsideVolume(IDirectSound3DBuffer
*iface
,
595 LONG lConeOutsideVolume
, DWORD dwApply
)
597 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
599 TRACE("setting: ConeOutsideVolume = %d; dwApply = %d\n", lConeOutsideVolume
, dwApply
);
600 This
->ds3db_ds3db
.lConeOutsideVolume
= lConeOutsideVolume
;
601 if (dwApply
== DS3D_IMMEDIATE
)
603 This
->ds3db_need_recalc
= FALSE
;
604 DSOUND_Mix3DBuffer(This
);
606 This
->ds3db_need_recalc
= TRUE
;
610 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetMaxDistance(IDirectSound3DBuffer
*iface
,
611 D3DVALUE fMaxDistance
, DWORD dwApply
)
613 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
615 TRACE("setting: MaxDistance = %f; dwApply = %d\n", fMaxDistance
, dwApply
);
616 This
->ds3db_ds3db
.flMaxDistance
= fMaxDistance
;
617 if (dwApply
== DS3D_IMMEDIATE
)
619 This
->ds3db_need_recalc
= FALSE
;
620 DSOUND_Mix3DBuffer(This
);
622 This
->ds3db_need_recalc
= TRUE
;
626 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetMinDistance(IDirectSound3DBuffer
*iface
,
627 D3DVALUE fMinDistance
, DWORD dwApply
)
629 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
631 TRACE("setting: MinDistance = %f; dwApply = %d\n", fMinDistance
, dwApply
);
632 This
->ds3db_ds3db
.flMinDistance
= fMinDistance
;
633 if (dwApply
== DS3D_IMMEDIATE
)
635 This
->ds3db_need_recalc
= FALSE
;
636 DSOUND_Mix3DBuffer(This
);
638 This
->ds3db_need_recalc
= TRUE
;
642 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetMode(IDirectSound3DBuffer
*iface
, DWORD dwMode
,
645 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
647 TRACE("setting: Mode = %d; dwApply = %d\n", dwMode
, dwApply
);
648 This
->ds3db_ds3db
.dwMode
= dwMode
;
649 if (dwApply
== DS3D_IMMEDIATE
)
651 This
->ds3db_need_recalc
= FALSE
;
652 DSOUND_Mix3DBuffer(This
);
654 This
->ds3db_need_recalc
= TRUE
;
658 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetPosition(IDirectSound3DBuffer
*iface
, D3DVALUE x
,
659 D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
661 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
663 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
664 This
->ds3db_ds3db
.vPosition
.x
= x
;
665 This
->ds3db_ds3db
.vPosition
.y
= y
;
666 This
->ds3db_ds3db
.vPosition
.z
= z
;
667 if (dwApply
== DS3D_IMMEDIATE
)
669 This
->ds3db_need_recalc
= FALSE
;
670 DSOUND_Mix3DBuffer(This
);
672 This
->ds3db_need_recalc
= TRUE
;
676 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetVelocity(IDirectSound3DBuffer
*iface
,
677 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
679 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
681 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
682 This
->ds3db_ds3db
.vVelocity
.x
= x
;
683 This
->ds3db_ds3db
.vVelocity
.y
= y
;
684 This
->ds3db_ds3db
.vVelocity
.z
= z
;
685 if (dwApply
== DS3D_IMMEDIATE
)
687 This
->ds3db_need_recalc
= FALSE
;
688 DSOUND_Mix3DBuffer(This
);
690 This
->ds3db_need_recalc
= TRUE
;
694 const IDirectSound3DBufferVtbl ds3dbvt
=
696 /* IUnknown methods */
697 IDirectSound3DBufferImpl_QueryInterface
,
698 IDirectSound3DBufferImpl_AddRef
,
699 IDirectSound3DBufferImpl_Release
,
700 /* IDirectSound3DBuffer methods */
701 IDirectSound3DBufferImpl_GetAllParameters
,
702 IDirectSound3DBufferImpl_GetConeAngles
,
703 IDirectSound3DBufferImpl_GetConeOrientation
,
704 IDirectSound3DBufferImpl_GetConeOutsideVolume
,
705 IDirectSound3DBufferImpl_GetMaxDistance
,
706 IDirectSound3DBufferImpl_GetMinDistance
,
707 IDirectSound3DBufferImpl_GetMode
,
708 IDirectSound3DBufferImpl_GetPosition
,
709 IDirectSound3DBufferImpl_GetVelocity
,
710 IDirectSound3DBufferImpl_SetAllParameters
,
711 IDirectSound3DBufferImpl_SetConeAngles
,
712 IDirectSound3DBufferImpl_SetConeOrientation
,
713 IDirectSound3DBufferImpl_SetConeOutsideVolume
,
714 IDirectSound3DBufferImpl_SetMaxDistance
,
715 IDirectSound3DBufferImpl_SetMinDistance
,
716 IDirectSound3DBufferImpl_SetMode
,
717 IDirectSound3DBufferImpl_SetPosition
,
718 IDirectSound3DBufferImpl_SetVelocity
,
722 /*******************************************************************************
723 * IDirectSound3DListener
725 static inline IDirectSoundBufferImpl
*impl_from_IDirectSound3DListener(IDirectSound3DListener
*iface
)
727 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSound3DListener_iface
);
731 /* IUnknown methods */
732 static HRESULT WINAPI
IDirectSound3DListenerImpl_QueryInterface(IDirectSound3DListener
*iface
,
733 REFIID riid
, void **ppobj
)
735 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
737 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(riid
), ppobj
);
739 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
742 static ULONG WINAPI
IDirectSound3DListenerImpl_AddRef(IDirectSound3DListener
*iface
)
744 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
745 ULONG ref
= InterlockedIncrement(&This
->ref3D
);
747 TRACE("(%p) ref was %d\n", This
, ref
- 1);
750 InterlockedIncrement(&This
->numIfaces
);
755 static ULONG WINAPI
IDirectSound3DListenerImpl_Release(IDirectSound3DListener
*iface
)
757 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
760 ref
= capped_refcount_dec(&This
->ref3D
);
762 capped_refcount_dec(&This
->numIfaces
);
764 TRACE("(%p) ref is now %d\n", This
, ref
);
769 /* IDirectSound3DListener methods */
770 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetAllParameter(IDirectSound3DListener
*iface
,
771 DS3DLISTENER
*lpDS3DL
)
773 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
775 TRACE("(%p,%p)\n",This
,lpDS3DL
);
777 if (lpDS3DL
== NULL
) {
778 WARN("invalid parameter: lpDS3DL == NULL\n");
779 return DSERR_INVALIDPARAM
;
782 if (lpDS3DL
->dwSize
< sizeof(*lpDS3DL
)) {
783 WARN("invalid parameter: lpDS3DL->dwSize = %d\n",lpDS3DL
->dwSize
);
784 return DSERR_INVALIDPARAM
;
787 TRACE("returning: all parameters\n");
788 *lpDS3DL
= This
->device
->ds3dl
;
792 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetDistanceFactor(IDirectSound3DListener
*iface
,
793 D3DVALUE
*lpfDistanceFactor
)
795 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
797 TRACE("returning: Distance Factor = %f\n", This
->device
->ds3dl
.flDistanceFactor
);
798 *lpfDistanceFactor
= This
->device
->ds3dl
.flDistanceFactor
;
802 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetDopplerFactor(IDirectSound3DListener
*iface
,
803 D3DVALUE
*lpfDopplerFactor
)
805 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
807 TRACE("returning: Doppler Factor = %f\n", This
->device
->ds3dl
.flDopplerFactor
);
808 *lpfDopplerFactor
= This
->device
->ds3dl
.flDopplerFactor
;
812 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetOrientation(IDirectSound3DListener
*iface
,
813 D3DVECTOR
*lpvOrientFront
, D3DVECTOR
*lpvOrientTop
)
815 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
817 TRACE("returning: OrientFront vector = (%f,%f,%f); OrientTop vector = (%f,%f,%f)\n", This
->device
->ds3dl
.vOrientFront
.x
,
818 This
->device
->ds3dl
.vOrientFront
.y
, This
->device
->ds3dl
.vOrientFront
.z
, This
->device
->ds3dl
.vOrientTop
.x
, This
->device
->ds3dl
.vOrientTop
.y
,
819 This
->device
->ds3dl
.vOrientTop
.z
);
820 *lpvOrientFront
= This
->device
->ds3dl
.vOrientFront
;
821 *lpvOrientTop
= This
->device
->ds3dl
.vOrientTop
;
825 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetPosition(IDirectSound3DListener
*iface
,
826 D3DVECTOR
*lpvPosition
)
828 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
830 TRACE("returning: Position vector = (%f,%f,%f)\n", This
->device
->ds3dl
.vPosition
.x
, This
->device
->ds3dl
.vPosition
.y
, This
->device
->ds3dl
.vPosition
.z
);
831 *lpvPosition
= This
->device
->ds3dl
.vPosition
;
835 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetRolloffFactor(IDirectSound3DListener
*iface
,
836 D3DVALUE
*lpfRolloffFactor
)
838 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
840 TRACE("returning: RolloffFactor = %f\n", This
->device
->ds3dl
.flRolloffFactor
);
841 *lpfRolloffFactor
= This
->device
->ds3dl
.flRolloffFactor
;
845 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetVelocity(IDirectSound3DListener
*iface
,
846 D3DVECTOR
*lpvVelocity
)
848 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
850 TRACE("returning: Velocity vector = (%f,%f,%f)\n", This
->device
->ds3dl
.vVelocity
.x
, This
->device
->ds3dl
.vVelocity
.y
, This
->device
->ds3dl
.vVelocity
.z
);
851 *lpvVelocity
= This
->device
->ds3dl
.vVelocity
;
855 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetAllParameters(IDirectSound3DListener
*iface
,
856 const DS3DLISTENER
*lpcDS3DL
, DWORD dwApply
)
858 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
860 TRACE("setting: all parameters; dwApply = %d\n", dwApply
);
861 This
->device
->ds3dl
= *lpcDS3DL
;
862 if (dwApply
== DS3D_IMMEDIATE
)
864 This
->device
->ds3dl_need_recalc
= FALSE
;
865 DSOUND_ChangeListener(This
);
867 This
->device
->ds3dl_need_recalc
= TRUE
;
871 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetDistanceFactor(IDirectSound3DListener
*iface
,
872 D3DVALUE fDistanceFactor
, DWORD dwApply
)
874 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
876 TRACE("setting: Distance Factor = %f; dwApply = %d\n", fDistanceFactor
, dwApply
);
877 This
->device
->ds3dl
.flDistanceFactor
= fDistanceFactor
;
878 if (dwApply
== DS3D_IMMEDIATE
)
880 This
->device
->ds3dl_need_recalc
= FALSE
;
881 DSOUND_ChangeListener(This
);
883 This
->device
->ds3dl_need_recalc
= TRUE
;
887 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetDopplerFactor(IDirectSound3DListener
*iface
,
888 D3DVALUE fDopplerFactor
, DWORD dwApply
)
890 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
892 TRACE("setting: Doppler Factor = %f; dwApply = %d\n", fDopplerFactor
, dwApply
);
893 This
->device
->ds3dl
.flDopplerFactor
= fDopplerFactor
;
894 if (dwApply
== DS3D_IMMEDIATE
)
896 This
->device
->ds3dl_need_recalc
= FALSE
;
897 DSOUND_ChangeListener(This
);
899 This
->device
->ds3dl_need_recalc
= TRUE
;
903 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetOrientation(IDirectSound3DListener
*iface
,
904 D3DVALUE xFront
, D3DVALUE yFront
, D3DVALUE zFront
, D3DVALUE xTop
, D3DVALUE yTop
,
905 D3DVALUE zTop
, DWORD dwApply
)
907 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
909 TRACE("setting: Front vector = (%f,%f,%f); Top vector = (%f,%f,%f); dwApply = %d\n",
910 xFront
, yFront
, zFront
, xTop
, yTop
, zTop
, dwApply
);
911 This
->device
->ds3dl
.vOrientFront
.x
= xFront
;
912 This
->device
->ds3dl
.vOrientFront
.y
= yFront
;
913 This
->device
->ds3dl
.vOrientFront
.z
= zFront
;
914 This
->device
->ds3dl
.vOrientTop
.x
= xTop
;
915 This
->device
->ds3dl
.vOrientTop
.y
= yTop
;
916 This
->device
->ds3dl
.vOrientTop
.z
= zTop
;
917 if (dwApply
== DS3D_IMMEDIATE
)
919 This
->device
->ds3dl_need_recalc
= FALSE
;
920 DSOUND_ChangeListener(This
);
922 This
->device
->ds3dl_need_recalc
= TRUE
;
926 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetPosition(IDirectSound3DListener
*iface
,
927 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
929 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
931 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
932 This
->device
->ds3dl
.vPosition
.x
= x
;
933 This
->device
->ds3dl
.vPosition
.y
= y
;
934 This
->device
->ds3dl
.vPosition
.z
= z
;
935 if (dwApply
== DS3D_IMMEDIATE
)
937 This
->device
->ds3dl_need_recalc
= FALSE
;
938 DSOUND_ChangeListener(This
);
940 This
->device
->ds3dl_need_recalc
= TRUE
;
944 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetRolloffFactor(IDirectSound3DListener
*iface
,
945 D3DVALUE fRolloffFactor
, DWORD dwApply
)
947 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
949 TRACE("setting: Rolloff Factor = %f; dwApply = %d\n", fRolloffFactor
, dwApply
);
950 This
->device
->ds3dl
.flRolloffFactor
= fRolloffFactor
;
951 if (dwApply
== DS3D_IMMEDIATE
)
953 This
->device
->ds3dl_need_recalc
= FALSE
;
954 DSOUND_ChangeListener(This
);
956 This
->device
->ds3dl_need_recalc
= TRUE
;
960 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetVelocity(IDirectSound3DListener
*iface
,
961 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
963 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
965 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
966 This
->device
->ds3dl
.vVelocity
.x
= x
;
967 This
->device
->ds3dl
.vVelocity
.y
= y
;
968 This
->device
->ds3dl
.vVelocity
.z
= z
;
969 if (dwApply
== DS3D_IMMEDIATE
)
971 This
->device
->ds3dl_need_recalc
= FALSE
;
972 DSOUND_ChangeListener(This
);
974 This
->device
->ds3dl_need_recalc
= TRUE
;
978 static HRESULT WINAPI
IDirectSound3DListenerImpl_CommitDeferredSettings(IDirectSound3DListener
*iface
)
980 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
983 DSOUND_ChangeListener(This
);
987 const IDirectSound3DListenerVtbl ds3dlvt
=
989 /* IUnknown methods */
990 IDirectSound3DListenerImpl_QueryInterface
,
991 IDirectSound3DListenerImpl_AddRef
,
992 IDirectSound3DListenerImpl_Release
,
993 /* IDirectSound3DListener methods */
994 IDirectSound3DListenerImpl_GetAllParameter
,
995 IDirectSound3DListenerImpl_GetDistanceFactor
,
996 IDirectSound3DListenerImpl_GetDopplerFactor
,
997 IDirectSound3DListenerImpl_GetOrientation
,
998 IDirectSound3DListenerImpl_GetPosition
,
999 IDirectSound3DListenerImpl_GetRolloffFactor
,
1000 IDirectSound3DListenerImpl_GetVelocity
,
1001 IDirectSound3DListenerImpl_SetAllParameters
,
1002 IDirectSound3DListenerImpl_SetDistanceFactor
,
1003 IDirectSound3DListenerImpl_SetDopplerFactor
,
1004 IDirectSound3DListenerImpl_SetOrientation
,
1005 IDirectSound3DListenerImpl_SetPosition
,
1006 IDirectSound3DListenerImpl_SetRolloffFactor
,
1007 IDirectSound3DListenerImpl_SetVelocity
,
1008 IDirectSound3DListenerImpl_CommitDeferredSettings
,