00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <snx/snxConfig.h>
00043
00044 #include <stdlib.h>
00045 #include <gmtl/Math.h>
00046 #include <gmtl/Vec.h>
00047 #include <gmtl/MatrixOps.h>
00048 #include <gmtl/VecOps.h>
00049 #include <gmtl/Xforms.h>
00050
00051 #include <vpr/Util/Assert.h>
00052 #include <vpr/Util/Debug.h>
00053 #include <snx/Util/Debug.h>
00054 #include <snx/SoundFactory.h>
00055 #include <snx/sonix.h>
00056
00057
00058 vprSingletonImp(sonix);
00059
00060
00061 sonix::~sonix()
00062 {
00063
00064 if (mImplementation != NULL)
00065 {
00066
00067 mImplementation->unbindAll();
00068
00069
00070 mImplementation->shutdownAPI();
00071 delete mImplementation;
00072 mImplementation = NULL;
00073 }
00074 }
00075
00083 void sonix::trigger( const std::string& alias, const int& repeat )
00084 {
00085 this->impl().trigger( alias, repeat );
00086 }
00087
00091 bool sonix::isPlaying( const std::string& alias )
00092 {
00093 return this->impl().isPlaying( alias );
00094 }
00095
00096
00097
00098
00099
00100 void sonix::setRetriggerable( const std::string& alias, bool onOff )
00101 {
00102 this->impl().setRetriggerable( alias, onOff );
00103 }
00104
00108 bool sonix::isRetriggerable( const std::string& alias )
00109 {
00110 return this->impl().isRetriggerable( alias );
00111 }
00112
00117 void sonix::stop( const std::string& alias )
00118 {
00119 this->impl().stop( alias );
00120 }
00121
00125 void sonix::pause( const std::string& alias )
00126 {
00127 this->impl().pause( alias );
00128 }
00129
00133 void sonix::unpause( const std::string& alias )
00134 {
00135 this->impl().unpause( alias );
00136 }
00137
00139 bool sonix::isPaused( const std::string& alias )
00140 {
00141 return this->impl().isPaused( alias );
00142 }
00143
00150 void sonix::setAmbient( const std::string& alias, bool setting )
00151 {
00152 this->impl().setAmbient( alias, setting );
00153 }
00154
00156 bool sonix::isAmbient( const std::string& alias )
00157 {
00158 return this->impl().isAmbient( alias );
00159 }
00160
00166 void sonix::setPitchBend( const std::string& alias, float amount )
00167 {
00168 this->impl().setPitchBend( alias, amount );
00169 }
00170
00172 void sonix::setVolume( const std::string& alias, float amount )
00173 {
00174 this->impl().setVolume( alias, amount );
00175 }
00176
00180 void sonix::setCutoff( const std::string& alias, float amount )
00181 {
00182 this->impl().setCutoff( alias, amount );
00183 }
00184
00189 void sonix::setPosition( const std::string& alias, const float& x, const float& y, const float& z )
00190 {
00191 this->impl().setPosition( alias, x, y, z );
00192 }
00193
00199 void sonix::getPosition( const std::string& alias, float& x, float& y, float& z )
00200 {
00201 this->impl().getPosition( alias, x, y, z );
00202 }
00203
00207 void sonix::setListenerPosition( const gmtl::Matrix44f& mat )
00208 {
00209 this->impl().setListenerPosition( mat );
00210 }
00211
00215 void sonix::getListenerPosition( gmtl::Matrix44f& mat )
00216 {
00217 this->impl().getListenerPosition( mat );
00218 }
00219
00220
00230 void sonix::changeAPI( const std::string& apiName )
00231 {
00232 snx::ISoundImplementation& oldImpl = this->impl();
00233 vprASSERT( &oldImpl != NULL && "this->impl() should ensure that oldImpl is non-NULL" );
00234
00235
00236 snx::SoundFactory::instance()->createImplementation( apiName, mImplementation );
00237
00238 vprDEBUG(snxDBG, vprDBG_CRITICAL_LVL) << "Changing sound API from '"
00239 << oldImpl.name() << "' to '"
00240 << mImplementation->name() << "'\n"
00241 << vprDEBUG_FLUSH;
00242
00243
00244 snx::SoundImplementation* si = dynamic_cast<snx::SoundImplementation*>( mImplementation );
00245 vprASSERT( NULL != si && "implementation is not of type SoundImplementation, cast fails" );
00246 snx::SoundImplementation& old_si = dynamic_cast<snx::SoundImplementation&>( oldImpl );
00247 vprASSERT( NULL != &old_si && "implementation is not of type SoundImplementation, cast fails" );
00248 si->copy( old_si );
00249
00250
00251 oldImpl.unbindAll();
00252
00253
00254 oldImpl.shutdownAPI();
00255
00256
00257 delete &oldImpl;
00258
00259
00260 if(!mImplementation->startAPI())
00261 {
00262 vprDEBUG(snxDBG, vprDBG_CRITICAL_LVL)
00263 << clrOutBOLD(clrRED, "ERROR:") << " Failed to start new API--"
00264 << "changing back to Stub\n" << vprDEBUG_FLUSH;
00265 changeAPI("stub");
00266 }
00267
00268
00269 mImplementation->bindAll();
00270 }
00271
00272
00273
00274
00275 void sonix::configure( const snx::SoundAPIInfo& sai )
00276 {
00277 this->impl().configure( sai );
00278 }
00279
00288 void sonix::configure( const std::string& alias, const snx::SoundInfo& description )
00289 {
00290 this->impl().configure( alias, description );
00291 }
00292
00297 void sonix::remove( const std::string alias )
00298 {
00299 this->impl().remove( alias );
00300 }
00301
00306 void sonix::step( const float& timeElapsed )
00307 {
00308 this->impl().step( timeElapsed );
00309 }
00310
00311 snx::ISoundImplementation& sonix::impl()
00312 {
00313 if (mImplementation == NULL)
00314 {
00315 snx::SoundFactory::instance()->createImplementation( "stub", mImplementation );
00316 mImplementation->startAPI();
00317 mImplementation->bindAll();
00318 }
00319 return *mImplementation;
00320 }