[Orxonox-commit 1542] r6260 - code/branches/presentation2/src/orxonox/sound

rgrieder at orxonox.net rgrieder at orxonox.net
Sun Dec 6 21:46:04 CET 2009


Author: rgrieder
Date: 2009-12-06 21:46:04 +0100 (Sun, 06 Dec 2009)
New Revision: 6260

Modified:
   code/branches/presentation2/src/orxonox/sound/BaseSound.cc
   code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
Log:
Audio sources seem to be very limited resources. If we create more than available sources (usually more than 256), it will not result in a failed assert anymore. Instead, the sound will simply not load and play.

Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.cc	2009-12-06 19:16:04 UTC (rev 6259)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.cc	2009-12-06 20:46:04 UTC (rev 6260)
@@ -54,14 +54,15 @@
         if (GameMode::playsSound())
         {
             alGenSources(1, &this->audioSource_);
-            assert(this->audioSource_ != 0);
+            if (!alIsSource(this->audioSource_))
+                COUT(1) << "Sound: Source generation failed: " << SoundManager::getALErrorString(alGetError()) << std::endl;
         }
     }
 
     BaseSound::~BaseSound()
     {
         this->setSource("");
-        if (GameMode::playsSound())
+        if (GameMode::playsSound() && alIsSource(this->audioSource_))
             alDeleteSources(1, &this->audioSource_);
     }
 
@@ -76,7 +77,7 @@
     void BaseSound::play()
     {
         this->state_ = Playing;
-        if (GameMode::playsSound() && this->getSourceState() != AL_PLAYING)
+        if (GameMode::playsSound() && alIsSource(this->audioSource_) && this->getSourceState() != AL_PLAYING)
         {
             alSourcePlay(this->audioSource_);
 
@@ -88,7 +89,7 @@
     void BaseSound::stop()
     {
         this->state_ = Stopped;
-        if (GameMode::playsSound())
+        if (GameMode::playsSound() && alIsSource(this->audioSource_))
             alSourceStop(this->audioSource_);
     }
 
@@ -97,13 +98,13 @@
         if (this->isStopped())
             return;
         this->state_ = Paused;
-        if (GameMode::playsSound())
+        if (GameMode::playsSound() && alIsSource(this->audioSource_))
             alSourcePause(this->audioSource_);
     }
 
     ALint BaseSound::getSourceState() const
     {
-        if (GameMode::playsSound())
+        if (GameMode::playsSound() && alIsSource(this->audioSource_))
         {
             ALint state;
             alGetSourcei(this->audioSource_, AL_SOURCE_STATE, &state);
@@ -144,7 +145,7 @@
     void BaseSound::setLooping(bool val)
     {
         this->bLoop_ = val;
-        if (GameMode::playsSound())
+        if (GameMode::playsSound() && alIsSource(this->audioSource_))
             alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE));
     }
 
@@ -157,7 +158,7 @@
             pitch = pitch < 0.5 ? 0.5 : pitch;
         }        
         this->pitch_ = pitch;
-        if (GameMode::playsSound())
+        if (GameMode::playsSound() && alIsSource(this->audioSource_))
         {
             if (int error = alGetError())
                 COUT(2) << "Sound: Error setting pitch: " << error << std::endl;
@@ -175,15 +176,18 @@
 
         if (this->soundBuffer_ != NULL)
         {
-            alSourceStop(this->audioSource_);
-            // Unload old sound first
-            alSourcei(this->audioSource_, AL_BUFFER, 0);
+            if (alIsSource(this->audioSource_))
+            {
+                alSourceStop(this->audioSource_);
+                // Unload old buffer first
+                alSourcei(this->audioSource_, AL_BUFFER, 0);
+            }
             SoundManager::getInstance().releaseSoundBuffer(this->soundBuffer_, this->bPooling_);
             this->soundBuffer_.reset();
         }
 
         this->source_ = source;
-        if (source_.empty())
+        if (source_.empty() || !alIsSource(this->audioSource_))
             return;
 
         // Get DataStream from the resources
@@ -199,9 +203,9 @@
             return;
 
         alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
-        if (alGetError() != AL_NO_ERROR)
+        if (ALuint error = alGetError())
         {
-            COUT(2) << "Sound: OpenAL: Error loading sample file: " << source << std::endl;
+            COUT(1) << "Sound Error: Could not load file \"" << source << "\": " << SoundManager::getALErrorString << std::endl;
             return;
         }
 

Modified: code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc	2009-12-06 19:16:04 UTC (rev 6259)
+++ code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc	2009-12-06 20:46:04 UTC (rev 6260)
@@ -86,7 +86,7 @@
         this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, this->fileInfo_->size);
         delete[] buffer;
 
-        if (this->audioBuffer_ == AL_NONE)
+        if (!alIsBuffer(this->audioBuffer_))
             ThrowException(General, "Sound Error: Standard file loader failed: " << alutGetErrorString(alutGetError()));
     }
 
@@ -169,7 +169,7 @@
         alBufferData(this->audioBuffer_, format, &outbuffer[0], outbuffer.size(), vorbisInfo->rate);
         ov_clear(&vf);
 
-        if (this->audioBuffer_ == AL_NONE)
+        if (!alIsBuffer(this->audioBuffer_))
             ThrowException(General, "Sound: Ogg file loader failed when creating the buffer.");
     }
 }




More information about the Orxonox-commit mailing list