Index: code/branches/presentation2/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.cc	(revision 6298)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.cc	(revision 6322)
@@ -87,5 +87,5 @@
             COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
 #endif
-            ThrowException(InitialisationFailed, "Sound: OpenAL error: Could not open sound device.");
+            ThrowException(InitialisationFailed, "Sound Error: Could not open sound device.");
         }
         Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
@@ -100,4 +100,5 @@
 
         GameMode::setPlaysSound(true);
+        Loki::ScopeGuard resetPlaysSoundGuard = Loki::MakeGuard(&GameMode::setPlaysSound, false);
 
         // Get some information about the sound
@@ -110,4 +111,31 @@
         else
             COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
+        
+        this->setVolumeInternal(1.0, SoundType::none);
+        this->setVolumeInternal(1.0, SoundType::ambient);
+        this->setVolumeInternal(1.0, SoundType::effects);
+        
+        this->mute_[SoundType::none] = false;
+        this->mute_[SoundType::ambient] = false;
+        this->mute_[SoundType::effects] = false;
+
+        this->setConfigValues();
+
+        // Try to get at least one source
+        ALuint source;
+        alGenSources(1, &source);
+        if (!alGetError() && alIsSource(source))
+            this->soundSources_.push_back(source);
+        else
+            ThrowException(InitialisationFailed, "Sound Error: Could not even create a single source");
+        // Get the rest of the sources
+        alGenSources(1, &source);
+        unsigned int count = 1;
+        while (alIsSource(source) && !alGetError() && count <= this->maxSources_)
+        {
+            this->soundSources_.push_back(source);
+            alGenSources(1, &source);
+            ++count;
+        }
 
         // Disarm guards
@@ -115,14 +143,5 @@
         closeDeviceGuard.Dismiss();
         desroyContextGuard.Dismiss();
-        
-        this->setVolumeInternal(1.0, SoundType::none);
-        this->setVolumeInternal(1.0, SoundType::ambient);
-        this->setVolumeInternal(1.0, SoundType::effects);
-        
-        this->mute_[SoundType::none] = false;
-        this->mute_[SoundType::ambient] = false;
-        this->mute_[SoundType::effects] = false;
-
-        this->setConfigValues();
+        resetPlaysSoundGuard.Dismiss();
 
         COUT(4) << "Sound: Initialisation complete" << std::endl;
@@ -164,16 +183,19 @@
             .description("Determines how fast sounds should fade, per second.")
             .callback(this, &SoundManager::checkFadeStepValidity);
-            
+
         SetConfigValue(soundVolume_, 1.0f)
             .description("Defines the overall volume.")
             .callback(this, &SoundManager::checkSoundVolumeValidity);
-            
+
         SetConfigValue(ambientVolume_, 1.0f)
             .description("Defines the ambient volume.")
             .callback(this, &SoundManager::checkAmbientVolumeValidity);
-            
+
         SetConfigValue(effectsVolume_, 1.0f)
             .description("Defines the effects volume.")
             .callback(this, &SoundManager::checkEffectsVolumeValidity);
+
+        SetConfigValue(maxSources_, 1024)
+            .description("Maximum number of sources to be made available");
     }
 
@@ -595,3 +617,29 @@
         }
     }
+
+    ALuint SoundManager::getSoundSource()
+    {
+        if (!this->soundSources_.empty())
+        {
+            ALuint source = this->soundSources_.back();
+            this->soundSources_.pop_back();
+            return source;
+        }
+        else
+        {
+            // Return no source ID
+            ALuint source = 123456789;
+            while (alIsSource(++source));
+            return source;
+        }
+    }
+
+    void SoundManager::releaseSoundSource(ALuint source)
+    {
+#ifndef NDEBUG
+        for (std::vector<ALuint>::const_iterator it = this->soundSources_.begin(); it != this->soundSources_.end(); ++it)
+            assert((*it) != source);
+#endif
+        this->soundSources_.push_back(source);
+    }
 }
