sound3d.c 34.4 KB
Newer Older
1 2 3 4 5
/*  			DirectSound
 *
 * Copyright 1998 Marcus Meissner
 * Copyright 1998 Rob Riggs
 * Copyright 2000-2001 TransGaming Technologies, Inc.
6
 * Copyright 2002-2003 Rok Mandeljc <rok.mandeljc@gimb.org>
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 */
/*
 * Most thread locking is complete. There may be a few race
 * conditions still lurking.
 *
 * Tested with a Soundblaster clone, a Gravis UltraSound Classic,
 * and a Turtle Beach Tropez+.
 *
 * TODO:
 *	Implement SetCooperativeLevel properly (need to address focus issues)
 *	Implement DirectSound3DBuffers (stubs in place)
 *	Use hardware 3D support if available
 *      Add critical section locking inside Release and AddRef methods
 *      Handle static buffers - put those in hardware, non-static not in hardware
 *      Hardware DuplicateSoundBuffer
 *      Proper volume calculation, and setting volume in HEL primary buffer
 *      Optimize WINMM and negotiate fragment size, decrease DS_HEL_MARGIN
 */

40
#include <stdarg.h>
41 42 43 44
#include <math.h>	/* Insomnia - pow() function */

#include "windef.h"
#include "winbase.h"
45
#include "winuser.h"
46
#include "mmsystem.h"
47
#include "winternl.h"
48 49 50 51 52
#include "mmddk.h"
#include "wine/debug.h"
#include "dsound.h"
#include "dsound_private.h"

53 54
/* default velocity of sound in the air */
#define DEFAULT_VELOCITY 340
55

56
WINE_DEFAULT_DEBUG_CHANNEL(dsound3d);
57

Rok Mandeljc's avatar
Rok Mandeljc committed
58 59 60 61
/*******************************************************************************
 *              Auxiliary functions
 */

62
/* scalar product (I believe it's called dot product in English) */
63
static inline D3DVALUE ScalarProduct (const D3DVECTOR *a, const D3DVECTOR *b)
Rok Mandeljc's avatar
Rok Mandeljc committed
64 65
{
	D3DVALUE c;
66
	c = (a->x*b->x) + (a->y*b->y) + (a->z*b->z);
67
	TRACE("(%f,%f,%f) * (%f,%f,%f) = %f)\n", a->x, a->y, a->z, b->x, b->y,
68
	      b->z, c);
Rok Mandeljc's avatar
Rok Mandeljc committed
69 70 71
	return c;
}

72
/* vector product (I believe it's called cross product in English */
73
static inline D3DVECTOR VectorProduct (const D3DVECTOR *a, const D3DVECTOR *b)
Rok Mandeljc's avatar
Rok Mandeljc committed
74
{
Rok Mandeljc's avatar
Rok Mandeljc committed
75
	D3DVECTOR c;
76 77 78
	c.x = (a->y*b->z) - (a->z*b->y);
	c.y = (a->z*b->x) - (a->x*b->z);
	c.z = (a->x*b->y) - (a->y*b->x);
79
	TRACE("(%f,%f,%f) x (%f,%f,%f) = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y,
80
	      b->z, c.x, c.y, c.z);
Rok Mandeljc's avatar
Rok Mandeljc committed
81 82 83
	return c;
}

Francois Gouget's avatar
Francois Gouget committed
84
/* magnitude (length) of vector */
85
static inline D3DVALUE VectorMagnitude (const D3DVECTOR *a)
Rok Mandeljc's avatar
Rok Mandeljc committed
86 87 88
{
	D3DVALUE l;
	l = sqrt (ScalarProduct (a, a));
89
	TRACE("|(%f,%f,%f)| = %f\n", a->x, a->y, a->z, l);
Rok Mandeljc's avatar
Rok Mandeljc committed
90 91 92 93
	return l;
}

/* conversion between radians and degrees */
Rok Mandeljc's avatar
Rok Mandeljc committed
94
static inline D3DVALUE RadToDeg (D3DVALUE angle)
Rok Mandeljc's avatar
Rok Mandeljc committed
95
{
Rok Mandeljc's avatar
Rok Mandeljc committed
96
	D3DVALUE newangle;
Rok Mandeljc's avatar
Rok Mandeljc committed
97
	newangle = angle * (360/(2*M_PI));
Rok Mandeljc's avatar
Rok Mandeljc committed
98
	TRACE("%f rad = %f deg\n", angle, newangle);
Rok Mandeljc's avatar
Rok Mandeljc committed
99 100 101
	return newangle;
}

102 103
/* angle between vectors - rad version */
static inline D3DVALUE AngleBetweenVectorsRad (const D3DVECTOR *a, const D3DVECTOR *b)
Rok Mandeljc's avatar
Rok Mandeljc committed
104
{
Rok Mandeljc's avatar
Rok Mandeljc committed
105
	D3DVALUE la, lb, product, angle, cos;
106
	/* definition of scalar product: a*b = |a|*|b|*cos... therefore: */
Rok Mandeljc's avatar
Rok Mandeljc committed
107 108 109
	product = ScalarProduct (a,b);
	la = VectorMagnitude (a);
	lb = VectorMagnitude (b);
110 111 112
	if (!la || !lb)
		return 0;

Rok Mandeljc's avatar
Rok Mandeljc committed
113
	cos = product/(la*lb);
Rok Mandeljc's avatar
Rok Mandeljc committed
114
	angle = acos(cos);
115 116
	TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians (%f degrees)\n",  a->x, a->y, a->z, b->x,
	      b->y, b->z, angle, RadToDeg(angle));
Rok Mandeljc's avatar
Rok Mandeljc committed
117 118 119
	return angle;	
}

120
static inline D3DVALUE AngleBetweenVectorsDeg (const D3DVECTOR *a, const D3DVECTOR *b)
Rok Mandeljc's avatar
Rok Mandeljc committed
121
{
122
	return RadToDeg(AngleBetweenVectorsRad(a, b));
Rok Mandeljc's avatar
Rok Mandeljc committed
123 124
}

125
/* calculates vector between two points */
126
static inline D3DVECTOR VectorBetweenTwoPoints (const D3DVECTOR *a, const D3DVECTOR *b)
127 128
{
	D3DVECTOR c;
129 130 131 132 133
	c.x = b->x - a->x;
	c.y = b->y - a->y;
	c.z = b->z - a->z;
	TRACE("A (%f,%f,%f), B (%f,%f,%f), AB = (%f,%f,%f)\n", a->x, a->y, a->z, b->x, b->y,
	      b->z, c.x, c.y, c.z);
134 135 136
	return c;
}

