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/Services/AudioServer/Mixer.h | |
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/Services/AudioServer/Mixer.h')
-rw-r--r-- | Userland/Services/AudioServer/Mixer.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Userland/Services/AudioServer/Mixer.h b/Userland/Services/AudioServer/Mixer.h index 33549fca3c..1b4c09a516 100644 --- a/Userland/Services/AudioServer/Mixer.h +++ b/Userland/Services/AudioServer/Mixer.h @@ -8,6 +8,7 @@ #pragma once #include "ClientConnection.h" +#include "FadingProperty.h" #include <AK/Atomic.h> #include <AK/Badge.h> #include <AK/ByteBuffer.h> @@ -23,6 +24,10 @@ namespace AudioServer { +// Headroom, i.e. fixed attenuation for all audio streams. +// This is to prevent clipping when two streams with low headroom (e.g. normalized & compressed) are playing. +constexpr double SAMPLE_HEADROOM = 0.7; + class ClientConnection; class BufferQueue : public RefCounted<BufferQueue> { @@ -82,6 +87,10 @@ public: return -1; } + FadingProperty<double>& volume() { return m_volume; } + double volume() const { return m_volume; } + void set_volume(double const volume) { m_volume = volume; } + private: RefPtr<Audio::Buffer> m_current; Queue<NonnullRefPtr<Audio::Buffer>> m_queue; @@ -89,7 +98,9 @@ private: int m_remaining_samples { 0 }; int m_played_samples { 0 }; bool m_paused { false }; + WeakPtr<ClientConnection> m_client; + FadingProperty<double> m_volume { 1 }; }; class Mixer : public Core::Object { @@ -100,8 +111,9 @@ public: NonnullRefPtr<BufferQueue> create_queue(ClientConnection&); - int main_volume() const { return m_main_volume; } - void set_main_volume(int volume); + // To the outside world, we pretend that the target volume is already reached, even though it may be still fading. + double main_volume() const { return m_main_volume.target(); } + void set_main_volume(double volume); bool is_muted() const { return m_muted; } void set_muted(bool); @@ -122,7 +134,7 @@ private: NonnullRefPtr<Threading::Thread> m_sound_thread; bool m_muted { false }; - int m_main_volume { 100 }; + FadingProperty<double> m_main_volume { 1 }; NonnullRefPtr<Core::ConfigFile> m_config; RefPtr<Core::Timer> m_config_write_timer; |