ID3 extract

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
Post Reply
Brek
Senior User
Posts: 60
Joined: Sun 2016-09-11 5:51

ID3 extract

Post by Brek » Sat 2016-10-01 7:29

Hi Guys :)
I just got this done today, so I’m sure it will get some improvement, but for now I thought it might help someone else get started.
I only want the artist and track title from the file, so that’s all I’m looking for.

Right now, it will break if:
The sum of artist and title strings exceed the length of the “idtext” string.

Right now, information is not extracted, and file is reported as NOT id3 if:
The mp3 tag is not ID3 ver 2,
The artist and track info is not in the first 1027 bytes of the mp3 file, in which case the file is reported not ID3 so the filename can be displayed.
(This will happen if an image is in the tag, but I’m sure the size is present in the tag, so it can be skipped for a later fix).

Due to my project only using upper case font glyphs, all characters are converted to uppercase for the idtext string.
Very rudimentary, but I’m using a limited micro after all, so didn’t want to use an existing comprehensive library.
Cheers, Brek.

Code: Select all

unsigned char iseyedeethree = 0;
char idtext[62]; // test string “Artist - Title"

void eyedeethree() {
FSFILE * idpointer;
unsigned char tagheader = 0;
int index = 0;
int subindex = 0;
int textsize = 0;
unsigned char gotinfo = 0;

idpointer = FSfopen (rec.filename,"r"); // open file for reading

FSfread (receiveBuffer, 1, 3, idpointer); // check header
tagheader = 1;
if (receiveBuffer[0] != 0x49) {tagheader = 0;}
if (receiveBuffer[1] != 0x44) {tagheader = 0;}
if (receiveBuffer[2] != 0x33) {tagheader = 0;}
if (tagheader == 0) {
FSfclose (idpointer);
iseyedeethree = 0; return;
} // tagheader

FSfread (imagebuffer, 1, 1024, idpointer); // read in 1k chunk


for (index=0;index<1024;index++) { // search chunk for artist
if (imagebuffer[index+0] == 0x54) { // "T"
if (imagebuffer[index+1] == 0x50) { // "P"
if (imagebuffer[index+2] == 0x45) { // "E"
if (imagebuffer[index+3] == 0x31) { // "1"
textsize = imagebuffer[index+7] - 1;

for (subindex=0;subindex<textsize;subindex++) {
idtext[subindex] = imagebuffer[index+11+subindex];
if (idtext[subindex]>0x60 && idtext[subindex]<0x7B) {idtext[subindex] = idtext[subindex] - 0x20;} // convert lower case chars
} // textsize
idtext[subindex] = 0x20;
subindex++;
idtext[subindex] = 0x2D; // "-"
subindex++;
idtext[subindex] = 0x20;
subindex++;
index = 1024; gotinfo = 1;
}}}} // imagebuffer
} // index


for (index=0;index<1024;index++) { // search chunk for title
if (imagebuffer[index+0] == 0x54) { // "T"
if (imagebuffer[index+1] == 0x49) { // "I"
if (imagebuffer[index+2] == 0x54) { // "T"
if (imagebuffer[index+3] == 0x32) { // "2"
textsize = imagebuffer[index+7] - 1;
for (n=0;n<textsize;n++) {
idtext[subindex] = imagebuffer[index+11+n];
if (idtext[subindex]>0x60 && idtext[subindex]<0x7B) {idtext[subindex] = idtext[subindex] - 0x20;} // convert lower case chars
subindex++;
} // textsize
idtext[subindex] = 0; // terminate string 

index = 1024; gotinfo = 1;
}}}} // imagebuffer
} // index

FSfclose (idpointer);
if (gotinfo == 1) {iseyedeethree = 1;}

}

Post Reply