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

+61
View File
@@ -0,0 +1,61 @@
#include <Arduino.h>
#include "AudioFileStream.h"
AudioFileStream::AudioFileStream(AudioFileSource *source, int definedLen)
{
src = source;
len = definedLen;
ptr = 0;
saved = -1;
}
AudioFileStream::~AudioFileStream()
{
// If there's a defined len, read until we're empty
if (len) {
while (ptr++ < len) (void)read();
}
}
int AudioFileStream::available()
{
if (saved >= 0) return 1;
else if (len) return ptr - len;
else if (src->getSize()) return (src->getPos() - src->getSize());
else return 1;
}
int AudioFileStream::read()
{
uint8_t c;
int r;
if (ptr >= len) return -1;
ptr++;
if (saved >= 0) {
c = (uint8_t)saved;
saved = -1;
r = 1;
} else {
r = src->read(&c, 1);
}
if (r != 1) return -1;
return (int)c;
}
int AudioFileStream::peek()
{
uint8_t c;
if ((ptr+1) >= len) return -1;
if (saved >= 0) return saved;
int r = src->read(&c, 1);
if (r<1) return -1;
saved = c;
return saved;
}
void AudioFileStream::flush()
{
/* noop? */
}