Index: code/branches/usability/src/orxonox/MoodManager.h
===================================================================
--- code/branches/usability/src/orxonox/MoodManager.h	(revision 8003)
+++ code/branches/usability/src/orxonox/MoodManager.h	(revision 8005)
@@ -59,8 +59,11 @@
     };
 
-    /*
-    @brief
-        The MoodManager class serves to allow for different musical themes in the game.
-    */
+    /**
+     * The MoodManager class enables the game to set different themes, i.e. audio themes, each
+     * with a set of different audio files. A theme (called mood) is set by the server and applies to
+     * all clients. Existing moods are currently hard-coded in function checkMoodValidity(). Each mood
+     * needs to have a folder with its name in "data_extern/audo/ambient/" containing sound files named like
+     * the ones in mood "default".
+     */
     class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass
     {
Index: code/branches/usability/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/usability/src/orxonox/sound/AmbientSound.cc	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/AmbientSound.cc	(revision 8005)
@@ -23,5 +23,5 @@
  *      Reto Grieder
  *   Co-authors:
- *      ...
+ *      Kevin Young
  *
  */
@@ -33,7 +33,16 @@
 #include "core/Resource.h"
 #include "SoundManager.h"
+#include "SoundStreamer.h"
+#include "util/Sleep.h"
+
+#include <AL/alut.h>
 
 namespace orxonox
 {
+    // vorbis callbacks
+    size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource);
+    int seekVorbis(void* datasource, ogg_int64_t offset, int whence);
+    long tellVorbis(void* datasource);
+    
     AmbientSound::AmbientSound()
         : bPlayOnLoad_(false)
@@ -42,5 +51,5 @@
 
         // Ambient sounds always fade in
-        this->setVolume(0);
+        //this->setVolume(0);
     }
 
@@ -51,4 +60,5 @@
             // Smoothly fade out by keeping a SmartPtr
             SoundManager::getInstance().unregisterAmbientSound(this);
+            this->soundstreamthread_.interrupt();
         }
     }
@@ -62,5 +72,5 @@
     bool AmbientSound::stop()
     {
-        if (GameMode::playsSound())
+        if (GameMode::playsSound()) 
             SoundManager::getInstance().unregisterAmbientSound(this);
         return false; // sound source not (yet) destroyed - return false
@@ -92,5 +102,5 @@
             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;
@@ -104,3 +114,141 @@
             this->play();
     }
+
+    // hacky solution for file streaming
+    void AmbientSound::setStreamSource(const std::string& source)
+    {
+        if (!GameMode::playsSound())
+        {
+            this->source_ = source;
+            return;
+        }
+
+        if(!alIsSource(this->audioSource_))
+            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(); // terminate an old thread if necessary
+        }
+
+        // queue some init buffers
+        COUT(4) << "Sound: Creating thread for " << source << std::endl;
+        // 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);
+        
+        alSourcei(this->audioSource_, AL_BUFFER, 0);
+
+        // 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 = new OggVorbis_File();
+        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;
+        }
+        vorbis_info* vorbisInfo;
+        vorbisInfo = ov_info(vf, -1);
+        ALenum format;
+        if (vorbisInfo->channels == 1)
+            format = AL_FORMAT_MONO16;
+        else
+            format = AL_FORMAT_STEREO16;
+
+        char inbuffer[4096];
+        ALuint initbuffers[10];
+        alGenBuffers(10, initbuffers);
+        if (ALint error = alGetError()) {
+            COUT(2) << "Sound: Streamer: Could not generate buffer:" << getALErrorString(error) << std::endl;
+            return;
+        }
+        int current_section;
+
+        for(int i = 0; i < 10; i++)
+        {
+            long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
+            if (ret == 0)
+            {
+                break;
+            }
+            else if (ret < 0)
+            {
+                COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
+                ov_clear(vf);
+                return;
+            }
+
+            alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);
+            if(ALint error = alGetError()) {
+                COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
+                break;
+             }
+             alSourceQueueBuffers(this->audioSource_, 1, &initbuffers[i]);
+             if (ALint error = alGetError()) {
+                 COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
+             }
+        }
+        
+        this->soundstreamthread_ = boost::thread(SoundStreamer(), this->audioSource_, dataStream, vf, current_section);
+        if(this->soundstreamthread_ == boost::thread())
+            COUT(2) << "Sound: Failed to create thread." << std::endl;
+        //SoundStreamer streamer;
+        //streamer(this->audioSource_, dataStream);
+
+        alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
+        alSource3f(this->audioSource_, AL_VELOCITY,  0, 0, 0);
+        alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);
+        if (ALint error = alGetError())
+            COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl;
+    }
+
+    bool AmbientSound::doStop()
+    {
+        bool result = BaseSound::doStop();
+        this->soundstreamthread_.interrupt();
+        return result;
+    }
+
+    void AmbientSound::doPlay()
+    {
+        BaseSound::doPlay();
+
+        if(GameMode::playsSound() && this->getSourceState() != AL_PLAYING)
+        {
+            if(!alIsSource(this->audioSource_))
+            {
+                this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
+                if(!alIsSource(this->audioSource_))
+                    return;
+                this->initialiseSource();
+            }
+
+            alSourcePlay(this->audioSource_);
+            if(int error = alGetError())
+                COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
+        }
+    }
 }
