[Orxonox-commit 396] r2984 - in branches/sound: cmake src/orxonox/sound

erwin at orxonox.net erwin at orxonox.net
Mon May 18 16:52:26 CEST 2009


Author: erwin
Date: 2009-05-18 16:52:26 +0200 (Mon, 18 May 2009)
New Revision: 2984

Modified:
   branches/sound/cmake/LibraryConfig.cmake
   branches/sound/src/orxonox/sound/SoundBase.cc
   branches/sound/src/orxonox/sound/SoundManager.cc
Log:
implemented a fallback ogg loader via libvorbisfile

Modified: branches/sound/cmake/LibraryConfig.cmake
===================================================================
--- branches/sound/cmake/LibraryConfig.cmake	2009-05-18 14:29:40 UTC (rev 2983)
+++ branches/sound/cmake/LibraryConfig.cmake	2009-05-18 14:52:26 UTC (rev 2984)
@@ -110,8 +110,8 @@
 
 FIND_PACKAGE(OGRE  1.4 EXACT REQUIRED)
 FIND_PACKAGE(ENet  1.1       REQUIRED)
-#FIND_PACKAGE(Ogg             REQUIRED)
-#FIND_PACKAGE(Vorbis          REQUIRED)
+FIND_PACKAGE(Ogg             REQUIRED)
+FIND_PACKAGE(Vorbis          REQUIRED)
 FIND_PACKAGE(ALUT            REQUIRED)
 FIND_PACKAGE(ZLIB            REQUIRED)
 IF(WIN32)

Modified: branches/sound/src/orxonox/sound/SoundBase.cc
===================================================================
--- branches/sound/src/orxonox/sound/SoundBase.cc	2009-05-18 14:29:40 UTC (rev 2983)
+++ branches/sound/src/orxonox/sound/SoundBase.cc	2009-05-18 14:52:26 UTC (rev 2984)
@@ -25,6 +25,7 @@
  *      ...
  *
  */
+#include <vector>
 #include <AL/alut.h>
 #include <vorbis/vorbisfile.h>
 
@@ -70,20 +71,20 @@
             alSource3f(this->source_, AL_POSITION, pos.x, pos.y, pos.z);
             ALenum error = alGetError();
             if(error == AL_INVALID_VALUE)
-                COUT(2) << "OpenAL: Invalid sound position" << std::endl;
+                COUT(2) << "Sound: OpenAL: Invalid sound position" << std::endl;
 
             Vector3 vel = this->entity_->getVelocity();
             alSource3f(this->source_, AL_VELOCITY, vel.x, vel.y, vel.z);
             error = alGetError();
             if(error == AL_INVALID_VALUE)
-                COUT(2) << "OpenAL: Invalid sound position" << std::endl;
+                COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl;
 
             Quaternion orient = this->entity_->getOrientation();
             Vector3 at = orient.zAxis();
             alSource3f(this->source_, AL_DIRECTION, at.x, at.y, at.z);
             error = alGetError();
             if(error == AL_INVALID_VALUE)
-                COUT(2) << "OpenAL: Invalid sound position" << std::endl;
+                COUT(2) << "Sound: OpenAL: Invalid sound direction" << std::endl;
         }
     }
 
