Index: code/branches/sound3/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/sound3/src/orxonox/sound/BaseSound.cc	(revision 6070)
+++ code/branches/sound3/src/orxonox/sound/BaseSound.cc	(revision 6071)
@@ -29,4 +29,5 @@
 #include "BaseSound.h"
 
+#include <cassert>
 #include <vector>
 #include <AL/alut.h>
@@ -42,11 +43,14 @@
         : audioSource_(0)
         , audioBuffer_(0)
-        , bPlayOnLoad_(false)
         , bLoop_(false)
+        , state_(Stopped)
     {
         RegisterRootObject(BaseSound);
 
         if (GameMode::playsSound())
+        {
             alGenSources(1, &this->audioSource_);
+            assert(this->audioSource_ != 0);
+        }
     }
 
@@ -54,5 +58,5 @@
     {
         this->setSource("");
-        if (this->audioSource_)
+        if (GameMode::playsSound())
             alDeleteSources(1, &this->audioSource_);
     }
@@ -60,16 +64,11 @@
     void BaseSound::play()
     {
-        if (alIsSource(this->audioSource_))
-        {
-            if (this->bLoop_)
-                alSourcei(this->audioSource_, AL_LOOPING, AL_TRUE);
-            else
-                alSourcei(this->audioSource_, AL_LOOPING, AL_FALSE);
+        if (!this->isPlaying() && GameMode::showsGraphics())
+        {
+            this->state_ = Playing;
             alSourcePlay(this->audioSource_);
 
             if (alGetError() != AL_NO_ERROR)
-            {
                  COUT(2) << "Sound: OpenAL: Error playing sound " << this->audioSource_ << std::endl;
-            }
         }
     }
@@ -77,5 +76,6 @@
     void BaseSound::stop()
     {
-        if (alIsSource(this->audioSource_))
+        this->state_ = Stopped;
+        if (GameMode::playsSound())
             alSourceStop(this->audioSource_);
     }
@@ -83,27 +83,9 @@
     void BaseSound::pause()
     {
-        if (alIsSource(this->audioSource_))
+        if (this->isStopped())
+            return;
+        this->state_ = Paused;
+        if (GameMode::playsSound())
             alSourcePause(this->audioSource_);
-    }
-
-    bool BaseSound::isPlaying()
-    {
-        if (alIsSource(this->audioSource_))
-            return getSourceState() == AL_PLAYING;
-        return false;
-    }
-
-    bool BaseSound::isPaused()
-    {
-        if (alIsSource(this->audioSource_))
-            return getSourceState() == AL_PAUSED;
-        return false;
-    }
-
-    bool BaseSound::isStopped()
-    {
-        if (alIsSource(this->audioSource_))
-            return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;
-        return true;
     }
 
@@ -121,4 +103,11 @@
     }
 
+    void BaseSound::setLooping(bool val)
+    {
+        this->bLoop_ = val;
+        if (GameMode::playsSound())
+            alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE));
+    }
+
     void BaseSound::setSource(const std::string& source)
     {
@@ -128,8 +117,8 @@
             return;
         }
-        
-        if (alIsSource(this->audioBuffer_))
-        {
-            this->stop();
+
+        if (this->audioBuffer_ != 0 && alIsBuffer(this->audioBuffer_))
+        {
+            alSourceStop(this->audioSource_);
             // Unload old sound first
             alSourcei(this->audioSource_, AL_BUFFER, 0);
@@ -183,16 +172,13 @@
 
         alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
-
-        this->setVolume(this->volume_);
-
-        if (this->bPlayOnLoad_)
-            this->play();
-    }
-
-    ALint BaseSound::getSourceState()
-    {
-        ALint state;
-        alGetSourcei(this->audioSource_, AL_SOURCE_STATE, &state);
-        return state;
+        alSourcef (this->audioSource_, AL_GAIN, this->volume_);
+        alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE));
+        if (this->isPlaying() || this->isPaused())
+            alSourcePlay(this->audioSource_);
+        if (this->isPaused())
+            alSourcePause(this->audioSource_);
+
+        if (alGetError() != AL_NO_ERROR)
+            COUT(2) << "Sound: OpenAL: Error playing sound " << this->audioSource_ << std::endl;
     }
 
