Skip to content

Commit

Permalink
Fix #4938
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
Alayan-stk-2 committed Nov 17, 2023
1 parent 858ed6b commit 40511b2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
12 changes: 9 additions & 3 deletions src/config/user_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,22 @@ namespace UserConfigParams
PARAM_DEFAULT( BoolUserConfigParam(true, "music_on",
&m_audio_group,
"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_DEFAULT( FloatUserConfigParam(0.6f, "sfx_volume",
PARAM_DEFAULT( FloatUserConfigParam(0.2678f, "sfx_volume",
&m_audio_group, "Volume for sound effects, see openal AL_GAIN "
"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_DEFAULT( FloatUserConfigParam(0.5f, "music_volume",
PARAM_DEFAULT( FloatUserConfigParam(0.2678f, "music_volume",
&m_audio_group, "Music volume from 0.0 to 1.0") );

PARAM_PREFIX IntUserConfigParam m_volume_denominator
PARAM_DEFAULT( IntUserConfigParam(10, "volume_denominator",
PARAM_DEFAULT( IntUserConfigParam(15, "volume_denominator",
&m_audio_group,
"Number of steps for volume adjustment") );

Expand Down
37 changes: 27 additions & 10 deletions src/states_screens/options/options_screen_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ void OptionsScreenAudio::init()
SpinnerWidget* gauge = this->getWidget<SpinnerWidget>("sfx_volume");
assert(gauge != NULL);
gauge->setMax(UserConfigParams::m_volume_denominator);
gauge->setValue((int)(SFXManager::get()->getMasterSFXVolume() *
float(UserConfigParams::m_volume_denominator)));
gauge->setValue(UserConfigParams::m_sfx_numerator);

gauge = this->getWidget<SpinnerWidget>("music_volume");
assert(gauge != NULL);
gauge->setMax(UserConfigParams::m_volume_denominator);
gauge->setValue((int)(music_manager->getMasterMusicVolume() *
float(UserConfigParams::m_volume_denominator)));
gauge->setValue(UserConfigParams::m_music_numerator);

// ---- music volume
CheckBoxWidget* sfx = this->getWidget<CheckBoxWidget>("sfx_enabled");
Expand Down Expand Up @@ -136,8 +134,10 @@ void OptionsScreenAudio::eventCallback(Widget* widget, const std::string& name,
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
assert(w != NULL);

music_manager->setMasterMusicVolume(w->getValue() /
float(UserConfigParams::m_volume_denominator));
float new_volume = computeVolume(w->getValue(), UserConfigParams::m_volume_denominator);

UserConfigParams::m_music_numerator = w->getValue();
music_manager->setMasterMusicVolume(new_volume);
}
else if(name == "sfx_volume")
{
Expand All @@ -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" );
sample_sound->setVolume(1);

float new_vol = w->getValue() /
float(UserConfigParams::m_volume_denominator);
SFXManager::get()->setMasterSFXVolume(new_vol);
UserConfigParams::m_sfx_volume = new_vol;
float new_volume = computeVolume(w->getValue(), UserConfigParams::m_volume_denominator);
SFXManager::get()->setMasterSFXVolume(new_volume);
UserConfigParams::m_sfx_numerator = w->getValue();
UserConfigParams::m_sfx_volume = new_volume;

// play a sample sound to show the user what this volume is like
sample_sound->play();
Expand Down Expand Up @@ -194,6 +194,23 @@ void OptionsScreenAudio::eventCallback(Widget* widget, const std::string& name,
}
} // 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()
Expand Down
3 changes: 3 additions & 0 deletions src/states_screens/options/options_screen_audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class OptionsScreenAudio : public GUIEngine::Screen, public GUIEngine::ScreenSin
{
OptionsScreenAudio();

private:
float computeVolume(int numerator, int denominator);

public:
friend class GUIEngine::ScreenSingleton<OptionsScreenAudio>;

Expand Down

0 comments on commit 40511b2

Please sign in to comment.