6. Block Diagram:¶

[Illustration]:
Similar to the general audio recording process, after initialization, a thread is used to capture audio frames using CVI_AI_GetFrame.
However, when VQE/AEC is enabled:
Two VQE APIs are set:
CVI_AI_SetTalkVqeAttr
CVI_AI_EnableVqe
When AEC is enabled, the audio input is dual-channel and the audio output is single-channel:
Please note that the recording attribute CVI_AI_SetPubAttr must be set to dual-channel.
When storing with CVI_AI_GetFrame, the channel count for each frame is only for single-channel.
6.1. Detailed Code Explanation¶
(Please refer to cvi_sample_audio.c, case 10; and cvi_aec_test.c for unit testing process):
The user can enable the VQE function through two APIs, CVI_AI_SetTalkVqeAttr and CVI_AI_EnableVqe. Only three parameter structures need to be set in CVI_AI_SetTalkVqeAttr:
AUDIO_DEV AiDevId: the audio device ID, which should be consistent with the CVI_AI_Enable ID.
AI_CHN AiCh: the audio device channel, which should be consistent with the CVI_AI_EnableChn ID.
AI_TALKVQE_CONFIG_S *pstVqeConfig,
The AI_TALKVQE_CONFIG_S structure will have the following sub-structures:
CVI_U16 para_client_config;
CVI_U32 u32OpenMask;
CVI_S32 s32WorkSampleRate;
/* Sample Rate: 8KHz/16KHz. default: 8KHz*/
//MIC IN VQE setting
AI_AEC_CONFIG_S stAecCfg;
AUDIO_ANR_CONFIG_S stAnrCfg;
AUDIO_AGC_CONFIG_S stAgcCfg;
AUDIO_DELAY_CONFIG_S stAecDelayCfg;
CVI_S32 s32RevMask;//turn this flag to default 0x11
CVI_S32 para_notch_freq;//user can ignore this flag
CVI_CHAR customize[MAX_AUDIO_VQE_CUSTOMIZE_NAME];
[Parameter]:
AI_AEC_CONFIG_S stAecCfg;
AUDIO_ANR_CONFIG_S stAnrCfg;
AUDIO_AGC_CONFIG_S stAgcCfg;
The three structures mentioned above can set the corresponding VQE parameters, and decide which switch is needed to use the current VQE via u32OpenMask.
s32FrameSample = 160; // The sampling number of each audio frame is a multiple of 160.
s32WorkSampleRate //Sampling rate(only support speech sampling rate 8000/16000)
enWorkstate = VQE_WORKSTATE_COMMON;
para_notch_freq = 0; // Please set the custom parameters to 0.
s32RevMask = 0; // Please set the custom config(custom parameters) to 0.
customize // Please set the custom blocking to "none".
[Switch]:
ex: (If you need to fully enable the function.)
u32OpenMask = LP_AEC_ENABLE|NLP_AES_ENABLE|NR_ENABLE|AGC_ENABLE|DCREMOVER_ENABLE|DG_ENABLE|DELAY_ENABLE
ex: (If you need to only enable the AGC/ANR.)
u32OpenMask = (AI_TALKVQE_MASK_AGC)|(AI_TALKVQE_MASK_ANR)
ex: (Enable AEC/AGC/ANR)
u32OpenMask = (AI_TALKVQE_MASK_AEC)|(AI_TALKVQE_MASK_AGC)|(AI_TALKVQE_MASK_ANR)