diff --git a/engine/SoundBase.cc b/engine/SoundBase.cc index 68aae26..d52baa9 100644 --- a/engine/SoundBase.cc +++ b/engine/SoundBase.cc @@ -1,3 +1,5 @@ +#include + #include "SoundBase.h" #include "SoundBaseGlobal.h" @@ -172,7 +174,25 @@ void SoundBase::HaltMusic () { mCurrentMusic = NULL; } +void SoundBase::SetMusicVolume(const float &music_volume) { + int mix_volume = static_cast (fabsf(music_volume) * MIX_MAX_VOLUME); + Mix_VolumeMusic(mix_volume); +} + +float SoundBase::GetMusicVolume() { + return static_cast(Mix_VolumeMusic(-1)) / static_cast(MIX_MAX_VOLUME); +} + +void SoundBase::SetEffectsVolume(const float &effects_volume) { + int mix_volume = static_cast (fabsf(effects_volume) * MIX_MAX_VOLUME); + + Mix_Volume(-1, mix_volume); +} + +float SoundBase::GetEffectsVolume() { + return static_cast(Mix_Volume(-1, -1)) / static_cast(MIX_MAX_VOLUME); +} /* * Global Functions */ diff --git a/engine/SoundBase.h b/engine/SoundBase.h index 2215b6b..93930ae 100644 --- a/engine/SoundBase.h +++ b/engine/SoundBase.h @@ -39,6 +39,21 @@ class SoundBase : public Module { void PlayMusic (const std::string &music_name); void HaltMusic (); + /** \brief Sets the volume of the music channel to the given value + * + * \param music_value is a value from 0. (no music) to 1. (maximum volume) + */ + void SetMusicVolume (const float &music_volume); + /** \brief Returns the value of the music (0. - 1.) */ + float GetMusicVolume (); + /** \brief Sets the volume of the music channel to the given value + * + * \param music_value is a value from 0. (no music) to 1. (maximum volume) + */ + void SetEffectsVolume (const float &effects_volume); + /** \brief Returns the value of the effects (0. - 1.) */ + float GetEffectsVolume (); + protected: /** \brief Initializes the system */ virtual int OnInit (int argc, char* argv[]);