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
);
115 TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians (%f degrees)\n", a
->x
, a
->y
, a
->z
, b
->x
,
116 b
->y
, b
->z
, angle
, RadToDeg(angle
));
120 static inline D3DVALUE
AngleBetweenVectorsDeg (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
122 return RadToDeg(AngleBetweenVectorsRad(a
, b
));
125 /* calculates vector between two points */
126 static inline D3DVECTOR
VectorBetweenTwoPoints (const D3DVECTOR
*a
, const D3DVECTOR
*b
)
132 TRACE("A (%f,%f,%f), B (%f,%f,%f), AB = (%f,%f,%f)\n", a
->x
, a
->y
, a
->z
, b
->x
, b
->y
,
133 b
->z
, c
.x
, c
.y
, c
.z
);
137 /* calculates the length of vector's projection on another vector */
138 static inline D3DVALUE
ProjectVector (const D3DVECTOR
*a
, const D3DVECTOR
*p
)
140 D3DVALUE prod
, result
;
141 prod
= ScalarProduct(a
, p
);
142 result
= prod
/VectorMagnitude(p
);
143 TRACE("length projection of (%f,%f,%f) on (%f,%f,%f) = %f\n", a
->x
, a
->y
, a
->z
, p
->x
,
148 /*******************************************************************************
149 * 3D Buffer and Listener mixing
152 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
)
154 /* volume, at which the sound will be played after all calcs. */
155 D3DVALUE lVolume
= 0;
156 /* stuff for distance related stuff calc. */
158 D3DVALUE flDistance
= 0;
159 /* panning related stuff */
160 D3DVALUE flAngle
, flAngle2
;
162 int i
, num_main_speakers
;
164 /* doppler shift related stuff */
168 /* initial buffer volume */
169 lVolume
= dsb
->ds3db_lVolume
;
171 switch (dsb
->ds3db_ds3db
.dwMode
)
173 case DS3DMODE_NORMAL
:
174 TRACE("Normal 3D processing mode\n");
175 /* we need to calculate distance between buffer and listener*/
176 vDistance
= VectorBetweenTwoPoints(&dsb
->device
->ds3dl
.vPosition
, &dsb
->ds3db_ds3db
.vPosition
);
177 flDistance
= VectorMagnitude (&vDistance
);
179 case DS3DMODE_HEADRELATIVE
:
180 TRACE("Head-relative 3D processing mode\n");
181 /* distance between buffer and listener is same as buffer's position */
182 vDistance
= dsb
->ds3db_ds3db
.vPosition
;
183 flDistance
= VectorMagnitude (&vDistance
);
186 TRACE("3D processing disabled\n");
187 /* this one is here only to eliminate annoying warning message */
188 dsb
->volpan
.lVolume
= dsb
->ds3db_lVolume
;
189 DSOUND_RecalcVolPan (&dsb
->volpan
);
193 if (flDistance
> dsb
->ds3db_ds3db
.flMaxDistance
)
195 /* some apps don't want you to hear too distant sounds... */
196 if (dsb
->dsbd
.dwFlags
& DSBCAPS_MUTE3DATMAXDISTANCE
)
198 dsb
->volpan
.lVolume
= DSBVOLUME_MIN
;
199 DSOUND_RecalcVolPan (&dsb
->volpan
);
200 /* i guess mixing here would be a waste of power */
204 flDistance
= dsb
->ds3db_ds3db
.flMaxDistance
;
207 if (flDistance
< dsb
->ds3db_ds3db
.flMinDistance
)
208 flDistance
= dsb
->ds3db_ds3db
.flMinDistance
;
210 flDistance
= dsb
->ds3db_ds3db
.flMinDistance
+ (flDistance
- dsb
->ds3db_ds3db
.flMinDistance
) * dsb
->device
->ds3dl
.flRolloffFactor
;
212 /* attenuation proportional to the distance squared, converted to millibels as in lVolume*/
213 lVolume
-= log10(flDistance
/dsb
->ds3db_ds3db
.flMinDistance
* flDistance
/dsb
->ds3db_ds3db
.flMinDistance
)*1000;
214 TRACE("dist. att: Distance = %f, MinDistance = %f => adjusting volume %d to %f\n", flDistance
, dsb
->ds3db_ds3db
.flMinDistance
, dsb
->ds3db_lVolume
, lVolume
);
217 /* sometimes it happens that vConeOrientation vector = (0,0,0); in this case angle is "nan" and it's useless*/
218 if (dsb
->ds3db_ds3db
.vConeOrientation
.x
== 0 && dsb
->ds3db_ds3db
.vConeOrientation
.y
== 0 && dsb
->ds3db_ds3db
.vConeOrientation
.z
== 0)
220 TRACE("conning: cones not set\n");
224 D3DVECTOR vDistanceInv
;
226 vDistanceInv
.x
= -vDistance
.x
;
227 vDistanceInv
.y
= -vDistance
.y
;
228 vDistanceInv
.z
= -vDistance
.z
;
230 /* calculate angle */
231 flAngle
= AngleBetweenVectorsDeg(&dsb
->ds3db_ds3db
.vConeOrientation
, &vDistanceInv
);
232 /* if by any chance it happens that OutsideConeAngle = InsideConeAngle (that means that conning has no effect) */
233 if (dsb
->ds3db_ds3db
.dwInsideConeAngle
!= dsb
->ds3db_ds3db
.dwOutsideConeAngle
)
235 /* my test show that for my way of calc., we need only half of angles */
236 DWORD dwInsideConeAngle
= dsb
->ds3db_ds3db
.dwInsideConeAngle
/2;
237 DWORD dwOutsideConeAngle
= dsb
->ds3db_ds3db
.dwOutsideConeAngle
/2;
238 if (dwOutsideConeAngle
== dwInsideConeAngle
)
239 ++dwOutsideConeAngle
;
242 if (flAngle
< dwInsideConeAngle
)
243 flAngle
= dwInsideConeAngle
;
244 /* min (app defined) volume */
245 if (flAngle
> dwOutsideConeAngle
)
246 flAngle
= dwOutsideConeAngle
;
247 /* this probably isn't the right thing, but it's ok for the time being */
248 lVolume
+= ((flAngle
- dwInsideConeAngle
)/(dwOutsideConeAngle
- dwInsideConeAngle
)) * dsb
->ds3db_ds3db
.lConeOutsideVolume
;
250 TRACE("conning: Angle = %f deg; InsideConeAngle(/2) = %d deg; OutsideConeAngle(/2) = %d deg; ConeOutsideVolume = %d => adjusting volume to %f\n",
251 flAngle
, dsb
->ds3db_ds3db
.dwInsideConeAngle
/2, dsb
->ds3db_ds3db
.dwOutsideConeAngle
/2, dsb
->ds3db_ds3db
.lConeOutsideVolume
, lVolume
);
253 dsb
->volpan
.lVolume
= lVolume
;
255 ingain
= pow(2.0, dsb
->volpan
.lVolume
/ 600.0) * 0xffff;
257 if (dsb
->device
->pwfx
->nChannels
== 1)
259 dsb
->volpan
.dwTotalAmpFactor
[0] = ingain
;
264 if (vDistance
.x
== 0.0f
&& vDistance
.y
== 0.0f
&& vDistance
.z
== 0.0f
)
268 vLeft
= VectorProduct(&dsb
->device
->ds3dl
.vOrientFront
, &dsb
->device
->ds3dl
.vOrientTop
);
269 /* To calculate angle to sound source we need to:
270 * 1) Get angle between vDistance and a plane on which angle to sound source should be 0.
271 * Such a plane is given by vectors vOrientFront and vOrientTop, and angle between vector
272 * and a plane equals to M_PI_2 - angle between vector and normal to this plane (vLeft in this case).
273 * 2) Determine if the source is behind or in front of us by calculating angle between vDistance
276 flAngle
= AngleBetweenVectorsRad(&vLeft
, &vDistance
);
277 flAngle2
= AngleBetweenVectorsRad(&dsb
->device
->ds3dl
.vOrientFront
, &vDistance
);
278 if (flAngle2
> M_PI_2
)
284 TRACE("panning: Angle = %f rad, lPan = %d\n", flAngle
, dsb
->volpan
.lPan
);
286 /* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */
289 D3DVALUE flFreq
, flBufferVel
, flListenerVel
;
291 if (!VectorMagnitude(&dsb
->ds3db_ds3db
.vVelocity
) && !VectorMagnitude(&dsb
->device
->ds3dl
.vVelocity
))
293 TRACE("doppler: Buffer and Listener don't have velocities\n");
295 else if (!(dsb
->ds3db_ds3db
.vVelocity
.x
== dsb
->device
->ds3dl
.vVelocity
.x
&&
296 dsb
->ds3db_ds3db
.vVelocity
.y
== dsb
->device
->ds3dl
.vVelocity
.y
&&
297 dsb
->ds3db_ds3db
.vVelocity
.z
== dsb
->device
->ds3dl
.vVelocity
.z
))
299 /* calculate length of ds3db_ds3db.vVelocity component which causes Doppler Effect
300 NOTE: if buffer moves TOWARDS the listener, its velocity component is NEGATIVE
301 if buffer moves AWAY from listener, its velocity component is POSITIVE */
302 flBufferVel
= ProjectVector(&dsb
->ds3db_ds3db
.vVelocity
, &vDistance
);
303 /* calculate length of ds3dl.vVelocity component which causes Doppler Effect
304 NOTE: if listener moves TOWARDS the buffer, its velocity component is POSITIVE
305 if listener moves AWAY from buffer, its velocity component is NEGATIVE */
306 flListenerVel
= ProjectVector(&dsb
->device
->ds3dl
.vVelocity
, &vDistance
);
307 /* formula taken from Gianicoli D.: Physics, 4th edition: */
308 /* FIXME: replace dsb->freq with appropriate frequency ! */
309 flFreq
= dsb
->freq
* ((DEFAULT_VELOCITY
+ flListenerVel
)/(DEFAULT_VELOCITY
+ flBufferVel
));
310 TRACE("doppler: Buffer velocity (component) = %f, Listener velocity (component) = %f => Doppler shift: %d Hz -> %f Hz\n",
311 flBufferVel
, flListenerVel
, dsb
->freq
, flFreq
);
312 /* FIXME: replace following line with correct frequency setting ! */
314 DSOUND_RecalcFormat(dsb
);
318 for (i
= 0; i
< dsb
->device
->pwfx
->nChannels
; i
++)
319 dsb
->volpan
.dwTotalAmpFactor
[i
] = 0;
321 num_main_speakers
= dsb
->device
->pwfx
->nChannels
;
323 if (dsb
->device
->lfe_channel
!= -1) {
324 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->lfe_channel
] = ingain
;
328 /* adapted from OpenAL's Alc/panning.c */
329 for (i
= 0; i
< num_main_speakers
- 1; i
++)
331 if(flAngle
>= dsb
->device
->speaker_angles
[i
] && flAngle
< dsb
->device
->speaker_angles
[i
+1])
333 /* Sound is between speakers i and i+1 */
334 a
= (flAngle
-dsb
->device
->speaker_angles
[i
]) / (dsb
->device
->speaker_angles
[i
+1]-dsb
->device
->speaker_angles
[i
]);
335 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->speaker_num
[i
]] = sqrtf(1.0f
-a
) * ingain
;
336 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->speaker_num
[i
+1]] = sqrtf(a
) * ingain
;
341 /* Sound is between last and first speakers */
342 if (flAngle
< dsb
->device
->speaker_angles
[0]) { flAngle
+= M_PI
*2.0f
; }
343 a
= (flAngle
-dsb
->device
->speaker_angles
[i
]) / (M_PI
*2.0f
+ dsb
->device
->speaker_angles
[0]-dsb
->device
->speaker_angles
[i
]);
344 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->speaker_num
[i
]] = sqrtf(1.0f
-a
) * ingain
;
345 dsb
->volpan
.dwTotalAmpFactor
[dsb
->device
->speaker_num
[0]] = sqrtf(a
) * ingain
;
348 static void DSOUND_Mix3DBuffer(IDirectSoundBufferImpl
*dsb
)
352 DSOUND_Calc3DBuffer(dsb
);
355 static void DSOUND_ChangeListener(IDirectSoundBufferImpl
*ds3dl
)
358 TRACE("(%p)\n",ds3dl
);
359 for (i
= 0; i
< ds3dl
->device
->nrofbuffers
; i
++)
361 /* check if this buffer is waiting for recalculation */
362 if (ds3dl
->device
->buffers
[i
]->ds3db_need_recalc
)
364 DSOUND_Mix3DBuffer(ds3dl
->device
->buffers
[i
]);
369 /*******************************************************************************
370 * IDirectSound3DBuffer
372 static inline IDirectSoundBufferImpl
*impl_from_IDirectSound3DBuffer(IDirectSound3DBuffer
*iface
)
374 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSound3DBuffer_iface
);
377 /* IUnknown methods */
378 static HRESULT WINAPI
IDirectSound3DBufferImpl_QueryInterface(IDirectSound3DBuffer
*iface
,
379 REFIID riid
, void **ppobj
)
381 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
383 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
385 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
388 static ULONG WINAPI
IDirectSound3DBufferImpl_AddRef(IDirectSound3DBuffer
*iface
)
390 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
391 ULONG ref
= InterlockedIncrement(&This
->ref3D
);
393 TRACE("(%p) ref was %d\n", This
, ref
- 1);
396 InterlockedIncrement(&This
->numIfaces
);
401 static ULONG WINAPI
IDirectSound3DBufferImpl_Release(IDirectSound3DBuffer
*iface
)
403 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
404 ULONG ref
= InterlockedDecrement(&This
->ref3D
);
406 TRACE("(%p) ref was %d\n", This
, ref
+ 1);
408 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
409 secondarybuffer_destroy(This
);
414 /* IDirectSound3DBuffer methods */
415 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetAllParameters(IDirectSound3DBuffer
*iface
,
416 DS3DBUFFER
*lpDs3dBuffer
)
418 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
420 TRACE("(%p,%p)\n",This
,lpDs3dBuffer
);
422 if (lpDs3dBuffer
== NULL
) {
423 WARN("invalid parameter: lpDs3dBuffer == NULL\n");
424 return DSERR_INVALIDPARAM
;
427 if (lpDs3dBuffer
->dwSize
< sizeof(*lpDs3dBuffer
)) {
428 WARN("invalid parameter: lpDs3dBuffer->dwSize = %d\n",lpDs3dBuffer
->dwSize
);
429 return DSERR_INVALIDPARAM
;
432 TRACE("returning: all parameters\n");
433 *lpDs3dBuffer
= This
->ds3db_ds3db
;
437 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetConeAngles(IDirectSound3DBuffer
*iface
,
438 DWORD
*lpdwInsideConeAngle
, DWORD
*lpdwOutsideConeAngle
)
440 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
442 TRACE("returning: Inside Cone Angle = %d degrees; Outside Cone Angle = %d degrees\n",
443 This
->ds3db_ds3db
.dwInsideConeAngle
, This
->ds3db_ds3db
.dwOutsideConeAngle
);
444 *lpdwInsideConeAngle
= This
->ds3db_ds3db
.dwInsideConeAngle
;
445 *lpdwOutsideConeAngle
= This
->ds3db_ds3db
.dwOutsideConeAngle
;
449 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetConeOrientation(IDirectSound3DBuffer
*iface
,
450 D3DVECTOR
*lpvConeOrientation
)
452 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
454 TRACE("returning: Cone Orientation vector = (%f,%f,%f)\n",
455 This
->ds3db_ds3db
.vConeOrientation
.x
,
456 This
->ds3db_ds3db
.vConeOrientation
.y
,
457 This
->ds3db_ds3db
.vConeOrientation
.z
);
458 *lpvConeOrientation
= This
->ds3db_ds3db
.vConeOrientation
;
462 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetConeOutsideVolume(IDirectSound3DBuffer
*iface
,
463 LONG
*lplConeOutsideVolume
)
465 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
467 TRACE("returning: Cone Outside Volume = %d\n", This
->ds3db_ds3db
.lConeOutsideVolume
);
468 *lplConeOutsideVolume
= This
->ds3db_ds3db
.lConeOutsideVolume
;
472 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetMaxDistance(IDirectSound3DBuffer
*iface
,
473 D3DVALUE
*lpfMaxDistance
)
475 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
477 TRACE("returning: Max Distance = %f\n", This
->ds3db_ds3db
.flMaxDistance
);
478 *lpfMaxDistance
= This
->ds3db_ds3db
.flMaxDistance
;
482 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetMinDistance(IDirectSound3DBuffer
*iface
,
483 D3DVALUE
*lpfMinDistance
)
485 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
487 TRACE("returning: Min Distance = %f\n", This
->ds3db_ds3db
.flMinDistance
);
488 *lpfMinDistance
= This
->ds3db_ds3db
.flMinDistance
;
492 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetMode(IDirectSound3DBuffer
*iface
,
495 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
497 TRACE("returning: Mode = %d\n", This
->ds3db_ds3db
.dwMode
);
498 *lpdwMode
= This
->ds3db_ds3db
.dwMode
;
502 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetPosition(IDirectSound3DBuffer
*iface
,
503 D3DVECTOR
*lpvPosition
)
505 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
507 TRACE("returning: Position vector = (%f,%f,%f)\n", This
->ds3db_ds3db
.vPosition
.x
,
508 This
->ds3db_ds3db
.vPosition
.y
, This
->ds3db_ds3db
.vPosition
.z
);
509 *lpvPosition
= This
->ds3db_ds3db
.vPosition
;
513 static HRESULT WINAPI
IDirectSound3DBufferImpl_GetVelocity(IDirectSound3DBuffer
*iface
,
514 D3DVECTOR
*lpvVelocity
)
516 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
518 TRACE("returning: Velocity vector = (%f,%f,%f)\n", This
->ds3db_ds3db
.vVelocity
.x
,
519 This
->ds3db_ds3db
.vVelocity
.y
, This
->ds3db_ds3db
.vVelocity
.z
);
520 *lpvVelocity
= This
->ds3db_ds3db
.vVelocity
;
524 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetAllParameters(IDirectSound3DBuffer
*iface
,
525 const DS3DBUFFER
*lpcDs3dBuffer
, DWORD dwApply
)
527 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
528 DWORD status
= DSERR_INVALIDPARAM
;
530 TRACE("(%p,%p,%x)\n",iface
,lpcDs3dBuffer
,dwApply
);
532 if (lpcDs3dBuffer
== NULL
) {
533 WARN("invalid parameter: lpcDs3dBuffer == NULL\n");
537 if (lpcDs3dBuffer
->dwSize
!= sizeof(DS3DBUFFER
)) {
538 WARN("invalid parameter: lpcDs3dBuffer->dwSize = %d\n", lpcDs3dBuffer
->dwSize
);
542 TRACE("setting: all parameters; dwApply = %d\n", dwApply
);
543 This
->ds3db_ds3db
= *lpcDs3dBuffer
;
545 if (dwApply
== DS3D_IMMEDIATE
)
547 DSOUND_Mix3DBuffer(This
);
549 This
->ds3db_need_recalc
= TRUE
;
555 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetConeAngles(IDirectSound3DBuffer
*iface
,
556 DWORD dwInsideConeAngle
, DWORD dwOutsideConeAngle
, DWORD dwApply
)
558 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
560 TRACE("setting: Inside Cone Angle = %d; Outside Cone Angle = %d; dwApply = %d\n",
561 dwInsideConeAngle
, dwOutsideConeAngle
, dwApply
);
562 This
->ds3db_ds3db
.dwInsideConeAngle
= dwInsideConeAngle
;
563 This
->ds3db_ds3db
.dwOutsideConeAngle
= dwOutsideConeAngle
;
564 if (dwApply
== DS3D_IMMEDIATE
)
565 DSOUND_Mix3DBuffer(This
);
566 This
->ds3db_need_recalc
= TRUE
;
570 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetConeOrientation(IDirectSound3DBuffer
*iface
,
571 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
573 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
575 TRACE("setting: Cone Orientation vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
576 This
->ds3db_ds3db
.vConeOrientation
.x
= x
;
577 This
->ds3db_ds3db
.vConeOrientation
.y
= y
;
578 This
->ds3db_ds3db
.vConeOrientation
.z
= z
;
579 if (dwApply
== DS3D_IMMEDIATE
)
581 This
->ds3db_need_recalc
= FALSE
;
582 DSOUND_Mix3DBuffer(This
);
584 This
->ds3db_need_recalc
= TRUE
;
588 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetConeOutsideVolume(IDirectSound3DBuffer
*iface
,
589 LONG lConeOutsideVolume
, DWORD dwApply
)
591 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
593 TRACE("setting: ConeOutsideVolume = %d; dwApply = %d\n", lConeOutsideVolume
, dwApply
);
594 This
->ds3db_ds3db
.lConeOutsideVolume
= lConeOutsideVolume
;
595 if (dwApply
== DS3D_IMMEDIATE
)
597 This
->ds3db_need_recalc
= FALSE
;
598 DSOUND_Mix3DBuffer(This
);
600 This
->ds3db_need_recalc
= TRUE
;
604 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetMaxDistance(IDirectSound3DBuffer
*iface
,
605 D3DVALUE fMaxDistance
, DWORD dwApply
)
607 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
609 TRACE("setting: MaxDistance = %f; dwApply = %d\n", fMaxDistance
, dwApply
);
610 This
->ds3db_ds3db
.flMaxDistance
= fMaxDistance
;
611 if (dwApply
== DS3D_IMMEDIATE
)
613 This
->ds3db_need_recalc
= FALSE
;
614 DSOUND_Mix3DBuffer(This
);
616 This
->ds3db_need_recalc
= TRUE
;
620 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetMinDistance(IDirectSound3DBuffer
*iface
,
621 D3DVALUE fMinDistance
, DWORD dwApply
)
623 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
625 TRACE("setting: MinDistance = %f; dwApply = %d\n", fMinDistance
, dwApply
);
626 This
->ds3db_ds3db
.flMinDistance
= fMinDistance
;
627 if (dwApply
== DS3D_IMMEDIATE
)
629 This
->ds3db_need_recalc
= FALSE
;
630 DSOUND_Mix3DBuffer(This
);
632 This
->ds3db_need_recalc
= TRUE
;
636 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetMode(IDirectSound3DBuffer
*iface
, DWORD dwMode
,
639 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
641 TRACE("setting: Mode = %d; dwApply = %d\n", dwMode
, dwApply
);
642 This
->ds3db_ds3db
.dwMode
= dwMode
;
643 if (dwApply
== DS3D_IMMEDIATE
)
645 This
->ds3db_need_recalc
= FALSE
;
646 DSOUND_Mix3DBuffer(This
);
648 This
->ds3db_need_recalc
= TRUE
;
652 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetPosition(IDirectSound3DBuffer
*iface
, D3DVALUE x
,
653 D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
655 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
657 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
658 This
->ds3db_ds3db
.vPosition
.x
= x
;
659 This
->ds3db_ds3db
.vPosition
.y
= y
;
660 This
->ds3db_ds3db
.vPosition
.z
= z
;
661 if (dwApply
== DS3D_IMMEDIATE
)
663 This
->ds3db_need_recalc
= FALSE
;
664 DSOUND_Mix3DBuffer(This
);
666 This
->ds3db_need_recalc
= TRUE
;
670 static HRESULT WINAPI
IDirectSound3DBufferImpl_SetVelocity(IDirectSound3DBuffer
*iface
,
671 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
673 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DBuffer(iface
);
675 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
676 This
->ds3db_ds3db
.vVelocity
.x
= x
;
677 This
->ds3db_ds3db
.vVelocity
.y
= y
;
678 This
->ds3db_ds3db
.vVelocity
.z
= z
;
679 if (dwApply
== DS3D_IMMEDIATE
)
681 This
->ds3db_need_recalc
= FALSE
;
682 DSOUND_Mix3DBuffer(This
);
684 This
->ds3db_need_recalc
= TRUE
;
688 const IDirectSound3DBufferVtbl ds3dbvt
=
690 /* IUnknown methods */
691 IDirectSound3DBufferImpl_QueryInterface
,
692 IDirectSound3DBufferImpl_AddRef
,
693 IDirectSound3DBufferImpl_Release
,
694 /* IDirectSound3DBuffer methods */
695 IDirectSound3DBufferImpl_GetAllParameters
,
696 IDirectSound3DBufferImpl_GetConeAngles
,
697 IDirectSound3DBufferImpl_GetConeOrientation
,
698 IDirectSound3DBufferImpl_GetConeOutsideVolume
,
699 IDirectSound3DBufferImpl_GetMaxDistance
,
700 IDirectSound3DBufferImpl_GetMinDistance
,
701 IDirectSound3DBufferImpl_GetMode
,
702 IDirectSound3DBufferImpl_GetPosition
,
703 IDirectSound3DBufferImpl_GetVelocity
,
704 IDirectSound3DBufferImpl_SetAllParameters
,
705 IDirectSound3DBufferImpl_SetConeAngles
,
706 IDirectSound3DBufferImpl_SetConeOrientation
,
707 IDirectSound3DBufferImpl_SetConeOutsideVolume
,
708 IDirectSound3DBufferImpl_SetMaxDistance
,
709 IDirectSound3DBufferImpl_SetMinDistance
,
710 IDirectSound3DBufferImpl_SetMode
,
711 IDirectSound3DBufferImpl_SetPosition
,
712 IDirectSound3DBufferImpl_SetVelocity
,
716 /*******************************************************************************
717 * IDirectSound3DListener
719 static inline IDirectSoundBufferImpl
*impl_from_IDirectSound3DListener(IDirectSound3DListener
*iface
)
721 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSound3DListener_iface
);
725 /* IUnknown methods */
726 static HRESULT WINAPI
IDirectSound3DListenerImpl_QueryInterface(IDirectSound3DListener
*iface
,
727 REFIID riid
, void **ppobj
)
729 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
731 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(riid
), ppobj
);
733 return IDirectSoundBuffer_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
736 static ULONG WINAPI
IDirectSound3DListenerImpl_AddRef(IDirectSound3DListener
*iface
)
738 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
739 ULONG ref
= InterlockedIncrement(&This
->ref3D
);
741 TRACE("(%p) ref was %d\n", This
, ref
- 1);
744 InterlockedIncrement(&This
->numIfaces
);
749 static ULONG WINAPI
IDirectSound3DListenerImpl_Release(IDirectSound3DListener
*iface
)
751 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
754 ref
= capped_refcount_dec(&This
->ref3D
);
756 capped_refcount_dec(&This
->numIfaces
);
758 TRACE("(%p) ref is now %d\n", This
, ref
);
763 /* IDirectSound3DListener methods */
764 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetAllParameter(IDirectSound3DListener
*iface
,
765 DS3DLISTENER
*lpDS3DL
)
767 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
769 TRACE("(%p,%p)\n",This
,lpDS3DL
);
771 if (lpDS3DL
== NULL
) {
772 WARN("invalid parameter: lpDS3DL == NULL\n");
773 return DSERR_INVALIDPARAM
;
776 if (lpDS3DL
->dwSize
< sizeof(*lpDS3DL
)) {
777 WARN("invalid parameter: lpDS3DL->dwSize = %d\n",lpDS3DL
->dwSize
);
778 return DSERR_INVALIDPARAM
;
781 TRACE("returning: all parameters\n");
782 *lpDS3DL
= This
->device
->ds3dl
;
786 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetDistanceFactor(IDirectSound3DListener
*iface
,
787 D3DVALUE
*lpfDistanceFactor
)
789 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
791 TRACE("returning: Distance Factor = %f\n", This
->device
->ds3dl
.flDistanceFactor
);
792 *lpfDistanceFactor
= This
->device
->ds3dl
.flDistanceFactor
;
796 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetDopplerFactor(IDirectSound3DListener
*iface
,
797 D3DVALUE
*lpfDopplerFactor
)
799 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
801 TRACE("returning: Doppler Factor = %f\n", This
->device
->ds3dl
.flDopplerFactor
);
802 *lpfDopplerFactor
= This
->device
->ds3dl
.flDopplerFactor
;
806 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetOrientation(IDirectSound3DListener
*iface
,
807 D3DVECTOR
*lpvOrientFront
, D3DVECTOR
*lpvOrientTop
)
809 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
811 TRACE("returning: OrientFront vector = (%f,%f,%f); OrientTop vector = (%f,%f,%f)\n", This
->device
->ds3dl
.vOrientFront
.x
,
812 This
->device
->ds3dl
.vOrientFront
.y
, This
->device
->ds3dl
.vOrientFront
.z
, This
->device
->ds3dl
.vOrientTop
.x
, This
->device
->ds3dl
.vOrientTop
.y
,
813 This
->device
->ds3dl
.vOrientTop
.z
);
814 *lpvOrientFront
= This
->device
->ds3dl
.vOrientFront
;
815 *lpvOrientTop
= This
->device
->ds3dl
.vOrientTop
;
819 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetPosition(IDirectSound3DListener
*iface
,
820 D3DVECTOR
*lpvPosition
)
822 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
824 TRACE("returning: Position vector = (%f,%f,%f)\n", This
->device
->ds3dl
.vPosition
.x
, This
->device
->ds3dl
.vPosition
.y
, This
->device
->ds3dl
.vPosition
.z
);
825 *lpvPosition
= This
->device
->ds3dl
.vPosition
;
829 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetRolloffFactor(IDirectSound3DListener
*iface
,
830 D3DVALUE
*lpfRolloffFactor
)
832 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
834 TRACE("returning: RolloffFactor = %f\n", This
->device
->ds3dl
.flRolloffFactor
);
835 *lpfRolloffFactor
= This
->device
->ds3dl
.flRolloffFactor
;
839 static HRESULT WINAPI
IDirectSound3DListenerImpl_GetVelocity(IDirectSound3DListener
*iface
,
840 D3DVECTOR
*lpvVelocity
)
842 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
844 TRACE("returning: Velocity vector = (%f,%f,%f)\n", This
->device
->ds3dl
.vVelocity
.x
, This
->device
->ds3dl
.vVelocity
.y
, This
->device
->ds3dl
.vVelocity
.z
);
845 *lpvVelocity
= This
->device
->ds3dl
.vVelocity
;
849 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetAllParameters(IDirectSound3DListener
*iface
,
850 const DS3DLISTENER
*lpcDS3DL
, DWORD dwApply
)
852 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
854 TRACE("setting: all parameters; dwApply = %d\n", dwApply
);
855 This
->device
->ds3dl
= *lpcDS3DL
;
856 if (dwApply
== DS3D_IMMEDIATE
)
858 This
->device
->ds3dl_need_recalc
= FALSE
;
859 DSOUND_ChangeListener(This
);
861 This
->device
->ds3dl_need_recalc
= TRUE
;
865 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetDistanceFactor(IDirectSound3DListener
*iface
,
866 D3DVALUE fDistanceFactor
, DWORD dwApply
)
868 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
870 TRACE("setting: Distance Factor = %f; dwApply = %d\n", fDistanceFactor
, dwApply
);
871 This
->device
->ds3dl
.flDistanceFactor
= fDistanceFactor
;
872 if (dwApply
== DS3D_IMMEDIATE
)
874 This
->device
->ds3dl_need_recalc
= FALSE
;
875 DSOUND_ChangeListener(This
);
877 This
->device
->ds3dl_need_recalc
= TRUE
;
881 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetDopplerFactor(IDirectSound3DListener
*iface
,
882 D3DVALUE fDopplerFactor
, DWORD dwApply
)
884 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
886 TRACE("setting: Doppler Factor = %f; dwApply = %d\n", fDopplerFactor
, dwApply
);
887 This
->device
->ds3dl
.flDopplerFactor
= fDopplerFactor
;
888 if (dwApply
== DS3D_IMMEDIATE
)
890 This
->device
->ds3dl_need_recalc
= FALSE
;
891 DSOUND_ChangeListener(This
);
893 This
->device
->ds3dl_need_recalc
= TRUE
;
897 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetOrientation(IDirectSound3DListener
*iface
,
898 D3DVALUE xFront
, D3DVALUE yFront
, D3DVALUE zFront
, D3DVALUE xTop
, D3DVALUE yTop
,
899 D3DVALUE zTop
, DWORD dwApply
)
901 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
903 TRACE("setting: Front vector = (%f,%f,%f); Top vector = (%f,%f,%f); dwApply = %d\n",
904 xFront
, yFront
, zFront
, xTop
, yTop
, zTop
, dwApply
);
905 This
->device
->ds3dl
.vOrientFront
.x
= xFront
;
906 This
->device
->ds3dl
.vOrientFront
.y
= yFront
;
907 This
->device
->ds3dl
.vOrientFront
.z
= zFront
;
908 This
->device
->ds3dl
.vOrientTop
.x
= xTop
;
909 This
->device
->ds3dl
.vOrientTop
.y
= yTop
;
910 This
->device
->ds3dl
.vOrientTop
.z
= zTop
;
911 if (dwApply
== DS3D_IMMEDIATE
)
913 This
->device
->ds3dl_need_recalc
= FALSE
;
914 DSOUND_ChangeListener(This
);
916 This
->device
->ds3dl_need_recalc
= TRUE
;
920 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetPosition(IDirectSound3DListener
*iface
,
921 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
923 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
925 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
926 This
->device
->ds3dl
.vPosition
.x
= x
;
927 This
->device
->ds3dl
.vPosition
.y
= y
;
928 This
->device
->ds3dl
.vPosition
.z
= z
;
929 if (dwApply
== DS3D_IMMEDIATE
)
931 This
->device
->ds3dl_need_recalc
= FALSE
;
932 DSOUND_ChangeListener(This
);
934 This
->device
->ds3dl_need_recalc
= TRUE
;
938 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetRolloffFactor(IDirectSound3DListener
*iface
,
939 D3DVALUE fRolloffFactor
, DWORD dwApply
)
941 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
943 TRACE("setting: Rolloff Factor = %f; dwApply = %d\n", fRolloffFactor
, dwApply
);
944 This
->device
->ds3dl
.flRolloffFactor
= fRolloffFactor
;
945 if (dwApply
== DS3D_IMMEDIATE
)
947 This
->device
->ds3dl_need_recalc
= FALSE
;
948 DSOUND_ChangeListener(This
);
950 This
->device
->ds3dl_need_recalc
= TRUE
;
954 static HRESULT WINAPI
IDirectSound3DListenerImpl_SetVelocity(IDirectSound3DListener
*iface
,
955 D3DVALUE x
, D3DVALUE y
, D3DVALUE z
, DWORD dwApply
)
957 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
959 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x
, y
, z
, dwApply
);
960 This
->device
->ds3dl
.vVelocity
.x
= x
;
961 This
->device
->ds3dl
.vVelocity
.y
= y
;
962 This
->device
->ds3dl
.vVelocity
.z
= z
;
963 if (dwApply
== DS3D_IMMEDIATE
)
965 This
->device
->ds3dl_need_recalc
= FALSE
;
966 DSOUND_ChangeListener(This
);
968 This
->device
->ds3dl_need_recalc
= TRUE
;
972 static HRESULT WINAPI
IDirectSound3DListenerImpl_CommitDeferredSettings(IDirectSound3DListener
*iface
)
974 IDirectSoundBufferImpl
*This
= impl_from_IDirectSound3DListener(iface
);
977 DSOUND_ChangeListener(This
);
981 const IDirectSound3DListenerVtbl ds3dlvt
=
983 /* IUnknown methods */
984 IDirectSound3DListenerImpl_QueryInterface
,
985 IDirectSound3DListenerImpl_AddRef
,
986 IDirectSound3DListenerImpl_Release
,
987 /* IDirectSound3DListener methods */
988 IDirectSound3DListenerImpl_GetAllParameter
,
989 IDirectSound3DListenerImpl_GetDistanceFactor
,
990 IDirectSound3DListenerImpl_GetDopplerFactor
,
991 IDirectSound3DListenerImpl_GetOrientation
,
992 IDirectSound3DListenerImpl_GetPosition
,
993 IDirectSound3DListenerImpl_GetRolloffFactor
,
994 IDirectSound3DListenerImpl_GetVelocity
,
995 IDirectSound3DListenerImpl_SetAllParameters
,
996 IDirectSound3DListenerImpl_SetDistanceFactor
,
997 IDirectSound3DListenerImpl_SetDopplerFactor
,
998 IDirectSound3DListenerImpl_SetOrientation
,
999 IDirectSound3DListenerImpl_SetPosition
,
1000 IDirectSound3DListenerImpl_SetRolloffFactor
,
1001 IDirectSound3DListenerImpl_SetVelocity
,
1002 IDirectSound3DListenerImpl_CommitDeferredSettings
,