From 60961165265f582ff89c4086cc92c03434367f86 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Sat, 25 Jun 2022 02:10:17 +0200 Subject: [PATCH] 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 --- Telegram/SourceFiles/media/audio/media_audio.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/media/audio/media_audio.cpp b/Telegram/SourceFiles/media/audio/media_audio.cpp index fbe1e5753a..7c3a2747eb 100644 --- a/Telegram/SourceFiles/media/audio/media_audio.cpp +++ b/Telegram/SourceFiles/media/audio/media_audio.cpp @@ -315,12 +315,15 @@ base::Observable &Updated() { // Thread: Any. Must be locked: AudioMutex. float64 ComputeVolume(AudioMsgId::Type type) { - 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.; + 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() {