[Orxonox-commit 1466] r6184 - in code/branches/presentation2/src/orxonox: . sound
dafrick at orxonox.net
dafrick at orxonox.net
Mon Nov 30 20:50:44 CET 2009
Author: dafrick
Date: 2009-11-30 20:50:44 +0100 (Mon, 30 Nov 2009)
New Revision: 6184
Modified:
code/branches/presentation2/src/orxonox/CMakeLists.txt
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
code/branches/presentation2/src/orxonox/sound/BaseSound.h
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
code/branches/presentation2/src/orxonox/sound/SoundManager.h
Log:
Created capability in SoundManager to set an overall volume, and to also adjust general ambient and effects volumes.
For this to work, you need to delete your config-file (orxonox.ini) so that it can be reset.
It has still som quirks, though.
Modified: code/branches/presentation2/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/presentation2/src/orxonox/CMakeLists.txt 2009-11-30 10:07:06 UTC (rev 6183)
+++ code/branches/presentation2/src/orxonox/CMakeLists.txt 2009-11-30 19:50:44 UTC (rev 6184)
@@ -58,6 +58,7 @@
MoodManager.h
pickup/BaseItem.h
pickup/PickupInventory.h
+ sound/SoundManager.h
DEFINE_SYMBOL
"ORXONOX_SHARED_BUILD"
PCH_FILE
Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.cc 2009-11-30 10:07:06 UTC (rev 6183)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.cc 2009-11-30 19:50:44 UTC (rev 6184)
@@ -108,8 +108,27 @@
}
this->volume_ = vol;
if (alIsSource(this->audioSource_))
- alSourcef(this->audioSource_, AL_GAIN, vol);
+ alSourcef(this->audioSource_, AL_GAIN, this->getEffectiveVolume());
}
+
+ void BaseSound::setVolumeGain(float gain)
+ {
+ COUT(1) << "blubb: " << gain << std::endl;
+ if (gain > 1 || gain < 0)
+ {
+ COUT(2) << "Sound warning: volume gain out of range, cropping value." << std::endl;
+ gain = gain > 1 ? 1 : gain;
+ gain = gain < 0 ? 0 : gain;
+ }
+ this->volumeGain_ = gain;
+ if (alIsSource(this->audioSource_))
+ alSourcef(this->audioSource_, AL_GAIN, this->getEffectiveVolume());
+ }
+
+ float BaseSound::getEffectiveVolume(void)
+ {
+ return this->volume_*this->volumeGain_;
+ }
void BaseSound::setLooping(bool val)
{
@@ -180,7 +199,7 @@
}
alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0);
- alSourcef (this->audioSource_, AL_GAIN, this->volume_);
+ alSourcef (this->audioSource_, AL_GAIN, this->getEffectiveVolume());
alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE));
if (this->isPlaying() || this->isPaused())
alSourcePlay(this->audioSource_);
Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.h 2009-11-30 10:07:06 UTC (rev 6183)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.h 2009-11-30 19:50:44 UTC (rev 6184)
@@ -63,6 +63,12 @@
void setVolume(float vol);
float getVolume() const { return this->volume_; }
+
+ void setVolumeGain(float gain);
+ inline float getVolumeGain()
+ { return this->volumeGain_; }
+
+ float getEffectiveVolume(void);
bool getLooping() const { return this->bLoop_; }
void setLooping(bool val);
@@ -85,6 +91,7 @@
std::string source_;
float volume_;
+ float volumeGain_;
bool bLoop_;
State state_;
DataStreamPtr dataStream_;
Modified: code/branches/presentation2/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.cc 2009-11-30 10:07:06 UTC (rev 6183)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.cc 2009-11-30 19:50:44 UTC (rev 6184)
@@ -42,6 +42,7 @@
#include "core/ConfigValueIncludes.h"
#include "BaseSound.h"
#include "AmbientSound.h"
+#include "WorldSound.h"
namespace orxonox
{
@@ -89,6 +90,10 @@
alutExitGuard.Dismiss();
closeDeviceGuard.Dismiss();
desroyContextGuard.Dismiss();
+
+ this->volume_ = 1.0;
+ this->ambientVolume_ = 1.0;
+ this->effectsVolume_ = 1.0;
this->setConfigValues();
}
@@ -111,6 +116,18 @@
SetConfigValue(crossFadeStep_, 0.2f)
.description("Determines how fast sounds should fade, per second.")
.callback(this, &SoundManager::checkFadeStepValidity);
+
+ SetConfigValue(volume_, 1.0f)
+ .description("Defines the overall volume.")
+ .callback(this, &SoundManager::checkVolumeValidity);
+
+ 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);
}
void SoundManager::checkFadeStepValidity()
@@ -123,6 +140,45 @@
COUT(3) << "SoundManager: fade step set to " << crossFadeStep_ << std::endl;
return;
}
+
+ void SoundManager::checkVolumeValidity()
+ {
+ if(volume_ < 0.0 || volume_ > 1.0)
+ {
+ COUT(2) << "Sound warning: Sound volume out of range, ignoring change." << std::endl;
+ ResetConfigValue(volume_);
+ }
+
+ this->updateVolume();
+ COUT(3) << "SoundManager: Overall volume set to " << volume_ << std::endl;
+ return;
+ }
+
+ void SoundManager::checkAmbientVolumeValidity()
+ {
+ if(this->ambientVolume_ < 0.0 || this->ambientVolume_ > 1.0)
+ {
+ COUT(2) << "Sound warning: Ambient volume out of range, ignoring change." << std::endl;
+ ResetConfigValue(ambientVolume_);
+ }
+
+ this->updateAmbientVolume();
+ COUT(3) << "SoundManager: Ambient volume set to " << this->ambientVolume_ << std::endl;
+ return;
+ }
+
+ void SoundManager::checkEffectsVolumeValidity()
+ {
+ if(this->effectsVolume_ < 0.0 || this->effectsVolume_ > 1.0)
+ {
+ COUT(2) << "Sound warning: effects volume out of range, ignoring change." << std::endl;
+ ResetConfigValue(effectsVolume_);
+ }
+
+ this->updateEffectsVolume();
+ COUT(3) << "SoundManager: Effects volume set to " << this->effectsVolume_ << std::endl;
+ return;
+ }
void SoundManager::setListenerPosition(const Vector3& position)
{
@@ -218,6 +274,60 @@
}
}
}
+
+ void SoundManager::setAmbientVolume(float vol)
+ {
+ if (vol > 1 || vol < 0)
+ {
+ COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl;
+ vol = vol > 1 ? 1 : vol;
+ vol = vol < 0 ? 0 : vol;
+ }
+ this->ambientVolume_ = vol;
+
+ this->updateAmbientVolume();
+ }
+
+ void SoundManager::setEffectsVolume(float vol)
+ {
+ if (vol > 1 || vol < 0)
+ {
+ COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl;
+ vol = vol > 1 ? 1 : vol;
+ vol = vol < 0 ? 0 : vol;
+ }
+ this->effectsVolume_ = vol;
+
+ this->updateEffectsVolume();
+ }
+
+ void SoundManager::setVolume(float vol)
+ {
+ if (vol > 1 || vol < 0)
+ {
+ COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl;
+ vol = vol > 1 ? 1 : vol;
+ vol = vol < 0 ? 0 : vol;
+ }
+ this->volume_ = vol;
+
+ this->updateVolume();
+ }
+
+ float SoundManager::getAmbientVolume(void)
+ {
+ return this->ambientVolume_;
+ }
+
+ float SoundManager::getEffectsVolume(void)
+ {
+ return this->effectsVolume_;
+ }
+
+ float SoundManager::getVolume(void)
+ {
+ return this->volume_;
+ }
void SoundManager::fadeIn(AmbientSound* sound)
{
@@ -304,4 +414,41 @@
}
}
}
+
+ void SoundManager::updateAmbientVolume(void)
+ {
+ for(ObjectList<AmbientSound>::iterator it = ObjectList<AmbientSound>::begin(); it != ObjectList<AmbientSound>::end(); ++it)
+ {
+ (*it)->setVolumeGain(this->volume_*this->ambientVolume_);
+ }
+ }
+
+ void SoundManager::updateEffectsVolume(void)
+ {
+ for (ObjectList<WorldSound>::iterator it = ObjectList<WorldSound>::begin(); it != ObjectList<WorldSound>::end(); ++it)
+ {
+ (*it)->setVolumeGain(this->volume_*this->effectsVolume_);
+ }
+ }
+
+ void SoundManager::updateVolume(void)
+ {
+ for (ObjectList<BaseSound>::iterator it = ObjectList<BaseSound>::begin(); it != ObjectList<BaseSound>::end(); ++it)
+ {
+ AmbientSound* ambient = dynamic_cast<AmbientSound*>(*it);
+ WorldSound* world = dynamic_cast<WorldSound*>(*it);
+ if(ambient != NULL)
+ {
+ ambient->setVolumeGain(this->volume_*this->ambientVolume_);
+ }
+ else if(world != NULL)
+ {
+ world->setVolumeGain(this->volume_*this->effectsVolume_);
+ }
+ else
+ {
+ (*it)->setVolumeGain(this->volume_);
+ }
+ }
+ }
}
Modified: code/branches/presentation2/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/SoundManager.h 2009-11-30 10:07:06 UTC (rev 6183)
+++ code/branches/presentation2/src/orxonox/sound/SoundManager.h 2009-11-30 19:50:44 UTC (rev 6184)
@@ -34,7 +34,9 @@
#include <list>
#include <string>
#include "util/Singleton.h"
+#include "core/OrxonoxClass.h"
+// tolua_begin
namespace orxonox
{
/**
@@ -42,8 +44,10 @@
* position. It is a singleton.
*
*/
- class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public OrxonoxClass
- {
+ class _OrxonoxExport SoundManager
+ // tolua_end
+ : public Singleton<SoundManager>, public OrxonoxClass
+ { // tolua_export
friend class Singleton<SoundManager>;
public:
@@ -52,6 +56,8 @@
void preUpdate(const Clock& time);
void setConfigValues();
+
+ static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); } // tolua_export
void setListenerPosition(const Vector3& position);
void setListenerOrientation(const Quaternion& orientation);
@@ -59,6 +65,14 @@
void registerAmbientSound(AmbientSound* newAmbient);
void unregisterAmbientSound(AmbientSound* oldAmbient);
void pauseAmbientSound(AmbientSound* ambient);
+
+ void setAmbientVolume(float vol); // tolua_export
+ void setEffectsVolume(float vol); // tolua_export
+ void setVolume(float vol); // tolua_export
+
+ float getAmbientVolume(void); // tolua_export
+ float getEffectsVolume(void); // tolua_export
+ float getVolume(void); // tolua_export
private:
void processCrossFading(float dt);
@@ -66,6 +80,13 @@
void fadeOut(AmbientSound* sound);
void checkFadeStepValidity();
+ void checkVolumeValidity();
+ void checkAmbientVolumeValidity();
+ void checkEffectsVolumeValidity();
+
+ void updateAmbientVolume(void);
+ void updateEffectsVolume(void);
+ void updateVolume(void);
ALCdevice* device_;
ALCcontext* context_;
@@ -77,8 +98,12 @@
std::list<AmbientSound*> fadeInList_;
std::list<AmbientSound*> fadeOutList_;
+ float ambientVolume_;
+ float effectsVolume_;
+ float volume_;
+
static SoundManager* singletonPtr_s;
- };
-}
+ }; // tolua_export
+} // tolua_export
#endif /* _SoundManager_H__ */
More information about the Orxonox-commit
mailing list