Index: code/branches/usability/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/usability/src/orxonox/sound/AmbientSound.h	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/AmbientSound.h	(revision 8005)
@@ -22,7 +22,7 @@
  *   Author:
  *      Reto Grieder
+ *      
+ *   Co-authors:
  *      Kevin Young
- *   Co-authors:
- *      ...
  *
  */
@@ -31,5 +31,7 @@
 #define _AmbientSound_H__
 
-#include "OrxonoxPrereqs.h"
+#include <boost/thread.hpp>
+
+#include "sound/SoundPrereqs.h"
 
 #include "BaseSound.h"
@@ -39,6 +41,9 @@
 {
     /**
-     * The AmbientSound class is used to play background music. It can not be placed
-     * directly in a level file, use WorldAmbientSound instead.
+     * The AmbientSound class implements the non-3D sound, i.e. sound files that are used for atmospheric
+     * highlighting.
+     * It interfaces with BaseSound and is controllable by MoodManager.
+     * Ambient sounds are always cross-faded. New sounds are registered and activated/deactivated as needed.
+     *
      */
     class _OrxonoxExport AmbientSound : public BaseSound, public MoodListener
@@ -65,4 +70,7 @@
         ~AmbientSound() { }
 
+        bool doStop();
+        void doPlay();
+
     private:
         void preDestroy();
@@ -76,4 +84,7 @@
         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);
     };
 }
Index: code/branches/usability/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/usability/src/orxonox/sound/BaseSound.cc	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/BaseSound.cc	(revision 8005)
@@ -92,5 +92,5 @@
             alSourcePlay(this->audioSource_);
             if (int error = alGetError())
-                COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
+                COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
         }
     }
@@ -145,10 +145,10 @@
         alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);
         if (ALint error = alGetError())
-            COUT(2) << "Sound Warning: Setting source parameters to 0 failed: "
-                    << SoundManager::getALErrorString(error) << std::endl;
-        assert(this->soundBuffer_ != NULL);
-        alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
+            COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl;
+        if(this->soundBuffer_ != NULL) {
+            alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
+        }
         if (ALuint error = alGetError())
-            COUT(1) << "Sound Error: Could not set buffer \"" << this->source_ << "\": " << SoundManager::getALErrorString(error) << std::endl;
+            COUT(1) << "Sound: Error: Could not set buffer \"" << this->source_ << "\": " << getALErrorString(error) << std::endl;
     }
 
@@ -157,5 +157,5 @@
         this->volume_ = clamp(vol, 0.0f, 1.0f);
         if (this->volume_ != vol)
-            COUT(2) << "Sound warning: volume out of range, clamping value." << std::endl;
+            COUT(2) << "Sound: Warning: volume out of range, clamping value." << std::endl;
         this->updateVolume();
     }
