我正在尝试从文件中提取 mp3 标头。这与 ID3 标签不同——mp3 标头是保存有关 MPEG 版本、比特率、频率等信息的地方。
您可以在此处查看 mp3 标头结构的概述:http: //upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg
我的问题是,尽管加载了文件并且现在接收到有效的(据我所知)二进制输出,但我没有看到预期的值。mp3 文件的前 12 位应全为 1,用于 mp3 同步字。但是,仅前 8 位我就收到了不同的东西。这对我来说是个问题。
作为旁注,我有一个通过 fopen 附加的有效 mp3 文件
// 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]);
}