From 152ec28da0d1a51ade18fe6799a34ac9b7aa07b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Fri, 27 Aug 2021 23:47:09 +0200 Subject: Audio: Change how volume works Across the entire audio system, audio now works in 0-1 terms instead of 0-100 as before. Therefore, volume is now a double instead of an int. The master volume of the AudioServer changes smoothly through a FadingProperty, preventing clicks. Finally, volume computations are done with logarithmic scaling, which is more natural for the human ear. Note that this could be 4-5 different commits, but as they change each other's code all the time, it makes no sense to split them up. --- Userland/Applets/Audio/main.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'Userland/Applets') diff --git a/Userland/Applets/Audio/main.cpp b/Userland/Applets/Audio/main.cpp index be6247078f..0e1e736942 100644 --- a/Userland/Applets/Audio/main.cpp +++ b/Userland/Applets/Audio/main.cpp @@ -38,8 +38,8 @@ public: update(); }; - m_audio_client->on_main_mix_volume_change = [this](int volume) { - m_audio_volume = volume; + m_audio_client->on_main_mix_volume_change = [this](double volume) { + m_audio_volume = static_cast(volume * 100); if (!m_audio_muted) update(); }; @@ -87,14 +87,14 @@ public: }; m_slider = m_root_container->add(); - m_slider->set_max(20); - int non_log_volume = sqrt(100 * m_audio_volume); - m_slider->set_value(-(non_log_volume / 5.0f) + 20); + m_slider->set_max(100); + m_slider->set_page_step(5); + m_slider->set_step(5); + m_slider->set_value(m_slider->max() - m_audio_volume); m_slider->set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional); m_slider->on_change = [&](int value) { - int volume = clamp((20 - value) * 5, 0, 100); - double volume_log = ((volume / 100.0) * (volume / 100.0)) * 100.0; - m_audio_client->set_main_mix_volume(static_cast(volume_log)); + double volume = clamp(static_cast(m_slider->max() - value) / m_slider->max(), 0.0, 1.0); + m_audio_client->set_main_mix_volume(volume); update(); }; @@ -131,8 +131,7 @@ private: { if (m_audio_muted) return; - int new_slider_value = m_slider->value() + event.wheel_delta() / 4; - m_slider->set_value(new_slider_value); + m_slider->dispatch_event(event); update(); } -- cgit v1.2.3