@@ -168,6 +168,5 @@
             alSourcef(this->audioSource_, AL_GAIN, volume);
             if (int error = alGetError())
-                COUT(2) << "Sound: Error setting volume to " << volume
-                        << ": " << SoundManager::getALErrorString(error) << std::endl;
+                COUT(2) << "Sound: Error setting volume to " << volume << ": " << getALErrorString(error) << std::endl;
         }
     }
@@ -184,5 +183,5 @@
         if (pitch > 2 || pitch < 0.5f)
         {
-            COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;
+            COUT(2) << "Sound: Warning: pitch out of range, cropping value." << std::endl;
             pitch = pitch > 2.0f ? 2.0f : pitch;
             pitch = pitch < 0.5f ? 0.5f : pitch;
@@ -193,5 +192,5 @@
             alSourcef(this->audioSource_, AL_PITCH, pitch);
             if (int error = alGetError())
-                COUT(2) << "Sound: Error setting pitch: " << SoundManager::getALErrorString(error) << std::endl;
+                COUT(2) << "Sound: Error setting pitch: " << getALErrorString(error) << std::endl;
         }
     }
@@ -238,5 +237,5 @@
             if (ALuint error = alGetError())
             {
-                COUT(1) << "Sound Error: Could not set buffer \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;
+                COUT(1) << "Sound: Error: Could not set buffer \"" << source << "\": " << getALErrorString(error) << std::endl;
                 return;
             }
@@ -246,5 +245,5 @@
             alSourcePlay(this->audioSource_);
             if (int error = alGetError())
-                COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
+                COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
             if (this->isPaused())
                 alSourcePause(this->audioSource_);
Index: code/branches/usability/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/usability/src/orxonox/sound/BaseSound.h	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/BaseSound.h	(revision 8005)
@@ -30,5 +30,5 @@
 #define _BaseSound_H__
 
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
 
 #include <string>
@@ -85,7 +85,7 @@
         virtual ~BaseSound();
 
-        void doPlay();
-        bool doStop(); // returns true if the sound source was destroyed
-        void doPause();
+        virtual void doPlay();
+        virtual bool doStop(); // returns true if the sound source was destroyed
+        virtual void doPause();
 
         // network callbacks
Index: code/branches/usability/src/orxonox/sound/SoundBuffer.h
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundBuffer.h	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/SoundBuffer.h	(revision 8005)
@@ -30,5 +30,5 @@
 #define _SoundBuffer_H__
 
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
 
 #include <list>
Index: code/branches/usability/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundManager.cc	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/SoundManager.cc	(revision 8005)
@@ -22,8 +22,8 @@
  *   Author:
  *       Erwin 'vaiursch' Herrsche
+ *       
+ *   Co-authors:
  *       Kevin Young
  *       Reto Grieder
- *   Co-authors:
- *      ...
  *
  */
@@ -52,5 +52,6 @@
     ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
 
