diff options
author | kleines Filmröllchen <malu.bertsch@gmail.com> | 2021-08-27 23:47:09 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-12 23:38:57 +0200 |
commit | 152ec28da0d1a51ade18fe6799a34ac9b7aa07b0 (patch) | |
tree | 540e62552da0d9bb767e566f8951f081009e136a /Userland/Applets | |
parent | 2909c3a931439d0cbed3e4599d9eed47a6fdb446 (diff) | |
download | serenity-152ec28da0d1a51ade18fe6799a34ac9b7aa07b0.zip |
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.
Diffstat (limited to 'Userland/Applets')
-rw-r--r-- | Userland/Applets/Audio/main.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
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<int>(volume * 100); if (!m_audio_muted) update(); }; @@ -87,14 +87,14 @@ public: }; m_slider = m_root_container->add<GUI::VerticalSlider>(); - 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<i32>(volume_log)); + double volume = clamp(static_cast<double>(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(); } |