From cde8002df4a86a2a6efd4aa0b5c174b2f39f7bf7 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 22 Jun 2023 09:40:46 +1000 Subject: Fix (i think?) mysterious overly large reads in libmad --- src/audio/audio_task.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/audio/audio_task.cpp') diff --git a/src/audio/audio_task.cpp b/src/audio/audio_task.cpp index d4c1d27a..24bc7be7 100644 --- a/src/audio/audio_task.cpp +++ b/src/audio/audio_task.cpp @@ -173,11 +173,11 @@ void AudioTaskMain(std::unique_ptr pipeline, IAudioSink* sink) { float samples_sunk = bytes_sunk; samples_sunk /= pcm.channels; - int8_t bps = pcm.bits_per_sample; - if (bps == 24) { - bps = 32; - } - samples_sunk /= (bps / 8); + // 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 = ((pcm.bits_per_sample + 16 - 1) / 16) * 2; + samples_sunk /= bytes_per_sample; current_sample_in_second += samples_sunk; while (current_sample_in_second >= pcm.sample_rate) { -- cgit v1.2.3