]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/soundmgr_openal.cxx
Remove the dependency on boost for STANDALONE mode
[simgear.git] / simgear / sound / soundmgr_openal.cxx
index b1091aa59dcde6231ec2522346f5879a79d31137..24992a742560f894d36397c8cb8f58ac0b2f7fdc 100644 (file)
@@ -45,7 +45,6 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/sg_path.hxx>
 
-using std::string;
 using std::vector;
 
 
@@ -129,13 +128,13 @@ SGSoundMgr::SGSoundMgr() :
     _changed(true),
     _volume(0.0),
     _offset_pos(SGVec3d::zeros()),
-    _geod_pos(SGGeod::fromCart(SGVec3d::zeros())),
     _velocity(SGVec3d::zeros()),
     _bad_doppler(false),
     _renderer("unknown"),
     _vendor("unknown")
 {
     d.reset(new SoundManagerPrivate);
+    d->_base_pos = SGVec3d::fromGeod(_geod_pos);
 }
 
 // destructor
@@ -148,8 +147,9 @@ SGSoundMgr::~SGSoundMgr() {
 }
 
 // initialize the sound manager
-void SGSoundMgr::init() {
-
+void SGSoundMgr::init()
+{
+#ifdef ENABLE_SOUND
     if (is_working())
     {
         SG_LOG( SG_SOUND, SG_ALERT, "Oops, OpenAL sound manager is already initialized." );
@@ -239,7 +239,6 @@ void SGSoundMgr::init() {
 
     if (_vendor == "Creative Labs Inc.") {
        _bad_doppler = true;
-
     } else if (_vendor == "OpenAL Community" && _renderer == "OpenAL Soft") {
        _bad_doppler = true;
     }
@@ -247,6 +246,7 @@ void SGSoundMgr::init() {
     if (d->_free_sources.empty()) {
         SG_LOG(SG_SOUND, SG_ALERT, "Unable to grab any OpenAL sources!");
     }
+#endif
 }
 
 void SGSoundMgr::reinit()
@@ -265,7 +265,9 @@ void SGSoundMgr::reinit()
         resume();
 }
 
-void SGSoundMgr::activate() {
+void SGSoundMgr::activate()
+{
+#ifdef ENABLE_SOUND
     if ( is_working() ) {
         _active = true;
                 
@@ -276,11 +278,13 @@ void SGSoundMgr::activate() {
             sgrp->activate();
         }
     }
+#endif
 }
 
 // stop the sound manager
-void SGSoundMgr::stop() {
-
+void SGSoundMgr::stop()
+{
+#ifdef ENABLE_SOUND
     // first stop all sample groups
     sample_group_map_iterator sample_grp_current = d->_sample_groups.begin();
     sample_group_map_iterator sample_grp_end = d->_sample_groups.end();
@@ -319,9 +323,12 @@ void SGSoundMgr::stop() {
         _renderer = "unknown";
         _vendor = "unknown";
     }
+#endif
 }
 
-void SGSoundMgr::suspend() {
+void SGSoundMgr::suspend()
+{
+#ifdef ENABLE_SOUND
     if (is_working()) {
         sample_group_map_iterator sample_grp_current = d->_sample_groups.begin();
         sample_group_map_iterator sample_grp_end = d->_sample_groups.end();
@@ -331,9 +338,12 @@ void SGSoundMgr::suspend() {
         }
         _active = false;
     }
+#endif
 }
 
-void SGSoundMgr::resume() {
+void SGSoundMgr::resume()
+{
+#ifdef ENABLE_SOUND
     if (is_working()) {
         sample_group_map_iterator sample_grp_current = d->_sample_groups.begin();
         sample_group_map_iterator sample_grp_end = d->_sample_groups.end();
@@ -343,10 +353,13 @@ void SGSoundMgr::resume() {
         }
         _active = true;
     }
+#endif
 }
 
 // run the audio scheduler
-void SGSoundMgr::update( double dt ) {
+void SGSoundMgr::update( double dt )
+{
+#ifdef ENABLE_SOUND
     if (_active) {
         alcSuspendContext(d->_context);
 
@@ -389,10 +402,11 @@ if (isNaN(_velocity.data())) printf("NaN in listener velocity\n");
 
         alcProcessContext(d->_context);
     }
+#endif
 }
 
 // add a sample group, return true if successful
-bool SGSoundMgr::add( SGSampleGroup *sgrp, const string& refname )
+bool SGSoundMgr::add( SGSampleGroup *sgrp, const std::string& refname )
 {
     sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname );
     if ( sample_grp_it != d->_sample_groups.end() ) {
@@ -408,7 +422,7 @@ bool SGSoundMgr::add( SGSampleGroup *sgrp, const string& refname )
 
 
 // remove a sound effect, return true if successful
-bool SGSoundMgr::remove( const string &refname )
+bool SGSoundMgr::remove( const std::string &refname )
 {
     sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname );
     if ( sample_grp_it == d->_sample_groups.end() ) {
@@ -423,7 +437,7 @@ bool SGSoundMgr::remove( const string &refname )
 
 
 // return true of the specified sound exists in the sound manager system
-bool SGSoundMgr::exists( const string &refname ) {
+bool SGSoundMgr::exists( const std::string &refname ) {
     sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname );
     return ( sample_grp_it != d->_sample_groups.end() );
 }
@@ -431,7 +445,7 @@ bool SGSoundMgr::exists( const string &refname ) {
 
 // return a pointer to the SGSampleGroup if the specified sound exists
 // in the sound manager system, otherwise return NULL
-SGSampleGroup *SGSoundMgr::find( const string &refname, bool create ) {
+SGSampleGroup *SGSoundMgr::find( const std::string &refname, bool create ) {
     sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname );
     if ( sample_grp_it == d->_sample_groups.end() ) {
         // sample group was not found.
@@ -486,6 +500,7 @@ void SGSoundMgr::release_source( unsigned int source )
 
     it = std::find(d->_sources_in_use.begin(), d->_sources_in_use.end(), source);
     if ( it != d->_sources_in_use.end() ) {
+  #ifdef ENABLE_SOUND
         ALint result;
 
         alGetSourcei( source, AL_SOURCE_STATE, &result );
@@ -495,6 +510,7 @@ void SGSoundMgr::release_source( unsigned int source )
 
         alSourcei( source, AL_BUFFER, 0 );     // detach the associated buffer
         testForALError("release_source");
+  #endif
         d->_free_sources.push_back( source );
         d->_sources_in_use.erase( it );
     }
@@ -503,10 +519,10 @@ void SGSoundMgr::release_source( unsigned int source )
 unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
 {
     ALuint buffer = NO_BUFFER;
-
+#ifdef ENABLE_SOUND
     if ( !sample->is_valid_buffer() ) {
         // sample was not yet loaded or removed again
-        string sample_name = sample->get_sample_name();
+        std::string sample_name = sample->get_sample_name();
         void *sample_data = NULL;
 
         // see if the sample name is already cached
@@ -562,7 +578,7 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
     else {
         buffer = sample->get_buffer();
     }
-
+#endif
     return buffer;
 }
 
@@ -570,7 +586,7 @@ void SGSoundMgr::release_buffer(SGSoundSample *sample)
 {
     if ( !sample->is_queue() )
     {
-        string sample_name = sample->get_sample_name();
+        std::string sample_name = sample->get_sample_name();
         buffer_map_iterator buffer_it = d->_buffers.find( sample_name );
         if ( buffer_it == d->_buffers.end() ) {
             // buffer was not found
@@ -580,16 +596,21 @@ void SGSoundMgr::release_buffer(SGSoundSample *sample)
         sample->no_valid_buffer();
         buffer_it->second.refctr--;
         if (buffer_it->second.refctr == 0) {
+#ifdef ENABLE_SOUND
             ALuint buffer = buffer_it->second.id;
             alDeleteBuffers(1, &buffer);
+#endif
             d->_buffers.erase( buffer_it );
             testForALError("release buffer");
         }
     }
 }
 
-bool SGSoundMgr::load(const string &samplepath, void **dbuf, int *fmt,
-                                          size_t *sz, int *frq )
+bool SGSoundMgr::load( const std::string &samplepath,
+                       void **dbuf,
+                       int *fmt,
+                       size_t *sz,
+                       int *frq )
 {
     if ( !is_working() )
         return false;
@@ -623,6 +644,7 @@ bool SGSoundMgr::load(const string &samplepath, void **dbuf, int *fmt,
 vector<const char*> SGSoundMgr::get_available_devices()
 {
     vector<const char*> devices;
+#ifdef ENABLE_SOUND
     const ALCchar *s;
 
     if (alcIsExtensionPresent(NULL, "ALC_enumerate_all_EXT") == AL_TRUE) {
@@ -642,12 +664,12 @@ vector<const char*> SGSoundMgr::get_available_devices()
         }
         devices.push_back(ptr);
     }
-
+#endif
     return devices;
 }
 
 
-bool SGSoundMgr::testForError(void *p, string s)
+bool SGSoundMgr::testForError(void *p, std::string s)
 {
    if (p == NULL) {
       SG_LOG( SG_SOUND, SG_ALERT, "Error: " << s);
@@ -657,19 +679,22 @@ bool SGSoundMgr::testForError(void *p, string s)
 }
 
 
-bool SGSoundMgr::testForALError(string s)
+bool SGSoundMgr::testForALError(std::string s)
 {
+#ifdef ENABLE_SOUND
     ALenum error = alGetError();
     if (error != AL_NO_ERROR)  {
        SG_LOG( SG_SOUND, SG_ALERT, "AL Error (sound manager): "
                                       << alGetString(error) << " at " << s);
        return true;
     }
+#endif
     return false;
 }
 
-bool SGSoundMgr::testForALCError(string s)
+bool SGSoundMgr::testForALCError(std::string s)
 {
+#ifdef ENABLE_SOUND
     ALCenum error;
     error = alcGetError(d->_device);
     if (error != ALC_NO_ERROR) {
@@ -678,6 +703,7 @@ bool SGSoundMgr::testForALCError(string s)
                                        << s);
         return true;
     }
+#endif
     return false;
 }