- Home /
Math formula to set volume levels nicely
I'm setting up basic volume controls for my game and noticed, that my sliders work correctly, but they "feel wrong".
When I lower the slider from full volume towards no volume, the perceived audio volume drops off very fast and then for the biggest part of the slider, my music is not audible.
Here's how I'm doing it:
public void SetSoundVolume(float volume)
{
SetVolume("SoundVolume", volume);
}
private void SetVolume(string parameter, float volume)
{
if (volume < -80f || volume > 0f)
throw new System.ArgumentOutOfRangeException("volume", "Volume levels must be between -80 and 0.");
m_MasterMixer.SetFloat(parameter, volume);
}
And my slider is a UnityEngine.UI component with min set to -80 and max to 0.
When I test, I can see the music meters peak out just below 0 at full volume and then linearly decrease with my slider. So I assume that technically everything works correctly, but at around -20db the audio is already too silent to hear, making the rest of the slider range useless.
Is something wrong with my audio levels or is this a common problem that can be solved by converting the slider range to a different behaviour like say, a logarithmic scale or something similar?
Thank you!