From 1fde10daa0768f794bf7dbffb2280137474d2440 Mon Sep 17 00:00:00 2001 From: geoffday67 Date: Sun, 26 Apr 2020 18:07:13 +0100 Subject: [PATCH] Wait after reading MP3 file for final frames (#263) --- src/AudioGeneratorMP3.cpp | 9 +++++++-- src/AudioGeneratorMP3.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/AudioGeneratorMP3.cpp b/src/AudioGeneratorMP3.cpp index 6f19da9..1f45cfc 100644 --- a/src/AudioGeneratorMP3.cpp +++ b/src/AudioGeneratorMP3.cpp @@ -112,6 +112,11 @@ enum mad_flow AudioGeneratorMP3::Input() memmove(buff, stream->next_frame, unused); stream->next_frame = NULL; } + + if (finishing && (unused == buffLen - 1)) { + return MAD_FLOW_STOP; + } + if (unused == buffLen) { // Something wicked this way came, throw it all out and try again unused = 0; @@ -121,8 +126,7 @@ enum mad_flow AudioGeneratorMP3::Input() int len = buffLen - unused; len = file->read(buff + unused, len); if (len == 0) { - audioLogger->printf_P(PSTR("MP3 stop, len==0\n")); - return MAD_FLOW_STOP; + finishing = true; } mad_stream_buffer(stream, buff, len + unused); @@ -238,6 +242,7 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output) lastRate = 0; lastChannels = 0; lastReadPos = 0; + finishing = false; // Allocate all large memory chunks if (preallocateSpace) { diff --git a/src/AudioGeneratorMP3.h b/src/AudioGeneratorMP3.h index 674baab..b1b82d6 100644 --- a/src/AudioGeneratorMP3.h +++ b/src/AudioGeneratorMP3.h @@ -45,6 +45,7 @@ class AudioGeneratorMP3 : public AudioGenerator int lastReadPos; unsigned int lastRate; int lastChannels; + bool finishing; // Decoding bits bool madInitted;