SDK : Hi3516CV300_SDK_V1.0.2.0
前一篇描述了HI3518EV200平台AEC + ANR功能的使用,这篇就不做多赘述, 不同的是该SDK版本的接口和之前的有点不一样,之前的是AI AO需要分开操作,现在的是直接一个接口完成对AI AO的设置而已。
接口:HI_MPI_AI_SetTalkVqeAttr HI_MPI_AI_EnableVqe
【注意】
代码如下:
只开了VQE模块下的 HPF + AEC + ANR 功能
//注意:调用该函数前,必须先使能对应的 AI 通道。
//注意:调用该函数前,必须先使能对应的 AI 通道。
static int audio_config_TalkVqeAttr(HI_S32 AiDevId, HI_S32 AiChn, HI_S32 AoDevId, HI_S32 AoChn)
{
AI_TALKVQE_CONFIG_S ai_talkvqe;
memset(&ai_talkvqe,0,sizeof(AI_TALKVQE_CONFIG_S));
ai_talkvqe.u32OpenMask = AI_TALKVQE_MASK_HPF|AI_TALKVQE_MASK_AEC|AI_TALKVQE_MASK_ANR;
ai_talkvqe.s32WorkSampleRate = AUDIO_SAMPLE_RATE_8000;
ai_talkvqe.s32FrameSample = AUDIO_PTNUMPERFRM;
ai_talkvqe.enWorkstate = 0;
ai_talkvqe.stHpfCfg.bUsrMode = 1;
ai_talkvqe.stHpfCfg.enHpfFreq = AUDIO_HPF_FREQ_80;
//AEC config
ai_talkvqe.stAecCfg.bUsrMode = 1;
ai_talkvqe.stAecCfg.s8CngMode = 1;//舒适噪音模式
ai_talkvqe.stAecCfg.s8NearAllPassEnergy = 1;
ai_talkvqe.stAecCfg.s8NearCleanSupEnergy = 2;
ai_talkvqe.stAecCfg.s16DTHnlSortQTh = 16384;
ai_talkvqe.stAecCfg.s16EchoBandLow = 10;
ai_talkvqe.stAecCfg.s16EchoBandHigh = 41;
ai_talkvqe.stAecCfg.s16EchoBandLow2 = 47;
ai_talkvqe.stAecCfg.s16EchoBandHigh2 = 63;
HI_S16 s16ERLBand[6] = {4, 6, 36, 49, 50, 51};
HI_S16 s16ERL[7] = {7, 10, 16, 10, 18, 18, 18};
memcpy(ai_talkvqe.stAecCfg.s16ERLBand,s16ERLBand,sizeof(s16ERLBand));
memcpy(ai_talkvqe.stAecCfg.s16ERL,s16ERL,sizeof(s16ERL));
ai_talkvqe.stAecCfg.s16VioceProtectFreqL = 3;
ai_talkvqe.stAecCfg.s16VioceProtectFreqL1 = 6;
//ANR config
ai_talkvqe.stAnrCfg.bUsrMode = 1;
ai_talkvqe.stAnrCfg.s16NrIntensity = 5;
ai_talkvqe.stAnrCfg.s16NoiseDbThr = 45;
ai_talkvqe.stAnrCfg.s8SpProSwitch = 0;
ai_talkvqe.stAgcCfg.bUsrMode = 0;
//ai_talkvqe.stEqCfg.stEqCfg =
ai_talkvqe.stHdrCfg.bUsrMode = 0;
HI_S32 ret = HI_MPI_AI_SetTalkVqeAttr(AiDevId,AiChn,AoDevId,AoChn,&ai_talkvqe);
if(ret < 0)
{
ERROR_LOG("HI_MPI_AI_SetTalkVqeAttr failed! ret(%0x)\n",ret);
return -1;
}
ret = HI_MPI_AI_EnableVqe(AiDevId, AiChn);
if(ret < 0)
{
ERROR_LOG("HI_MPI_AI_EnableVqe failed! ret(%0x)\n",ret);
return -1;
}
return 0;
}
其中的参数基本上只是用了默认参数,没有做调试,回音和噪音已经比没有使用之前好很多。
也可不开启user mode ,只使能功能,系统也会采用默认参数:
ai_talkvqe.s32WorkSampleRate = AUDIO_SAMPLE_RATE_16000;
ai_talkvqe.s32FrameSample = AUDIO_PTNUMPERFRM; //480
ai_talkvqe.enWorkstate = VQE_WORKSTATE_COMMON;
ai_talkvqe.stAgcCfg.bUsrMode = HI_FALSE; /*bUsrMode 不使能,将使用内部默认参数*/
ai_talkvqe.stAecCfg.bUsrMode = HI_FALSE;
ai_talkvqe.stAnrCfg.bUsrMode = HI_FALSE;
ai_talkvqe.stHpfCfg.bUsrMode = HI_TRUE;
ai_talkvqe.stHpfCfg.enHpfFreq = AUDIO_HPF_FREQ_150;
ai_talkvqe.u32OpenMask = AI_TALKVQE_MASK_HPF | AI_TALKVQE_MASK_ANR | AI_TALKVQE_MASK_AEC;
另外,注意以下图中紫色的文字,可能导致使能AEC功能后,音频产生噪音 :
--------VO VQE功能设置---------------------------------------------------------------------------------------------------------------------------------------
在开启AITalkVQE功能时,同时把AO VQE功能也开启,效果会更好(但要注意AO VQE开启的条件)
/*---#设置AO 的 VQE 参数------------------------------------------------------------*/
AO_VQE_CONFIG_S ao_vqe = {0};
ao_vqe.u32OpenMask = AO_VQE_MASK_HPF|AO_VQE_MASK_ANR|AO_VQE_MASK_AGC/*|AO_VQE_MASK_EQ*/;
ao_vqe.s32WorkSampleRate = AUDIO_SAMPLE_RATE_16000;
ao_vqe.s32FrameSample = AUDIO_PTNUMPERFRM;
ao_vqe.enWorkstate = VQE_WORKSTATE_COMMON;
ao_vqe.stHpfCfg.bUsrMode = HI_TRUE;
ao_vqe.stHpfCfg.enHpfFreq = AUDIO_HPF_FREQ_120;
ao_vqe.stAnrCfg.bUsrMode = HI_FALSE;
ao_vqe.stAgcCfg.bUsrMode = HI_FALSE; /*bUsrMode 不使能,将使用内部默认参数*/
//ao_vqe.stEqCfg 采用内部默认值
//设置之前需要先保证已经开启了AO设备+通道
ret = HI_MPI_AO_SetVqeAttr(AO_DEVICE_ID,TALK_AO_CHN,&ao_vqe);
if(ret < 0)
{
ERROR_LOG("HI_MPI_AO_SetVqeAttr failed! ret(%0x)\n",ret);
return HLE_RET_ERROR;
}
/*---#------------------------------------------------------------*/