我正在编写一些快速代码来尝试从 mp3 文件头中提取数据。
目标是从标头中提取信息,例如比特率和其他重要信息,以便我可以适当地将文件流式传输到带有必要参数的 mp3decoder。
这是显示 mp3header 信息的维基百科图像:http: //upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg
我的问题是,我是否正确地攻击了这个?打印收到的数据毫无价值——我只是得到一堆随机字符。我需要获取二进制文件,以便对其进行解码并确定重要信息。
这是我的基线代码:
// mp3 Header File IO.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
// Main function
int main (void)
{
// Declare variables
FILE *mp3file;
char *mp3syncword; // we will need to allocate memory to this!!
char requestedFile[255] = "";
unsigned long fileLength;
// Counters
int i;
// Memory allocation with malloc
mp3syncword=(char *)malloc(2000);
// Let's get the name of the requested file (hard-coded for now)
strcpy(requestedFile,"testmp3.mp3");
// Open the file with mode read, binary
mp3file = fopen(requestedFile, "rb");
if (!mp3file){
// If we can't find the file, notify the user of the problem
printf("Not found!");
}
// Let's get some header data from the file
fseek(mp3file,1,SEEK_SET);
fread(mp3syncword,32,1,mp3file);
// For debug purposes, lets print the received data
for(i = 0; i < 32; ++i)
printf("%c", ((char *)mp3syncword)[i]);
enter code here
return 0;
}
帮助表示赞赏。