Index: code/branches/sound/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/sound/src/orxonox/CMakeLists.txt	(revision 2965)
+++ code/branches/sound/src/orxonox/CMakeLists.txt	(revision 2966)
@@ -31,4 +31,5 @@
 ADD_SUBDIRECTORY(overlays)
 ADD_SUBDIRECTORY(tools)
+ADD_SUBDIRECTORY(sound)
 GET_ALL_HEADER_FILES(ORXONOX_HDR_FILES)
 SET(ORXONOX_FILES ${ORXONOX_SRC_FILES} ${ORXONOX_HDR_FILES})
@@ -51,4 +52,9 @@
   ${CEGUILUA_LIBRARY}
   ${Boost_SYSTEM_LIBRARY}
+  ${OPENAL_LIBRARY}
+  ${ALUT_LIBRARY}
+  #${VORBISFILE_LIBRARY}
+  #${VORBIS_LIBRARY}
+  #${OGG_LIBRARY}
   ogreceguirenderer_orxonox
   tinyxml++_orxonox
@@ -58,5 +64,4 @@
   core
   network
-  sound
 )
 
Index: code/branches/sound/src/orxonox/objects/Level.cc
===================================================================
--- code/branches/sound/src/orxonox/objects/Level.cc	(revision 2965)
+++ code/branches/sound/src/orxonox/objects/Level.cc	(revision 2966)
@@ -57,4 +57,6 @@
         if (this->xmlfilename_.length() >= Core::getMediaPathString().length())
             this->xmlfilename_ = this->xmlfilename_.substr(Core::getMediaPathString().length());
+            
+        this->sndmgr_ = new SoundManager();
     }
 
@@ -68,4 +70,9 @@
             if (this->xmlfile_)
                 Loader::unload(this->xmlfile_);
+            
+            if(this->ambientsound_ != NULL)
+                delete this->ambientsound_;
+            
+            delete this->sndmgr_;
         }
     }
@@ -158,5 +165,5 @@
             {
                 this->ambientsound_ = new SoundBase();
-                this->sndmgr_.addSound(this->ambientsound_);
+                this->sndmgr_->addSound(this->ambientsound_);
             }
 
Index: code/branches/sound/src/orxonox/objects/Level.h
===================================================================
--- code/branches/sound/src/orxonox/objects/Level.h	(revision 2965)
+++ code/branches/sound/src/orxonox/objects/Level.h	(revision 2966)
@@ -73,5 +73,5 @@
             XMLFile*               xmlfile_;
             std::list<BaseObject*> objects_;
-            SoundManager           sndmgr_;
+            SoundManager*          sndmgr_;
             SoundBase*             ambientsound_;
     };
