Fix #4938
- Set the minimum sound volume to 0.025f instead of effectively 0.1f. This is particularly helpful for headphone users. - Make the step between each volume setting exponential. - Add parameters to remember the parameters of the audio spinners. - Increase the default number of values the audio spinners can take from 10 to 15. Old config files will keep using 10. - Set the default values to 10 (spinners), which translates to 0.2678 (volume fraction) instead of 0.6 (previous default)
This commit is contained in:
parent
858ed6bb3e
commit
40511b218c
@ -414,16 +414,22 @@ namespace UserConfigParams
|
|||||||
PARAM_DEFAULT( BoolUserConfigParam(true, "music_on",
|
PARAM_DEFAULT( BoolUserConfigParam(true, "music_on",
|
||||||
&m_audio_group,
|
&m_audio_group,
|
||||||
"Whether musics are enabled or not (true or false)") );
|
"Whether musics are enabled or not (true or false)") );
|
||||||
|
PARAM_PREFIX IntUserConfigParam m_sfx_numerator
|
||||||
|
PARAM_DEFAULT( IntUserConfigParam(10, "sfx_numerator",
|
||||||
|
&m_audio_group, "The value in the audio options SFX spinner") );
|
||||||
PARAM_PREFIX FloatUserConfigParam m_sfx_volume
|
PARAM_PREFIX FloatUserConfigParam m_sfx_volume
|
||||||
PARAM_DEFAULT( FloatUserConfigParam(0.6f, "sfx_volume",
|
PARAM_DEFAULT( FloatUserConfigParam(0.2678f, "sfx_volume",
|
||||||
&m_audio_group, "Volume for sound effects, see openal AL_GAIN "
|
&m_audio_group, "Volume for sound effects, see openal AL_GAIN "
|
||||||
"for interpretation") );
|
"for interpretation") );
|
||||||
|
PARAM_PREFIX IntUserConfigParam m_music_numerator
|
||||||
|
PARAM_DEFAULT( IntUserConfigParam(10, "music_numerator",
|
||||||
|
&m_audio_group, "The value in the audio options music spinner") );
|
||||||
PARAM_PREFIX FloatUserConfigParam m_music_volume
|
PARAM_PREFIX FloatUserConfigParam m_music_volume
|
||||||
PARAM_DEFAULT( FloatUserConfigParam(0.5f, "music_volume",
|
PARAM_DEFAULT( FloatUserConfigParam(0.2678f, "music_volume",
|
||||||
&m_audio_group, "Music volume from 0.0 to 1.0") );
|
&m_audio_group, "Music volume from 0.0 to 1.0") );
|
||||||
|
|
||||||
PARAM_PREFIX IntUserConfigParam m_volume_denominator
|
PARAM_PREFIX IntUserConfigParam m_volume_denominator
|
||||||
PARAM_DEFAULT( IntUserConfigParam(10, "volume_denominator",
|
PARAM_DEFAULT( IntUserConfigParam(15, "volume_denominator",
|
||||||
&m_audio_group,
|
&m_audio_group,
|
||||||
"Number of steps for volume adjustment") );
|
"Number of steps for volume adjustment") );
|
||||||
|
|
||||||
|
@ -67,14 +67,12 @@ void OptionsScreenAudio::init()
|
|||||||
SpinnerWidget* gauge = this->getWidget<SpinnerWidget>("sfx_volume");
|
SpinnerWidget* gauge = this->getWidget<SpinnerWidget>("sfx_volume");
|
||||||
assert(gauge != NULL);
|
assert(gauge != NULL);
|
||||||
gauge->setMax(UserConfigParams::m_volume_denominator);
|
gauge->setMax(UserConfigParams::m_volume_denominator);
|
||||||
gauge->setValue((int)(SFXManager::get()->getMasterSFXVolume() *
|
gauge->setValue(UserConfigParams::m_sfx_numerator);
|
||||||
float(UserConfigParams::m_volume_denominator)));
|
|
||||||
|
|
||||||
gauge = this->getWidget<SpinnerWidget>("music_volume");
|
gauge = this->getWidget<SpinnerWidget>("music_volume");
|
||||||
assert(gauge != NULL);
|
assert(gauge != NULL);
|
||||||
gauge->setMax(UserConfigParams::m_volume_denominator);
|
gauge->setMax(UserConfigParams::m_volume_denominator);
|
||||||
gauge->setValue((int)(music_manager->getMasterMusicVolume() *
|
gauge->setValue(UserConfigParams::m_music_numerator);
|
||||||
float(UserConfigParams::m_volume_denominator)));
|
|
||||||
|
|
||||||
// ---- music volume
|
// ---- music volume
|
||||||
CheckBoxWidget* sfx = this->getWidget<CheckBoxWidget>("sfx_enabled");
|
CheckBoxWidget* sfx = this->getWidget<CheckBoxWidget>("sfx_enabled");
|
||||||
@ -136,8 +134,10 @@ void OptionsScreenAudio::eventCallback(Widget* widget, const std::string& name,
|
|||||||
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
|
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
|
||||||
assert(w != NULL);
|
assert(w != NULL);
|
||||||
|
|
||||||
music_manager->setMasterMusicVolume(w->getValue() /
|
float new_volume = computeVolume(w->getValue(), UserConfigParams::m_volume_denominator);
|
||||||
float(UserConfigParams::m_volume_denominator));
|
|
||||||
|
UserConfigParams::m_music_numerator = w->getValue();
|
||||||
|
music_manager->setMasterMusicVolume(new_volume);
|
||||||
}
|
}
|
||||||
else if(name == "sfx_volume")
|
else if(name == "sfx_volume")
|
||||||
{
|
{
|
||||||
@ -149,10 +149,10 @@ void OptionsScreenAudio::eventCallback(Widget* widget, const std::string& name,
|
|||||||
if (sample_sound == NULL) sample_sound = SFXManager::get()->createSoundSource( "pre_start_race" );
|
if (sample_sound == NULL) sample_sound = SFXManager::get()->createSoundSource( "pre_start_race" );
|
||||||
sample_sound->setVolume(1);
|
sample_sound->setVolume(1);
|
||||||
|
|
||||||
float new_vol = w->getValue() /
|
float new_volume = computeVolume(w->getValue(), UserConfigParams::m_volume_denominator);
|
||||||
float(UserConfigParams::m_volume_denominator);
|
SFXManager::get()->setMasterSFXVolume(new_volume);
|
||||||
SFXManager::get()->setMasterSFXVolume(new_vol);
|
UserConfigParams::m_sfx_numerator = w->getValue();
|
||||||
UserConfigParams::m_sfx_volume = new_vol;
|
UserConfigParams::m_sfx_volume = new_volume;
|
||||||
|
|
||||||
// play a sample sound to show the user what this volume is like
|
// play a sample sound to show the user what this volume is like
|
||||||
sample_sound->play();
|
sample_sound->play();
|
||||||
@ -194,6 +194,23 @@ void OptionsScreenAudio::eventCallback(Widget* widget, const std::string& name,
|
|||||||
}
|
}
|
||||||
} // eventCallback
|
} // eventCallback
|
||||||
|
|
||||||
|
float OptionsScreenAudio::computeVolume(int numerator, int denominator)
|
||||||
|
{
|
||||||
|
if (numerator <= 1)
|
||||||
|
{
|
||||||
|
return 0.025f;
|
||||||
|
}
|
||||||
|
else if (numerator == denominator)
|
||||||
|
{
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float num_root = pow(40.0f, 1.0f / (float)(denominator - 1));
|
||||||
|
return 0.025f * pow(num_root, (float)(numerator - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void OptionsScreenAudio::unloaded()
|
void OptionsScreenAudio::unloaded()
|
||||||
|
@ -35,6 +35,9 @@ class OptionsScreenAudio : public GUIEngine::Screen, public GUIEngine::ScreenSin
|
|||||||
{
|
{
|
||||||
OptionsScreenAudio();
|
OptionsScreenAudio();
|
||||||
|
|
||||||
|
private:
|
||||||
|
float computeVolume(int numerator, int denominator);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class GUIEngine::ScreenSingleton<OptionsScreenAudio>;
|
friend class GUIEngine::ScreenSingleton<OptionsScreenAudio>;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user