[Orxonox-commit 1654] r6372 - in code/branches/presentation2/src/orxonox: . sound

rgrieder at orxonox.net rgrieder at orxonox.net
Thu Dec 17 16:52:45 CET 2009


Author: rgrieder
Date: 2009-12-17 16:52:45 +0100 (Thu, 17 Dec 2009)
New Revision: 6372

Modified:
   code/branches/presentation2/src/orxonox/Scene.cc
   code/branches/presentation2/src/orxonox/Scene.h
   code/branches/presentation2/src/orxonox/sound/BaseSound.cc
   code/branches/presentation2/src/orxonox/sound/WorldSound.cc
Log:
Added new XML parameter for the Scene: soundReferenceDistance.
This value represents the distance to a sound source where the gain is still 1.0. Further away it will decrease with 1/(distance - soundReferenceDistance).
Default value is 20.

Modified: code/branches/presentation2/src/orxonox/Scene.cc
===================================================================
--- code/branches/presentation2/src/orxonox/Scene.cc	2009-12-17 15:39:34 UTC (rev 6371)
+++ code/branches/presentation2/src/orxonox/Scene.cc	2009-12-17 15:52:45 UTC (rev 6372)
@@ -57,6 +57,7 @@
 
         this->setScene(SmartPtr<Scene>(this, false), OBJECTID_UNKNOWN);
         this->bShadows_ = true;
+        this->soundReferenceDistance_ = 20.0;
 
         if (GameMode::showsGraphics())
         {
@@ -112,6 +113,7 @@
         XMLPortParam(Scene, "skybox", setSkybox, getSkybox, xmlelement, mode);
         XMLPortParam(Scene, "ambientlight", setAmbientLight, getAmbientLight, xmlelement, mode).defaultValues(ColourValue(0.2f, 0.2f, 0.2f, 1.0f));
         XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true);
+        XMLPortParam(Scene, "soundReferenceDistance", setSoundReferenceDistance, getSoundReferenceDistance, xmlelement, mode).defaultValues(true);
 
         XMLPortParam(Scene, "gravity", setGravity, getGravity, xmlelement, mode);
         XMLPortParam(Scene, "negativeWorldRange", setNegativeWorldRange, getNegativeWorldRange, xmlelement, mode);

Modified: code/branches/presentation2/src/orxonox/Scene.h
===================================================================
--- code/branches/presentation2/src/orxonox/Scene.h	2009-12-17 15:39:34 UTC (rev 6371)
+++ code/branches/presentation2/src/orxonox/Scene.h	2009-12-17 15:52:45 UTC (rev 6372)
@@ -70,6 +70,11 @@
             inline bool getShadow() const
                 { return this->bShadows_; }
 
+            inline void setSoundReferenceDistance(float distance)
+                { this->soundReferenceDistance_ = distance; }
+            inline float getSoundReferenceDistance() const
+                { return this->soundReferenceDistance_; }
+
             inline Radar* getRadar()
                 { return this->radar_; }
             
@@ -95,6 +100,7 @@
             ColourValue              ambientLight_;
             std::list<BaseObject*>   objects_;
             bool                     bShadows_;
+            float                    soundReferenceDistance_;
             Radar*                   radar_;
 
 

Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.cc	2009-12-17 15:39:34 UTC (rev 6371)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.cc	2009-12-17 15:52:45 UTC (rev 6372)
@@ -131,8 +131,6 @@
         alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
         alSource3f(this->audioSource_, AL_VELOCITY,  0, 0, 0);
         alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);
-        alSourcei(this->audioSource_, AL_REFERENCE_DISTANCE, 20);
-        alSourcei(this->audioSource_, AL_MAX_DISTANCE, 10000);
         if (ALint error = alGetError())
             COUT(2) << "Sound Warning: Setting source parameters to 0 failed: "
                     << SoundManager::getALErrorString(error) << std::endl;

Modified: code/branches/presentation2/src/orxonox/sound/WorldSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/WorldSound.cc	2009-12-17 15:39:34 UTC (rev 6371)
+++ code/branches/presentation2/src/orxonox/sound/WorldSound.cc	2009-12-17 15:52:45 UTC (rev 6372)
@@ -34,6 +34,7 @@
 #include "core/CoreIncludes.h"
 #include "core/EventIncludes.h"
 #include "core/XMLPort.h"
+#include "Scene.h"
 #include "SoundManager.h"
 #include <core/ConsoleCommandCompilation.h>
 
@@ -78,6 +79,13 @@
     void WorldSound::initialiseSource()
     {
         BaseSound::initialiseSource();
+        if (this->getScene())
+        {
+            float refDist = this->getScene()->getSoundReferenceDistance();
+            alSourcei(this->audioSource_, AL_REFERENCE_DISTANCE, refDist);
+            // TODO: 500 is very magical here. Derive something better
+            alSourcei(this->audioSource_, AL_MAX_DISTANCE, refDist * 500);
+        }
         this->tick(0); // update position, orientation and velocity
     }
 




More information about the Orxonox-commit mailing list