From b05db70c14e8835989fb7df60775f68d2732cd69 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 26 Jul 2023 17:36:10 +1000 Subject: Fix premature end of track --- src/audio/audio_task.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'src/audio/audio_task.cpp') diff --git a/src/audio/audio_task.cpp b/src/audio/audio_task.cpp index 6079e077..b6eff550 100644 --- a/src/audio/audio_task.cpp +++ b/src/audio/audio_task.cpp @@ -68,18 +68,9 @@ auto Timer::SetLengthBytes(uint32_t len) -> void { } auto Timer::AddBytes(std::size_t bytes) -> void { - float samples_sunk = bytes; - samples_sunk /= format_.channels; - - // Samples must be aligned to 16 bits. The number of actual bytes per - // sample is therefore the bps divided by 16, rounded up (align to word), - // times two (convert to bytes). - uint8_t bytes_per_sample = ((format_.bits_per_sample + 16 - 1) / 16) * 2; - samples_sunk /= bytes_per_sample; - - current_sample_in_second_ += samples_sunk; bool incremented = false; - while (current_sample_in_second_ > format_.sample_rate) { + current_sample_in_second_ += bytes_to_samples(bytes); + while (current_sample_in_second_ >= format_.sample_rate) { current_seconds_++; current_sample_in_second_ -= format_.sample_rate; incremented = true; -- cgit v1.2.3