|
eeprom word BitRateValue[16]= {0, 32, 40, 48, 56, 64, 80, 96, 112,
128, 160, 192, 224, 256, 320, 0
};
eeprom byte MpegLayer[4]= {0, 3, 2, 1};
eeprom byte SampleRateValue[3]={44, 48, 32};
eeprom byte TimeInfo[7]= {'[',' ',' ',':',' ',' ',']'}; //time info.
dword mp3StreamHeader; //32 bits for saving mp3 stream header.
byte mp3BitRate; //bitrate of a mp3 file.
byte mp3SampleRate; //sample rate of a song.
byte mpegLayer; //layer of a song; eg:mp2 or mp3.
byte mp3Pos; //Global
//This function is used to decode BitRate and SampleRate of a song
//In this function,we read 512 bytes of a file to find stream header.
byte DecodeMP3StreamHeader( ) {
byte i=0;
mp3StreamHeader=0;
mp3BitRate=0;
mp3SampleRate=0;
mpegLayer=0;
readPos=0; //need to read a sector, set readPos=0
sectorPos=0;
//Read the first 512 bytes of MP3 file. This is where we will look for mp3 stream header.
ATA_Read_Sectors_LBA(clust2LBA(currentCluster),256);
fileoffset=512; // we have read 256 bytes of the file.
mp3Pos=0;
//we actually read 509 bytes so that we don't cross array
//boundary when we are doing following instructions in the loop.
while (mp3Pos<509) {
if (sectorBuffer.data[mp3Pos]==0xff) {//Check if it is "ff".
mp3Pos++; //check next byte.
if ((sectorBuffer.data[mp3Pos] & 0xf0)==0xf0){ //if it is true,we found header.
mp3Pos--;
//Load the bytes into mp3StreamHeader for calculating.
for(i=0; i<4; i++) mp3StreamHeader=(mp3StreamHeader<<8)+sectorBuffer.data[mp3Pos+i];
mpegLayer=(mp3StreamHeader & 0x00060000)>>17;
mp3BitRate=(mp3StreamHeader & 0x0000f000)>>12;
mp3SampleRate=(mp3StreamHeader & 0x00000c00)>>10;
i=mp3BitRate; mp3BitRate=BitRateValue;
i=mp3SampleRate; mp3SampleRate=SampleRateValue;
i=mpegLayer; mpegLayer=MpegLayer;
return 1; //decode successfully.
}
}
mp3Pos++;
} .
return 0; //we don't find stream header at beginning 512 bytes.Failed! return 0
} |
|