[Orxonox-commit 1614] r6332 - code/branches/presentation2/src/orxonox/sound

rgrieder at orxonox.net rgrieder at orxonox.net
Sun Dec 13 00:11:40 CET 2009


Author: rgrieder
Date: 2009-12-13 00:11:40 +0100 (Sun, 13 Dec 2009)
New Revision: 6332

Modified:
   code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
   code/branches/presentation2/src/orxonox/sound/SoundBuffer.h
   code/branches/presentation2/src/orxonox/sound/SoundManager.cc
   code/branches/presentation2/src/orxonox/sound/SoundManager.h
Log:
Improved SoundBuffer class design and removed its pooling property (just a boolean).

Modified: code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc	2009-12-12 19:36:02 UTC (rev 6331)
+++ code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc	2009-12-12 23:11:40 UTC (rev 6332)
@@ -32,6 +32,8 @@
 #include <AL/alut.h>
 #include <vorbis/vorbisfile.h>
 
+#include "util/Clock.h"
+#include "core/Game.h"
 #include "util/Exception.h"
 #include "util/StringUtils.h"
 #include "core/Resource.h"
@@ -39,9 +41,10 @@
 
 namespace orxonox
 {
-    SoundBuffer::SoundBuffer(const std::string& filename)
+    SoundBuffer::SoundBuffer(const std::string& filename, std::list<shared_ptr<SoundBuffer> >::iterator poolIterator)
         : filename_(filename)
         , audioBuffer_(AL_NONE)
+        , poolIterator_(poolIterator)
     {
         if (this->filename_.empty())
             ThrowException(General, "SoundBuffer construction: fileInfo was NULL");
@@ -59,8 +62,11 @@
         std::string extension(this->filename_.substr(this->filename_.find_last_of('.') + 1));
         if (getLowercase(extension) == "ogg")
         {
+            int before = Game::getInstance().getGameClock().getRealMicroseconds();
             // Try ogg loader
             this->loadOgg(fileInfo, dataStream);
+            int after = Game::getInstance().getGameClock().getRealMicroseconds();
+            COUT(0) << filename << ": " << (after - before) << std::endl;
         }
         else
         {
@@ -79,10 +85,7 @@
     {
         ALint size;
         alGetBufferi(this->audioBuffer_, AL_SIZE, &size);
-        if (!alGetError())
-            return size;
-        else
-            return 0;
+        return alGetError() ? 0 : size;
     }
 
     void SoundBuffer::loadStandard(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream)
@@ -107,14 +110,20 @@
     int seekVorbis(void* datasource, ogg_int64_t offset, int whence)
     {
         Ogre::DataStream* stream = static_cast<Ogre::DataStream*>(datasource);
-        int offset_beg = offset;
-        if (whence == SEEK_CUR)
-            offset_beg = stream->tell() + offset;
-        else if (whence == SEEK_END)
-            offset_beg = stream->size() + offset;
-        else if (whence != SEEK_SET)
+        switch (whence)
+        {
+        case SEEK_SET:
+            stream->seek(offset);
+            break;
+        case SEEK_CUR:
+            stream->skip(offset);
+            break;
+        case SEEK_END:
+            stream->seek(stream->size() + offset);
+            break;
+        default:
             return -1;
-        stream->seek(offset_beg);
+        }
         return 0;
     }
 

Modified: code/branches/presentation2/src/orxonox/sound/SoundBuffer.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundBuffer.h	2009-12-12 19:36:02 UTC (rev 6331)
+++ code/branches/presentation2/src/orxonox/sound/SoundBuffer.h	2009-12-12 23:11:40 UTC (rev 6332)
@@ -41,11 +41,11 @@
     class _OrxonoxExport SoundBuffer
     {
         friend class SoundManager;
+        // Make sure nobody deletes an instance (using smart pointers)
+        template <class T>
+        friend void boost::checked_delete(T*);
 
     public:
-        SoundBuffer(const std::string& filename);
-        ~SoundBuffer();
-
         inline ALuint getBuffer()
             { return this->audioBuffer_; }
 
@@ -54,19 +54,15 @@
         const std::string& getFilename() const
             { return this->filename_; }
 
-        void setPooling(bool val)
-            { this->bPooling_ = true; }
-        bool getPooling() const
-            { return this->bPooling_; }
-
     private:
+        SoundBuffer(const std::string& filename, std::list<shared_ptr<SoundBuffer> >::iterator poolIterator);
+        ~SoundBuffer();
         void loadStandard(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream);
         void loadOgg(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream);
 
         std::string filename_;
         ALuint audioBuffer_;
         std::list<shared_ptr<SoundBuffer> >::iterator poolIterator_;
-        bool bPooling_;
     };
 }
 

Modified: code/branches/presentation2/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.cc	2009-12-12 19:36:02 UTC (rev 6331)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.cc	2009-12-12 23:11:40 UTC (rev 6332)
@@ -59,12 +59,13 @@
             ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
         Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
 
+/*
         // Get list of available sound devices and display them
-/*        const char* devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
+        const char* devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
         char* device = new char[strlen(devices)+1];
         strcpy(device, devices);
         std::string renderDevice;
-//        SetConfigValue(renderDevice, std::string(device)).description("Sound device used for rendering");
+        SetConfigValue(renderDevice, std::string(device)).description("Sound device used for rendering");
         COUT(4) << "Sound: Available devices: ";
         while (true)
         {
@@ -78,7 +79,8 @@
 
         // Open the selected device
         COUT(3) << "Sound: Opening device \"" << renderDevice << "\"" << std::endl;
-        this->device_ = alcOpenDevice(renderDevice.c_str());*/
+        this->device_ = alcOpenDevice(renderDevice.c_str());
+*/
         this->device_ = alcOpenDevice(NULL);
         if (this->device_ == NULL)
         {
@@ -572,8 +574,7 @@
         {
             try
             {
-                buffer.reset(new SoundBuffer(filename));
-                buffer->poolIterator_ = this->effectsPool_.end();
+                buffer.reset(new SoundBuffer(filename, this->effectsPool_.end()));
             }
             catch (...)
             {

Modified: code/branches/presentation2/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.h	2009-12-12 19:36:02 UTC (rev 6331)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.h	2009-12-12 23:11:40 UTC (rev 6332)
@@ -91,10 +91,10 @@
         void registerAmbientSound(AmbientSound* newAmbient);
         void unregisterAmbientSound(AmbientSound* oldAmbient);
         void pauseAmbientSound(AmbientSound* ambient);
-        
+
         void setVolume(float vol, SoundType::Value type);
         float getVolume(SoundType::Value type); // tolua_export
-        
+
         void toggleMute(SoundType::Value type); // tolua_export
         bool getMute(SoundType::Value type); // tolua_export
 
@@ -116,25 +116,25 @@
         void checkSoundVolumeValidity(void);
         void checkAmbientVolumeValidity(void);
         void checkEffectsVolumeValidity(void);
-        
+
         float checkVolumeRange(float vol);
-        
+
         void updateVolume(SoundType::Value type);
-        
+
         void setVolumeInternal(float vol, SoundType::Value type);
         float getVolumeInternal(SoundType::Value type);
 
         std::vector<std::string> deviceNames_;
         ALCdevice* device_;
         ALCcontext* context_;
-       
+
         typedef std::list<std::pair<AmbientSound*, bool> > AmbientList;
         AmbientList ambientSounds_;
-        
+
         float crossFadeStep_;       //!< Absolute change per second (0.1 means 10% of the nominal volume) for cross fading
         std::list<AmbientSound*> fadeInList_;
         std::list<AmbientSound*> fadeOutList_;
-        
+
         float soundVolume_;
         float ambientVolume_;
         float effectsVolume_;
@@ -149,7 +149,7 @@
 
         unsigned int maxSources_;
         std::vector<ALuint> soundSources_;
-        
+
         static SoundManager* singletonPtr_s;
     }; // tolua_export
 } // tolua_export




More information about the Orxonox-commit mailing list