[Orxonox-commit 1665] r6383 - in code/branches/presentation2/src: modules/weapons/projectiles orxonox/sound

rgrieder at orxonox.net rgrieder at orxonox.net
Sat Dec 19 22:14:08 CET 2009


Author: rgrieder
Date: 2009-12-19 22:14:08 +0100 (Sat, 19 Dec 2009)
New Revision: 6383

Modified:
   code/branches/presentation2/src/modules/weapons/projectiles/Rocket.cc
   code/branches/presentation2/src/orxonox/sound/BaseSound.cc
   code/branches/presentation2/src/orxonox/sound/SoundManager.cc
   code/branches/presentation2/src/orxonox/sound/SoundManager.h
Log:
Fixed a major sound issue: The state gets reset to 'Stopped' when the sound has finished playing (unless in loop mode of course).

Modified: code/branches/presentation2/src/modules/weapons/projectiles/Rocket.cc
===================================================================
--- code/branches/presentation2/src/modules/weapons/projectiles/Rocket.cc	2009-12-18 23:18:41 UTC (rev 6382)
+++ code/branches/presentation2/src/modules/weapons/projectiles/Rocket.cc	2009-12-19 21:14:08 UTC (rev 6383)
@@ -114,21 +114,13 @@
         if(this->isInitialized())
         {
             if (GameMode::isMaster() && this->player_)
-            {
                 this->player_->stopTemporaryControl();
-            }
+
             if ( this->defSndWpnEngine_ )
-            {
-                if ( this->defSndWpnEngine_->isPlaying() )
-                    this->defSndWpnEngine_->stop();
                 this->defSndWpnEngine_->destroy();
-            }
+
             if ( this->defSndWpnLaunch_ )
-            {
-                if ( this->defSndWpnLaunch_->isPlaying())
-                    this->defSndWpnLaunch_->stop();
                 this->defSndWpnLaunch_->destroy();
-            }
         }
     }
 

Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.cc	2009-12-18 23:18:41 UTC (rev 6382)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.cc	2009-12-19 21:14:08 UTC (rev 6383)
@@ -76,7 +76,7 @@
         {
             if (!alIsSource(this->audioSource_))
             {
-                this->audioSource_ = SoundManager::getInstance().getSoundSource();
+                this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
                 if (!alIsSource(this->audioSource_))
                     return;
                 this->initialiseSource();

Modified: code/branches/presentation2/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.cc	2009-12-18 23:18:41 UTC (rev 6382)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.cc	2009-12-19 21:14:08 UTC (rev 6383)
@@ -144,7 +144,7 @@
         ALuint source;
         alGenSources(1, &source);
         if (!alGetError() && alIsSource(source))
-            this->soundSources_.push_back(source);
+            this->availableSoundSources_.push_back(source);
         else
             ThrowException(InitialisationFailed, "Sound Error: Could not even create a single source");
         // Get the rest of the sources
@@ -152,7 +152,7 @@
         unsigned int count = 1;
         while (alIsSource(source) && !alGetError() && count <= this->maxSources_)
         {
-            this->soundSources_.push_back(source);
+            this->availableSoundSources_.push_back(source);
             alGenSources(1, &source);
             ++count;
         }
@@ -194,6 +194,18 @@
     void SoundManager::preUpdate(const Clock& time)
     {
         this->processCrossFading(time.getDeltaTime());
+
+        // Check whether a sound object has stopped playing
+        for (unsigned int i = 0; i < this->usedSoundSources_.size(); ++i)
+        {
+            ALint state;
+            alGetSourcei(this->usedSoundSources_[i].first, AL_SOURCE_STATE, &state);
+            if (state == AL_STOPPED)
+            {
+                this->usedSoundSources_[i].second->stop();
+                --i;
+            }
+        }
     }
 
     void SoundManager::setConfigValues()
@@ -535,12 +547,13 @@
         }
     }
 
-    ALuint SoundManager::getSoundSource()
+    ALuint SoundManager::getSoundSource(BaseSound* object)
     {
-        if (!this->soundSources_.empty())
+        if (!this->availableSoundSources_.empty())
         {
-            ALuint source = this->soundSources_.back();
-            this->soundSources_.pop_back();
+            ALuint source = this->availableSoundSources_.back();
+            this->availableSoundSources_.pop_back();
+            this->usedSoundSources_.push_back(std::make_pair(source, object));
             return source;
         }
         else
@@ -555,9 +568,18 @@
     void SoundManager::releaseSoundSource(ALuint source)
     {
 #ifndef NDEBUG
-        for (std::vector<ALuint>::const_iterator it = this->soundSources_.begin(); it != this->soundSources_.end(); ++it)
+        for (std::vector<ALuint>::const_iterator it = this->availableSoundSources_.begin(); it != this->availableSoundSources_.end(); ++it)
             assert((*it) != source);
 #endif
-        this->soundSources_.push_back(source);
+        this->availableSoundSources_.push_back(source);
+        for (std::vector<std::pair<ALuint, BaseSound*> >::iterator it = this->usedSoundSources_.begin();
+            it != this->usedSoundSources_.end(); ++it)
+        {
+            if (it->first == source)
+            {
+                this->usedSoundSources_.erase(it);
+                break;
+            }
+        }
     }
 }

Modified: code/branches/presentation2/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.h	2009-12-18 23:18:41 UTC (rev 6382)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.h	2009-12-19 21:14:08 UTC (rev 6383)
@@ -101,7 +101,7 @@
         shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename);
         void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer);
 
-        ALuint getSoundSource();
+        ALuint getSoundSource(BaseSound* object);
         void releaseSoundSource(ALuint source);
 
         static std::string getALErrorString(ALenum error);
@@ -146,7 +146,8 @@
 
         // Sound source related
         unsigned int maxSources_;
-        std::vector<ALuint> soundSources_;
+        std::vector<ALuint> availableSoundSources_;
+        std::vector<std::pair<ALuint, BaseSound*> > usedSoundSources_;
 
         static SoundManager* singletonPtr_s;
     }; // tolua_export




More information about the Orxonox-commit mailing list