137
/* calculates the length of vector's projection on another vector */
138
static inline D3DVALUE ProjectVector (const D3DVECTOR *a, const D3DVECTOR *p)
139 140 141 142
{
	D3DVALUE prod, result;
	prod = ScalarProduct(a, p);
	result = prod/VectorMagnitude(p);
143 144
	TRACE("length projection of (%f,%f,%f) on (%f,%f,%f) = %f\n", a->x, a->y, a->z, p->x,
              p->y, p->z, result);
145 146 147
	return result;
}

Rok Mandeljc's avatar
Rok Mandeljc committed
148 149 150
/*******************************************************************************
 *              3D Buffer and Listener mixing
 */
151

152
void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb)
Rok Mandeljc's avatar
Rok Mandeljc committed
153
{
154
	/* volume, at which the sound will be played after all calcs. */
Rok Mandeljc's avatar
Rok Mandeljc committed
155
	D3DVALUE lVolume = 0;
156
	/* stuff for distance related stuff calc. */
157
	D3DVECTOR vDistance;
Rok Mandeljc's avatar
Rok Mandeljc committed
158 159
	D3DVALUE flDistance = 0;
	/* panning related stuff */
160
	D3DVALUE flAngle, flAngle2;
Rok Mandeljc's avatar
Rok Mandeljc committed
161
	D3DVECTOR vLeft;
162
	int i, num_main_speakers;
163
	float a, ingain;
164
	/* doppler shift related stuff */
Alexandre Julliard's avatar
Alexandre Julliard committed
165

166
	TRACE("(%p)\n",dsb);
167

Rok Mandeljc's avatar
Rok Mandeljc committed
168
	/* initial buffer volume */
169
	lVolume = dsb->ds3db_lVolume;
170
	
171
	switch (dsb->ds3db_ds3db.dwMode)
172 173
	{
		case DS3DMODE_NORMAL:
174 175
			TRACE("Normal 3D processing mode\n");
			/* we need to calculate distance between buffer and listener*/
176
			vDistance = VectorBetweenTwoPoints(&dsb->device->ds3dl.vPosition, &dsb->ds3db_ds3db.vPosition);
177
			flDistance = VectorMagnitude (&vDistance);
178
			break;
179
		case DS3DMODE_HEADRELATIVE:
180 181
			TRACE("Head-relative 3D processing mode\n");
			/* distance between buffer and listener is same as buffer's position */
182 183
			vDistance = dsb->ds3db_ds3db.vPosition;
			flDistance = VectorMagnitude (&vDistance);
Rok Mandeljc's avatar
Rok Mandeljc committed
184
			break;
185 186 187
		default:
			TRACE("3D processing disabled\n");
			/* this one is here only to eliminate annoying warning message */
188
			dsb->volpan.lVolume = dsb->ds3db_lVolume;
189 190
			DSOUND_RecalcVolPan (&dsb->volpan);
			return;
Rok Mandeljc's avatar
Rok Mandeljc committed
191
	}
192
	
193
	if (flDistance > dsb->ds3db_ds3db.flMaxDistance)
194 195
	{
		/* some apps don't want you to hear too distant sounds... */
196
		if (dsb->dsbd.dwFlags & DSBCAPS_MUTE3DATMAXDISTANCE)
197
		{
198 199
			dsb->volpan.lVolume = DSBVOLUME_MIN;
			DSOUND_RecalcVolPan (&dsb->volpan);		
200 201 202 203
			/* i guess mixing here would be a waste of power */
			return;
		}
		else
204
			flDistance = dsb->ds3db_ds3db.flMaxDistance;
205
	}		
206 207 208

	if (flDistance < dsb->ds3db_ds3db.flMinDistance)
		flDistance = dsb->ds3db_ds3db.flMinDistance;
209 210

	flDistance = dsb->ds3db_ds3db.flMinDistance + (flDistance - dsb->ds3db_ds3db.flMinDistance) * dsb->device->ds3dl.flRolloffFactor;
211
	
212
	/* attenuation proportional to the distance squared, converted to millibels as in lVolume*/
213
	lVolume -= log10(flDistance/dsb->ds3db_ds3db.flMinDistance * flDistance/dsb->ds3db_ds3db.flMinDistance)*1000;
214
	TRACE("dist. att: Distance = %f, MinDistance = %f => adjusting volume %d to %f\n", flDistance, dsb->ds3db_ds3db.flMinDistance, dsb->ds3db_lVolume, lVolume);
Rok Mandeljc's avatar
Rok Mandeljc committed
215 216 217

	/* conning */
	/* sometimes it happens that vConeOrientation vector = (0,0,0); in this case angle is "nan" and it's useless*/
218
	if (dsb->ds3db_ds3db.vConeOrientation.x == 0 && dsb->ds3db_ds3db.vConeOrientation.y == 0 && dsb->ds3db_ds3db.vConeOrientation.z == 0)
Rok Mandeljc's avatar
Rok Mandeljc committed
219 220 221 222 223
	{
		TRACE("conning: cones not set\n");
	}
	else
	{
224 225 226 227 228 229
		D3DVECTOR vDistanceInv;

		vDistanceInv.x = -vDistance.x;
		vDistanceInv.y = -vDistance.y;
		vDistanceInv.z = -vDistance.z;

Rok Mandeljc's avatar
Rok Mandeljc committed
230
		/* calculate angle */
231
		flAngle = AngleBetweenVectorsDeg(&dsb->ds3db_ds3db.vConeOrientation, &vDistanceInv);
Rok Mandeljc's avatar
Rok Mandeljc committed
232
		/* if by any chance it happens that OutsideConeAngle = InsideConeAngle (that means that conning has no effect) */
233
		if (dsb->ds3db_ds3db.dwInsideConeAngle != dsb->ds3db_ds3db.dwOutsideConeAngle)
Rok Mandeljc's avatar
Rok Mandeljc committed
234 235
		{
			/* my test show that for my way of calc., we need only half of angles */
236 237
			DWORD dwInsideConeAngle = dsb->ds3db_ds3db.dwInsideConeAngle/2;
			DWORD dwOutsideConeAngle = dsb->ds3db_ds3db.dwOutsideConeAngle/2;
238 239 240
			if (dwOutsideConeAngle == dwInsideConeAngle)
				++dwOutsideConeAngle;

Rok Mandeljc's avatar
Rok Mandeljc committed
241 242 243 244 245 246 247
			/* full volume */
			if (flAngle < dwInsideConeAngle)
				flAngle = dwInsideConeAngle;
			/* min (app defined) volume */
			if (flAngle > dwOutsideConeAngle)
				flAngle = dwOutsideConeAngle;
			/* this probably isn't the right thing, but it's ok for the time being */
248
			lVolume += ((flAngle - dwInsideConeAngle)/(dwOutsideConeAngle - dwInsideConeAngle)) * dsb->ds3db_ds3db.lConeOutsideVolume;
249
		}
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);
Rok Mandeljc's avatar
Rok Mandeljc committed
252
	}
