00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stddsound.h"
00027
00028 #include "listener_dsound.h"
00029 #include "sound_driver_dsound.h"
00030
00031
00032 using namespace NLMISC;
00033
00034
00035 namespace NLSOUND {
00036
00037
00038
00039 CListenerDSound *CListenerDSound::_Instance = NULL;
00040
00041
00042
00043
00044
00045 CListenerDSound::CListenerDSound(LPDIRECTSOUND3DLISTENER dsoundListener)
00046 {
00047 _Pos = CVector::Null;
00048 if ( _Instance == NULL )
00049 {
00050 _Instance = this;
00051 _Listener = dsoundListener;
00052
00053 setRolloffFactor(DS3D_MINROLLOFFFACTOR);
00054 }
00055 else
00056 {
00057
00058 }
00059 }
00060
00061
00062 CListenerDSound::~CListenerDSound()
00063 {
00064 nldebug("Destroying DirectSound listener");
00065
00066 release();
00067 _Instance = NULL;
00068 }
00069
00070
00071
00072
00073
00074 void CListenerDSound::release()
00075 {
00076 if (_Listener != NULL)
00077 {
00078 _Listener->Release();
00079 _Listener = NULL;
00080 }
00081 }
00082
00083
00084
00085
00086
00087 void CListenerDSound::setPos( const NLMISC::CVector& pos )
00088 {
00089
00090 _Pos = pos;
00091
00092 if (_Listener != NULL)
00093 {
00094 if (FAILED(_Listener->SetPosition(pos.x, pos.z, pos.y, DS3D_DEFERRED)))
00095 {
00096 nlwarning("SetPosition failed");
00097 }
00098 else
00099 {
00100
00101 }
00102 }
00103 }
00104
00105
00109 const NLMISC::CVector &CListenerDSound::getPos() const
00110 {
00111 return _Pos;
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 }
00133
00134
00135
00136
00137
00138 void CListenerDSound::setVelocity( const NLMISC::CVector& vel )
00139 {
00140 if (_Listener != NULL)
00141 {
00142 if (FAILED(_Listener->SetVelocity(vel.x, vel.z, vel.y, DS3D_DEFERRED)))
00143 {
00144 nlwarning("SetVelocity failed");
00145 }
00146 }
00147 }
00148
00149
00150
00151
00152
00153 void CListenerDSound::getVelocity( NLMISC::CVector& vel ) const
00154 {
00155 if (_Listener != NULL)
00156 {
00157 D3DVECTOR v;
00158 if (FAILED(_Listener->GetVelocity(&v)))
00159 {
00160 nlwarning("GetVelocity failed");
00161 vel.set(0.0f, 0.0f, 0.0f);
00162 }
00163 else
00164 {
00165 vel.set(v.x, v.z, v.y);
00166 }
00167 }
00168 else
00169 {
00170 vel.set(0, 0, 0);
00171 }
00172 }
00173
00174
00175
00176
00177
00178 void CListenerDSound::setOrientation( const NLMISC::CVector& front, const NLMISC::CVector& up )
00179 {
00180 if (_Listener != NULL)
00181 {
00182 if (FAILED(_Listener->SetOrientation(front.x, front.z, front.y, up.x, up.z, up.y, DS3D_DEFERRED)))
00183 {
00184 nlwarning("SetOrientation failed");
00185 }
00186 else
00187 {
00188
00189 }
00190 }
00191 }
00192
00193
00194
00195
00196
00197 void CListenerDSound::getOrientation( NLMISC::CVector& front, NLMISC::CVector& up ) const
00198 {
00199 if (_Listener != NULL)
00200 {
00201 D3DVECTOR vfront, vtop;
00202 if (FAILED(_Listener->GetOrientation(&vfront, &vtop)))
00203 {
00204 nlwarning("GetOrientation failed");
00205 front.set(0.0f, 0.0f, 1.0f);
00206 up.set(0.0f, 1.0f, 0.0f);
00207 }
00208 else
00209 {
00210 front.set(vfront.x, vfront.z, vfront.y);
00211 up.set(vtop.x, vtop.z, vtop.y);
00212 }
00213 }
00214 else
00215 {
00216 front.set(0, 0, 1);
00217 up.set(0, 1, 0);
00218 }
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228 void CListenerDSound::setGain( float gain )
00229 {
00230 CSoundDriverDSound::instance()->setGain(gain);
00231 }
00232
00233
00234
00235
00236
00237 float CListenerDSound::getGain() const
00238 {
00239 return CSoundDriverDSound::instance()->getGain();
00240 }
00241
00242
00243
00244
00245
00246 void CListenerDSound::setDopplerFactor( float f )
00247 {
00248 if (_Listener != NULL)
00249 {
00250 if (f > DS3D_MAXDOPPLERFACTOR)
00251 {
00252 f = DS3D_MAXDOPPLERFACTOR;
00253 }
00254 else if (f < DS3D_MINDOPPLERFACTOR)
00255 {
00256 f = DS3D_MINDOPPLERFACTOR;
00257 }
00258
00259 if (FAILED(_Listener->SetDopplerFactor(f, DS3D_DEFERRED)))
00260 {
00261 nlwarning("SetDopplerFactor failed");
00262 }
00263 }
00264 }
00265
00266
00267
00268
00269
00270 void CListenerDSound::setRolloffFactor( float f )
00271 {
00272 if (_Listener != NULL)
00273 {
00274
00275
00276
00277
00278 f = DS3D_MINROLLOFFFACTOR;
00279
00280
00281 if (FAILED(_Listener->SetRolloffFactor(f, DS3D_DEFERRED)))
00282 {
00283 nlwarning("SetRolloffFactor failed");
00284 }
00285 }
00286 }
00287
00288
00289 float CListenerDSound::getRolloffFactor()
00290 {
00291 if (_Listener != NULL)
00292 {
00293 float f;
00294 _Listener->GetRolloffFactor(&f);
00295 return f;
00296 }
00297 else
00298 {
00299 return 1.0;
00300 }
00301 }
00302
00303
00304 void CListenerDSound::commit3DChanges()
00305 {
00306 if (_Listener != NULL)
00307 {
00308 _Listener->CommitDeferredSettings();
00309 }
00310 }
00311
00312
00313
00314
00315
00316 void CListenerDSound::setEnvironment( uint env, float size )
00317 {
00318 #ifdef EAX_AVAILABLE
00319 if ( EAXSetProp != NULL )
00320 {
00321 EAXSetProp( &DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ENVIRONMENT, 0, &env, sizeof(unsigned long) );
00322 EAXSetProp( &DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE, 0, &size, sizeof(float) );
00323 }
00324 #endif
00325 }
00326
00327
00328
00329
00330
00331 void CListenerDSound::setEAXProperty( uint prop, void *value, uint valuesize )
00332 {
00333 #ifdef EAX_AVAILABLE
00334 if ( EAXSetProp != NULL )
00335 {
00336 EAXSetProp( &DSPROPSETID_EAX_ListenerProperties, prop, 0, value, valuesize );
00337 }
00338 #endif
00339 }
00340
00341
00342 }