Add callbacks for metadata and status reports

All objects can have a metadata and/or status report callback once created.
They will call the source program with the parsed ID3 tag, ICY StreamTitle,
or text and numeric error ID of any interesting event.  It is up to the end
application to figure out what to do with this.  Normally, you'd just print
it to the LCD or Serial port.  But it is possible to detect, say, a buffer
overflow and then switch to a lower bitrate stream for example.
This commit is contained in:
Earle F. Philhower, III committed 2017-12-06 21:11:23 -08:00
1 parent 1ab9348a4c
commit 9c120a777a
22 files changed
+339 -85

No files matched your search

+9 -4
View File
@@ -67,9 +67,11 @@ bool AudioGeneratorMP3::isRunning()
enum mad_flow AudioGeneratorMP3::ErrorToFlow()
{
char err[64];
char errLine[128];
strcpy_P(err, mad_stream_errorstr(&stream));
Serial.printf("Decoding error 0x%04x (%s) at byte offset %d\n", stream.error, err, (stream.this_frame - buff) + lastReadPos);
Serial.flush();
snprintf(errLine, sizeof(errLine), "Decoding error '%s' at byte offset %d",
err, (stream.this_frame - buff) + lastReadPos);
cb.st(stream.error, errLine);
return MAD_FLOW_CONTINUE;
}
@@ -193,11 +195,14 @@ done:
bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
{
if (!source) return false;
if (!source) return false;
file = source;
if (!output) return false;
this->output = output;
if (!file->isOpen()) return false; // Error
if (!file->isOpen()) {
Serial.printf("MP3 source file not open\n");
return false; // Error
}
if (!output->begin()) return false;
// Where we are in generating one frame's data, set to invalid so we will run loop on first getsample()