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.
This commit is contained in:
1 parent
e844536251
commit
025edf0d81
1 file changed
+8
-13
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user