From 8f6c750064c1dc45158aa28150e87410ff23e39b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 27 Jun 2019 21:17:37 +0200 Subject: [PATCH] output/alsa: improve silence generator test in DrainInternal() There cannot be partial frames in the buffer, so we don't need GetPeriodPosition(); it's enough to check whether head has been moved in this period. --- src/lib/alsa/PeriodBuffer.hxx | 12 ++++++++---- src/output/plugins/AlsaOutputPlugin.cxx | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/alsa/PeriodBuffer.hxx b/src/lib/alsa/PeriodBuffer.hxx index 803a4003a..e2068f5c9 100644 --- a/src/lib/alsa/PeriodBuffer.hxx +++ b/src/lib/alsa/PeriodBuffer.hxx @@ -73,6 +73,14 @@ public: return tail >= capacity; } + /** + * Has some data already been consumed at the buffer's head in + * this period? + */ + bool WasConsumed() const noexcept { + return head > 0; + } + /** * Returns the tail of the buffer, i.e. where new data can be * written. Call GetSpaceBytes() to find out how much may be @@ -163,10 +171,6 @@ public: ConsumeBytes(n * frame_size); } - snd_pcm_uframes_t GetPeriodPosition(size_t frame_size) const noexcept { - return head / frame_size; - } - void Rewind() noexcept { head = 0; } diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index d32213c68..718e0ac66 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -746,8 +746,7 @@ AlsaOutput::DrainInternal() /* drain ring_buffer */ CopyRingToPeriodBuffer(); - auto period_position = period_buffer.GetPeriodPosition(out_frame_size); - if (period_position > 0) + if (period_buffer.WasConsumed()) /* generate some silence to finish the partial period */ period_buffer.FillWithSilence(silence, out_frame_size);