Skip to content

SGS APC ALGORITHM USER GUIDE


REVISION HISTORY

Revision No.
Description
Date
1.0
  • Initial release
  • 09/09/2020
    1.1
  • Modified API
  • 10/15/2020
    1.2
  • Add parameter in AGC config
  • 12/17/2020
    1.3
  • Add parameter in ANR config
  • 08/03/2021
    1.4
  • Add frequency domain DRC in AGC module
  • 08/05/2021
    1.5
  • Add IaaApc_GetVadOut function
  • 08/10/2021
    1.6
  • Add IaaApc_ApplyDigitalGain function
  • 04/06/2022
    1.7
  • Add IaaApc_Enhance_NNBFMode, IaaApc_SetCompressionRatioCurve, IaaApc_NrEstimateReferAec, APC_BF_HANDLE
  • 07/21/2022
    1.71
  • Modified structure description in AudioProcessInit
  • 08/16/2022
    1.8
  • Add IaaApc_FilterDesign, IaaApc_FilterApply, IaaEq_FilterDesign, IaaEq_FilterApply
  • 08/17/2022
    1.9
  • Add IaaAnr_Enhance_NNBFMode
  • 09/27/2022
    1.91
  • More detail for stereo data arrangement
  • 10/25/2022
    1.92
  • More detail for ANR filter mode 5
  • 12/12/2022
    1.93
  • Update tunable anr_intensity for ANR filter mode 5
  • 03/07/2023
    2.0
  • Add IaaApc_GetAPIVersion, IaaApc_SetHandleId, IaaAnr_SetHandleId, IaaEq_SetHandleId, IaaAgc_SetHandleId
  • 03/24/2023
    2.01
  • Revise IaaApc_Enhance_NNBFMode to IaaApc_EnhanceNNBFMode and IaaAnr_Enhance_NNBFMode to IaaAnr_EnhanceNNBFMode
  • 04/17/2023
    2.1
  • Add IaaApc_GetJsonFileSize, IaaApc_NrReadJson, IaaAnr_GetJsonFileSize and IaaAnr_ReadJson function
  • 07/25/2023
    2.2
  • Add IaaApc_EnableComfortNoise, IaaAnr_EnableComfortNoise, IaaEq_EnableComfortNoise and IaaAgc_EnableComfortNoise function
  • 10/12/2023
    2.21
  • Add frequency domain Agc setting function detail
  • 10/23/2023
    2.3
  • Add auto smooth API and comfort noise apply API
  • 02/22/2024
    2.31
  • Add more detail about IIR filter setting
  • 02/22/2024
    2.4
  • Add IaaApc_SwitchReadFromJson, IaaApc_InitReadFromJson, IaaApc_ConfigReadFromJson, IaaApc_SetAgcReadFromJson, IaaApc_FilterDesignReadFromJson, IaaAnr_InitReadFromJson, IaaAnr_ConfigReadFromJson, IaaEq_GetJsonFileSize, IaaEq_InitReadFromJson, IaaEq_ConfigReadFromJson, IaaEq_FilterDesignReadFromJson, IaaAgc_GetJsonFileSize, IaaAgc_InitReadFromJson, IaaAgc_ConfigReadFromJson, IaaAgc_SetAgcReadFromJson
  • 04/15/2024
    2.41
  • Update typesetting and description in API
  • 04/19/2024
    2.5
  • Add IaaAnr_NrEstimateReferAec
  • 05/22/2024
    2.51
  • Add more detail about Hpf user_mode setting and description of IaaApc_GetVadOut
  • 06/03/2024
    2.6
  • Add IaaApc_FilterFreqz and IaaEq_FilterFreqz
  • 07/11/2024
    2.61
  • Update ANR config constrain and description of ANR filter mode 5
  • 09/11/2024
    2.7
  • Add IaaApc_OptionReadFromJson and structure of AudioApcOption for applying IaaApc_ApplyDigitalGain through json file
  • 09/11/2024
    2.8
  • Add IaaApc_ReadJson through json file
  • 09/16/2024
    2.9
  • Add IaaEq_ReadJson and IaaAgc_ReadJson through json file
  • 10/08/2024
    2.91
  • Update description of IaaApc_NrEstimateReferAec and IaaAnr_NrEstimateReferAec
  • 01/08/2025
    2.92
  • Update description of AgcGainInfo and AudioAgcConfig
  • 01/13/2025
    2.93
  • Update description of anr_filter_mode 6
  • 03/31/2025
    2.94
  • Update file description and copyright
  • 04/19/2025
    2.95
  • Remove copyright and update file description
  • 05/15/2025
    2.96
  • Fix enum type IAA_HPF_FREQ order as description
  • 07/24/2025
    2.97
  • Fix formatting and textual errors
  • 10/28/2025
    2.98
  • Remove ANR5v1.2.4 description
  • 10/29/2025
    2.99
  • Add and update description of Chapter 1
  • 11/21/2025

    1. OVERVIEW


    1.1. Module Description

    APC (Audio Process Chain) is an algorithm combination including noise reduction, equalizer and automatic gain control. The main purpose of APC is to improve audio quality. The internal algorithm connection process of APC is ANR → EQ/HPF → AGC. Improve SNR by eliminating noise, then adjust EQ/HPF according to the curve required by the customer, and finally gain or attenuate the output volume through AGC.

    Keyword

    • AGC

      AGC(Automatic Gain Control), used to control digital signal output.

    • EQ

      EQ(Equalizer), used to gain or attenuate specific frequency bands.

    • ANR

      ANR(Acoustic Noise Reduction), used to remove the continued and fixed frequency noise in the environment.

    • HPF

      HPF(High-Pass Filtering).

    Note

    In order to facilitate debugging and confirm the effect of the algorithm, the user application needs to implement replacement algorithm parameter and grab audio data.


    1.2. Basic Structure

    After the APC algorithm completes memory allocation and parameter setup, the input signal buffer becomes the sole runtime requirement. The APC applies the configured parameters and algorithm to the buffer contents and commits the processed output directly back to the original buffer location.


    1.3. Function Introduction

    ANR :

    To suppress non-speech steady-state noise in the input signal and improve the signal-to-noise ratio (SNR).

    EQ :

    To apply energy gain or attenuation to specific frequency bands, adjusting the relative amplitude across bands to improve overall audio quality.

    HPF :

    To permit only signal components above the configured cutoff frequency to pass, while attenuating all components below that threshold.

    AGC :

    To compute the input signal energy based on the configured compression curve parameters, automatically adjust the gain, and apply it to the input signal to maintain signal stability.


    1.4. Application Scenarios

    APC is commonly applied in conference systems, building intercoms, security monitoring, and consumer electronic products, delivering low-noise, high-quality, and stable audio performance across diverse environments.


    1.5. Chip Difference Description

    Across different chip series, the APC algorithm demonstrates consistent performance with no observable differences.


    1.6. Example Introduction

    Use the APC API to obtain the memory size required by the APC algorithm, initialize the APC algorithm handle, configure parameters to the APC handle, execute the APC algorithm, and release the APC algorithm resources.

        #include <stdio.h>
        #include <unistd.h>
        #include <fcntl.h>
        #include <string.h>
        #include <time.h>
        #include <stdlib.h>
        #ifndef OS_WINDOWS
        #include <sys/ioctl.h>
        #endif
        #include <sys/types.h>
        #include <sys/stat.h>
        #include <sys/time.h>
    
        #include "AudioProcess.h"
    
    
        #define USE_MALLOC          (1)
        #define USE_JSON            (0)
        #define FILTER_ENABLE       (0)
        #define FREQ_AGC_ENABEL     (1)
    
        unsigned int WorkingBuffer2[1] = {0};
    
        typedef unsigned char                uint8;
        typedef unsigned short               uint16;
        typedef unsigned long                uint32;
    
        float AVERAGE_RUN(int a)
        {
            static unsigned int num = 0;
            static float avg = 0;
            if(num == 0) avg = 0;
            num++;
            avg = avg + ((float)a - avg) / ((float)num);  
            return avg;
        }
        unsigned int _OsCounterGetMs(void)
        {
            struct  timeval t1;
            gettimeofday(&t1,NULL);
            unsigned int T = ( (1000000 * t1.tv_sec)+ t1.tv_usec )/1000;
            return T;
        }
    
        int main(int argc, char *argv[])
        {
            short input[1024];
            unsigned int T0, T1;
            float avg = 0;
            float peak = 0;
            char input_file[512];
            char output_file[512];
            int counter=0;
            int intensity_band[6] = {3,24,40,64,80,128};
            int intensity[7] = {0,30,0,30,0,30,0};
            short eq_table[129]  = { 1, 1, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5    };
            memset (eq_table,0,sizeof(short)*129);
            short compression_ratio_input[_AGC_CR_NUM] = {-65,-55,-48,-25,-18,-12,0};
            short compression_ratio_output[_AGC_CR_NUM] = {-65,-50,-27,-12,-1,-1,-1};
        #if FREQ_AGC_ENABEL
            int freqBand[_AGC_FREQ_BAND_NUM] = {3000,6000,8000};
            int compressionRatioArrayLowInput[_AGC_CR_NUM] = {-80,-60,-40,-20,0,0,0};
            int compressionRatioArrayLowOutput[_AGC_CR_NUM] = {-5,-5,-5,-5,-5,-5,-5};
            int compressionRatioArrayMidInput[_AGC_CR_NUM] = {-80,-60,-40,-20,0,0,0};
            int compressionRatioArrayMidOutput[_AGC_CR_NUM] = {-80,-60,-40,-20,0,0,0};
            int compressionRatioArrayHighInput[_AGC_CR_NUM] = {-80,-60,-40,-20,0,0,0};
            int compressionRatioArrayHighOutput[_AGC_CR_NUM] = {-80,-60,-40,-20,0,0,0};
        #endif
    
            AudioApcBufferConfig apc_switch;
            memset(&apc_switch,0,sizeof(AudioApcBufferConfig));
            apc_switch.anr_enable = 1;
            apc_switch.eq_enable = 1;
            apc_switch.dr_enable = 0;
            apc_switch.vad_enable = 0;
            apc_switch.agc_enable = 1;
    
            int buffersize = IaaApc_GetBufferSize(&apc_switch);
            if(buffersize == 0){
                printf("IaaApc_GetBufferSize() error.\t\n");
                return -1;
            }
            else{
                printf("IaaApc_GetBufferSize() succeed.\t\n");
            }
        #if USE_MALLOC
            char *working_buf_ptr = (char*)malloc(buffersize);
        #else
            char working_buf_ptr[512*1000];
        #endif
    
        #if USE_JSON
            unsigned int use_anr_intl_json = 1;
            char anr_intl_json_file[512];
            sprintf(anr_intl_json_file,"%s","./../sample/data/AnrInternalJson.json");
            int anr_intl_buffersize = IaaApc_GetJsonFileSize(anr_intl_json_file);
            if(anr_intl_buffersize == 0){
                printf("IaaApc_GetJsonFileSize() error. Can not load json file [%s]\t\n", anr_intl_json_file);
                use_anr_intl_json = 0;
            }
            else{
                printf("IaaApc_GetJsonFileSize() succeed.\t\n");
            }
        #if USE_MALLOC
            char *anr_intl_json_buf_ptr = (char*)malloc(anr_intl_buffersize);
        #else
            char anr_intl_json_buf_ptr[512*1000];
        #endif
        #endif
    
        #if USE_JSON
            unsigned int use_apc_intl_json = 1;
            char apc_intl_json_file[512];
            sprintf(apc_intl_json_file,"%s","./../sample/data/ApcInternalJson.json");
            int apc_intl_buffersize = IaaApc_GetJsonFileSize(apc_intl_json_file);
            if(apc_intl_buffersize == 0){
                printf("IaaApc_GetJsonFileSize() error. Can not load json file [%s]\t\n", apc_intl_json_file);
                use_apc_intl_json = 0;
            }
            else{
                printf("IaaApc_GetJsonFileSize() succeed.\t\n");
            }
        #if USE_MALLOC
            char *apc_intl_json_buf_ptr = (char*)malloc(apc_intl_buffersize);
        #else
            char apc_intl_json_buf_ptr[512*1000];
        #endif
        #endif
    
            FILE * fin, * fout;
            int ret1;
            AudioProcessInit apc_init;
            AudioAnrConfig anr_config;
            AudioEqConfig eq_config;
            AudioHpfConfig hpf_config;
            AudioAgcConfig agc_config;
            APC_HANDLE handle;
            memset(&apc_init,0,sizeof(AudioProcessInit));
            memset(&anr_config,0,sizeof(AudioAnrConfig));
            memset(&eq_config,0,sizeof(AudioEqConfig));
            memset(&hpf_config,0,sizeof(AudioHpfConfig));
            memset(&agc_config,0,sizeof(AudioAgcConfig));
            int PN=128;
            apc_init.point_number = PN;
            apc_init.channel = 1;
            apc_init.sample_rate = IAA_APC_SAMPLE_RATE_16000;
    
            handle = IaaApc_Init((char *)working_buf_ptr, &apc_init, &apc_switch);
            if(handle==NULL){
                printf("IaaApc_Init() error.\t\n");
                return -1;
            }
            else{
                printf("IaaApc_Init() succeed.\t\n");
            }
    
            /******ANR Config*******/
            anr_config.anr_enable = apc_switch.anr_enable;
            anr_config.user_mode = 1;
            anr_config.anr_filter_mode = 0;
            memcpy(anr_config.anr_intensity_band, intensity_band, 6*sizeof(int));
            memcpy(anr_config.anr_intensity, intensity, 7*sizeof(int));
            anr_config.anr_smooth_level = 10;
            anr_config.anr_converge_speed = 2;
            /******EQ Config********/
            eq_config.eq_enable =apc_switch.eq_enable;
            eq_config.user_mode = 1;
            memcpy(eq_config.eq_gain_db, eq_table,_EQ_BAND_NUM*sizeof(short));
            /******HPF Config********/
            hpf_config.hpf_enable = apc_switch.eq_enable;
            hpf_config.user_mode =1;
            hpf_config.cutoff_frequency = AUDIO_HPF_FREQ_150;
            /******AGC Config********/
            agc_config.agc_enable = apc_switch.agc_enable;
            agc_config.user_mode = 1;
            agc_config.gain_info.gain_max  = 40;
            agc_config.gain_info.gain_min  = -10;
            agc_config.gain_info.gain_init = 12;
            agc_config.drop_gain_max = 36;
            agc_config.gain_step = 1;
            agc_config.attack_time = 1;
            agc_config.release_time = 1;
            agc_config.noise_gate_db = -80;
            memcpy(agc_config.compression_ratio_input, compression_ratio_input,_AGC_CR_NUM*sizeof(short));
            memcpy(agc_config.compression_ratio_output, compression_ratio_output,_AGC_CR_NUM*sizeof(short));
            agc_config.noise_gate_attenuation_db = 0;
            agc_config.drop_gain_threshold = -5;
    
            if(IaaApc_Config(handle,&anr_config,&eq_config,&hpf_config,NULL,NULL,&agc_config) != -0){
                printf("IaaApc_Config() error.\t\n");
                return -1;
            }
            else{
                printf("IaaApc_Config() succeed.\t\n");
            }
    
            // IaaApc_EnableComfortNoise(handle, 1, -50);
    
        #if USE_JSON
            if(apc_switch.anr_enable && use_anr_intl_json){
                if(IaaApc_NrReadJson(handle, anr_intl_json_buf_ptr, anr_intl_json_file, anr_intl_buffersize) != 0){
                    printf("IaaApc_NrReadJson() error.\t\n");
                    return -1;
                }
                else{
                    printf("IaaApc_NrReadJson() succeed.\t\n");
                }
            }
        #endif
    
        #if USE_JSON
            if(use_apc_intl_json){
                if(IaaApc_ReadJson(handle, apc_intl_json_buf_ptr, apc_intl_json_file, apc_intl_buffersize) != 0){
                    printf("IaaApc_ReadJson() error.\t\n");
                    return -1;
                }
                else{
                    printf("IaaApc_ReadJson() succeed.\t\n");
                }
            }
        #endif
    
        #if FILTER_ENABLE
            float h[512];
            //filter 1
            AudioFilterConfig filter_design;
            filter_design.q_factor = 5;
            filter_design.f0 = 1000;
            filter_design.type = EQ_NOTCH_FILTER;
            filter_design.gain = -10;
            //filter 2
            AudioFilterConfig filter_design2;
            filter_design2.q_factor = 5;
            filter_design2.f0 = 5000;
            filter_design2.type = EQ_NOTCH_FILTER;
            filter_design2.gain = -10;
            //filter 3
            AudioFilterConfig filter_design3;
            filter_design3.q_factor = 5;
            filter_design3.f0 = 500;
            filter_design3.type = EQ_NOTCH_FILTER;
            filter_design3.gain = -10;
    
            if(IaaApc_FilterDesign(handle, 1, &filter_design) != 0){
                printf("IaaEq_FilterDesign() error.\t\n");
                return -1;
            }
            if(IaaApc_FilterDesign(handle, 2, &filter_design2) != 0){
                printf("IaaEq_FilterDesign() error.\t\n");
                return -1;
            }
            if(IaaApc_FilterDesign(handle, 3, &filter_design3) != 0){
                printf("IaaEq_FilterDesign() error.\t\n");
                return -1;
            }
            IaaApc_FilterFreqz(handle,h);
        #endif
    
    
        #if FREQ_AGC_ENABEL
            if(agc_config.user_mode == 2){
                IaaApc_SetAgcFreqBand(handle, freqBand);
                IaaApc_SetLowFreqCompressionRatioCurve(handle, compressionRatioArrayLowInput, compressionRatioArrayLowOutput);
                IaaApc_SetMidFreqCompressionRatioCurve(handle, compressionRatioArrayMidInput, compressionRatioArrayMidOutput);
                IaaApc_SetHighFreqCompressionRatioCurve(handle, compressionRatioArrayHighInput, compressionRatioArrayHighOutput);
            }
        #endif
    
            AudioProcessInit apc_init_cpy;
            AudioAnrConfig anr_config_cpy;
            AudioEqConfig eq_config_cpy;
            AudioHpfConfig hpf_config_cpy;
            AudioAgcConfig agc_config_cpy;
            memset(&apc_init_cpy,0,sizeof(AudioProcessInit));
            memset(&anr_config_cpy,0,sizeof(AudioAnrConfig));
            memset(&eq_config_cpy,0,sizeof(AudioEqConfig));
            memset(&hpf_config_cpy,0,sizeof(AudioHpfConfig));
            memset(&agc_config_cpy,0,sizeof(AudioAgcConfig));
            if(IaaApc_GetConfig(handle, &apc_init_cpy, &anr_config_cpy, &eq_config_cpy, &hpf_config_cpy, NULL, NULL, &agc_config_cpy) != ALGO_APC_RET_SUCCESS){
                printf("IaaApc_GetConfig() error.\t\n");
                return -1;
            }
            else{
                printf("IaaApc_GetConfig() succeed.\t\n");
            }
            sprintf(input_file,"%s","./../sample/data/APC_AFE_16K.wav");
            sprintf(output_file,"%s","./../sample/data/APC_out_16K.wav");
    
            fin = fopen(input_file, "rb");
            if(!fin)
            {
                printf("the input file %s could not be open\n",input_file);
                return -1;
            }
    
            fout = fopen(output_file, "wb");
            if(!fout)
            {
                printf("the output file could not be open\n");
                return -1;
            }
    
            fread(input, sizeof(char), 44, fin); // read header 44 bytes
            fwrite(input, sizeof(char),44, fout); // write 44 bytes output
    
            while(fread(input, sizeof(short), apc_init.point_number*apc_init.channel, fin))
            {
    
                counter++;
                T0  = (long)_OsCounterGetMs();
                ret1 = IaaApc_Run(handle,input);
        #if FILTER_ENABLE
                ret1 += IaaApc_FilterApply(handle, input);
        #endif
                T1  = (long)_OsCounterGetMs();
                avg += (T1 - T0);
                if(peak < (T1 - T0))
                    peak = (T1 - T0);
    
                if(counter%1000== 999)
                {
                    printf("counter = %d\n", counter);
                    printf("current time = %f\n", (float)counter*PN/apc_init.sample_rate);
                    printf("process time = %lu(ms)\t",(long)(T1 - T0));
                }
    
                if(ret1 != 0)
                {
                    printf("Error occured in APC\n");
                    break;
                }
    
                fwrite(input, sizeof(short), apc_init.point_number*apc_init.channel, fout);
            }
            avg /= counter;
            printf("AVG is %.2f ms\n",avg);
            printf("PEAK is %.2f ms\n",peak);
            IaaApc_Free(handle);
            free(working_buf_ptr);
            fclose(fin);
            fclose(fout);
    
            printf("Done\n");
        return 0;
        }
    

    Use the APC API to read parameters from the APC JSON file, obtain the memory size required for APC algorithm execution, initialize the APC algorithm handle, configure parameters to the handle, execute the APC algorithm, and release the APC algorithm resources.

        #include <stdio.h>
        #include <unistd.h>
        #include <fcntl.h>
        #include <string.h>
        #include <time.h>
        #include <stdlib.h>
        #ifndef OS_WINDOWS
        #include <sys/ioctl.h>
        #endif
        #include <sys/types.h>
        #include <sys/stat.h>
        #include <sys/time.h>
    
        #include "AudioProcess.h"
    
        #if (ANR_IPU_ENABLE)
        #include "mi_sys.h"
        #endif
    
        #define USE_MALLOC               (1)
        #define USE_JSON                 (1)
        #define FILTER_ENABLE            (0)
        #define FREQ_AGC_ENABEL          (0)
        #define DIGITAL_GAIN_ENABLE      (0)
    
        unsigned int WorkingBuffer2[1] = {0};
    
        typedef unsigned char                uint8;
        typedef unsigned short               uint16;
        typedef unsigned long                uint32;
    
        float AVERAGE_RUN(int a)
        {
            static unsigned int num = 0;
            static float avg = 0;
            if(num == 0) avg = 0;
            num++;
            avg = avg + ((float)a - avg) / ((float)num);  
            return avg;
        }
        unsigned int _OsCounterGetMs(void)
        {
            struct  timeval t1;
            gettimeofday(&t1,NULL);
            unsigned int T = ( (1000000 * t1.tv_sec)+ t1.tv_usec )/1000;
            return T;
        }
    
        int main(int argc, char *argv[])
        {
        #if (ANR_IPU_ENABLE)
            MI_SYS_Init(0);
        #endif
            short input[1024];
            unsigned int T0, T1;
            float avg = 0;
            float peak = 0;
            char input_file[512];
            char output_file[512];
            int counter=0;
        #if FREQ_AGC_ENABEL
            int freqBand[_AGC_FREQ_BAND_NUM];
            int compressionRatioArrayLowInput[_AGC_CR_NUM];
            int compressionRatioArrayLowOutput[_AGC_CR_NUM];
            int compressionRatioArrayMidInput[_AGC_CR_NUM];
            int compressionRatioArrayMidOutput[_AGC_CR_NUM];
            int compressionRatioArrayHighInput[_AGC_CR_NUM];
            int compressionRatioArrayHighOutput[_AGC_CR_NUM];
        #endif
    
            AudioApcBufferConfig apc_switch;
            memset(&apc_switch,0,sizeof(AudioApcBufferConfig));
        #if USE_JSON
            unsigned int use_apc_param_json = 1;
            char apc_para_json_file[512];
            sprintf(apc_para_json_file,"%s","./../sample/data/ApcParamJson.json");
            int apc_para_buffersize = IaaApc_GetJsonFileSize(apc_para_json_file);
            if(apc_para_buffersize == 0){
                printf("IaaApc_GetJsonFileSize() error. Can not load json file [%s]\t\n", apc_para_json_file);
                use_apc_param_json = 0;
            }
            else{
                printf("IaaApc_GetJsonFileSize() succeed.\t\n");
            }
        #if USE_MALLOC
            char *apc_para_json_buf_ptr = (char*)malloc(apc_para_buffersize);
        #else
            char apc_para_json_buf_ptr[512*1000];
        #endif
            if(use_apc_param_json){
                if(IaaApc_SwitchReadFromJson(&apc_switch, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                    printf("IaaApc_SwitchReadFromJson() error.\t\n");
                    return -1;
                }
                else{
                    printf("IaaApc_SwitchReadFromJson() succeed.\t\n");
                }
            }
        #endif
    
            int buffersize = IaaApc_GetBufferSize(&apc_switch);
            if(buffersize == 0){
                printf("IaaApc_GetBufferSize() error.\t\n");
                return -1;
            }
            else{
                printf("IaaApc_GetBufferSize() succeed.\t\n");
            }
        #if USE_MALLOC
            char *working_buf_ptr = (char*)malloc(buffersize);
        #else
            char working_buf_ptr[512*1000];
        #endif
    
        #if USE_JSON
            unsigned int use_anr_intl_json = 1;
            char anr_intl_json_file[512];
            sprintf(anr_intl_json_file,"%s","./../sample/data/AnrInternalJson.json");
            int anr_intl_buffersize = IaaApc_GetJsonFileSize(anr_intl_json_file);
            if(anr_intl_buffersize == 0){
                printf("IaaApc_GetJsonFileSize() error. Can not load json file [%s]\t\n", anr_intl_json_file);
                use_anr_intl_json = 0;
            }
            else{
                printf("IaaApc_GetJsonFileSize() succeed.\t\n");
            }
        #if USE_MALLOC
            char *anr_intl_json_buf_ptr = (char*)malloc(anr_intl_buffersize);
        #else
            char anr_intl_json_buf_ptr[512*1000];
        #endif
        #endif
    
        #if USE_JSON
            unsigned int use_apc_intl_json = 1;
            char apc_intl_json_file[512];
            sprintf(apc_intl_json_file,"%s","./../sample/data/ApcInternalJson.json");
            int apc_intl_buffersize = IaaApc_GetJsonFileSize(apc_intl_json_file);
            if(apc_intl_buffersize == 0){
                printf("IaaApc_GetJsonFileSize() error. Can not load json file [%s]\t\n", apc_intl_json_file);
                use_apc_intl_json = 0;
            }
            else{
                printf("IaaApc_GetJsonFileSize() succeed.\t\n");
            }
        #if USE_MALLOC
            char *apc_intl_json_buf_ptr = (char*)malloc(apc_intl_buffersize);
        #else
            char apc_intl_json_buf_ptr[512*1000];
        #endif
        #endif
    
            FILE * fin, * fout;
            int ret1;
            AudioProcessInit apc_init;
            AudioAnrConfig anr_config;
            AudioEqConfig eq_config;
            AudioHpfConfig hpf_config;
            AudioAgcConfig agc_config;
            AudioApcOption apc_option;
            memset(&apc_init,0,sizeof(AudioProcessInit));
            memset(&anr_config,0,sizeof(AudioAnrConfig));
            memset(&eq_config,0,sizeof(AudioEqConfig));
            memset(&hpf_config,0,sizeof(AudioHpfConfig));
            memset(&agc_config,0,sizeof(AudioAgcConfig));
            memset(&apc_option,0,sizeof(AudioApcOption));
            APC_HANDLE handle;
    
        #if USE_JSON
            if(use_apc_param_json){
                if(IaaApc_InitReadFromJson(&apc_init, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                    printf("IaaApc_InitReadFromJson() error.\t\n");
                    return -1;
                }
                else{
                    printf("IaaApc_InitReadFromJson() succeed.\t\n");
                }
            }
        #endif
            handle = IaaApc_Init((char *)working_buf_ptr, &apc_init, &apc_switch);
            if(handle==NULL){
                printf("IaaApc_Init() error.\t\n");
                return -1;
            }
            else{
                printf("IaaApc_Init() succeed.\t\n");
            }
    
        #if USE_JSON
            if(use_apc_param_json){
                if(IaaApc_ConfigReadFromJson(&anr_config, &eq_config, &hpf_config, &agc_config, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                    printf("IaaApc_ConfigReadFromJson() error.\t\n");
                    return -1;
                }
                else{
                    printf("IaaApc_ConfigReadFromJson() succeed.\t\n");
                }
            }
        #endif
            if(IaaApc_Config(handle,&anr_config,&eq_config,&hpf_config,NULL,NULL,&agc_config) != -0){
                printf("IaaApc_Config() error.\t\n");
                return -1;
            }
            else{
                printf("IaaApc_Config() succeed.\t\n");
            }
    
        #if USE_JSON
            if(apc_switch.anr_enable && use_anr_intl_json){
                if(IaaApc_NrReadJson(handle, anr_intl_json_buf_ptr, anr_intl_json_file, anr_intl_buffersize) != 0){
                    printf("IaaApc_NrReadJson() error.\t\n");
                    return -1;
                }
                else{
                    printf("IaaApc_NrReadJson() succeed.\t\n");
                }
            }
        #endif
    
        #if USE_JSON
            if(use_apc_intl_json){
                if(IaaApc_ReadJson(handle, apc_intl_json_buf_ptr, apc_intl_json_file, apc_intl_buffersize) != 0){
                    printf("IaaApc_ReadJson() error.\t\n");
                    return -1;
                }
                else{
                    printf("IaaApc_ReadJson() succeed.\t\n");
                }
            }
        #endif
    
        #if FILTER_ENABLE
            float h[512];
        #if USE_JSON
            if(use_apc_param_json){
                if(IaaApc_FilterDesignReadFromJson(handle, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                    printf("IaaEq_FilterDesignReadFromJson() error.\t\n");
                    return -1;
                }
                else{
                    printf("IaaEq_FilterDesignReadFromJson() succeed.\t\n");
                }
            }
        #endif
            IaaApc_FilterFreqz(handle,h);
        #endif
    
    
        #if FREQ_AGC_ENABEL
            if(agc_config.user_mode == 2){
        #if USE_JSON
                if(use_apc_param_json){
                    if(IaaApc_SetAgcReadFromJson(&freqBand[0], &compressionRatioArrayLowInput[0], &compressionRatioArrayLowOutput[0],
                                &compressionRatioArrayMidInput[0], &compressionRatioArrayMidOutput[0],
                                &compressionRatioArrayHighInput[0], &compressionRatioArrayHighOutput[0],
                                apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0 ){
                        printf("IaaAgc_SetAgcReadFromJson() error.\t\n");
                        return -1;
                    }
                    else{
                        printf("IaaAgc_SetAgcReadFromJson() succeed.\t\n");
                    }
                }
        #endif
                IaaApc_SetAgcFreqBand(handle, freqBand);
                IaaApc_SetLowFreqCompressionRatioCurve(handle, compressionRatioArrayLowInput, compressionRatioArrayLowOutput);
                IaaApc_SetMidFreqCompressionRatioCurve(handle, compressionRatioArrayMidInput, compressionRatioArrayMidOutput);
                IaaApc_SetHighFreqCompressionRatioCurve(handle, compressionRatioArrayHighInput, compressionRatioArrayHighOutput);
            }
        #endif
    
        #if DIGITAL_GAIN_ENABLE
        #if USE_JSON
            if(use_apc_param_json){
                if(IaaApc_OptionReadFromJson(&apc_option, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                    printf("IaaApc_OptionReadFromJson() error.\t\n");
                    return -1;
                }
                else{
                    printf("IaaApc_OptionReadFromJson() succeed.\t\n");
                }
            }
        #endif
        #endif
    
            sprintf(input_file,"%s","./../sample/data/APC_AFE_16K.wav");
            sprintf(output_file,"%s","./../sample/data/APC_out_16K.wav");
    
            fin = fopen(input_file, "rb");
            if(!fin)
            {
                printf("the input file %s could not be open\n",input_file);
                return -1;
            }
    
            fout = fopen(output_file, "wb");
            if(!fout)
            {
                printf("the output file could not be open\n");
                return -1;
            }
    
            fread(input, sizeof(char), 44, fin); // read header 44 bytes
            fwrite(input, sizeof(char),44, fout); // write 44 bytes output
    
            while(fread(input, sizeof(short), apc_init.point_number*apc_init.channel, fin))
            {
    
                counter++;
                T0  = (long)_OsCounterGetMs();
        #if DIGITAL_GAIN_ENABLE
                ret1 = IaaApc_ApplyDigitalGain(handle,input,apc_option.digital_gain[0]);
        #endif
                ret1 = IaaApc_Run(handle,input);
        #if FILTER_ENABLE
                ret1 += IaaApc_FilterApply(handle, input);
        #endif
    
        #if DIGITAL_GAIN_ENABLE
                ret1 += IaaApc_ApplyDigitalGain(handle,input,apc_option.digital_gain[1]);
        #endif
    
                T1  = (long)_OsCounterGetMs();
                avg += (T1 - T0);
                if(peak < (T1 - T0))
                    peak = (T1 - T0);
    
                if(counter%1000== 999)
                {
                    printf("counter = %d\n", counter);
                    printf("current time = %f\n", (float)counter*apc_init.point_number/apc_init.sample_rate);
                    printf("process time = %lu(ms)\t",(long)(T1 - T0));
                }
    
                if(ret1 != 0)
                {
                    printf("Error occured in APC\n");
                    break;
                }
    
                fwrite(input, sizeof(short), apc_init.point_number*apc_init.channel, fout);
            }
            avg /= counter;
            printf("AVG is %.2f ms\n",avg);
            printf("PEAK is %.2f ms\n",peak);
            IaaApc_Free(handle);
            free(working_buf_ptr);
            fclose(fin);
            fclose(fout);
        #if (ANR_IPU_ENABLE)
            MI_SYS_Exit(0);
        #endif
            printf("Done\n");
        return 0;
        }
    

    2. API REFERENCE


    2.1. API List

    API name Features
    IaaApc_GetBufferSize Get the memory size required for Apc algorithm running
    IaaApc_Init Initialize the Apc algorithm
    IaaApc_Config Configure the Apc algorithm
    IaaApc_SetLowFreqCompressionRatioCurve Set Agc in Apc compression ratio by bin(low frequency)
    IaaApc_SetMidFreqCompressionRatioCurve Set Agc in Apc compression ratio by bin(Mid frequency)
    IaaApc_SetHighFreqCompressionRatioCurve Set Agc in Apc compression ratio by bin(High frequency)
    IaaApc_SetAgcFreqBand Set Agc in Apc frequency band
    IaaApc_GetNrResult Get Anr output
    IaaApc_GetNrEqResult Get Anr and Eq output
    IaaApc_GetVadOut Get the speech probability of Anr in the Apc algorithm
    IaaApc_Run Apc algorithm run
    IaaApc_Free Release Apc algorithm resources
    IaaApc_Reset Reinitialize the Apc algorithm
    IaaApc_GetConfig Get the Apc algorithm current configuration parameters
    IaaApc_ApplyDigitalGain Apply digital gain on input data
    IaaAnr_GetBufferSize Get the memory size required for Anr algorithm running
    IaaAnr_Init Initialize the Anr algorithm
    IaaAnr_Config Configure the Anr algorithm
    IaaAnr_Run Anr algorithm processing
    IaaAnr_Free Release Anr algorithm resources
    IaaAnr_Reset Reinitialize the Anr algorithm
    IaaAnr_GetConfig Get the Anr algorithm current configuration parameters
    IaaEq_GetBufferSize Get the memory size required for Eq algorithm running
    IaaEq_Init Initialize the Eq algorithm
    IaaEq_Config Configure the Eq algorithm
    IaaEq_Run Eq algorithm processing
    IaaEq_Free Release Eq algorithm resources
    IaaEq_Reset Reinitialize the Eq algorithm
    IaaEq_GetConfig Get the Eq algorithm current configuration parameters
    IaaAgc_GetBufferSize Get the memory size required for Agc algorithm running
    IaaAgc_Init Initialize the Agc algorithm
    IaaAgc_Config Configure the Agc algorithm
    IaaAgc_SetLowFreqCompressionRatioCurve Set Agc compression ratio by bin(low frequency)
    IaaAgc_SetMidFreqCompressionRatioCurve Set Agc compression ratio by bin(Mid frequency)
    IaaAgc_SetHighFreqCompressionRatioCurve Set Agc compression ratio by bin(High frequency)
    IaaAgc_SetAgcFreqBand Set Agc frequency band
    IaaAgc_Run Agc algorithm processing
    IaaAgc_Free Release Agc algorithm resources
    IaaAgc_Reset Reinitialize the Eq algorithm
    IaaAgc_GetConfig Get the Agc algorithm current configuration parameters
    IaaApc_SetCompressionRatioCurve Set Agc in Apc compression ratio curve for more slope segment
    IaaAgc_SetCompressionRatioCurve Set Agc compression ratio curve for more slope segment
    IaaApc_NrEstimateReferAec Noise estimation refer to Aec linear process output
    IaaApc_EnhanceNNBFMode Special enhancement for concatenating Bf mode 3 and Apc deep learning based noise reduction
    IaaApc_FilterDesign Initialized IIR filter configuration
    IaaApc_FilterApply IIR filter apply
    IaaEq_FilterDesign Initialized IIR filter configuration
    IaaEq_FilterApply IIR filter apply
    IaaAnr_EnhanceNNBFMode Special enhancement for concatenating Bf mode 3 and Anr deep learning based noise reduction
    IaaApc_GetAPIVersion Get Apc API version
    IaaApc_SetHandleId Set Apc Handle Id
    IaaAnr_SetHandleId Set Anr Handle Id
    IaaEq_SetHandleId Set Eq Handle Id
    IaaAgc_SetHandleId Set Agc Handle Id
    IaaApc_GetJsonFileSize Apc get size of json file
    IaaApc_NrReadJson Set json parameter into Apc Handle
    IaaAnr_GetJsonFileSize Anr get size of json file
    IaaAnr_NrReadJson Set json parameter into Anr Handle
    IaaApc_EnableComfortNoise Enable comfort noise algorithm and set power of comfort noise into Apc Handle
    IaaAnr_EnableComfortNoise Enable comfort noise algorithm and set power of comfort noise into Anr Handle
    IaaEq_EnableComfortNoise Enable comfort noise algorithm and set power of comfort noise into Eq Handle
    IaaAgc_EnableComfortNoise Enable comfort noise algorithm and set power of comfort noise into Agc Handle
    IaaApc_EnableAutoSmooth Enable automatic smooth algorithm into Apc handle
    IaaAnr_EnableAutoSmooth Enable automatic smooth algorithm into Anr handle
    IaaApc_ApplyComfortNoise Specified power comfort noise mixture
    IaaApc_SwitchReadFromJson Configure Json parameters to enable setting structure handle of Apc algorithm
    IaaApc_InitReadFromJson Configure Json parameters to initialize structure handle of the Apc algorithm
    IaaApc_ConfigReadFromJson Configure Json parameters to the structure handle of the Apc algorithm
    IaaApc_SetAgcReadFromJson Configure Json parameters to Agc band array
    IaaApc_FilterDesignReadFromJson Configure Json parameters to the Eq filter structure handle of the Apc algorithm
    IaaAnr_InitReadFromJson Configure Json parameters to the initialize structure handle of the Anr algorithm
    IaaAnr_ConfigReadFromJson Configure Json parameters to the structure handle of the Anr algorithm
    IaaEq_GetJsonFileSize Get the memory size to parse the content of the Json file required by Eq
    IaaEq_InitReadFromJson Configure Json parameters to initialize structure handle of the Eq algorithm
    IaaEq_ConfigReadFromJson Configure Json parameters to the structure handle of the Eq algorithm
    IaaEq_FilterDesignReadFromJson Configure Json parameters to the filter structure handle of the Eq algorithm
    IaaAgc_GetJsonFileSize Get the memory size to parse the content of the Json file required by Agc
    IaaAgc_InitReadFromJson Configure Json parameters to initialize structure handle of the Agc algorithm
    IaaAgc_ConfigReadFromJson Configure Json parameters to the structure handle of the Agc algorithm
    IaaAgc_SetAgcReadFromJson Configure Json parameters to Agc band array
    IaaAnr_NrEstimateReferAec Refer to the Aec linear processing results for noise reduction processing to avoid Anr convergence anomalies caused by nonlinear Aec
    IaaApc_FilterFreqz Get the result of superimposing the frequency response of several filters after configuring IaaApc_FilterDesign
    IaaEq_FilterFreqz Get the result of superimposing the frequency response of several filters after configuring IaaEq_FilterDesign
    IaaApc_OptionReadFromJson Configure Json parameters to optional structure
    IaaApc_ReadJson Configure Json parameters to Apc common setting
    IaaEq_ReadJson Configure Json parameters to Eq common setting
    IaaAgc_ReadJson Configure Json parameters to Agc common setting

    2.2. IaaApc_GetBufferSize

    • Features

      Get the memory size required for Apc algorithm running.

    • Syntax

      unsigned int IaaApc_GetBufferSize(AudioApcBufferConfig *apc_switch);
      
    • Parameters

      Parameter name Description Input/Output
      apc_switch Structure pointer for configure the Apc algorithm to enable Input
    • Return value

      Return value is the memory size required for Apc algorithm running.

    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      This interface only returns the memory size required to handle applications that request and release memory.

    • Example

      Please refer to IaaApc_Run example.


    2.3. IaaApc_Init

    • Features

      Initialize the Apc algorithm .

    • Syntax

      APC_HANDLE IaaApc_Init(char* const working_buffer_address,AudioProcessInit *audio_process_init, AudioApcBufferConfig *apc_switch);
      
    • Parameters

      Parameter name Description Input/Output
      working_buffer_address Apc algorithm memory address Input
      audio_process_init Apc algorithm initialization structure pointer Input
      apc_switch Apc algorithm enable structure pointer Input
    • Return value

      Return value Result
      Not NULL Successful
      NULL Failed
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • In the Apc algorithm, Anr/Agc/Eq/Hpf supports 8K/16K/32K/48K sampling rate.
    • Example

      Please refer to IaaApc_Run example.


    2.4. IaaApc_Config

    • Features

      Configure the Apc algorithm.

    • Syntax

      ALGO_APC_RET IaaApc_Config(APC_HANDLE handle,
                          AudioAnrConfig *anr_config,
                          AudioEqConfig *eq_config,
                          AudioHpfConfig *hpf_config,
                          AudioVadConfig *vad_config,
                          AudioDereverbConfig *dereverb_config,
                          AudioAgcConfig *agc_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      anr_config Configure Anr algorithm structure pointer Input
      eq_config Configure Eq algorithm structure pointer Input
      hpf_config Configure Hpf algorithm structure pointer Input
      vad_config Configure Vad algorithm structure pointer(stop using) Input
      dereverb_config Configure Dereverb algorithm structure pointer (stop using) Input
      agc_config Configure Agc algorithm structure pointer Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaApc_Run example.


    2.5. IaaApc_SetLowFreqCompressionRatioCurve

    • Features

      Set Agc in Apc compression ratio by bin (low frequency).

      Please set agc user_mode 2 to enable frequency domain Agc before calling this function.

    • Syntax

      ALGO_APC_RET IaaApc_SetLowFreqCompressionRatioCurve(APC_HANDLE handle,
                          int* CompressRatioInput, int* CompressRatioOutput);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      CompressRatioInput Compression ratio curve input array, please refer to compression ratio of agc_config Input
      CompressRatioOutput Compression ratio curve output array, please refer to compression ratio of agc_config Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaApc_Run example.


    2.6. IaaApc_SetMidFreqCompressionRatioCurve

    • Features

      Set Agc in Apc compression ratio by bin (Mid frequency).

      Please set agc user_mode 2 to enable frequency domain Agc before calling this function.

    • Syntax

      ALGO_APC_RET IaaApc_SetMidFreqCompressionRatioCurve(APC_HANDLE handle,
                          int* CompressRatioInput, int* CompressRatioOutput);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      CompressRatioInput Compression ratio curve input array, please refer to compression ratio of agc_config Input
      CompressRatioOutput Compression ratio curve output array, please refer to compression ratio of agc_config Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaApc_Run example.


    2.7. IaaApc_SetHighFreqCompressionRatioCurve

    • Features

      Set Agc in Apc compression ratio by bin (High frequency).

      Please set agc user_mode 2 to enable frequency domain Agc before calling this function.

    • Syntax

      ALGO_APC_RET IaaApc_SetHighFreqCompressionRatioCurve(APC_HANDLE handle,
                          int* CompressRatioInput, int* CompressRatioOutput);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      CompressRatioInput Compression ratio curve input array, please refer to compression ratio of agc_config Input
      CompressRatioOutput Compression ratio curve output array, please refer to compression ratio of agc_config Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaApc_Run example.


    2.8. IaaApc_SetAgcFreqBand

    • Features

      Set Agc in Apc frequency band.

      Please set agc user_mode 2 to enable frequency domain Agc before calling this function.

    • Syntax

      ALGO_APC_RET IaaApc_ SetAgcFreqBand(APC_HANDLE handle,
                              int* frequency_band);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      Frequency_band Frequency band setting array. It involve low frequency upper limit, middle frequency upper limit and high frequency upper limit.
      For example: When the sampling rate is 16K, setting frequency band as {3000,4000,8000}
      Then the low frequency band is range from 0 to 3000Hz, middle frequency band is range from 3000 to 4000Hz, high frequency band is range from 4000 to 8000Hz. Please double check that the highest frequency can't exceed the half of sampling rate.
      Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaApc_Run example.


    2.9. IaaApc_GetNrResult

    • Features

      Get the Apc algorithm Anr processing result.

    • Syntax

      ALGO_APC_RET IaaApc_GetNrResult(APC_HANDLE handle, short*
      nr_audio_out);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      nr_audio_out Anr handles Output data pointer Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • Anr in the Apc algorithm must be enabled before calling the interface to obtain data.
    • Example

      Please refer to IaaApc_Run example.


    2.10. IaaApc_GetNrEqResult

    • Features

      Get the processing result of Anr and Eq in the Apc algorithm

    • Syntax

      ALGO_APC_RET IaaApc_GetNrEqResult(APC_HANDLE handle,short*
      nr_eq_audio_out);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      nr_eq_audio_out Anr and Eq handle output data pointer Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • Enable Anr and Eq in the Apc algorithm before calling this interface to obtain data.
    • Example

      Please refer to IaaApc_Run example.


    2.11. IaaApc_GetVadOut

    • Features

      Get the probability calculated by Anr that the current input signal is speech in the Apc algorithm.

    • Syntax

      ALGO_APC_RET IaaApc_GetVadOut(APC_HANDLE handle, int* speech_probability);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      Speech_prob Anr handle output speech probability pointer Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • Enable Anr in the Apc algorithm before calling this interface to obtain data.

      • speech_probability is the probability that the input signal pss_audio_in (the input signal size is 256 bytes) in calling IaaApc_Run is the speech.

    • Example

      Please refer to IaaApc_Run example.


    2.12. IaaApc_Run

    • Features

      Apc algorithm processing.

    • Syntax

      ALGO_APC_RET IaaApc_Run(APC_HANDLE handle,short* pss_audio_in);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      pss_audio_in Input data pointer Input/Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The data length must correspond to the point_number (sampling points required for one IaaApc_Run) set when calling IaaApc_Init. The processed data will be written back to the memory pointed to by pss_audio_in.
    • Example


    2.13. IaaApc_Free

    • Features

      Release Apc algorithm resources

    • Syntax

      ALGO_APC_RET IaaApc_Free(APC_HANDLE handle);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      Please refer to IaaApc_Run example.


    2.14. IaaApc_Reset

    • Features

      Reinitialize the Apc algorithm.

    • Syntax

      APC_HANDLE IaaApc_Reset(char* working_buffer_address,AudioProcessInit *audio_process_init, AudioApcBufferConfig *apc_switch);
      
    • Parameters

      Parameter name Description Input/Output
      working_buffer_address Memory address used by Apc algorithm Input
      audio_process_init Apc algorithm initialization structure pointer Input
      apc_switch Structure pointer for configure the Apc algorithm to enable Input
    • Return value

      Return value Result
      Not NULL Successful
      NULL Failed
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      When the Apc algorithm is reinitialized and the function options are different from previous, we need to release the memory used by the original algorithm, call IaaApc_GetBufferSize again to get the memory size required by the current function options, and reapply for the corresponding size of memory for the Apc algorithm.

    • Example

      None.


    2.15. IaaApc_GetConfig

    • Features

      Get the Apc algorithm current configuration parameters.

    • Syntax

      ALGO_APC_RET IaaApc_GetConfig(APC_HANDLE handle,
                          AudioProcessInit *audio_process_init,
                          AudioAnrConfig *anr_config,
                          AudioEqConfig *eq_config,
                          AudioHpfConfig *hpf_config,
                          AudioVadConfig *vad_config,
                          AudioDereverbConfig *dereverb_config,
                          AudioAgcConfig *agc_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      audio_process_init Apc algorithm initialization structure pointer Output
      anr_config The current Anr configuration parameters in the Apc algorithm Output
      eq_config The current Eq configuration parameters in the Apc algorithm Output
      hpf_config The current Hpf configuration parameters in the Apc algorithm Output
      vad_config The current Vad configuration parameters in the Apc algorithm(stop using) Output
      dereverb_config The current Dereverb configuration parameters in the Apc algorithm(stop using) Output
      agc_config The current Agc configuration parameters in the Apc algorithm Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      Please refer to IaaApc_Run example.


    2.16. IaaApc_ApplyDigitalGain

    • Features

      Apply digital gain on input data.

    • Syntax

      ALGO_APC_RET IaaApc_ApplyDigitalGain(APC_HANDLE handle,
      short* pss_audio_in, float gain_value);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc handle Input
      pss_audio_in Input data pointer Input/Output
      gain_value Gain value
      range: [-120,120]
      input
    • Return value

      Return value Result
      Not NULL Successful
      NULL Failed
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.17. IaaAnr_GetBufferSize

    • Features

      Get the memory size required for Anr algorithm running.

    • Syntax

      unsigned int IaaAnr_GetBufferSize(void);
      
    • Return value

      Return value is the memory size required for Anr algorithm running.

    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      This interface only returns the memory size required to handle applications that request and release memory.

    • Example

      Please refer to IaaAnr_Run example.


    2.18. IaaAnr_Init

    • Features

      Initialize the Anr algorithm.

    • Syntax

      ANR_HANDLE IaaAnr_Init(char* working_buffer_address, AudioProcessInit *anr_init);
      
    • Parameters

      Parameter name Description Input/Output
      working_buffer_address Anr algorithm memory address Input
      anr_init Anr algorithm initialization structure pointer Input
    • Return value

      Return value Result
      Not NULL Successful
      NULL Failed
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • Anr algorithm supports 8K/16K/32K/48K sampling rate.
    • Example

      Please refer to IaaAnr_Run example.


    2.19. IaaAnr_Config

    • Features

      Configure the Anr algorithm.

    • Syntax

      ALGO_ANR_RET IaaAnr_Config(ANR_HANDLE handle, AudioAnrConfig *anr_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
      anr_config Configure Anr algorithm structure pointer Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaAnr_Run example.


    2.20. IaaAnr_Run

    • Features

      Anr algorithm processing.

    • Syntax

      ALGO_ANR_RET IaaAnr_Run(ANR_HANDLE handle, short* pss_audio_in);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
      pss_audio_in Input data pointer Input/Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The data length must correspond to the point_number (sampling points required for one IaaAnr_Run) set when calling IaaAnr_Init. The processed data will be written back to the memory pointed to by pss_audio_in.
    • Example

      #include <stdio.h>
      #include <string.h>
      #include <stdlib.h>
      #include <sys/time.h>
      
      #include "AudioProcess.h"
      
      /*  0:Fixed input file  1:User input file   */
      #define IN_PARAMETER 1
      
      int main(int argc, char *argv[])
      {
          short in_output[1024];
          unsigned int workingBufferSize;
          char *workingBuffer = NULL;
          ANR_HANDLE handle;
          AudioProcessInit anr_init, anr_get_init;
          AudioAnrConfig anr_config, anr_get_config;
          ALGO_APC_RET ret;
          int tempSize;
          FILE* fpIn;  //input file
          FILE* fpOut; //output file
          char src_file[128] = {0};
          char dst_file[128] = {0};
          /*********************User change section start*******************/
          int intensity_band[6] = {3,24,40,64,80,128};
          int intensity[7] = {30,30,30,30,30,30,30};
          anr_init.point_number = 128;
          anr_init.channel = 1;
          anr_init.sample_rate = IAA_APC_SAMPLE_RATE_16000;
      
          anr_config.anr_enable = 1;
          anr_config.user_mode = 2;
          anr_config.anr_filter_mode = 4;
          anr_config.anr_smooth_level = 10;
          anr_config.anr_converge_speed = 2;
          /*********************User change section end*******************/
          memcpy(anr_config.anr_intensity_band, intensity_band, sizeof(intensity_band));
          memcpy(anr_config.anr_intensity, intensity, sizeof(intensity));
          //(1)IaaAnr_GetBufferSize
          workingBufferSize = IaaAnr_GetBufferSize();
          workingBuffer = (char *)malloc(workingBufferSize);
          if(NULL == workingBuffer)
          {
              printf("malloc workingBuffer failed !\n");
              return -1;
          }
          printf("malloc workingBuffer succeed !\n");
          //(2)IaaAnr_Init
          handle = IaaAnr_Init(workingBuffer, &anr_init);
          if(NULL == handle)
          {
              printf("IaaAnr_Init failed !\n");
              return -1;
          }
          printf("IaaAnr_Init succeed !\n");
          //(3)IaaAnr_Config
          ret = IaaAnr_Config(handle, &anr_config);
          if(ret)
          {
              printf("IaaAnr_Config failed !\n");
              return -1;
          }
          printf("IaaAnr_Config succeed !\n");
          //(4)IaaAnr_GetConfig
          ret = IaaAnr_GetConfig(handle, &anr_get_init, &anr_get_config);
          if(ret)
          {
              printf("IaaAnr_GetConfig failed !\n");
              return -1;
          }
          printf("IaaAnr_GetConfig succeed !\n");
          printf("anr_get_config.user_mode = %d, ...\n", anr_get_config.user_mode);
      
      #if IN_PARAMETER
          if(argc < 3)
          {
              printf("Please enter the correct parameters!\n");
              return -1;
          }
          sscanf(argv[1], "%s", src_file);
          sscanf(argv[2], "%s", dst_file);
      #else
          sprintf(src_file, "%s", "./APC_AFE_16K.wav");
          if(argc < 2)
          {
              printf("Please enter the correct parameters!\n");
              return -1;
          }
          sscanf(argv[1], "%s", dst_file);
      #endif
      
          fpIn = fopen(src_file, "rb");
          if(NULL == fpIn)
          {
              printf("fopen in_file failed !\n");
              return -1;
          }
          printf("fopen in_file success !\n");
          fpOut = fopen(dst_file, "wb");
          if(NULL == fpOut)
          {
              printf("fopen out_file failed !\n");
              return -1;
          }
          printf("fopen out_file success !\n");
      #if 1
          fread(in_output, sizeof(char), 44, fpIn);
          fwrite(in_output, sizeof(char), 44, fpOut);
      #endif
          tempSize = anr_init.point_number * anr_init.channel;
          while(tempSize == fread(in_output, sizeof(short), tempSize, fpIn))
          {
              //(5)IaaAnr_Run
              ret = IaaAnr_Run(handle, in_output);
              if(ret)
              {
                  printf("IaaAnr_Run failed !\n");
                  return -1;
              }
              fwrite(in_output, sizeof(short), tempSize, fpOut);
          }
          printf("Break:needBytes =%d \t nBytesRead = %d\n", anr_init.point_number * anr_init.channel, tempSize);
          //(6)IaaAnr_Free
          IaaAnr_Free(handle);
          free(workingBuffer);
          fclose(fpIn);
          fclose(fpOut);
          printf("APC_ANR end !\n");
      
          return 0;
      }
      

    2.21. IaaAnr_Free

    • Features

      Release Anr algorithm resources.

    • Syntax

      ALGO_APC_RET IaaAnr_Free(ANR_HANDLE handle);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaAnr_Run example.


    2.22. IaaAnr_Reset

    • Features

      Reinitialize the Anr algorithm.

    • Syntax

      ANR_HANDLE IaaAnr_Reset(char* working_buffer_address, AudioProcessInit *anr_init);
      
    • Parameters

      Parameter name Description Input/Output
      working_buffer_address Memory address used by Anr algorithm Input
      anr_init Anr algorithm initialization structure pointer Input
    • Return value

      Return value Result
      Not NULL Successful
      NULL Failed
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.23. IaaAnr_GetConfig

    • Features

      Get the Anr algorithm current configuration parameters.

    • Syntax

      ALGO_ANR_RET IaaAnr_GetConfig(ANR_HANDLE handle, AudioProcessInit *anr_init, AudioAnrConfig *anr_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
      anr_init Anr algorithm initialization structure pointer Output
      anr_config Anr algorithm in the current configuration parameters Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaAnr_Run example.


    2.24. IaaEq_GetBufferSize

    • Features

      Get the memory size required for Anr algorithm running.

    • Syntax

      unsigned int IaaEq_GetBufferSize(void);
      
    • Parameters

      Parameter name Description Input/Output
    • Return value

      Return value is the memory size required for Eq algorithm running.

    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      This interface only returns the memory size required to handle applications that request and release memory.

    • Example

      Please refer to IaaEq_Run example.


    2.25. IaaEq_Init

    • Features

      Initialize the Eq algorithm.

    • Syntax

      EQ_HANDLE IaaEq_Init(char* working_buffer_address, AudioProcessInit *eq_init);
      
    • Parameters

      Parameter name Description Input/Output
      working_buffer_address Eq algorithm memory address Input
      eq_init Eq algorithm initialization structure pointer Input
    • Return value

      Return value Result
      Not NULL Successful
      NULL Failed
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • Eq/Hpf algorithm supports 8K/16K/32K/48K sampling Rate.
    • Example

      Please refer to IaaEq_Run example.


    2.26. IaaEq_Config

    • Features

      Configure the Eq algorithm.

    • Syntax

      ALGO_EQ_RET IaaEq_Config(EQ_HANDLE handle, AudioHpfConfig *hpf_config, AudioEqConfig *eq_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input
      hpf_config Configure Hpf algorithm structure pointer Input
      eq_config Configure Eq algorithm structure pointer Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      Please refer to IaaEq_Run example.


    2.27. IaaEq_Run

    • Features

      Eq algorithm processing.

    • Syntax

      ALGO_EQ_RET IaaEq_Run(EQ_HANDLE handle, short* pss_audio_in);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input
      pss_audio_in Input data pointer Input/Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The data length must correspond to the point_number (sampling points required for one IaaEq_Run set when calling IaaEq_Init. The processed data will be written back to the memory pointed to by pss_audio_in.
    • Example

      #include <stdio.h>
      #include <string.h>
      #include <stdlib.h>
      #include <sys/time.h>
      
      #include "AudioProcess.h"
      
      /*  0:Fixed input file  1:User input file   */
      #define IN_PARAMETER 1
      
      int main(int argc, char *argv[])
      {
          short in_output[1024];
          unsigned int workingBufferSize;
          char *workingBuffer = NULL;
          EQ_HANDLE handle;
          AudioProcessInit eq_init, eq_get_init;
          AudioHpfConfig hpf_config, hpf_get_config;
          AudioEqConfig  eq_config, eq_get_config;
          ALGO_APC_RET ret;
          int tempSize;
      
          FILE* fpIn;  //input file
          FILE* fpOut; //output file
          char src_file[128] = {0};
          char dst_file[128] = {0};
          /*********************User change section start*******************/
          short eq_table[129];
          memset(eq_table, 0, sizeof(eq_table));
          eq_init.point_number = 128;
          eq_init.channel = 1;
          eq_init.sample_rate = IAA_APC_SAMPLE_RATE_16000;
      
          hpf_config.hpf_enable = 1;
          hpf_config.user_mode = 1;
          hpf_config.cutoff_frequency = AUDIO_HPF_FREQ_150;
      
          eq_config.eq_enable = 1;
          eq_config.user_mode = 1;
          /*********************User change section end*******************/
          memcpy(eq_config.eq_gain_db, eq_table, sizeof(eq_table));
          //(1)IaaEq_GetBufferSize
          workingBufferSize = IaaEq_GetBufferSize();
          workingBuffer = (char *)malloc(workingBufferSize);
          if(NULL == workingBuffer)
          {
              printf("malloc workingBuffer failed !\n");
              return -1;
          }
          printf("malloc workingBuffer succeed !\n");
          //(2)IaaEq_Init
          handle = IaaEq_Init(workingBuffer, &eq_init);
          if(NULL == handle)
          {
              printf("IaaEq_Init failed !\n");
              return -1;
          }
          printf("IaaEq_Init succeed !\n");
          //(3)IaaEq_Config
          ret = IaaEq_Config(handle, &hpf_config, &eq_config);
          if(ret)
          {
              printf("IaaEq_Config failed !\n");
              return -1;
          }
          printf("IaaEq_Config succeed !\n");
          //(4)IaaEq_GetConfig
          ret = IaaEq_GetConfig(handle, &eq_get_init, &hpf_get_config, &eq_get_config);
          if(ret)
          {
              printf("IaaEq_GetConfig failed !\n");
              return -1;
          }
          printf("IaaEq_GetConfig succeed !\n");
          printf("eq_get_config.user_mode = %d, ...\n", eq_get_config.user_mode);
      
      #if IN_PARAMETER
          if(argc < 3)
          {
              printf("Please enter the correct parameters!\n");
              return -1;
          }
          sscanf(argv[1], "%s", src_file);
          sscanf(argv[2], "%s", dst_file);
      #else
          sprintf(src_file, "%s", "./APC_AFE_16K.wav");
          if(argc < 2)
          {
              printf("Please enter the correct parameters!\n");
              return -1;
          }
          sscanf(argv[1], "%s", dst_file);
      #endif
      
          fpIn = fopen(src_file, "rb");
          if(NULL == fpIn)
          {
              printf("fopen in_file failed !\n");
              return -1;
          }
          printf("fopen in_file success !\n");
          fpOut = fopen(dst_file, "wb");
          if(NULL == fpOut)
          {
              printf("fopen out_file failed !\n");
              return -1;
          }
          printf("fopen out_file success !\n");
      #if 1
          fread(in_output, sizeof(char), 44, fpIn);
          fwrite(in_output, sizeof(char), 44, fpOut);
      #endif
          tempSize = eq_init.point_number * eq_init.channel;
          while(tempSize == fread(in_output, sizeof(short), tempSize, fpIn))
          {
              //(5)IaaEq_Run
              ret = IaaEq_Run(handle, in_output);
              if(ret)
              {
                  printf("IaaEq_Run failed !\n");
                  return -1;
              }
              fwrite(in_output, sizeof(short), tempSize, fpOut);
          }
          printf("Break:needBytes =%d \t nBytesRead = %d\n", eq_init.point_number * eq_init.channel, tempSize);
          //(6)IaaEq_Free
          IaaEq_Free(handle);
          free(workingBuffer);
          fclose(fpIn);
          fclose(fpOut);
          printf("APC_EQ end !\n");
      
          return 0;
      }
      

    2.28. IaaEq_Free

    • Features

      Release Eq algorithm resources.

    • Syntax

      ALGO_EQ_RET IaaEq_Free(EQ_HANDLE handle);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      Please refer to IaaEq_Run example.


    2.29. IaaEq_Reset

    • Features

      Reinitialize the Eq algorithm.

    • Syntax

      EQ_HANDLE IaaEq_Reset(char* working_buffer_address, AudioProcessInit *eq_init);
      
    • Parameters

      Parameter name Description Input/Output
      working_buffer_address Memory address used by Eq algorithm Input
      eq_init Eq algorithm initialization structure pointer Input
    • Return value

      Return value Result
      Not NULL Successful
      NULL Failed
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      None.


    2.30. IaaEq_GetConfig

    • Features

      Get the Eq algorithm current configuration parameters.

    • Syntax

      ALGO_EQ_RET IaaEq_GetConfig(EQ_HANDLE handle,
      AudioProcessInit *eq_init,
      AudioHpfConfig *hpf_config,
      AudioEqConfig *eq_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input
      eq_init Eq algorithm initialization structure pointer Output
      hpf_config Hpf algorithm in the current configuration parameters Output
      eq_config Eq algorithm in the current configuration parameters Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      Please refer to IaaEq_Run example


    2.31. IaaAgc_GetBufferSize

    • Features

      Get the memory size required for Agc algorithm running.

    • Syntax

      unsigned int IaaAgc_GetBufferSize(void);
      
    • Parameters

      Parameter name Description Input/Output
    • Return value

      Return value is the memory size required for Agc algorithm running.

    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      This interface only returns the memory size required to handle applications that request and release memory.

    • Example

      Please refer to IaaAgc_Run example.


    2.32. IaaAgc_Init

    • Features

      Initialize the Agc algorithm.

    • Syntax

      AGC_HANDLE IaaAgc_Init(char* working_buffer_address, AudioProcessInit *agc_init);
      
    • Parameters

      Parameter name Description Input/Output
      working_buffer_address Agc algorithm memory address Input
      agc_init Agc algorithm initialization structure pointer Input
    • Return value

      Return value Result
      Not NULL Successful
      NULL Failed
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • Agc algorithm supports 8K/16K/32K/48K sampling rate.
    • Example

      Please refer to IaaAgc_Run example.


    2.33. IaaAgc_Config

    • Features

      Configure the Agc algorithm.

    • Syntax

      ALGO_AGC_RET IaaAgc_Config(AGC_HANDLE handle, AudioAgcConfig *agc_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      agc_config Configure Agc algorithm structure pointer Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      Please refer to IaaAgc_Run example.


    2.34. IaaAgc_SetLowFreqCompressionRatioCurve

    • Features

      Set Agc compression ratio by bin (low frequency).

      Please set agc user_mode 2 to enable frequency domain Agc before calling this function.

    • Syntax

      ALGO_AGC_RET IaaAgc_SetLowFreqCompressionRatioCurve(AGC_HANDLE handle,
                          int* CompressRatioInput, int* CompressRatioOutput);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      CompressRatioInput Compression ratio curve input array, please refer to compression ratio of agc_config Input
      CompressRatioOutput Compression ratio curve output array, please refer to compression ratio of agc_config Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaAgc_Run example.


    2.35. IaaAgc_SetMidFreqCompressionRatioCurve

    • Features

      Set Agc compression ratio by bin (Mid frequency). Please set agc user_mode 2 to enable frequency domain Agc before calling this function.

    • Syntax

      ALGO_AGC_RET IaaAgc_SetMidFreqCompressionRatioCurve(AGC_HANDLE handle,
                          int* CompressRatioInput, int* CompressRatioOutput);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      CompressRatioInput Compression ratio curve input array, please refer to compression ratio of agc_config Input
      CompressRatioOutput Compression ratio curve output array, please refer to compression ratio of agc_config Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaAgc_Run example.


    2.36. IaaAgc_SetHighFreqCompressionRatioCurve

    • Features

      Set Agc compression ratio by bin (High frequency).

      Please set agc user_mode 2 to enable frequency domain Agc before calling this function.

    • Syntax

      ALGO_AGC_RET IaaAgc_SetHighFreqCompressionRatioCurve(AGC_HANDLE handle,
                          int* CompressRatioInput, int* CompressRatioOutput);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      CompressRatioInput Compression ratio curve input array, please refer to compression ratio of agc_config Input
      CompressRatioOutput Compression ratio curve output array, please refer to compression ratio of agc_config Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaAgc_Run example.


    2.37. IaaAgc_SetAgcFreqBand

    • Features

      Set Agc frequency band.

      Please set agc user_mode 2 to enable frequency domain Agc before calling this function.

    • Syntax

      ALGO_AGC_RET IaaAgc_SetAgcFreqBand(AGC_HANDLE handle, int* frequency_band);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      Frequency_band Frequency band setting array. It involve low frequency upper limit, middle frequency upper limit and high frequency upper limit.
      For example: When the sampling rate is 16K, setting frequency band as {3000,4000,8000}
      Then the low frequency band is range from 0 to 3000Hz, middle frequency band is range from 3000 to 4000Hz, high frequency band is range from 4000 to 8000Hz. Please double check that the highest frequency can't exceed the half of sampling rate.
      Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaAgc_Run example.


    2.38. IaaAgc_Run

    • Features

      Agc algorithm processing.

    • Syntax

      ALGO_AGC_RET IaaAgc_Run(AGC_HANDLE handle, short* pss_audio_in);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      pss_audio_in Input data pointer Input/Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The data length must correspond to the point_number (sampling points required for one IaaAgc_Run) set when calling IaaAgc_Init. The processed data will be written back to the memory pointed to by pss_audio_in.
    • Example

      #include <stdio.h>
      #include <string.h>
      #include <stdlib.h>
      #include <sys/time.h>
      
      #include "AudioProcess.h"
      
      /*  0:Fixed input file  1:User input file   */
      #define IN_PARAMETER 1
      
      int main(int argc, char *argv[])
      {
          short in_output[1024];
          unsigned int workingBufferSize;
          char *workingBuffer = NULL;
          AGC_HANDLE handle;
          AudioProcessInit agc_init, agc_get_init;
          AudioAgcConfig agc_config, agc_get_config;
          ALGO_APC_RET ret;
          int tempSize;
          FILE* fpIn;  //input file
          FILE* fpOut; //output file
          char src_file[128] = {0};
          char dst_file[128] = {0};
          /*********************User change section start*******************/
          short compression_ratio_input[7] = {-65,-55,-48,-25,-18,-12,0};
          short compression_ratio_output[7] = {-65,-50,-27,-12,-1,-1,-1};
          int freqBand[7] = {1000,6000,8000};
          int compressionRatioArrayLowInput[7] = {-65,-55,-48,-25,-18,-12,0};
          int  compressionRatioArrayLowOutput [7] = {-65,-50,-27,-12,-1,-1,-1};
          int  compressionRatioArrayMidInput [7] = {-65,-55,-48,-25,-18,-12,0};
          int  compressionRatioArrayMidOutput [7] = {-65,-50,-27,-12,-1,-1,-1};
          int  compressionRatioArrayHighInput [7] = {-65,-55,-48,-25,-18,-12,0};
          int  compressionRatioArrayHighOutput [7] = {-65,-50,-27,-12,-1,-1,-1};
          agc_init.point_number = 128;
          agc_init.channel = 1;
          agc_init.sample_rate = IAA_APC_SAMPLE_RATE_16000;
      
          agc_config.agc_enable = 1;
          agc_config.user_mode = 2;
          agc_config.gain_info.gain_max  = 40;
          agc_config.gain_info.gain_min  = -10;
          agc_config.gain_info.gain_init = 12;
          agc_config.drop_gain_max = 36;
          agc_config.drop_gain_step = 1;
          agc_config.attack_time = 1;
          agc_config.release_time = 1;
          agc_config.noise_gate_db = -80;
          agc_config.noise_gate_attenuation_db = 0;
          agc_config.drop_gain_threshold = -5;
          /*********************User change section end*******************/
          memcpy(agc_config.compression_ratio_input, compression_ratio_input, sizeof(compression_ratio_input));
          memcpy(agc_config.compression_ratio_output, compression_ratio_output, sizeof(compression_ratio_output));
          //(1)IaaAgc_GetBufferSize
          workingBufferSize = IaaAgc_GetBufferSize();
          workingBuffer = (char *)malloc(workingBufferSize);
      
          if(NULL == workingBuffer)
          {
              printf("malloc workingBuffer failed !\n");
              return -1;
          }
          printf("malloc workingBuffer succeed !\n");
          //(2)IaaAgc_Init
          handle = IaaAgc_Init(workingBuffer, &agc_init);
          if(NULL == handle)
          {
              printf("IaaAgc_Init failed !\n");
              return -1;
          }
          printf("IaaAgc_Init succeed !\n");
          //(3)IaaAgc_Config
          ret = IaaAgc_Config(handle, &agc_config);
          if(ret)
          {
              printf("IaaAgc_Config failed !\n");
              return -1;
          }
          printf("IaaAgc_Config succeed !\n");
      
          IaaAgc_SetAgcFreqBand(handle, freqBand);
          IaaAgc_SetLowFreqCompressionRatioCurve(handle,compressionRatioArrayLowInput, compressionRatioArrayLowOutput);
          IaaAgc_SetMidFreqCompressionRatioCurve(handle,compressionRatioArrayMidInput, compressionRatioArrayMidOutput);
          IaaAgc_SetHighFreqCompressionRatioCurve(handle,compressionRatioArrayHighInput, compressionRatioArrayHighOutput);
          //(4)IaaAgc_GetConfig
          ret = IaaAgc_GetConfig(handle, &agc_get_init, &agc_get_config);
          if(ret)
          {
              printf("IaaAgc_GetConfig failed !\n");
              return -1;
          }
          printf("IaaAgc_GetConfig succeed !\n");
          printf("agc_get_config.user_mode = %d, ...\n", agc_get_config.user_mode);
      
      #if IN_PARAMETER
          if(argc < 3)
          {
              printf("Please enter the correct parameters!\n");
              return -1;
          }
          sscanf(argv[1], "%s", src_file);
          sscanf(argv[2], "%s", dst_file);
      #else
          sprintf(src_file, "%s", "./APC_AFE_16K.wav");
          if(argc < 2)
          {
              printf("Please enter the correct parameters!\n");
              return -1;
          }
          sscanf(argv[1], "%s", dst_file);
      #endif
      
          fpIn = fopen(src_file, "rb");
          if(NULL == fpIn)
          {
              printf("fopen in_file failed !\n");
              return -1;
          }
          printf("fopen in_file success !\n");
          fpOut = fopen(dst_file, "wb");
          if(NULL == fpOut)
          {
              printf("fopen out_file failed !\n");
              return -1;
          }
          printf("fopen out_file success !\n");
      
          fread(in_output, sizeof(char), 44, fpIn);
          fwrite(in_output, sizeof(char), 44, fpOut);
      
          tempSize = agc_init.point_number * agc_init.channel;
          while(tempSize == fread(in_output, sizeof(short), tempSize, fpIn))
          {
              //(5)IaaAgc_Run
              ret = IaaAgc_Run(handle, in_output);
              if(ret)
              {
                  printf("IaaAnr_Run failed !\n");
                  return -1;
              }
              fwrite(in_output, sizeof(short), tempSize, fpOut);
          }
          printf("Break:needBytes =%d \t nBytesRead = %d\n", agc_init.point_number * agc_init.channel, tempSize);
          //(6)IaaAgc_Free
          IaaAgc_Free(handle);
          free(workingBuffer);
          fclose(fpIn);
          fclose(fpOut);
          printf("APC_AGC end !\n");
      
          return 0;
      }
      

    2.39. IaaAgc_Free

    • Features

      Release Agc algorithm resources.

    • Syntax

      ALGO_AGC_RET IaaAgc_Free(AGC_HANDLE handle);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      Please refer to IaaAgc_Run example.


    2.40. IaaAgc_Reset

    • Features

      Reinitialize the Eq algorithm.

    • Syntax

      AGC_HANDLE IaaAgc_Reset(char* working_buffer_address, AudioProcessInit *agc_init);
      
    • Parameters

      Parameter name Description Input/Output
      working_buffer_address Memory address used by Agc algorithm Input
      agc_init Agc algorithm initialization structure pointer Input
    • Return value

      Return value Result
      Not NULL Successful
      NULL Failed
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      None.


    2.41. IaaAgc_GetConfig

    • Features

      Get the Agc algorithm current configuration parameters.

    • Syntax

      ALGO_AGC_RET IaaAgc_GetConfig(AGC_HANDLE handle, AudioProcessInit *agc_init, AudioAgcConfig *agc_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      agc_init Agc algorithm initialization structure pointer Output
      agc_config Agc algorithm in the current configuration parameters Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      None.

    • Example

      Please refer to IaaAgc_Run example.


    2.42. IaaApc_SetCompressionRatioCurve

    • Features

      Set Agc in Apc compression ratio curve for more slope segment.

    • Syntax

      ALGO_APC_RET IaaApc_SetCompressionRatioCurve(APC_HANDLE handle, short* CompressionRatioInput, short* CompressionRatioOutput, int curve_len);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      CompressionRatioInput Compression ratio curve input Input
      CompressionRatioOutput Compression ratio curve output Input
      curve_len Compression ratio curve array length value
      Range: [2, 20]
      Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaApc_Run example.


    2.43. IaaAgc_SetCompressionRatioCurve

    • Features

      Set Agc compression ratio curve for more slope segment.

    • Syntax

      ALGO_AGC_RET IaaAgc_SetCompressionRatioCurve(AGC_HANDLE handle, short* CompressionRatioInput, short* CompressionRatioOutput, int curve_len);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      CompressionRatioInput Compression ratio curve input Input
      CompressionRatioOutput Compression ratio curve output Input
      curve_len Compression ratio curve array length value
      Range: [2, 20]
      Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to IaaAgc_Run example.


    2.44. IaaApc_NrEstimateReferAec

    • Features

      Noise estimation refer to Aec linear process output.

    • Syntax

      ALGO_APC_RET IaaApc_NrEstimateReferAec (APC_HANDLE handle, short aec_in);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      aec_in Input data pointer. Provide Aec linear process output for Noise reduction module. Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The API is only support AudioAnrConfig anr_filter_mode 0~4.

    2.45. IaaApc_EnhanceNNBFMode

    • Features

      Special enhancement for concatenating Bf mode 3 and APC deep learning based noise reduction.

    • Syntax

      ALGO_APC_RET IaaApc_EnhanceNNBFMode(APC_HANDLE handle, APC_BF_HANDLE  handle2 , int is_enable);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc handle Input
      handle2 Bf handle Input
      is_enable 0:disable, 1: enable Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The API is only applicable to special enhancement that using BF mode 3 and anr_filter_mode 5 simultaneously.

      • Must include BF library.

      • The API should be run between IaaBf_Run and IaaApc_Run.


    2.46. IaaApc_FilterDesign

    • Features

      Initialized IIR filter configuration.

    • Syntax

      ALGO_APC_RET IaaApc_FilterDesign(APC_HANDLE handle, int filter_cnt, AudioFilterConfig* filter_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      filter_cnt Filter sequence
      range:[1,10]
      Input
      filter_config Filter configuration Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The results of filter design must be based on the frequency response curve. It does not mean that the target gain will be achieved by setting a certain frequency.

      • Because this filter is an IIR filter and will have a non-linear impact on the phase, it is recommended to place it at the end of all algorithms.

      • If the Q value is set too large, it means the energy decreases steeply, which may cause other frequency bands to increase abnormally. Please refer to the frequency response curve.

      • If you want to achieve a steeper curve, you can design multiple identical filter superpositions.

      • There is no standard answer to filter design, it depends on the user's needs.

    • Example

      Please refer to the example section in IaaEq_FilterDesign.


    2.47. IaaApc_FilterApply

    • Features

      IIR filter apply.

    • Syntax

      ALGO_APC_RET IaaApc_FilterApply(APC_HANDLE handle, short* pss_audio_in);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      pss_audio_in Input data pointer Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      //filter 1
      AudioFilterConfig filter_design;
      filter_design.q_factor = 5;
      filter_design.f0 = 1000;
      filter_design.type = EQ_NOTCH_FILTER;
      filter_design.gain = -10;
      //filter 2
      AudioFilterConfig filter_design2;
      filter_design2.q_factor = 5;
      filter_design2.f0 = 5000;
      filter_design2.type = EQ_NOTCH_FILTER;
      filter_design2.gain = -10;
      //filter 3
      AudioFilterConfig filter_design3;
      filter_design3.q_factor = 5;
      filter_design3.f0 = 500;
      filter_design3.type = EQ_NOTCH_FILTER;
      filter_design3.gain = -10;
      
      IaaApc_FilterDesign(handle, 1, &filter_design);
      IaaApc_FilterDesign(handle, 2, &filter_design2);
      IaaApc_FilterDesign(handle, 3, &filter_design3);
      float h[512];
      IaaApc_FilterApply(handle, h);
      
      while(read input data){
      ret1 = IaaApc_FilterApply(handle, input);
      }
      

    2.48. IaaEq_FilterDesign

    • Features

      Initialized IIR filter configuration.

    • Syntax

      ALGO_EQ_RET IaaEq_FilterDesign (EQ_HANDLE handle, int filter_cnt, AudioFilterConfig* filter_config);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input
      filter_cnt Filter sequence
      range:[1,10]
      Input
      filter_config Filter configuration Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The result of filtering design is based on the frequency response curve. The target gain is not always achieved by setting the filter to a certain level.
      • Suggest that user should put this filtering at the end of audio process flow, because this filtering is IIR filtering.
      • The higher the Q factor, the faster the energy drop. It may cause other frequency band to pull up abnormally. Please refer to this frequency response curve.
      • If users want to get faster drop of frequency response curve, users can design serval filter for application.
      • There is no stardard answer of filtering design. It's all based on user's requirement.
    • Example

      • The following is an example of over-set Q factor

        filter_design.q_factor = 5;
        
        filter_design.f0 = 2000;
        
        filter_design.type = EQ_HIGH_PASS_FILTER;
        
        filter_design.gain = 3;
        

      • Filter overlay

        As the name suggests, it's straightforward to set up multiple filters.

        //filter1
        AudioFilterConfig filter_design;
        
        filter_design.q_factor = 1;
        
        filter_design.f0 = 2000;
        
        filter_design.type = EQ_HIGH_PASS_FILTER;
        
        filter_design.gain = 0;
        
        //filter 2
        AudioFilterConfig filter_design2;
        
        filter_design2.q_factor = 1;
        
        filter_design2.f0 = 2000;
        
        filter_design2.type = EQ_HIGH_PASS_FILTER;
        
        filter_design2.gain = 0;
        

        The blue line below is the frequency response of filter_design only, while the orange line is the frequency response of filter_design and filter_design2 at the same time, which can achieve a faster frequency drop.


    2.49. IaaEq_FilterApply

    • Features

      IIR filter apply.

    • Syntax

      ALGO_EQ_RET IaaEq_FilterApply(EQ_HANDLE handle, short* pss_audio_in);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input
      pss_audio_in Input data pointer Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      //filter 1
      AudioFilterConfig filter_design;
      filter_design.q_factor = 5;
      filter_design.f0 = 1000;
      filter_design.type = EQ_NOTCH_FILTER;
      filter_design.gain = -10;
      //filter 2
      AudioFilterConfig filter_design2;
      filter_design2.q_factor = 5;
      filter_design2.f0 = 5000;
      filter_design2.type = EQ_NOTCH_FILTER;
      filter_design2.gain = -10;
      //filter 3
      AudioFilterConfig filter_design3;
      filter_design3.q_factor = 5;
      filter_design3.f0 = 500;
      filter_design3.type = EQ_NOTCH_FILTER;
      filter_design3.gain = -10;
      
      IaaEq_FilterDesign(handle, 1, &filter_design);
      IaaEq_FilterDesign(handle, 2, &filter_design2);
      IaaEq_FilterDesign(handle, 3, &filter_design3);
      float h[512];
      IaaEq_FilterFreqz(handle, h);
      
      while(read input data){
      ret1 = IaaEq_FilterApply(handle, input);
      }
      

    2.50. IaaAnr_EnhanceNNBFMode

    • Features

      Special enhancement for concatenating Bf mode 3 and ANR deep learning based noise reduction.

    • Syntax

      ALGO_ANR_RET IaaAnr_EnhanceNNBFMode(ANR_HANDLE handle, ANR_BF_HANDLE  handle2 , int is_enable);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
      handle2 Bf algorithm handle Input
      is_enable 0:disable, 1: enable Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The API is only applicable to special enhancement that using BF mode 3 and anr_filter_mode 5 simultaneously.
      • Must include BF library.
      • The API should be run between IaaBf_Run and IaaAnr_Run.

    2.51. IaaApc_GetAPIVersion

    • Features

      Get version of Apc API.

    • Syntax

      ALGO_APC_RET IaaApc_GetAPIVersion(unsigned short* major, unsigned short* minor);
      
    • Parameters

      Parameter name Description Input/Output
      major Input data pointer and get number before the decimal point of APC API version Output
      minor Input data pointer and get number after the decimal point of APC API version Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.52. IaaApc_SetHandleId

    • Features

      Set Apc Handle Id.

    • Syntax

      ALGO_APC_RET IaaApc_SetHandleId(APC_HANDLE handle, int id);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      id Apc handle id
      range:[0,100]
      Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.53. IaaAnr_SetHandleId

    • Features

      Set Anr Handle Id.

    • Syntax

      ALGO_ANR_RET IaaAnr_SetHandleId(ANR_HANDLE handle, int id);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
      id Anr handle id
      range:[0,100]
      Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.54. IaaEq_SetHandleId

    • Features

      Set Eq Handle Id.

    • Syntax

      ALGO_EQ_RET IaaEq_SetHandleId(EQ_HANDLE handle, int id);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input
      id Eq handle id
      range:[0,100]
      Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.55. IaaAgc_SetHandleId

    • Features

      Set Agc Handle Id.

    • Syntax

      ALGO_AGC_RET IaaAgc_SetHandleId(AGC_HANDLE handle, int id);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      id Agc handle id
      range:[0,100]
      Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.56. IaaApc_GetJsonFileSize

    • Features

      Apc get size of json file.

    • Syntax

      unsigned int IaaApc_GetJsonFileSize(char* jsonfile);
      
    • Parameters

      Parameter name Description Input/Output
      jsonfile name of json file Input
    • Return value

      Return value is the memory size required for decoding json file.

    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.57. IaaApc_NrReadJson

    • Features

      Set json parameter into Apc Handle.

    • Syntax

      ALGO_APC_RET IaaApc_NrReadJson(APC_HANDLE handle, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      jsonBuffer json buffer memory address Input
      jsonfile name of json file Input
      buffSize size of json file Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.58. IaaAnr_GetJsonFileSize

    • Features

      Anr get size of json file.

    • Syntax

      unsigned int IaaAnr_GetJsonFileSize(char* jsonfile);
      
    • Parameters

      Parameter name Description Input/Output
      jsonfile name of json file Input
    • Return value

      Return value is the memory size required for decoding json file.

    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.59. IaaAnr_NrReadJson

    • Features

      Set json parameter into Anr Handle.

    • Syntax

      ALGO_ANR_RET IaaAnr_NrReadJson(ANR_HANDLE handle, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
      jsonBuffer json buffer memory address Input
      jsonfile name of json file Input
      buffSize size of json file Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.60. IaaApc_EnableComfortNoise

    • Features

      Enable comfort noise algorithm and set power of comfort noise into Apc Handle

    • Syntax

      ALGO_APC_RET IaaApc_EnableComfortNoise(APC_HANDLE handle, int enable, int dB);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      enable enable comfort noise algorithm Input
      dB set power of comfort noise Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.61. IaaAnr_EnableComfortNoise

    • Features

      Enable comfort noise algorithm and set power of comfort noise into Anr Handle

    • Syntax

      ALGO_ANR_RET IaaAnr_EnableComfortNoise(ANR_HANDLE handle, int enable, int dB);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
      enable enable comfort noise algorithm Input
      dB set power of comfort noise Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.62. IaaEq_EnableComfortNoise

    • Features

      Enable comfort noise algorithm and set power of comfort noise into Eq Handle

    • Syntax

      ALGO_EQ_RET IaaEq_EnableComfortNoise(EQ_HANDLE handle, int enable, int dB);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input
      enable enable comfort noise algorithm Input
      dB set power of comfort noise Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.63. IaaAgc_EnableComfortNoise

    • Features

      Enable comfort noise algorithm and set power of comfort noise into Agc Handle

    • Syntax

      ALGO_AGC_RET IaaAgc_EnableComfortNoise(AGC_HANDLE handle, int enable, int dB);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input
      enable enable comfort noise algorithm Input
      dB set power of comfort noise Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.64. IaaApc_EnableAutoSmooth

    • Features

      Enable automatic smooth algorithm into Apc Handle

    • Syntax

      ALGO_APC_RET IaaApc_EnableAutoSmooth(APC_HANDLE handle, int enable);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      enable enable auto smooth algorithm Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.65. IaaAnr_EnableAutoSmooth

    • Features

      Enable automatic smooth algorithm into Anr Handle

    • Syntax

      ALGO_ANR_RET IaaAnr_EnableAutoSmooth(ANR_HANDLE handle, int enable);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
      enable enable auto smooth algorithm Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.66. IaaApc_ApplyComfortNoise

    • Features

      Specified power comfort noise mixture.

    • Syntax

      ALGO_APC_RET IaaApc_ApplyComfortNoise(CngStruct cng_para, short* pss_audio_in);
      
    • Parameters

      Parameter name Description Input/Output
      cng_para comfort noise configuration structure Input
      pss_audio_in Input data. It will be overwrirted by processed signal Input/Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.67. IaaApc_SwitchReadFromJson

    • Features

      Configure Json parameters to enable setting structure handle of Apc algorithm

    • Syntax

      ALGO_APC_RET IaaApc_SwitchReadFromJson(AudioApcBufferConfig *apc_switch, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      apc_switch Structure handle of Apc algorithm enable setting Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      #include <stdio.h>
      #include <unistd.h>
      #include <fcntl.h>
      #include <string.h>
      #include <time.h>
      #include <stdlib.h>
      #ifndef OS_WINDOWS
      #include <sys/ioctl.h>
      #endif
      #include <sys/types.h>
      #include <sys/stat.h>
      #include <sys/time.h>
      
      #include "AudioProcess.h"
      
      #define USE_MALLOC               (1)
      #define USE_JSON                 (1)
      #define FILTER_ENABLE            (0)
      #define FREQ_AGC_ENABEL          (1)
      #define DIGITAL_GAIN_ENABLE      (1)
      
      unsigned int WorkingBuffer2[1] = {0};
      
      typedef unsigned char                uint8;
      typedef unsigned short               uint16;
      typedef unsigned long                uint32;
      
      float AVERAGE_RUN(int a)
      {
          static unsigned int num = 0;
          static float avg = 0;
          if(num == 0) avg = 0;
          num++;
          avg = avg + ((float)a - avg) / ((float)num);
          return avg;
      }
      unsigned int _OsCounterGetMs(void)
      {
          struct  timeval t1;
          gettimeofday(&t1,NULL);
          unsigned int T = ( (1000000 * t1.tv_sec)+ t1.tv_usec )/1000;
          return T;
      }
      
      int main(int argc, char *argv[])
      {
          short input[1024];
          unsigned int T0, T1;
          float avg = 0;
          float peak = 0;
          char input_file[512];
          char output_file[512];
          int counter=0;
      #if FREQ_AGC_ENABEL
          int freqBand[_AGC_FREQ_BAND_NUM];
          int compressionRatioArrayLowInput[_AGC_CR_NUM];
          int compressionRatioArrayLowOutput[_AGC_CR_NUM];
          int compressionRatioArrayMidInput[_AGC_CR_NUM];
          int compressionRatioArrayMidOutput[_AGC_CR_NUM];
          int compressionRatioArrayHighInput[_AGC_CR_NUM];
          int compressionRatioArrayHighOutput[_AGC_CR_NUM];
      #endif
      
          AudioApcBufferConfig apc_switch;
          memset(&apc_switch,0,sizeof(AudioApcBufferConfig));
      #if USE_JSON
          unsigned int use_apc_param_json = 1;
          char apc_para_json_file[512];
          sprintf(apc_para_json_file,"%s","./../sample/data/ApcParamJson.json");
          int apc_para_buffersize = IaaApc_GetJsonFileSize(apc_para_json_file);
          if(apc_para_buffersize == 0){
              printf("IaaApc_GetJsonFileSize() error. Can not load json file [%s]\t\n", apc_para_json_file);
              use_apc_param_json = 0;
          }
          else{
              printf("IaaApc_GetJsonFileSize() succeed.\t\n");
          }
      #if USE_MALLOC
          char *apc_para_json_buf_ptr = (char*)malloc(apc_para_buffersize);
      #else
          char apc_para_json_buf_ptr[512*1000];
      #endif
          if(use_apc_param_json){
              if(IaaApc_SwitchReadFromJson(&apc_switch, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                  printf("IaaApc_SwitchReadFromJson() error.\t\n");
                  return -1;
              }
              else{
                  printf("IaaApc_SwitchReadFromJson() succeed.\t\n");
              }
          }
      #endif
      
          int buffersize = IaaApc_GetBufferSize(&apc_switch);
          if(buffersize == 0){
              printf("IaaApc_GetBufferSize() error.\t\n");
              return -1;
          }
          else{
              printf("IaaApc_GetBufferSize() succeed.\t\n");
          }
      #if USE_MALLOC
          char *working_buf_ptr = (char*)malloc(buffersize);
      #else
          char working_buf_ptr[512*1000];
      #endif
      
      #if USE_JSON
          unsigned int use_anr_intl_json = 1;
          char anr_intl_json_file[512];
          sprintf(anr_intl_json_file,"%s","./../sample/data/AnrInternalJson.json");
          int anr_intl_buffersize = IaaApc_GetJsonFileSize(anr_intl_json_file);
          if(anr_intl_buffersize == 0){
              printf("IaaApc_GetJsonFileSize() error. Can not load json file [%s]\t\n", anr_intl_json_file);
              use_anr_intl_json = 0;
          }
          else{
              printf("IaaApc_GetJsonFileSize() succeed.\t\n");
          }
      #if USE_MALLOC
          char *anr_intl_json_buf_ptr = (char*)malloc(anr_intl_buffersize);
      #else
          char anr_intl_json_buf_ptr[512*1000];
      #endif
      #endif
      
      #if USE_JSON
          unsigned int use_apc_intl_json = 1;
          char apc_intl_json_file[512];
          sprintf(apc_intl_json_file,"%s","./../sample/data/ApcInternalJson.json");
          int apc_intl_buffersize = IaaApc_GetJsonFileSize(apc_intl_json_file);
          if(apc_intl_buffersize == 0){
              printf("IaaApc_GetJsonFileSize() error. Can not load json file [%s]\t\n", apc_intl_json_file);
              use_apc_intl_json = 0;
          }
          else{
              printf("IaaApc_GetJsonFileSize() succeed.\t\n");
          }
      #if USE_MALLOC
          char *apc_intl_json_buf_ptr = (char*)malloc(apc_intl_buffersize);
      #else
          char apc_intl_json_buf_ptr[512*1000];
      #endif
      #endif
      
          FILE * fin, * fout;
          int ret1;
          AudioProcessInit apc_init;
          AudioAnrConfig anr_config;
          AudioEqConfig eq_config;
          AudioHpfConfig hpf_config;
          AudioAgcConfig agc_config;
          AudioApcOption apc_option;
          memset(&apc_init,0,sizeof(AudioProcessInit));
          memset(&anr_config,0,sizeof(AudioAnrConfig));
          memset(&eq_config,0,sizeof(AudioEqConfig));
          memset(&hpf_config,0,sizeof(AudioHpfConfig));
          memset(&agc_config,0,sizeof(AudioAgcConfig));
          memset(&apc_option,0,sizeof(AudioApcOption));
          APC_HANDLE handle;
      
      #if USE_JSON
          if(use_apc_param_json){
              if(IaaApc_InitReadFromJson(&apc_init, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                  printf("IaaApc_InitReadFromJson() error.\t\n");
                  return -1;
              }
              else{
                  printf("IaaApc_InitReadFromJson() succeed.\t\n");
              }
          }
      #endif
          handle = IaaApc_Init((char *)working_buf_ptr, &apc_init, &apc_switch);
          if(handle==NULL){
              printf("IaaApc_Init() error.\t\n");
              return -1;
          }
          else{
              printf("IaaApc_Init() succeed.\t\n");
          }
      
      #if USE_JSON
          if(use_apc_param_json){
              if(IaaApc_ConfigReadFromJson(&anr_config, &eq_config, &hpf_config, &agc_config, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                  printf("IaaApc_ConfigReadFromJson() error.\t\n");
                  return -1;
              }
              else{
                  printf("IaaApc_ConfigReadFromJson() succeed.\t\n");
              }
          }
      #endif
          if(IaaApc_Config(handle,&anr_config,&eq_config,&hpf_config,NULL,NULL,&agc_config) != -0){
              printf("IaaApc_Config() error.\t\n");
              return -1;
          }
          else{
              printf("IaaApc_Config() succeed.\t\n");
          }
      
      #if USE_JSON
          if(apc_switch.anr_enable && use_anr_intl_json){
              if(IaaApc_NrReadJson(handle, anr_intl_json_buf_ptr, anr_intl_json_file, anr_intl_buffersize) != 0){
                  printf("IaaApc_NrReadJson() error.\t\n");
                  return -1;
              }
              else{
                  printf("IaaApc_NrReadJson() succeed.\t\n");
              }
          }
      #endif
      
      #if USE_JSON
          if(use_apc_intl_json){
              if(IaaApc_ReadJson(handle, apc_intl_json_buf_ptr, apc_intl_json_file, apc_intl_buffersize) != 0){
                  printf("IaaApc_ReadJson() error.\t\n");
                  return -1;
              }
              else{
                  printf("IaaApc_ReadJson() succeed.\t\n");
              }
          }
      #endif
      
      #if FILTER_ENABLE
          float h[512];
      #if USE_JSON
          if(use_apc_param_json){
              if(IaaApc_FilterDesignReadFromJson(handle, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                  printf("IaaEq_FilterDesignReadFromJson() error.\t\n");
                  return -1;
              }
              else{
                  printf("IaaEq_FilterDesignReadFromJson() succeed.\t\n");
              }
          }
      #endif
          IaaApc_FilterFreqz(handle,h);
      #endif
      
      #if FREQ_AGC_ENABEL
          if(agc_config.user_mode == 2){
      #if USE_JSON
              if(use_apc_param_json){
                  if(IaaApc_SetAgcReadFromJson(&freqBand[0], &compressionRatioArrayLowInput[0], &compressionRatioArrayLowOutput[0],
                              &compressionRatioArrayMidInput[0], &compressionRatioArrayMidOutput[0],
                              &compressionRatioArrayHighInput[0], &compressionRatioArrayHighOutput[0],
                              apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0 ){
                      printf("IaaAgc_SetAgcReadFromJson() error.\t\n");
                      return -1;
                  }
                  else{
                      printf("IaaAgc_SetAgcReadFromJson() succeed.\t\n");
                  }
              }
      #endif
              IaaApc_SetAgcFreqBand(handle, freqBand);
              IaaApc_SetLowFreqCompressionRatioCurve(handle, compressionRatioArrayLowInput, compressionRatioArrayLowOutput);
              IaaApc_SetMidFreqCompressionRatioCurve(handle, compressionRatioArrayMidInput, compressionRatioArrayMidOutput);
              IaaApc_SetHighFreqCompressionRatioCurve(handle, compressionRatioArrayHighInput, compressionRatioArrayHighOutput);
          }
      #endif
      
      #if DIGITAL_GAIN_ENABLE
      #if USE_JSON
          if(use_apc_param_json){
              if(IaaApc_OptionReadFromJson(&apc_option, apc_para_json_buf_ptr, apc_para_json_file, apc_para_buffersize) != 0){
                  printf("IaaApc_OptionReadFromJson() error.\t\n");
                  return -1;
              }
              else{
                  printf("IaaApc_OptionReadFromJson() succeed.\t\n");
              }
          }
      #endif
      #endif
      
          sprintf(input_file,"%s","./../sample/data/APC_AFE_16K.wav");
          sprintf(output_file,"%s","./../sample/data/APC_out_16K.wav");
      
          fin = fopen(input_file, "rb");
          if(!fin)
          {
              printf("the input file %s could not be open\n",input_file);
              return -1;
          }
      
          fout = fopen(output_file, "wb");
          if(!fout)
          {
              printf("the output file could not be open\n");
              return -1;
          }
      
          fread(input, sizeof(char), 44, fin); // read header 44 bytes
          fwrite(input, sizeof(char),44, fout); // write 44 bytes output
      
          while(fread(input, sizeof(short), apc_init.point_number*apc_init.channel, fin))
          {
      
              counter++;
              T0  = (long)_OsCounterGetMs();
      #if DIGITAL_GAIN_ENABLE
              ret1 = IaaApc_ApplyDigitalGain(handle,input,apc_option.digital_gain[0]);
      #endif
              ret1 = IaaApc_Run(handle,input);
      #if FILTER_ENABLE
              ret1 += IaaApc_FilterApply(handle, input);
      #endif
      
      #if DIGITAL_GAIN_ENABLE
              ret1 += IaaApc_ApplyDigitalGain(handle,input,apc_option.digital_gain[1]);
      #endif
      
              T1  = (long)_OsCounterGetMs();
              avg += (T1 - T0);
              if(peak < (T1 - T0))
                  peak = (T1 - T0);
      
              if(counter%1000== 999)
              {
                  printf("counter = %d\n", counter);
                  printf("current time = %f\n", (float)counter*apc_init.point_number/apc_init.sample_rate);
                  printf("process time = %lu(ms)\t",(long)(T1 - T0));
              }
      
              if(ret1 != 0)
              {
                  printf("Error occured in APC\n");
                  break;
              }
      
              fwrite(input, sizeof(short), apc_init.point_number*apc_init.channel, fout);
          }
          avg /= counter;
          printf("AVG is %.2f ms\n",avg);
          printf("PEAK is %.2f ms\n",peak);
          IaaApc_Free(handle);
          free(working_buf_ptr);
          fclose(fin);
          fclose(fout);
      
          printf("Done\n");
      return 0;
      }
      

    2.68. IaaApc_InitReadFromJson

    • Features

      Configure Json parameters to initialize structure handle of the Apc algorithm

    • Syntax

      ALGO_APC_RET IaaApc_InitReadFromJson(AudioProcessInit *audio_process_init, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      audio_process_init Apc algorithm initialization structure handle Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to the example section of IaaApc_SwitchReadFromJson.


    2.69. IaaApc_ConfigReadFromJson

    • Features

      Configure Json parameters to the structure handle of the Apc algorithm

    • Syntax

      ALGO_APC_RET IaaApc_ConfigReadFromJson(AudioAnrConfig *anr_config, AudioEqConfig *eq_config, AudioHpfConfig *hpf_config, AudioAgcConfig *agc_config, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      anr_config Configure the structure handle of the Anr algorithm Input/Output
      eq_config Configure the structure handle of the Eq algorithm Input/Output
      hpf_config Configure the structure handle of the Hpf algorithm Input/Output
      agc_config Configure the structure handle of the Agc algorithm Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to the example section of IaaApc_SwitchReadFromJson.


    2.70. IaaApc_SetAgcReadFromJson

    • Features

      Configure Json parameters to Agc band array

    • Syntax

      ALGO_APC_RET IaaApc_SetAgcReadFromJson(int *freqBand, int *compressionRatioArrayLowInput, int *compressionRatioArrayLowOutput, int *compressionRatioArrayMidInput, int *compressionRatioArrayMidOutput, int *compressionRatioArrayHighInput, int *compressionRatioArrayHighOutput, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      freqBand Frequency band array, including low frequency upper limit, middle frequency upper limit and high frequency upper limit.
      For example: When the sampling rate is 16K, setting frequency band as {3000,4000,8000}
      Then the low frequency band is range from 0 to 3000Hz, middle frequency band is range from 3000 to 4000Hz, high frequency band is range from 4000 to 8000Hz. Please double check that the highest frequency can't exceed the half of sampling rate.
      Input/Output
      compressionRatioArrayLowInput Compression ratio input, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayLowOutput Compression ratio output, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayMidInput Compression ratio input, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayMidOutput Compression ratio output, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayHighInput Compression ratio input, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayHighOutput Compression ratio output, please refer to compression ratio in agc_config Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to the example section of IaaApc_SwitchReadFromJson.


    2.71. IaaApc_FilterDesignReadFromJson

    • Features

      Configure Json parameters to the Eq filter structure handle of the Apc algorithm

    • Syntax

      ALGO_APC_RET IaaApc_FilterDesignReadFromJson(APC_HANDLE handle, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to the example section of [IaaApc_SwitchReadFromJson](#267-iaaapc_switchreadfromjson).
      

    2.72. IaaAnr_InitReadFromJson

    • Features

      Configure Json parameters to the initialize structure handle of the Anr algorithm

    • Syntax

      ALGO_ANR_RET IaaAnr_InitReadFromJson(AudioProcessInit *anr_init, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      anr_init Anr algorithm initialization structure handle Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.73. IaaAnr_ConfigReadFromJson

    • Features

      Configure Json parameters to the structure handle of the Anr algorithm

    • Syntax

      ALGO_ANR_RET IaaAnr_ConfigReadFromJson(AudioAnrConfig *anr_config, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      anr_config Configure the structure handle of the Anr algorithm Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.74. IaaEq_GetJsonFileSize

    • Features

      Get the memory size to parse the content of the Json file required by Eq

    • Syntax

      unsigned int IaaEq_GetJsonFileSize(char* jsonfile);
      
    • Parameters

      Parameter name Description Input/Output
      jsonfile Json file name Input
    • Return value

      The return value is the memory size required to parse the Json file content.

    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.75. IaaEq_InitReadFromJson

    • Features

      Configure Json parameters to initialize structure handle of the Eq algorithm

    • Syntax

      ALGO_EQ_RET IaaEq_InitReadFromJson(AudioProcessInit *eq_init, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      eq_init Initialization structure handle of Eq algorithm Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.76. IaaEq_ConfigReadFromJson

    • Features

      Configure Json parameters to the structure handle of the Eq algorithm

    • Syntax

      ALGO_EQ_RET IaaEq_ConfigReadFromJson(AudioEqConfig *eq_config, AudioHpfConfig *hpf_config, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      eq_config Configure the structure handle of the Eq algorithm Input/Output
      hpf_config Configure the structure handle of the Hpf algorithm Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.77. IaaEq_FilterDesignReadFromJson

    • Features

      Configure Json parameters to the filter structure handle of the Eq algorithm

    • Syntax

      ALGO_EQ_RET IaaEq_FilterDesignReadFromJson(EQ_HANDLE handle, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.78. IaaAgc_GetJsonFileSize

    • Features

      Get the memory size to parse the content of the Json file required by Agc

    • Syntax

      unsigned int IaaAgc_GetJsonFileSize(char* jsonfile);
      
    • Parameters

      Parameter name Description Input/Output
      jsonfile Json file name Input
    • Return value

      The return value is the memory size required to parse the Json file content.

    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.79. IaaAgc_InitReadFromJson

    • Features

      Configure Json parameters to initialize structure handle of the Agc algorithm

    • Syntax

      ALGO_AGC_RET IaaAgc_InitReadFromJson(AudioProcessInit *agc_init, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      agc_init Initialization structure handle of Agc algorithm Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.80. IaaAgc_ConfigReadFromJson

    • Features

      Configure Json parameters to the structure handle of the Agc algorithm

    • Syntax

      ALGO_AGC_RET IaaAgc_ConfigReadFromJson(AudioAgcConfig *agc_config, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      agc_config Configure the structure handle of the Agc algorithm Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.81. IaaAgc_SetAgcReadFromJson

    • Features

      Configure Json parameters to Agc band array

    • Syntax

      ALGO_AGC_RET IaaAgc_SetAgcReadFromJson(int *freqBand, int *compressionRatioArrayLowInput, int *compressionRatioArrayLowOutput, int *compressionRatioArrayMidInput, int *compressionRatioArrayMidOutput, int *compressionRatioArrayHighInput, int *compressionRatioArrayHighOutput, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      freqBand Frequency band array, including low frequency upper limit, middle frequency upper limit and high frequency upper limit.
      For example: When the sampling rate is 16K, setting frequency band as {3000,4000,8000}
      Then the low frequency band is range from 0 to 3000Hz, middle frequency band is range from 3000 to 4000Hz, high frequency band is range from 4000 to 8000Hz. Please double check that the highest frequency can't exceed the half of sampling rate.
      Input/Output
      compressionRatioArrayLowInput Compression ratio input, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayLowOutput Compression ratio output, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayMidInput Compression ratio input, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayMidOutput Compression ratio output, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayHighInput Compression ratio input, please refer to compression ratio in agc_config Input/Output
      compressionRatioArrayHighOutput Compression ratio output, please refer to compression ratio in agc_config Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a


    2.82. IaaAnr_NrEstimateReferAec

    • Features

      Refer to the Aec linear processing results for noise reduction to avoid Anr convergence anomalies caused by nonlinear Aec.

    • Syntax

      ALGO_ANR_RET IaaAnr_NrEstimateReferAec (ANR_HANDLE handle, short aec_in);
      
    • Parameters

      Parameter name Description Input/Output
      handle Anr algorithm handle Input
      aec_in Input data index, which provides data for noise estimation by the NR algorithm. Microphone data or Aec linear processing results can be used Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • The API is only support AudioAnrConfig anr_filter_mode 0~4.

    2.83. IaaApc_FilterFreqz

    • Features

      Get the result of superimposing the frequency response of several filters after configuring IaaApc_FilterDesign.

    • Syntax

      ALGO_APC_RET IaaApc_FilterFreqz(APC_HANDLE handle, float* frequency_response);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input
      frequency_response The result of the frequency response superposition of several filters, which is returned to frequency_response in the form of an array of 512 floats Input/Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      The superimposed frequency response of all digital filters currently designed can be drawn and returned to the frequency_response parameter in the form of an array of 512 floats. It is recommended that users use excel to draw the current frequency response. The 512 values in the array correspond to frequencies. From 0 to sample rate/2, the value of frequency_response represents the gain value.

    • Example

      Please refer to the example section in IaaApc_FilterApply.


    2.84. IaaEq_FilterFreqz

    • Features

      Get the result of superposition of frequency responses of several filters after configuring IaaEq_FilterFreqz.

    • Syntax

      ALGO_EQ_RET IaaEq_FilterFreqz(EQ_HANDLE handle, float* frequency_response);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input
      frequency_response The result of the superposition of frequency responses of several filters, which is returned to frequency_response in the form of an array of 512 floats Input/Output
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      The superimposed frequency response of all digital filters currently designed can be drawn and returned to the frequency_response parameter in the form of an array of 512 floats. It is recommended that users use excel to draw the current frequency response. The 512 values in the array correspond to frequencies. From 0 to sample rate/2, the value of frequency_response represents the gain value.

    • Example

      Please refer to the example section in IaaEq_FilterApply.


    2.85. IaaApc_OptionReadFromJson

    • Features

      Configure Json parameters to optional structure.

    • Syntax

      ALGO_APC_RET IaaApc_OptionReadFromJson(AudioApcOption *apc_option, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      apc_option Apc option setting pointer Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to the example section in IaaApc_SwitchReadFromJson.


    2.86. IaaApc_ReadJson

    • Features

      Configure Json parameters to Apc common setting

    • Syntax

      ALGO_APC_RET IaaApc_ReadJson(APC_HANDLE handle, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      handle Apc algorithm handle Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Note

      • It's available by using AUDIO_APC_DUMP, AUDIO_ANR_DUMP, AUDIO_EQ_DUMP, AUDIO_EQ_DUMP, AUDIO_DUMP_PATH to enable/disable dump debug operation.
      • User can use AUDIO_DUMP_PATH to set dump data path, the strings length is up to 40.
      • User can use Pre_APC_GAIN, POST_APC_GAIN to set Digital gain in the first and last process in IaaApc_Run. the range of gain value is [-120, 120], data type is floating. Please refer to the following figure:

    • Example

      {
          "project": "APC",
          "AUDIO_APC_DUMP": 1,
          "AUDIO_ANR_DUMP": 1,
          "AUDIO_EQ_DUMP": 1,
          "AUDIO_AGC_DUMP": 1,
          "AUDIO_DUMP_PATH": "./",
          "PRE_APC_GAIN": 10.0,
          "POST_APC_GAIN": -5.0
      }
      

    2.87. IaaEq_ReadJson

    • Features

      Configure Json parameters to Eq common setting

    • Syntax

      ALGO_EQ_RET IaaEq_ReadJson(EQ_HANDLE handle, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      handle Eq algorithm handle Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to the example section in IaaApc_SwitchReadFromJson.


    2.88. IaaAgc_ReadJson

    • Features

      Configure Json parameters to Agc common setting

    • Syntax

      ALGO_AGC_RET IaaAgc_ReadJson(AGC_HANDLE handle, char* jsonBuffer, char* jsonfile, unsigned int buffSize);
      
    • Parameters

      Parameter name Description Input/Output
      handle Agc algorithm handle Input/Output
      jsonBuffer The memory address used to parse the Json file content Input
      jsonfile Json file name Input
      buffSize The memory size required to parse the Json file content Input
    • Return value

      Return value Result
      0 Successful
      Non-zero Failed, refer to error code
    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Dependency

      • Header: AudioProcess.h

      • Library: libAPC_LINUX.so/ libAPC_LINUX.a

    • Example

      Please refer to the example section in IaaApc_SwitchReadFromJson.


    3. APC DATA TYPE


    3.1. APC data type list

    Data type Definition
    AudioApcBufferConfig The buffer configuration parameter structure type of the Apc algorithm
    AudioProcessInit Apc algorithm initialization parameter structure type
    APC_HANDLE Apc algorithm handle type
    AudioAnrConfig The Anr configuration parameter structure type of the Apc algorithm
    AudioEqConfig The Eq configuration parameter structure type of the Apc algorithm
    AudioHpfConfig The Hpf configuration parameter structure type of the Apc algorithm
    AudioAgcConfig The Agc configuration parameter structure type of the Apc algorithm
    AgcGainInfo Agc gain parameter structure type in Apc algorithm
    IAA_APC_SAMPLE_RATE Define the sampling rate type in the Apc algorithm
    NR_CONVERGE_SPEED Anr algorithm convergence speed type
    IAA_HPF_FREQ Hpf algorithm cut-off frequency type
    ANR_HANDLE Anr algorithm handle type
    EQ_HANDLE Eq algorithm handle type
    AGC_HANDLE Agc algorithm handle type
    APC_BF_HANDLE Define the BF handle type that cooperating with Apc algorithm
    EQ_FILTER_TYPE IIR filter type
    AudioFilterConfig The IIR configuration parameter structure type of the filter algorithm
    CngStruct The configuration parameter structure type of the comfort noise
    AudioApcOption Apc optional configuration structure

    3.2. AudioApcBufferConfig

    • Description

      Define the buffer configuration parameter structure type of the Apc algorithm.

    • Definition

      typedef struct{
      
          unsigned int anr_enable;
      
          unsigned int eq_enable;
      
          unsigned int dr_enable;
      
          unsigned int vad_enable;
      
          unsigned int agc_enable;
      
      }AudioApcBufferConfig;
      
    • Member

      Member name Description
      anr_enable The Anr enable option in the Apc algorithm is used to assist in calculating the memory size required for Apc algorithm running.
      eq_enable The Eq enable option in the Apc algorithm is used to assist in calculating the memory size required for Apc algorithm running.
      dr_enable Algorithm is being developed
      vad_enable Vad algorithm has established a separate module, Vad is currently disabled in APC, it is recommended to close
      agc_enable The Agc enable option in the Apc algorithm is used to assist in calculating the memory size required for Apc algorithm running.
    • Note

      None.

    • Related data types and interfaces

      IaaApc_GetBufferSize

      IaaApc_Init

      IaaApc_Reset


    3.3. AudioProcessInit

    • Description

      Define Apc(Anr/Eq/Hpf/Agc) algorithm initialization parameter structure type.

    • Definition

      typedef struct {
      
          unsigned int point_number;
      
          unsigned int channel;
      
          IAA_APC_SAMPLE_RATE sample_rate;
      
      }AudioProcessInit;
      
    • Member

      Member name Description
      point_number The amount of data processed by the algorithm once (that is, how many sampling points are in a frame), the value is 128 or 256(according to chip), and how many short values need to be given to Apc is determined by chip. Value range: 128 or 256
      channel The channel numbers of data. If it is a dual channel, the data given to Apc in each frame is twice the point_number.
      sample_rate Data sampling frequency
    • Related data types and interfaces

      IaaApc_Init

      IaaApc_Reset

      IaaApc_GetConfig

      IaaAnr_Init

      IaaAnr_Reset

      IaaAnr_GetConfig

      IaaEq_Init

      IaaEq_Reset

      IaaEq_GetConfig

      IaaAgc_Init

      IaaAgc_Reset

      IaaAgc_GetConfig


    3.4. APC_HANDLE


    3.5. AudioAnrConfig

    • Description

      Define the Anr configuration parameter structure type of the Apc algorithm.

    • Definition

      typedef struct{
      
          unsigned int anr_enable;
      
          unsigned int user_mode;
      
          int anr_intensity_band[6];
      
          int anr_intensity[7];
      
          unsigned int anr_smooth_level;
      
          NR_CONVERGE_SPEED anr_converge_speed;
      
          int anr_filter_mode;
      
      }AudioAnrConfig;
      
    • Member

      Member name Description
      anr_enable Whether to enable Anr algorithm
      user_mode Anr algorithm running mode
      anr_intensity_band Anr frequency range Range [1,128]; step size 1
      anr_intensity ANR intensity, the larger the value, the higher the ANR intensity, but at the same time it will also bring about the loss/damage of details. The recommended value is 10. Range [0,30]; step size 1
      anr_smooth_level Frequency domain smoothness Recommended value:10 Range [0,10]; step size 1
      anr_converge_speed Noise convergence speed Recommended value: NR_SPEED_MID Range [NR_SPEED_LOW;NR_SPEED_MID;NR_SPEED_HIGH]
      anr_filter_mode Frequency domain noise reduction filter Range [0,6]; step size 1
    • Note

      • When anr_enable is FALSE, other Anr parameters will not work;

      • user_mode specifies the running mode of Anr. 0, means that the Anr algorithm does not use other Anr parameters at all, but uses the internal settings of the Anr algorithm; 1 or 2 means that the Anr parameters under the application are completely used.

      • anr_intensity_band, ANR frequency range, the latter element must be greater than or equal to the first element.

        For example: u32NrIntensityBand[0]= 10, then: u32NrIntensityBand[1] must be greater than or equal to 10.

        The highest frequency corresponding to the current sampling rate is divided into 128 parts on average, and the frequency range corresponds to how many parts form a frequency band.

        For example: the current sampling rate is 16K, the corresponding maximum frequency is 8K, each one is 8000 / 128 ≈ 62.5Hz. Under the setting of {4,6,36, 49,50,51}, the ANR frequency range is {0 ~ 4 * 62.5Hz, 4 ~ 6 * 62.5Hz, 6 ~ 36 * 62.5Hz, 36 ~ 49 * 62.5Hz, 49 ~ 50 * 62.5Hz, 50 ~ 51 * 62.5Hz, 51-127 * 62.5Hz} = {0 ~ 250Hz, 250 ~ 375Hz, 375 ~ 2250Hz, 2250 ~ 3062.5Hz, 3062.5 ~ 3125Hz, 3125 ~ 3187.5Hz, 3187.5Hz ~ 8000Hz}, anr_intensity is the Anr intensity, According to the frequency band division of anr_intensity_band, different parameters are set for the noise situation of each frequency band.

      • anr_smooth_level, the smoothness of Anr algorithm the frequency domain procession, avoid excessively large suppression gaps between adjacent frequencies during noise estimation, resulting in sound damage.

      • anr_converge_speed, Anr algorithm convergence speed, noise update speed, the faster the setting, the faster the Anr will converge, but the details will be lost/damaged.

      • anr_filter_mode specifies the Anr algorithm. 0 is the original Anr algorithm. 1 ~ 4 Anr algorithms are based on different noise estimation approaches. 5 Anr algorithm is deep-learning based noise reduction algorithm. 6 Anr algorithm is IPU based deep-learning algorithm.

      • When using anr_filter_mode 5, the anr_converge_speed must be set as NR_SPEED_MID or NR_SPEED_HIGH. In addition, anr_smooth_level will not affect the results of using anr_filter_mode 5.

      • When using anr_filter_mode 5 and the anr_converge_speed is NR_SPEED_MID, it will reduce the cpu loading effectively(most half), but the trade off is less noise suppress effect and lower converge speed.

      • anr_filter_mode 5 has two version. Version 5 are focus on wideband scenario from 0kHz to 8kHz, supporting 8kHz, 16kHz and 32kHz sampling rate and 128 point number. Version 3 is designed for superwideband scenario from 0kHz to 16kHz and only support 32kHz sampling rate and 256 point number. The latest anr_filter_mode 5 version 5 is recommended. The anr_filter_mode version can be checked by following command to APC or ANR library.

         strings libAPC_LINUX.a | grep ALGO 

      • When using anr_filter_mode 6, anr_smooth_level will not affect the results.

      • When using anr_filter_mode 6, The recommended setting for anr_converge_speed is NR_SPEED_HIGH.

    • Related data types and interfaces

      IaaApc_Config

      IaaApc_GetConfig

      IaaAnr_Config

      IaaAnr_GetConfig

      NR_CONVERGE_SPEED


    3.6. AudioEqConfig

    • Description

      Define the Eq configuration parameter structure type of the Apc algorithm.

    • Definition

      typedef struct{
      
          unsigned int eq_enable;
      
          unsigned int user_mode;
      
          short eq_gain_db[129];
      
      }AudioEqConfig;
      
    • Member

      Member name Description
      eq_enable Whether to enable Eq algorithm
      user_mode Eq algorithm running mode
      eq_gain_db Eq algorithm gain adjustment value, divide the frequency range of the current sampling rate into 129 frequency ranges for adjustment. Unit: 1dB Range [-100,20]; step size 1
    • Note

      • When eq_enable is FALSE, other Eq parameters will not work;

      • user_mode specifies the running mode of Eq. 0, means Eq uses the preset parameters which are all 0, without any gain or attenuation; 1 means that the Eq parameters under the application are completely used.

      • eq_gain_db is the table for gain adjustment, divide the frequency range of the current sampling rate into 129 frequency ranges for adjustment. For example: the current sampling rate is 16K, the corresponding highest frequency is 8K, 8000 / 129 ≈ 62Hz, the frequency range of a single adjustment is 62Hz, and 0-8K is divided into {0-1 * 62Hz, 1-2 * 62Hz, 2-3 * 62Hz, …, 128-129 * 62Hz} = {0-62Hz, 62-124Hz, 124-186Hz, … ,7938-8000Hz}, each segment corresponds to a gain value.

    • Related data types and interfaces

      IaaApc_Config

      IaaApc_GetConfig

      IaaEq_Config

      IaaEq_GetConfig


    3.7. AudioHpfConfig

    • Description

      Define the Hpf configuration parameter structure type of the Apc algorithm.

    • Definition

      typedef struct{
      
          unsigned int hpf_enable;
      
          unsigned int user_mode;
      
          IAA_HPF_FREQ cutoff_frequency;
      
      }AudioHpfConfig;
      
    • Member

      Member name Description
      hpf_enable Whether to enable Hpf algorithm
      user_mode The running mode of the Hpf algorithm, setting 1 is the frequency domain processing mode, and setting 2 is the time domain processing mode
      cutoff_frequency Hpf cutoff frequency Range: [0,1,2,3,4]
    • Note

      • When hpf_enable is FALSE, other Hpf parameters will not work;

      • user_mode specifies the running mode of Hpf. 0, represents the preset parameters without any attenuation; 1, represents the application of the Hpf parameters set by the user, the Hpf algorithm is applied in the frequency domain, and the internal algorithm connection process of APC is ANR → EQ/HPF → AGC; 2, represents applying the Hpf parameters set by the user. The Hpf algorithm is applied in the time domain. The internal algorithm connection process of APC is HPF → ANR → EQ → AGC.

      • cutoff_frequency is the cutoff frequency of Hpf. Signals below this frequency will be filtered out.

      • If you only need to use the Hpf algorithm, hpf_enable is TRUE, and eq_enable in AudioEqConfig is set to FALSE. Please also set eq_enable in AudioApcBufferConfig to TRUE so that the system can get the correct memory size required to run the algorithm through IaaApc_GetBufferSize.

    • Related data types and interfaces

      IaaApc_Config

      IaaApc_GetConfig

      IaaEq_Config

      IaaEq_GetConfig


    3.8. AudioAgcConfig

    • Description

      Define the Agc configuration parameter structure type of the Apc algorithm.

    • Definition

      typedef struct
      
      {
      
          unsigned int agc_enable;
      
          unsigned int user_mode;
      
          //gain setting
      
          AgcGainInfo gain_info;
      
          unsigned int drop_gain_max;
      
          //attack time, release time
      
          unsigned int attack_time;
      
          unsigned int release_time;
      
          //target level
      
          short compression_ratio_input[7];
      
          short compression_ratio_output[7];
      
          int drop_gain_threshold;
      
          // noise gate
      
          int noise_gate_db;
      
          unsigned int noise_gate_attenuation_db;
      
          unsigned int gain_step;
      
      }AudioAgcConfig;
      
    • Member

      Member name Description
      agc_enable Whether to enable Agc algorithm
      user_mode Agc algorithm running mode. This value is set to 1 for time domain Agc process. and it is set to 2 for frequency domain Agc process.
      gain_info The Agc algorithm gain information, which defines the maximum, minimum and initial values of the AGC gain
      drop_gain_max The maximum value of instantaneous gain drop, prevent output saturation. If the output plus the current Gain exceeds the dB value set by drop_gain_threshold, Agc will instantly reduce the Gain to prevent the peak value of the current signal from exceeding drop_gain_threshold. Range: [0,120]; Step size: 1 Note:This value only represents the range that can be lowered, but the specific value that can be lowered depends on the minimum value of the AGC gain.
      attack_time Time step for gain reduction, take 4 milliseconds as 1 unit, if set to 2, it will judge whether to increase Gain every 8 milliseconds. Range: [1,99]; step size: 1
      release_time Time step for gain increase, take 4 milliseconds as 1 unit, if set to 2, it will judge whether to increase Gain every 8 milliseconds Range: [1,99]; step size: 1
      compression_ratio_input Use with compression_ratio_output, realize the curve with multiple slopes through multiple turning points to get the relationship between input power level and output power level. Range: [-120,0]dBFS; step size: 1
      compression_ratio_output Use with compression_ratio_input, realize the curve with multiple slopes through multiple turning points to get the relationship between input power level and output power level. Range: [-120,0]dBFS; step size: 1
      drop_gain_threshold Attenuation threshold, When the signal peak amplitude exceeds this value, it will attenuate instantly, and the attenuation amplitude is limited by drop_gain_max and gain_info. Range: [-120,0]dB; step size: 1
      noise_gate_db Noise threshold, when the signal is less than this value, treat it as noise. Case1: If you set noise_gate_db from -80 to 0, the current gain value will converge to 0 according to the release/attack time. Case2: If you set noise_gate_db from 1 to 80, when the signal is less than this value, the Gain value will not be changed, and keep the Gain value of the previous frame Range: [-120,120] ; step size: 1
      noise_gate_attenuation_db When the noise threshold is effective, it is input source attenuation percentage. Range: [0,100] ; step size: 1
      gain_step The speed of applying gain is 0.5dB as a unit. If it is set to 1, then ±0.5dB is applied per frame according to requirements. The higher the value, the faster the speed of increasing and decreasing the volume. Range: [1,10] ; step size: 1
    • Note

      • When agc_enable is FALSE, other Agc parameters will not work;

      • user_mode specifies the running mode of Agc. 0, means that the Agc algorithm does not use other Agc parameters at all, but uses the internal settings of the Agc algorithm; 1 means that the Agc parameters under the application are completely used.

      • Compression ratio Curve defines the relationship between InputOutput energy. By setting seven points, six different slope transitions can be obtained. For example, the parameters are set as follows:

        compression_ratio_input[7] = {-80, -60, -50,-40,-30,-12,0}
        
        compression_ratio_output[7] = {-80, -45, -36, -27, -18, -9, -6}
        

        The curve is shown in the figure below.

        If you don't need so many different slopes, you can set the last compression ratio parameter to 0, as follows:

        compression_ratio_input[7] = {-70, -60, -30, 0,0,0,0};
        
        compression_ratio_output[7] = {-60, -50, -10, -3, 0,0,0};
        

      • There are two modes for the noise gate setting, which can converge Gain to 0 or keep it unchanged. Convergence to 0 can prevent signals smaller than the noise gate from being amplified, maintain noise stability, and maintain the Gain value unchanged to avoid the "breathing phenomenon" where the beginning and end of the voice disappear.

      • If user set user mode to 2, frequency domain Agc process enable. Please refer to the following API and call following API when user use frequency domain Agc.

        IaaApc_SetLowFreqCompressionRatioCurve

        IaaApc_SetMidFreqCompressionRatioCurve

        IaaApc_SetHighFreqCompressionRatioCurve

        IaaApc_SetAgcFreqBand

        IaaAgc_SetLowFreqCompressionRatioCurve

        IaaAgc_SetMidFreqCompressionRatioCurve

        IaaAgc_SetHighFreqCompressionRatioCurve

        IaaAgc_SetAgcFreqBand

    • Related data types and interfaces

      IaaApc_Config

      IaaApc_GetConfig

      IaaAgc_Config

      IaaAgc_GetConfig


    3.9. AgcGainInfo

    • Description

      Define Agc gain parameter structure type in Apc algorithm.

    • Definition

      typedef struct
      
      {
      
          int gain_max; //gain maximum
      
          int gain_min; //gain minimum
      
          int gain_init; //default gain (initial gain)
      
      }AgcGainInfo;
      
    • Member

      Member name Description
      gain_max Maximum gain Range: [-120,100]; step size: 1
      gain_min Minimum gain Range: [-120,100] ; step size: 1
      gain_init Gain initial value Range: [-100,100] ; step size: 1
    • Note

      None.

    • Related data types and interfaces

      AudioAgcConfig


    3.10. IAA_APC_SAMPLE_RATE

    • Description

      Define the sampling rate type in the Apc algorithm.

    • Definition

      typedef enum {
      
          IAA_APC_SAMPLE_RATE_8000 = 8000 ,
      
          IAA_APC_SAMPLE_RATE_16000 = 16000 ,
      
          IAA_APC_SAMPLE_RATE_32000 = 32000 ,
      
          IAA_APC_SAMPLE_RATE_48000 = 48000 ,
      
      }IAA_APC_SAMPLE_RATE;
      
    • Member

      Member name Description
      IAA_APC_SAMPLE_RATE_8000 8K sampling rate
      IAA_APC_SAMPLE_RATE_16000 16K sampling rate
      IAA_APC_SAMPLE_RATE_32000 32K sampling rate
      IAA_APC_SAMPLE_RATE_48000 48K sampling rate
    • Note

      None.

    • Related data types and interfaces

      AudioProcessInit


    3.11. NR_CONVERGE_SPEED

    • Description

      Define Anr algorithm convergence speed type.

    • Definition

      typedef enum {
      
          NR_SPEED_LOW,
      
          NR_SPEED_MID,
      
          NR_SPEED_HIGH
      
      } NR_CONVERGE_SPEED;
      
    • Member

      Member name Description
      NR_SPEED_LOW Low speed
      NR_SPEED_MID Medium speed
      NR_SPEED_HIGH High speed
    • Note

      • Low/medium/high NR convergence speed represents 3/2/1 frame update once noise suppression
    • Related data types and interfaces

      AudioAnrConfig


    3.12. IAA_HPF_FREQ

    • Description

      Define Hpf algorithm cut-off frequency type.

    • Definition

      typedef enum {
      
          AUDIO_HPF_FREQ_80 , /* 80Hz*/
      
          AUDIO_HPF_FREQ_120, /*120Hz*/
      
          AUDIO_HPF_FREQ_150, /*150Hz*/
      
          AUDIO_HPF_FREQ_500, /*500Hz*/
      
          AUDIO_HPF_FREQ_BUTT,
      
      }IAA_HPF_FREQ;
      
    • Member

      Member name Description
      AUDIO_HPF_FREQ_80 80Hz
      AUDIO_HPF_FREQ_120 120Hz
      AUDIO_HPF_FREQ_150 150Hz
      AUDIO_HPF_FREQ_500 500Hz
      AUDIO_HPF_FREQ_BUTT
    • Related data types and interfaces

      AudioHpfConfig


    3.13. ANR_HANDLE


    3.14. EQ_HANDLE


    3.15. AGC_HANDLE


    3.16. APC_BF_HANDLE

    • Description

      Define the BF handle type that cooperating with Apc algorithm.

    • Definition

      typedef void* APC_BF_HANDLE;
      
    • Related data types and interfaces

      IaaApc_EnhanceNNBFMode

    • Note

      • This handle is only applicable to special enhancement that using BF mode as 3 and anr_filter_mode as 5 simultaneously. It won't affect the results of using other modes.

    3.17. EQ_FILTER_TYPE

    • Description

      Define IIR filter type.

    • Definition

      typedef enum {
      
          EQ_NOTCH_FILTER ,
      
          EQ_HIGH_PASS_FILTER,
      
          EQ_LOW_PASS_FILTER,
      
      }EQ_FILTER_TYPE;
      
    • Member

      Member name Description
      EQ_NOTCH_FILTER Notch filter
      EQ_HIGH_PASS_FILTER High pass filter
      EQ_LOW_PASS_FILTER Low pass filter
    • Related data types and interfaces

      AudioFilterConfig


    3.18. AudioFilterConfig

    • Description

      Define IIR filter parameter structure type in filter algorithm.

    • Definition

      typedef struct{
      
          EQ_FILTER_TYPE type;
      
          int f0;
      
          int q_factor;
      
          int gain;
      
      }AudioFilterConfig;
      
    • Member

      Member name Description
      type Filter type by EQ_FILTER_TYPE
      f0 Fitler center frequency
      q_fctor Q factor
      gain Gain value
    • Related data types and interfaces

      EQ_FILTER_TYPE

    • Note

      • type

        There are three types, notch filter/high-pass filter/low-pass filter, the following figures is the typical frequency response of three types of filter. 1. Notch fitler is for specific frequency suppression. 2. High-pass filter is the suppression of band below a specific frequency. 3. Low-pass filter is the suppression of band above a specific frequency.

      • f0

        f0 is transition frequency for HPF and LPF, the bend in the frequency response curve. That is the -3dB frequency point.

        And for notch filter, f0 is center frequency. Please refer to the following figure.

      • q_factor

        Q is quality factor. The formula of q factor is as following. f_0, f_1 and f_2 Please refer to the above figure. Q=\frac{f_0}{f_2-f_1}

      • gain

        This is steady state gain of HPF and LPF, and for notch filter, gain represent peak value.

        filter_design.q_factor = 1;
        
        filter_design.f0 = 2000;
        
        filter_design.type = EQ_HIGH_PASS_FILTER;
        
        filter_design.gain = 3;
        

        The frequency response is as following

        filter_design.q_factor = 1;
        
        filter_design.f0 = 2000;
        
        filter_design.type = EQ_NOTCH_FILTER;
        
        filter_design.gain = 3;
        

        The frequency response is as following


    3.19. CngStruct

    • Description

      The structure of comfort noise configuration.

    • Definition

      typedef struct
      {
          int energy_dbfs;
      
          short point_number;
      
          int channel_num;
      
      }CngStruct;
      
    • Member

      Member name Description
      energy_dbfs specified power of comfort noise
      point_number input data frame length
      channel_num input data channel number
    • Note

      If the channel number is stereo, user should permutate the data following the sequence of left/right/left/right...


    3.20. AudioApcOption


    4. Error code

    APC API error codes are shown as follow:

    Error code Definition Description
    0x00000000 ALGO_APC_RET_SUCCESS APC run successful
    0x10000501 ALGO_APC_RET_INIT_ERROR APC not initialized
    0x10000502 ALGO_APC_RET_INVALID_HANDLE HANDLE invalid
    0x10000503 ALGO_APC_RET_INVALID_SAMPLE_RATE Sampling frequency is not supported
    0x10000504 ALGO_APC_RET_INVALID_POINT_NUMBER Points per frame not supported
    0x10000505 ALGO_APC_RET_INVALID_CHANNEL Channel number doesn't support
    0x10000506 ALGO_APC_ANR_RET_INVALID_ENABLE ANR switch parameter setting is invalid
    0x10000507 ALGO_APC_ANR_RET_INVALID_MODE ANR mode parameter setting is invalid
    0x10000508 ALGO_APC_ANR_RET_INVALID_INTENSITY ANR intensive parameter setting is invalid
    0x10000509 ALGO_APC_ANR_RET_INVALID_SMOOTH_LEVEL ANR smoothing parameter setting is invalid
    0x10000510 ALGO_APC_ANR_RET_INVALID_COVERGE_SPEED ANR convergence rate parameter setting is invalid
    0x10000511 ALGO_APC_EQ_RET_INVALID_ENABLE EQ switch parameter setting is invalid
    0x10000512 ALGO_APC_EQ_RET_INVALID_MODE EQ mode parameter setting is invalid
    0x10000513 ALGO_APC_EQ_RET_INVALID_TABLE EQ parameter setting is invalid
    0x10000514 ALGO_APC_HPF_RET_INVALID_ENABLE HPF switch parameter setting is invalid
    0x10000515 ALGO_APC_HPF_RET_INVALID_MODE HPF mode parameter setting is invalid
    0x10000516 ALGO_APC_HPF_RET_INVALID_TABLE HPF parameter setting is invalid
    0x10000517 ALGO_APC_AGC_RET_INVALID_ENABLE AGC switch parameter setting is invalid
    0x10000518 ALGO_APC_AGC_RET_INVALID_MODE AGC mode parameter setting is invalid
    0x10000519 ALGO_APC_AGC_RET_INVALID_COMPRESSION_RATIO AGC compression curve parameter setting is invalid
    0x10000520 ALGO_APC_AGC_RET_INVALID_FREQUENCY_BAND AGC frequency band setting is invalid
    0x10000521 ALGO_APC_AGC_RET_INVALID_DROP_GAIN_MAX AGC anti-saturation parameter setting is invalid
    0x10000522 ALGO_APC_AGC_RET_INVALID_GAIN_STEP AGC gain step parameter setting is invalid
    0x10000523 ALGO_APC_AGC_RET_INVALID_RELEASE_TIME AGC recovery time parameter setting is invalid
    0x10000524 ALGO_APC_AGC_RET_INVALID_ATTACK_TIME AGC subtracted time parameter setting is invalid
    0x10000525 ALGO_APC_AGC_RET_INVALID_NOISE_GATE AGC noise threshold parameter setting is invalid
    0x10000526 ALGO_APC_AGC_RET_INVALID_NOISE_ATTENU AGC noise attenuation setting is invalid
    0x10000527 ALGO_APC_AGC_RET_INVALID_DROP_GAIN_LEVEL AGC anti-saturation threshold parameter setting is invalid
    0x10000528 ALGO_APC_AGC_RET_INVALID_GAIN_INFO AGC gain control parameter setting is invalid
    0x10000529 ALGO_APC_RET_API_CONFLICT Other APIs are running
    0x10000530 ALGO_APC_RET_INVALID_CALLING Incorrect order of calling API
    0x10000531 ALGO_APC_RET_FAILED Parameter setting error