00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdopenal.h"
00027
00028 #include "listener_al.h"
00029
00030
00031 using namespace NLMISC;
00032
00033
00034 namespace NLSOUND {
00035
00036
00037
00038 CListenerAL *CListenerAL::_Instance = NULL;
00039
00040
00041
00042
00043
00044 CListenerAL::CListenerAL() : IListener()
00045 {
00046 if ( _Instance == NULL )
00047 {
00048 _Instance = this;
00049 }
00050 else
00051 {
00052 nlerror( "Listener singleton instanciated twice" );
00053 }
00054 }
00055
00056
00057
00058
00059
00060 void CListenerAL::setPos( const NLMISC::CVector& pos )
00061 {
00062 _Pos = pos;
00063
00064 alListener3f( AL_POSITION, pos.x, pos.z, -pos.y );
00065 TestALError();
00066 }
00067
00068
00072 const NLMISC::CVector &CListenerAL::getPos() const
00073 {
00074 return _Pos;
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 }
00093
00094
00095
00096
00097
00098 void CListenerAL::setVelocity( const NLMISC::CVector& vel )
00099 {
00100
00101 alListener3f( AL_VELOCITY, vel.x, vel.z, -vel.y );
00102 TestALError();
00103 }
00104
00105
00106
00107
00108
00109 void CListenerAL::getVelocity( NLMISC::CVector& vel ) const
00110 {
00111 #ifdef NL_OS_WINDOWS
00112
00113 float glposz;
00114 alGetListener3f( AL_VELOCITY, &vel.x, &vel.z, &glposz );
00115 vel.y = - glposz;
00116 #else
00117 float velarray [3];
00118 alGetListenerfv( AL_VELOCITY, velarray );
00119
00120 vel.set( velarray[0], -velarray[2], velarray[1] );
00121 #endif
00122 TestALError();
00123 }
00124
00125
00126
00127
00128
00129 void CListenerAL::setOrientation( const NLMISC::CVector& front, const NLMISC::CVector& up )
00130 {
00131
00132 ALfloat v[6];
00133
00134 v[0] = front.x;
00135 v[1] = front.z;
00136 v[2] = -front.y;
00137 v[3] = up.x;
00138 v[4] = up.z;
00139 v[5] = -up.y;
00140 alListenerfv( AL_ORIENTATION, v );
00141 TestALError();
00142 }
00143
00144
00145
00146
00147
00148 void CListenerAL::getOrientation( NLMISC::CVector& front, NLMISC::CVector& up ) const
00149 {
00150
00151 ALfloat v[6];
00152 alGetListenerfv( AL_ORIENTATION, v );
00153 TestALError();
00154
00155 front.set( v[0], -v[2], v[1] );
00156 up.set( v[3], -v[5], v[4] );
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166 void CListenerAL::setGain( float gain )
00167 {
00168 alListenerf( AL_GAIN, gain );
00169 TestALError();
00170 }
00171
00172
00173
00174
00175
00176 float CListenerAL::getGain() const
00177 {
00178 ALfloat gain;
00179 #ifdef NL_OS_WINDOWS
00180 alGetListenerf( AL_GAIN, &gain );
00181 #else
00182 alGetListenerfv( AL_GAIN, &gain );
00183 #endif
00184 TestALError();
00185 return gain;
00186 }
00187
00188
00189
00190
00191
00192 void CListenerAL::setDopplerFactor( float f )
00193 {
00194 alDopplerFactor( f );
00195 TestALError();
00196 }
00197
00198
00199
00200
00201
00202 void CListenerAL::setRolloffFactor( float f )
00203 {
00204 nlassert( CSoundDriverAL::instance() != NULL );
00205 CSoundDriverAL::instance()->applyRolloffFactor( f );
00206 }
00207
00208
00209
00210
00211
00212 void CListenerAL::setEnvironment( uint env, float size )
00213 {
00214 #ifdef EAX_AVAILABLE
00215 if ( EAXSetProp != NULL )
00216 {
00217 EAXSetProp( &DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ENVIRONMENT, 0, &env, sizeof(unsigned long) );
00218 EAXSetProp( &DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE, 0, &size, sizeof(float) );
00219 }
00220 #endif
00221 }
00222
00223
00224
00225
00226
00227 void CListenerAL::setEAXProperty( uint prop, void *value, uint valuesize )
00228 {
00229 #ifdef EAX_AVAILABLE
00230 if ( EAXSetProp != NULL )
00231 {
00232 EAXSetProp( &DSPROPSETID_EAX_ListenerProperties, prop, 0, value, valuesize );
00233 }
00234 #endif
00235 }
00236
00237
00238 }