Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified AudioFileSource ID3 to enable tag skipping. #350

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/AudioFileSourceFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
class AudioFileSourceFS : public AudioFileSource
{
public:
AudioFileSourceFS(FS &fs) { filesystem = &fs; }
AudioFileSourceFS(FS &fs, const char *filename);
AudioFileSourceFS(fs::FS &fs) { filesystem = &fs; }
AudioFileSourceFS(fs::FS &fs, const char *filename);
virtual ~AudioFileSourceFS() override;

virtual bool open(const char *filename) override;
Expand All @@ -42,8 +42,8 @@ class AudioFileSourceFS : public AudioFileSource
virtual uint32_t getPos() override { if (!f) return 0; else return f.position(); };

private:
FS *filesystem;
File f;
fs::FS *filesystem;
fs::File f;
};


Expand Down
27 changes: 25 additions & 2 deletions src/AudioFileSourceID3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ bool AudioFileSourceUnsync::eof()



AudioFileSourceID3::AudioFileSourceID3(AudioFileSource *src)
AudioFileSourceID3::AudioFileSourceID3(AudioFileSource *src, bool skip)
{
this->src = src;
this->checked = false;
this->skip = skip;
}

AudioFileSourceID3::~AudioFileSourceID3()
Expand All @@ -143,6 +144,7 @@ uint32_t AudioFileSourceID3::read(void *data, uint32_t len)
if (ret<10) return ret;

if ((buff[0]!='I') || (buff[1]!='D') || (buff[2]!='3') || (buff[3]>0x04) || (buff[3]<0x02) || (buff[4]!=0)) {
cb.md("eof", false, "id3");
return 10 + src->read(buff+10, len-10);
}

Expand All @@ -169,6 +171,13 @@ uint32_t AudioFileSourceID3::read(void *data, uint32_t len)
id3Size |= buff[8];
id3Size = id3Size << 7;
id3Size |= buff[9];

// Return now to the player if we want to skip ID3 parsing.
if(skip){
// Advance to the end of ID3 tag
src->seek(id3Size + 10, 0);
return src->read(data, len);
}
// Every read from now may be unsync'd
AudioFileSourceUnsync id3(src, id3Size, unsync);

Expand Down Expand Up @@ -212,7 +221,7 @@ uint32_t AudioFileSourceID3::read(void *data, uint32_t len)

// Read the value and send to callback
char value[64];
uint16_t i;
uint32_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();
Expand All @@ -231,10 +240,24 @@ uint32_t AudioFileSourceID3::read(void *data, uint32_t len)
} else if ( (frameid[0]=='T' && frameid[1]=='Y' && frameid[2]=='E' && frameid[3] == 'R') ||
(frameid[0]=='T' && frameid[1]=='Y' && frameid[2]=='E' && rev==2) ) {
cb.md("Year", isUnicode, value);
} else if ( (frameid[0]=='T' && frameid[1]=='R' && frameid[2]=='C' && frameid[3] == 'K') ||
(frameid[0]=='T' && frameid[1]=='R' && frameid[2]=='K' && rev==2) ) {
cb.md("Track", isUnicode, value);
} else if ( (frameid[0]=='T' && frameid[1]=='P' && frameid[2]=='O' && frameid[3] == 'S') ||
(frameid[0]=='T' && frameid[1]=='P' && frameid[2]=='A' && rev==2) ) {
cb.md("Set", isUnicode, value);
} else if ( (frameid[0]=='P' && frameid[1]=='O' && frameid[2]=='P' && frameid[3] == 'M') ||
(frameid[0]=='P' && frameid[1]=='O' && frameid[2]=='P' && rev==2) ) {
cb.md("Popularimeter", isUnicode, value);
} else if ( (frameid[0]=='T' && frameid[1]=='C' && frameid[2]=='M' && frameid[3] == 'P') ) {
cb.md("Compilation", isUnicode, value);
}
}
} while (!id3.eof());

// use callback function to signal end of tags and beginning of content.
cb.md("eof", false, "id3");

// All ID3 processing done, return to main caller
return src->read(data, len);
}
Expand Down
3 changes: 2 additions & 1 deletion src/AudioFileSourceID3.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class AudioFileSourceID3 : public AudioFileSource
{
public:
AudioFileSourceID3(AudioFileSource *src);
AudioFileSourceID3(AudioFileSource *src, bool skip = false);
virtual ~AudioFileSourceID3() override;

virtual uint32_t read(void *data, uint32_t len) override;
Expand All @@ -41,6 +41,7 @@ class AudioFileSourceID3 : public AudioFileSource
private:
AudioFileSource *src;
bool checked;
bool skip;
};


Expand Down