253
	dsb->volpan.lVolume = lVolume;
254 255 256 257 258 259 260 261

	ingain = pow(2.0, dsb->volpan.lVolume / 600.0) * 0xffff;

	if (dsb->device->pwfx->nChannels == 1)
	{
		dsb->volpan.dwTotalAmpFactor[0] = ingain;
		return;
	}
Rok Mandeljc's avatar
Rok Mandeljc committed
262 263
	
	/* panning */
264
	if (vDistance.x == 0.0f && vDistance.y == 0.0f && vDistance.z == 0.0f)
265 266 267
		flAngle = 0.0;
	else
	{
Robert Reif's avatar
Robert Reif committed
268
		vLeft = VectorProduct(&dsb->device->ds3dl.vOrientFront, &dsb->device->ds3dl.vOrientTop);
269 270 271 272 273 274 275 276 277 278 279 280 281 282
		/* To calculate angle to sound source we need to:
		 * 1) Get angle between vDistance and a plane on which angle to sound source should be 0.
		 *    Such a plane is given by vectors vOrientFront and vOrientTop, and angle between vector
		 *    and a plane equals to M_PI_2 - angle between vector and normal to this plane (vLeft in this case).
		 * 2) Determine if the source is behind or in front of us by calculating angle between vDistance
		 *    and vOrientFront.
		 */
		flAngle = AngleBetweenVectorsRad(&vLeft, &vDistance);
		flAngle2 = AngleBetweenVectorsRad(&dsb->device->ds3dl.vOrientFront, &vDistance);
		if (flAngle2 > M_PI_2)
			flAngle = -flAngle;
		flAngle -= M_PI_2;
		if (flAngle < -M_PI)
			flAngle += 2*M_PI;
283
	}
284
	TRACE("panning: Angle = %f rad, lPan = %d\n", flAngle, dsb->volpan.lPan);
285 286

	/* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */
287 288 289
if(0)
{
	D3DVALUE flFreq, flBufferVel, flListenerVel;
Rok Mandeljc's avatar
Rok Mandeljc committed
290
	/* doppler shift*/
291
	if (!VectorMagnitude(&dsb->ds3db_ds3db.vVelocity) && !VectorMagnitude(&dsb->device->ds3dl.vVelocity))
292 293 294
	{
		TRACE("doppler: Buffer and Listener don't have velocities\n");
	}
295 296 297
	else if (!(dsb->ds3db_ds3db.vVelocity.x == dsb->device->ds3dl.vVelocity.x &&
	           dsb->ds3db_ds3db.vVelocity.y == dsb->device->ds3dl.vVelocity.y &&
	           dsb->ds3db_ds3db.vVelocity.z == dsb->device->ds3dl.vVelocity.z))
298
	{
299
		/* calculate length of ds3db_ds3db.vVelocity component which causes Doppler Effect
300 301
		   NOTE: if buffer moves TOWARDS the listener, its velocity component is NEGATIVE
		         if buffer moves AWAY from listener, its velocity component is POSITIVE */
302
		flBufferVel = ProjectVector(&dsb->ds3db_ds3db.vVelocity, &vDistance);
Francois Gouget's avatar
Francois Gouget committed
303
		/* calculate length of ds3dl.vVelocity component which causes Doppler Effect
304 305
		   NOTE: if listener moves TOWARDS the buffer, its velocity component is POSITIVE
		         if listener moves AWAY from buffer, its velocity component is NEGATIVE */
Robert Reif's avatar
Robert Reif committed
306
		flListenerVel = ProjectVector(&dsb->device->ds3dl.vVelocity, &vDistance);
307
		/* formula taken from Gianicoli D.: Physics, 4th edition: */
308 309
		/* FIXME: replace dsb->freq with appropriate frequency ! */
		flFreq = dsb->freq * ((DEFAULT_VELOCITY + flListenerVel)/(DEFAULT_VELOCITY + flBufferVel));
310 311
		TRACE("doppler: Buffer velocity (component) = %f, Listener velocity (component) = %f => Doppler shift: %d Hz -> %f Hz\n",
		      flBufferVel, flListenerVel, dsb->freq, flFreq);
312
		/* FIXME: replace following line with correct frequency setting ! */
313
		dsb->freq = flFreq;
314
		DSOUND_RecalcFormat(dsb);
315
	}
316
}
317 318 319 320

	for (i = 0; i < dsb->device->pwfx->nChannels; i++)
		dsb->volpan.dwTotalAmpFactor[i] = 0;

321 322 323 324 325 326 327
	num_main_speakers = dsb->device->pwfx->nChannels;

	if (dsb->device->lfe_channel != -1) {
		dsb->volpan.dwTotalAmpFactor[dsb->device->lfe_channel] = ingain;
		num_main_speakers--;
	}

328
	/* adapted from OpenAL's Alc/panning.c */
329
	for (i = 0; i < num_main_speakers - 1; i++)
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
	{
		if(flAngle >= dsb->device->speaker_angles[i] && flAngle < dsb->device->speaker_angles[i+1])
		{
			/* Sound is between speakers i and i+1 */
			a = (flAngle-dsb->device->speaker_angles[i]) / (dsb->device->speaker_angles[i+1]-dsb->device->speaker_angles[i]);
			dsb->volpan.dwTotalAmpFactor[dsb->device->speaker_num[i]] = sqrtf(1.0f-a) * ingain;
			dsb->volpan.dwTotalAmpFactor[dsb->device->speaker_num[i+1]] = sqrtf(a) * ingain;
			return;
		}
	}

	/* Sound is between last and first speakers */
	if (flAngle < dsb->device->speaker_angles[0]) { flAngle += M_PI*2.0f; }
	a = (flAngle-dsb->device->speaker_angles[i]) / (M_PI*2.0f + dsb->device->speaker_angles[0]-dsb->device->speaker_angles[i]);
	dsb->volpan.dwTotalAmpFactor[dsb->device->speaker_num[i]] = sqrtf(1.0f-a) * ingain;
	dsb->volpan.dwTotalAmpFactor[dsb->device->speaker_num[0]] = sqrtf(a) * ingain;
