[Orxonox-commit 2016] r6733 - code/branches/sound5/src/orxonox/sound

erwin at orxonox.net erwin at orxonox.net
Thu Apr 15 15:42:25 CEST 2010


Author: erwin
Date: 2010-04-15 15:42:24 +0200 (Thu, 15 Apr 2010)
New Revision: 6733

Modified:
   code/branches/sound5/src/orxonox/sound/AmbientSound.cc
   code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
Log:
Added some hacks, now the source is playing, but there are no processed buffers...

Modified: code/branches/sound5/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/sound5/src/orxonox/sound/AmbientSound.cc	2010-04-15 13:35:31 UTC (rev 6732)
+++ code/branches/sound5/src/orxonox/sound/AmbientSound.cc	2010-04-15 13:42:24 UTC (rev 6733)
@@ -182,30 +182,7 @@
         this->soundstreamthread_ = boost::thread(SoundStreamer(), this->audioSource_, dataStream);
         if(this->soundstreamthread_ == boost::thread())
             COUT(2) << "Sound: Failed to create thread." << std::endl;
-
-        if (alIsSource(this->audioSource_)) // already playing or paused
-        {
-            // 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: " << getALErrorString(error) << std::endl;
-            if (this->isPaused())
-                alSourcePause(this->audioSource_);
-        }
-        else // No source acquired so far, but might be set to playing or paused
-        {
-            if (this->isPlaying() || this->isPaused())
-                doPlay();
-            if (this->isPaused())
-            {
-                doPause();
-            }
-        }
-
-        this->updateVolume();
-        this->setPitch(this->getPitch());
-        this->setLooping(this->getLooping());
+       
         alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
         alSource3f(this->audioSource_, AL_VELOCITY,  0, 0, 0);
         alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);

Modified: code/branches/sound5/src/orxonox/sound/SoundStreamer.cc
===================================================================
--- code/branches/sound5/src/orxonox/sound/SoundStreamer.cc	2010-04-15 13:35:31 UTC (rev 6732)
+++ code/branches/sound5/src/orxonox/sound/SoundStreamer.cc	2010-04-15 13:42:24 UTC (rev 6733)
@@ -43,6 +43,9 @@
     void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream)
     {
         COUT(4) << "Sound: Creating thread for " << dataStream->getName() << std::endl;
+
+        alSourcei(audioSource, AL_BUFFER, 0);
+
         // Open file with custom streaming
         ov_callbacks vorbisCallbacks;
         vorbisCallbacks.read_func  = &readVorbis;
@@ -100,35 +103,41 @@
              }
         }
 
+        alSourcei(audioSource, AL_LOOPING, AL_TRUE);
+
+        alSourcePlay(audioSource);
+        if(ALint error = alGetError())
+            COUT(2) << "Sound: Could not start ambient sound" << std::endl;
+
         while(true) // Stream forever, control through thread control
         {
-            int processed;
 
+            int info;
+            alGetSourcei(audioSource, AL_SOURCE_STATE, &info);
+            if(info == AL_PLAYING)
+                COUT(4) << "Sound: " << dataStream->getName() << " is playing." << std::endl;
+            else
+                COUT(4) << "Sound: " << dataStream->getName() << " is not playing." << std::endl;
+
             if(alcGetCurrentContext() == NULL)
             {
                 COUT(2) << "Sound: There is no context, terminating thread for " << dataStream->getName() << std::endl;
                 return;
             }
 
+            int processed;
             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(4) << "Sound: processed buffers: " << processed << std::endl;
 
             if(processed > 0)
             {
-                COUT(4) << "Sound: " << processed << std::endl;
                 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;
 
-                int info;
-                alGetSourcei(audioSource, AL_SOURCE_STATE, &info);
-                if(info == AL_PLAYING)
-                    COUT(4) << "Sound: " << dataStream->getName() << " is playing." << std::endl;
-                else
-                    COUT(4) << "Sound: " << dataStream->getName() << " is not playing." << std::endl;
-
                 for(int i = 0; i < processed; i++)
                 {
                     long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
@@ -170,7 +179,7 @@
 
                 return;
             }
-            msleep(100); // perhaps another value here is better
+            msleep(50); // perhaps another value here is better
         }
     }
 }




More information about the Orxonox-commit mailing list