Replace Stream with simple string in MD callback
@armSeb found that the stream interface caused a big slowdown and hiccups in his playback, replace the MetadataCallback's *Stream with a simple *char for faster operation and less overhead.
This commit is contained in:
1 parent
d923ebef36
commit
8e94702468
5 files changed
+29
-33
No files matched your search
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
|
||||
#include "AudioFileSourceICYStream.h"
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include "AudioFileStream.h"
|
||||
|
||||
AudioFileSourceICYStream::AudioFileSourceICYStream()
|
||||
{
|
||||
@@ -209,18 +207,13 @@ retry:
|
||||
if (d==';') { mdr.unread(d); break; }
|
||||
else { mdr.unread(d); }
|
||||
}
|
||||
// if ((c=='\n') || (c=='\r') || (c==' ') || (c=='\t') || (c==0)) continue; // Throw away any whitespace
|
||||
*(p++) = c;
|
||||
}
|
||||
if (c != '\'') {
|
||||
// MD data was too long, read and throw away rest
|
||||
while ((c != '\'') && !mdr.eof()) mdr.read(&c, 1);
|
||||
}
|
||||
{
|
||||
AudioFileSourcePROGMEM afsp(value, strlen(value));
|
||||
AudioFileStream afs(&afsp, strlen(value));
|
||||
cb.md(type, false, &afs);
|
||||
}
|
||||
cb.md(type, false, value);
|
||||
do {
|
||||
ret = mdr.read(&c, 1);
|
||||
} while ((c !=';') && (c!=0) && !mdr.eof());
|
||||
|
||||
+17
-13
@@ -19,7 +19,6 @@
|
||||
*/
|
||||
|
||||
#include "AudioFileSourceID3.h"
|
||||
#include "AudioFileStream.h"
|
||||
|
||||
// Handle unsync operation in ID3 with custom class
|
||||
class AudioFileSourceUnsync : public AudioFileSource
|
||||
@@ -178,18 +177,23 @@ uint32_t AudioFileSourceID3::read(void *data, uint32_t len)
|
||||
for (int j=0; j<framesize; j++)
|
||||
id3.getByte();
|
||||
}
|
||||
{
|
||||
AudioFileStream afs(&id3, framesize);
|
||||
if (frameid[0]=='T' && frameid[1]=='A' && frameid[2]=='L' && frameid[3] == 'B') {
|
||||
cb.md("Album", afs.read()==1, &afs);
|
||||
} else if (frameid[0]=='T' && frameid[1]=='I' && frameid[2]=='T' && frameid[3] == '2') {
|
||||
cb.md("Title", afs.read()==1, &afs);
|
||||
} else if (frameid[0]=='T' && frameid[1]=='P' && frameid[2]=='E' && frameid[3] == '1') {
|
||||
cb.md("Performer", afs.read()==1, &afs);
|
||||
} else if (frameid[0]=='T' && frameid[1]=='Y' && frameid[2]=='E' && frameid[3] == 'R') {
|
||||
cb.md("Year", afs.read()==1, &afs);
|
||||
}
|
||||
//afs destructor here will read any unread bytes
|
||||
|
||||
// Read the value and send to callback
|
||||
char value[64];
|
||||
uint16_t i;
|
||||
bool isUnicode = (id3.getByte()==1) ? true : false;
|
||||
for (i=0; i<framesize-1; i++) {
|
||||
if (i<sizeof(value)-1) value[i] = id3.getByte();
|
||||
}
|
||||
value[i] = 0; // Terminate the string...
|
||||
if (frameid[0]=='T' && frameid[1]=='A' && frameid[2]=='L' && frameid[3] == 'B') {
|
||||
cb.md("Album", isUnicode, value);
|
||||
} else if (frameid[0]=='T' && frameid[1]=='I' && frameid[2]=='T' && frameid[3] == '2') {
|
||||
cb.md("Title", isUnicode, value);
|
||||
} else if (frameid[0]=='T' && frameid[1]=='P' && frameid[2]=='E' && frameid[3] == '1') {
|
||||
cb.md("Performer", isUnicode, value);
|
||||
} else if (frameid[0]=='T' && frameid[1]=='Y' && frameid[2]=='E' && frameid[3] == 'R') {
|
||||
cb.md("Year", isUnicode, value);
|
||||
}
|
||||
}
|
||||
} while (!id3.eof());
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ class AudioStatus
|
||||
|
||||
void ClearCBs() { mdFn = NULL; stFn = NULL; };
|
||||
|
||||
typedef void (*metadataCBFn)(void *cbData, const char *type, bool isUnicode, Stream *stream);
|
||||
typedef void (*metadataCBFn)(void *cbData, const char *type, bool isUnicode, const char *str);
|
||||
bool RegisterMetadataCB(metadataCBFn f, void *cbData) { mdFn = f; mdData = cbData; return true; }
|
||||
|
||||
// Returns a unique warning/error code, varying by the object. The string may be a PSTR, use _P functions!
|
||||
@@ -39,7 +39,7 @@ class AudioStatus
|
||||
bool RegisterStatusCB(statusCBFn f, void *cbData) { stFn = f; stData = cbData; return true; }
|
||||
|
||||
// Safely call the md function, if defined
|
||||
inline void md(const char *type, bool isUnicode, Stream *stream) { if (mdFn) mdFn(mdData, type, isUnicode, stream); }
|
||||
inline void md(const char *type, bool isUnicode, const char *string) { if (mdFn) mdFn(mdData, type, isUnicode, string); }
|
||||
|
||||
// Safely call the st function, if defined
|
||||
inline void st(int code, const char *string) { if (stFn) stFn(stData, code, string); }
|
||||
|
||||
Reference in new issue
Block a user