Get rid of the no longer used ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
[wine/multimedia.git] / dlls / dsound / sound3d.c
blob8ebc94e0d0be2c88b972c47e51f11f7bd76ae4e2
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "config.h"
41 #include <assert.h>
42 #include <stdarg.h>
43 #include <stdio.h>
44 #include <sys/types.h>
45 #include <sys/fcntl.h>
46 #ifdef HAVE_UNISTD_H
47 # include <unistd.h>
48 #endif
49 #include <stdlib.h>
50 #include <string.h>
51 #include <math.h> /* Insomnia - pow() function */
53 #define NONAMELESSUNION
54 #define NONAMELESSSTRUCT
55 #include "windef.h"
56 #include "winbase.h"
57 #include "wingdi.h"
58 #include "winuser.h"
59 #include "winerror.h"
60 #include "mmsystem.h"
61 #include "winreg.h"
62 #include "winternl.h"
63 #include "mmddk.h"
64 #include "wine/windef16.h"
65 #include "wine/debug.h"
66 #include "dsound.h"
67 #include "dsdriver.h"
68 #include "dsound_private.h"
70 /* default intensity level for human ears */
71 #define DEFAULT_INTENSITY 0.000000000001f
72 /* default velocity of sound in the air */
73 #define DEFAULT_VELOCITY 340
75 WINE_DEFAULT_DEBUG_CHANNEL(dsound3d);
77 /*******************************************************************************
78 * Auxiliary functions
81 /* scalar product (i believe it's called dot product in english) */
82 static inline D3DVALUE ScalarProduct (LPD3DVECTOR a, LPD3DVECTOR b)
84 D3DVALUE c;
85 c = (a->x*b->x) + (a->y*b->y) + (a->z*b->z);
86 TRACE("(%f,%f,%f) * (%f,%f,%f) = %f)\n", a->x, a->y, a->z, b->x, b->y, \
87 b->z, c);
88 return c;
91 /* vector product (i believe it's called cross product in english */
92 static inline D3DVECTOR VectorProduct (LPD3DVECTOR a, LPD3DVECTOR b)
94 D3DVECTOR c;
95 c.x = (a->y*b->z) - (a->z*b->y);
96 c.y = (a->z*b->x) - (a->x*b->z);
97 c.z = (a->x*b->y) - (a->y*b->x);
98 TRACE("(%f,%f,%f) x (%f,%f,%f) = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y, \
99 b->z, c.x, c.y, c.z);
100 return c;
103 /* magnitude (length) of vector */
104 static inline D3DVALUE VectorMagnitude (LPD3DVECTOR a)
106 D3DVALUE l;
107 l = sqrt (ScalarProduct (a, a));
108 TRACE("|(%f,%f,%f)| = %f\n", a->x, a->y, a->z, l);
109 return l;
112 /* conversion between radians and degrees */
113 static inline D3DVALUE RadToDeg (D3DVALUE angle)
115 D3DVALUE newangle;
116 newangle = angle * (360/(2*M_PI));
117 TRACE("%f rad = %f deg\n", angle, newangle);
118 return newangle;
121 /* conversion between degrees and radians */
122 static inline D3DVALUE DegToRad (D3DVALUE angle)
124 D3DVALUE newangle;
125 newangle = angle * (2*M_PI/360);
126 TRACE("%f deg = %f rad\n", angle, newangle);
127 return newangle;
130 /* angle between vectors - deg version */
131 static inline D3DVALUE AngleBetweenVectorsDeg (LPD3DVECTOR a, LPD3DVECTOR b)
133 D3DVALUE la, lb, product, angle, cos;
134 /* definition of scalar product: a*b = |a|*|b|*cos...therefore: */
135 product = ScalarProduct (a,b);
136 la = VectorMagnitude (a);
137 lb = VectorMagnitude (b);
138 cos = product/(la*lb);
139 angle = acos(cos);
140 /* we now have angle in radians */
141 angle = RadToDeg(angle);
142 TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f degrees\n", a->x, a->y, a->z, b->x,
143 b->y, b->z, angle);
144 return angle;
147 /* angle between vectors - rad version */
148 static inline D3DVALUE AngleBetweenVectorsRad (LPD3DVECTOR a, LPD3DVECTOR b)
150 D3DVALUE la, lb, product, angle, cos;
151 /* definition of scalar product: a*b = |a|*|b|*cos...therefore: */
152 product = ScalarProduct (a,b);
153 la = VectorMagnitude (a);
154 lb = VectorMagnitude (b);
155 cos = product/(la*lb);
156 angle = acos(cos);
157 TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians\n", a->x, a->y, a->z, b->x,
158 b->y, b->z, angle);
159 return angle;
162 /* calculates vector between two points */
163 static inline D3DVECTOR VectorBetweenTwoPoints (LPD3DVECTOR a, LPD3DVECTOR b)
165 D3DVECTOR c;
166 c.x = b->x - a->x;
167 c.y = b->y - a->y;
168 c.z = b->z - a->z;
169 TRACE("A (%f,%f,%f), B (%f,%f,%f), AB = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y,
170 b->z, c.x, c.y, c.z);
171 return c;
174 /* calculates the length of vector's projection on another vector */
175 static inline D3DVALUE ProjectVector (LPD3DVECTOR a, LPD3DVECTOR p)
177 D3DVALUE prod, result;
178 prod = ScalarProduct(a, p);
179 result = prod/VectorMagnitude(p);
180 TRACE("length projection of (%f,%f,%f) on (%f,%f,%f) = %f\n", a->x, a->y, a->z, p->x,
181 p->y, p->z, result);
182 return result;
185 /*******************************************************************************
186 * 3D Buffer and Listener mixing
189 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb)
191 /* volume, at which the sound will be played after all calcs. */
192 D3DVALUE lVolume = 0;
193 /* intensity (used for distance related stuff) */
194 double flIntensity;
195 double flTemp;
196 /* stuff for distance related stuff calc. */
197 D3DVECTOR vDistance;
198 D3DVALUE flDistance = 0;
199 /* panning related stuff */
200 D3DVALUE flAngle;
201 D3DVECTOR vLeft;
202 /* doppler shift related stuff */
203 #if 0
204 D3DVALUE flFreq, flBufferVel, flListenerVel;
205 #endif
207 TRACE("(%p)\n",dsb);
209 /* initial buffer volume */
210 lVolume = dsb->ds3db_lVolume;
212 switch (dsb->ds3db_ds3db.dwMode)
214 case DS3DMODE_DISABLE:
215 TRACE("3D processing disabled\n");
216 /* this one is here only to eliminate annoying warning message */
217 DSOUND_RecalcVolPan (&dsb->volpan);
218 DSOUND_ForceRemix (dsb);
219 break;
220 case DS3DMODE_NORMAL:
221 TRACE("Normal 3D processing mode\n");
222 /* we need to calculate distance between buffer and listener*/
223 vDistance = VectorBetweenTwoPoints(&dsb->ds3db_ds3db.vPosition, &dsb->dsound->ds3dl.vPosition);
224 flDistance = VectorMagnitude (&vDistance);
225 break;
226 case DS3DMODE_HEADRELATIVE:
227 TRACE("Head-relative 3D processing mode\n");
228 /* distance between buffer and listener is same as buffer's position */
229 flDistance = VectorMagnitude (&dsb->ds3db_ds3db.vPosition);
230 break;
233 if (flDistance > dsb->ds3db_ds3db.flMaxDistance)
235 /* some apps don't want you to hear too distant sounds... */
236 if (dsb->dsbd.dwFlags & DSBCAPS_MUTE3DATMAXDISTANCE)
238 dsb->volpan.lVolume = DSBVOLUME_MIN;
239 DSOUND_RecalcVolPan (&dsb->volpan);
240 /* i guess mixing here would be a waste of power */
241 return;
243 else
244 flDistance = dsb->ds3db_ds3db.flMaxDistance;
247 if (flDistance < dsb->ds3db_ds3db.flMinDistance)
248 flDistance = dsb->ds3db_ds3db.flMinDistance;
250 /* 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 */
251 lVolume += 10000; /* ms likes working with negative volume...i don't */
252 lVolume /= 1000; /* convert hundreths of dB into B */
253 /* intensity level (loudness) = log10(Intensity/DefaultIntensity)...therefore */
254 flIntensity = pow(10,lVolume)*DEFAULT_INTENSITY;
255 flTemp = (flDistance/dsb->ds3db_ds3db.flMinDistance)*(flDistance/dsb->ds3db_ds3db.flMinDistance);
256 flIntensity /= flTemp;
257 lVolume = log10(flIntensity/DEFAULT_INTENSITY);
258 lVolume *= 1000; /* convert back to hundreths of dB */
259 lVolume -= 10000; /* we need to do it in ms way */
260 TRACE("dist. att: Distance = %f, MinDistance = %f => adjusting volume %ld to %f\n", flDistance, dsb->ds3db_ds3db.flMinDistance, dsb->ds3db_lVolume, lVolume);
262 /* conning */
263 /* sometimes it happens that vConeOrientation vector = (0,0,0); in this case angle is "nan" and it's useless*/
264 if (dsb->ds3db_ds3db.vConeOrientation.x == 0 && dsb->ds3db_ds3db.vConeOrientation.y == 0 && dsb->ds3db_ds3db.vConeOrientation.z == 0)
266 TRACE("conning: cones not set\n");
268 else
270 /* calculate angle */
271 flAngle = AngleBetweenVectorsDeg(&dsb->ds3db_ds3db.vConeOrientation, &vDistance);
272 /* if by any chance it happens that OutsideConeAngle = InsideConeAngle (that means that conning has no effect) */
273 if (dsb->ds3db_ds3db.dwInsideConeAngle != dsb->ds3db_ds3db.dwOutsideConeAngle)
275 /* my test show that for my way of calc., we need only half of angles */
276 DWORD dwInsideConeAngle = dsb->ds3db_ds3db.dwInsideConeAngle/2;
277 DWORD dwOutsideConeAngle = dsb->ds3db_ds3db.dwOutsideConeAngle/2;
278 /* full volume */
279 if (flAngle < dwInsideConeAngle)
280 flAngle = dwInsideConeAngle;
281 /* min (app defined) volume */
282 if (flAngle > dwOutsideConeAngle)
283 flAngle = dwOutsideConeAngle;
284 /* this probably isn't the right thing, but it's ok for the time being */
285 lVolume += ((dsb->ds3db_ds3db.lConeOutsideVolume)/((dwOutsideConeAngle) - (dwInsideConeAngle))) * flAngle;
287 TRACE("conning: Angle = %f deg; InsideConeAngle(/2) = %ld deg; OutsideConeAngle(/2) = %ld deg; ConeOutsideVolume = %ld => adjusting volume to %f\n",
288 flAngle, dsb->ds3db_ds3db.dwInsideConeAngle/2, dsb->ds3db_ds3db.dwOutsideConeAngle/2, dsb->ds3db_ds3db.lConeOutsideVolume, lVolume);
290 dsb->volpan.lVolume = lVolume;
292 /* panning */
293 if (dsb->dsound->ds3dl.vPosition.x == dsb->ds3db_ds3db.vPosition.x &&
294 dsb->dsound->ds3dl.vPosition.y == dsb->ds3db_ds3db.vPosition.y &&
295 dsb->dsound->ds3dl.vPosition.z == dsb->ds3db_ds3db.vPosition.z) {
296 dsb->volpan.lPan = 0;
297 flAngle = 0.0;
299 else
301 vDistance = VectorBetweenTwoPoints(&dsb->dsound->ds3dl.vPosition, &dsb->ds3db_ds3db.vPosition);
302 vLeft = VectorProduct(&dsb->dsound->ds3dl.vOrientFront, &dsb->dsound->ds3dl.vOrientTop);
303 flAngle = AngleBetweenVectorsRad(&vLeft, &vDistance);
304 /* for now, we'll use "linear formula" (which is probably incorrect); if someone has it in book, correct it */
305 dsb->volpan.lPan = 10000*2*flAngle/M_PI - 10000;
307 TRACE("panning: Angle = %f rad, lPan = %ld\n", flAngle, dsb->volpan.lPan);
309 /* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */
310 #if 0
311 /* doppler shift*/
312 if ((VectorMagnitude(&ds3db.vVelocity) == 0) && (VectorMagnitude(&dsb->dsound->ds3dl.vVelocity) == 0))
314 TRACE("doppler: Buffer and Listener don't have velocities\n");
316 else
318 /* calculate length of ds3db.vVelocity component which causes Doppler Effect
319 NOTE: if buffer moves TOWARDS the listener, it's velocity component is NEGATIVE
320 if buffer moves AWAY from listener, it's velocity component is POSITIVE */
321 flBufferVel = ProjectVector(&dsb->ds3db_ds3db.vVelocity, &vDistance);
322 /* calculate length of ds3dl.vVelocity component which causes Doppler Effect
323 NOTE: if listener moves TOWARDS the buffer, it's velocity component is POSITIVE
324 if listener moves AWAY from buffer, it's velocity component is NEGATIVE */
325 flListenerVel = ProjectVector(&dsb->dsound->ds3dl.vVelocity, &vDistance);
326 /* formula taken from Gianicoli D.: Physics, 4th edition: */
327 /* FIXME: replace dsb->freq with appropriate frequency ! */
328 flFreq = dsb->freq * ((DEFAULT_VELOCITY + flListenerVel)/(DEFAULT_VELOCITY + flBufferVel));
329 TRACE("doppler: Buffer velocity (component) = %lf, Listener velocity (component) = %lf => Doppler shift: %ld Hz -> %lf Hz\n", flBufferVel, flListenerVel, \
330 dsb->freq, flFreq);
331 /* FIXME: replace following line with correct frequency setting ! */
332 dsb->freq = flFreq;
334 #endif
336 /* time for remix */
337 DSOUND_RecalcVolPan(&dsb->volpan);
340 static void DSOUND_Mix3DBuffer(IDirectSoundBufferImpl *dsb)
342 TRACE("(%p)\n",dsb);
344 DSOUND_Calc3DBuffer(dsb);
345 DSOUND_ForceRemix(dsb);
348 static void WINAPI DSOUND_ChangeListener(IDirectSound3DListenerImpl *ds3dl)
350 int i;
351 TRACE("(%p)\n",ds3dl);
352 for (i = 0; i < ds3dl->dsound->nrofbuffers; i++)
354 /* some buffers don't have 3d buffer (Ultima IX seems to
355 crash without the following line) */
356 if (ds3dl->dsound->buffers[i]->ds3db == NULL)
357 continue;
358 if (ds3dl->dsound->buffers[i]->ds3db_need_recalc == TRUE)
360 DSOUND_Mix3DBuffer(ds3dl->dsound->buffers[i]);
365 /*******************************************************************************
366 * IDirectSound3DBuffer
369 /* IUnknown methods */
370 static HRESULT WINAPI IDirectSound3DBufferImpl_QueryInterface(
371 LPDIRECTSOUND3DBUFFER iface, REFIID riid, LPVOID *ppobj)
373 ICOM_THIS(IDirectSound3DBufferImpl,iface);
375 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
376 return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb, riid, ppobj);
379 static ULONG WINAPI IDirectSound3DBufferImpl_AddRef(LPDIRECTSOUND3DBUFFER iface)
381 ICOM_THIS(IDirectSound3DBufferImpl,iface);
382 ULONG ref;
384 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
385 ref = InterlockedIncrement(&This->ref);
386 if (!ref) {
387 FIXME("thread-safety alert! AddRef-ing with a zero refcount!\n");
389 return ref;
392 static ULONG WINAPI IDirectSound3DBufferImpl_Release(LPDIRECTSOUND3DBUFFER iface)
394 ICOM_THIS(IDirectSound3DBufferImpl,iface);
395 ULONG ulReturn;
397 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
398 ulReturn = InterlockedDecrement(&This->ref);
399 if (!ulReturn) {
400 This->dsb->ds3db = NULL;
401 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
402 HeapFree(GetProcessHeap(),0,This);
403 TRACE("(%p) released\n",This);
406 return ulReturn;
409 /* IDirectSound3DBuffer methods */
410 static HRESULT WINAPI IDirectSound3DBufferImpl_GetAllParameters(
411 LPDIRECTSOUND3DBUFFER iface,
412 LPDS3DBUFFER lpDs3dBuffer)
414 ICOM_THIS(IDirectSound3DBufferImpl,iface);
415 TRACE("(%p,%p)\n",This,lpDs3dBuffer);
417 if (lpDs3dBuffer == NULL) {
418 WARN("invalid parameter: lpDs3dBuffer == NULL\n");
419 return DSERR_INVALIDPARAM;
422 if (lpDs3dBuffer->dwSize < sizeof(*lpDs3dBuffer)) {
423 WARN("invalid parameter: lpDs3dBuffer->dwSize = %ld < %d\n",lpDs3dBuffer->dwSize, sizeof(*lpDs3dBuffer));
424 return DSERR_INVALIDPARAM;
427 TRACE("returning: all parameters\n");
428 *lpDs3dBuffer = This->dsb->ds3db_ds3db;
429 return DS_OK;
432 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeAngles(
433 LPDIRECTSOUND3DBUFFER iface,
434 LPDWORD lpdwInsideConeAngle,
435 LPDWORD lpdwOutsideConeAngle)
437 ICOM_THIS(IDirectSound3DBufferImpl,iface);
438 TRACE("returning: Inside Cone Angle = %ld degrees; Outside Cone Angle = %ld degrees\n",
439 This->dsb->ds3db_ds3db.dwInsideConeAngle, This->dsb->ds3db_ds3db.dwOutsideConeAngle);
440 *lpdwInsideConeAngle = This->dsb->ds3db_ds3db.dwInsideConeAngle;
441 *lpdwOutsideConeAngle = This->dsb->ds3db_ds3db.dwOutsideConeAngle;
442 return DS_OK;
445 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOrientation(
446 LPDIRECTSOUND3DBUFFER iface,
447 LPD3DVECTOR lpvConeOrientation)
449 ICOM_THIS(IDirectSound3DBufferImpl,iface);
450 TRACE("returning: Cone Orientation vector = (%f,%f,%f)\n",
451 This->dsb->ds3db_ds3db.vConeOrientation.x,
452 This->dsb->ds3db_ds3db.vConeOrientation.y,
453 This->dsb->ds3db_ds3db.vConeOrientation.z);
454 *lpvConeOrientation = This->dsb->ds3db_ds3db.vConeOrientation;
455 return DS_OK;
458 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOutsideVolume(
459 LPDIRECTSOUND3DBUFFER iface,
460 LPLONG lplConeOutsideVolume)
462 ICOM_THIS(IDirectSound3DBufferImpl,iface);
463 TRACE("returning: Cone Outside Volume = %ld\n", This->dsb->ds3db_ds3db.lConeOutsideVolume);
464 *lplConeOutsideVolume = This->dsb->ds3db_ds3db.lConeOutsideVolume;
465 return DS_OK;
468 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMaxDistance(
469 LPDIRECTSOUND3DBUFFER iface,
470 LPD3DVALUE lpfMaxDistance)
472 ICOM_THIS(IDirectSound3DBufferImpl,iface);
473 TRACE("returning: Max Distance = %f\n", This->dsb->ds3db_ds3db.flMaxDistance);
474 *lpfMaxDistance = This->dsb->ds3db_ds3db.flMaxDistance;
475 return DS_OK;
478 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMinDistance(
479 LPDIRECTSOUND3DBUFFER iface,
480 LPD3DVALUE lpfMinDistance)
482 ICOM_THIS(IDirectSound3DBufferImpl,iface);
483 TRACE("returning: Min Distance = %f\n", This->dsb->ds3db_ds3db.flMinDistance);
484 *lpfMinDistance = This->dsb->ds3db_ds3db.flMinDistance;
485 return DS_OK;
488 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMode(
489 LPDIRECTSOUND3DBUFFER iface,
490 LPDWORD lpdwMode)
492 ICOM_THIS(IDirectSound3DBufferImpl,iface);
493 TRACE("returning: Mode = %ld\n", This->dsb->ds3db_ds3db.dwMode);
494 *lpdwMode = This->dsb->ds3db_ds3db.dwMode;
495 return DS_OK;
498 static HRESULT WINAPI IDirectSound3DBufferImpl_GetPosition(
499 LPDIRECTSOUND3DBUFFER iface,
500 LPD3DVECTOR lpvPosition)
502 ICOM_THIS(IDirectSound3DBufferImpl,iface);
503 TRACE("returning: Position vector = (%f,%f,%f)\n",
504 This->dsb->ds3db_ds3db.vPosition.x,
505 This->dsb->ds3db_ds3db.vPosition.y,
506 This->dsb->ds3db_ds3db.vPosition.z);
507 *lpvPosition = This->dsb->ds3db_ds3db.vPosition;
508 return DS_OK;
511 static HRESULT WINAPI IDirectSound3DBufferImpl_GetVelocity(
512 LPDIRECTSOUND3DBUFFER iface,
513 LPD3DVECTOR lpvVelocity)
515 ICOM_THIS(IDirectSound3DBufferImpl,iface);
516 TRACE("returning: Velocity vector = (%f,%f,%f)\n",
517 This->dsb->ds3db_ds3db.vVelocity.x,
518 This->dsb->ds3db_ds3db.vVelocity.y,
519 This->dsb->ds3db_ds3db.vVelocity.z);
520 *lpvVelocity = This->dsb->ds3db_ds3db.vVelocity;
521 return DS_OK;
524 static HRESULT WINAPI IDirectSound3DBufferImpl_SetAllParameters(
525 LPDIRECTSOUND3DBUFFER iface,
526 LPCDS3DBUFFER lpcDs3dBuffer,
527 DWORD dwApply)
529 ICOM_THIS(IDirectSound3DBufferImpl,iface);
530 DWORD status = DSERR_INVALIDPARAM;
531 TRACE("(%p,%p,%lx)\n",iface,lpcDs3dBuffer,dwApply);
533 if (lpcDs3dBuffer == NULL) {
534 WARN("invalid parameter: lpcDs3dBuffer == NULL\n");
535 return status;
538 if (lpcDs3dBuffer->dwSize != sizeof(DS3DBUFFER)) {
539 WARN("invalid parameter: lpcDs3dBuffer->dwSize = %ld != %d\n",
540 lpcDs3dBuffer->dwSize, sizeof(DS3DBUFFER));
541 return status;
544 TRACE("setting: all parameters; dwApply = %ld\n", dwApply);
545 This->dsb->ds3db_ds3db = *lpcDs3dBuffer;
547 if (dwApply == DS3D_IMMEDIATE)
549 DSOUND_Mix3DBuffer(This->dsb);
551 This->dsb->ds3db_need_recalc = TRUE;
552 status = DS_OK;
554 return status;
557 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeAngles(
558 LPDIRECTSOUND3DBUFFER iface,
559 DWORD dwInsideConeAngle,
560 DWORD dwOutsideConeAngle,
561 DWORD dwApply)
563 ICOM_THIS(IDirectSound3DBufferImpl,iface);
564 TRACE("setting: Inside Cone Angle = %ld; Outside Cone Angle = %ld; dwApply = %ld\n",
565 dwInsideConeAngle, dwOutsideConeAngle, dwApply);
566 This->dsb->ds3db_ds3db.dwInsideConeAngle = dwInsideConeAngle;
567 This->dsb->ds3db_ds3db.dwOutsideConeAngle = dwOutsideConeAngle;
568 if (dwApply == DS3D_IMMEDIATE)
570 DSOUND_Mix3DBuffer(This->dsb);
572 This->dsb->ds3db_need_recalc = TRUE;
573 return DS_OK;
576 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOrientation(
577 LPDIRECTSOUND3DBUFFER iface,
578 D3DVALUE x, D3DVALUE y, D3DVALUE z,
579 DWORD dwApply)
581 ICOM_THIS(IDirectSound3DBufferImpl,iface);
582 TRACE("setting: Cone Orientation vector = (%f,%f,%f); dwApply = %ld\n", x, y, z, dwApply);
583 This->dsb->ds3db_ds3db.vConeOrientation.x = x;
584 This->dsb->ds3db_ds3db.vConeOrientation.y = y;
585 This->dsb->ds3db_ds3db.vConeOrientation.z = z;
586 if (dwApply == DS3D_IMMEDIATE)
588 This->dsb->ds3db_need_recalc = FALSE;
589 DSOUND_Mix3DBuffer(This->dsb);
591 This->dsb->ds3db_need_recalc = TRUE;
592 return DS_OK;
595 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOutsideVolume(
596 LPDIRECTSOUND3DBUFFER iface,
597 LONG lConeOutsideVolume,
598 DWORD dwApply)
600 ICOM_THIS(IDirectSound3DBufferImpl,iface);
601 TRACE("setting: ConeOutsideVolume = %ld; dwApply = %ld\n", lConeOutsideVolume, dwApply);
602 This->dsb->ds3db_ds3db.lConeOutsideVolume = lConeOutsideVolume;
603 if (dwApply == DS3D_IMMEDIATE)
605 This->dsb->ds3db_need_recalc = FALSE;
606 DSOUND_Mix3DBuffer(This->dsb);
608 This->dsb->ds3db_need_recalc = TRUE;
609 return DS_OK;
612 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMaxDistance(
613 LPDIRECTSOUND3DBUFFER iface,
614 D3DVALUE fMaxDistance,
615 DWORD dwApply)
617 ICOM_THIS(IDirectSound3DBufferImpl,iface);
618 TRACE("setting: MaxDistance = %f; dwApply = %ld\n", fMaxDistance, dwApply);
619 This->dsb->ds3db_ds3db.flMaxDistance = fMaxDistance;
620 if (dwApply == DS3D_IMMEDIATE)
622 This->dsb->ds3db_need_recalc = FALSE;
623 DSOUND_Mix3DBuffer(This->dsb);
625 This->dsb->ds3db_need_recalc = TRUE;
626 return DS_OK;
629 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMinDistance(
630 LPDIRECTSOUND3DBUFFER iface,
631 D3DVALUE fMinDistance,
632 DWORD dwApply)
634 ICOM_THIS(IDirectSound3DBufferImpl,iface);
635 TRACE("setting: MinDistance = %f; dwApply = %ld\n", fMinDistance, dwApply);
636 This->dsb->ds3db_ds3db.flMinDistance = fMinDistance;
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_SetMode(
647 LPDIRECTSOUND3DBUFFER iface,
648 DWORD dwMode,
649 DWORD dwApply)
651 ICOM_THIS(IDirectSound3DBufferImpl,iface);
652 TRACE("setting: Mode = %ld; dwApply = %ld\n", dwMode, dwApply);
653 This->dsb->ds3db_ds3db.dwMode = dwMode;
654 if (dwApply == DS3D_IMMEDIATE)
656 This->dsb->ds3db_need_recalc = FALSE;
657 DSOUND_Mix3DBuffer(This->dsb);
659 This->dsb->ds3db_need_recalc = TRUE;
660 return DS_OK;
663 static HRESULT WINAPI IDirectSound3DBufferImpl_SetPosition(
664 LPDIRECTSOUND3DBUFFER iface,
665 D3DVALUE x, D3DVALUE y, D3DVALUE z,
666 DWORD dwApply)
668 ICOM_THIS(IDirectSound3DBufferImpl,iface);
669 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %ld\n", x, y, z, dwApply);
670 This->dsb->ds3db_ds3db.vPosition.x = x;
671 This->dsb->ds3db_ds3db.vPosition.y = y;
672 This->dsb->ds3db_ds3db.vPosition.z = z;
673 if (dwApply == DS3D_IMMEDIATE)
675 This->dsb->ds3db_need_recalc = FALSE;
676 DSOUND_Mix3DBuffer(This->dsb);
678 This->dsb->ds3db_need_recalc = TRUE;
679 return DS_OK;
682 static HRESULT WINAPI IDirectSound3DBufferImpl_SetVelocity(
683 LPDIRECTSOUND3DBUFFER iface,
684 D3DVALUE x, D3DVALUE y, D3DVALUE z,
685 DWORD dwApply)
687 ICOM_THIS(IDirectSound3DBufferImpl,iface);
688 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %ld\n", x, y, z, dwApply);
689 This->dsb->ds3db_ds3db.vVelocity.x = x;
690 This->dsb->ds3db_ds3db.vVelocity.y = y;
691 This->dsb->ds3db_ds3db.vVelocity.z = z;
692 if (dwApply == DS3D_IMMEDIATE)
694 This->dsb->ds3db_need_recalc = FALSE;
695 DSOUND_Mix3DBuffer(This->dsb);
697 This->dsb->ds3db_need_recalc = TRUE;
698 return DS_OK;
701 static IDirectSound3DBufferVtbl ds3dbvt =
703 /* IUnknown methods */
704 IDirectSound3DBufferImpl_QueryInterface,
705 IDirectSound3DBufferImpl_AddRef,
706 IDirectSound3DBufferImpl_Release,
707 /* IDirectSound3DBuffer methods */
708 IDirectSound3DBufferImpl_GetAllParameters,
709 IDirectSound3DBufferImpl_GetConeAngles,
710 IDirectSound3DBufferImpl_GetConeOrientation,
711 IDirectSound3DBufferImpl_GetConeOutsideVolume,
712 IDirectSound3DBufferImpl_GetMaxDistance,
713 IDirectSound3DBufferImpl_GetMinDistance,
714 IDirectSound3DBufferImpl_GetMode,
715 IDirectSound3DBufferImpl_GetPosition,
716 IDirectSound3DBufferImpl_GetVelocity,
717 IDirectSound3DBufferImpl_SetAllParameters,
718 IDirectSound3DBufferImpl_SetConeAngles,
719 IDirectSound3DBufferImpl_SetConeOrientation,
720 IDirectSound3DBufferImpl_SetConeOutsideVolume,
721 IDirectSound3DBufferImpl_SetMaxDistance,
722 IDirectSound3DBufferImpl_SetMinDistance,
723 IDirectSound3DBufferImpl_SetMode,
724 IDirectSound3DBufferImpl_SetPosition,
725 IDirectSound3DBufferImpl_SetVelocity,
728 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
729 IDirectSoundBufferImpl *dsb,
730 IDirectSound3DBufferImpl **pds3db)
732 IDirectSound3DBufferImpl *ds3db;
733 TRACE("(%p,%p)\n",dsb,pds3db);
735 ds3db = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*ds3db));
737 if (ds3db == NULL) {
738 WARN("out of memory\n");
739 *pds3db = 0;
740 return DSERR_OUTOFMEMORY;
743 ds3db->ref = 0;
744 ds3db->dsb = dsb;
745 ds3db->lpVtbl = &ds3dbvt;
747 ds3db->dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
748 ds3db->dsb->ds3db_ds3db.vPosition.x = 0.0;
749 ds3db->dsb->ds3db_ds3db.vPosition.y = 0.0;
750 ds3db->dsb->ds3db_ds3db.vPosition.z = 0.0;
751 ds3db->dsb->ds3db_ds3db.vVelocity.x = 0.0;
752 ds3db->dsb->ds3db_ds3db.vVelocity.y = 0.0;
753 ds3db->dsb->ds3db_ds3db.vVelocity.z = 0.0;
754 ds3db->dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
755 ds3db->dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
756 ds3db->dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
757 ds3db->dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
758 ds3db->dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
759 ds3db->dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
760 ds3db->dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
761 ds3db->dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
762 ds3db->dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
764 ds3db->dsb->ds3db_need_recalc = TRUE;
766 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
768 *pds3db = ds3db;
769 return S_OK;
772 HRESULT WINAPI IDirectSound3DBufferImpl_Destroy(
773 IDirectSound3DBufferImpl *pds3db)
775 TRACE("(%p)\n",pds3db);
777 while (IDirectSound3DBufferImpl_Release((LPDIRECTSOUND3DBUFFER)pds3db) > 0);
779 return S_OK;
782 /*******************************************************************************
783 * IDirectSound3DListener
786 /* IUnknown methods */
787 static HRESULT WINAPI IDirectSound3DListenerImpl_QueryInterface(
788 LPDIRECTSOUND3DLISTENER iface, REFIID riid, LPVOID *ppobj)
790 ICOM_THIS(IDirectSound3DListenerImpl,iface);
792 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
794 if (ppobj == NULL) {
795 WARN("invalid parameter\n");
796 return E_INVALIDARG;
799 *ppobj = NULL; /* assume failure */
801 if ( IsEqualGUID(riid, &IID_IUnknown) ||
802 IsEqualGUID(riid, &IID_IDirectSound3DListener ) ) {
803 IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)This);
804 *ppobj = This;
805 return S_OK;
808 if ( IsEqualGUID(riid, &IID_IDirectSoundBuffer) ) {
809 if (!This->dsound->primary)
810 PrimaryBufferImpl_Create(This->dsound, &(This->dsound->primary), &(This->dsound->dsbd));
811 if (This->dsound->primary) {
812 *ppobj = This->dsound->primary;
813 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)*ppobj);
814 return S_OK;
818 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
819 return E_NOINTERFACE;
822 static ULONG WINAPI IDirectSound3DListenerImpl_AddRef(LPDIRECTSOUND3DLISTENER iface)
824 ICOM_THIS(IDirectSound3DListenerImpl,iface);
825 ULONG ref;
826 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
828 ref = InterlockedIncrement(&This->ref);
830 if (!ref) {
831 FIXME("thread-safety alert! AddRef-ing with a zero refcount!\n");
834 return ref;
837 static ULONG WINAPI IDirectSound3DListenerImpl_Release(LPDIRECTSOUND3DLISTENER iface)
839 ICOM_THIS(IDirectSound3DListenerImpl,iface);
840 ULONG ulReturn;
842 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
843 ulReturn = InterlockedDecrement(&This->ref);
845 /* Free all resources */
846 if( ulReturn == 0 ) {
847 This->dsound->listener = 0;
848 HeapFree(GetProcessHeap(),0,This);
849 TRACE("(%p) released\n",This);
852 return ulReturn;
855 /* IDirectSound3DListener methods */
856 static HRESULT WINAPI IDirectSound3DListenerImpl_GetAllParameter(
857 LPDIRECTSOUND3DLISTENER iface,
858 LPDS3DLISTENER lpDS3DL)
860 ICOM_THIS(IDirectSound3DListenerImpl,iface);
861 TRACE("(%p,%p)\n",This,lpDS3DL);
863 if (lpDS3DL == NULL) {
864 WARN("invalid parameter: lpDS3DL == NULL\n");
865 return DSERR_INVALIDPARAM;
868 if (lpDS3DL->dwSize < sizeof(*lpDS3DL)) {
869 WARN("invalid parameter: lpDS3DL->dwSize = %ld < %d\n",lpDS3DL->dwSize, sizeof(*lpDS3DL));
870 return DSERR_INVALIDPARAM;
873 TRACE("returning: all parameters\n");
874 *lpDS3DL = This->dsound->ds3dl;
875 return DS_OK;
878 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDistanceFactor(
879 LPDIRECTSOUND3DLISTENER iface,
880 LPD3DVALUE lpfDistanceFactor)
882 ICOM_THIS(IDirectSound3DListenerImpl,iface);
883 TRACE("returning: Distance Factor = %f\n", This->dsound->ds3dl.flDistanceFactor);
884 *lpfDistanceFactor = This->dsound->ds3dl.flDistanceFactor;
885 return DS_OK;
888 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDopplerFactor(
889 LPDIRECTSOUND3DLISTENER iface,
890 LPD3DVALUE lpfDopplerFactor)
892 ICOM_THIS(IDirectSound3DListenerImpl,iface);
893 TRACE("returning: Doppler Factor = %f\n", This->dsound->ds3dl.flDopplerFactor);
894 *lpfDopplerFactor = This->dsound->ds3dl.flDopplerFactor;
895 return DS_OK;
898 static HRESULT WINAPI IDirectSound3DListenerImpl_GetOrientation(
899 LPDIRECTSOUND3DLISTENER iface,
900 LPD3DVECTOR lpvOrientFront,
901 LPD3DVECTOR lpvOrientTop)
903 ICOM_THIS(IDirectSound3DListenerImpl,iface);
904 TRACE("returning: OrientFront vector = (%f,%f,%f); OrientTop vector = (%f,%f,%f)\n", This->dsound->ds3dl.vOrientFront.x, \
905 This->dsound->ds3dl.vOrientFront.y, This->dsound->ds3dl.vOrientFront.z, This->dsound->ds3dl.vOrientTop.x, This->dsound->ds3dl.vOrientTop.y, \
906 This->dsound->ds3dl.vOrientTop.z);
907 *lpvOrientFront = This->dsound->ds3dl.vOrientFront;
908 *lpvOrientTop = This->dsound->ds3dl.vOrientTop;
909 return DS_OK;
912 static HRESULT WINAPI IDirectSound3DListenerImpl_GetPosition(
913 LPDIRECTSOUND3DLISTENER iface,
914 LPD3DVECTOR lpvPosition)
916 ICOM_THIS(IDirectSound3DListenerImpl,iface);
917 TRACE("returning: Position vector = (%f,%f,%f)\n", This->dsound->ds3dl.vPosition.x, This->dsound->ds3dl.vPosition.y, This->dsound->ds3dl.vPosition.z);
918 *lpvPosition = This->dsound->ds3dl.vPosition;
919 return DS_OK;
922 static HRESULT WINAPI IDirectSound3DListenerImpl_GetRolloffFactor(
923 LPDIRECTSOUND3DLISTENER iface,
924 LPD3DVALUE lpfRolloffFactor)
926 ICOM_THIS(IDirectSound3DListenerImpl,iface);
927 TRACE("returning: RolloffFactor = %f\n", This->dsound->ds3dl.flRolloffFactor);
928 *lpfRolloffFactor = This->dsound->ds3dl.flRolloffFactor;
929 return DS_OK;
932 static HRESULT WINAPI IDirectSound3DListenerImpl_GetVelocity(
933 LPDIRECTSOUND3DLISTENER iface,
934 LPD3DVECTOR lpvVelocity)
936 ICOM_THIS(IDirectSound3DListenerImpl,iface);
937 TRACE("returning: Velocity vector = (%f,%f,%f)\n", This->dsound->ds3dl.vVelocity.x, This->dsound->ds3dl.vVelocity.y, This->dsound->ds3dl.vVelocity.z);
938 *lpvVelocity = This->dsound->ds3dl.vVelocity;
939 return DS_OK;
942 static HRESULT WINAPI IDirectSound3DListenerImpl_SetAllParameters(
943 LPDIRECTSOUND3DLISTENER iface,
944 LPCDS3DLISTENER lpcDS3DL,
945 DWORD dwApply)
947 ICOM_THIS(IDirectSound3DListenerImpl,iface);
948 TRACE("setting: all parameters; dwApply = %ld\n", dwApply);
949 This->dsound->ds3dl = *lpcDS3DL;
950 if (dwApply == DS3D_IMMEDIATE)
952 This->dsound->ds3dl_need_recalc = FALSE;
953 DSOUND_ChangeListener(This);
955 This->dsound->ds3dl_need_recalc = TRUE;
956 return DS_OK;
959 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDistanceFactor(
960 LPDIRECTSOUND3DLISTENER iface,
961 D3DVALUE fDistanceFactor,
962 DWORD dwApply)
964 ICOM_THIS(IDirectSound3DListenerImpl,iface);
965 TRACE("setting: Distance Factor = %f; dwApply = %ld\n", fDistanceFactor, dwApply);
966 This->dsound->ds3dl.flDistanceFactor = fDistanceFactor;
967 if (dwApply == DS3D_IMMEDIATE)
969 This->dsound->ds3dl_need_recalc = FALSE;
970 DSOUND_ChangeListener(This);
972 This->dsound->ds3dl_need_recalc = TRUE;
973 return DS_OK;
976 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDopplerFactor(
977 LPDIRECTSOUND3DLISTENER iface,
978 D3DVALUE fDopplerFactor,
979 DWORD dwApply)
981 ICOM_THIS(IDirectSound3DListenerImpl,iface);
982 TRACE("setting: Doppler Factor = %f; dwApply = %ld\n", fDopplerFactor, dwApply);
983 This->dsound->ds3dl.flDopplerFactor = fDopplerFactor;
984 if (dwApply == DS3D_IMMEDIATE)
986 This->dsound->ds3dl_need_recalc = FALSE;
987 DSOUND_ChangeListener(This);
989 This->dsound->ds3dl_need_recalc = TRUE;
990 return DS_OK;
993 static HRESULT WINAPI IDirectSound3DListenerImpl_SetOrientation(
994 LPDIRECTSOUND3DLISTENER iface,
995 D3DVALUE xFront, D3DVALUE yFront, D3DVALUE zFront,
996 D3DVALUE xTop, D3DVALUE yTop, D3DVALUE zTop,
997 DWORD dwApply)
999 ICOM_THIS(IDirectSound3DListenerImpl,iface);
1000 TRACE("setting: Front vector = (%f,%f,%f); Top vector = (%f,%f,%f); dwApply = %ld\n", \
1001 xFront, yFront, zFront, xTop, yTop, zTop, dwApply);
1002 This->dsound->ds3dl.vOrientFront.x = xFront;
1003 This->dsound->ds3dl.vOrientFront.y = yFront;
1004 This->dsound->ds3dl.vOrientFront.z = zFront;
1005 This->dsound->ds3dl.vOrientTop.x = xTop;
1006 This->dsound->ds3dl.vOrientTop.y = yTop;
1007 This->dsound->ds3dl.vOrientTop.z = zTop;
1008 if (dwApply == DS3D_IMMEDIATE)
1010 This->dsound->ds3dl_need_recalc = FALSE;
1011 DSOUND_ChangeListener(This);
1013 This->dsound->ds3dl_need_recalc = TRUE;
1014 return DS_OK;
1017 static HRESULT WINAPI IDirectSound3DListenerImpl_SetPosition(
1018 LPDIRECTSOUND3DLISTENER iface,
1019 D3DVALUE x, D3DVALUE y, D3DVALUE z,
1020 DWORD dwApply)
1022 ICOM_THIS(IDirectSound3DListenerImpl,iface);
1023 TRACE("setting: Position vector = (%f,%f,%f); dwApply = %ld\n", x, y, z, dwApply);
1024 This->dsound->ds3dl.vPosition.x = x;
1025 This->dsound->ds3dl.vPosition.y = y;
1026 This->dsound->ds3dl.vPosition.z = z;
1027 if (dwApply == DS3D_IMMEDIATE)
1029 This->dsound->ds3dl_need_recalc = FALSE;
1030 DSOUND_ChangeListener(This);
1032 This->dsound->ds3dl_need_recalc = TRUE;
1033 return DS_OK;
1036 static HRESULT WINAPI IDirectSound3DListenerImpl_SetRolloffFactor(
1037 LPDIRECTSOUND3DLISTENER iface,
1038 D3DVALUE fRolloffFactor,
1039 DWORD dwApply)
1041 ICOM_THIS(IDirectSound3DListenerImpl,iface);
1042 TRACE("setting: Rolloff Factor = %f; dwApply = %ld\n", fRolloffFactor, dwApply);
1043 This->dsound->ds3dl.flRolloffFactor = fRolloffFactor;
1044 if (dwApply == DS3D_IMMEDIATE)
1046 This->dsound->ds3dl_need_recalc = FALSE;
1047 DSOUND_ChangeListener(This);
1049 This->dsound->ds3dl_need_recalc = TRUE;
1050 return DS_OK;
1053 static HRESULT WINAPI IDirectSound3DListenerImpl_SetVelocity(
1054 LPDIRECTSOUND3DLISTENER iface,
1055 D3DVALUE x, D3DVALUE y, D3DVALUE z,
1056 DWORD dwApply)
1058 ICOM_THIS(IDirectSound3DListenerImpl,iface);
1059 TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %ld\n", x, y, z, dwApply);
1060 This->dsound->ds3dl.vVelocity.x = x;
1061 This->dsound->ds3dl.vVelocity.y = y;
1062 This->dsound->ds3dl.vVelocity.z = z;
1063 if (dwApply == DS3D_IMMEDIATE)
1065 This->dsound->ds3dl_need_recalc = FALSE;
1066 DSOUND_ChangeListener(This);
1068 This->dsound->ds3dl_need_recalc = TRUE;
1069 return DS_OK;
1072 static HRESULT WINAPI IDirectSound3DListenerImpl_CommitDeferredSettings(
1073 LPDIRECTSOUND3DLISTENER iface)
1075 ICOM_THIS(IDirectSound3DListenerImpl,iface);
1076 TRACE("\n");
1077 DSOUND_ChangeListener(This);
1078 return DS_OK;
1081 static IDirectSound3DListenerVtbl ds3dlvt =
1083 /* IUnknown methods */
1084 IDirectSound3DListenerImpl_QueryInterface,
1085 IDirectSound3DListenerImpl_AddRef,
1086 IDirectSound3DListenerImpl_Release,
1087 /* IDirectSound3DListener methods */
1088 IDirectSound3DListenerImpl_GetAllParameter,
1089 IDirectSound3DListenerImpl_GetDistanceFactor,
1090 IDirectSound3DListenerImpl_GetDopplerFactor,
1091 IDirectSound3DListenerImpl_GetOrientation,
1092 IDirectSound3DListenerImpl_GetPosition,
1093 IDirectSound3DListenerImpl_GetRolloffFactor,
1094 IDirectSound3DListenerImpl_GetVelocity,
1095 IDirectSound3DListenerImpl_SetAllParameters,
1096 IDirectSound3DListenerImpl_SetDistanceFactor,
1097 IDirectSound3DListenerImpl_SetDopplerFactor,
1098 IDirectSound3DListenerImpl_SetOrientation,
1099 IDirectSound3DListenerImpl_SetPosition,
1100 IDirectSound3DListenerImpl_SetRolloffFactor,
1101 IDirectSound3DListenerImpl_SetVelocity,
1102 IDirectSound3DListenerImpl_CommitDeferredSettings,
1105 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
1106 PrimaryBufferImpl *This,
1107 IDirectSound3DListenerImpl **pdsl)
1109 IDirectSound3DListenerImpl *dsl;
1110 TRACE("(%p,%p)\n",This,pdsl);
1112 dsl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsl));
1114 if (dsl == NULL) {
1115 WARN("out of memory\n");
1116 *pdsl = 0;
1117 return DSERR_OUTOFMEMORY;
1120 dsl->ref = 0;
1121 dsl->lpVtbl = &ds3dlvt;
1123 dsl->dsound = This->dsound;
1125 dsl->dsound->ds3dl.dwSize = sizeof(DS3DLISTENER);
1126 dsl->dsound->ds3dl.vPosition.x = 0.0;
1127 dsl->dsound->ds3dl.vPosition.y = 0.0;
1128 dsl->dsound->ds3dl.vPosition.z = 0.0;
1129 dsl->dsound->ds3dl.vVelocity.x = 0.0;
1130 dsl->dsound->ds3dl.vVelocity.y = 0.0;
1131 dsl->dsound->ds3dl.vVelocity.z = 0.0;
1132 dsl->dsound->ds3dl.vOrientFront.x = 0.0;
1133 dsl->dsound->ds3dl.vOrientFront.y = 0.0;
1134 dsl->dsound->ds3dl.vOrientFront.z = 1.0;
1135 dsl->dsound->ds3dl.vOrientTop.x = 0.0;
1136 dsl->dsound->ds3dl.vOrientTop.y = 1.0;
1137 dsl->dsound->ds3dl.vOrientTop.z = 0.0;
1138 dsl->dsound->ds3dl.flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
1139 dsl->dsound->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
1140 dsl->dsound->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
1142 dsl->dsound->ds3dl_need_recalc = TRUE;
1144 *pdsl = dsl;
1145 return S_OK;