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.
This commit is contained in:
Max Kellermann 2019-06-27 21:17:37 +02:00
parent 9fc1668de3
commit 8f6c750064
2 changed files with 9 additions and 6 deletions

View File

@ -73,6 +73,14 @@ public:
return tail >= capacity; 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 * Returns the tail of the buffer, i.e. where new data can be
* written. Call GetSpaceBytes() to find out how much may be * written. Call GetSpaceBytes() to find out how much may be
@ -163,10 +171,6 @@ public:
ConsumeBytes(n * frame_size); ConsumeBytes(n * frame_size);
} }
snd_pcm_uframes_t GetPeriodPosition(size_t frame_size) const noexcept {
return head / frame_size;
}
void Rewind() noexcept { void Rewind() noexcept {
head = 0; head = 0;
} }

View File

@ -746,8 +746,7 @@ AlsaOutput::DrainInternal()
/* drain ring_buffer */ /* drain ring_buffer */
CopyRingToPeriodBuffer(); CopyRingToPeriodBuffer();
auto period_position = period_buffer.GetPeriodPosition(out_frame_size); if (period_buffer.WasConsumed())
if (period_position > 0)
/* generate some silence to finish the partial /* generate some silence to finish the partial
period */ period */
period_buffer.FillWithSilence(silence, out_frame_size); period_buffer.FillWithSilence(silence, out_frame_size);