Accessing binary MP3 Header in C via fopen

I am trying to extract the mp3 header from a file. This is different then the ID3 tags -- the mp3 header is where information about the MPEG version, bit rate, frequency, etc is held. You can see an overview of the mp3 header structure here: http://upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg My problem is, despite loading the file and now receiving valid (as far as I know) binary output, I am not seeing the expected values. The first 12 bits of the mp3 file should be all ones, for the mp3 sync word. However, I am receiving something different for the first 8 bits alone. This would suggest a problem to me. As a side note, I have a valid mp3 file being attached via 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]); }
I seem to recall that ID3v2 integrates into the MP3 structure to store it's info at the start of the file, but with the sync bits not matching. That's not your main problem, though - refer to the other answers for that.

以上就是Accessing binary MP3 Header in C via fopen的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