mirror of https://github.com/OpenMW/openmw.git
Clamp sound volume on settings update
parent
f639c62428
commit
a36a55bfb5
@ -0,0 +1,17 @@
|
||||
#ifndef GAME_SOUND_TYPE_H
|
||||
#define GAME_SOUND_TYPE_H
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
enum class Type
|
||||
{
|
||||
Sfx = 1 << 4, /* Normal SFX sound */
|
||||
Voice = 1 << 5, /* Voice sound */
|
||||
Foot = 1 << 6, /* Footstep sound */
|
||||
Music = 1 << 7, /* Music track */
|
||||
Movie = 1 << 8, /* Movie audio track */
|
||||
Mask = Sfx | Voice | Foot | Music | Movie
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,56 @@
|
||||
#include "volumesettings.hpp"
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
namespace
|
||||
{
|
||||
float clamp(float value)
|
||||
{
|
||||
return std::max(0.0f, std::min(1.0f, value));
|
||||
}
|
||||
}
|
||||
|
||||
VolumeSettings::VolumeSettings()
|
||||
: mMasterVolume(clamp(Settings::Manager::getFloat("master volume", "Sound"))),
|
||||
mSFXVolume(clamp(Settings::Manager::getFloat("sfx volume", "Sound"))),
|
||||
mMusicVolume(clamp(Settings::Manager::getFloat("music volume", "Sound"))),
|
||||
mVoiceVolume(clamp(Settings::Manager::getFloat("voice volume", "Sound"))),
|
||||
mFootstepsVolume(clamp(Settings::Manager::getFloat("footsteps volume", "Sound")))
|
||||
{
|
||||
}
|
||||
|
||||
float VolumeSettings::getVolumeFromType(Type type) const
|
||||
{
|
||||
float volume = mMasterVolume;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case Type::Sfx:
|
||||
volume *= mSFXVolume;
|
||||
break;
|
||||
case Type::Voice:
|
||||
volume *= mVoiceVolume;
|
||||
break;
|
||||
case Type::Foot:
|
||||
volume *= mFootstepsVolume;
|
||||
break;
|
||||
case Type::Music:
|
||||
volume *= mMusicVolume;
|
||||
break;
|
||||
case Type::Movie:
|
||||
case Type::Mask:
|
||||
break;
|
||||
}
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
||||
void VolumeSettings::update()
|
||||
{
|
||||
*this = VolumeSettings();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#ifndef GAME_SOUND_VOLUMESETTINGS_H
|
||||
#define GAME_SOUND_VOLUMESETTINGS_H
|
||||
|
||||
#include "type.hpp"
|
||||
|
||||
namespace MWSound
|
||||
{
|
||||
class VolumeSettings
|
||||
{
|
||||
public:
|
||||
VolumeSettings();
|
||||
|
||||
float getVolumeFromType(Type type) const;
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
float mMasterVolume;
|
||||
float mSFXVolume;
|
||||
float mMusicVolume;
|
||||
float mVoiceVolume;
|
||||
float mFootstepsVolume;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue