From 025edf0d81497012c8218941b8083c68dba10af3 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 24 Dec 2017 09:20:01 -0800 Subject: [PATCH] Clean up DecodeNextFrame path to something sane As seen in issue #21, the MP3 decoder would barf on a single lost sync error, even though it was not actually a fatel error. Rewrote the logic to include another Input() on DNF failure, and only die when Input() actually fails. Seems to fix the problem in issue #21 and also did not break the WebRadio. --- src/AudioGeneratorMP3.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/AudioGeneratorMP3.cpp b/src/AudioGeneratorMP3.cpp index 07d6d49..7d0333c 100644 --- a/src/AudioGeneratorMP3.cpp +++ b/src/AudioGeneratorMP3.cpp @@ -110,17 +110,12 @@ enum mad_flow AudioGeneratorMP3::Input() bool AudioGeneratorMP3::DecodeNextFrame() { - do { - if (mad_frame_decode(&frame, &stream) == -1) { - if (!MAD_RECOVERABLE(stream.error)) break; - ErrorToFlow(); // Always returns CONTINUE - continue; - } - nsCountMax = MAD_NSBSAMPLES(&frame.header); - return true; - } while (stream.error == MAD_ERROR_BUFLEN); - Serial.printf_P(PSTR("stream.error != mad_Err_bufflen\n")); - return false; + if (mad_frame_decode(&frame, &stream) == -1) { + ErrorToFlow(); // Always returns CONTINUE + return false; + } + nsCountMax = MAD_NSBSAMPLES(&frame.header); + return true; } bool AudioGeneratorMP3::GetOneSample(int16_t sample[2]) @@ -170,13 +165,13 @@ bool AudioGeneratorMP3::loop() { // Decode next frame if we're beyond the existing generated data if ( (samplePtr >= synth.pcm.length) && (nsCount >= nsCountMax) ) { +retry: if (Input() == MAD_FLOW_STOP) { return false; } if (!DecodeNextFrame()) { - Serial.printf_P(PSTR("DNF failed\n")); - return false; + goto retry; } samplePtr = 9999; nsCount = 0;