346 347 348 349 350 351 352
}

static void DSOUND_Mix3DBuffer(IDirectSoundBufferImpl *dsb)
{
	TRACE("(%p)\n",dsb);

	DSOUND_Calc3DBuffer(dsb);
Rok Mandeljc's avatar
Rok Mandeljc committed
353 354
}

355
static void DSOUND_ChangeListener(IDirectSoundBufferImpl *ds3dl)
Rok Mandeljc's avatar
Rok Mandeljc committed
356 357
{
	int i;
358
	TRACE("(%p)\n",ds3dl);
Robert Reif's avatar
Robert Reif committed
359
	for (i = 0; i < ds3dl->device->nrofbuffers; i++)
Rok Mandeljc's avatar
Rok Mandeljc committed
360
	{
361
		/* check if this buffer is waiting for recalculation */
Robert Reif's avatar
Robert Reif committed
362
		if (ds3dl->device->buffers[i]->ds3db_need_recalc)
363
		{
Robert Reif's avatar
Robert Reif committed
364
			DSOUND_Mix3DBuffer(ds3dl->device->buffers[i]);
365
		}
Rok Mandeljc's avatar
Rok Mandeljc committed
366 367
	}
}
368 369 370 371

/*******************************************************************************
 *              IDirectSound3DBuffer
 */
372 373 374 375
static inline IDirectSoundBufferImpl *impl_from_IDirectSound3DBuffer(IDirectSound3DBuffer *iface)
{
    return CONTAINING_RECORD(iface, IDirectSoundBufferImpl, IDirectSound3DBuffer_iface);
}
376 377

/* IUnknown methods */
378 379
static HRESULT WINAPI IDirectSound3DBufferImpl_QueryInterface(IDirectSound3DBuffer *iface,
        REFIID riid, void **ppobj)
380
{
381 382 383
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
384

385
    return IDirectSoundBuffer8_QueryInterface(&This->IDirectSoundBuffer8_iface, riid, ppobj);
386 387
}

388
static ULONG WINAPI IDirectSound3DBufferImpl_AddRef(IDirectSound3DBuffer *iface)
389
{
390 391
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);
    ULONG ref = InterlockedIncrement(&This->ref3D);
392

393
    TRACE("(%p) ref was %d\n", This, ref - 1);
394 395

    if(ref == 1)
396
        InterlockedIncrement(&This->numIfaces);
397

398
    return ref;
399 400
}

401
static ULONG WINAPI IDirectSound3DBufferImpl_Release(IDirectSound3DBuffer *iface)
402
{
403 404 405
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);
    ULONG ref = InterlockedDecrement(&This->ref3D);

406
    TRACE("(%p) ref was %d\n", This, ref + 1);
407

408 409 410
    if (!ref && !InterlockedDecrement(&This->numIfaces))
        secondarybuffer_destroy(This);

411
    return ref;
412 413 414
}

/* IDirectSound3DBuffer methods */
415 416
static HRESULT WINAPI IDirectSound3DBufferImpl_GetAllParameters(IDirectSound3DBuffer *iface,
	DS3DBUFFER *lpDs3dBuffer)
417
{
418 419
	IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

420 421 422
	TRACE("(%p,%p)\n",This,lpDs3dBuffer);

	if (lpDs3dBuffer == NULL) {
423
		WARN("invalid parameter: lpDs3dBuffer == NULL\n");
424 425 426 427
		return DSERR_INVALIDPARAM;
	}

	if (lpDs3dBuffer->dwSize < sizeof(*lpDs3dBuffer)) {
428
		WARN("invalid parameter: lpDs3dBuffer->dwSize = %d\n",lpDs3dBuffer->dwSize);
429 430 431
		return DSERR_INVALIDPARAM;
	}
	
432
	TRACE("returning: all parameters\n");
433
	*lpDs3dBuffer = This->ds3db_ds3db;
434 435 436
	return DS_OK;
}

437 438
static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeAngles(IDirectSound3DBuffer *iface,
        DWORD *lpdwInsideConeAngle, DWORD *lpdwOutsideConeAngle)
439
{
440 441 442 443 444 445 446
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("returning: Inside Cone Angle = %d degrees; Outside Cone Angle = %d degrees\n",
            This->ds3db_ds3db.dwInsideConeAngle, This->ds3db_ds3db.dwOutsideConeAngle);
    *lpdwInsideConeAngle = This->ds3db_ds3db.dwInsideConeAngle;
    *lpdwOutsideConeAngle = This->ds3db_ds3db.dwOutsideConeAngle;
    return DS_OK;
447 448
}

449 450
static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOrientation(IDirectSound3DBuffer *iface,
        D3DVECTOR *lpvConeOrientation)
451
{
452 453 454 455 456 457 458 459
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("returning: Cone Orientation vector = (%f,%f,%f)\n",
            This->ds3db_ds3db.vConeOrientation.x,
            This->ds3db_ds3db.vConeOrientation.y,
            This->ds3db_ds3db.vConeOrientation.z);
    *lpvConeOrientation = This->ds3db_ds3db.vConeOrientation;
    return DS_OK;
460 461
}

462 463
static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOutsideVolume(IDirectSound3DBuffer *iface,
        LONG *lplConeOutsideVolume)
464
{
465 466 467 468 469
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("returning: Cone Outside Volume = %d\n", This->ds3db_ds3db.lConeOutsideVolume);
    *lplConeOutsideVolume = This->ds3db_ds3db.lConeOutsideVolume;
    return DS_OK;
470 471
}

472 473
static HRESULT WINAPI IDirectSound3DBufferImpl_GetMaxDistance(IDirectSound3DBuffer *iface,
        D3DVALUE *lpfMaxDistance)