-    std::string SoundManager::getALErrorString(ALenum code)
+    // From SoundPrereqs.h
+    std::string getALErrorString(ALenum code)
     {
         switch (code)
@@ -80,5 +81,5 @@
 
         if (!alutInitWithoutContext(NULL, NULL))
-            ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
+            ThrowException(InitialisationFailed, "Sound: Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
         Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
 
@@ -112,15 +113,16 @@
             COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
 #endif
-            ThrowException(InitialisationFailed, "Sound Error: Could not open sound device.");
+            ThrowException(InitialisationFailed, "Sound: Error: Could not open sound device.");
         }
         Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
 
         // Create sound context and make it the currently used one
-        this->context_ = alcCreateContext(this->device_, NULL);
+        const ALint contattr[]  = {ALC_SYNC, 1, 0};
+        this->context_ = alcCreateContext(this->device_, contattr);
         if (this->context_ == NULL)
-            ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context");
+            ThrowException(InitialisationFailed, "Sound: Error: Could not create ALC context");
         Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
         if (!alcMakeContextCurrent(this->context_))
-            ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context");
+            ThrowException(InitialisationFailed, "Sound: Error: Could not use ALC context");
 
         GameMode::setPlaysSound(true);
@@ -135,5 +137,5 @@
             COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl;
         else
-            COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
+            COUT(2) << "Sound: Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
 
         this->mute_[SoundType::All]     = 1.0f;
@@ -149,5 +151,5 @@
             this->availableSoundSources_.push_back(source);
         else
-            ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source");
+            ThrowException(InitialisationFailed, "Sound: Error: Could not create even a single source");
         // Create a few initial sources
         this->createSoundSources(this->minSources_ - 1);
@@ -171,5 +173,5 @@
         // If there are still used buffers around, well, that's just very bad...
         if (this->soundBuffers_.size() != this->effectsPool_.size())
-            COUT(1) << "Sound Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
+            COUT(1) << "Sound: Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
         // Empty buffer pool and buffer list
         this->effectsPool_.clear();
@@ -178,5 +180,5 @@
         // There should not be any sources in use anymore
         if (!this->usedSoundSources_.empty())
-            COUT(1) << "Sound Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
+            COUT(1) << "Sound: Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
         while (!this->availableSoundSources_.empty())
         {
@@ -189,21 +191,21 @@
         // Relieve context to destroy it
         if (!alcMakeContextCurrent(NULL))
-            COUT(1) << "Sound Error: Could not unset ALC context" << std::endl;
+            COUT(1) << "Sound: Error: Could not unset ALC context" << std::endl;
         alcDestroyContext(this->context_);
         if (ALCenum error = alcGetError(this->device_))
         {
             if (error == AL_INVALID_OPERATION)
-                COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl;
+                COUT(1) << "Sound: Error: Could not destroy ALC context because it is the current one" << std::endl;
             else
-                COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl;
+                COUT(1) << "Sound: Error: Could not destroy ALC context because it is invalid" << std::endl;
         }
 #ifdef AL_VERSION_1_1
         if (!alcCloseDevice(this->device_))
-            COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
+            COUT(1) << "Sound: Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
 #else
         alcCloseDevice(this->device_);
 #endif
         if (!alutExit())
-            COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
+            COUT(1) << "Sound: Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
     }
 
@@ -251,5 +253,5 @@
         if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 )
         {
-            COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl;
+            COUT(2) << "Sound: Warning: fade step out of range, ignoring change." << std::endl;
             ResetConfigValue(crossFadeStep_);
         }
@@ -260,5 +262,5 @@
         float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f);
         if (clampedVolume != this->volume_[type])
-            COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
+            COUT(2) << "Sound: Warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
         this->updateVolume(type);
     }
@@ -352,5 +354,5 @@
                 if (it->first == newAmbient)
                 {
-                    COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl;
+                    COUT(2) << "Sound: Warning: Will not play an AmbientSound twice." << std::endl;
                     return;
                 }
@@ -620,5 +622,5 @@
             alDeleteSources(1, &this->availableSoundSources_.back());
             if (alGetError())
-                COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl;
+                COUT(1) << "Sound: Error: Failed to delete a source --> lost forever" << std::endl;
             this->availableSoundSources_.pop_back();
         }
Index: code/branches/usability/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundManager.h	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/SoundManager.h	(revision 8005)
@@ -22,8 +22,8 @@
  *   Author:
  *       Erwin 'vaiursch' Herrsche
+ *       
+ *   Co-authors:
  *       Kevin Young
  *       Reto Grieder
- *   Co-authors:
- *      ...
  */
 
@@ -31,5 +31,5 @@
 #define _SoundManager_H__
 
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
 
 #include <list>
@@ -99,6 +99,4 @@
         void releaseSoundSource(ALuint source);
 
-        static std::string getALErrorString(ALenum error);
-
     private:
         void processCrossFading(float dt);
