Index: code/branches/presentation2/src/libraries/core/Resource.h
===================================================================
--- code/branches/presentation2/src/libraries/core/Resource.h	(revision 6202)
+++ code/branches/presentation2/src/libraries/core/Resource.h	(revision 6203)
@@ -86,4 +86,11 @@
             bool bSearchGroupsIfNotFound = false);
 
+        //! Similar to open(string, string, bool), but with a fileInfo struct
+        static DataStreamPtr open(shared_ptr<ResourceInfo> fileInfo,
+            bool bSearchGroupsIfNotFound = false)
+        {
+            return open(fileInfo->filename, fileInfo->group, bSearchGroupsIfNotFound);
+        }
+
         /**
         @brief
Index: code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/AmbientSound.cc	(revision 6202)
+++ code/branches/presentation2/src/orxonox/sound/AmbientSound.cc	(revision 6203)
@@ -71,5 +71,4 @@
         if (GameMode::playsSound())
         {
-            COUT(3) << "Sound: " << this->getSource() << ": Playing" << std::endl;
             SoundManager::getInstance().registerAmbientSound(this);
         }
Index: code/branches/presentation2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.cc	(revision 6202)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.cc	(revision 6203)
@@ -31,6 +31,5 @@
 #include <cassert>
 #include <vector>
-#include <AL/alut.h>
-#include <vorbis/vorbisfile.h>
+#include <al.h>
 
 #include "core/CoreIncludes.h"
@@ -38,4 +37,5 @@
 #include "core/Resource.h"
 #include "core/XMLPort.h"
+#include "SoundBuffer.h"
 #include "SoundManager.h"
 
@@ -44,5 +44,5 @@
     BaseSound::BaseSound()
         : audioSource_(0)
-        , audioBuffer_(0)
+        , volume_(1.0)
         , bLoop_(false)
         , state_(Stopped)
@@ -82,6 +82,6 @@
             alSourcePlay(this->audioSource_);
 
-            if (alGetError() != AL_NO_ERROR)
-                 COUT(2) << "Sound: OpenAL: Error playing sound " << this->audioSource_ << std::endl;
+            if (int error = alGetError())
+                COUT(2) << "Sound: Error playing sound: " << error << std::endl;
         }
     }
@@ -155,11 +155,10 @@
         }
 
-        if (this->audioBuffer_ != 0 && alIsBuffer(this->audioBuffer_))
+        if (this->soundBuffer_ != NULL)
         {
             alSourceStop(this->audioSource_);
             // Unload old sound first
             alSourcei(this->audioSource_, AL_BUFFER, 0);
-            alDeleteBuffers(1, &this->audioBuffer_);
-            this->audioBuffer_ = 0;
+            this->soundBuffer_.reset();
         }
 
@@ -168,5 +167,4 @@
             return;
 
-        COUT(3) << "Sound: OpenAL ALUT: loading file " << source << std::endl;
         // Get DataStream from the resources
         shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source);
@@ -176,30 +174,10 @@
             return;
         }
-        dataStream_ = Resource::open(source);
-        // Read everything into a temporary buffer
-        char* buffer = new char[fileInfo->size];
-        dataStream_->read(buffer, fileInfo->size);
-        dataStream_->seek(0);
-
-        this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);
-        delete[] buffer;
-
-        if (this->audioBuffer_ == AL_NONE)
-        {
-            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
-            if (source.find("ogg", 0) != std::string::npos)
-            {
-                COUT(2) << "Sound: Trying fallback ogg loader" << std::endl;
-                this->audioBuffer_ = this->loadOggFile();
-            }
-
-            if (this->audioBuffer_ == AL_NONE)
-            {
-                COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl;
-                return;
-            }
-        }
-
-        alSourcei(this->audioSource_, AL_BUFFER, this->audioBuffer_);
+
+        this->soundBuffer_ = SoundManager::getInstance().getSoundBuffer(fileInfo);
+        if (this->soundBuffer_ == NULL)
+            return;
+
+        alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
         if (alGetError() != AL_NO_ERROR)
         {
@@ -217,89 +195,6 @@
             alSourcePause(this->audioSource_);
 
-        if (alGetError() != AL_NO_ERROR)
-            COUT(2) << "Sound: OpenAL: Error playing sound " << this->audioSource_ << std::endl;
-    }
-
-    size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource)
-    {
-        return static_cast<Ogre::DataStream*>(datasource)->read(ptr, size * nmemb);
-    }
-
-    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)
-            return -1;
-        stream->seek(offset_beg);
-        return 0;
-    }
-
-    long tellVorbis(void* datasource)
-    {
-        return static_cast<long>(static_cast<Ogre::DataStream*>(datasource)->tell());
-    }
-
-    ALuint BaseSound::loadOggFile()
-    {
-        char inbuffer[256*1024];
-        std::vector<char> outbuffer;
-        outbuffer.reserve(80*1024*1024);
-        OggVorbis_File vf;
-        vorbis_info* vorbisInfo;
-        int eof = false;
-        int current_section;
-        ALuint buffer;
-        ALenum format;
-
-        // Open file with custom streaming
-        ov_callbacks vorbisCallbacks;
-        vorbisCallbacks.read_func  = &readVorbis;
-        vorbisCallbacks.seek_func  = &seekVorbis;
-        vorbisCallbacks.tell_func  = &tellVorbis;
-        vorbisCallbacks.close_func = NULL;
-
-        int ret = ov_open_callbacks(dataStream_.get(), &vf, NULL, 0, vorbisCallbacks);
-        if (ret < 0)
-        {
-            COUT(2) << "Sound: libvorbisfile: File does not seem 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 + ret);
-            }
-        }
-
-        vorbisInfo = ov_info(&vf, -1);
-        if (vorbisInfo->channels == 1)
-            format = AL_FORMAT_MONO16;
-        else
-            format = AL_FORMAT_STEREO16;
-
-        alGenBuffers(1, &buffer);
-        alBufferData(buffer, format, &outbuffer[0], outbuffer.size(), vorbisInfo->rate);
-        ov_clear(&vf);
-
-        return buffer;
+        if (int error = alGetError())
+            COUT(2) << "Sound: OpenAL: Error playing sound: " << error << std::endl;
     }
 }
Index: code/branches/presentation2/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.h	(revision 6202)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.h	(revision 6203)
@@ -33,4 +33,5 @@
 
 #include <string>
+#include <boost/shared_ptr.hpp>
 #include <OgreDataStream.h>
 #include "core/OrxonoxClass.h"
@@ -38,4 +39,7 @@
 namespace orxonox
 {
+    // forward declaration
+    class SoundBuffer;
+
     /**
      * The BaseSound class is the base class for all sound file loader classes.
@@ -83,5 +87,5 @@
 
         ALuint audioSource_;
-        ALuint audioBuffer_;
+        shared_ptr<SoundBuffer> soundBuffer_;
 
     private:
Index: code/branches/presentation2/src/orxonox/sound/CMakeLists.txt
===================================================================
--- code/branches/presentation2/src/orxonox/sound/CMakeLists.txt	(revision 6202)
+++ code/branches/presentation2/src/orxonox/sound/CMakeLists.txt	(revision 6203)
@@ -2,4 +2,5 @@
     AmbientSound.cc
     BaseSound.cc
+    SoundBuffer.cc
     SoundManager.cc
     WorldSound.cc
Index: code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc	(revision 6203)
+++ code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc	(revision 6203)
@@ -0,0 +1,168 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *      Erwin 'vaiursch' Herrsche
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "SoundBuffer.h"
+
+#include <AL/alut.h>
+#include <vorbis/vorbisfile.h>
+
+#include "util/Exception.h"
+#include "util/StringUtils.h"
+#include "core/Resource.h"
+#include "sound/SoundManager.h"
+
+namespace orxonox
+{
+    SoundBuffer::SoundBuffer(shared_ptr<ResourceInfo> fileInfo)
+        : fileInfo_(fileInfo)
+        , audioBuffer_(AL_NONE)
+    {
+        if (this->fileInfo_ == NULL)
+            ThrowException(General, "SoundBuffer construction: fileInfo was NULL");
+        DataStreamPtr dataStream = Resource::open(this->fileInfo_);
+
+        std::string extension(this->fileInfo_->basename.substr(this->fileInfo_->basename.find_last_of('.') + 1));
+        if (getLowercase(extension) == "ogg")
+        {
+            // Try ogg loader
+            this->loadOgg(dataStream);
+        }
+        else
+        {
+            // Try standard OpenAL loader
+            this->loadStandard(dataStream);
+        }
+    }
+
+    SoundBuffer::~SoundBuffer()
+    {
+        // Unregister buffer from SoundManager
+        SoundManager::getInstance().removeBuffer(this->fileInfo_);
+
+        // Destroy buffer
+        alDeleteBuffers(1, &this->audioBuffer_);
+    }
+
+    void SoundBuffer::loadStandard(DataStreamPtr dataStream)
+    {
+        // Read everything into a temporary buffer
+        char* buffer = new char[this->fileInfo_->size];
+        dataStream->read(buffer, this->fileInfo_->size);
+        dataStream->seek(0);
+
+        this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, this->fileInfo_->size);
+        delete[] buffer;
+
+        if (this->audioBuffer_ == AL_NONE)
+            ThrowException(General, "Sound: Standard file loader failed: " << alutGetErrorString(alutGetError()));
+    }
+
+    size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource)
+    {
+        return static_cast<Ogre::DataStream*>(datasource)->read(ptr, size * nmemb);
+    }
+
+    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)
+            return -1;
+        stream->seek(offset_beg);
+        return 0;
+    }
+
+    long tellVorbis(void* datasource)
+    {
+        return static_cast<long>(static_cast<Ogre::DataStream*>(datasource)->tell());
+    }
+
+    void SoundBuffer::loadOgg(DataStreamPtr dataStream)
+    {
+        char inbuffer[256*1024];
+        std::vector<char> outbuffer;
+        outbuffer.reserve(80*1024*1024);
+
+        // Open file with custom streaming
+        ov_callbacks vorbisCallbacks;
+        vorbisCallbacks.read_func  = &readVorbis;
+        vorbisCallbacks.seek_func  = &seekVorbis;
+        vorbisCallbacks.tell_func  = &tellVorbis;
+        vorbisCallbacks.close_func = NULL;
+
+        OggVorbis_File vf;
+        int ret = ov_open_callbacks(dataStream.get(), &vf, NULL, 0, vorbisCallbacks);
+        if (ret < 0)
+        {
+            COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl;
+            ov_clear(&vf);
+            ThrowException(General, "Sound: Ogg file loader failed when opening the bitstream");
+        }
+
+        int current_section;
+        int eof = false;
+        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);
+                ThrowException(General, "Sound: Ogg file loader failed when decoding the file");
+            }
+            else
+            {
+                outbuffer.insert(outbuffer.end(), inbuffer, inbuffer + ret);
+            }
+        }
+
+        vorbis_info* vorbisInfo;
+        vorbisInfo = ov_info(&vf, -1);
+        ALenum format;
+        if (vorbisInfo->channels == 1)
+            format = AL_FORMAT_MONO16;
+        else
+            format = AL_FORMAT_STEREO16;
+
+        alGenBuffers(1, &this->audioBuffer_);
+        alBufferData(this->audioBuffer_, format, &outbuffer[0], outbuffer.size(), vorbisInfo->rate);
+        ov_clear(&vf);
+
+        if (this->audioBuffer_ == AL_NONE)
+            ThrowException(General, "Sound: Ogg file loader failed when creating the buffer.");
+    }
+}
Index: code/branches/presentation2/src/orxonox/sound/SoundBuffer.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundBuffer.h	(revision 6203)
+++ code/branches/presentation2/src/orxonox/sound/SoundBuffer.h	(revision 6203)
@@ -0,0 +1,59 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _SoundBuffer_H__
+#define _SoundBuffer_H__
+
+#include "OrxonoxPrereqs.h"
+#include <boost/shared_ptr.hpp>
+
+namespace orxonox
+{
+    /*
+    @brief
+        The SoundBuffer class is to be used for sounds with position and orientation.
+    */
+    class _OrxonoxExport SoundBuffer
+    {
+    public:
+        SoundBuffer(shared_ptr<ResourceInfo> fileInfo);
+        ~SoundBuffer();
+
+        inline ALuint getBuffer()
+            { return this->audioBuffer_; }
+
+    private:
+        void loadStandard(DataStreamPtr dataStream);
+        void loadOgg(DataStreamPtr dataStream);
+
+        shared_ptr<ResourceInfo> fileInfo_;
+        ALuint audioBuffer_;
+    };
+}
+
+#endif /* _SoundBuffer_H__ */
Index: code/branches/presentation2/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.cc	(revision 6202)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.cc	(revision 6203)
@@ -38,7 +38,9 @@
 #include "util/StringUtils.h"
 #include "util/Clock.h"
