From 60fa8ac10931f2119fba0fe1ae0182c4a08f16e9 Mon Sep 17 00:00:00 2001 From: Max Trussell Date: Sun, 19 Dec 2021 19:00:00 -0800 Subject: [PATCH] AudioServer/Mixer: Fix remaining samples underflow The `m_remaining_samples` attribute was underflowing at the end of an audio stream. This fix guards against the underflow by only decrementing the attribute when it is greater than zero. I found this bug because the SoundPlayer userland application was not correctly detecting when an audio stream was completed. This was happening because the remaining samples being returned from the client audio connection was an underflowed 16 bit integer instead of zero. --- Userland/Services/AudioServer/Mixer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Userland/Services/AudioServer/Mixer.h b/Userland/Services/AudioServer/Mixer.h index 9c64ab0eec..3c0669a784 100644 --- a/Userland/Services/AudioServer/Mixer.h +++ b/Userland/Services/AudioServer/Mixer.h @@ -52,7 +52,8 @@ public: return false; sample = m_current->samples()[m_position++]; - --m_remaining_samples; + if (m_remaining_samples > 0) + --m_remaining_samples; ++m_played_samples; if (m_position >= m_current->sample_count()) {