summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAlex Chronopoulos <achronop@gmail.com>2022-11-04 00:01:03 +0100
committerSam Atkins <atkinssj@gmail.com>2022-11-07 12:30:57 +0000
commite86cab00b6302c5f3e0819e8235811416360fafc (patch)
tree9bb38962a0588fc4ebfc8c0cefcc76019337459c /Userland
parent5822bc9cb543746ac59a315ed9f339aa3721e670 (diff)
downloadserenity-e86cab00b6302c5f3e0819e8235811416360fafc.zip
AudioServer: Skip mixing when volume is zero
When volume is zero it is not necessary to go through the mixing loop. The zero-filled buffer can be written directly to the device, instead, similar to the muted case. Tested by using the piano app and the main volume control.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Services/AudioServer/Mixer.cpp10
1 files changed, 3 insertions, 7 deletions
diff --git a/Userland/Services/AudioServer/Mixer.cpp b/Userland/Services/AudioServer/Mixer.cpp
index 4b5cdc41be..6f69718d4b 100644
--- a/Userland/Services/AudioServer/Mixer.cpp
+++ b/Userland/Services/AudioServer/Mixer.cpp
@@ -96,19 +96,15 @@ void Mixer::mix()
}
}
- if (m_muted) {
+ // Even though it's not realistic, the user expects no sound at 0%.
+ if (m_muted || m_main_volume < 0.01) {
m_device->write(m_zero_filled_buffer.data(), static_cast<int>(m_zero_filled_buffer.size()));
} else {
Array<u8, HARDWARE_BUFFER_SIZE_BYTES> buffer;
OutputMemoryStream stream { buffer };
for (auto& mixed_sample : mixed_buffer) {
-
- // Even though it's not realistic, the user expects no sound at 0%.
- if (m_main_volume < 0.01)
- mixed_sample = Audio::Sample { 0 };
- else
- mixed_sample.log_multiply(static_cast<float>(m_main_volume));
+ mixed_sample.log_multiply(static_cast<float>(m_main_volume));
mixed_sample.clip();
LittleEndian<i16> out_sample;