474
{
475 476 477 478 479
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("returning: Max Distance = %f\n", This->ds3db_ds3db.flMaxDistance);
    *lpfMaxDistance = This->ds3db_ds3db.flMaxDistance;
    return DS_OK;
480 481
}

482 483
static HRESULT WINAPI IDirectSound3DBufferImpl_GetMinDistance(IDirectSound3DBuffer *iface,
        D3DVALUE *lpfMinDistance)
484
{
485 486 487 488 489
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("returning: Min Distance = %f\n", This->ds3db_ds3db.flMinDistance);
    *lpfMinDistance = This->ds3db_ds3db.flMinDistance;
    return DS_OK;
490 491
}

492 493
static HRESULT WINAPI IDirectSound3DBufferImpl_GetMode(IDirectSound3DBuffer *iface,
        DWORD *lpdwMode)
494
{
495 496 497 498 499
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("returning: Mode = %d\n", This->ds3db_ds3db.dwMode);
    *lpdwMode = This->ds3db_ds3db.dwMode;
    return DS_OK;
500 501
}

502 503
static HRESULT WINAPI IDirectSound3DBufferImpl_GetPosition(IDirectSound3DBuffer *iface,
        D3DVECTOR *lpvPosition)
504
{
505 506 507 508 509 510
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("returning: Position vector = (%f,%f,%f)\n", This->ds3db_ds3db.vPosition.x,
            This->ds3db_ds3db.vPosition.y, This->ds3db_ds3db.vPosition.z);
    *lpvPosition = This->ds3db_ds3db.vPosition;
    return DS_OK;
511 512
}

513 514
static HRESULT WINAPI IDirectSound3DBufferImpl_GetVelocity(IDirectSound3DBuffer *iface,
        D3DVECTOR *lpvVelocity)
515
{
516 517 518 519 520 521
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("returning: Velocity vector = (%f,%f,%f)\n", This->ds3db_ds3db.vVelocity.x,
            This->ds3db_ds3db.vVelocity.y, This->ds3db_ds3db.vVelocity.z);
    *lpvVelocity = This->ds3db_ds3db.vVelocity;
    return DS_OK;
522 523
}

524 525
static HRESULT WINAPI IDirectSound3DBufferImpl_SetAllParameters(IDirectSound3DBuffer *iface,
	const DS3DBUFFER *lpcDs3dBuffer, DWORD dwApply)
526
{
527
	IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);
528
	DWORD status = DSERR_INVALIDPARAM;
529

530
	TRACE("(%p,%p,%x)\n",iface,lpcDs3dBuffer,dwApply);
531 532 533 534

	if (lpcDs3dBuffer == NULL) {
		WARN("invalid parameter: lpcDs3dBuffer == NULL\n");
		return status;
535
	}
536 537

	if (lpcDs3dBuffer->dwSize != sizeof(DS3DBUFFER)) {
538
		WARN("invalid parameter: lpcDs3dBuffer->dwSize = %d\n", lpcDs3dBuffer->dwSize);
539 540 541
		return status;
	}

542
	TRACE("setting: all parameters; dwApply = %d\n", dwApply);
543
	This->ds3db_ds3db = *lpcDs3dBuffer;
544

545 546
	if (dwApply == DS3D_IMMEDIATE)
	{
547
		DSOUND_Mix3DBuffer(This);
548
	}
549
	This->ds3db_need_recalc = TRUE;
550
	status = DS_OK;
551 552

	return status;
553 554
}

555 556
static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeAngles(IDirectSound3DBuffer *iface,
        DWORD dwInsideConeAngle, DWORD dwOutsideConeAngle, DWORD dwApply)
557
{
558 559 560 561 562 563 564 565 566 567
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("setting: Inside Cone Angle = %d; Outside Cone Angle = %d; dwApply = %d\n",
            dwInsideConeAngle, dwOutsideConeAngle, dwApply);
    This->ds3db_ds3db.dwInsideConeAngle = dwInsideConeAngle;
    This->ds3db_ds3db.dwOutsideConeAngle = dwOutsideConeAngle;
    if (dwApply == DS3D_IMMEDIATE)
        DSOUND_Mix3DBuffer(This);
    This->ds3db_need_recalc = TRUE;
    return DS_OK;
568 569
}

570 571
static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOrientation(IDirectSound3DBuffer *iface,
        D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply)
