音频海思头:
- HISI Aenc模块编码出来的数据是带海思头的,因而在解码的时候就要注意,音频文件是否需要海思头。
- 直接读取音频文件数据交给AO播放(HI_MPI_ADEC_SendStream),每一帧数据都是要带海思头的。如若文件数据没有海思头,就得手动进行填充再送给HISI接口。
如下图所示:
char decodebuf[164];
decodebuf[0]=0x00;
decodebuf[1]=0x01;
decodebuf[2]=0x50; /*数据净荷长度 (单位:short)0x50 = 80,80*2(short) = 160字节数据(g711),对应320字节的原始PCM数据,对应160个原始采样点*/
decodebuf[3]=0x00;
随后160个字节为数据部分
添加海思头的代码:
/*******************************************************************************
*@ Description :添加音频海思帧头(海思《HiMPP V4.0 媒体处理软件 FAQ》6.2.1章节)
*@ Input :<inputdata>:输入的编码后的 Audio 帧数据指针
<inputsamplelen>:输入的样本点数
<PersampleLen>:每帧数据有多少个采样点
每帧数据,采样点净荷长度(注意单位为:short)
*@ Output :<Hisivoicedata>:填充haisi头后的数据输出buf地址
*@ Return :成功:返回总采样点个数(4字节海思头算作两个采样点数据,包括在内)
*@ attention :
*******************************************************************************/
int HisiVoiceAddHisiHeader(short *inputdata, short *Hisivoicedata, int PersampleLen,int inputsamplelen)
{
int len = 0, outlen = 0;
short HisiHeader[2];
short *copyHisidata, *copyinputdata;
int copysamplelen = 0;//输入的样本点数
HisiHeader[0] = (short)(0x001<<8) & (0x0300); // = 0x0100
HisiHeader[1] = PersampleLen & 0x00ff;
copysamplelen = inputsamplelen; //输入的样本点数
copyHisidata = Hisivoicedata;//填充haisi头后的数据输出buf地址
copyinputdata = inputdata; //输入的编码后的 Audio 帧数据指针
while(copysamplelen >= PersampleLen)
{
memcpy(copyHisidata, HisiHeader, 2 * sizeof(short));
outlen += 2;
copyHisidata += 2;
memcpy(copyHisidata, copyinputdata, PersampleLen * sizeof(short));
copyinputdata += PersampleLen;
copyHisidata += PersampleLen;
copysamplelen -= PersampleLen;
outlen += PersampleLen;
}
return outlen;
}
关于AO和ADEC之间的参数配置,可参考:https://blog.csdn.net/spy_007_/article/details/102787416