ファイルからmp3ヘッダーを抽出しようとしています。これはID3タグとは異なります。mp3ヘッダーには、MPEGバージョン、ビットレート、周波数などに関する情報が保持されます。
ここでmp3ヘッダー構造の概要を見ることができます:http://upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg
私の問題は、ファイルをロードし、有効な(私が知る限り)バイナリ出力を受け取っているにもかかわらず、期待される値が表示されないことです。mp3同期ワードの場合、mp3ファイルの最初の12ビットはすべて1である必要があります。ただし、最初の8ビットだけで何か違うものを受け取っています。これは私に問題を示唆するでしょう。
ちなみに、有効なmp3ファイルがfopen経由で添付されています
// Main function
int main (void)
{
// Declare variables
FILE *mp3file;
char requestedFile[255] = "";
unsigned long fileLength;
// Counters
int i;
// Tryout
unsigned char byte; // Read from file
unsigned char mask = 1; // Bit mask
unsigned char bits[8];
// Memory allocation with malloc
// Ignore this at the moment! Will be used in the future
//mp3syncword=(unsigned int *)malloc(20000);
// Let's get the name of the file thats requested
strcpy(requestedFile,"testmp3.mp3"); // lets hardcode this into here for now
// Open the file
mp3file = fopen(requestedFile, "rb"); // open the requested file with mode read, binary
if (!mp3file){
printf("Not found!"); // if we can't find the file, notify the user of the problem
}
// Let's get some header data from the file
fseek(mp3file,0,SEEK_SET);
fread(&byte,sizeof(byte),1,mp3file);
// Extract the bits
for (int i = 0; i < sizeof(bits); i++) {
bits[i] = (byte >> i) & mask;
}
// For debug purposes, lets print the received data
for (int i = 0; i < sizeof(bits); i++) {
printf("Bit: %d\n",bits[i]);
}