572
{
573 574 575 576 577 578 579 580 581 582 583 584 585
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("setting: Cone Orientation vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
    This->ds3db_ds3db.vConeOrientation.x = x;
    This->ds3db_ds3db.vConeOrientation.y = y;
    This->ds3db_ds3db.vConeOrientation.z = z;
    if (dwApply == DS3D_IMMEDIATE)
    {
        This->ds3db_need_recalc = FALSE;
        DSOUND_Mix3DBuffer(This);
    }
    This->ds3db_need_recalc = TRUE;
    return DS_OK;
586 587
}

588 589
static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOutsideVolume(IDirectSound3DBuffer *iface,
        LONG lConeOutsideVolume, DWORD dwApply)
590
{
591 592 593 594 595 596 597 598 599 600 601
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("setting: ConeOutsideVolume = %d; dwApply = %d\n", lConeOutsideVolume, dwApply);
    This->ds3db_ds3db.lConeOutsideVolume = lConeOutsideVolume;
    if (dwApply == DS3D_IMMEDIATE)
    {
        This->ds3db_need_recalc = FALSE;
        DSOUND_Mix3DBuffer(This);
    }
    This->ds3db_need_recalc = TRUE;
    return DS_OK;
602 603
}

604 605
static HRESULT WINAPI IDirectSound3DBufferImpl_SetMaxDistance(IDirectSound3DBuffer *iface,
        D3DVALUE fMaxDistance, DWORD dwApply)
606
{
607 608 609 610 611 612 613 614 615 616 617
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("setting: MaxDistance = %f; dwApply = %d\n", fMaxDistance, dwApply);
    This->ds3db_ds3db.flMaxDistance = fMaxDistance;
    if (dwApply == DS3D_IMMEDIATE)
    {
        This->ds3db_need_recalc = FALSE;
        DSOUND_Mix3DBuffer(This);
    }
    This->ds3db_need_recalc = TRUE;
    return DS_OK;
618 619
}

620 621
static HRESULT WINAPI IDirectSound3DBufferImpl_SetMinDistance(IDirectSound3DBuffer *iface,
        D3DVALUE fMinDistance, DWORD dwApply)
622
{
623 624 625 626 627 628 629 630 631 632 633
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("setting: MinDistance = %f; dwApply = %d\n", fMinDistance, dwApply);
    This->ds3db_ds3db.flMinDistance = fMinDistance;
    if (dwApply == DS3D_IMMEDIATE)
    {
        This->ds3db_need_recalc = FALSE;
        DSOUND_Mix3DBuffer(This);
    }
    This->ds3db_need_recalc = TRUE;
    return DS_OK;
634 635
}

636 637
static HRESULT WINAPI IDirectSound3DBufferImpl_SetMode(IDirectSound3DBuffer *iface, DWORD dwMode,
        DWORD dwApply)
638
{
639 640 641 642 643 644 645 646 647 648 649
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("setting: Mode = %d; dwApply = %d\n", dwMode, dwApply);
    This->ds3db_ds3db.dwMode = dwMode;
    if (dwApply == DS3D_IMMEDIATE)
    {
        This->ds3db_need_recalc = FALSE;
        DSOUND_Mix3DBuffer(This);
    }
    This->ds3db_need_recalc = TRUE;
    return DS_OK;
650 651
}

652 653
static HRESULT WINAPI IDirectSound3DBufferImpl_SetPosition(IDirectSound3DBuffer *iface, D3DVALUE x,
        D3DVALUE y, D3DVALUE z, DWORD dwApply)
654
{
655 656 657 658 659 660 661 662 663 664 665 666 667
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
    This->ds3db_ds3db.vPosition.x = x;
    This->ds3db_ds3db.vPosition.y = y;
    This->ds3db_ds3db.vPosition.z = z;
    if (dwApply == DS3D_IMMEDIATE)
    {
        This->ds3db_need_recalc = FALSE;
        DSOUND_Mix3DBuffer(This);
    }
    This->ds3db_need_recalc = TRUE;
    return DS_OK;
668 669
}

670 671
static HRESULT WINAPI IDirectSound3DBufferImpl_SetVelocity(IDirectSound3DBuffer *iface,
        D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply)
672
{
673 674 675 676 677 678 679 680 681 682 683 684 685
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DBuffer(iface);

    TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
    This->ds3db_ds3db.vVelocity.x = x;
    This->ds3db_ds3db.vVelocity.y = y;
    This->ds3db_ds3db.vVelocity.z = z;
    if (dwApply == DS3D_IMMEDIATE)
    {
        This->ds3db_need_recalc = FALSE;
        DSOUND_Mix3DBuffer(This);
    }
    This->ds3db_need_recalc = TRUE;
    return DS_OK;
686 687
}

688
const IDirectSound3DBufferVtbl ds3dbvt =
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
{
	/* IUnknown methods */
	IDirectSound3DBufferImpl_QueryInterface,
	IDirectSound3DBufferImpl_AddRef,
	IDirectSound3DBufferImpl_Release,
	/* IDirectSound3DBuffer methods */
	IDirectSound3DBufferImpl_GetAllParameters,
	IDirectSound3DBufferImpl_GetConeAngles,
	IDirectSound3DBufferImpl_GetConeOrientation,
	IDirectSound3DBufferImpl_GetConeOutsideVolume,
	IDirectSound3DBufferImpl_GetMaxDistance,
	IDirectSound3DBufferImpl_GetMinDistance,
	IDirectSound3DBufferImpl_GetMode,
	IDirectSound3DBufferImpl_GetPosition,
	IDirectSound3DBufferImpl_GetVelocity,
	IDirectSound3DBufferImpl_SetAllParameters,
	IDirectSound3DBufferImpl_SetConeAngles,
	IDirectSound3DBufferImpl_SetConeOrientation,
	IDirectSound3DBufferImpl_SetConeOutsideVolume,
	IDirectSound3DBufferImpl_SetMaxDistance,
	IDirectSound3DBufferImpl_SetMinDistance,
	IDirectSound3DBufferImpl_SetMode,
	IDirectSound3DBufferImpl_SetPosition,
	IDirectSound3DBufferImpl_SetVelocity,
};

715

716 717 718
/*******************************************************************************
 *	      IDirectSound3DListener
 */
719
static inline IDirectSoundBufferImpl *impl_from_IDirectSound3DListener(IDirectSound3DListener *iface)
720
{
721 722
    return CONTAINING_RECORD(iface, IDirectSoundBufferImpl, IDirectSound3DListener_iface);
}
723 724


725 726 727 728 729
/* IUnknown methods */
static HRESULT WINAPI IDirectSound3DListenerImpl_QueryInterface(IDirectSound3DListener *iface,
        REFIID riid, void **ppobj)
{
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
730

731
        TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
732

733
        return IDirectSoundBuffer_QueryInterface(&This->IDirectSoundBuffer8_iface, riid, ppobj);
734 735
}

736
static ULONG WINAPI IDirectSound3DListenerImpl_AddRef(IDirectSound3DListener *iface)
737
{
738 739
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
    ULONG ref = InterlockedIncrement(&This->ref3D);
740

741
    TRACE("(%p) ref was %d\n", This, ref - 1);
742 743

    if(ref == 1)
744
        InterlockedIncrement(&This->numIfaces);
745

746
    return ref;
747 748
}

749
static ULONG WINAPI IDirectSound3DListenerImpl_Release(IDirectSound3DListener *iface)
750
{
751
    IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);
752
    ULONG ref;
753

754 755 756
    ref = capped_refcount_dec(&This->ref3D);
    if(!ref)
        capped_refcount_dec(&This->numIfaces);
757

758
    TRACE("(%p) ref is now %d\n", This, ref);
759

760
    return ref;
761 762 763
}

/* IDirectSound3DListener methods */
764 765
static HRESULT WINAPI IDirectSound3DListenerImpl_GetAllParameter(IDirectSound3DListener *iface,
        DS3DLISTENER *lpDS3DL)
766
{
767 768
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

769 770 771
	TRACE("(%p,%p)\n",This,lpDS3DL);

	if (lpDS3DL == NULL) {
772
		WARN("invalid parameter: lpDS3DL == NULL\n");
773 774 775 776
		return DSERR_INVALIDPARAM;
	}

	if (lpDS3DL->dwSize < sizeof(*lpDS3DL)) {
777
		WARN("invalid parameter: lpDS3DL->dwSize = %d\n",lpDS3DL->dwSize);
778 779 780
		return DSERR_INVALIDPARAM;
	}
	
781
	TRACE("returning: all parameters\n");
Robert Reif's avatar
Robert Reif committed
782
	*lpDS3DL = This->device->ds3dl;
783 784 785
	return DS_OK;
}

