[Orxonox-commit 1845] r6562 - code/branches/sound5/src/orxonox/sound

erwin at orxonox.net erwin at orxonox.net
Thu Mar 18 15:48:49 CET 2010


Author: erwin
Date: 2010-03-18 15:48:49 +0100 (Thu, 18 Mar 2010)
New Revision: 6562

Modified:
   code/branches/sound5/src/orxonox/sound/AmbientSound.cc
   code/branches/sound5/src/orxonox/sound/SoundManager.cc
   code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
Log:
More tries to fix the sound: there seems to be no context in the stream thread...

Modified: code/branches/sound5/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/sound5/src/orxonox/sound/AmbientSound.cc	2010-03-18 13:55:51 UTC (rev 6561)
+++ code/branches/sound5/src/orxonox/sound/AmbientSound.cc	2010-03-18 14:48:49 UTC (rev 6562)
@@ -174,7 +174,10 @@
         DataStreamPtr dataStream = Resource::open(fileInfo);
 
         this->soundstreamthread_ = boost::thread(SoundStreamer(), this->audioSource_, dataStream);
+        if(this->soundstreamthread_ == boost::thread())
+            COUT(2) << "Sound: Failed to create thread." << std::endl;
 
+
         this->updateVolume();
         this->setPitch(this->getPitch());
         this->setLooping(this->getLooping());

Modified: code/branches/sound5/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/sound5/src/orxonox/sound/SoundManager.cc	2010-03-18 13:55:51 UTC (rev 6561)
+++ code/branches/sound5/src/orxonox/sound/SoundManager.cc	2010-03-18 14:48:49 UTC (rev 6562)
@@ -115,7 +115,8 @@
         Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
 
         // Create sound context and make it the currently used one
-        this->context_ = alcCreateContext(this->device_, NULL);
+        const ALint contattr[]  = {ALC_SYNC, 1, 0};
+        this->context_ = alcCreateContext(this->device_, contattr);
         if (this->context_ == NULL)
             ThrowException(InitialisationFailed, "Sound: Error: Could not create ALC context");
         Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);

Modified: code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
===================================================================
--- code/branches/sound5/src/orxonox/sound/SoundStreamer.cc	2010-03-18 13:55:51 UTC (rev 6561)
+++ code/branches/sound5/src/orxonox/sound/SoundStreamer.cc	2010-03-18 14:48:49 UTC (rev 6562)
@@ -27,6 +27,7 @@
 #include "SoundStreamer.h"
 
 #include <al.h>
+#include <alc.h>
 #include <vorbis/vorbisfile.h>
 #include "SoundManager.h"
 #include "util/Sleep.h"
@@ -66,6 +67,10 @@
         char inbuffer[256*1024];
         ALuint initbuffers[4];
         alGenBuffers(4, initbuffers);
+        if (ALint error = alGetError()) {
+            COUT(2) << "Sound: Streamer: Could not generate buffer:" << getALErrorString(error) << std::endl;
+            return;
+        }
         int current_section;
 
         for(int i = 0; i < 4; i++)
@@ -83,22 +88,30 @@
             }
 
             alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);
+            alGetError();
         }
         alSourceQueueBuffers(audioSource, 4, initbuffers);
+        if (ALint error = alGetError()) {
+            COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
+        }
 
         while(true) // Stream forever, control through thread control
         {
             int processed;
+
+        if(alcGetCurrentContext() == NULL)
+            COUT(2) << "This should not be!" << std::endl;
+
             alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed);
             if (ALint error = alGetError())
-            COUT(2) << "Sound Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;
+            COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;
 
             if(processed > 0)
             {
                 ALuint* buffers = new ALuint[processed];
                 alSourceUnqueueBuffers(audioSource, processed, buffers);
                 if (ALint error = alGetError())
-                    COUT(2) << "Sound Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl;
+                    COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl;
 
                 for(int i = 0; i < processed; i++)
                 {
@@ -115,13 +128,14 @@
                     }
 
                     alBufferData(buffers[i], format, &inbuffer, ret, vorbisInfo->rate);
+                    alGetError();
                 }
 
                 alSourceQueueBuffers(audioSource, processed, buffers);
                 if (ALint error = alGetError())
-                    COUT(2) << "Sound Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
+                    COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
             }
-            msleep(250); // perhaps another value here is better
+            msleep(100); // perhaps another value here is better
         }
     }
 }




More information about the Orxonox-commit mailing list