[Orxonox-commit 1622] r6340 - code/branches/presentation2/src/orxonox/sound

rgrieder at orxonox.net rgrieder at orxonox.net
Sun Dec 13 17:39:23 CET 2009


Author: rgrieder
Date: 2009-12-13 17:39:22 +0100 (Sun, 13 Dec 2009)
New Revision: 6340

Modified:
   code/branches/presentation2/src/orxonox/sound/BaseSound.cc
   code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
Log:
Fixed bug: Ambient sounds were sometimes not played at all (caused by the source management changes).
And removed some debug output.

Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.cc	2009-12-13 16:35:59 UTC (rev 6339)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.cc	2009-12-13 16:39:22 UTC (rev 6340)
@@ -223,15 +223,18 @@
         }
 
         this->source_ = source;
+        // Don't load ""
         if (source_.empty())
             return;
 
+        // Get new sound buffer
         this->soundBuffer_ = SoundManager::getInstance().getSoundBuffer(this->source_);
         if (this->soundBuffer_ == NULL)
             return;
 
-        if (alIsSource(this->audioSource_))
+        if (alIsSource(this->audioSource_)) // already playing or paused
         {
+            // Set new buffer 
             alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
             if (ALuint error = alGetError())
             {
@@ -239,14 +242,24 @@
                 return;
             }
 
+            // Sound was already playing or paused because there was a source acquired
+            assert(this->isPlaying() || this->isPaused());
+            alSourcePlay(this->audioSource_);
+            if (int error = alGetError())
+                COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
+            if (this->isPaused())
+                alSourcePause(this->audioSource_);
+        }
+        else // No source acquired so far, but might be set to playing or paused
+        {
+            State state = this->state_; // save
             if (this->isPlaying() || this->isPaused())
+                BaseSound::play();
+            if (state == Paused)
             {
-                alSourcePlay(this->audioSource_);
-                if (int error = alGetError())
-                    COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
+                this->state_ = Paused;
+                BaseSound::pause();
             }
-            if (this->isPaused())
-                alSourcePause(this->audioSource_);
         }
     }
     

Modified: code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc	2009-12-13 16:35:59 UTC (rev 6339)
+++ code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc	2009-12-13 16:39:22 UTC (rev 6340)
@@ -32,8 +32,6 @@
 #include <AL/alut.h>
 #include <vorbis/vorbisfile.h>
 
-#include "util/Clock.h"
-#include "core/Game.h"
 #include "util/Exception.h"
 #include "util/StringUtils.h"
 #include "core/Resource.h"
@@ -62,11 +60,8 @@
         std::string extension(this->filename_.substr(this->filename_.find_last_of('.') + 1));
         if (getLowercase(extension) == "ogg")
         {
-            int before = Game::getInstance().getGameClock().getRealMicroseconds();
             // Try ogg loader
             this->loadOgg(fileInfo, dataStream);
-            int after = Game::getInstance().getGameClock().getRealMicroseconds();
-            COUT(0) << filename << ": " << (after - before) << std::endl;
         }
         else
         {




More information about the Orxonox-commit mailing list