Use quasi-logarithmic volume controls

This commit significantly improves the usability of the volume controls
for controlling volume in a way that matches intuitively onto human
needs and loudness perception.

Using the third power of the volume is a good approximation of the
quasi-logarithmic psychoacoustic system, while being defined everywhere
and preserving the useful quality of 0% volume mapping onto gain 0.0.
The use of this exact mapping function is a prior art established by
e.g. PulseAudio, among many other programs.

Fixes #24488
This commit is contained in:
Niklas Haas 2022-06-25 02:10:17 +02:00 committed by John Preston
parent 5c3f15af41
commit 6096116526

View file

@ -315,12 +315,15 @@ base::Observable<AudioMsgId> &Updated() {
// Thread: Any. Must be locked: AudioMutex.
float64 ComputeVolume(AudioMsgId::Type type) {
const auto gain = [&] {
switch (type) {
case AudioMsgId::Type::Voice: return VolumeMultiplierAll;
case AudioMsgId::Type::Song: return VolumeMultiplierSong * mixer()->getSongVolume();
case AudioMsgId::Type::Video: return mixer()->getVideoVolume();
}
return 1.;
}();
return gain * gain * gain;
}
Mixer *mixer() {