@@ -132,10 +133,10 @@
 
     bool SoundBase::loadFile(std::string filename) {
         filename = Core::getMediaPathString() + "/audio/" + filename;
-        COUT(3) << "OpenAL ALUT: loading file " << filename << std::endl;
+        COUT(3) << "Sound: OpenAL ALUT: loading file " << filename << std::endl;
         this->buffer_ = alutCreateBufferFromFile(filename.c_str());
         if(this->buffer_ == AL_NONE) {
-            COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
+            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
             if(filename.find("ogg", 0) != std::string::npos)
             {
                 this->buffer_ = loadOggFile(filename);
@@ -148,7 +149,7 @@
         alGenSources(1, &this->source_);
         alSourcei(this->source_, AL_BUFFER, this->buffer_);
         if(alGetError() != AL_NO_ERROR) {
-            COUT(2) << "OpenAL: Error loading sample file" << std::endl;
+            COUT(2) << "Sound: OpenAL: Error loading sample file" << std::endl;
             return false;
         }
         return true;
@@ -159,10 +160,47 @@
         alGetSourcei(this->source_, AL_SOURCE_STATE, &state);
         return state;
     }
-    
+
     ALuint SoundBase::loadOggFile(std::string filename)
     {
-        // just a dummy
-        return AL_NONE;
+        COUT(2) << "Sound: Trying fallback ogg loader";
+
+        char inbuffer[4096];
+        std::vector<char> outbuffer;
+        OggVorbis_File vf;
+        int eof = false;
+        int current_section;
+
+        FILE* f = fopen(filename.c_str(), "rb");
+
+        if(ov_open(f, &vf, NULL, 0) < 0)
+        {
+            COUT(2) << "Sound: libvorbisfile: File seems not to be an Ogg Vorbis bitstream" << std::endl;
+            ov_clear(&vf);
+            return AL_NONE;
+        }
+
+        while(!eof)
+        {
+            long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
+            if (ret == 0)
+            {
+                eof = true;
+            }
+            else if (ret < 0)
+            {
+                COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
+                ov_clear(&vf);
+                return AL_NONE;
+            }
+            else
+            {
+                outbuffer.insert(outbuffer.end(), inbuffer, inbuffer + sizeof(inbuffer));
+            }
+        }
+        
+        ov_clear(&vf);
+
+        return alutCreateBufferFromFileImage(&outbuffer, outbuffer.size());
     }
 } // namespace: orxonox

Modified: branches/sound/src/orxonox/sound/SoundManager.cc
===================================================================
--- branches/sound/src/orxonox/sound/SoundManager.cc	2009-05-18 14:29:40 UTC (rev 2983)
+++ branches/sound/src/orxonox/sound/SoundManager.cc	2009-05-18 14:52:26 UTC (rev 2984)
@@ -45,34 +45,34 @@
     {
         if(!alutInitWithoutContext(NULL,NULL))
         {
-            COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
+            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
         }
         else
         {
-            COUT(4) << "OpenAL ALUT version:" << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
-            COUT(4) << "OpenAL ALUT supported MIME types:" << alutGetMIMETypes(ALUT_LOADER_BUFFER) << std::endl;
+            COUT(4) << "Sound: OpenAL ALUT version:" << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
+            COUT(4) << "Sound: OpenAL ALUT supported MIME types:" << alutGetMIMETypes(ALUT_LOADER_BUFFER) << std::endl;
             if(SoundManager::device_s == NULL)
             {
-                COUT(3) << "OpenAL: Open sound device..." << std::endl;
+                COUT(3) << "Sound: OpenAL: Open sound device..." << std::endl;
                 SoundManager::device_s = alcOpenDevice(NULL);
             }
 
             if(SoundManager::device_s == NULL)
             {
-                COUT(2) << "OpenAL: Could not open sound device" << std::endl;
+                COUT(2) << "Sound: OpenAL: Could not open sound device" << std::endl;
             }
             else
             {
-                COUT(3) << "OpenAL: Sound device opened" << std::endl;
+                COUT(3) << "Sound: OpenAL: Sound device opened" << std::endl;
                 this->context_ = alcCreateContext(SoundManager::device_s, NULL);
                 if(this->context_ == NULL)
                 {
-                    COUT(2) << "OpenAL: Could not create sound context" << std::endl;
+                    COUT(2) << "Sound: OpenAL: Could not create sound context" << std::endl;
                 }
                 else
                 {
                     if(alcMakeContextCurrent(this->context_) == AL_TRUE)
-                        COUT(3) << "OpenAL: Context " << this->context_ << "loaded" << std::endl;
+                        COUT(3) << "Sound: OpenAL: Context " << this->context_ << "loaded" << std::endl;
                 }
             }
         }
@@ -126,7 +126,7 @@
         alListener3f(AL_POSITION, pos.x, pos.y, pos.z);
         ALenum error = alGetError();
         if(error == AL_INVALID_VALUE)
-            COUT(2) << "OpenAL: Invalid listener position" << std::endl;
+            COUT(2) << "Sound: OpenAL: Invalid listener position" << std::endl;
 
         // update listener orientation
         Quaternion orient = camera->getOrientation();
@@ -139,7 +139,7 @@
         alListenerfv(AL_POSITION, orientation);
         error = alGetError();
         if(error == AL_INVALID_VALUE)
-            COUT(2) << "OpenAL: Invalid listener orientation" << std::endl;
+            COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl;
 
         // update sounds
         for(std::list<SoundBase*>::iterator i = this->soundlist_.begin(); i != this->soundlist_.end(); i++)




More information about the Orxonox-commit mailing list