海思Hi3516DV300上播放G711U音频文件
在海思Hi3516DV300芯片运行Linux系统下,可通过如下函数来实现G711U音频文件的播放:
int ADecPlayVoiceFile(const char* filename)
{
FILE* pfd;
AUDIO_STREAM_S stStream;
HI_S32 s32Ret,length,decLength,allLength = 0,aChn = 0;
HI_U8 buf[SAMPLE_AUDIO_PTNUMPERFRM+4] = {0,1,0,0};
pfd = fopen(filename, "rb");
if (NULL == pfd)
{
printf("%s: open file %s failed\n", __FUNCTION__, filename);
return -1;
}
memset(&stStream,0,sizeof(AUDIO_STREAM_S));
fseek(pfd, 0, SEEK_END);
length= ftell(pfd);
fseek(pfd, 0, SEEK_SET);
while(allLength < length)
{
decLength = (length - allLength)> SAMPLE_AUDIO_PTNUMPERFRM ? SAMPLE_AUDIO_PTNUMPERFRM:(length-allLength);
decLength = fread(buf+4, 1, decLength, pfd);
allLength += decLength;
buf[2] = decLength/2;
stStream.pStream = (HI_U8 *)buf;
stStream.u32Len = decLength + 4;
s32Ret = HI_MPI_ADEC_SendStream(aChn, &stStream, HI_TRUE);
if (s32Ret)
{
printf("%s %d chn:%d s32ret:%#x\n",__FUNCTION__, __LINE__, aChn, s32Ret);
break;
}
}
s32Ret = HI_MPI_ADEC_SendEndOfStream(aChn, HI_FALSE);
if (HI_SUCCESS != s32Ret)
{
printf("%s: HI_MPI_ADEC_SendEndOfStream failed!\n", __FUNCTION__);
}
fclose(pfd);
return s32Ret;
}
播放时,只需调用ADecPlayVoiceFile函数,传入G711U音频文件的路径即可。