AMR解码编程(C++直接用opencore-amr-0.1.3库)

来源:互联网 发布:数据质量整改报告 编辑:程序博客网 时间:2024/06/06 00:59

先定义每种帧的大小数组

const int sizes[] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 6, 5, 5, 0, 0, 0, 0 };

初始化解码器

void *m_pAmr = Decoder_Interface_init();


判断文件头,去掉文件头,读取第一个帧头,以第一个帧头为标准,后面用于判断坏帧

if (0 == memcmp(pBuf, "#!AMR\n", 6)){pos += 6;audioHeader = pBuf[pos];}

得到帧头就可以知道帧的长度

len = sizes[(<span style="font-family: Arial, Helvetica, sans-serif;">audioHeader</span><span style="font-family: Arial, Helvetica, sans-serif;"> >> 3) & 0x0f];</span>

中间有可能会出现坏帧,要去掉

while ( (pos < fileLen) && (audioHeader != pBuf[pos]) ){++pos;}

解一帧

Decoder_Interface_Decode(m_pAmr, &<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:10px;">pBuf[pos]</span></span><span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:10px;">,  pcmFrame</span>,  0);</span>

pos的位置包括帧头。


退出时要关闭解码器

if (NULL != m_pAmr){Decoder_Interface_exit(m_pAmr);m_pAmr = NULL;}


0 0
原创粉丝点击