rodio icon indicating copy to clipboard operation
rodio copied to clipboard

How to detect when the Decoder has reached the end of the audio file?

Open Boscop opened this issue 5 years ago • 2 comments

I'm using this function that should return true when the decoder has reached the end of the audio file:

fn sum_channels_return_reached_end(
	channel_count: usize,
	decoder: &mut Decoder<BufReader<File>>,
	output: &mut [f32],
) -> bool {
	let mut reached_end = true;
	for (chunk, dst) in decoder.chunks(channel_count).into_iter().zip(output.iter_mut()) {
		let (sum, count) = chunk.map(sample_conv).fold((0., 0), |(s, c), v| (s + v, c + 1));
		*dst = sum / count as f32;
		reached_end = false;
	}
	reached_end
}

It works with wav files but always returns false for mp3 files: The decoder iterator still yields values after the end of the mp3 file. I tested with several mp3 files, all behave the same. Is there a reliable way to detect when the decoder has reached the end of the audio file?

Boscop avatar Jun 17 '20 00:06 Boscop

next_frame seems to always return Some. So this is a minimp3 bug, not ours.

est31 avatar Jun 17 '20 11:06 est31

Maybe our bug after all. #297 has been merged. Could you try out latest master of rodio and check whether the issue still persists?

est31 avatar Jul 07 '20 12:07 est31