jjccx

jjccx's blog
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

获得AMR音乐文件的时间

Posted on 2007-05-15 16:31  jjccx  阅读(375)  评论(0)    收藏  举报

我不知道这种办法是否是是简单的,不过这样能加深对AMR的认识

int GetDuration(char* szFileName)

{

   CFile file;

   int duration = 0;

 

   if(file.Open(szFileName, CFile::modeRead))

   {

      const unsigned char packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};

 

      int pos = 0;

      pos += 6;

      int lenth = file.GetSize();

      char toc = '\0';

      int framecount = 0;

      unsigned char ft;

 

      while (pos < lenth)

      {

         file.Seek(pos, CFile::begin);

         if (1 != file.Read(&toc, 1))

         {

            duration = lenth > 0 ? ((lenth - 6) / 650) : 0;

            file.Close();

            break;

         }

 

         ft = (toc >> 3) & 0x0F;

 

         pos += packed_size[ft] + 1;

 

         framecount++;

      }

 

      duration = framecount * 20 / 1000;

      file.Close();

   }

 

   return duration;

}