2002-06-13 21:15:06 +02:00
/* DirectSound
*
* Copyright 1998 Marcus Meissner
* Copyright 1998 Rob Riggs
* Copyright 2000 - 2001 TransGaming Technologies , Inc .
2003-02-17 02:46:46 +01:00
* Copyright 2002 - 2003 Rok Mandeljc < rok . mandeljc @ gimb . org >
2002-06-13 21:15:06 +02:00
*
* 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
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
/*
* 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 3 D 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
*/
2003-09-06 01:08:26 +02:00
# include <stdarg.h>
2002-06-13 21:15:06 +02:00
# include <math.h> /* Insomnia - pow() function */
2003-01-07 21:36:20 +01:00
# define NONAMELESSUNION
# define NONAMELESSSTRUCT
2002-06-13 21:15:06 +02:00
# include "windef.h"
# include "winbase.h"
# include "mmsystem.h"
2003-09-06 01:08:26 +02:00
# include "winreg.h"
2002-09-13 00:07:02 +02:00
# include "winternl.h"
2002-06-13 21:15:06 +02:00
# include "mmddk.h"
# include "wine/debug.h"
# include "dsound.h"
# include "dsdriver.h"
# include "dsound_private.h"
2003-02-17 02:46:46 +01:00
/* default intensity level for human ears */
# define DEFAULT_INTENSITY 0.000000000001f
2003-03-31 03:34:08 +02:00
/* default velocity of sound in the air */
# define DEFAULT_VELOCITY 340
2003-02-17 02:46:46 +01:00
2003-01-04 02:24:59 +01:00
WINE_DEFAULT_DEBUG_CHANNEL ( dsound3d ) ;
2002-06-13 21:15:06 +02:00
2003-01-04 02:22:51 +01:00
/*******************************************************************************
* Auxiliary functions
*/
/* scalar product (i believe it's called dot product in english) */
static inline D3DVALUE ScalarProduct ( LPD3DVECTOR a , LPD3DVECTOR b )
{
D3DVALUE c ;
2003-09-06 01:08:26 +02:00
c = ( a - > x * b - > x ) + ( a - > y * b - > y ) + ( a - > z * b - > z ) ;
TRACE ( " (%f,%f,%f) * (%f,%f,%f) = %f) \n " , a - > x , a - > y , a - > z , b - > x , b - > y , \
b - > z , c ) ;
2003-01-04 02:22:51 +01:00
return c ;
}
/* vector product (i believe it's called cross product in english */
2003-03-10 20:06:02 +01:00
static inline D3DVECTOR VectorProduct ( LPD3DVECTOR a , LPD3DVECTOR b )
2003-01-04 02:22:51 +01:00
{
2003-03-10 20:06:02 +01:00
D3DVECTOR c ;
2003-09-06 01:08:26 +02:00
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 ) ;
TRACE ( " (%f,%f,%f) x (%f,%f,%f) = (%f,%f,%f) \n " , a - > x , a - > y , a - > z , b - > x , b - > y , \
b - > z , c . x , c . y , c . z ) ;
2003-01-04 02:22:51 +01:00
return c ;
}
2003-07-09 04:52:57 +02:00
/* magnitude (length) of vector */
2003-01-04 02:22:51 +01:00
static inline D3DVALUE VectorMagnitude ( LPD3DVECTOR a )
{
D3DVALUE l ;
l = sqrt ( ScalarProduct ( a , a ) ) ;
2003-09-06 01:08:26 +02:00
TRACE ( " |(%f,%f,%f)| = %f \n " , a - > x , a - > y , a - > z , l ) ;
2003-01-04 02:22:51 +01:00
return l ;
}
/* conversion between radians and degrees */
2003-03-10 20:06:02 +01:00
static inline D3DVALUE RadToDeg ( D3DVALUE angle )
2003-01-04 02:22:51 +01:00
{
2003-03-10 20:06:02 +01:00
D3DVALUE newangle ;
2003-01-04 02:22:51 +01:00
newangle = angle * ( 360 / ( 2 * M_PI ) ) ;
2003-03-10 20:06:02 +01:00
TRACE ( " %f rad = %f deg \n " , angle , newangle ) ;
2003-01-04 02:22:51 +01:00
return newangle ;
}
/* conversion between degrees and radians */
2003-03-10 20:06:02 +01:00
static inline D3DVALUE DegToRad ( D3DVALUE angle )
2003-01-04 02:22:51 +01:00
{
2003-03-10 20:06:02 +01:00
D3DVALUE newangle ;
2003-01-04 02:22:51 +01:00
newangle = angle * ( 2 * M_PI / 360 ) ;
2003-03-10 20:06:02 +01:00
TRACE ( " %f deg = %f rad \n " , angle , newangle ) ;
2003-01-04 02:22:51 +01:00
return newangle ;
}
2003-03-10 20:06:02 +01:00
/* angle between vectors - deg version */
static inline D3DVALUE AngleBetweenVectorsDeg ( LPD3DVECTOR a , LPD3DVECTOR b )
2003-01-04 02:22:51 +01:00
{
2003-03-10 20:06:02 +01:00
D3DVALUE la , lb , product , angle , cos ;
2003-01-04 02:22:51 +01:00
/* definition of scalar product: a*b = |a|*|b|*cos...therefore: */
product = ScalarProduct ( a , b ) ;
la = VectorMagnitude ( a ) ;
lb = VectorMagnitude ( b ) ;
cos = product / ( la * lb ) ;
2003-03-10 20:06:02 +01:00
angle = acos ( cos ) ;
2003-01-04 02:22:51 +01:00
/* we now have angle in radians */
2003-03-10 20:06:02 +01:00
angle = RadToDeg ( angle ) ;
2003-09-06 01:08:26 +02:00
TRACE ( " angle between (%f,%f,%f) and (%f,%f,%f) = %f degrees \n " , a - > x , a - > y , a - > z , b - > x ,
b - > y , b - > z , angle ) ;
2003-03-10 20:06:02 +01:00
return angle ;
}
/* angle between vectors - rad version */
static inline D3DVALUE AngleBetweenVectorsRad ( LPD3DVECTOR a , LPD3DVECTOR b )
{
D3DVALUE la , lb , product , angle , cos ;
/* definition of scalar product: a*b = |a|*|b|*cos...therefore: */
product = ScalarProduct ( a , b ) ;
la = VectorMagnitude ( a ) ;
lb = VectorMagnitude ( b ) ;
cos = product / ( la * lb ) ;
angle = acos ( cos ) ;
2003-09-06 01:08:26 +02:00
TRACE ( " angle between (%f,%f,%f) and (%f,%f,%f) = %f radians \n " , a - > x , a - > y , a - > z , b - > x ,
b - > y , b - > z , angle ) ;
2003-01-04 02:22:51 +01:00
return angle ;
}
2003-01-04 02:24:59 +01:00
/* calculates vector between two points */
static inline D3DVECTOR VectorBetweenTwoPoints ( LPD3DVECTOR a , LPD3DVECTOR b )
{
D3DVECTOR c ;
2003-09-06 01:08:26 +02:00
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 ) ;
2003-01-04 02:24:59 +01:00
return c ;
}
2003-06-28 00:22:15 +02:00
/* calculates the length of vector's projection on another vector */
2003-03-31 03:34:08 +02:00
static inline D3DVALUE ProjectVector ( LPD3DVECTOR a , LPD3DVECTOR p )
{
D3DVALUE prod , result ;
prod = ScalarProduct ( a , p ) ;
result = prod / VectorMagnitude ( p ) ;
2003-09-06 01:08:26 +02:00
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 ) ;
2003-03-31 03:34:08 +02:00
return result ;
}
2003-01-04 02:22:51 +01:00
/*******************************************************************************
* 3 D Buffer and Listener mixing
*/
2003-01-04 02:24:59 +01:00
2003-06-28 00:22:15 +02:00
void DSOUND_Calc3DBuffer ( IDirectSoundBufferImpl * dsb )
2003-01-04 02:22:51 +01:00
{
2003-01-10 02:46:36 +01:00
/* volume, at which the sound will be played after all calcs. */
2003-03-10 20:06:02 +01:00
D3DVALUE lVolume = 0 ;
2003-02-17 02:46:46 +01:00
/* intensity (used for distance related stuff) */
double flIntensity ;
double flTemp ;
2003-01-10 02:46:36 +01:00
/* stuff for distance related stuff calc. */
2003-01-04 02:24:59 +01:00
D3DVECTOR vDistance ;
2003-03-10 20:06:02 +01:00
D3DVALUE flDistance = 0 ;
/* panning related stuff */
D3DVALUE flAngle ;
D3DVECTOR vLeft ;
2003-03-31 03:34:08 +02:00
/* doppler shift related stuff */
2003-04-05 00:13:02 +02:00
#if 0
2003-03-31 03:34:08 +02:00
D3DVALUE flFreq , flBufferVel , flListenerVel ;
2003-04-05 00:13:02 +02:00
# endif
2003-06-28 00:22:15 +02:00
TRACE ( " (%p) \n " , dsb ) ;
2003-02-17 02:46:46 +01:00
2003-03-10 20:06:02 +01:00
/* initial buffer volume */
2004-07-14 01:35:09 +02:00
lVolume = dsb - > ds3db_lVolume ;
2003-01-04 02:24:59 +01:00
2003-06-28 00:22:15 +02:00
switch ( dsb - > ds3db_ds3db . dwMode )
2003-01-04 02:24:59 +01:00
{
2003-03-05 03:47:39 +01:00
case DS3DMODE_DISABLE :
2003-03-10 20:06:02 +01:00
TRACE ( " 3D processing disabled \n " ) ;
/* this one is here only to eliminate annoying warning message */
2003-06-28 00:22:15 +02:00
DSOUND_RecalcVolPan ( & dsb - > volpan ) ;
DSOUND_ForceRemix ( dsb ) ;
2003-03-05 03:47:39 +01:00
break ;
2003-01-04 02:24:59 +01:00
case DS3DMODE_NORMAL :
2003-03-05 03:47:39 +01:00
TRACE ( " Normal 3D processing mode \n " ) ;
/* we need to calculate distance between buffer and listener*/
2005-05-31 11:31:37 +02:00
vDistance = VectorBetweenTwoPoints ( & dsb - > ds3db_ds3db . vPosition , & dsb - > dsound - > device - > ds3dl . vPosition ) ;
2003-02-17 02:46:46 +01:00
flDistance = VectorMagnitude ( & vDistance ) ;
2003-01-10 02:46:36 +01:00
break ;
2003-01-04 02:24:59 +01:00
case DS3DMODE_HEADRELATIVE :
2003-03-05 03:47:39 +01:00
TRACE ( " Head-relative 3D processing mode \n " ) ;
/* distance between buffer and listener is same as buffer's position */
2003-06-28 00:22:15 +02:00
flDistance = VectorMagnitude ( & dsb - > ds3db_ds3db . vPosition ) ;
2003-03-10 20:06:02 +01:00
break ;
}
2003-03-05 03:47:39 +01:00
2003-06-28 00:22:15 +02:00
if ( flDistance > dsb - > ds3db_ds3db . flMaxDistance )
2003-03-05 03:47:39 +01:00
{
/* some apps don't want you to hear too distant sounds... */
2003-06-28 00:22:15 +02:00
if ( dsb - > dsbd . dwFlags & DSBCAPS_MUTE3DATMAXDISTANCE )
2003-03-05 03:47:39 +01:00
{
2003-06-28 00:22:15 +02:00
dsb - > volpan . lVolume = DSBVOLUME_MIN ;
DSOUND_RecalcVolPan ( & dsb - > volpan ) ;
2003-03-05 03:47:39 +01:00
/* i guess mixing here would be a waste of power */
return ;
}
else
2003-06-28 00:22:15 +02:00
flDistance = dsb - > ds3db_ds3db . flMaxDistance ;
2003-03-05 03:47:39 +01:00
}
2003-06-28 00:22:15 +02:00
if ( flDistance < dsb - > ds3db_ds3db . flMinDistance )
flDistance = dsb - > ds3db_ds3db . flMinDistance ;
2003-03-05 03:47:39 +01:00
/* 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 */
lVolume + = 10000 ; /* ms likes working with negative volume...i don't */
lVolume / = 1000 ; /* convert hundreths of dB into B */
/* intensity level (loudness) = log10(Intensity/DefaultIntensity)...therefore */
2003-03-10 20:06:02 +01:00
flIntensity = pow ( 10 , lVolume ) * DEFAULT_INTENSITY ;
2003-06-28 00:22:15 +02:00
flTemp = ( flDistance / dsb - > ds3db_ds3db . flMinDistance ) * ( flDistance / dsb - > ds3db_ds3db . flMinDistance ) ;
2003-03-05 03:47:39 +01:00
flIntensity / = flTemp ;
2003-03-10 20:06:02 +01:00
lVolume = log10 ( flIntensity / DEFAULT_INTENSITY ) ;
2003-03-05 03:47:39 +01:00
lVolume * = 1000 ; /* convert back to hundreths of dB */
lVolume - = 10000 ; /* we need to do it in ms way */
2003-06-28 00:22:15 +02:00
TRACE ( " dist. att: Distance = %f, MinDistance = %f => adjusting volume %ld to %f \n " , flDistance , dsb - > ds3db_ds3db . flMinDistance , dsb - > ds3db_lVolume , lVolume ) ;
2003-03-10 20:06:02 +01:00
/* conning */
/* sometimes it happens that vConeOrientation vector = (0,0,0); in this case angle is "nan" and it's useless*/
2003-09-06 01:08:26 +02:00
if ( dsb - > ds3db_ds3db . vConeOrientation . x = = 0 & & dsb - > ds3db_ds3db . vConeOrientation . y = = 0 & & dsb - > ds3db_ds3db . vConeOrientation . z = = 0 )
2003-03-10 20:06:02 +01:00
{
TRACE ( " conning: cones not set \n " ) ;
}
else
{
/* calculate angle */
2003-06-28 00:22:15 +02:00
flAngle = AngleBetweenVectorsDeg ( & dsb - > ds3db_ds3db . vConeOrientation , & vDistance ) ;
2003-03-10 20:06:02 +01:00
/* if by any chance it happens that OutsideConeAngle = InsideConeAngle (that means that conning has no effect) */
2003-06-28 00:22:15 +02:00
if ( dsb - > ds3db_ds3db . dwInsideConeAngle ! = dsb - > ds3db_ds3db . dwOutsideConeAngle )
2003-03-10 20:06:02 +01:00
{
/* my test show that for my way of calc., we need only half of angles */
2003-06-28 00:22:15 +02:00
DWORD dwInsideConeAngle = dsb - > ds3db_ds3db . dwInsideConeAngle / 2 ;
DWORD dwOutsideConeAngle = dsb - > ds3db_ds3db . dwOutsideConeAngle / 2 ;
2003-03-10 20:06:02 +01:00
/* 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 */
2003-06-28 00:22:15 +02:00
lVolume + = ( ( dsb - > ds3db_ds3db . lConeOutsideVolume ) / ( ( dwOutsideConeAngle ) - ( dwInsideConeAngle ) ) ) * flAngle ;
}
2003-03-10 20:06:02 +01:00
TRACE ( " conning: Angle = %f deg; InsideConeAngle(/2) = %ld deg; OutsideConeAngle(/2) = %ld deg; ConeOutsideVolume = %ld => adjusting volume to %f \n " ,
2003-06-28 00:22:15 +02:00
flAngle , dsb - > ds3db_ds3db . dwInsideConeAngle / 2 , dsb - > ds3db_ds3db . dwOutsideConeAngle / 2 , dsb - > ds3db_ds3db . lConeOutsideVolume , lVolume ) ;
2003-03-10 20:06:02 +01:00
}
2003-06-28 00:22:15 +02:00
dsb - > volpan . lVolume = lVolume ;
2003-03-10 20:06:02 +01:00
/* panning */
2005-05-31 11:31:37 +02:00
if ( dsb - > dsound - > device - > ds3dl . vPosition . x = = dsb - > ds3db_ds3db . vPosition . x & &
dsb - > dsound - > device - > ds3dl . vPosition . y = = dsb - > ds3db_ds3db . vPosition . y & &
dsb - > dsound - > device - > ds3dl . vPosition . z = = dsb - > ds3db_ds3db . vPosition . z ) {
2003-06-28 00:22:15 +02:00
dsb - > volpan . lPan = 0 ;
flAngle = 0.0 ;
}
else
{
2005-05-31 11:31:37 +02:00
vDistance = VectorBetweenTwoPoints ( & dsb - > dsound - > device - > ds3dl . vPosition , & dsb - > ds3db_ds3db . vPosition ) ;
vLeft = VectorProduct ( & dsb - > dsound - > device - > ds3dl . vOrientFront , & dsb - > dsound - > device - > ds3dl . vOrientTop ) ;
2003-06-28 00:22:15 +02:00
flAngle = AngleBetweenVectorsRad ( & vLeft , & vDistance ) ;
/* for now, we'll use "linear formula" (which is probably incorrect); if someone has it in book, correct it */
dsb - > volpan . lPan = 10000 * 2 * flAngle / M_PI - 10000 ;
}
TRACE ( " panning: Angle = %f rad, lPan = %ld \n " , flAngle , dsb - > volpan . lPan ) ;
2003-03-31 03:34:08 +02:00
/* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */
#if 0
2003-03-10 20:06:02 +01:00
/* doppler shift*/
2005-05-31 11:31:37 +02:00
if ( ( VectorMagnitude ( & ds3db . vVelocity ) = = 0 ) & & ( VectorMagnitude ( & dsb - > dsound - > device - > ds3dl . vVelocity ) = = 0 ) )
2003-03-31 03:34:08 +02:00
{
TRACE ( " doppler: Buffer and Listener don't have velocities \n " ) ;
}
else
{
2003-07-09 04:52:57 +02:00
/* calculate length of ds3db.vVelocity component which causes Doppler Effect
2003-03-31 03:34:08 +02:00
NOTE : if buffer moves TOWARDS the listener , it ' s velocity component is NEGATIVE
if buffer moves AWAY from listener , it ' s velocity component is POSITIVE */
2003-06-28 00:22:15 +02:00
flBufferVel = ProjectVector ( & dsb - > ds3db_ds3db . vVelocity , & vDistance ) ;
2003-07-09 04:52:57 +02:00
/* calculate length of ds3dl.vVelocity component which causes Doppler Effect
2003-03-31 03:34:08 +02:00
NOTE : if listener moves TOWARDS the buffer , it ' s velocity component is POSITIVE
if listener moves AWAY from buffer , it ' s velocity component is NEGATIVE */
2005-05-31 11:31:37 +02:00
flListenerVel = ProjectVector ( & dsb - > dsound - > device - > ds3dl . vVelocity , & vDistance ) ;
2003-03-31 03:34:08 +02:00
/* formula taken from Gianicoli D.: Physics, 4th edition: */
2003-06-28 00:22:15 +02:00
/* FIXME: replace dsb->freq with appropriate frequency ! */
flFreq = dsb - > freq * ( ( DEFAULT_VELOCITY + flListenerVel ) / ( DEFAULT_VELOCITY + flBufferVel ) ) ;
2003-03-31 03:34:08 +02:00
TRACE ( " doppler: Buffer velocity (component) = %lf, Listener velocity (component) = %lf => Doppler shift: %ld Hz -> %lf Hz \n " , flBufferVel , flListenerVel , \
2003-06-28 00:22:15 +02:00
dsb - > freq , flFreq ) ;
2003-03-31 03:34:08 +02:00
/* FIXME: replace following line with correct frequency setting ! */
2003-06-28 00:22:15 +02:00
dsb - > freq = flFreq ;
2003-03-31 03:34:08 +02:00
}
# endif
2003-03-10 20:06:02 +01:00
2003-03-31 03:34:08 +02:00
/* time for remix */
2003-06-28 00:22:15 +02:00
DSOUND_RecalcVolPan ( & dsb - > volpan ) ;
}
static void DSOUND_Mix3DBuffer ( IDirectSoundBufferImpl * dsb )
{
TRACE ( " (%p) \n " , dsb ) ;
DSOUND_Calc3DBuffer ( dsb ) ;
DSOUND_ForceRemix ( dsb ) ;
2003-01-04 02:22:51 +01:00
}
static void WINAPI DSOUND_ChangeListener ( IDirectSound3DListenerImpl * ds3dl )
{
int i ;
2003-05-22 05:39:13 +02:00
TRACE ( " (%p) \n " , ds3dl ) ;
2005-05-31 11:31:37 +02:00
for ( i = 0 ; i < ds3dl - > dsound - > device - > nrofbuffers ; i + + )
2003-01-04 02:22:51 +01:00
{
2003-01-04 02:24:59 +01:00
/* some buffers don't have 3d buffer (Ultima IX seems to
crash without the following line ) */
2005-05-31 11:31:37 +02:00
if ( ds3dl - > dsound - > device - > buffers [ i ] - > ds3db = = NULL )
2003-01-04 02:24:59 +01:00
continue ;
2005-05-31 11:31:37 +02:00
if ( ds3dl - > dsound - > device - > buffers [ i ] - > ds3db_need_recalc )
2003-01-04 02:24:59 +01:00
{
2005-05-31 11:31:37 +02:00
DSOUND_Mix3DBuffer ( ds3dl - > dsound - > device - > buffers [ i ] ) ;
2003-01-04 02:24:59 +01:00
}
2003-01-04 02:22:51 +01:00
}
}
2002-06-13 21:15:06 +02:00
/*******************************************************************************
* IDirectSound3DBuffer
*/
/* IUnknown methods */
static HRESULT WINAPI IDirectSound3DBufferImpl_QueryInterface (
LPDIRECTSOUND3DBUFFER iface , REFIID riid , LPVOID * ppobj )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2002-06-13 21:15:06 +02:00
TRACE ( " (%p,%s,%p) \n " , This , debugstr_guid ( riid ) , ppobj ) ;
return IDirectSoundBuffer_QueryInterface ( ( LPDIRECTSOUNDBUFFER8 ) This - > dsb , riid , ppobj ) ;
}
static ULONG WINAPI IDirectSound3DBufferImpl_AddRef ( LPDIRECTSOUND3DBUFFER iface )
{
2005-02-11 12:49:05 +01:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
ULONG ref = InterlockedIncrement ( & ( This - > ref ) ) ;
TRACE ( " (%p) ref was %ld \n " , This , ref - 1 ) ;
return ref ;
2002-06-13 21:15:06 +02:00
}
static ULONG WINAPI IDirectSound3DBufferImpl_Release ( LPDIRECTSOUND3DBUFFER iface )
{
2005-02-11 12:49:05 +01:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
ULONG ref = InterlockedDecrement ( & ( This - > ref ) ) ;
TRACE ( " (%p) ref was %ld \n " , This , ref + 1 ) ;
2002-06-13 21:15:06 +02:00
2005-02-11 12:49:05 +01:00
if ( ! ref ) {
This - > dsb - > ds3db = NULL ;
IDirectSoundBuffer_Release ( ( LPDIRECTSOUNDBUFFER8 ) This - > dsb ) ;
HeapFree ( GetProcessHeap ( ) , 0 , This ) ;
TRACE ( " (%p) released \n " , This ) ;
}
return ref ;
2002-06-13 21:15:06 +02:00
}
/* IDirectSound3DBuffer methods */
static HRESULT WINAPI IDirectSound3DBufferImpl_GetAllParameters (
LPDIRECTSOUND3DBUFFER iface ,
LPDS3DBUFFER lpDs3dBuffer )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-06-28 00:22:15 +02:00
TRACE ( " (%p,%p) \n " , This , lpDs3dBuffer ) ;
if ( lpDs3dBuffer = = NULL ) {
2003-07-02 06:37:26 +02:00
WARN ( " invalid parameter: lpDs3dBuffer == NULL \n " ) ;
2003-06-28 00:22:15 +02:00
return DSERR_INVALIDPARAM ;
}
if ( lpDs3dBuffer - > dwSize < sizeof ( * lpDs3dBuffer ) ) {
2003-07-02 06:37:26 +02:00
WARN ( " invalid parameter: lpDs3dBuffer->dwSize = %ld < %d \n " , lpDs3dBuffer - > dwSize , sizeof ( * lpDs3dBuffer ) ) ;
2003-06-28 00:22:15 +02:00
return DSERR_INVALIDPARAM ;
}
2003-09-02 02:56:14 +02:00
TRACE ( " returning: all parameters \n " ) ;
* lpDs3dBuffer = This - > dsb - > ds3db_ds3db ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeAngles (
LPDIRECTSOUND3DBUFFER iface ,
LPDWORD lpdwInsideConeAngle ,
LPDWORD lpdwOutsideConeAngle )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-09-02 02:56:14 +02:00
TRACE ( " returning: Inside Cone Angle = %ld degrees; Outside Cone Angle = %ld degrees \n " ,
This - > dsb - > ds3db_ds3db . dwInsideConeAngle , This - > dsb - > ds3db_ds3db . dwOutsideConeAngle ) ;
* lpdwInsideConeAngle = This - > dsb - > ds3db_ds3db . dwInsideConeAngle ;
* lpdwOutsideConeAngle = This - > dsb - > ds3db_ds3db . dwOutsideConeAngle ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOrientation (
LPDIRECTSOUND3DBUFFER iface ,
LPD3DVECTOR lpvConeOrientation )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-09-02 02:56:14 +02:00
TRACE ( " returning: Cone Orientation vector = (%f,%f,%f) \n " ,
2004-07-14 01:35:09 +02:00
This - > dsb - > ds3db_ds3db . vConeOrientation . x ,
This - > dsb - > ds3db_ds3db . vConeOrientation . y ,
2003-09-06 01:08:26 +02:00
This - > dsb - > ds3db_ds3db . vConeOrientation . z ) ;
2003-09-02 02:56:14 +02:00
* lpvConeOrientation = This - > dsb - > ds3db_ds3db . vConeOrientation ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_GetConeOutsideVolume (
LPDIRECTSOUND3DBUFFER iface ,
LPLONG lplConeOutsideVolume )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-09-02 02:56:14 +02:00
TRACE ( " returning: Cone Outside Volume = %ld \n " , This - > dsb - > ds3db_ds3db . lConeOutsideVolume ) ;
* lplConeOutsideVolume = This - > dsb - > ds3db_ds3db . lConeOutsideVolume ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_GetMaxDistance (
LPDIRECTSOUND3DBUFFER iface ,
LPD3DVALUE lpfMaxDistance )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-09-02 02:56:14 +02:00
TRACE ( " returning: Max Distance = %f \n " , This - > dsb - > ds3db_ds3db . flMaxDistance ) ;
* lpfMaxDistance = This - > dsb - > ds3db_ds3db . flMaxDistance ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_GetMinDistance (
LPDIRECTSOUND3DBUFFER iface ,
LPD3DVALUE lpfMinDistance )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-09-02 02:56:14 +02:00
TRACE ( " returning: Min Distance = %f \n " , This - > dsb - > ds3db_ds3db . flMinDistance ) ;
* lpfMinDistance = This - > dsb - > ds3db_ds3db . flMinDistance ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_GetMode (
LPDIRECTSOUND3DBUFFER iface ,
LPDWORD lpdwMode )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-09-02 02:56:14 +02:00
TRACE ( " returning: Mode = %ld \n " , This - > dsb - > ds3db_ds3db . dwMode ) ;
* lpdwMode = This - > dsb - > ds3db_ds3db . dwMode ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_GetPosition (
LPDIRECTSOUND3DBUFFER iface ,
LPD3DVECTOR lpvPosition )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-09-02 02:56:14 +02:00
TRACE ( " returning: Position vector = (%f,%f,%f) \n " ,
2003-09-06 01:08:26 +02:00
This - > dsb - > ds3db_ds3db . vPosition . x ,
This - > dsb - > ds3db_ds3db . vPosition . y ,
This - > dsb - > ds3db_ds3db . vPosition . z ) ;
2003-09-02 02:56:14 +02:00
* lpvPosition = This - > dsb - > ds3db_ds3db . vPosition ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_GetVelocity (
LPDIRECTSOUND3DBUFFER iface ,
LPD3DVECTOR lpvVelocity )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-09-02 02:56:14 +02:00
TRACE ( " returning: Velocity vector = (%f,%f,%f) \n " ,
2003-09-06 01:08:26 +02:00
This - > dsb - > ds3db_ds3db . vVelocity . x ,
This - > dsb - > ds3db_ds3db . vVelocity . y ,
This - > dsb - > ds3db_ds3db . vVelocity . z ) ;
2003-09-02 02:56:14 +02:00
* lpvVelocity = This - > dsb - > ds3db_ds3db . vVelocity ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_SetAllParameters (
LPDIRECTSOUND3DBUFFER iface ,
LPCDS3DBUFFER lpcDs3dBuffer ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-06-28 00:22:15 +02:00
DWORD status = DSERR_INVALIDPARAM ;
TRACE ( " (%p,%p,%lx) \n " , iface , lpcDs3dBuffer , dwApply ) ;
if ( lpcDs3dBuffer = = NULL ) {
WARN ( " invalid parameter: lpcDs3dBuffer == NULL \n " ) ;
return status ;
2002-12-13 01:31:06 +01:00
}
2003-06-28 00:22:15 +02:00
if ( lpcDs3dBuffer - > dwSize ! = sizeof ( DS3DBUFFER ) ) {
WARN ( " invalid parameter: lpcDs3dBuffer->dwSize = %ld != %d \n " ,
lpcDs3dBuffer - > dwSize , sizeof ( DS3DBUFFER ) ) ;
return status ;
}
2003-09-02 02:56:14 +02:00
TRACE ( " setting: all parameters; dwApply = %ld \n " , dwApply ) ;
This - > dsb - > ds3db_ds3db = * lpcDs3dBuffer ;
2003-06-28 00:22:15 +02:00
2003-09-02 02:56:14 +02:00
if ( dwApply = = DS3D_IMMEDIATE )
{
DSOUND_Mix3DBuffer ( This - > dsb ) ;
}
This - > dsb - > ds3db_need_recalc = TRUE ;
status = DS_OK ;
2003-06-28 00:22:15 +02:00
return status ;
2002-06-13 21:15:06 +02:00
}
static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeAngles (
LPDIRECTSOUND3DBUFFER iface ,
DWORD dwInsideConeAngle ,
DWORD dwOutsideConeAngle ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2003-06-28 00:22:15 +02:00
TRACE ( " setting: Inside Cone Angle = %ld; Outside Cone Angle = %ld; dwApply = %ld \n " ,
dwInsideConeAngle , dwOutsideConeAngle , dwApply ) ;
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_ds3db . dwInsideConeAngle = dwInsideConeAngle ;
This - > dsb - > ds3db_ds3db . dwOutsideConeAngle = dwOutsideConeAngle ;
if ( dwApply = = DS3D_IMMEDIATE )
{
DSOUND_Mix3DBuffer ( This - > dsb ) ;
2002-12-13 01:31:06 +01:00
}
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOrientation (
LPDIRECTSOUND3DBUFFER iface ,
D3DVALUE x , D3DVALUE y , D3DVALUE z ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2002-12-13 01:31:06 +01:00
TRACE ( " setting: Cone Orientation vector = (%f,%f,%f); dwApply = %ld \n " , x , y , z , dwApply ) ;
2003-09-06 01:08:26 +02:00
This - > dsb - > ds3db_ds3db . vConeOrientation . x = x ;
This - > dsb - > ds3db_ds3db . vConeOrientation . y = y ;
This - > dsb - > ds3db_ds3db . vConeOrientation . z = z ;
2003-09-02 02:56:14 +02:00
if ( dwApply = = DS3D_IMMEDIATE )
{
This - > dsb - > ds3db_need_recalc = FALSE ;
DSOUND_Mix3DBuffer ( This - > dsb ) ;
2002-12-13 01:31:06 +01:00
}
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_SetConeOutsideVolume (
LPDIRECTSOUND3DBUFFER iface ,
LONG lConeOutsideVolume ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2002-12-13 01:31:06 +01:00
TRACE ( " setting: ConeOutsideVolume = %ld; dwApply = %ld \n " , lConeOutsideVolume , dwApply ) ;
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_ds3db . lConeOutsideVolume = lConeOutsideVolume ;
if ( dwApply = = DS3D_IMMEDIATE )
{
This - > dsb - > ds3db_need_recalc = FALSE ;
DSOUND_Mix3DBuffer ( This - > dsb ) ;
2002-12-13 01:31:06 +01:00
}
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_SetMaxDistance (
LPDIRECTSOUND3DBUFFER iface ,
D3DVALUE fMaxDistance ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2002-12-13 01:31:06 +01:00
TRACE ( " setting: MaxDistance = %f; dwApply = %ld \n " , fMaxDistance , dwApply ) ;
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_ds3db . flMaxDistance = fMaxDistance ;
if ( dwApply = = DS3D_IMMEDIATE )
{
This - > dsb - > ds3db_need_recalc = FALSE ;
DSOUND_Mix3DBuffer ( This - > dsb ) ;
2002-12-13 01:31:06 +01:00
}
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_SetMinDistance (
LPDIRECTSOUND3DBUFFER iface ,
D3DVALUE fMinDistance ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2002-12-13 01:31:06 +01:00
TRACE ( " setting: MinDistance = %f; dwApply = %ld \n " , fMinDistance , dwApply ) ;
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_ds3db . flMinDistance = fMinDistance ;
if ( dwApply = = DS3D_IMMEDIATE )
{
This - > dsb - > ds3db_need_recalc = FALSE ;
DSOUND_Mix3DBuffer ( This - > dsb ) ;
2002-12-13 01:31:06 +01:00
}
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_SetMode (
LPDIRECTSOUND3DBUFFER iface ,
DWORD dwMode ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2002-12-13 01:31:06 +01:00
TRACE ( " setting: Mode = %ld; dwApply = %ld \n " , dwMode , dwApply ) ;
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_ds3db . dwMode = dwMode ;
if ( dwApply = = DS3D_IMMEDIATE )
{
This - > dsb - > ds3db_need_recalc = FALSE ;
DSOUND_Mix3DBuffer ( This - > dsb ) ;
2002-12-13 01:31:06 +01:00
}
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_SetPosition (
LPDIRECTSOUND3DBUFFER iface ,
D3DVALUE x , D3DVALUE y , D3DVALUE z ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2002-12-13 01:31:06 +01:00
TRACE ( " setting: Position vector = (%f,%f,%f); dwApply = %ld \n " , x , y , z , dwApply ) ;
2003-09-06 01:08:26 +02:00
This - > dsb - > ds3db_ds3db . vPosition . x = x ;
This - > dsb - > ds3db_ds3db . vPosition . y = y ;
This - > dsb - > ds3db_ds3db . vPosition . z = z ;
2003-09-02 02:56:14 +02:00
if ( dwApply = = DS3D_IMMEDIATE )
{
This - > dsb - > ds3db_need_recalc = FALSE ;
DSOUND_Mix3DBuffer ( This - > dsb ) ;
2002-12-13 01:31:06 +01:00
}
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DBufferImpl_SetVelocity (
LPDIRECTSOUND3DBUFFER iface ,
D3DVALUE x , D3DVALUE y , D3DVALUE z ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DBufferImpl * This = ( IDirectSound3DBufferImpl * ) iface ;
2002-12-13 01:31:06 +01:00
TRACE ( " setting: Velocity vector = (%f,%f,%f); dwApply = %ld \n " , x , y , z , dwApply ) ;
2003-09-06 01:08:26 +02:00
This - > dsb - > ds3db_ds3db . vVelocity . x = x ;
This - > dsb - > ds3db_ds3db . vVelocity . y = y ;
This - > dsb - > ds3db_ds3db . vVelocity . z = z ;
2003-09-02 02:56:14 +02:00
if ( dwApply = = DS3D_IMMEDIATE )
{
This - > dsb - > ds3db_need_recalc = FALSE ;
DSOUND_Mix3DBuffer ( This - > dsb ) ;
2002-12-13 01:31:06 +01:00
}
2003-09-02 02:56:14 +02:00
This - > dsb - > ds3db_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
2005-06-01 21:57:42 +02:00
static const IDirectSound3DBufferVtbl ds3dbvt =
2002-06-13 21:15:06 +02:00
{
/* 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 ,
} ;
HRESULT WINAPI IDirectSound3DBufferImpl_Create (
2003-09-02 01:58:43 +02:00
IDirectSoundBufferImpl * dsb ,
2002-06-13 21:15:06 +02:00
IDirectSound3DBufferImpl * * pds3db )
{
IDirectSound3DBufferImpl * ds3db ;
2003-09-02 01:58:43 +02:00
TRACE ( " (%p,%p) \n " , dsb , pds3db ) ;
2003-05-22 05:39:13 +02:00
2004-08-18 02:30:37 +02:00
ds3db = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , sizeof ( * ds3db ) ) ;
2003-05-22 05:39:13 +02:00
if ( ds3db = = NULL ) {
WARN ( " out of memory \n " ) ;
2003-06-28 00:22:15 +02:00
* pds3db = 0 ;
2003-05-22 05:39:13 +02:00
return DSERR_OUTOFMEMORY ;
}
2002-06-13 21:15:06 +02:00
ds3db - > ref = 0 ;
2003-09-02 01:58:43 +02:00
ds3db - > dsb = dsb ;
2003-04-10 20:17:34 +02:00
ds3db - > lpVtbl = & ds3dbvt ;
2003-06-28 00:22:15 +02:00
ds3db - > dsb - > ds3db_ds3db . dwSize = sizeof ( DS3DBUFFER ) ;
2003-09-06 01:08:26 +02:00
ds3db - > dsb - > ds3db_ds3db . vPosition . x = 0.0 ;
ds3db - > dsb - > ds3db_ds3db . vPosition . y = 0.0 ;
ds3db - > dsb - > ds3db_ds3db . vPosition . z = 0.0 ;
ds3db - > dsb - > ds3db_ds3db . vVelocity . x = 0.0 ;
ds3db - > dsb - > ds3db_ds3db . vVelocity . y = 0.0 ;
ds3db - > dsb - > ds3db_ds3db . vVelocity . z = 0.0 ;
2003-06-28 00:22:15 +02:00
ds3db - > dsb - > ds3db_ds3db . dwInsideConeAngle = DS3D_DEFAULTCONEANGLE ;
ds3db - > dsb - > ds3db_ds3db . dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE ;
2003-09-06 01:08:26 +02:00
ds3db - > dsb - > ds3db_ds3db . vConeOrientation . x = 0.0 ;
ds3db - > dsb - > ds3db_ds3db . vConeOrientation . y = 0.0 ;
ds3db - > dsb - > ds3db_ds3db . vConeOrientation . z = 0.0 ;
2003-06-28 00:22:15 +02:00
ds3db - > dsb - > ds3db_ds3db . lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME ;
ds3db - > dsb - > ds3db_ds3db . flMinDistance = DS3D_DEFAULTMINDISTANCE ;
ds3db - > dsb - > ds3db_ds3db . flMaxDistance = DS3D_DEFAULTMAXDISTANCE ;
ds3db - > dsb - > ds3db_ds3db . dwMode = DS3DMODE_NORMAL ;
ds3db - > dsb - > ds3db_need_recalc = TRUE ;
2003-09-02 01:58:43 +02:00
IDirectSoundBuffer_AddRef ( ( LPDIRECTSOUNDBUFFER8 ) dsb ) ;
2002-06-13 21:15:06 +02:00
* pds3db = ds3db ;
return S_OK ;
}
2004-07-14 01:35:09 +02:00
HRESULT WINAPI IDirectSound3DBufferImpl_Destroy (
IDirectSound3DBufferImpl * pds3db )
{
TRACE ( " (%p) \n " , pds3db ) ;
while ( IDirectSound3DBufferImpl_Release ( ( LPDIRECTSOUND3DBUFFER ) pds3db ) > 0 ) ;
return S_OK ;
}
2002-06-13 21:15:06 +02:00
/*******************************************************************************
* IDirectSound3DListener
*/
/* IUnknown methods */
static HRESULT WINAPI IDirectSound3DListenerImpl_QueryInterface (
LPDIRECTSOUND3DLISTENER iface , REFIID riid , LPVOID * ppobj )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2002-06-13 21:15:06 +02:00
TRACE ( " (%p,%s,%p) \n " , This , debugstr_guid ( riid ) , ppobj ) ;
2003-06-28 00:22:15 +02:00
2003-08-07 00:57:24 +02:00
if ( ppobj = = NULL ) {
WARN ( " invalid parameter \n " ) ;
return E_INVALIDARG ;
}
* ppobj = NULL ; /* assume failure */
2003-06-28 00:22:15 +02:00
if ( IsEqualGUID ( riid , & IID_IUnknown ) | |
IsEqualGUID ( riid , & IID_IDirectSound3DListener ) ) {
IDirectSound3DListener_AddRef ( ( LPDIRECTSOUND3DLISTENER ) This ) ;
* ppobj = This ;
return S_OK ;
}
if ( IsEqualGUID ( riid , & IID_IDirectSoundBuffer ) ) {
2005-05-31 11:31:37 +02:00
if ( ! This - > dsound - > device - > primary )
PrimaryBufferImpl_Create ( This - > dsound , & ( This - > dsound - > device - > primary ) , & ( This - > dsound - > device - > dsbd ) ) ;
if ( This - > dsound - > device - > primary ) {
* ppobj = This - > dsound - > device - > primary ;
2003-09-02 01:58:43 +02:00
IDirectSoundBuffer_AddRef ( ( LPDIRECTSOUNDBUFFER ) * ppobj ) ;
return S_OK ;
}
2003-06-28 00:22:15 +02:00
}
FIXME ( " Unknown IID %s \n " , debugstr_guid ( riid ) ) ;
return E_NOINTERFACE ;
2002-06-13 21:15:06 +02:00
}
static ULONG WINAPI IDirectSound3DListenerImpl_AddRef ( LPDIRECTSOUND3DLISTENER iface )
{
2005-02-11 12:49:05 +01:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
ULONG ref = InterlockedIncrement ( & ( This - > ref ) ) ;
TRACE ( " (%p) ref was %ld \n " , This , ref - 1 ) ;
return ref ;
2002-06-13 21:15:06 +02:00
}
static ULONG WINAPI IDirectSound3DListenerImpl_Release ( LPDIRECTSOUND3DLISTENER iface )
{
2005-02-11 12:49:05 +01:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
ULONG ref = InterlockedDecrement ( & ( This - > ref ) ) ;
TRACE ( " (%p) ref was %ld \n " , This , ref + 1 ) ;
2002-06-13 21:15:06 +02:00
2005-02-11 12:49:05 +01:00
if ( ! ref ) {
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > listener = 0 ;
2005-02-11 12:49:05 +01:00
HeapFree ( GetProcessHeap ( ) , 0 , This ) ;
TRACE ( " (%p) released \n " , This ) ;
}
return ref ;
2002-06-13 21:15:06 +02:00
}
/* IDirectSound3DListener methods */
static HRESULT WINAPI IDirectSound3DListenerImpl_GetAllParameter (
LPDIRECTSOUND3DLISTENER iface ,
LPDS3DLISTENER lpDS3DL )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2003-06-28 00:22:15 +02:00
TRACE ( " (%p,%p) \n " , This , lpDS3DL ) ;
if ( lpDS3DL = = NULL ) {
2003-07-02 06:37:26 +02:00
WARN ( " invalid parameter: lpDS3DL == NULL \n " ) ;
2003-06-28 00:22:15 +02:00
return DSERR_INVALIDPARAM ;
}
if ( lpDS3DL - > dwSize < sizeof ( * lpDS3DL ) ) {
2003-07-02 06:37:26 +02:00
WARN ( " invalid parameter: lpDS3DL->dwSize = %ld < %d \n " , lpDS3DL - > dwSize , sizeof ( * lpDS3DL ) ) ;
2003-06-28 00:22:15 +02:00
return DSERR_INVALIDPARAM ;
}
2002-12-13 00:01:05 +01:00
TRACE ( " returning: all parameters \n " ) ;
2005-05-31 11:31:37 +02:00
* lpDS3DL = This - > dsound - > device - > ds3dl ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_GetDistanceFactor (
LPDIRECTSOUND3DLISTENER iface ,
LPD3DVALUE lpfDistanceFactor )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2005-05-31 11:31:37 +02:00
TRACE ( " returning: Distance Factor = %f \n " , This - > dsound - > device - > ds3dl . flDistanceFactor ) ;
* lpfDistanceFactor = This - > dsound - > device - > ds3dl . flDistanceFactor ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_GetDopplerFactor (
LPDIRECTSOUND3DLISTENER iface ,
LPD3DVALUE lpfDopplerFactor )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2005-05-31 11:31:37 +02:00
TRACE ( " returning: Doppler Factor = %f \n " , This - > dsound - > device - > ds3dl . flDopplerFactor ) ;
* lpfDopplerFactor = This - > dsound - > device - > ds3dl . flDopplerFactor ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_GetOrientation (
LPDIRECTSOUND3DLISTENER iface ,
LPD3DVECTOR lpvOrientFront ,
LPD3DVECTOR lpvOrientTop )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2005-05-31 11:31:37 +02:00
TRACE ( " returning: OrientFront vector = (%f,%f,%f); OrientTop vector = (%f,%f,%f) \n " , This - > dsound - > device - > ds3dl . vOrientFront . x , \
This - > dsound - > device - > ds3dl . vOrientFront . y , This - > dsound - > device - > ds3dl . vOrientFront . z , This - > dsound - > device - > ds3dl . vOrientTop . x , This - > dsound - > device - > ds3dl . vOrientTop . y , \
This - > dsound - > device - > ds3dl . vOrientTop . z ) ;
* lpvOrientFront = This - > dsound - > device - > ds3dl . vOrientFront ;
* lpvOrientTop = This - > dsound - > device - > ds3dl . vOrientTop ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_GetPosition (
LPDIRECTSOUND3DLISTENER iface ,
LPD3DVECTOR lpvPosition )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2005-05-31 11:31:37 +02:00
TRACE ( " returning: Position vector = (%f,%f,%f) \n " , This - > dsound - > device - > ds3dl . vPosition . x , This - > dsound - > device - > ds3dl . vPosition . y , This - > dsound - > device - > ds3dl . vPosition . z ) ;
* lpvPosition = This - > dsound - > device - > ds3dl . vPosition ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_GetRolloffFactor (
LPDIRECTSOUND3DLISTENER iface ,
LPD3DVALUE lpfRolloffFactor )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2005-05-31 11:31:37 +02:00
TRACE ( " returning: RolloffFactor = %f \n " , This - > dsound - > device - > ds3dl . flRolloffFactor ) ;
* lpfRolloffFactor = This - > dsound - > device - > ds3dl . flRolloffFactor ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_GetVelocity (
LPDIRECTSOUND3DLISTENER iface ,
LPD3DVECTOR lpvVelocity )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2005-05-31 11:31:37 +02:00
TRACE ( " returning: Velocity vector = (%f,%f,%f) \n " , This - > dsound - > device - > ds3dl . vVelocity . x , This - > dsound - > device - > ds3dl . vVelocity . y , This - > dsound - > device - > ds3dl . vVelocity . z ) ;
* lpvVelocity = This - > dsound - > device - > ds3dl . vVelocity ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_SetAllParameters (
LPDIRECTSOUND3DLISTENER iface ,
LPCDS3DLISTENER lpcDS3DL ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2002-12-14 00:20:58 +01:00
TRACE ( " setting: all parameters; dwApply = %ld \n " , dwApply ) ;
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl = * lpcDS3DL ;
2002-12-14 00:20:58 +01:00
if ( dwApply = = DS3D_IMMEDIATE )
{
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = FALSE ;
2003-01-04 02:22:51 +01:00
DSOUND_ChangeListener ( This ) ;
2002-12-14 00:20:58 +01:00
}
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_SetDistanceFactor (
LPDIRECTSOUND3DLISTENER iface ,
D3DVALUE fDistanceFactor ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2002-12-14 00:20:58 +01:00
TRACE ( " setting: Distance Factor = %f; dwApply = %ld \n " , fDistanceFactor , dwApply ) ;
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl . flDistanceFactor = fDistanceFactor ;
2002-12-14 00:20:58 +01:00
if ( dwApply = = DS3D_IMMEDIATE )
{
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = FALSE ;
2003-01-04 02:22:51 +01:00
DSOUND_ChangeListener ( This ) ;
2002-12-14 00:20:58 +01:00
}
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_SetDopplerFactor (
LPDIRECTSOUND3DLISTENER iface ,
D3DVALUE fDopplerFactor ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2002-12-14 00:20:58 +01:00
TRACE ( " setting: Doppler Factor = %f; dwApply = %ld \n " , fDopplerFactor , dwApply ) ;
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl . flDopplerFactor = fDopplerFactor ;
2002-12-14 00:20:58 +01:00
if ( dwApply = = DS3D_IMMEDIATE )
{
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = FALSE ;
2003-01-04 02:22:51 +01:00
DSOUND_ChangeListener ( This ) ;
2002-12-14 00:20:58 +01:00
}
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_SetOrientation (
LPDIRECTSOUND3DLISTENER iface ,
D3DVALUE xFront , D3DVALUE yFront , D3DVALUE zFront ,
D3DVALUE xTop , D3DVALUE yTop , D3DVALUE zTop ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2002-12-14 00:20:58 +01:00
TRACE ( " setting: Front vector = (%f,%f,%f); Top vector = (%f,%f,%f); dwApply = %ld \n " , \
xFront , yFront , zFront , xTop , yTop , zTop , dwApply ) ;
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl . vOrientFront . x = xFront ;
This - > dsound - > device - > ds3dl . vOrientFront . y = yFront ;
This - > dsound - > device - > ds3dl . vOrientFront . z = zFront ;
This - > dsound - > device - > ds3dl . vOrientTop . x = xTop ;
This - > dsound - > device - > ds3dl . vOrientTop . y = yTop ;
This - > dsound - > device - > ds3dl . vOrientTop . z = zTop ;
2002-12-14 00:20:58 +01:00
if ( dwApply = = DS3D_IMMEDIATE )
{
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = FALSE ;
2003-01-04 02:22:51 +01:00
DSOUND_ChangeListener ( This ) ;
2002-12-14 00:20:58 +01:00
}
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_SetPosition (
LPDIRECTSOUND3DLISTENER iface ,
D3DVALUE x , D3DVALUE y , D3DVALUE z ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2002-12-14 00:20:58 +01:00
TRACE ( " setting: Position vector = (%f,%f,%f); dwApply = %ld \n " , x , y , z , dwApply ) ;
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl . vPosition . x = x ;
This - > dsound - > device - > ds3dl . vPosition . y = y ;
This - > dsound - > device - > ds3dl . vPosition . z = z ;
2002-12-14 00:20:58 +01:00
if ( dwApply = = DS3D_IMMEDIATE )
{
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = FALSE ;
2003-01-04 02:22:51 +01:00
DSOUND_ChangeListener ( This ) ;
2002-12-14 00:20:58 +01:00
}
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_SetRolloffFactor (
LPDIRECTSOUND3DLISTENER iface ,
D3DVALUE fRolloffFactor ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2002-12-14 00:20:58 +01:00
TRACE ( " setting: Rolloff Factor = %f; dwApply = %ld \n " , fRolloffFactor , dwApply ) ;
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl . flRolloffFactor = fRolloffFactor ;
2002-12-14 00:20:58 +01:00
if ( dwApply = = DS3D_IMMEDIATE )
{
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = FALSE ;
2003-01-04 02:22:51 +01:00
DSOUND_ChangeListener ( This ) ;
2002-12-14 00:20:58 +01:00
}
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_SetVelocity (
LPDIRECTSOUND3DLISTENER iface ,
D3DVALUE x , D3DVALUE y , D3DVALUE z ,
DWORD dwApply )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2002-12-14 00:20:58 +01:00
TRACE ( " setting: Velocity vector = (%f,%f,%f); dwApply = %ld \n " , x , y , z , dwApply ) ;
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl . vVelocity . x = x ;
This - > dsound - > device - > ds3dl . vVelocity . y = y ;
This - > dsound - > device - > ds3dl . vVelocity . z = z ;
2002-12-14 00:20:58 +01:00
if ( dwApply = = DS3D_IMMEDIATE )
{
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = FALSE ;
2003-01-04 02:22:51 +01:00
DSOUND_ChangeListener ( This ) ;
2002-12-14 00:20:58 +01:00
}
2005-05-31 11:31:37 +02:00
This - > dsound - > device - > ds3dl_need_recalc = TRUE ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
static HRESULT WINAPI IDirectSound3DListenerImpl_CommitDeferredSettings (
LPDIRECTSOUND3DLISTENER iface )
{
2004-09-09 22:17:07 +02:00
IDirectSound3DListenerImpl * This = ( IDirectSound3DListenerImpl * ) iface ;
2003-01-04 02:22:51 +01:00
TRACE ( " \n " ) ;
DSOUND_ChangeListener ( This ) ;
2002-06-13 21:15:06 +02:00
return DS_OK ;
}
2005-06-01 21:57:42 +02:00
static const IDirectSound3DListenerVtbl ds3dlvt =
2002-06-13 21:15:06 +02:00
{
/* 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 ,
} ;
HRESULT WINAPI IDirectSound3DListenerImpl_Create (
PrimaryBufferImpl * This ,
IDirectSound3DListenerImpl * * pdsl )
{
IDirectSound3DListenerImpl * dsl ;
2003-05-22 05:39:13 +02:00
TRACE ( " (%p,%p) \n " , This , pdsl ) ;
2004-08-18 02:30:37 +02:00
dsl = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , sizeof ( * dsl ) ) ;
2003-05-22 05:39:13 +02:00
if ( dsl = = NULL ) {
WARN ( " out of memory \n " ) ;
2003-06-28 00:22:15 +02:00
* pdsl = 0 ;
2003-05-22 05:39:13 +02:00
return DSERR_OUTOFMEMORY ;
}
2002-06-13 21:15:06 +02:00
2003-06-28 00:22:15 +02:00
dsl - > ref = 0 ;
2003-04-10 20:17:34 +02:00
dsl - > lpVtbl = & ds3dlvt ;
2002-06-13 21:15:06 +02:00
2003-06-28 00:22:15 +02:00
dsl - > dsound = This - > dsound ;
2005-05-31 11:31:37 +02:00
dsl - > dsound - > device - > ds3dl . dwSize = sizeof ( DS3DLISTENER ) ;
dsl - > dsound - > device - > ds3dl . vPosition . x = 0.0 ;
dsl - > dsound - > device - > ds3dl . vPosition . y = 0.0 ;
dsl - > dsound - > device - > ds3dl . vPosition . z = 0.0 ;
dsl - > dsound - > device - > ds3dl . vVelocity . x = 0.0 ;
dsl - > dsound - > device - > ds3dl . vVelocity . y = 0.0 ;
dsl - > dsound - > device - > ds3dl . vVelocity . z = 0.0 ;
dsl - > dsound - > device - > ds3dl . vOrientFront . x = 0.0 ;
dsl - > dsound - > device - > ds3dl . vOrientFront . y = 0.0 ;
dsl - > dsound - > device - > ds3dl . vOrientFront . z = 1.0 ;
dsl - > dsound - > device - > ds3dl . vOrientTop . x = 0.0 ;
dsl - > dsound - > device - > ds3dl . vOrientTop . y = 1.0 ;
dsl - > dsound - > device - > ds3dl . vOrientTop . z = 0.0 ;
dsl - > dsound - > device - > ds3dl . flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR ;
dsl - > dsound - > device - > ds3dl . flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR ;
dsl - > dsound - > device - > ds3dl . flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR ;
dsl - > dsound - > device - > ds3dl_need_recalc = TRUE ;
2003-06-28 00:22:15 +02:00
2002-06-13 21:15:06 +02:00
* pdsl = dsl ;
return S_OK ;
}