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
00043
00044 #ifndef SNXSOUNDIMPLEMENTATION_H
00045 #define SNXSOUNDIMPLEMENTATION_H
00046
00047 #include <snx/snxConfig.h>
00048
00049 #include <assert.h>
00050 #include <string>
00051 #include <map>
00052 #include <boost/concept_check.hpp>
00053 #include <gmtl/Matrix.h>
00054
00055 #include <snx/SoundInfo.h>
00056 #include <snx/SoundAPIInfo.h>
00057 #include <snx/ISoundImplementation.h>
00058
00059 namespace snx
00060 {
00061
00062 class SNX_CLASS_API SoundImplementation : public ISoundImplementation
00063 {
00064 public:
00068 SoundImplementation() : ISoundImplementation(),
00069 mName( "unknown" ),
00070 mSoundAPIInfo(),
00071 mSounds(),
00072 mListenerPos()
00073 {
00074 }
00075
00079 virtual void clone( ISoundImplementation* &newCopy ) = 0;
00080
00084 virtual ~SoundImplementation()
00085 {
00086
00087 this->shutdownAPI();
00088 }
00089
00094 void copy( const SoundImplementation& si );
00095
00096 public:
00097
00104 virtual void trigger( const std::string & alias, const int & repeat = 1 )
00105 {
00106 assert( this->isStarted() == true && "must call startAPI prior to this function" );
00107
00108 this->lookup( alias ).repeat = repeat;
00109 this->lookup( alias ).repeatCountdown = repeat;
00110 }
00111
00115 virtual bool isPlaying( const std::string& alias )
00116 {
00117 boost::ignore_unused_variable_warning(alias);
00118 return false;
00119 }
00120
00126 virtual void setRetriggerable( const std::string& alias, bool onOff )
00127 {
00128 this->lookup( alias ).retriggerable = onOff;
00129 }
00130
00134 virtual bool isRetriggerable( const std::string& alias )
00135 {
00136 return bool( this->lookup( alias ).retriggerable == true );
00137 }
00138
00143 virtual void stop( const std::string& alias )
00144 {
00145 assert( this->isStarted() == true && "must call startAPI prior to this function" );
00146 this->lookup( alias ).repeatCountdown = 0;
00147 }
00148
00152 virtual void pause( const std::string& alias )
00153 {
00154 this->stop( alias );
00155 }
00156
00160 virtual void unpause( const std::string& alias )
00161 {
00162 this->trigger( alias, this->lookup( alias ).repeat );
00163 }
00164
00166 virtual bool isPaused( const std::string& alias )
00167 {
00168 boost::ignore_unused_variable_warning(alias);
00169 return false;
00170 }
00171
00178 virtual void setAmbient( const std::string& alias, bool ambient = false )
00179 {
00180 this->lookup( alias ).ambient = ambient;
00181 }
00182
00187 virtual bool isAmbient( const std::string& alias )
00188 {
00189 return this->lookup( alias ).ambient;
00190 }
00191
00193 virtual void setPitchBend( const std::string& alias, float amount )
00194 {
00195 this->lookup( alias ).pitchbend = amount;
00196 }
00197
00199 virtual void setVolume( const std::string& alias, float amount )
00200 {
00201 this->lookup( alias ).volume = amount;
00202 }
00203
00207 virtual void setCutoff( const std::string& alias, float amount )
00208 {
00209 this->lookup( alias ).cutoff = amount;
00210 }
00211
00215 virtual void setPosition( const std::string& alias, float x, float y, float z )
00216 {
00217 assert( this->isStarted() == true && "must call startAPI prior to this function" );
00218 this->lookup( alias ).position[0] = x;
00219 this->lookup( alias ).position[1] = y;
00220 this->lookup( alias ).position[2] = z;
00221 }
00222
00228 virtual void getPosition( const std::string& alias, float& x, float& y, float& z )
00229 {
00230 assert( this->isStarted() == true && "must call startAPI prior to this function" );
00231
00232 x = this->lookup( alias ).position[0];
00233 y = this->lookup( alias ).position[1];
00234 z = this->lookup( alias ).position[2];
00235 }
00236
00240 virtual void setListenerPosition( const gmtl::Matrix44f& mat )
00241 {
00242 assert( this->isStarted() == true && "must call startAPI prior to this function" );
00243 mListenerPos = mat;
00244 }
00245
00249 virtual void getListenerPosition( gmtl::Matrix44f& mat )
00250 {
00251 assert( this->isStarted() == true && "must call startAPI prior to this function" );
00252 mat = mListenerPos;
00253 }
00254
00261 virtual int startAPI() = 0;
00262
00267 virtual bool isStarted() const = 0;
00268
00274 virtual void shutdownAPI() {}
00275
00276
00277
00278
00279 virtual void configure( const snx::SoundAPIInfo& sai )
00280 {
00281 mSoundAPIInfo = sai;
00282 }
00283
00292 virtual void configure( const std::string& alias, const snx::SoundInfo& description );
00293
00298 virtual void remove(const std::string& alias);
00299
00304 virtual void step( const float& timeElapsed )
00305 {
00306 boost::ignore_unused_variable_warning(timeElapsed);
00307 }
00308
00313 virtual void clear()
00314 {
00315 this->unbindAll();
00316 }
00317
00322 virtual void bindAll();
00323
00328 virtual void unbindAll();
00329
00334 virtual void bind( const std::string& alias ) = 0;
00335
00340 virtual void unbind( const std::string& alias ) = 0;
00341
00342 snx::SoundInfo& lookup( const std::string& alias )
00343 {
00344 return mSounds[alias];
00345 }
00346
00347 void setName( const std::string& name )
00348 {
00349 mName = name;
00350 }
00351
00352 std::string& name()
00353 {
00354 return mName;
00355 }
00356
00357 protected:
00358
00359
00360
00361
00362 std::string mName;
00363
00364 snx::SoundAPIInfo mSoundAPIInfo;
00365 std::map<std::string, snx::SoundInfo> mSounds;
00366
00367
00368
00369 gmtl::Matrix44f mListenerPos;
00370 };
00371
00372 }
00373
00374 #endif //SNXSOUNDIMPLEMENTATION_H