dsound: Fix bug preventing correct calculation of the sound parameters
[wine/wine-kai.git] / dlls / dsound / sound3d.c
blob0e4ea0e93a5a2eea2eb17d7da8953952be8519a5
1 /* DirectSound
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+.
29 * TODO:
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 <stdarg.h>
41 #include <math.h> /* Insomnia - pow() function */
43 #define NONAMELESSUNION
44 #define NONAMELESSSTRUCT
45 #include "windef.h"
46 #include "winbase.h"
47 #include "winuser.h"
48 #include "mmsystem.h"
49 #include "winternl.h"
50 #include "mmddk.h"
51 #include "wine/debug.h"
52 #include "dsound.h"
53 #include "dsdriver.h"
54 #include "dsound_private.h"
56 /* default intensity level for human ears */
57 #define DEFAULT_INTENSITY 0.000000000001f
58 /* default velocity of sound in the air */
59 #define DEFAULT_VELOCITY 340
61 WINE_DEFAULT_DEBUG_CHANNEL(dsound3d);
63 /*******************************************************************************
64 * Auxiliary functions
67 /* scalar product (i believe it's called dot product in english) */
68 static inline D3DVALUE ScalarProduct (const D3DVECTOR *a, const D3DVECTOR *b)
70 D3DVALUE c;
71 c = (a->x*b->x) + (a->y*b->y) + (a->z*b->z);
72 TRACE("(%f,%f,%f) * (%f,%f,%f) = %f)\n", a->x, a->y, a->z, b->x, b->y,
73 b->z, c);
74 return c;
77 /* vector product (i believe it's called cross product in english */
78 static inline D3DVECTOR VectorProduct (const D3DVECTOR *a, const D3DVECTOR *b)
80 D3DVECTOR c;
81 c.x = (a->y*b->z) - (a->z*b->y);
82 c.y = (a->z*b->x) - (a->x*b->z);
83 c.z = (a->x*b->y) - (a->y*b->x);
84 TRACE("(%f,%f,%f) x (%f,%f,%f) = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y,
85 b->z, c.x, c.y, c.z);
86 return c;
89 /* magnitude (length) of vector */
90 static inline D3DVALUE VectorMagnitude (const D3DVECTOR *a)
92 D3DVALUE l;
93 l = sqrt (ScalarProduct (a, a));
94 TRACE("|(%f,%f,%f)| = %f\n", a->x, a->y, a->z, l);
95 return l;
98 /* conversion between radians and degrees */
99 static inline D3DVALUE RadToDeg (D3DVALUE angle)
101 D3DVALUE newangle;
102 newangle = angle * (360/(2*M_PI));
103 TRACE("%f rad = %f deg\n", angle, newangle);
104 return newangle;
107 /* angle between vectors - deg version */
108 static inline D3DVALUE AngleBetweenVectorsDeg (const D3DVECTOR *a, const D3DVECTOR *b)
110 D3DVALUE la, lb, product, angle, cos;
111 /* definition of scalar product: a*b = |a|*|b|*cos...therefore: */
112 product = ScalarProduct (a,b);
113 la = VectorMagnitude (a);
114 lb = VectorMagnitude (b);
115 cos = product/(la*lb);
116 angle = acos(cos);
117 /* we now have angle in radians */
118 angle = RadToDeg(angle);
119 TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f degrees\n", a->x, a->y, a->z, b->x,
120 b->y, b->z, angle);
121 return angle;
124 /* angle between vectors - rad version */
125 static inline D3DVALUE AngleBetweenVectorsRad (const D3DVECTOR *a, const D3DVECTOR *b)
127 D3DVALUE la, lb, product, angle, cos;
128 /* definition of scalar product: a*b = |a|*|b|*cos...therefore: */
129 product = ScalarProduct (a,b);
130 la = VectorMagnitude (a);
131 lb = VectorMagnitude (b);
132 cos = product/(la*lb);
133 angle = acos(cos);
134 TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians\n", a->x, a->y, a->z, b->x,
135 b->y, b->z, angle);
136 return angle;
139 /* calculates vector between two points */
140 static inline D3DVECTOR VectorBetweenTwoPoints (const D3DVECTOR *a, const D3DVECTOR *b)
142 D3DVECTOR c;
143 c.x = b->x - a->x;
144 c.y = b->y - a->y;
145 c.z = b->z - a->z;
146 TRACE("A (%f,%f,%f), B (%f,%f,%f), AB = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y,
147 b->z, c.x, c.y, c.z);
148 return c;
151 /* calculates the length of vector's projection on another vector */
152 static inline D3DVALUE ProjectVector (const D3DVECTOR *a, const D3DVECTOR *p)
154 D3DVALUE prod, result;
155 prod = ScalarProduct(a, p);
156 result = prod/VectorMagnitude(p);
157 TRACE("length projection of (%f,%f,%f) on (%f,%f,%f) = %f\n", a->x, a->y, a->z, p->x,
158 p->y, p->z, result);
159 return result;
162 /*******************************************************************************
163 * 3D Buffer and Listener mixing
166 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb)
168 /* volume, at which the sound will be played after all calcs. */
169 D3DVALUE lVolume = 0;
170 /* intensity (used for distance related stuff) */
171 double flIntensity;
172 double flTemp;
173 /* stuff for distance related stuff calc. */
174 D3DVECTOR vDistance;
175 D3DVALUE flDistance = 0;
176 /* panning related stuff */
177 D3DVALUE flAngle;
178 D3DVECTOR vLeft;
179 /* doppler shift related stuff */
180 #if 0
181 D3DVALUE flFreq, flBufferVel, flListenerVel;
182 #endif
184 TRACE("(%p)\n",dsb);
186 /* initial buffer volume */
187 lVolume = dsb->ds3db_lVolume;
189 switch (dsb->ds3db_ds3db.dwMode)
191 case DS3DMODE_DISABLE:
192 TRACE("3D processing disabled\n");
193 /* this one is here only to eliminate annoying warning message */
194 DSOUND_RecalcVolPan (&dsb->volpan);
195 break;
196 case DS3DMODE_NORMAL:
197 TRACE("Normal 3D processing mode\n");
198 /* we need to calculate distance between buffer and listener*/
199 vDistance = VectorBetweenTwoPoints(&dsb->ds3db_ds3db.vPosition, &dsb->device->ds3dl.vPosition);
200 flDistance = VectorMagnitude (&vDistance);
201 break;
202 case DS3DMODE_HEADRELATIVE:
203 TRACE("Head-relative 3D processing mode\n");
204 /* distance between buffer and listener is same as buffer's position */
205 flDistance = VectorMagnitude (&dsb->ds3db_ds3db.vPosition);
206 break;
209 if (flDistance > dsb->ds3db_ds3db.flMaxDistance)
211 /* some apps don't want you to hear too distant sounds... */
212 if (dsb->dsbd.dwFlags & DSBCAPS_MUTE3DATMAXDISTANCE)
214 dsb->volpan.lVolume = DSBVOLUME_MIN;
215 DSOUND_RecalcVolPan (&dsb->volpan);
216 /* i guess mixing here would be a waste of power */
217 return;
219 else
220 flDistance = dsb->ds3db_ds3db.flMaxDistance;
223 if (flDistance < dsb->ds3db_ds3db.flMinDistance)
224 flDistance = dsb->ds3db_ds3db.flMinDistance;
226 /* the following formula is taken from my physics book. I think it's ok for the *real* world...i hope m$ does it that way */
227 lVolume += 10000; /* ms likes working with negative volume...i don't */
228 lVolume /= 1000; /* convert hundreths of dB into B */
229 /* intensity level (loudness) = log10(Intensity/DefaultIntensity)...therefore */
230 flIntensity = pow(10,lVolume)*DEFAULT_INTENSITY;
231 flTemp = (flDistance/dsb->ds3db_ds3db.flMinDistance)*(flDistance/dsb->ds3db_ds3db.flMinDistance);
232 flIntensity /= flTemp;
233 lVolume = log10(flIntensity/DEFAULT_INTENSITY);
234 lVolume *= 1000; /* convert back to hundreths of dB */
235 lVolume -= 10000; /* we need to do it in ms way */
236 TRACE("dist. att: Distance = %f, MinDistance = %f => adjusting volume %d to %f\n", flDistance, dsb->ds3db_ds3db.flMinDistance, dsb->ds3db_lVolume, lVolume);
238 /* conning */
239 /* sometimes it happens that vConeOrientation vector = (0,0,0); in this case angle is "nan" and it's useless*/
240 if (dsb->ds3db_ds3db.vConeOrientation.x == 0 && dsb->ds3db_ds3db.vConeOrientation.y == 0 && dsb->ds3db_ds3db.vConeOrientation.z == 0)
242 TRACE("conning: cones not set\n");
244 else
246 /* calculate angle */
247 flAngle = AngleBetweenVectorsDeg(&dsb->ds3db_ds3db.vConeOrientation, &vDistance);
248 /* if by any chance it happens that OutsideConeAngle = InsideConeAngle (that means that conning has no effect) */
249 if (dsb->ds3db_ds3db.dwInsideConeAngle != dsb->ds3db_ds3db.dwOutsideConeAngle)
251 /* my test show that for my way of calc., we need only half of angles */
252 DWORD dwInsideConeAngle = dsb->ds3db_ds3db.dwInsideConeAngle/2;
253 DWORD dwOutsideConeAngle = dsb->ds3db_ds3db.dwOutsideConeAngle/2;
254 /* full volume */
255 if (flAngle < dwInsideConeAngle)
256 flAngle = dwInsideConeAngle;
257 /* min (app defined) volume */
258 if (flAngle > dwOutsideConeAngle)
259 flAngle = dwOutsideConeAngle;
260 /* this probably isn't the right thing, but it's ok for the time being */
261 lVolume += ((dsb->ds3db_ds3db.lConeOutsideVolume)/((dwOutsideConeAngle) - (dwInsideConeAngle))) * flAngle;
263 TRACE("conning: Angle = %f deg; InsideConeAngle(/2) = %d deg; OutsideConeAngle(/2) = %d deg; ConeOutsideVolume = %d => adjusting volume to %f\n",
264 flAngle, dsb->ds3db_ds3db.dwInsideConeAngle/2, dsb->ds3db_ds3db.dwOutsideConeAngle/2, dsb->ds3db_ds3db.lConeOutsideVolume, lVolume);
266 dsb->volpan.lVolume = lVolume;
268 /* panning */
269 if (dsb->device->ds3dl.vPosition.x == dsb->ds3db_ds3db.vPosition.x &&
270 dsb->device->ds3dl.vPosition.y == dsb->ds3db_ds3db.vPosition.y &&
271 dsb->device->ds3dl.vPosition.z == dsb->ds3db_ds3db.vPosition.z) {
272 dsb->volpan.lPan = 0;
273 flAngle = 0.0;
275 else
277 vDistance = VectorBetweenTwoPoints(&dsb->device->ds3dl.vPosition, &dsb->ds3db_ds3db.vPosition);
278 vLeft = VectorProduct(&dsb->device->ds3dl.vOrientFront, &dsb->device->ds3dl.vOrientTop);
279 flAngle = AngleBetweenVectorsRad(&vLeft, &vDistance);
280 /* for now, we'll use "linear formula" (which is probably incorrect); if someone has it in book, correct it */
281 dsb->volpan.lPan = 10000*2*flAngle/M_PI - 10000;
283 TRACE("panning: Angle = %f rad, lPan = %d\n", flAngle, dsb->volpan.lPan);
285 /* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */
286 #if 0
287 /* doppler shift*/
288 if ((VectorMagnitude(&ds3db.vVelocity) == 0) && (VectorMagnitude(&dsb->device->ds3dl.vVelocity) == 0))
290 TRACE("doppler: Buffer and Listener don't have velocities\n");
292 else
294 /* calculate length of ds3db.vVelocity component which causes Doppler Effect
295 NOTE: if buffer moves TOWARDS the listener, it's velocity component is NEGATIVE
296 if buffer moves AWAY from listener, it's velocity component is POSITIVE */
297 flBufferVel = ProjectVector(&dsb->ds3db_ds3db.vVelocity, &vDistance);
298 /* calculate length of ds3dl.vVelocity component which causes Doppler Effect
299 NOTE: if listener moves TOWARDS the buffer, it's velocity component is POSITIVE
300 if listener moves AWAY from buffer, it's velocity component is NEGATIVE */
301 flListenerVel = ProjectVector(&dsb->device->ds3dl.vVelocity, &vDistance);
302 /* formula taken from Gianicoli D.: Physics, 4th edition: */
303 /* FIXME: replace dsb->freq with appropriate frequency ! */
304 flFreq = dsb->freq * ((DEFAULT_VELOCITY + flListenerVel)/(DEFAULT_VELOCITY + flBufferVel));
305 TRACE("doppler: Buffer velocity (component) = %lf, Listener velocity (component) = %lf => Doppler shift: %ld Hz -> %lf Hz\n", flBufferVel, flListenerVel,
306 dsb->freq, flFreq);
307 /* FIXME: replace following line with correct frequency setting ! */
308 dsb->freq = flFreq;
310 #endif
312 /* time for remix */
313 DSOUND_RecalcVolPan(&dsb->volpan);
316 static void DSOUND_Mix3DBuffer(IDirectSoundBufferImpl *dsb)
318 TRACE("(%p)\n",dsb);
320 DSOUND_Calc3DBuffer(dsb);
323 static void DSOUND_ChangeListener(IDirectSound3DListenerImpl *ds3dl)
325 int i;
326 TRACE("(%p)\n",ds3dl);
327 for (i = 0; i < ds3dl->device->nrofbuffers; i++)
329 /* check if this buffer is waiting for recalculation */
330 if (ds3dl->device->buffers[i]->ds3db_need_recalc)
332 DSOUND_Mix3DBuffer(ds3dl->device->buffers[i]);
337 /*******************************************************************************
338 * IDirectSound3DBuffer
341 /* IUnknown methods */
342 static HRESULT WINAPI IDirectSound3DBufferImpl_QueryInterface(
343 LPDIRECTSOUND3DBUFFER iface, REFIID riid, LPVOID *ppobj)
345 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
347 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
348 return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb, riid, ppobj);
351 static ULONG WINAPI IDirectSound3DBufferImpl_AddRef(LPDIRECTSOUND3DBUFFER iface)
353 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
354 ULONG ref = InterlockedIncrement(&(This->ref));
355 TRACE("(%p) ref was %d\n", This, ref - 1);
356 return ref;
359 static ULONG WINAPI IDirectSound3DBufferImpl_Release(LPDIRECTSOUND3DBUFFER iface)
361 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
362 ULONG ref = InterlockedDecrement(&(This->ref));
363 TRACE("(%p) ref was %d\n", This, ref + 1);
365 if (!ref) {
366 This->dsb->ds3db = NULL;
367 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
368 HeapFree(GetProcessHeap(), 0, This);
369 TRACE("(%p) released\n", This);
371 return ref;
374 /* IDirectSound3DBuffer methods */
375 static HRESULT WINAPI IDirectSound3DBufferImpl_GetAllParameters(
376 LPDIRECTSOUND3DBUFFER iface,
377 LPDS3DBUFFER lpDs3dBuffer)
379 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
380 TRACE("(%p,%p)\n",This,lpDs3dBuffer);
382 if (lpDs3dBuffer == NULL) {
383 WARN("invalid parameter: lpDs3dBuffer == NULL\n");
384 return DSERR_INVALIDPARAM;
387 if (lpDs3dBuffer->dwSize < sizeof(*lpDs3dBuffer)) {
388 WARN("invalid parameter: lpDs3dBuffer->dwSize = %d\n",lpDs3dBuffer->dwSize);
389 return DSERR_INVALIDPARAM;
392 TRACE("returning: all parameters\n");
393 *lpDs3dBuffer = This->dsb->ds3db_ds3db;
394 return DS_OK;
397 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeAngles(
398 LPDIRECTSOUND3DBUFFER iface,
399 LPDWORD lpdwInsideConeAngle,
400 LPDWORD lpdwOutsideConeAngle)
402 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
403 TRACE("returning: Inside Cone Angle = %d degrees; Outside Cone Angle = %d degrees\n",
404 This->dsb->ds3db_ds3db.dwInsideConeAngle, This->dsb->ds3db_ds3db.dwOutsideConeAngle);
405 *lpdwInsideConeAngle = This->dsb->ds3db_ds3db.dwInsideConeAngle;
406 *lpdwOutsideConeAngle = This->dsb->ds3db_ds3db.dwOutsideConeAngle;
407 return DS_OK;
410 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOrientation(
411 LPDIRECTSOUND3DBUFFER iface,
412 LPD3DVECTOR lpvConeOrientation)
414 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
415 TRACE("returning: Cone Orientation vector = (%f,%f,%f)\n",
416 This->dsb->ds3db_ds3db.vConeOrientation.x,
417 This->dsb->ds3db_ds3db.vConeOrientation.y,
418 This->dsb->ds3db_ds3db.vConeOrientation.z);
419 *lpvConeOrientation = This->dsb->ds3db_ds3db.vConeOrientation;
420 return DS_OK;
423 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOutsideVolume(
424 LPDIRECTSOUND3DBUFFER iface,
425 LPLONG lplConeOutsideVolume)
427 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
428 TRACE("returning: Cone Outside Volume = %d\n", This->dsb->ds3db_ds3db.lConeOutsideVolume);
429 *lplConeOutsideVolume = This->dsb->ds3db_ds3db.lConeOutsideVolume;
430 return DS_OK;
433 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMaxDistance(
434 LPDIRECTSOUND3DBUFFER iface,
435 LPD3DVALUE lpfMaxDistance)
437 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
438 TRACE("returning: Max Distance = %f\n", This->dsb->ds3db_ds3db.flMaxDistance);
439 *lpfMaxDistance = This->dsb->ds3db_ds3db.flMaxDistance;
440 return DS_OK;
443 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMinDistance(
444 LPDIRECTSOUND3DBUFFER iface,
445 LPD3DVALUE lpfMinDistance)
447 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
448 TRACE("returning: Min Distance = %f\n", This->dsb->ds3db_ds3db.flMinDistance);
449 *lpfMinDistance = This->dsb->ds3db_ds3db.flMinDistance;
450 return DS_OK;
453 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMode(
454 LPDIRECTSOUND3DBUFFER iface,
455 LPDWORD lpdwMode)
457 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
458 TRACE("returning: Mode = %d\n", This->dsb->ds3db_ds3db.dwMode);
459 *lpdwMode = This->dsb->ds3db_ds3db.dwMode;
460 return DS_OK;
463 static HRESULT WINAPI IDirectSound3DBufferImpl_GetPosition(
464 LPDIRECTSOUND3DBUFFER iface,
465 LPD3DVECTOR lpvPosition)
467 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
468 TRACE("returning: Position vector = (%f,%f,%f)\n",
469 This->dsb->ds3db_ds3db.vPosition.x,
470 This->dsb->ds3db_ds3db.vPosition.y,
471 This->dsb->ds3db_ds3db.vPosition.z);
472 *lpvPosition = This->dsb->ds3db_ds3db.vPosition;
473 return DS_OK;
476 static HRESULT WINAPI IDirectSound3DBufferImpl_GetVelocity(
477 LPDIRECTSOUND3DBUFFER iface,
478 LPD3DVECTOR lpvVelocity)
480 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
481 TRACE("returning: Velocity vector = (%f,%f,%f)\n",
482 This->dsb->ds3db_ds3db.vVelocity.x,
483 This->dsb->ds3db_ds3db.vVelocity.y,
484 This->dsb->ds3db_ds3db.vVelocity.z);
485 *lpvVelocity = This->dsb->ds3db_ds3db.vVelocity;
486 return DS_OK;
489 static HRESULT WINAPI IDirectSound3DBufferImpl_SetAllParameters(
490 LPDIRECTSOUND3DBUFFER iface,
491 LPCDS3DBUFFER lpcDs3dBuffer,
492 DWORD dwApply)
494 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
495 DWORD status = DSERR_INVALIDPARAM;
496 TRACE("(%p,%p,%x)\n",iface,lpcDs3dBuffer,dwApply);
498 if (lpcDs3dBuffer == NULL) {
499 WARN("invalid parameter: lpcDs3dBuffer == NULL\n");
500 return status;
503 if (lpcDs3dBuffer->dwSize != sizeof(DS3DBUFFER)) {
504 WARN("invalid parameter: lpcDs3dBuffer->dwSize = %d\n", lpcDs3dBuffer->dwSize);
505 return status;
508 TRACE("setting: all parameters; dwApply = %d\n", dwApply);
509 This->dsb->ds3db_ds3db = *lpcDs3dBuffer;
511 if (dwApply == DS3D_IMMEDIATE)
513 DSOUND_Mix3DBuffer(This->dsb);
515 This->dsb->ds3db_need_recalc = TRUE;
516 status = DS_OK;
518 return status;
521 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeAngles(
522 LPDIRECTSOUND3DBUFFER iface,
523 DWORD dwInsideConeAngle,
524 DWORD dwOutsideConeAngle,
525 DWORD dwApply)
527 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
528 TRACE("setting: Inside Cone Angle = %d; Outside Cone Angle = %d; dwApply = %d\n",
529 dwInsideConeAngle, dwOutsideConeAngle, dwApply);
530 This->dsb->ds3db_ds3db.dwInsideConeAngle = dwInsideConeAngle;
531 This->dsb->ds3db_ds3db.dwOutsideConeAngle = dwOutsideConeAngle;
532 if (dwApply == DS3D_IMMEDIATE)
534 DSOUND_Mix3DBuffer(This->dsb);
536 This->dsb->ds3db_need_recalc = TRUE;
537 return DS_OK;
540 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOrientation(
541 LPDIRECTSOUND3DBUFFER iface,
542 D3DVALUE x, D3DVALUE y, D3DVALUE z,
543 DWORD dwApply)
545 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
546 TRACE("setting: Cone Orientation vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
547 This->dsb->ds3db_ds3db.vConeOrientation.x = x;
548 This->dsb->ds3db_ds3db.vConeOrientation.y = y;
549 This->dsb->ds3db_ds3db.vConeOrientation.z = z;
550 if (dwApply == DS3D_IMMEDIATE)
552 This->dsb->ds3db_need_recalc = FALSE;
553 DSOUND_Mix3DBuffer(This->dsb);
555 This->dsb->ds3db_need_recalc = TRUE;
556 return DS_OK;
559 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOutsideVolume(
560 LPDIRECTSOUND3DBUFFER iface,
561 LONG lConeOutsideVolume,
562 DWORD dwApply)
564 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
565 TRACE("setting: ConeOutsideVolume = %d; dwApply = %d\n", lConeOutsideVolume, dwApply);
566 This->dsb->ds3db_ds3db.lConeOutsideVolume = lConeOutsideVolume;
567 if (dwApply == DS3D_IMMEDIATE)
569 This->dsb->ds3db_need_recalc = FALSE;
570 DSOUND_Mix3DBuffer(This->dsb);
572 This->dsb->ds3db_need_recalc = TRUE;
573 return DS_OK;
576 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMaxDistance(
577 LPDIRECTSOUND3DBUFFER iface,
578 D3DVALUE fMaxDistance,
579 DWORD dwApply)
581 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
582 TRACE("setting: MaxDistance = %f; dwApply = %d\n", fMaxDistance, dwApply);
583 This->dsb->ds3db_ds3db.flMaxDistance = fMaxDistance;
584 if (dwApply == DS3D_IMMEDIATE)
586 This->dsb->ds3db_need_recalc = FALSE;
587 DSOUND_Mix3DBuffer(This->dsb);
589 This->dsb->ds3db_need_recalc = TRUE;
590 return DS_OK;
593 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMinDistance(
594 LPDIRECTSOUND3DBUFFER iface,
595 D3DVALUE fMinDistance,
596 DWORD dwApply)
598 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
599 TRACE("setting: MinDistance = %f; dwApply = %d\n", fMinDistance, dwApply);
600 This->dsb->ds3db_ds3db.flMinDistance = fMinDistance;
601 if (dwApply == DS3D_IMMEDIATE)
603 This->dsb->ds3db_need_recalc = FALSE;
604 DSOUND_Mix3DBuffer(This->dsb);
606 This->dsb->ds3db_need_recalc = TRUE;
607 return DS_OK;
610 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMode(
611 LPDIRECTSOUND3DBUFFER iface,
612 DWORD dwMode,
613 DWORD dwApply)
615 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
616 TRACE("setting: Mode = %d; dwApply = %d\n", dwMode, dwApply);
617 This->dsb->ds3db_ds3db.dwMode = dwMode;
618 if (dwApply == DS3D_IMMEDIATE)
620 This->dsb->ds3db_need_recalc = FALSE;
621 DSOUND_Mix3DBuffer(This->dsb);
623 This->dsb->ds3db_need_recalc = TRUE;
624 return DS_OK;
627 static HRESULT WINAPI IDirectSound3DBufferImpl_SetPosition(
628 LPDIRECTSOUND3DBUFFER iface,
629 D3DVALUE x, D3DVALUE y, D3DVALUE z,
630 DWORD dwApply)
632 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
633 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
634 This->dsb->ds3db_ds3db.vPosition.x = x;
635 This->dsb->ds3db_ds3db.vPosition.y = y;
636 This->dsb->ds3db_ds3db.vPosition.z = z;
637 if (dwApply == DS3D_IMMEDIATE)
639 This->dsb->ds3db_need_recalc = FALSE;
640 DSOUND_Mix3DBuffer(This->dsb);
642 This->dsb->ds3db_need_recalc = TRUE;
643 return DS_OK;
646 static HRESULT WINAPI IDirectSound3DBufferImpl_SetVelocity(
647 LPDIRECTSOUND3DBUFFER iface,
648 D3DVALUE x, D3DVALUE y, D3DVALUE z,
649 DWORD dwApply)
651 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
652 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
653 This->dsb->ds3db_ds3db.vVelocity.x = x;
654 This->dsb->ds3db_ds3db.vVelocity.y = y;
655 This->dsb->ds3db_ds3db.vVelocity.z = z;
656 if (dwApply == DS3D_IMMEDIATE)
658 This->dsb->ds3db_need_recalc = FALSE;
659 DSOUND_Mix3DBuffer(This->dsb);
661 This->dsb->ds3db_need_recalc = TRUE;
662 return DS_OK;
665 static const IDirectSound3DBufferVtbl ds3dbvt =
667 /* IUnknown methods */
668 IDirectSound3DBufferImpl_QueryInterface,
669 IDirectSound3DBufferImpl_AddRef,
670 IDirectSound3DBufferImpl_Release,
671 /* IDirectSound3DBuffer methods */
672 IDirectSound3DBufferImpl_GetAllParameters,
673 IDirectSound3DBufferImpl_GetConeAngles,
674 IDirectSound3DBufferImpl_GetConeOrientation,
675 IDirectSound3DBufferImpl_GetConeOutsideVolume,
676 IDirectSound3DBufferImpl_GetMaxDistance,
677 IDirectSound3DBufferImpl_GetMinDistance,
678 IDirectSound3DBufferImpl_GetMode,
679 IDirectSound3DBufferImpl_GetPosition,
680 IDirectSound3DBufferImpl_GetVelocity,
681 IDirectSound3DBufferImpl_SetAllParameters,
682 IDirectSound3DBufferImpl_SetConeAngles,
683 IDirectSound3DBufferImpl_SetConeOrientation,
684 IDirectSound3DBufferImpl_SetConeOutsideVolume,
685 IDirectSound3DBufferImpl_SetMaxDistance,
686 IDirectSound3DBufferImpl_SetMinDistance,
687 IDirectSound3DBufferImpl_SetMode,
688 IDirectSound3DBufferImpl_SetPosition,
689 IDirectSound3DBufferImpl_SetVelocity,
692 HRESULT IDirectSound3DBufferImpl_Create(
693 IDirectSoundBufferImpl *dsb,
694 IDirectSound3DBufferImpl **pds3db)
696 IDirectSound3DBufferImpl *ds3db;
697 TRACE("(%p,%p)\n",dsb,pds3db);
699 ds3db = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*ds3db));
701 if (ds3db == NULL) {
702 WARN("out of memory\n");
703 *pds3db = 0;
704 return DSERR_OUTOFMEMORY;
707 ds3db->ref = 0;
708 ds3db->dsb = dsb;
709 ds3db->lpVtbl = &ds3dbvt;
711 ds3db->dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
712 ds3db->dsb->ds3db_ds3db.vPosition.x = 0.0;
713 ds3db->dsb->ds3db_ds3db.vPosition.y = 0.0;
714 ds3db->dsb->ds3db_ds3db.vPosition.z = 0.0;
715 ds3db->dsb->ds3db_ds3db.vVelocity.x = 0.0;
716 ds3db->dsb->ds3db_ds3db.vVelocity.y = 0.0;
717 ds3db->dsb->ds3db_ds3db.vVelocity.z = 0.0;
718 ds3db->dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
719 ds3db->dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
720 ds3db->dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
721 ds3db->dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
722 ds3db->dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
723 ds3db->dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
724 ds3db->dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
725 ds3db->dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
726 ds3db->dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
728 ds3db->dsb->ds3db_need_recalc = TRUE;
730 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
732 *pds3db = ds3db;
733 return S_OK;
736 HRESULT IDirectSound3DBufferImpl_Destroy(
737 IDirectSound3DBufferImpl *pds3db)
739 TRACE("(%p)\n",pds3db);
741 while (IDirectSound3DBufferImpl_Release((LPDIRECTSOUND3DBUFFER)pds3db) > 0);
743 return S_OK;
746 /*******************************************************************************
747 * IDirectSound3DListener
750 /* IUnknown methods */
751 static HRESULT WINAPI IDirectSound3DListenerImpl_QueryInterface(
752 LPDIRECTSOUND3DLISTENER iface, REFIID riid, LPVOID *ppobj)
754 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
756 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
758 if (ppobj == NULL) {
759 WARN("invalid parameter\n");
760 return E_INVALIDARG;
763 *ppobj = NULL; /* assume failure */
765 if ( IsEqualGUID(riid, &IID_IUnknown) ||
766 IsEqualGUID(riid, &IID_IDirectSound3DListener ) ) {
767 IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)This);
768 *ppobj = This;
769 return S_OK;
772 if ( IsEqualGUID(riid, &IID_IDirectSoundBuffer) ) {
773 if (!This->device->primary)
774 PrimaryBufferImpl_Create(This->device, &(This->device->primary), &(This->device->dsbd));
775 if (This->device->primary) {
776 *ppobj = This->device->primary;
777 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)*ppobj);
778 return S_OK;
782 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
783 return E_NOINTERFACE;
786 static ULONG WINAPI IDirectSound3DListenerImpl_AddRef(LPDIRECTSOUND3DLISTENER iface)
788 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
789 ULONG ref = InterlockedIncrement(&(This->ref));
790 TRACE("(%p) ref was %d\n", This, ref - 1);
791 return ref;
794 static ULONG WINAPI IDirectSound3DListenerImpl_Release(LPDIRECTSOUND3DLISTENER iface)
796 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
797 ULONG ref = InterlockedDecrement(&(This->ref));
798 TRACE("(%p) ref was %d\n", This, ref + 1);
800 if (!ref) {
801 This->device->listener = 0;
802 HeapFree(GetProcessHeap(), 0, This);
803 TRACE("(%p) released\n", This);
805 return ref;
808 /* IDirectSound3DListener methods */
809 static HRESULT WINAPI IDirectSound3DListenerImpl_GetAllParameter(
810 LPDIRECTSOUND3DLISTENER iface,
811 LPDS3DLISTENER lpDS3DL)
813 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
814 TRACE("(%p,%p)\n",This,lpDS3DL);
816 if (lpDS3DL == NULL) {
817 WARN("invalid parameter: lpDS3DL == NULL\n");
818 return DSERR_INVALIDPARAM;
821 if (lpDS3DL->dwSize < sizeof(*lpDS3DL)) {
822 WARN("invalid parameter: lpDS3DL->dwSize = %d\n",lpDS3DL->dwSize);
823 return DSERR_INVALIDPARAM;
826 TRACE("returning: all parameters\n");
827 *lpDS3DL = This->device->ds3dl;
828 return DS_OK;
831 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDistanceFactor(
832 LPDIRECTSOUND3DLISTENER iface,
833 LPD3DVALUE lpfDistanceFactor)
835 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
836 TRACE("returning: Distance Factor = %f\n", This->device->ds3dl.flDistanceFactor);
837 *lpfDistanceFactor = This->device->ds3dl.flDistanceFactor;
838 return DS_OK;
841 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDopplerFactor(
842 LPDIRECTSOUND3DLISTENER iface,
843 LPD3DVALUE lpfDopplerFactor)
845 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
846 TRACE("returning: Doppler Factor = %f\n", This->device->ds3dl.flDopplerFactor);
847 *lpfDopplerFactor = This->device->ds3dl.flDopplerFactor;
848 return DS_OK;
851 static HRESULT WINAPI IDirectSound3DListenerImpl_GetOrientation(
852 LPDIRECTSOUND3DLISTENER iface,
853 LPD3DVECTOR lpvOrientFront,
854 LPD3DVECTOR lpvOrientTop)
856 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
857 TRACE("returning: OrientFront vector = (%f,%f,%f); OrientTop vector = (%f,%f,%f)\n", This->device->ds3dl.vOrientFront.x,
858 This->device->ds3dl.vOrientFront.y, This->device->ds3dl.vOrientFront.z, This->device->ds3dl.vOrientTop.x, This->device->ds3dl.vOrientTop.y,
859 This->device->ds3dl.vOrientTop.z);
860 *lpvOrientFront = This->device->ds3dl.vOrientFront;
861 *lpvOrientTop = This->device->ds3dl.vOrientTop;
862 return DS_OK;
865 static HRESULT WINAPI IDirectSound3DListenerImpl_GetPosition(
866 LPDIRECTSOUND3DLISTENER iface,
867 LPD3DVECTOR lpvPosition)
869 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
870 TRACE("returning: Position vector = (%f,%f,%f)\n", This->device->ds3dl.vPosition.x, This->device->ds3dl.vPosition.y, This->device->ds3dl.vPosition.z);
871 *lpvPosition = This->device->ds3dl.vPosition;
872 return DS_OK;
875 static HRESULT WINAPI IDirectSound3DListenerImpl_GetRolloffFactor(
876 LPDIRECTSOUND3DLISTENER iface,
877 LPD3DVALUE lpfRolloffFactor)
879 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
880 TRACE("returning: RolloffFactor = %f\n", This->device->ds3dl.flRolloffFactor);
881 *lpfRolloffFactor = This->device->ds3dl.flRolloffFactor;
882 return DS_OK;
885 static HRESULT WINAPI IDirectSound3DListenerImpl_GetVelocity(
886 LPDIRECTSOUND3DLISTENER iface,
887 LPD3DVECTOR lpvVelocity)
889 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
890 TRACE("returning: Velocity vector = (%f,%f,%f)\n", This->device->ds3dl.vVelocity.x, This->device->ds3dl.vVelocity.y, This->device->ds3dl.vVelocity.z);
891 *lpvVelocity = This->device->ds3dl.vVelocity;
892 return DS_OK;
895 static HRESULT WINAPI IDirectSound3DListenerImpl_SetAllParameters(
896 LPDIRECTSOUND3DLISTENER iface,
897 LPCDS3DLISTENER lpcDS3DL,
898 DWORD dwApply)
900 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
901 TRACE("setting: all parameters; dwApply = %d\n", dwApply);
902 This->device->ds3dl = *lpcDS3DL;
903 if (dwApply == DS3D_IMMEDIATE)
905 This->device->ds3dl_need_recalc = FALSE;
906 DSOUND_ChangeListener(This);
908 This->device->ds3dl_need_recalc = TRUE;
909 return DS_OK;
912 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDistanceFactor(
913 LPDIRECTSOUND3DLISTENER iface,
914 D3DVALUE fDistanceFactor,
915 DWORD dwApply)
917 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
918 TRACE("setting: Distance Factor = %f; dwApply = %d\n", fDistanceFactor, dwApply);
919 This->device->ds3dl.flDistanceFactor = fDistanceFactor;
920 if (dwApply == DS3D_IMMEDIATE)
922 This->device->ds3dl_need_recalc = FALSE;
923 DSOUND_ChangeListener(This);
925 This->device->ds3dl_need_recalc = TRUE;
926 return DS_OK;
929 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDopplerFactor(
930 LPDIRECTSOUND3DLISTENER iface,
931 D3DVALUE fDopplerFactor,
932 DWORD dwApply)
934 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
935 TRACE("setting: Doppler Factor = %f; dwApply = %d\n", fDopplerFactor, dwApply);
936 This->device->ds3dl.flDopplerFactor = fDopplerFactor;
937 if (dwApply == DS3D_IMMEDIATE)
939 This->device->ds3dl_need_recalc = FALSE;
940 DSOUND_ChangeListener(This);
942 This->device->ds3dl_need_recalc = TRUE;
943 return DS_OK;
946 static HRESULT WINAPI IDirectSound3DListenerImpl_SetOrientation(
947 LPDIRECTSOUND3DLISTENER iface,
948 D3DVALUE xFront, D3DVALUE yFront, D3DVALUE zFront,
949 D3DVALUE xTop, D3DVALUE yTop, D3DVALUE zTop,
950 DWORD dwApply)
952 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
953 TRACE("setting: Front vector = (%f,%f,%f); Top vector = (%f,%f,%f); dwApply = %d\n",
954 xFront, yFront, zFront, xTop, yTop, zTop, dwApply);
955 This->device->ds3dl.vOrientFront.x = xFront;
956 This->device->ds3dl.vOrientFront.y = yFront;
957 This->device->ds3dl.vOrientFront.z = zFront;
958 This->device->ds3dl.vOrientTop.x = xTop;
959 This->device->ds3dl.vOrientTop.y = yTop;
960 This->device->ds3dl.vOrientTop.z = zTop;
961 if (dwApply == DS3D_IMMEDIATE)
963 This->device->ds3dl_need_recalc = FALSE;
964 DSOUND_ChangeListener(This);
966 This->device->ds3dl_need_recalc = TRUE;
967 return DS_OK;
970 static HRESULT WINAPI IDirectSound3DListenerImpl_SetPosition(
971 LPDIRECTSOUND3DLISTENER iface,
972 D3DVALUE x, D3DVALUE y, D3DVALUE z,
973 DWORD dwApply)
975 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
976 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
977 This->device->ds3dl.vPosition.x = x;
978 This->device->ds3dl.vPosition.y = y;
979 This->device->ds3dl.vPosition.z = z;
980 if (dwApply == DS3D_IMMEDIATE)
982 This->device->ds3dl_need_recalc = FALSE;
983 DSOUND_ChangeListener(This);
985 This->device->ds3dl_need_recalc = TRUE;
986 return DS_OK;
989 static HRESULT WINAPI IDirectSound3DListenerImpl_SetRolloffFactor(
990 LPDIRECTSOUND3DLISTENER iface,
991 D3DVALUE fRolloffFactor,
992 DWORD dwApply)
994 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
995 TRACE("setting: Rolloff Factor = %f; dwApply = %d\n", fRolloffFactor, dwApply);
996 This->device->ds3dl.flRolloffFactor = fRolloffFactor;
997 if (dwApply == DS3D_IMMEDIATE)
999 This->device->ds3dl_need_recalc = FALSE;
1000 DSOUND_ChangeListener(This);
1002 This->device->ds3dl_need_recalc = TRUE;
1003 return DS_OK;
1006 static HRESULT WINAPI IDirectSound3DListenerImpl_SetVelocity(
1007 LPDIRECTSOUND3DLISTENER iface,
1008 D3DVALUE x, D3DVALUE y, D3DVALUE z,
1009 DWORD dwApply)
1011 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
1012 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
1013 This->device->ds3dl.vVelocity.x = x;
1014 This->device->ds3dl.vVelocity.y = y;
1015 This->device->ds3dl.vVelocity.z = z;
1016 if (dwApply == DS3D_IMMEDIATE)
1018 This->device->ds3dl_need_recalc = FALSE;
1019 DSOUND_ChangeListener(This);
1021 This->device->ds3dl_need_recalc = TRUE;
1022 return DS_OK;
1025 static HRESULT WINAPI IDirectSound3DListenerImpl_CommitDeferredSettings(
1026 LPDIRECTSOUND3DLISTENER iface)
1028 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
1029 TRACE("\n");
1030 DSOUND_ChangeListener(This);
1031 return DS_OK;
1034 static const IDirectSound3DListenerVtbl ds3dlvt =
1036 /* IUnknown methods */
1037 IDirectSound3DListenerImpl_QueryInterface,
1038 IDirectSound3DListenerImpl_AddRef,
1039 IDirectSound3DListenerImpl_Release,
1040 /* IDirectSound3DListener methods */
1041 IDirectSound3DListenerImpl_GetAllParameter,
1042 IDirectSound3DListenerImpl_GetDistanceFactor,
1043 IDirectSound3DListenerImpl_GetDopplerFactor,
1044 IDirectSound3DListenerImpl_GetOrientation,
1045 IDirectSound3DListenerImpl_GetPosition,
1046 IDirectSound3DListenerImpl_GetRolloffFactor,
1047 IDirectSound3DListenerImpl_GetVelocity,
1048 IDirectSound3DListenerImpl_SetAllParameters,
1049 IDirectSound3DListenerImpl_SetDistanceFactor,
1050 IDirectSound3DListenerImpl_SetDopplerFactor,
1051 IDirectSound3DListenerImpl_SetOrientation,
1052 IDirectSound3DListenerImpl_SetPosition,
1053 IDirectSound3DListenerImpl_SetRolloffFactor,
1054 IDirectSound3DListenerImpl_SetVelocity,
1055 IDirectSound3DListenerImpl_CommitDeferredSettings,
1058 HRESULT IDirectSound3DListenerImpl_Create(
1059 DirectSoundDevice * device,
1060 IDirectSound3DListenerImpl ** ppdsl)
1062 IDirectSound3DListenerImpl *pdsl;
1063 TRACE("(%p,%p)\n",device,ppdsl);
1065 pdsl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*pdsl));
1067 if (pdsl == NULL) {
1068 WARN("out of memory\n");
1069 *ppdsl = 0;
1070 return DSERR_OUTOFMEMORY;
1073 pdsl->ref = 0;
1074 pdsl->lpVtbl = &ds3dlvt;
1076 pdsl->device = device;
1078 pdsl->device->ds3dl.dwSize = sizeof(DS3DLISTENER);
1079 pdsl->device->ds3dl.vPosition.x = 0.0;
1080 pdsl->device->ds3dl.vPosition.y = 0.0;
1081 pdsl->device->ds3dl.vPosition.z = 0.0;
1082 pdsl->device->ds3dl.vVelocity.x = 0.0;
1083 pdsl->device->ds3dl.vVelocity.y = 0.0;
1084 pdsl->device->ds3dl.vVelocity.z = 0.0;
1085 pdsl->device->ds3dl.vOrientFront.x = 0.0;
1086 pdsl->device->ds3dl.vOrientFront.y = 0.0;
1087 pdsl->device->ds3dl.vOrientFront.z = 1.0;
1088 pdsl->device->ds3dl.vOrientTop.x = 0.0;
1089 pdsl->device->ds3dl.vOrientTop.y = 1.0;
1090 pdsl->device->ds3dl.vOrientTop.z = 0.0;
1091 pdsl->device->ds3dl.flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
1092 pdsl->device->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
1093 pdsl->device->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
1095 pdsl->device->ds3dl_need_recalc = TRUE;
1097 *ppdsl = pdsl;
1098 return S_OK;