Index: code/branches/sound/src/orxonox/sound/CMakeLists.txt
===================================================================
--- code/branches/sound/src/orxonox/sound/CMakeLists.txt	(revision 2966)
+++ code/branches/sound/src/orxonox/sound/CMakeLists.txt	(revision 2966)
@@ -0,0 +1,8 @@
+ADD_SOURCE_FILES(ORXONOX_SRC_FILES
+    SoundManager.h
+    SoundBase.h
+
+    SoundManager.cc
+    SoundBase.cc
+)
+
Index: code/branches/sound/src/orxonox/sound/SoundBase.cc
===================================================================
--- code/branches/sound/src/orxonox/sound/SoundBase.cc	(revision 2966)
+++ code/branches/sound/src/orxonox/sound/SoundBase.cc	(revision 2966)
@@ -0,0 +1,151 @@
+/*
+ *   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:
+ *       Erwin 'vaiursch' Herrsche
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "orxonox/objects/worldentities/WorldEntity.h"
+#include "util/Math.h"
+#include "SoundManager.h"
+#include "SoundBase.h"
+
+namespace orxonox 
+{
+    SoundBase::SoundBase()
+    {
+        this->source_ = 0;
+        this->buffer_ = 0;
+        this->entity_ = NULL;
+    }
+
+    SoundBase::SoundBase(WorldEntity* entity)
+    {
+        this->source_ = 0;
+        this->buffer_ = 0;
+        this->entity_ = entity;
+    }
+
+    SoundBase::~SoundBase()
+    {
+        alSourcei(this->source_, AL_BUFFER, 0);
+        alDeleteSources(1, &this->source_);
+        alDeleteBuffers(1, &this->buffer_);
+    }
+
+    void SoundBase::attachToEntity(WorldEntity* entity)
+    {
+        this->entity_ = entity;
+        this->update();
+    }
+
+    void SoundBase::update() {
+        if(this->entity_ != NULL && alIsSource(this->source_)) {
+            Vector3 pos = this->entity_->getPosition();
+            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;
+
+            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;
+
+            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;
+        }
+    }
+
+    void SoundBase::play(bool loop) {
+        if(alIsSource(this->source_)) {
+            if(loop)
+                alSourcei(this->source_, AL_LOOPING, AL_TRUE);
+            else
+                alSourcei(this->source_, AL_LOOPING, AL_FALSE);
+            alSourcePlay(this->source_);
+        }
+    }
+
+    void SoundBase::stop() {
+        if(alIsSource(this->source_)) {
+            alSourceStop(this->source_);
+        }
+    }
+
+    void SoundBase::pause() {
+        if(alIsSource(this->source_)) {
+            alSourcePause(this->source_);
+        }
+    }
+
+    bool SoundBase::isPlaying() {
+        if(alIsSource(this->source_)) {
+            return getSourceState() == AL_PLAYING;
+        }
+        return false;
+    }
+
+    bool SoundBase::isPaused() {
+        if(alIsSource(this->source_)) {
+            return getSourceState() == AL_PAUSED;
+        }
+        return true;
+    }
+
+    bool SoundBase::isStopped() {
+        if(alIsSource(this->source_)) {
+            return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;
+        }
+        return true;
+    }
+
+    bool SoundBase::loadFile(std::string filename) {
+        COUT(3) << "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;
+            return false;
+        }
+
+        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;
+            return false;
+        }
+        return true;
+    }
+
+    ALint SoundBase::getSourceState() {
+        ALint state;
+        alGetSourcei(this->source_, AL_SOURCE_STATE, &state);
+        return state;
+    }
+} // namespace: orxonox
Index: code/branches/sound/src/orxonox/sound/SoundBase.h
===================================================================
--- code/branches/sound/src/orxonox/sound/SoundBase.h	(revision 2966)
+++ code/branches/sound/src/orxonox/sound/SoundBase.h	(revision 2966)
@@ -0,0 +1,72 @@
+/*
+ *   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:
+ *       Erwin 'vaiursch' Herrsche
+ *   Co-authors:
+ *      ...
+ *
+ */
+#ifndef _SOUNDBASE_H__
+#define _SOUNDBASE_H__
+
+#include <AL/al.h>
+#include <AL/alut.h>
+#include <string>
+
+namespace orxonox
+{
+    class SoundManager;
+    class WorldEntity;
+    /**
+     * The SoudBase class is the base class for all sound file loader classes.
+     * It server as main interface to the OpenAL library.
+     *
+     */
+    class _OrxonoxExport SoundBase
+    {
+    public:
+        SoundBase();
+        SoundBase(WorldEntity* entity);
+        ~SoundBase();
+
+        void attachToEntity(WorldEntity* entity);
+        void update();
+        void play(bool loop = false);
+        void stop();
+        void pause();
+
+        bool isPlaying();
+        bool isPaused();
+        bool isStopped();
+
+        bool loadFile(std::string filename);
+
+    private:
+        ALuint source_;
+        ALuint buffer_;
+        WorldEntity* entity_;
+
+        ALint getSourceState();
+    }; // class SoundBase
+} // namepsace orxonox
+
+#endif // _SOUNDBASE_H__
Index: code/branches/sound/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/sound/src/orxonox/sound/SoundManager.cc	(revision 2966)
+++ code/branches/sound/src/orxonox/sound/SoundManager.cc	(revision 2966)
@@ -0,0 +1,146 @@
+/*
+ *   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:
+ *       Erwin 'vaiursch' Herrsche
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include <AL/alut.h>
+
+#include "orxonox/CameraManager.h"
+#include "orxonox/objects/worldentities/Camera.h"
+#include "util/Math.h"
+#include "SoundBase.h"
+#include "SoundManager.h"
+
+namespace orxonox
+{
+    ALCdevice* SoundManager::device_s = NULL;
+
+    /**
+     * Default constructor
+     */
+    SoundManager::SoundManager()
+    {
+        if(!alutInitWithoutContext(NULL,NULL))
+        {
+            COUT(2) << "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;
+            if(SoundManager::device_s == NULL)
+            {
+                COUT(3) << "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;
+            }
+            else
+            {
+                this->context_ = alcCreateContext(SoundManager::device_s, NULL);
+                if(this->context_ == NULL)
+                {
+                    COUT(2) << "OpenAL: Could not create sound context";
+                }
+                else
+                {
+                    alcMakeContextCurrent(this->context_);
+                }
+            }
+        }
+    }
+
+    SoundManager::~SoundManager()
+    {
+        alcDestroyContext(this->context_);
+        alcCloseDevice(SoundManager::device_s);
+        alutExit();
+    }
+
+    /**
+     * Add a SoundBase object to the list. Every SoundBase object should be in
+     * this list.
+     *
+     * @param sound Pointer to the SoundBase object to add
+     */
+    void SoundManager::addSound(SoundBase* sound)
+    {
+        this->soundlist_.push_back(sound);
+    }
+
+    /**
+     * Remove a SoundBase object from the list and destroy it.
+     */
+    void SoundManager::removeSound(SoundBase* sound)
+    {
+        std::list<SoundBase*>::iterator pos = this->soundlist_.end();
+        for(std::list<SoundBase*>::iterator i = this->soundlist_.begin(); i != this->soundlist_.end(); i++)
+        {
+            if((*i) == sound)
+                pos = i;
+        }
+
+        delete (*pos);
+        this->soundlist_.erase(pos);
+    }
+
+    /**
+     * Tick function, updates listener and registred SoundBase objects
+     *
+     * @param dt @see Orxonox::Tickable
+     */
+    void SoundManager::tick(float dt)
+    {
+        // update listener position
+        Camera* camera = CameraManager::getInstance().getActiveCamera();
+        if(camera == NULL) return;
+        Vector3 pos = camera->getPosition();
+        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;
+
+        // update listener orientation
+        Quaternion orient = camera->getOrientation();
+        Vector3 up = orient.xAxis(); // just a wild guess
+        Vector3 at = orient.zAxis();
+
+        ALfloat orientation[6] = { at.x, at.y, at.z, 
+                                 up.x, up.y, up.z };
+
+        alListenerfv(AL_POSITION, orientation);
+        error = alGetError();
+        if(error == AL_INVALID_VALUE)
+            COUT(2) << "OpenAL: Invalid listener orientation" << std::endl;
+
+        // update sounds
+        for(std::list<SoundBase*>::iterator i = this->soundlist_.begin(); i != this->soundlist_.end(); i++)
+            (*i)->update();
+    }
+}
Index: code/branches/sound/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/sound/src/orxonox/sound/SoundManager.h	(revision 2966)
+++ code/branches/sound/src/orxonox/sound/SoundManager.h	(revision 2966)
@@ -0,0 +1,63 @@
+/*
+ *   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:
+ *       Erwin 'vaiursch' Herrsche
+ *   Co-authors:
+ *      ...
+ */
+#ifndef _SOUNDMANGER_H__
+#define _SOUNDMANGER_H__
+
+#include <AL/al.h>
+#include <AL/alc.h>
+
+#include <orxonox/objects/Tickable.h>
+
+namespace orxonox
+{
+    class SoundBase;
+
+    /**
+     * The SoundManager class manages the OpenAL device, context and listener
+     * position. It has a list of all SoundBase objects and calls their update
+     * function every tick. It is a singleton.
+     *
+     */
+    class _OrxonoxExport SoundManager : public Tickable 
+    {
+    public:
+        SoundManager();
+        ~SoundManager();
+        void addSound(SoundBase* sound);
+        void removeSound(SoundBase* sound);
+
+        virtual void tick(float dt);
+
+    private:
+        static ALCdevice* device_s;
+        ALCcontext* context_;
+        std::list<SoundBase*> soundlist_;
+
+    }; // class SoundManager
+} // namespace orxonox
+
+#endif // _SOUNDMANAGER_H__
