dsound: Simplify the calculation of sound attenuation due to distance.
[wine/multimedia.git] / dlls / dsound / sound3d.c
blobce7899ffc2198f1c111638ba083db0db0cc975de
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 velocity of sound in the air */
57 #define DEFAULT_VELOCITY 340
59 WINE_DEFAULT_DEBUG_CHANNEL(dsound3d);
61 /*******************************************************************************
62 * Auxiliary functions
65 /* scalar product (i believe it's called dot product in english) */
66 static inline D3DVALUE ScalarProduct (const D3DVECTOR *a, const D3DVECTOR *b)
68 D3DVALUE c;
69 c = (a->x*b->x) + (a->y*b->y) + (a->z*b->z);
70 TRACE("(%f,%f,%f) * (%f,%f,%f) = %f)\n", a->x, a->y, a->z, b->x, b->y,
71 b->z, c);
72 return c;
75 /* vector product (i believe it's called cross product in english */
76 static inline D3DVECTOR VectorProduct (const D3DVECTOR *a, const D3DVECTOR *b)
78 D3DVECTOR c;
79 c.x = (a->y*b->z) - (a->z*b->y);
80 c.y = (a->z*b->x) - (a->x*b->z);
81 c.z = (a->x*b->y) - (a->y*b->x);
82 TRACE("(%f,%f,%f) x (%f,%f,%f) = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y,
83 b->z, c.x, c.y, c.z);
84 return c;
87 /* magnitude (length) of vector */
88 static inline D3DVALUE VectorMagnitude (const D3DVECTOR *a)
90 D3DVALUE l;
91 l = sqrt (ScalarProduct (a, a));
92 TRACE("|(%f,%f,%f)| = %f\n", a->x, a->y, a->z, l);
93 return l;
96 /* conversion between radians and degrees */
97 static inline D3DVALUE RadToDeg (D3DVALUE angle)
99 D3DVALUE newangle;
100 newangle = angle * (360/(2*M_PI));
101 TRACE("%f rad = %f deg\n", angle, newangle);
102 return newangle;
105 /* angle between vectors - deg version */
106 static inline D3DVALUE AngleBetweenVectorsDeg (const D3DVECTOR *a, const D3DVECTOR *b)
108 D3DVALUE la, lb, product, angle, cos;
109 /* definition of scalar product: a*b = |a|*|b|*cos...therefore: */
110 product = ScalarProduct (a,b);
111 la = VectorMagnitude (a);
112 lb = VectorMagnitude (b);
113 cos = product/(la*lb);
114 angle = acos(cos);
115 /* we now have angle in radians */
116 angle = RadToDeg(angle);
117 TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f degrees\n", a->x, a->y, a->z, b->x,
118 b->y, b->z, angle);
119 return angle;
122 /* angle between vectors - rad version */
123 static inline D3DVALUE AngleBetweenVectorsRad (const D3DVECTOR *a, const D3DVECTOR *b)
125 D3DVALUE la, lb, product, angle, cos;
126 /* definition of scalar product: a*b = |a|*|b|*cos...therefore: */
127 product = ScalarProduct (a,b);
128 la = VectorMagnitude (a);
129 lb = VectorMagnitude (b);
130 cos = product/(la*lb);
131 angle = acos(cos);
132 TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians\n", a->x, a->y, a->z, b->x,
133 b->y, b->z, angle);
134 return angle;
137 /* calculates vector between two points */
138 static inline D3DVECTOR VectorBetweenTwoPoints (const D3DVECTOR *a, const D3DVECTOR *b)
140 D3DVECTOR c;
141 c.x = b->x - a->x;
142 c.y = b->y - a->y;
143 c.z = b->z - a->z;
144 TRACE("A (%f,%f,%f), B (%f,%f,%f), AB = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y,
145 b->z, c.x, c.y, c.z);
146 return c;
149 /* calculates the length of vector's projection on another vector */
150 static inline D3DVALUE ProjectVector (const D3DVECTOR *a, const D3DVECTOR *p)
152 D3DVALUE prod, result;
153 prod = ScalarProduct(a, p);
154 result = prod/VectorMagnitude(p);
155 TRACE("length projection of (%f,%f,%f) on (%f,%f,%f) = %f\n", a->x, a->y, a->z, p->x,
156 p->y, p->z, result);
157 return result;
160 /*******************************************************************************
161 * 3D Buffer and Listener mixing
164 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb)
166 /* volume, at which the sound will be played after all calcs. */
167 D3DVALUE lVolume = 0;
168 /* stuff for distance related stuff calc. */
169 D3DVECTOR vDistance;
170 D3DVALUE flDistance = 0;
171 /* panning related stuff */
172 D3DVALUE flAngle;
173 D3DVECTOR vLeft;
174 /* doppler shift related stuff */
175 #if 0
176 D3DVALUE flFreq, flBufferVel, flListenerVel;
177 #endif
179 TRACE("(%p)\n",dsb);
181 /* initial buffer volume */
182 lVolume = dsb->ds3db_lVolume;
184 switch (dsb->ds3db_ds3db.dwMode)
186 case DS3DMODE_DISABLE:
187 TRACE("3D processing disabled\n");
188 /* this one is here only to eliminate annoying warning message */
189 DSOUND_RecalcVolPan (&dsb->volpan);
190 break;
191 case DS3DMODE_NORMAL:
192 TRACE("Normal 3D processing mode\n");
193 /* we need to calculate distance between buffer and listener*/
194 vDistance = VectorBetweenTwoPoints(&dsb->ds3db_ds3db.vPosition, &dsb->device->ds3dl.vPosition);
195 flDistance = VectorMagnitude (&vDistance);
196 break;
197 case DS3DMODE_HEADRELATIVE:
198 TRACE("Head-relative 3D processing mode\n");
199 /* distance between buffer and listener is same as buffer's position */
200 flDistance = VectorMagnitude (&dsb->ds3db_ds3db.vPosition);
201 break;
204 if (flDistance > dsb->ds3db_ds3db.flMaxDistance)
206 /* some apps don't want you to hear too distant sounds... */
207 if (dsb->dsbd.dwFlags & DSBCAPS_MUTE3DATMAXDISTANCE)
209 dsb->volpan.lVolume = DSBVOLUME_MIN;
210 DSOUND_RecalcVolPan (&dsb->volpan);
211 /* i guess mixing here would be a waste of power */
212 return;
214 else
215 flDistance = dsb->ds3db_ds3db.flMaxDistance;
218 if (flDistance < dsb->ds3db_ds3db.flMinDistance)
219 flDistance = dsb->ds3db_ds3db.flMinDistance;
221 /* attenuation proportional to the distance squared, converted to millibels as in lVolume*/
222 lVolume -= log10(flDistance/dsb->ds3db_ds3db.flMinDistance * flDistance/dsb->ds3db_ds3db.flMinDistance)*1000;
223 TRACE("dist. att: Distance = %f, MinDistance = %f => adjusting volume %d to %f\n", flDistance, dsb->ds3db_ds3db.flMinDistance, dsb->ds3db_lVolume, lVolume);
225 /* conning */
226 /* sometimes it happens that vConeOrientation vector = (0,0,0); in this case angle is "nan" and it's useless*/
227 if (dsb->ds3db_ds3db.vConeOrientation.x == 0 && dsb->ds3db_ds3db.vConeOrientation.y == 0 && dsb->ds3db_ds3db.vConeOrientation.z == 0)
229 TRACE("conning: cones not set\n");
231 else
233 /* calculate angle */
234 flAngle = AngleBetweenVectorsDeg(&dsb->ds3db_ds3db.vConeOrientation, &vDistance);
235 /* if by any chance it happens that OutsideConeAngle = InsideConeAngle (that means that conning has no effect) */
236 if (dsb->ds3db_ds3db.dwInsideConeAngle != dsb->ds3db_ds3db.dwOutsideConeAngle)
238 /* my test show that for my way of calc., we need only half of angles */
239 DWORD dwInsideConeAngle = dsb->ds3db_ds3db.dwInsideConeAngle/2;
240 DWORD dwOutsideConeAngle = dsb->ds3db_ds3db.dwOutsideConeAngle/2;
241 /* full volume */
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 += ((dsb->ds3db_ds3db.lConeOutsideVolume)/((dwOutsideConeAngle) - (dwInsideConeAngle))) * flAngle;
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 /* panning */
256 if (dsb->device->ds3dl.vPosition.x == dsb->ds3db_ds3db.vPosition.x &&
257 dsb->device->ds3dl.vPosition.y == dsb->ds3db_ds3db.vPosition.y &&
258 dsb->device->ds3dl.vPosition.z == dsb->ds3db_ds3db.vPosition.z) {
259 dsb->volpan.lPan = 0;
260 flAngle = 0.0;
262 else
264 vDistance = VectorBetweenTwoPoints(&dsb->device->ds3dl.vPosition, &dsb->ds3db_ds3db.vPosition);
265 vLeft = VectorProduct(&dsb->device->ds3dl.vOrientFront, &dsb->device->ds3dl.vOrientTop);
266 flAngle = AngleBetweenVectorsRad(&vLeft, &vDistance);
267 /* for now, we'll use "linear formula" (which is probably incorrect); if someone has it in book, correct it */
268 dsb->volpan.lPan = 10000*2*flAngle/M_PI - 10000;
270 TRACE("panning: Angle = %f rad, lPan = %d\n", flAngle, dsb->volpan.lPan);
272 /* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */
273 #if 0
274 /* doppler shift*/
275 if ((VectorMagnitude(&ds3db.vVelocity) == 0) && (VectorMagnitude(&dsb->device->ds3dl.vVelocity) == 0))
277 TRACE("doppler: Buffer and Listener don't have velocities\n");
279 else
281 /* calculate length of ds3db.vVelocity component which causes Doppler Effect
282 NOTE: if buffer moves TOWARDS the listener, it's velocity component is NEGATIVE
283 if buffer moves AWAY from listener, it's velocity component is POSITIVE */
284 flBufferVel = ProjectVector(&dsb->ds3db_ds3db.vVelocity, &vDistance);
285 /* calculate length of ds3dl.vVelocity component which causes Doppler Effect
286 NOTE: if listener moves TOWARDS the buffer, it's velocity component is POSITIVE
287 if listener moves AWAY from buffer, it's velocity component is NEGATIVE */
288 flListenerVel = ProjectVector(&dsb->device->ds3dl.vVelocity, &vDistance);
289 /* formula taken from Gianicoli D.: Physics, 4th edition: */
290 /* FIXME: replace dsb->freq with appropriate frequency ! */
291 flFreq = dsb->freq * ((DEFAULT_VELOCITY + flListenerVel)/(DEFAULT_VELOCITY + flBufferVel));
292 TRACE("doppler: Buffer velocity (component) = %lf, Listener velocity (component) = %lf => Doppler shift: %ld Hz -> %lf Hz\n", flBufferVel, flListenerVel,
293 dsb->freq, flFreq);
294 /* FIXME: replace following line with correct frequency setting ! */
295 dsb->freq = flFreq;
297 #endif
299 /* time for remix */
300 DSOUND_RecalcVolPan(&dsb->volpan);
303 static void DSOUND_Mix3DBuffer(IDirectSoundBufferImpl *dsb)
305 TRACE("(%p)\n",dsb);
307 DSOUND_Calc3DBuffer(dsb);
310 static void DSOUND_ChangeListener(IDirectSound3DListenerImpl *ds3dl)
312 int i;
313 TRACE("(%p)\n",ds3dl);
314 for (i = 0; i < ds3dl->device->nrofbuffers; i++)
316 /* check if this buffer is waiting for recalculation */
317 if (ds3dl->device->buffers[i]->ds3db_need_recalc)
319 DSOUND_Mix3DBuffer(ds3dl->device->buffers[i]);
324 /*******************************************************************************
325 * IDirectSound3DBuffer
328 /* IUnknown methods */
329 static HRESULT WINAPI IDirectSound3DBufferImpl_QueryInterface(
330 LPDIRECTSOUND3DBUFFER iface, REFIID riid, LPVOID *ppobj)
332 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
334 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
335 return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb, riid, ppobj);
338 static ULONG WINAPI IDirectSound3DBufferImpl_AddRef(LPDIRECTSOUND3DBUFFER iface)
340 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
341 ULONG ref = InterlockedIncrement(&(This->ref));
342 TRACE("(%p) ref was %d\n", This, ref - 1);
343 return ref;
346 static ULONG WINAPI IDirectSound3DBufferImpl_Release(LPDIRECTSOUND3DBUFFER iface)
348 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
349 ULONG ref = InterlockedDecrement(&(This->ref));
350 TRACE("(%p) ref was %d\n", This, ref + 1);
352 if (!ref) {
353 This->dsb->ds3db = NULL;
354 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
355 HeapFree(GetProcessHeap(), 0, This);
356 TRACE("(%p) released\n", This);
358 return ref;
361 /* IDirectSound3DBuffer methods */
362 static HRESULT WINAPI IDirectSound3DBufferImpl_GetAllParameters(
363 LPDIRECTSOUND3DBUFFER iface,
364 LPDS3DBUFFER lpDs3dBuffer)
366 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
367 TRACE("(%p,%p)\n",This,lpDs3dBuffer);
369 if (lpDs3dBuffer == NULL) {
370 WARN("invalid parameter: lpDs3dBuffer == NULL\n");
371 return DSERR_INVALIDPARAM;
374 if (lpDs3dBuffer->dwSize < sizeof(*lpDs3dBuffer)) {
375 WARN("invalid parameter: lpDs3dBuffer->dwSize = %d\n",lpDs3dBuffer->dwSize);
376 return DSERR_INVALIDPARAM;
379 TRACE("returning: all parameters\n");
380 *lpDs3dBuffer = This->dsb->ds3db_ds3db;
381 return DS_OK;
384 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeAngles(
385 LPDIRECTSOUND3DBUFFER iface,
386 LPDWORD lpdwInsideConeAngle,
387 LPDWORD lpdwOutsideConeAngle)
389 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
390 TRACE("returning: Inside Cone Angle = %d degrees; Outside Cone Angle = %d degrees\n",
391 This->dsb->ds3db_ds3db.dwInsideConeAngle, This->dsb->ds3db_ds3db.dwOutsideConeAngle);
392 *lpdwInsideConeAngle = This->dsb->ds3db_ds3db.dwInsideConeAngle;
393 *lpdwOutsideConeAngle = This->dsb->ds3db_ds3db.dwOutsideConeAngle;
394 return DS_OK;
397 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOrientation(
398 LPDIRECTSOUND3DBUFFER iface,
399 LPD3DVECTOR lpvConeOrientation)
401 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
402 TRACE("returning: Cone Orientation vector = (%f,%f,%f)\n",
403 This->dsb->ds3db_ds3db.vConeOrientation.x,
404 This->dsb->ds3db_ds3db.vConeOrientation.y,
405 This->dsb->ds3db_ds3db.vConeOrientation.z);
406 *lpvConeOrientation = This->dsb->ds3db_ds3db.vConeOrientation;
407 return DS_OK;
410 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOutsideVolume(
411 LPDIRECTSOUND3DBUFFER iface,
412 LPLONG lplConeOutsideVolume)
414 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
415 TRACE("returning: Cone Outside Volume = %d\n", This->dsb->ds3db_ds3db.lConeOutsideVolume);
416 *lplConeOutsideVolume = This->dsb->ds3db_ds3db.lConeOutsideVolume;
417 return DS_OK;
420 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMaxDistance(
421 LPDIRECTSOUND3DBUFFER iface,
422 LPD3DVALUE lpfMaxDistance)
424 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
425 TRACE("returning: Max Distance = %f\n", This->dsb->ds3db_ds3db.flMaxDistance);
426 *lpfMaxDistance = This->dsb->ds3db_ds3db.flMaxDistance;
427 return DS_OK;
430 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMinDistance(
431 LPDIRECTSOUND3DBUFFER iface,
432 LPD3DVALUE lpfMinDistance)
434 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
435 TRACE("returning: Min Distance = %f\n", This->dsb->ds3db_ds3db.flMinDistance);
436 *lpfMinDistance = This->dsb->ds3db_ds3db.flMinDistance;
437 return DS_OK;
440 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMode(
441 LPDIRECTSOUND3DBUFFER iface,
442 LPDWORD lpdwMode)
444 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
445 TRACE("returning: Mode = %d\n", This->dsb->ds3db_ds3db.dwMode);
446 *lpdwMode = This->dsb->ds3db_ds3db.dwMode;
447 return DS_OK;
450 static HRESULT WINAPI IDirectSound3DBufferImpl_GetPosition(
451 LPDIRECTSOUND3DBUFFER iface,
452 LPD3DVECTOR lpvPosition)
454 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
455 TRACE("returning: Position vector = (%f,%f,%f)\n",
456 This->dsb->ds3db_ds3db.vPosition.x,
457 This->dsb->ds3db_ds3db.vPosition.y,
458 This->dsb->ds3db_ds3db.vPosition.z);
459 *lpvPosition = This->dsb->ds3db_ds3db.vPosition;
460 return DS_OK;
463 static HRESULT WINAPI IDirectSound3DBufferImpl_GetVelocity(
464 LPDIRECTSOUND3DBUFFER iface,
465 LPD3DVECTOR lpvVelocity)
467 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
468 TRACE("returning: Velocity vector = (%f,%f,%f)\n",
469 This->dsb->ds3db_ds3db.vVelocity.x,
470 This->dsb->ds3db_ds3db.vVelocity.y,
471 This->dsb->ds3db_ds3db.vVelocity.z);
472 *lpvVelocity = This->dsb->ds3db_ds3db.vVelocity;
473 return DS_OK;
476 static HRESULT WINAPI IDirectSound3DBufferImpl_SetAllParameters(
477 LPDIRECTSOUND3DBUFFER iface,
478 LPCDS3DBUFFER lpcDs3dBuffer,
479 DWORD dwApply)
481 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
482 DWORD status = DSERR_INVALIDPARAM;
483 TRACE("(%p,%p,%x)\n",iface,lpcDs3dBuffer,dwApply);
485 if (lpcDs3dBuffer == NULL) {
486 WARN("invalid parameter: lpcDs3dBuffer == NULL\n");
487 return status;
490 if (lpcDs3dBuffer->dwSize != sizeof(DS3DBUFFER)) {
491 WARN("invalid parameter: lpcDs3dBuffer->dwSize = %d\n", lpcDs3dBuffer->dwSize);
492 return status;
495 TRACE("setting: all parameters; dwApply = %d\n", dwApply);
496 This->dsb->ds3db_ds3db = *lpcDs3dBuffer;
498 if (dwApply == DS3D_IMMEDIATE)
500 DSOUND_Mix3DBuffer(This->dsb);
502 This->dsb->ds3db_need_recalc = TRUE;
503 status = DS_OK;
505 return status;
508 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeAngles(
509 LPDIRECTSOUND3DBUFFER iface,
510 DWORD dwInsideConeAngle,
511 DWORD dwOutsideConeAngle,
512 DWORD dwApply)
514 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
515 TRACE("setting: Inside Cone Angle = %d; Outside Cone Angle = %d; dwApply = %d\n",
516 dwInsideConeAngle, dwOutsideConeAngle, dwApply);
517 This->dsb->ds3db_ds3db.dwInsideConeAngle = dwInsideConeAngle;
518 This->dsb->ds3db_ds3db.dwOutsideConeAngle = dwOutsideConeAngle;
519 if (dwApply == DS3D_IMMEDIATE)
521 DSOUND_Mix3DBuffer(This->dsb);
523 This->dsb->ds3db_need_recalc = TRUE;
524 return DS_OK;
527 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOrientation(
528 LPDIRECTSOUND3DBUFFER iface,
529 D3DVALUE x, D3DVALUE y, D3DVALUE z,
530 DWORD dwApply)
532 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
533 TRACE("setting: Cone Orientation vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
534 This->dsb->ds3db_ds3db.vConeOrientation.x = x;
535 This->dsb->ds3db_ds3db.vConeOrientation.y = y;
536 This->dsb->ds3db_ds3db.vConeOrientation.z = z;
537 if (dwApply == DS3D_IMMEDIATE)
539 This->dsb->ds3db_need_recalc = FALSE;
540 DSOUND_Mix3DBuffer(This->dsb);
542 This->dsb->ds3db_need_recalc = TRUE;
543 return DS_OK;
546 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOutsideVolume(
547 LPDIRECTSOUND3DBUFFER iface,
548 LONG lConeOutsideVolume,
549 DWORD dwApply)
551 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
552 TRACE("setting: ConeOutsideVolume = %d; dwApply = %d\n", lConeOutsideVolume, dwApply);
553 This->dsb->ds3db_ds3db.lConeOutsideVolume = lConeOutsideVolume;
554 if (dwApply == DS3D_IMMEDIATE)
556 This->dsb->ds3db_need_recalc = FALSE;
557 DSOUND_Mix3DBuffer(This->dsb);
559 This->dsb->ds3db_need_recalc = TRUE;
560 return DS_OK;
563 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMaxDistance(
564 LPDIRECTSOUND3DBUFFER iface,
565 D3DVALUE fMaxDistance,
566 DWORD dwApply)
568 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
569 TRACE("setting: MaxDistance = %f; dwApply = %d\n", fMaxDistance, dwApply);
570 This->dsb->ds3db_ds3db.flMaxDistance = fMaxDistance;
571 if (dwApply == DS3D_IMMEDIATE)
573 This->dsb->ds3db_need_recalc = FALSE;
574 DSOUND_Mix3DBuffer(This->dsb);
576 This->dsb->ds3db_need_recalc = TRUE;
577 return DS_OK;
580 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMinDistance(
581 LPDIRECTSOUND3DBUFFER iface,
582 D3DVALUE fMinDistance,
583 DWORD dwApply)
585 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
586 TRACE("setting: MinDistance = %f; dwApply = %d\n", fMinDistance, dwApply);
587 This->dsb->ds3db_ds3db.flMinDistance = fMinDistance;
588 if (dwApply == DS3D_IMMEDIATE)
590 This->dsb->ds3db_need_recalc = FALSE;
591 DSOUND_Mix3DBuffer(This->dsb);
593 This->dsb->ds3db_need_recalc = TRUE;
594 return DS_OK;
597 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMode(
598 LPDIRECTSOUND3DBUFFER iface,
599 DWORD dwMode,
600 DWORD dwApply)
602 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
603 TRACE("setting: Mode = %d; dwApply = %d\n", dwMode, dwApply);
604 This->dsb->ds3db_ds3db.dwMode = dwMode;
605 if (dwApply == DS3D_IMMEDIATE)
607 This->dsb->ds3db_need_recalc = FALSE;
608 DSOUND_Mix3DBuffer(This->dsb);
610 This->dsb->ds3db_need_recalc = TRUE;
611 return DS_OK;
614 static HRESULT WINAPI IDirectSound3DBufferImpl_SetPosition(
615 LPDIRECTSOUND3DBUFFER iface,
616 D3DVALUE x, D3DVALUE y, D3DVALUE z,
617 DWORD dwApply)
619 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
620 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
621 This->dsb->ds3db_ds3db.vPosition.x = x;
622 This->dsb->ds3db_ds3db.vPosition.y = y;
623 This->dsb->ds3db_ds3db.vPosition.z = z;
624 if (dwApply == DS3D_IMMEDIATE)
626 This->dsb->ds3db_need_recalc = FALSE;
627 DSOUND_Mix3DBuffer(This->dsb);
629 This->dsb->ds3db_need_recalc = TRUE;
630 return DS_OK;
633 static HRESULT WINAPI IDirectSound3DBufferImpl_SetVelocity(
634 LPDIRECTSOUND3DBUFFER iface,
635 D3DVALUE x, D3DVALUE y, D3DVALUE z,
636 DWORD dwApply)
638 IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
639 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
640 This->dsb->ds3db_ds3db.vVelocity.x = x;
641 This->dsb->ds3db_ds3db.vVelocity.y = y;
642 This->dsb->ds3db_ds3db.vVelocity.z = z;
643 if (dwApply == DS3D_IMMEDIATE)
645 This->dsb->ds3db_need_recalc = FALSE;
646 DSOUND_Mix3DBuffer(This->dsb);
648 This->dsb->ds3db_need_recalc = TRUE;
649 return DS_OK;
652 static const IDirectSound3DBufferVtbl ds3dbvt =
654 /* IUnknown methods */
655 IDirectSound3DBufferImpl_QueryInterface,
656 IDirectSound3DBufferImpl_AddRef,
657 IDirectSound3DBufferImpl_Release,
658 /* IDirectSound3DBuffer methods */
659 IDirectSound3DBufferImpl_GetAllParameters,
660 IDirectSound3DBufferImpl_GetConeAngles,
661 IDirectSound3DBufferImpl_GetConeOrientation,
662 IDirectSound3DBufferImpl_GetConeOutsideVolume,
663 IDirectSound3DBufferImpl_GetMaxDistance,
664 IDirectSound3DBufferImpl_GetMinDistance,
665 IDirectSound3DBufferImpl_GetMode,
666 IDirectSound3DBufferImpl_GetPosition,
667 IDirectSound3DBufferImpl_GetVelocity,
668 IDirectSound3DBufferImpl_SetAllParameters,
669 IDirectSound3DBufferImpl_SetConeAngles,
670 IDirectSound3DBufferImpl_SetConeOrientation,
671 IDirectSound3DBufferImpl_SetConeOutsideVolume,
672 IDirectSound3DBufferImpl_SetMaxDistance,
673 IDirectSound3DBufferImpl_SetMinDistance,
674 IDirectSound3DBufferImpl_SetMode,
675 IDirectSound3DBufferImpl_SetPosition,
676 IDirectSound3DBufferImpl_SetVelocity,
679 HRESULT IDirectSound3DBufferImpl_Create(
680 IDirectSoundBufferImpl *dsb,
681 IDirectSound3DBufferImpl **pds3db)
683 IDirectSound3DBufferImpl *ds3db;
684 TRACE("(%p,%p)\n",dsb,pds3db);
686 ds3db = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*ds3db));
688 if (ds3db == NULL) {
689 WARN("out of memory\n");
690 *pds3db = 0;
691 return DSERR_OUTOFMEMORY;
694 ds3db->ref = 0;
695 ds3db->dsb = dsb;
696 ds3db->lpVtbl = &ds3dbvt;
698 ds3db->dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
699 ds3db->dsb->ds3db_ds3db.vPosition.x = 0.0;
700 ds3db->dsb->ds3db_ds3db.vPosition.y = 0.0;
701 ds3db->dsb->ds3db_ds3db.vPosition.z = 0.0;
702 ds3db->dsb->ds3db_ds3db.vVelocity.x = 0.0;
703 ds3db->dsb->ds3db_ds3db.vVelocity.y = 0.0;
704 ds3db->dsb->ds3db_ds3db.vVelocity.z = 0.0;
705 ds3db->dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
706 ds3db->dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
707 ds3db->dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
708 ds3db->dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
709 ds3db->dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
710 ds3db->dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
711 ds3db->dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
712 ds3db->dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
713 ds3db->dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
715 ds3db->dsb->ds3db_need_recalc = TRUE;
717 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
719 *pds3db = ds3db;
720 return S_OK;
723 HRESULT IDirectSound3DBufferImpl_Destroy(
724 IDirectSound3DBufferImpl *pds3db)
726 TRACE("(%p)\n",pds3db);
728 while (IDirectSound3DBufferImpl_Release((LPDIRECTSOUND3DBUFFER)pds3db) > 0);
730 return S_OK;
733 /*******************************************************************************
734 * IDirectSound3DListener
737 /* IUnknown methods */
738 static HRESULT WINAPI IDirectSound3DListenerImpl_QueryInterface(
739 LPDIRECTSOUND3DLISTENER iface, REFIID riid, LPVOID *ppobj)
741 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
743 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
745 if (ppobj == NULL) {
746 WARN("invalid parameter\n");
747 return E_INVALIDARG;
750 *ppobj = NULL; /* assume failure */
752 if ( IsEqualGUID(riid, &IID_IUnknown) ||
753 IsEqualGUID(riid, &IID_IDirectSound3DListener ) ) {
754 IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)This);
755 *ppobj = This;
756 return S_OK;
759 if ( IsEqualGUID(riid, &IID_IDirectSoundBuffer) ) {
760 if (!This->device->primary)
761 PrimaryBufferImpl_Create(This->device, &(This->device->primary), &(This->device->dsbd));
762 if (This->device->primary) {
763 *ppobj = This->device->primary;
764 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)*ppobj);
765 return S_OK;
769 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
770 return E_NOINTERFACE;
773 static ULONG WINAPI IDirectSound3DListenerImpl_AddRef(LPDIRECTSOUND3DLISTENER iface)
775 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
776 ULONG ref = InterlockedIncrement(&(This->ref));
777 TRACE("(%p) ref was %d\n", This, ref - 1);
778 return ref;
781 static ULONG WINAPI IDirectSound3DListenerImpl_Release(LPDIRECTSOUND3DLISTENER iface)
783 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
784 ULONG ref = InterlockedDecrement(&(This->ref));
785 TRACE("(%p) ref was %d\n", This, ref + 1);
787 if (!ref) {
788 This->device->listener = 0;
789 HeapFree(GetProcessHeap(), 0, This);
790 TRACE("(%p) released\n", This);
792 return ref;
795 /* IDirectSound3DListener methods */
796 static HRESULT WINAPI IDirectSound3DListenerImpl_GetAllParameter(
797 LPDIRECTSOUND3DLISTENER iface,
798 LPDS3DLISTENER lpDS3DL)
800 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
801 TRACE("(%p,%p)\n",This,lpDS3DL);
803 if (lpDS3DL == NULL) {
804 WARN("invalid parameter: lpDS3DL == NULL\n");
805 return DSERR_INVALIDPARAM;
808 if (lpDS3DL->dwSize < sizeof(*lpDS3DL)) {
809 WARN("invalid parameter: lpDS3DL->dwSize = %d\n",lpDS3DL->dwSize);
810 return DSERR_INVALIDPARAM;
813 TRACE("returning: all parameters\n");
814 *lpDS3DL = This->device->ds3dl;
815 return DS_OK;
818 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDistanceFactor(
819 LPDIRECTSOUND3DLISTENER iface,
820 LPD3DVALUE lpfDistanceFactor)
822 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
823 TRACE("returning: Distance Factor = %f\n", This->device->ds3dl.flDistanceFactor);
824 *lpfDistanceFactor = This->device->ds3dl.flDistanceFactor;
825 return DS_OK;
828 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDopplerFactor(
829 LPDIRECTSOUND3DLISTENER iface,
830 LPD3DVALUE lpfDopplerFactor)
832 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
833 TRACE("returning: Doppler Factor = %f\n", This->device->ds3dl.flDopplerFactor);
834 *lpfDopplerFactor = This->device->ds3dl.flDopplerFactor;
835 return DS_OK;
838 static HRESULT WINAPI IDirectSound3DListenerImpl_GetOrientation(
839 LPDIRECTSOUND3DLISTENER iface,
840 LPD3DVECTOR lpvOrientFront,
841 LPD3DVECTOR lpvOrientTop)
843 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
844 TRACE("returning: OrientFront vector = (%f,%f,%f); OrientTop vector = (%f,%f,%f)\n", This->device->ds3dl.vOrientFront.x,
845 This->device->ds3dl.vOrientFront.y, This->device->ds3dl.vOrientFront.z, This->device->ds3dl.vOrientTop.x, This->device->ds3dl.vOrientTop.y,
846 This->device->ds3dl.vOrientTop.z);
847 *lpvOrientFront = This->device->ds3dl.vOrientFront;
848 *lpvOrientTop = This->device->ds3dl.vOrientTop;
849 return DS_OK;
852 static HRESULT WINAPI IDirectSound3DListenerImpl_GetPosition(
853 LPDIRECTSOUND3DLISTENER iface,
854 LPD3DVECTOR lpvPosition)
856 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
857 TRACE("returning: Position vector = (%f,%f,%f)\n", This->device->ds3dl.vPosition.x, This->device->ds3dl.vPosition.y, This->device->ds3dl.vPosition.z);
858 *lpvPosition = This->device->ds3dl.vPosition;
859 return DS_OK;
862 static HRESULT WINAPI IDirectSound3DListenerImpl_GetRolloffFactor(
863 LPDIRECTSOUND3DLISTENER iface,
864 LPD3DVALUE lpfRolloffFactor)
866 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
867 TRACE("returning: RolloffFactor = %f\n", This->device->ds3dl.flRolloffFactor);
868 *lpfRolloffFactor = This->device->ds3dl.flRolloffFactor;
869 return DS_OK;
872 static HRESULT WINAPI IDirectSound3DListenerImpl_GetVelocity(
873 LPDIRECTSOUND3DLISTENER iface,
874 LPD3DVECTOR lpvVelocity)
876 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
877 TRACE("returning: Velocity vector = (%f,%f,%f)\n", This->device->ds3dl.vVelocity.x, This->device->ds3dl.vVelocity.y, This->device->ds3dl.vVelocity.z);
878 *lpvVelocity = This->device->ds3dl.vVelocity;
879 return DS_OK;
882 static HRESULT WINAPI IDirectSound3DListenerImpl_SetAllParameters(
883 LPDIRECTSOUND3DLISTENER iface,
884 LPCDS3DLISTENER lpcDS3DL,
885 DWORD dwApply)
887 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
888 TRACE("setting: all parameters; dwApply = %d\n", dwApply);
889 This->device->ds3dl = *lpcDS3DL;
890 if (dwApply == DS3D_IMMEDIATE)
892 This->device->ds3dl_need_recalc = FALSE;
893 DSOUND_ChangeListener(This);
895 This->device->ds3dl_need_recalc = TRUE;
896 return DS_OK;
899 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDistanceFactor(
900 LPDIRECTSOUND3DLISTENER iface,
901 D3DVALUE fDistanceFactor,
902 DWORD dwApply)
904 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
905 TRACE("setting: Distance Factor = %f; dwApply = %d\n", fDistanceFactor, dwApply);
906 This->device->ds3dl.flDistanceFactor = fDistanceFactor;
907 if (dwApply == DS3D_IMMEDIATE)
909 This->device->ds3dl_need_recalc = FALSE;
910 DSOUND_ChangeListener(This);
912 This->device->ds3dl_need_recalc = TRUE;
913 return DS_OK;
916 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDopplerFactor(
917 LPDIRECTSOUND3DLISTENER iface,
918 D3DVALUE fDopplerFactor,
919 DWORD dwApply)
921 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
922 TRACE("setting: Doppler Factor = %f; dwApply = %d\n", fDopplerFactor, dwApply);
923 This->device->ds3dl.flDopplerFactor = fDopplerFactor;
924 if (dwApply == DS3D_IMMEDIATE)
926 This->device->ds3dl_need_recalc = FALSE;
927 DSOUND_ChangeListener(This);
929 This->device->ds3dl_need_recalc = TRUE;
930 return DS_OK;
933 static HRESULT WINAPI IDirectSound3DListenerImpl_SetOrientation(
934 LPDIRECTSOUND3DLISTENER iface,
935 D3DVALUE xFront, D3DVALUE yFront, D3DVALUE zFront,
936 D3DVALUE xTop, D3DVALUE yTop, D3DVALUE zTop,
937 DWORD dwApply)
939 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
940 TRACE("setting: Front vector = (%f,%f,%f); Top vector = (%f,%f,%f); dwApply = %d\n",
941 xFront, yFront, zFront, xTop, yTop, zTop, dwApply);
942 This->device->ds3dl.vOrientFront.x = xFront;
943 This->device->ds3dl.vOrientFront.y = yFront;
944 This->device->ds3dl.vOrientFront.z = zFront;
945 This->device->ds3dl.vOrientTop.x = xTop;
946 This->device->ds3dl.vOrientTop.y = yTop;
947 This->device->ds3dl.vOrientTop.z = zTop;
948 if (dwApply == DS3D_IMMEDIATE)
950 This->device->ds3dl_need_recalc = FALSE;
951 DSOUND_ChangeListener(This);
953 This->device->ds3dl_need_recalc = TRUE;
954 return DS_OK;
957 static HRESULT WINAPI IDirectSound3DListenerImpl_SetPosition(
958 LPDIRECTSOUND3DLISTENER iface,
959 D3DVALUE x, D3DVALUE y, D3DVALUE z,
960 DWORD dwApply)
962 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
963 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
964 This->device->ds3dl.vPosition.x = x;
965 This->device->ds3dl.vPosition.y = y;
966 This->device->ds3dl.vPosition.z = z;
967 if (dwApply == DS3D_IMMEDIATE)
969 This->device->ds3dl_need_recalc = FALSE;
970 DSOUND_ChangeListener(This);
972 This->device->ds3dl_need_recalc = TRUE;
973 return DS_OK;
976 static HRESULT WINAPI IDirectSound3DListenerImpl_SetRolloffFactor(
977 LPDIRECTSOUND3DLISTENER iface,
978 D3DVALUE fRolloffFactor,
979 DWORD dwApply)
981 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
982 TRACE("setting: Rolloff Factor = %f; dwApply = %d\n", fRolloffFactor, dwApply);
983 This->device->ds3dl.flRolloffFactor = fRolloffFactor;
984 if (dwApply == DS3D_IMMEDIATE)
986 This->device->ds3dl_need_recalc = FALSE;
987 DSOUND_ChangeListener(This);
989 This->device->ds3dl_need_recalc = TRUE;
990 return DS_OK;
993 static HRESULT WINAPI IDirectSound3DListenerImpl_SetVelocity(
994 LPDIRECTSOUND3DLISTENER iface,
995 D3DVALUE x, D3DVALUE y, D3DVALUE z,
996 DWORD dwApply)
998 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
999 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
1000 This->device->ds3dl.vVelocity.x = x;
1001 This->device->ds3dl.vVelocity.y = y;
1002 This->device->ds3dl.vVelocity.z = z;
1003 if (dwApply == DS3D_IMMEDIATE)
1005 This->device->ds3dl_need_recalc = FALSE;
1006 DSOUND_ChangeListener(This);
1008 This->device->ds3dl_need_recalc = TRUE;
1009 return DS_OK;
1012 static HRESULT WINAPI IDirectSound3DListenerImpl_CommitDeferredSettings(
1013 LPDIRECTSOUND3DLISTENER iface)
1015 IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
1016 TRACE("\n");
1017 DSOUND_ChangeListener(This);
1018 return DS_OK;
1021 static const IDirectSound3DListenerVtbl ds3dlvt =
1023 /* IUnknown methods */
1024 IDirectSound3DListenerImpl_QueryInterface,
1025 IDirectSound3DListenerImpl_AddRef,
1026 IDirectSound3DListenerImpl_Release,
1027 /* IDirectSound3DListener methods */
1028 IDirectSound3DListenerImpl_GetAllParameter,
1029 IDirectSound3DListenerImpl_GetDistanceFactor,
1030 IDirectSound3DListenerImpl_GetDopplerFactor,
1031 IDirectSound3DListenerImpl_GetOrientation,
1032 IDirectSound3DListenerImpl_GetPosition,
1033 IDirectSound3DListenerImpl_GetRolloffFactor,
1034 IDirectSound3DListenerImpl_GetVelocity,
1035 IDirectSound3DListenerImpl_SetAllParameters,
1036 IDirectSound3DListenerImpl_SetDistanceFactor,
1037 IDirectSound3DListenerImpl_SetDopplerFactor,
1038 IDirectSound3DListenerImpl_SetOrientation,
1039 IDirectSound3DListenerImpl_SetPosition,
1040 IDirectSound3DListenerImpl_SetRolloffFactor,
1041 IDirectSound3DListenerImpl_SetVelocity,
1042 IDirectSound3DListenerImpl_CommitDeferredSettings,
1045 HRESULT IDirectSound3DListenerImpl_Create(
1046 DirectSoundDevice * device,
1047 IDirectSound3DListenerImpl ** ppdsl)
1049 IDirectSound3DListenerImpl *pdsl;
1050 TRACE("(%p,%p)\n",device,ppdsl);
1052 pdsl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*pdsl));
1054 if (pdsl == NULL) {
1055 WARN("out of memory\n");
1056 *ppdsl = 0;
1057 return DSERR_OUTOFMEMORY;
1060 pdsl->ref = 0;
1061 pdsl->lpVtbl = &ds3dlvt;
1063 pdsl->device = device;
1065 pdsl->device->ds3dl.dwSize = sizeof(DS3DLISTENER);
1066 pdsl->device->ds3dl.vPosition.x = 0.0;
1067 pdsl->device->ds3dl.vPosition.y = 0.0;
1068 pdsl->device->ds3dl.vPosition.z = 0.0;
1069 pdsl->device->ds3dl.vVelocity.x = 0.0;
1070 pdsl->device->ds3dl.vVelocity.y = 0.0;
1071 pdsl->device->ds3dl.vVelocity.z = 0.0;
1072 pdsl->device->ds3dl.vOrientFront.x = 0.0;
1073 pdsl->device->ds3dl.vOrientFront.y = 0.0;
1074 pdsl->device->ds3dl.vOrientFront.z = 1.0;
1075 pdsl->device->ds3dl.vOrientTop.x = 0.0;
1076 pdsl->device->ds3dl.vOrientTop.y = 1.0;
1077 pdsl->device->ds3dl.vOrientTop.z = 0.0;
1078 pdsl->device->ds3dl.flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
1079 pdsl->device->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
1080 pdsl->device->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
1082 pdsl->device->ds3dl_need_recalc = TRUE;
1084 *ppdsl = pdsl;
1085 return S_OK;