Index: code/branches/usability/src/orxonox/sound/SoundPrereqs.h
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundPrereqs.h	(revision 8005)
+++ code/branches/usability/src/orxonox/sound/SoundPrereqs.h	(revision 8005)
@@ -0,0 +1,70 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+/**
+@file
+@brief
+    Enums, constants, functions and forward declarations for the sound files.
+*/
+
+#ifndef _SoundPrereqs_H__
+#define _SoundPrereqs_H__
+
+#include "OrxonoxPrereqs.h"
+
+//-----------------------------------------------------------------------
+// Forward declarations
+//-----------------------------------------------------------------------
+
+namespace orxonox
+{
+    class AmbientSound;
+    class BaseSound;
+    class SoundBuffer;
+    class SoundManager;
+    class SoundStreamer;
+    class WorldSound;
+}
+
+typedef struct ALCcontext_struct ALCcontext;
+typedef struct ALCdevice_struct ALCdevice;
+typedef unsigned int ALuint;
+typedef int ALint;
+typedef int ALenum;
+
+//-----------------------------------------------------------------------
+// Helper functions
+//-----------------------------------------------------------------------
+
+namespace orxonox
+{
+    //! Returns an error string for an AL error code
+    _OrxonoxExport std::string getALErrorString(ALenum error);
+}
+
+#endif /* _SoundPrereqs_H__ */
Index: code/branches/usability/src/orxonox/sound/SoundStreamer.cc
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundStreamer.cc	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/SoundStreamer.cc	(revision 8005)
@@ -27,7 +27,10 @@
 #include "SoundStreamer.h"
 
-#include <al.h>
+#include <boost/thread.hpp>
+#include <AL/al.h>
+#include <AL/alc.h>
 #include <vorbis/vorbisfile.h>
 #include "SoundManager.h"
+#include "util/Sleep.h"
 
 namespace orxonox
@@ -38,23 +41,9 @@
     long tellVorbis(void* datasource);
 
-    void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream)
+    void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section)
     {
-        // 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);
-            return;
-        }
+        char inbuffer[4096];
         vorbis_info* vorbisInfo;
-        vorbisInfo = ov_info(&vf, -1);
+        vorbisInfo = ov_info(vf, -1);
         ALenum format;
         if (vorbisInfo->channels == 1)
@@ -63,34 +52,28 @@
             format = AL_FORMAT_STEREO16;
 
-        char inbuffer[256*1024];
-        ALuint initbuffers[4];
-        alGenBuffers(4, initbuffers);
-        int current_section;
+        while(true) // Stream forever, control through thread control
+        {
 
-        for(int i = 0; i < 4; i++)
-        {
-            long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
-            if (ret == 0)
+            int info;
+            alGetSourcei(audioSource, AL_SOURCE_STATE, &info);
+            if(info == AL_PLAYING)
+                COUT(4) << "Sound: " << dataStream->getName() << " is playing." << std::endl;
+            else
             {
-                return;
+                COUT(4) << "Sound: " << dataStream->getName() << " is not playing." << std::endl;
             }
-            else if (ret < 0)
+
+            if(alcGetCurrentContext() == NULL)
             {
-                COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
-                ov_clear(&vf);
+                COUT(2) << "Sound: There is no context, terminating thread for " << dataStream->getName() << std::endl;
                 return;
             }
 
-            alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);
-        }
-        alSourceQueueBuffers(audioSource, 4, initbuffers);
-
-        while(true) // Stream forever, control through thread control
-        {
             int processed;
             alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed);
             if (ALint error = alGetError())
-            COUT(2) << "Sound Warning: Couldn't get number of processed buffers: "
-                    << SoundManager::getALErrorString(error) << std::endl;
+                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)
@@ -99,28 +82,58 @@
                 alSourceUnqueueBuffers(audioSource, processed, buffers);
                 if (ALint error = alGetError())
