dsound: Merge IDirectSound3DListener into the primary buffer object.
[wine] / dlls / dsound / sound3d.c
1 /*                      DirectSound
2  *
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>
7  *
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.
12  *
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.
17  *
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
21  */
22 /*
23  * Most thread locking is complete. There may be a few race
24  * conditions still lurking.
25  *
26  * Tested with a Soundblaster clone, a Gravis UltraSound Classic,
27  * and a Turtle Beach Tropez+.
28  *
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
38  */
39
40 #include <stdarg.h>
41 #include <math.h>       /* Insomnia - pow() function */
42
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 "dsound_private.h"
54
55 /* default velocity of sound in the air */
56 #define DEFAULT_VELOCITY 340
57
58 WINE_DEFAULT_DEBUG_CHANNEL(dsound3d);
59
60 /*******************************************************************************
61  *              Auxiliary functions
62  */
63
64 /* scalar product (I believe it's called dot product in English) */
65 static inline D3DVALUE ScalarProduct (const D3DVECTOR *a, const D3DVECTOR *b)
66 {
67         D3DVALUE c;
68         c = (a->x*b->x) + (a->y*b->y) + (a->z*b->z);
69         TRACE("(%f,%f,%f) * (%f,%f,%f) = %f)\n", a->x, a->y, a->z, b->x, b->y,
70               b->z, c);
71         return c;
72 }
73
74 /* vector product (I believe it's called cross product in English */
75 static inline D3DVECTOR VectorProduct (const D3DVECTOR *a, const D3DVECTOR *b)
76 {
77         D3DVECTOR c;
78         c.x = (a->y*b->z) - (a->z*b->y);
79         c.y = (a->z*b->x) - (a->x*b->z);
80         c.z = (a->x*b->y) - (a->y*b->x);
81         TRACE("(%f,%f,%f) x (%f,%f,%f) = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y,
82               b->z, c.x, c.y, c.z);
83         return c;
84 }
85
86 /* magnitude (length) of vector */
87 static inline D3DVALUE VectorMagnitude (const D3DVECTOR *a)
88 {
89         D3DVALUE l;
90         l = sqrt (ScalarProduct (a, a));
91         TRACE("|(%f,%f,%f)| = %f\n", a->x, a->y, a->z, l);
92         return l;
93 }
94
95 /* conversion between radians and degrees */
96 static inline D3DVALUE RadToDeg (D3DVALUE angle)
97 {
98         D3DVALUE newangle;
99         newangle = angle * (360/(2*M_PI));
100         TRACE("%f rad = %f deg\n", angle, newangle);
101         return newangle;
102 }
103
104 /* angle between vectors - rad version */
105 static inline D3DVALUE AngleBetweenVectorsRad (const D3DVECTOR *a, const D3DVECTOR *b)
106 {
107         D3DVALUE la, lb, product, angle, cos;
108         /* definition of scalar product: a*b = |a|*|b|*cos... therefore: */
109         product = ScalarProduct (a,b);
110         la = VectorMagnitude (a);
111         lb = VectorMagnitude (b);
112         if (!la || !lb)
113                 return 0;
114
115         cos = product/(la*lb);
116         angle = acos(cos);
117         TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians (%f degrees)\n",  a->x, a->y, a->z, b->x,
118               b->y, b->z, angle, RadToDeg(angle));
119         return angle;   
120 }
121
122 static inline D3DVALUE AngleBetweenVectorsDeg (const D3DVECTOR *a, const D3DVECTOR *b)
123 {
124         return RadToDeg(AngleBetweenVectorsRad(a, b));
125 }
126
127 /* calculates vector between two points */
128 static inline D3DVECTOR VectorBetweenTwoPoints (const D3DVECTOR *a, const D3DVECTOR *b)
129 {
130         D3DVECTOR c;
131         c.x = b->x - a->x;
132         c.y = b->y - a->y;
133         c.z = b->z - a->z;
134         TRACE("A (%f,%f,%f), B (%f,%f,%f), AB = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y,
135               b->z, c.x, c.y, c.z);
136         return c;
137 }
138
139 /* calculates the length of vector's projection on another vector */
140 static inline D3DVALUE ProjectVector (const D3DVECTOR *a, const D3DVECTOR *p)
141 {
142         D3DVALUE prod, result;
143         prod = ScalarProduct(a, p);
144         result = prod/VectorMagnitude(p);
145         TRACE("length projection of (%f,%f,%f) on (%f,%f,%f) = %f\n", a->x, a->y, a->z, p->x,
146               p->y, p->z, result);
147         return result;
148 }
149
150 /*******************************************************************************
151  *              3D Buffer and Listener mixing
152  */
153
154 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb)
155 {
156         /* volume, at which the sound will be played after all calcs. */
157         D3DVALUE lVolume = 0;
158         /* stuff for distance related stuff calc. */
159         D3DVECTOR vDistance;
160         D3DVALUE flDistance = 0;
161         /* panning related stuff */
162         D3DVALUE flAngle;
163         D3DVECTOR vLeft;
164         /* doppler shift related stuff */
165
166         TRACE("(%p)\n",dsb);
167
168         /* initial buffer volume */
169         lVolume = dsb->ds3db_lVolume;
170         
171         switch (dsb->ds3db_ds3db.dwMode)
172         {
173                 case DS3DMODE_DISABLE:
174                         TRACE("3D processing disabled\n");
175                         /* this one is here only to eliminate annoying warning message */
176                         DSOUND_RecalcVolPan (&dsb->volpan);
177                         break;
178                 case DS3DMODE_NORMAL:
179                         TRACE("Normal 3D processing mode\n");
180                         /* we need to calculate distance between buffer and listener*/
181                         vDistance = VectorBetweenTwoPoints(&dsb->ds3db_ds3db.vPosition, &dsb->device->ds3dl.vPosition);
182                         flDistance = VectorMagnitude (&vDistance);
183                         break;
184                 case DS3DMODE_HEADRELATIVE:
185                         TRACE("Head-relative 3D processing mode\n");
186                         /* distance between buffer and listener is same as buffer's position */
187                         flDistance = VectorMagnitude (&dsb->ds3db_ds3db.vPosition);
188                         break;
189         }
190         
191         if (flDistance > dsb->ds3db_ds3db.flMaxDistance)
192         {
193                 /* some apps don't want you to hear too distant sounds... */
194                 if (dsb->dsbd.dwFlags & DSBCAPS_MUTE3DATMAXDISTANCE)
195                 {
196                         dsb->volpan.lVolume = DSBVOLUME_MIN;
197                         DSOUND_RecalcVolPan (&dsb->volpan);             
198                         /* i guess mixing here would be a waste of power */
199                         return;
200                 }
201                 else
202                         flDistance = dsb->ds3db_ds3db.flMaxDistance;
203         }               
204
205         if (flDistance < dsb->ds3db_ds3db.flMinDistance)
206                 flDistance = dsb->ds3db_ds3db.flMinDistance;
207         
208         /* attenuation proportional to the distance squared, converted to millibels as in lVolume*/
209         lVolume -= log10(flDistance/dsb->ds3db_ds3db.flMinDistance * flDistance/dsb->ds3db_ds3db.flMinDistance)*1000;
210         TRACE("dist. att: Distance = %f, MinDistance = %f => adjusting volume %d to %f\n", flDistance, dsb->ds3db_ds3db.flMinDistance, dsb->ds3db_lVolume, lVolume);
211
212         /* conning */
213         /* sometimes it happens that vConeOrientation vector = (0,0,0); in this case angle is "nan" and it's useless*/
214         if (dsb->ds3db_ds3db.vConeOrientation.x == 0 && dsb->ds3db_ds3db.vConeOrientation.y == 0 && dsb->ds3db_ds3db.vConeOrientation.z == 0)
215         {
216                 TRACE("conning: cones not set\n");
217         }
218         else
219         {
220                 /* calculate angle */
221                 flAngle = AngleBetweenVectorsDeg(&dsb->ds3db_ds3db.vConeOrientation, &vDistance);
222                 /* if by any chance it happens that OutsideConeAngle = InsideConeAngle (that means that conning has no effect) */
223                 if (dsb->ds3db_ds3db.dwInsideConeAngle != dsb->ds3db_ds3db.dwOutsideConeAngle)
224                 {
225                         /* my test show that for my way of calc., we need only half of angles */
226                         DWORD dwInsideConeAngle = dsb->ds3db_ds3db.dwInsideConeAngle/2;
227                         DWORD dwOutsideConeAngle = dsb->ds3db_ds3db.dwOutsideConeAngle/2;
228                         if (dwOutsideConeAngle == dwInsideConeAngle)
229                                 ++dwOutsideConeAngle;
230
231                         /* full volume */
232                         if (flAngle < dwInsideConeAngle)
233                                 flAngle = dwInsideConeAngle;
234                         /* min (app defined) volume */
235                         if (flAngle > dwOutsideConeAngle)
236                                 flAngle = dwOutsideConeAngle;
237                         /* this probably isn't the right thing, but it's ok for the time being */
238                         lVolume += ((dsb->ds3db_ds3db.lConeOutsideVolume)/((dwOutsideConeAngle) - (dwInsideConeAngle))) * flAngle;
239                 }
240                 TRACE("conning: Angle = %f deg; InsideConeAngle(/2) = %d deg; OutsideConeAngle(/2) = %d deg; ConeOutsideVolume = %d => adjusting volume to %f\n",
241                        flAngle, dsb->ds3db_ds3db.dwInsideConeAngle/2, dsb->ds3db_ds3db.dwOutsideConeAngle/2, dsb->ds3db_ds3db.lConeOutsideVolume, lVolume);
242         }
243         dsb->volpan.lVolume = lVolume;
244         
245         /* panning */
246         if (dsb->device->ds3dl.vPosition.x == dsb->ds3db_ds3db.vPosition.x &&
247             dsb->device->ds3dl.vPosition.y == dsb->ds3db_ds3db.vPosition.y &&
248             dsb->device->ds3dl.vPosition.z == dsb->ds3db_ds3db.vPosition.z) {
249                 dsb->volpan.lPan = 0;
250                 flAngle = 0.0;
251         }
252         else
253         {
254                 vDistance = VectorBetweenTwoPoints(&dsb->device->ds3dl.vPosition, &dsb->ds3db_ds3db.vPosition);
255                 vLeft = VectorProduct(&dsb->device->ds3dl.vOrientFront, &dsb->device->ds3dl.vOrientTop);
256                 flAngle = AngleBetweenVectorsRad(&vLeft, &vDistance);
257                 /* for now, we'll use "linear formula" (which is probably incorrect); if someone has it in book, correct it */
258                 dsb->volpan.lPan = 10000*2*flAngle/M_PI - 10000;
259         }
260         TRACE("panning: Angle = %f rad, lPan = %d\n", flAngle, dsb->volpan.lPan);
261
262         /* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */
263 if(0)
264 {
265         D3DVALUE flFreq, flBufferVel, flListenerVel;
266         /* doppler shift*/
267         if (!VectorMagnitude(&dsb->ds3db_ds3db.vVelocity) && !VectorMagnitude(&dsb->device->ds3dl.vVelocity))
268         {
269                 TRACE("doppler: Buffer and Listener don't have velocities\n");
270         }
271         else if (!(dsb->ds3db_ds3db.vVelocity.x == dsb->device->ds3dl.vVelocity.x &&
272                    dsb->ds3db_ds3db.vVelocity.y == dsb->device->ds3dl.vVelocity.y &&
273                    dsb->ds3db_ds3db.vVelocity.z == dsb->device->ds3dl.vVelocity.z))
274         {
275                 /* calculate length of ds3db_ds3db.vVelocity component which causes Doppler Effect
276                    NOTE: if buffer moves TOWARDS the listener, it's velocity component is NEGATIVE
277                          if buffer moves AWAY from listener, it's velocity component is POSITIVE */
278                 flBufferVel = ProjectVector(&dsb->ds3db_ds3db.vVelocity, &vDistance);
279                 /* calculate length of ds3dl.vVelocity component which causes Doppler Effect
280                    NOTE: if listener moves TOWARDS the buffer, it's velocity component is POSITIVE
281                          if listener moves AWAY from buffer, it's velocity component is NEGATIVE */
282                 flListenerVel = ProjectVector(&dsb->device->ds3dl.vVelocity, &vDistance);
283                 /* formula taken from Gianicoli D.: Physics, 4th edition: */
284                 /* FIXME: replace dsb->freq with appropriate frequency ! */
285                 flFreq = dsb->freq * ((DEFAULT_VELOCITY + flListenerVel)/(DEFAULT_VELOCITY + flBufferVel));
286                 TRACE("doppler: Buffer velocity (component) = %f, Listener velocity (component) = %f => Doppler shift: %d Hz -> %f Hz\n",
287                       flBufferVel, flListenerVel, dsb->freq, flFreq);
288                 /* FIXME: replace following line with correct frequency setting ! */
289                 dsb->freq = flFreq;
290                 DSOUND_RecalcFormat(dsb);
291         }
292 }
293         
294         /* time for remix */
295         DSOUND_RecalcVolPan(&dsb->volpan);
296 }
297
298 static void DSOUND_Mix3DBuffer(IDirectSoundBufferImpl *dsb)
299 {
300         TRACE("(%p)\n",dsb);
301
302         DSOUND_Calc3DBuffer(dsb);
303 }
304
305 static void DSOUND_ChangeListener(IDirectSoundBufferImpl *ds3dl)
306 {
307         int i;
308         TRACE("(%p)\n",ds3dl);
309         for (i = 0; i < ds3dl->device->nrofbuffers; i++)
310         {
311                 /* check if this buffer is waiting for recalculation */
312                 if (ds3dl->device->buffers[i]->ds3db_need_recalc)
313                 {
314                         DSOUND_Mix3DBuffer(ds3dl->device->buffers[i]);
315                 }
316         }
317 }
318
319 /*******************************************************************************
320  *              IDirectSound3DBuffer
321  */
322
323 /* IUnknown methods */
324 static HRESULT WINAPI IDirectSound3DBufferImpl_QueryInterface(
325         LPDIRECTSOUND3DBUFFER iface, REFIID riid, LPVOID *ppobj)
326 {
327         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
328
329         TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
330         return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb, riid, ppobj);
331 }
332
333 static ULONG WINAPI IDirectSound3DBufferImpl_AddRef(LPDIRECTSOUND3DBUFFER iface)
334 {
335     IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
336     ULONG ref = InterlockedIncrement(&(This->ref));
337
338     TRACE("(%p) ref was %d\n", This, ref - 1);
339
340     if(ref == 1)
341         InterlockedIncrement(&This->dsb->numIfaces);
342
343     return ref;
344 }
345
346 static ULONG WINAPI IDirectSound3DBufferImpl_Release(LPDIRECTSOUND3DBUFFER iface)
347 {
348     IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
349     ULONG ref = InterlockedDecrement(&(This->ref));
350     TRACE("(%p) ref was %d\n", This, ref + 1);
351
352     if (!ref) {
353         This->dsb->ds3db = NULL;
354         if (!InterlockedDecrement(&This->dsb->numIfaces))
355             secondarybuffer_destroy(This->dsb);
356         HeapFree(GetProcessHeap(), 0, This);
357         TRACE("(%p) released\n", This);
358     }
359     return ref;
360 }
361
362 /* IDirectSound3DBuffer methods */
363 static HRESULT WINAPI IDirectSound3DBufferImpl_GetAllParameters(
364         LPDIRECTSOUND3DBUFFER iface,
365         LPDS3DBUFFER lpDs3dBuffer)
366 {
367         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
368         TRACE("(%p,%p)\n",This,lpDs3dBuffer);
369
370         if (lpDs3dBuffer == NULL) {
371                 WARN("invalid parameter: lpDs3dBuffer == NULL\n");
372                 return DSERR_INVALIDPARAM;
373         }
374
375         if (lpDs3dBuffer->dwSize < sizeof(*lpDs3dBuffer)) {
376                 WARN("invalid parameter: lpDs3dBuffer->dwSize = %d\n",lpDs3dBuffer->dwSize);
377                 return DSERR_INVALIDPARAM;
378         }
379         
380         TRACE("returning: all parameters\n");
381         *lpDs3dBuffer = This->dsb->ds3db_ds3db;
382         return DS_OK;
383 }
384
385 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeAngles(
386         LPDIRECTSOUND3DBUFFER iface,
387         LPDWORD lpdwInsideConeAngle,
388         LPDWORD lpdwOutsideConeAngle)
389 {
390         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
391         TRACE("returning: Inside Cone Angle = %d degrees; Outside Cone Angle = %d degrees\n",
392                 This->dsb->ds3db_ds3db.dwInsideConeAngle, This->dsb->ds3db_ds3db.dwOutsideConeAngle);
393         *lpdwInsideConeAngle = This->dsb->ds3db_ds3db.dwInsideConeAngle;
394         *lpdwOutsideConeAngle = This->dsb->ds3db_ds3db.dwOutsideConeAngle;
395         return DS_OK;
396 }
397
398 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOrientation(
399         LPDIRECTSOUND3DBUFFER iface,
400         LPD3DVECTOR lpvConeOrientation)
401 {
402         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
403         TRACE("returning: Cone Orientation vector = (%f,%f,%f)\n",
404                 This->dsb->ds3db_ds3db.vConeOrientation.x,
405                 This->dsb->ds3db_ds3db.vConeOrientation.y,
406                 This->dsb->ds3db_ds3db.vConeOrientation.z);
407         *lpvConeOrientation = This->dsb->ds3db_ds3db.vConeOrientation;
408         return DS_OK;
409 }
410
411 static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOutsideVolume(
412         LPDIRECTSOUND3DBUFFER iface,
413         LPLONG lplConeOutsideVolume)
414 {
415         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
416         TRACE("returning: Cone Outside Volume = %d\n", This->dsb->ds3db_ds3db.lConeOutsideVolume);
417         *lplConeOutsideVolume = This->dsb->ds3db_ds3db.lConeOutsideVolume;
418         return DS_OK;
419 }
420
421 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMaxDistance(
422         LPDIRECTSOUND3DBUFFER iface,
423         LPD3DVALUE lpfMaxDistance)
424 {
425         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
426         TRACE("returning: Max Distance = %f\n", This->dsb->ds3db_ds3db.flMaxDistance);
427         *lpfMaxDistance = This->dsb->ds3db_ds3db.flMaxDistance;
428         return DS_OK;
429 }
430
431 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMinDistance(
432         LPDIRECTSOUND3DBUFFER iface,
433         LPD3DVALUE lpfMinDistance)
434 {
435         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
436         TRACE("returning: Min Distance = %f\n", This->dsb->ds3db_ds3db.flMinDistance);
437         *lpfMinDistance = This->dsb->ds3db_ds3db.flMinDistance;
438         return DS_OK;
439 }
440
441 static HRESULT WINAPI IDirectSound3DBufferImpl_GetMode(
442         LPDIRECTSOUND3DBUFFER iface,
443         LPDWORD lpdwMode)
444 {
445         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
446         TRACE("returning: Mode = %d\n", This->dsb->ds3db_ds3db.dwMode);
447         *lpdwMode = This->dsb->ds3db_ds3db.dwMode;
448         return DS_OK;
449 }
450
451 static HRESULT WINAPI IDirectSound3DBufferImpl_GetPosition(
452         LPDIRECTSOUND3DBUFFER iface,
453         LPD3DVECTOR lpvPosition)
454 {
455         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
456         TRACE("returning: Position vector = (%f,%f,%f)\n",
457                 This->dsb->ds3db_ds3db.vPosition.x,
458                 This->dsb->ds3db_ds3db.vPosition.y,
459                 This->dsb->ds3db_ds3db.vPosition.z);
460         *lpvPosition = This->dsb->ds3db_ds3db.vPosition;
461         return DS_OK;
462 }
463
464 static HRESULT WINAPI IDirectSound3DBufferImpl_GetVelocity(
465         LPDIRECTSOUND3DBUFFER iface,
466         LPD3DVECTOR lpvVelocity)
467 {
468         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
469         TRACE("returning: Velocity vector = (%f,%f,%f)\n",
470                 This->dsb->ds3db_ds3db.vVelocity.x,
471                 This->dsb->ds3db_ds3db.vVelocity.y,
472                 This->dsb->ds3db_ds3db.vVelocity.z);
473         *lpvVelocity = This->dsb->ds3db_ds3db.vVelocity;
474         return DS_OK;
475 }
476
477 static HRESULT WINAPI IDirectSound3DBufferImpl_SetAllParameters(
478         LPDIRECTSOUND3DBUFFER iface,
479         LPCDS3DBUFFER lpcDs3dBuffer,
480         DWORD dwApply)
481 {
482         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
483         DWORD status = DSERR_INVALIDPARAM;
484         TRACE("(%p,%p,%x)\n",iface,lpcDs3dBuffer,dwApply);
485
486         if (lpcDs3dBuffer == NULL) {
487                 WARN("invalid parameter: lpcDs3dBuffer == NULL\n");
488                 return status;
489         }
490
491         if (lpcDs3dBuffer->dwSize != sizeof(DS3DBUFFER)) {
492                 WARN("invalid parameter: lpcDs3dBuffer->dwSize = %d\n", lpcDs3dBuffer->dwSize);
493                 return status;
494         }
495
496         TRACE("setting: all parameters; dwApply = %d\n", dwApply);
497         This->dsb->ds3db_ds3db = *lpcDs3dBuffer;
498
499         if (dwApply == DS3D_IMMEDIATE)
500         {
501                 DSOUND_Mix3DBuffer(This->dsb);
502         }
503         This->dsb->ds3db_need_recalc = TRUE;
504         status = DS_OK;
505
506         return status;
507 }
508
509 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeAngles(
510         LPDIRECTSOUND3DBUFFER iface,
511         DWORD dwInsideConeAngle,
512         DWORD dwOutsideConeAngle,
513         DWORD dwApply)
514 {
515         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
516         TRACE("setting: Inside Cone Angle = %d; Outside Cone Angle = %d; dwApply = %d\n",
517                 dwInsideConeAngle, dwOutsideConeAngle, dwApply);
518         This->dsb->ds3db_ds3db.dwInsideConeAngle = dwInsideConeAngle;
519         This->dsb->ds3db_ds3db.dwOutsideConeAngle = dwOutsideConeAngle;
520         if (dwApply == DS3D_IMMEDIATE)
521         {
522                 DSOUND_Mix3DBuffer(This->dsb);
523         }
524         This->dsb->ds3db_need_recalc = TRUE;
525         return DS_OK;
526 }
527
528 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOrientation(
529         LPDIRECTSOUND3DBUFFER iface,
530         D3DVALUE x, D3DVALUE y, D3DVALUE z,
531         DWORD dwApply)
532 {
533         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
534         TRACE("setting: Cone Orientation vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
535         This->dsb->ds3db_ds3db.vConeOrientation.x = x;
536         This->dsb->ds3db_ds3db.vConeOrientation.y = y;
537         This->dsb->ds3db_ds3db.vConeOrientation.z = z;
538         if (dwApply == DS3D_IMMEDIATE)
539         {
540                 This->dsb->ds3db_need_recalc = FALSE;
541                 DSOUND_Mix3DBuffer(This->dsb);
542         }
543         This->dsb->ds3db_need_recalc = TRUE;
544         return DS_OK;
545 }
546
547 static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOutsideVolume(
548         LPDIRECTSOUND3DBUFFER iface,
549         LONG lConeOutsideVolume,
550         DWORD dwApply)
551 {
552         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
553         TRACE("setting: ConeOutsideVolume = %d; dwApply = %d\n", lConeOutsideVolume, dwApply);
554         This->dsb->ds3db_ds3db.lConeOutsideVolume = lConeOutsideVolume;
555         if (dwApply == DS3D_IMMEDIATE)
556         {
557                 This->dsb->ds3db_need_recalc = FALSE;
558                 DSOUND_Mix3DBuffer(This->dsb);
559         }
560         This->dsb->ds3db_need_recalc = TRUE;
561         return DS_OK;
562 }
563
564 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMaxDistance(
565         LPDIRECTSOUND3DBUFFER iface,
566         D3DVALUE fMaxDistance,
567         DWORD dwApply)
568 {
569         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
570         TRACE("setting: MaxDistance = %f; dwApply = %d\n", fMaxDistance, dwApply);
571         This->dsb->ds3db_ds3db.flMaxDistance = fMaxDistance;
572         if (dwApply == DS3D_IMMEDIATE)
573         {
574                 This->dsb->ds3db_need_recalc = FALSE;
575                 DSOUND_Mix3DBuffer(This->dsb);
576         }
577         This->dsb->ds3db_need_recalc = TRUE;
578         return DS_OK;
579 }
580
581 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMinDistance(
582         LPDIRECTSOUND3DBUFFER iface,
583         D3DVALUE fMinDistance,
584         DWORD dwApply)
585 {
586         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
587         TRACE("setting: MinDistance = %f; dwApply = %d\n", fMinDistance, dwApply);
588         This->dsb->ds3db_ds3db.flMinDistance = fMinDistance;
589         if (dwApply == DS3D_IMMEDIATE)
590         {
591                 This->dsb->ds3db_need_recalc = FALSE;
592                 DSOUND_Mix3DBuffer(This->dsb);
593         }
594         This->dsb->ds3db_need_recalc = TRUE;
595         return DS_OK;
596 }
597
598 static HRESULT WINAPI IDirectSound3DBufferImpl_SetMode(
599         LPDIRECTSOUND3DBUFFER iface,
600         DWORD dwMode,
601         DWORD dwApply)
602 {
603         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
604         TRACE("setting: Mode = %d; dwApply = %d\n", dwMode, dwApply);
605         This->dsb->ds3db_ds3db.dwMode = dwMode;
606         if (dwApply == DS3D_IMMEDIATE)
607         {
608                 This->dsb->ds3db_need_recalc = FALSE;
609                 DSOUND_Mix3DBuffer(This->dsb);
610         }
611         This->dsb->ds3db_need_recalc = TRUE;
612         return DS_OK;
613 }
614
615 static HRESULT WINAPI IDirectSound3DBufferImpl_SetPosition(
616         LPDIRECTSOUND3DBUFFER iface,
617         D3DVALUE x, D3DVALUE y, D3DVALUE z,
618         DWORD dwApply)
619 {
620         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
621         TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
622         This->dsb->ds3db_ds3db.vPosition.x = x;
623         This->dsb->ds3db_ds3db.vPosition.y = y;
624         This->dsb->ds3db_ds3db.vPosition.z = z;
625         if (dwApply == DS3D_IMMEDIATE)
626         {
627                 This->dsb->ds3db_need_recalc = FALSE;
628                 DSOUND_Mix3DBuffer(This->dsb);
629         }
630         This->dsb->ds3db_need_recalc = TRUE;
631         return DS_OK;
632 }
633
634 static HRESULT WINAPI IDirectSound3DBufferImpl_SetVelocity(
635         LPDIRECTSOUND3DBUFFER iface,
636         D3DVALUE x, D3DVALUE y, D3DVALUE z,
637         DWORD dwApply)
638 {
639         IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
640         TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
641         This->dsb->ds3db_ds3db.vVelocity.x = x;
642         This->dsb->ds3db_ds3db.vVelocity.y = y;
643         This->dsb->ds3db_ds3db.vVelocity.z = z;
644         if (dwApply == DS3D_IMMEDIATE)
645         {
646                 This->dsb->ds3db_need_recalc = FALSE;
647                 DSOUND_Mix3DBuffer(This->dsb);
648         }
649         This->dsb->ds3db_need_recalc = TRUE;
650         return DS_OK;
651 }
652
653 static const IDirectSound3DBufferVtbl ds3dbvt =
654 {
655         /* IUnknown methods */
656         IDirectSound3DBufferImpl_QueryInterface,
657         IDirectSound3DBufferImpl_AddRef,
658         IDirectSound3DBufferImpl_Release,
659         /* IDirectSound3DBuffer methods */
660         IDirectSound3DBufferImpl_GetAllParameters,
661         IDirectSound3DBufferImpl_GetConeAngles,
662         IDirectSound3DBufferImpl_GetConeOrientation,
663         IDirectSound3DBufferImpl_GetConeOutsideVolume,
664         IDirectSound3DBufferImpl_GetMaxDistance,
665         IDirectSound3DBufferImpl_GetMinDistance,
666         IDirectSound3DBufferImpl_GetMode,
667         IDirectSound3DBufferImpl_GetPosition,
668         IDirectSound3DBufferImpl_GetVelocity,
669         IDirectSound3DBufferImpl_SetAllParameters,
670         IDirectSound3DBufferImpl_SetConeAngles,
671         IDirectSound3DBufferImpl_SetConeOrientation,
672         IDirectSound3DBufferImpl_SetConeOutsideVolume,
673         IDirectSound3DBufferImpl_SetMaxDistance,
674         IDirectSound3DBufferImpl_SetMinDistance,
675         IDirectSound3DBufferImpl_SetMode,
676         IDirectSound3DBufferImpl_SetPosition,
677         IDirectSound3DBufferImpl_SetVelocity,
678 };
679
680 HRESULT IDirectSound3DBufferImpl_Create(
681         IDirectSoundBufferImpl *dsb,
682         IDirectSound3DBufferImpl **pds3db)
683 {
684         IDirectSound3DBufferImpl *ds3db;
685         TRACE("(%p,%p)\n",dsb,pds3db);
686
687         ds3db = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*ds3db));
688
689         if (ds3db == NULL) {
690                 WARN("out of memory\n");
691                 *pds3db = 0;
692                 return DSERR_OUTOFMEMORY;
693         }
694
695         ds3db->ref = 0;
696         ds3db->dsb = dsb;
697         ds3db->lpVtbl = &ds3dbvt;
698
699         ds3db->dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
700         ds3db->dsb->ds3db_ds3db.vPosition.x = 0.0;
701         ds3db->dsb->ds3db_ds3db.vPosition.y = 0.0;
702         ds3db->dsb->ds3db_ds3db.vPosition.z = 0.0;
703         ds3db->dsb->ds3db_ds3db.vVelocity.x = 0.0;
704         ds3db->dsb->ds3db_ds3db.vVelocity.y = 0.0;
705         ds3db->dsb->ds3db_ds3db.vVelocity.z = 0.0;
706         ds3db->dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
707         ds3db->dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
708         ds3db->dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
709         ds3db->dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
710         ds3db->dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
711         ds3db->dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
712         ds3db->dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
713         ds3db->dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
714         ds3db->dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
715
716         ds3db->dsb->ds3db_need_recalc = TRUE;
717
718         *pds3db = ds3db;
719         return S_OK;
720 }
721
722 HRESULT IDirectSound3DBufferImpl_Destroy(
723     IDirectSound3DBufferImpl *pds3db)
724 {
725     TRACE("(%p)\n",pds3db);
726
727     while (IDirectSound3DBufferImpl_Release((LPDIRECTSOUND3DBUFFER)pds3db) > 0);
728
729     return S_OK;
730 }
731
732 /*******************************************************************************
733  *            IDirectSound3DListener
734  */
735 static inline IDirectSoundBufferImpl *impl_from_IDirectSound3DListener(IDirectSound3DListener *iface)
736 {
737     return CONTAINING_RECORD(iface, IDirectSoundBufferImpl, IDirectSound3DListener_iface);
738 }
739
740
741 /* IUnknown methods */
742 static HRESULT WINAPI IDirectSound3DListenerImpl_QueryInterface(IDirectSound3DListener *iface,
743         REFIID riid, void **ppobj)
744 {
745         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
746
747         TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
748
749         return IDirectSoundBuffer_QueryInterface(&This->IDirectSoundBuffer8_iface, riid, ppobj);
750 }
751
752 static ULONG WINAPI IDirectSound3DListenerImpl_AddRef(IDirectSound3DListener *iface)
753 {
754     IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
755     ULONG ref = InterlockedIncrement(&This->ref3D);
756
757     TRACE("(%p) ref was %d\n", This, ref - 1);
758
759     if(ref == 1)
760         InterlockedIncrement(&This->numIfaces);
761
762     return ref;
763 }
764
765 static ULONG WINAPI IDirectSound3DListenerImpl_Release(IDirectSound3DListener *iface)
766 {
767     IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
768     ULONG ref = InterlockedDecrement(&This->ref3D);
769
770     TRACE("(%p) ref was %d\n", This, ref + 1);
771
772     if (!ref && !InterlockedDecrement(&This->numIfaces))
773             primarybuffer_destroy(This);
774
775     return ref;
776 }
777
778 /* IDirectSound3DListener methods */
779 static HRESULT WINAPI IDirectSound3DListenerImpl_GetAllParameter(IDirectSound3DListener *iface,
780         DS3DLISTENER *lpDS3DL)
781 {
782         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
783
784         TRACE("(%p,%p)\n",This,lpDS3DL);
785
786         if (lpDS3DL == NULL) {
787                 WARN("invalid parameter: lpDS3DL == NULL\n");
788                 return DSERR_INVALIDPARAM;
789         }
790
791         if (lpDS3DL->dwSize < sizeof(*lpDS3DL)) {
792                 WARN("invalid parameter: lpDS3DL->dwSize = %d\n",lpDS3DL->dwSize);
793                 return DSERR_INVALIDPARAM;
794         }
795         
796         TRACE("returning: all parameters\n");
797         *lpDS3DL = This->device->ds3dl;
798         return DS_OK;
799 }
800
801 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDistanceFactor(IDirectSound3DListener *iface,
802         D3DVALUE *lpfDistanceFactor)
803 {
804         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
805
806         TRACE("returning: Distance Factor = %f\n", This->device->ds3dl.flDistanceFactor);
807         *lpfDistanceFactor = This->device->ds3dl.flDistanceFactor;
808         return DS_OK;
809 }
810
811 static HRESULT WINAPI IDirectSound3DListenerImpl_GetDopplerFactor(IDirectSound3DListener *iface,
812         D3DVALUE *lpfDopplerFactor)
813 {
814         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
815
816         TRACE("returning: Doppler Factor = %f\n", This->device->ds3dl.flDopplerFactor);
817         *lpfDopplerFactor = This->device->ds3dl.flDopplerFactor;
818         return DS_OK;
819 }
820
821 static HRESULT WINAPI IDirectSound3DListenerImpl_GetOrientation(IDirectSound3DListener *iface,
822         D3DVECTOR *lpvOrientFront, D3DVECTOR *lpvOrientTop)
823 {
824         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
825
826         TRACE("returning: OrientFront vector = (%f,%f,%f); OrientTop vector = (%f,%f,%f)\n", This->device->ds3dl.vOrientFront.x,
827         This->device->ds3dl.vOrientFront.y, This->device->ds3dl.vOrientFront.z, This->device->ds3dl.vOrientTop.x, This->device->ds3dl.vOrientTop.y,
828         This->device->ds3dl.vOrientTop.z);
829         *lpvOrientFront = This->device->ds3dl.vOrientFront;
830         *lpvOrientTop = This->device->ds3dl.vOrientTop;
831         return DS_OK;
832 }
833
834 static HRESULT WINAPI IDirectSound3DListenerImpl_GetPosition(IDirectSound3DListener *iface,
835         D3DVECTOR *lpvPosition)
836 {
837         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
838
839         TRACE("returning: Position vector = (%f,%f,%f)\n", This->device->ds3dl.vPosition.x, This->device->ds3dl.vPosition.y, This->device->ds3dl.vPosition.z);
840         *lpvPosition = This->device->ds3dl.vPosition;
841         return DS_OK;
842 }
843
844 static HRESULT WINAPI IDirectSound3DListenerImpl_GetRolloffFactor(IDirectSound3DListener *iface,
845         D3DVALUE *lpfRolloffFactor)
846 {
847         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
848
849         TRACE("returning: RolloffFactor = %f\n", This->device->ds3dl.flRolloffFactor);
850         *lpfRolloffFactor = This->device->ds3dl.flRolloffFactor;
851         return DS_OK;
852 }
853
854 static HRESULT WINAPI IDirectSound3DListenerImpl_GetVelocity(IDirectSound3DListener *iface,
855         D3DVECTOR *lpvVelocity)
856 {
857         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
858
859         TRACE("returning: Velocity vector = (%f,%f,%f)\n", This->device->ds3dl.vVelocity.x, This->device->ds3dl.vVelocity.y, This->device->ds3dl.vVelocity.z);
860         *lpvVelocity = This->device->ds3dl.vVelocity;
861         return DS_OK;
862 }
863
864 static HRESULT WINAPI IDirectSound3DListenerImpl_SetAllParameters(IDirectSound3DListener *iface,
865         const DS3DLISTENER *lpcDS3DL, DWORD dwApply)
866 {
867         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
868
869         TRACE("setting: all parameters; dwApply = %d\n", dwApply);
870         This->device->ds3dl = *lpcDS3DL;
871         if (dwApply == DS3D_IMMEDIATE)
872         {
873                 This->device->ds3dl_need_recalc = FALSE;
874                 DSOUND_ChangeListener(This);
875         }
876         This->device->ds3dl_need_recalc = TRUE;
877         return DS_OK;
878 }
879
880 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDistanceFactor(IDirectSound3DListener *iface,
881         D3DVALUE fDistanceFactor, DWORD dwApply)
882 {
883         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
884
885         TRACE("setting: Distance Factor = %f; dwApply = %d\n", fDistanceFactor, dwApply);
886         This->device->ds3dl.flDistanceFactor = fDistanceFactor;
887         if (dwApply == DS3D_IMMEDIATE)
888         {
889                 This->device->ds3dl_need_recalc = FALSE;
890                 DSOUND_ChangeListener(This);
891         }
892         This->device->ds3dl_need_recalc = TRUE;
893         return DS_OK;
894 }
895
896 static HRESULT WINAPI IDirectSound3DListenerImpl_SetDopplerFactor(IDirectSound3DListener *iface,
897         D3DVALUE fDopplerFactor, DWORD dwApply)
898 {
899         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
900
901         TRACE("setting: Doppler Factor = %f; dwApply = %d\n", fDopplerFactor, dwApply);
902         This->device->ds3dl.flDopplerFactor = fDopplerFactor;
903         if (dwApply == DS3D_IMMEDIATE)
904         {
905                 This->device->ds3dl_need_recalc = FALSE;
906                 DSOUND_ChangeListener(This);
907         }
908         This->device->ds3dl_need_recalc = TRUE;
909         return DS_OK;
910 }
911
912 static HRESULT WINAPI IDirectSound3DListenerImpl_SetOrientation(IDirectSound3DListener *iface,
913         D3DVALUE xFront, D3DVALUE yFront, D3DVALUE zFront, D3DVALUE xTop, D3DVALUE yTop,
914         D3DVALUE zTop, DWORD dwApply)
915 {
916         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
917
918         TRACE("setting: Front vector = (%f,%f,%f); Top vector = (%f,%f,%f); dwApply = %d\n",
919         xFront, yFront, zFront, xTop, yTop, zTop, dwApply);
920         This->device->ds3dl.vOrientFront.x = xFront;
921         This->device->ds3dl.vOrientFront.y = yFront;
922         This->device->ds3dl.vOrientFront.z = zFront;
923         This->device->ds3dl.vOrientTop.x = xTop;
924         This->device->ds3dl.vOrientTop.y = yTop;
925         This->device->ds3dl.vOrientTop.z = zTop;
926         if (dwApply == DS3D_IMMEDIATE)
927         {
928                 This->device->ds3dl_need_recalc = FALSE;
929                 DSOUND_ChangeListener(This);
930         }
931         This->device->ds3dl_need_recalc = TRUE;
932         return DS_OK;
933 }
934
935 static HRESULT WINAPI IDirectSound3DListenerImpl_SetPosition(IDirectSound3DListener *iface,
936         D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply)
937 {
938         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
939
940         TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
941         This->device->ds3dl.vPosition.x = x;
942         This->device->ds3dl.vPosition.y = y;
943         This->device->ds3dl.vPosition.z = z;
944         if (dwApply == DS3D_IMMEDIATE)
945         {
946                 This->device->ds3dl_need_recalc = FALSE;
947                 DSOUND_ChangeListener(This);
948         }
949         This->device->ds3dl_need_recalc = TRUE;
950         return DS_OK;
951 }
952
953 static HRESULT WINAPI IDirectSound3DListenerImpl_SetRolloffFactor(IDirectSound3DListener *iface,
954         D3DVALUE fRolloffFactor, DWORD dwApply)
955 {
956         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
957
958         TRACE("setting: Rolloff Factor = %f; dwApply = %d\n", fRolloffFactor, dwApply);
959         This->device->ds3dl.flRolloffFactor = fRolloffFactor;
960         if (dwApply == DS3D_IMMEDIATE)
961         {
962                 This->device->ds3dl_need_recalc = FALSE;
963                 DSOUND_ChangeListener(This);
964         }
965         This->device->ds3dl_need_recalc = TRUE;
966         return DS_OK;
967 }
968
969 static HRESULT WINAPI IDirectSound3DListenerImpl_SetVelocity(IDirectSound3DListener *iface,
970         D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply)
971 {
972         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
973
974         TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
975         This->device->ds3dl.vVelocity.x = x;
976         This->device->ds3dl.vVelocity.y = y;
977         This->device->ds3dl.vVelocity.z = z;
978         if (dwApply == DS3D_IMMEDIATE)
979         {
980                 This->device->ds3dl_need_recalc = FALSE;
981                 DSOUND_ChangeListener(This);
982         }
983         This->device->ds3dl_need_recalc = TRUE;
984         return DS_OK;
985 }
986
987 static HRESULT WINAPI IDirectSound3DListenerImpl_CommitDeferredSettings(IDirectSound3DListener *iface)
988 {
989         IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
990
991         TRACE("\n");
992         DSOUND_ChangeListener(This);
993         return DS_OK;
994 }
995
996 const IDirectSound3DListenerVtbl ds3dlvt =
997 {
998         /* IUnknown methods */
999         IDirectSound3DListenerImpl_QueryInterface,
1000         IDirectSound3DListenerImpl_AddRef,
1001         IDirectSound3DListenerImpl_Release,
1002         /* IDirectSound3DListener methods */
1003         IDirectSound3DListenerImpl_GetAllParameter,
1004         IDirectSound3DListenerImpl_GetDistanceFactor,
1005         IDirectSound3DListenerImpl_GetDopplerFactor,
1006         IDirectSound3DListenerImpl_GetOrientation,
1007         IDirectSound3DListenerImpl_GetPosition,
1008         IDirectSound3DListenerImpl_GetRolloffFactor,
1009         IDirectSound3DListenerImpl_GetVelocity,
1010         IDirectSound3DListenerImpl_SetAllParameters,
1011         IDirectSound3DListenerImpl_SetDistanceFactor,
1012         IDirectSound3DListenerImpl_SetDopplerFactor,
1013         IDirectSound3DListenerImpl_SetOrientation,
1014         IDirectSound3DListenerImpl_SetPosition,
1015         IDirectSound3DListenerImpl_SetRolloffFactor,
1016         IDirectSound3DListenerImpl_SetVelocity,
1017         IDirectSound3DListenerImpl_CommitDeferredSettings,
1018 };