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;
}
助けていただければ幸いです。