[Orxonox-commit 1758] r6476 - code/branches/sound4/src/orxonox/sound

erwin at orxonox.net erwin at orxonox.net
Sat Mar 6 15:08:19 CET 2010


Author: erwin
Date: 2010-03-06 15:08:19 +0100 (Sat, 06 Mar 2010)
New Revision: 6476

Modified:
   code/branches/sound4/src/orxonox/sound/AmbientSound.cc
   code/branches/sound4/src/orxonox/sound/AmbientSound.h
   code/branches/sound4/src/orxonox/sound/SoundStreamer.cc
Log:
Tried to hack ths sound streaming part in... sound doesn't work at all now.

Modified: code/branches/sound4/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/sound4/src/orxonox/sound/AmbientSound.cc	2010-03-05 17:26:54 UTC (rev 6475)
+++ code/branches/sound4/src/orxonox/sound/AmbientSound.cc	2010-03-06 14:08:19 UTC (rev 6476)
@@ -34,6 +34,7 @@
 #include "core/Resource.h"
 #include "core/XMLPort.h"
 #include "SoundManager.h"
+#include "SoundStreamer.h"
 
 namespace orxonox
 {
@@ -119,7 +120,7 @@
             const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + this->ambientSource_;
             shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
             if (fileInfo != NULL)
-                this->setSource(path);
+                this->setStreamSource(path);
             else
                 COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl;
         }
@@ -140,4 +141,35 @@
         else
             this->stop();
     }
+
+    // hacky solution for file streaming
+    void AmbientSound::setStreamSource(const std::string& source)
+    {
+        this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
+        if (this->source_ == source)
+        {
+            return;
+        }
+
+        this->source_ = source;
+        // Don't load ""
+        if (source_.empty())
+            return;
+
+        if (this->soundstreamthread_.get_id() != boost::thread::id())
+        {
+            this->soundstreamthread_.interrupt(); // unhandled interruptions lead to thread terminating ;-)
+        }
+        // Get resource info
+        shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source);
+        if (fileInfo == NULL)
+        {
+            COUT(2) << "Sound: Warning: Sound file '" << source << "' not found" << std::endl;
+            return;
+        }
+        // Open data stream
+        DataStreamPtr dataStream = Resource::open(fileInfo);
+
+        this->soundstreamthread_ = boost::thread(SoundStreamer(), this->audioSource_, dataStream);
+    }
 }

Modified: code/branches/sound4/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/sound4/src/orxonox/sound/AmbientSound.h	2010-03-05 17:26:54 UTC (rev 6475)
+++ code/branches/sound4/src/orxonox/sound/AmbientSound.h	2010-03-06 14:08:19 UTC (rev 6476)
@@ -30,6 +30,8 @@
 #ifndef _AmbientSound_H__
 #define _AmbientSound_H__
 
+#include <boost/thread.hpp>
+
 #include "sound/SoundPrereqs.h"
 
 #include "core/BaseObject.h"
@@ -82,6 +84,9 @@
 
         std::string ambientSource_; //!< Analogous to source_, but mood independent
         bool        bPlayOnLoad_;   //!< Play the sound immediately when loaded
+
+        boost::thread soundstreamthread_; // hacky solution for streaming
+        void setStreamSource(const std::string& source);
     };
 }
 

Modified: code/branches/sound4/src/orxonox/sound/SoundStreamer.cc
===================================================================
--- code/branches/sound4/src/orxonox/sound/SoundStreamer.cc	2010-03-05 17:26:54 UTC (rev 6475)
+++ code/branches/sound4/src/orxonox/sound/SoundStreamer.cc	2010-03-06 14:08:19 UTC (rev 6476)
@@ -29,6 +29,7 @@
 #include <al.h>
 #include <vorbis/vorbisfile.h>
 #include "SoundManager.h"
+#include "util/Sleep.h"
 
 namespace orxonox
 {
@@ -120,6 +121,7 @@
                 if (ALint error = alGetError())
                     COUT(2) << "Sound Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
             }
+            msleep(250); // perhaps another value here is better
         }
     }
 }




More information about the Orxonox-commit mailing list