-                    COUT(2) << "Sound Warning: Couldn't unqueue buffers: "
-                    << SoundManager::getALErrorString(error) << std::endl;
+                    COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl;
+            
+                int queued;
+                alGetSourcei(audioSource, AL_BUFFERS_QUEUED, &queued);
+                if (ALint error = alGetError())
+                    COUT(2) << "Sound: Warning: Couldn't get number of queued buffers: " << getALErrorString(error) << std::endl;
+                COUT(4) << "Sound: queued buffers: " << queued << std::endl;
 
                 for(int i = 0; i < processed; i++)
                 {
-                    long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
+                    long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
                     if (ret == 0)
                     {
+                        COUT(4) << "Sound: End of file " << dataStream->getName() << ", terminating thread" << std::endl;
                         return;
                     }
                     else if (ret < 0)
                     {
-                        COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
-                        ov_clear(&vf);
+                        COUT(2) << "Sound: libvorbisfile: error reading the file " << dataStream->getName() << std::endl;
+                        ov_clear(vf);
                         return;
                     }
 
                     alBufferData(buffers[i], format, &inbuffer, ret, vorbisInfo->rate);
+                    if(ALint error = alGetError()) {
+                        COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
+                        break;
+                    }
+                    alSourceQueueBuffers(audioSource, 1, &buffers[i]);
+                    if (ALint error = alGetError()) {
+                        COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
+                    }
                 }
+            }
+            else
+            {
+                msleep(10); // perhaps another value here is better
+            }
 
-                alSourceQueueBuffers(audioSource, processed, buffers);
+            try {
+                boost::this_thread::interruption_point();
+            }
+            catch(boost::thread_interrupted) {
+                COUT(4) << "Sound: Catched interruption. Terminating thread for " << dataStream->getName() << std::endl;
+                ALuint* buffers = new ALuint[5];
+                alSourceUnqueueBuffers(audioSource, 5, buffers);
                 if (ALint error = alGetError())
-                    COUT(2) << "Sound Warning: Couldn't queue buffers: "
-                    << SoundManager::getALErrorString(error) << std::endl;
+                    COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl;
+
+                alDeleteBuffers(5, buffers);
+                if (ALint error = alGetError())
+                    COUT(2) << "Sound: Warning: Couldn't delete buffers: " << getALErrorString(error) << std::endl;
+
+                return;
             }
         }
Index: code/branches/usability/src/orxonox/sound/SoundStreamer.h
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundStreamer.h	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/SoundStreamer.h	(revision 8005)
@@ -29,7 +29,8 @@
 #define _SoundStreamer_H__
 
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
 
 #include <string>
+#include <vorbis/vorbisfile.h>
 #include <OgreDataStream.h>
 #include "core/CorePrereqs.h"
@@ -40,5 +41,5 @@
     {
     public:
-        void operator()(ALuint audioSource, DataStreamPtr dataStream);
+        void operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section);
     };
 }
Index: code/branches/usability/src/orxonox/sound/WorldSound.h
===================================================================
--- code/branches/usability/src/orxonox/sound/WorldSound.h	(revision 8003)
+++ code/branches/usability/src/orxonox/sound/WorldSound.h	(revision 8005)
@@ -30,5 +30,5 @@
 #define _WorldSound_H__
 
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
 
 #include "tools/interfaces/Tickable.h"
Index: code/branches/usability/src/orxonox/weaponsystem/WeaponMode.cc
===================================================================
--- code/branches/usability/src/orxonox/weaponsystem/WeaponMode.cc	(revision 8003)
+++ code/branches/usability/src/orxonox/weaponsystem/WeaponMode.cc	(revision 8005)
@@ -24,5 +24,5 @@
  *      Fabian 'x3n' Landau
  *   Co-authors:
- *      ...
+ *      Kevin Young
  *
  */
Index: code/branches/usability/src/orxonox/weaponsystem/WeaponMode.h
===================================================================
--- code/branches/usability/src/orxonox/weaponsystem/WeaponMode.h	(revision 8003)
+++ code/branches/usability/src/orxonox/weaponsystem/WeaponMode.h	(revision 8005)
@@ -24,5 +24,5 @@
  *      Fabian 'x3n' Landau
  *   Co-authors:
- *      ...
+ *      Kevin Young
  *
  */
@@ -41,4 +41,9 @@
 namespace orxonox
 {
+    /**
+     * The WeaponMode class enables the developer, amongst other things, to attach a sound file
+     * to the firing event of a weapon. The default firing sound is chosen by each weapon (ex.
+     * HsW01), hard-coded for now.
+     */
     class _OrxonoxExport WeaponMode : public BaseObject
     {