786 787
static HRESULT WINAPI IDirectSound3DListenerImpl_GetDistanceFactor(IDirectSound3DListener *iface,
        D3DVALUE *lpfDistanceFactor)
788
{
789 790
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

Robert Reif's avatar
Robert Reif committed
791 792
	TRACE("returning: Distance Factor = %f\n", This->device->ds3dl.flDistanceFactor);
	*lpfDistanceFactor = This->device->ds3dl.flDistanceFactor;
793 794 795
	return DS_OK;
}

796 797
static HRESULT WINAPI IDirectSound3DListenerImpl_GetDopplerFactor(IDirectSound3DListener *iface,
        D3DVALUE *lpfDopplerFactor)
798
{
799 800
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

Robert Reif's avatar
Robert Reif committed
801 802
	TRACE("returning: Doppler Factor = %f\n", This->device->ds3dl.flDopplerFactor);
	*lpfDopplerFactor = This->device->ds3dl.flDopplerFactor;
803 804 805
	return DS_OK;
}

806 807
static HRESULT WINAPI IDirectSound3DListenerImpl_GetOrientation(IDirectSound3DListener *iface,
        D3DVECTOR *lpvOrientFront, D3DVECTOR *lpvOrientTop)
808
{
809 810
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

811 812
	TRACE("returning: OrientFront vector = (%f,%f,%f); OrientTop vector = (%f,%f,%f)\n", This->device->ds3dl.vOrientFront.x,
	This->device->ds3dl.vOrientFront.y, This->device->ds3dl.vOrientFront.z, This->device->ds3dl.vOrientTop.x, This->device->ds3dl.vOrientTop.y,
Robert Reif's avatar
Robert Reif committed
813 814 815
	This->device->ds3dl.vOrientTop.z);
	*lpvOrientFront = This->device->ds3dl.vOrientFront;
	*lpvOrientTop = This->device->ds3dl.vOrientTop;
816 817 818
	return DS_OK;
}

819 820
static HRESULT WINAPI IDirectSound3DListenerImpl_GetPosition(IDirectSound3DListener *iface,
        D3DVECTOR *lpvPosition)
821
{
822 823
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

Robert Reif's avatar
Robert Reif committed
824 825
	TRACE("returning: Position vector = (%f,%f,%f)\n", This->device->ds3dl.vPosition.x, This->device->ds3dl.vPosition.y, This->device->ds3dl.vPosition.z);
	*lpvPosition = This->device->ds3dl.vPosition;
826 827 828
	return DS_OK;
}

829 830
static HRESULT WINAPI IDirectSound3DListenerImpl_GetRolloffFactor(IDirectSound3DListener *iface,
        D3DVALUE *lpfRolloffFactor)
831
{
832 833
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

Robert Reif's avatar
Robert Reif committed
834 835
	TRACE("returning: RolloffFactor = %f\n", This->device->ds3dl.flRolloffFactor);
	*lpfRolloffFactor = This->device->ds3dl.flRolloffFactor;
836 837 838
	return DS_OK;
}

839 840
static HRESULT WINAPI IDirectSound3DListenerImpl_GetVelocity(IDirectSound3DListener *iface,
        D3DVECTOR *lpvVelocity)
841
{
842 843
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

Robert Reif's avatar
Robert Reif committed
844 845
	TRACE("returning: Velocity vector = (%f,%f,%f)\n", This->device->ds3dl.vVelocity.x, This->device->ds3dl.vVelocity.y, This->device->ds3dl.vVelocity.z);
	*lpvVelocity = This->device->ds3dl.vVelocity;
846 847 848
	return DS_OK;
}

849 850
static HRESULT WINAPI IDirectSound3DListenerImpl_SetAllParameters(IDirectSound3DListener *iface,
        const DS3DLISTENER *lpcDS3DL, DWORD dwApply)
851
{
852 853
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

854
	TRACE("setting: all parameters; dwApply = %d\n", dwApply);
Robert Reif's avatar
Robert Reif committed
855
	This->device->ds3dl = *lpcDS3DL;
856 857
	if (dwApply == DS3D_IMMEDIATE)
	{
Robert Reif's avatar
Robert Reif committed
858
		This->device->ds3dl_need_recalc = FALSE;
Rok Mandeljc's avatar
Rok Mandeljc committed
859
		DSOUND_ChangeListener(This);
860
	}
Robert Reif's avatar
Robert Reif committed
861
	This->device->ds3dl_need_recalc = TRUE;
862 863 864
	return DS_OK;
}

865 866
static HRESULT WINAPI IDirectSound3DListenerImpl_SetDistanceFactor(IDirectSound3DListener *iface,
        D3DVALUE fDistanceFactor, DWORD dwApply)
867
{
868 869
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

870
	TRACE("setting: Distance Factor = %f; dwApply = %d\n", fDistanceFactor, dwApply);
Robert Reif's avatar
Robert Reif committed
871
	This->device->ds3dl.flDistanceFactor = fDistanceFactor;
872 873
	if (dwApply == DS3D_IMMEDIATE)
	{
Robert Reif's avatar
Robert Reif committed
874
		This->device->ds3dl_need_recalc = FALSE;
Rok Mandeljc's avatar
Rok Mandeljc committed
875
		DSOUND_ChangeListener(This);
876
	}
Robert Reif's avatar
Robert Reif committed
877
	This->device->ds3dl_need_recalc = TRUE;
878 879 880
	return DS_OK;
}

881 882
static HRESULT WINAPI IDirectSound3DListenerImpl_SetDopplerFactor(IDirectSound3DListener *iface,
        D3DVALUE fDopplerFactor, DWORD dwApply)
883
{
884 885
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

886
	TRACE("setting: Doppler Factor = %f; dwApply = %d\n", fDopplerFactor, dwApply);
Robert Reif's avatar
Robert Reif committed
887
	This->device->ds3dl.flDopplerFactor = fDopplerFactor;
888 889
	if (dwApply == DS3D_IMMEDIATE)
	{
Robert Reif's avatar
Robert Reif committed
890
		This->device->ds3dl_need_recalc = FALSE;
Rok Mandeljc's avatar
Rok Mandeljc committed
891
		DSOUND_ChangeListener(This);
892
	}
Robert Reif's avatar
Robert Reif committed
893
	This->device->ds3dl_need_recalc = TRUE;
894 895 896
	return DS_OK;
}

