搜索
bottom↓
回复: 4

看这里做mp3很火,发个mp3文件头解码函数

[复制链接]

出0入0汤圆

发表于 2005-4-17 11:28:41 | 显示全部楼层 |阅读模式
eeprom word BitRateValue[16]= {0, 32, 40, 48, 56, 64, 80, 96, 112,

                               128, 160, 192, 224, 256, 320, 0

                              };

eeprom byte MpegLayer[4]= {0, 3, 2, 1};

eeprom byte SampleRateValue[3]={44, 48, 32};

eeprom byte TimeInfo[7]= {'[',' ',' ',':',' ',' ',']'}; //time info.



dword mp3StreamHeader;  //32 bits for saving mp3 stream header.

byte  mp3BitRate;       //bitrate of a mp3 file.

byte  mp3SampleRate;    //sample rate of a song.

byte  mpegLayer;        //layer of a song; eg:mp2 or mp3.



byte  mp3Pos;           //Global

//This function is used to decode BitRate and SampleRate of a song

//In this function,we read 512 bytes of a file to find stream header.

byte DecodeMP3StreamHeader( ) {

  byte i=0;

  mp3StreamHeader=0;

  mp3BitRate=0;

  mp3SampleRate=0;

  mpegLayer=0;

  

  readPos=0;   //need to read a sector, set readPos=0

  sectorPos=0;            

  //Read the first 512 bytes of MP3 file. This is where we will look for mp3 stream header.

  ATA_Read_Sectors_LBA(clust2LBA(currentCluster),256);

  fileoffset=512; // we have read 256 bytes of the file.



  mp3Pos=0;

  //we actually read 509 bytes so that we don't cross array

  //boundary when we are doing following instructions in the loop.

  while (mp3Pos<509) {

   if (sectorBuffer.data[mp3Pos]==0xff) {//Check if it is "ff".

     mp3Pos++; //check next byte.

     if ((sectorBuffer.data[mp3Pos] & 0xf0)==0xf0){ //if it is true,we found header.

      mp3Pos--;

      //Load the bytes into mp3StreamHeader for calculating.

      for(i=0; i<4; i++) mp3StreamHeader=(mp3StreamHeader<<8)+sectorBuffer.data[mp3Pos+i];

      mpegLayer=(mp3StreamHeader & 0x00060000)>>17;

      mp3BitRate=(mp3StreamHeader & 0x0000f000)>>12;

      mp3SampleRate=(mp3StreamHeader & 0x00000c00)>>10;

      i=mp3BitRate; mp3BitRate=BitRateValue;

      i=mp3SampleRate; mp3SampleRate=SampleRateValue;

      i=mpegLayer; mpegLayer=MpegLayer;

      return 1;   //decode successfully.

     }

   }

    mp3Pos++;

  }   .

  return 0; //we don't find stream header at beginning 512 bytes.Failed! return 0

}

出0入0汤圆

 楼主| 发表于 2005-4-17 11:31:40 | 显示全部楼层
说明:我这个函数能解码出mp3文件的头(详细请参考mp3文件结构说明:给个很好的网站:www.id3.org),解码出比特率,采样率以及文件压缩层.这个函数能运行的,我在用.看对做mp3的有帮助不.
-----此内容被elefan于2005-04-17,11:35:43编辑过

出0入0汤圆

发表于 2005-4-17 15:08:37 | 显示全部楼层
现在做MP3 难点主要在 文件系统.解码都有芯片.

出0入0汤圆

 楼主| 发表于 2005-4-17 16:06:05 | 显示全部楼层
文件系统是一个方面,另外的一个就是硬件底层操作方式.例如:CF,SD,MMC.HD的读写方式.只要这两个方面好了,基本上就没有什么问题了.然后再去研究USB.文件系统不是很难的事情,就是要肯花时间去看微软关于文件系统的说明以及网站上的一些资料.我发点资料上来.

点击此处下载armok0145962.rar

出0入0汤圆

 楼主| 发表于 2005-4-17 16:10:03 | 显示全部楼层
里面有些网页资料和微软关于长文件名longNameSpec的白皮书.FAT白皮书已经在这个上面了,我记得有人发过.
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-2 23:36

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表