+#include "core/ConfigValueIncludes.h"
 #include "core/GameMode.h"
 #include "core/ScopedSingletonManager.h"
-#include "core/ConfigValueIncludes.h"
+#include "core/Resource.h"
+#include "SoundBuffer.h"
 #include "BaseSound.h"
 #include "AmbientSound.h"
@@ -473,3 +475,25 @@
         }
     }
+
+    shared_ptr<SoundBuffer> SoundManager::getSoundBuffer(shared_ptr<ResourceInfo> fileInfo)
+    {
+        std::map<std::string, weak_ptr<SoundBuffer> >::const_iterator it
+            = this->soundBuffers_.find(fileInfo->group + '/' + fileInfo->filename);
+        if (it != this->soundBuffers_.end())
+            return it->second.lock();
+        else
+        {
+            shared_ptr<SoundBuffer> buffer(new SoundBuffer(fileInfo));
+            this->soundBuffers_[fileInfo->group + '/' + fileInfo->filename] = buffer;
+            return buffer;
+        }
+    }
+
+    void SoundManager::removeBuffer(shared_ptr<ResourceInfo> fileInfo)
+    {
+        std::map<std::string, weak_ptr<SoundBuffer> >::const_iterator it
+            = this->soundBuffers_.find(fileInfo->group + '/' + fileInfo->filename);
+        if (it == this->soundBuffers_.end())
+            this->soundBuffers_.erase(it);
+    }
 }
Index: code/branches/presentation2/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.h	(revision 6202)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.h	(revision 6203)
@@ -33,6 +33,8 @@
 
 #include <list>
+#include <map>
 #include <string>
-#include <map>
+#include <boost/weak_ptr.hpp>
+
 #include "util/Singleton.h"
 #include "core/OrxonoxClass.h"
@@ -41,4 +43,6 @@
 namespace orxonox
 {
+    // forward declaration
+    class SoundBuffer;
     
     //! Enum for the sound type.
@@ -86,4 +90,7 @@
         bool getMute(SoundType::Value type); // tolua_export
 
+        shared_ptr<SoundBuffer> getSoundBuffer(shared_ptr<ResourceInfo> fileInfo);
+        void removeBuffer(shared_ptr<ResourceInfo> fileInfo);
+
     private:
         void processCrossFading(float dt);
@@ -118,4 +125,6 @@
         float effectsVolume_;
         std::map<SoundType::Value, bool> mute_;
+
+        std::map<std::string, weak_ptr<SoundBuffer> > soundBuffers_;
         
         static SoundManager* singletonPtr_s;