897 898 899
static HRESULT WINAPI IDirectSound3DListenerImpl_SetOrientation(IDirectSound3DListener *iface,
        D3DVALUE xFront, D3DVALUE yFront, D3DVALUE zFront, D3DVALUE xTop, D3DVALUE yTop,
        D3DVALUE zTop, DWORD dwApply)
900
{
901 902
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

903
	TRACE("setting: Front vector = (%f,%f,%f); Top vector = (%f,%f,%f); dwApply = %d\n",
904
	xFront, yFront, zFront, xTop, yTop, zTop, dwApply);
Robert Reif's avatar
Robert Reif committed
905 906 907 908 909 910
	This->device->ds3dl.vOrientFront.x = xFront;
	This->device->ds3dl.vOrientFront.y = yFront;
	This->device->ds3dl.vOrientFront.z = zFront;
	This->device->ds3dl.vOrientTop.x = xTop;
	This->device->ds3dl.vOrientTop.y = yTop;
	This->device->ds3dl.vOrientTop.z = zTop;
911 912
	if (dwApply == DS3D_IMMEDIATE)
	{
Robert Reif's avatar
Robert Reif committed
913
		This->device->ds3dl_need_recalc = FALSE;
Rok Mandeljc's avatar
Rok Mandeljc committed
914
		DSOUND_ChangeListener(This);
915
	}
Robert Reif's avatar
Robert Reif committed
916
	This->device->ds3dl_need_recalc = TRUE;
917 918 919
	return DS_OK;
}

920 921
static HRESULT WINAPI IDirectSound3DListenerImpl_SetPosition(IDirectSound3DListener *iface,
        D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply)
922
{
923 924
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

925
	TRACE("setting: Position vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
Robert Reif's avatar
Robert Reif committed
926 927 928
	This->device->ds3dl.vPosition.x = x;
	This->device->ds3dl.vPosition.y = y;
	This->device->ds3dl.vPosition.z = z;
929 930
	if (dwApply == DS3D_IMMEDIATE)
	{
Robert Reif's avatar
Robert Reif committed
931
		This->device->ds3dl_need_recalc = FALSE;
Rok Mandeljc's avatar
Rok Mandeljc committed
932
		DSOUND_ChangeListener(This);
933
	}
Robert Reif's avatar
Robert Reif committed
934
	This->device->ds3dl_need_recalc = TRUE;
935 936 937
	return DS_OK;
}

938 939
static HRESULT WINAPI IDirectSound3DListenerImpl_SetRolloffFactor(IDirectSound3DListener *iface,
        D3DVALUE fRolloffFactor, DWORD dwApply)
940
{
941 942
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

943
	TRACE("setting: Rolloff Factor = %f; dwApply = %d\n", fRolloffFactor, dwApply);
Robert Reif's avatar
Robert Reif committed
944
	This->device->ds3dl.flRolloffFactor = fRolloffFactor;
945 946
	if (dwApply == DS3D_IMMEDIATE)
	{
Robert Reif's avatar
Robert Reif committed
947
		This->device->ds3dl_need_recalc = FALSE;
Rok Mandeljc's avatar
Rok Mandeljc committed
948
		DSOUND_ChangeListener(This);
949
	}
Robert Reif's avatar
Robert Reif committed
950
	This->device->ds3dl_need_recalc = TRUE;
951 952 953
	return DS_OK;
}

954 955
static HRESULT WINAPI IDirectSound3DListenerImpl_SetVelocity(IDirectSound3DListener *iface,
        D3DVALUE x, D3DVALUE y, D3DVALUE z, DWORD dwApply)
956
{
957 958
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

959
	TRACE("setting: Velocity vector = (%f,%f,%f); dwApply = %d\n", x, y, z, dwApply);
Robert Reif's avatar
Robert Reif committed
960 961 962
	This->device->ds3dl.vVelocity.x = x;
	This->device->ds3dl.vVelocity.y = y;
	This->device->ds3dl.vVelocity.z = z;
963 964
	if (dwApply == DS3D_IMMEDIATE)
	{
Robert Reif's avatar
Robert Reif committed
965
		This->device->ds3dl_need_recalc = FALSE;
Rok Mandeljc's avatar
Rok Mandeljc committed
966
		DSOUND_ChangeListener(This);
967
	}
Robert Reif's avatar
Robert Reif committed
968
	This->device->ds3dl_need_recalc = TRUE;
969 970 971
	return DS_OK;
}

972
static HRESULT WINAPI IDirectSound3DListenerImpl_CommitDeferredSettings(IDirectSound3DListener *iface)
973
{
974 975
        IDirectSoundBufferImpl *This = impl_from_IDirectSound3DListener(iface);

Rok Mandeljc's avatar
Rok Mandeljc committed
976 977
	TRACE("\n");
	DSOUND_ChangeListener(This);
978 979 980
	return DS_OK;
}

981
const IDirectSound3DListenerVtbl ds3dlvt =
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
{
	/* IUnknown methods */
	IDirectSound3DListenerImpl_QueryInterface,
	IDirectSound3DListenerImpl_AddRef,
	IDirectSound3DListenerImpl_Release,
	/* IDirectSound3DListener methods */
	IDirectSound3DListenerImpl_GetAllParameter,
	IDirectSound3DListenerImpl_GetDistanceFactor,
	IDirectSound3DListenerImpl_GetDopplerFactor,
	IDirectSound3DListenerImpl_GetOrientation,
	IDirectSound3DListenerImpl_GetPosition,
	IDirectSound3DListenerImpl_GetRolloffFactor,
	IDirectSound3DListenerImpl_GetVelocity,
	IDirectSound3DListenerImpl_SetAllParameters,
	IDirectSound3DListenerImpl_SetDistanceFactor,
	IDirectSound3DListenerImpl_SetDopplerFactor,
	IDirectSound3DListenerImpl_SetOrientation,
	IDirectSound3DListenerImpl_SetPosition,
	IDirectSound3DListenerImpl_SetRolloffFactor,
	IDirectSound3DListenerImpl_SetVelocity,
	IDirectSound3DListenerImpl_CommitDeferredSettings,
};