⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vad1.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Function     : hangover_addition Purpose      : Add hangover for complex signal or after speech bursts Inputs       : burst_count:  counter for the length of speech bursts                hang_count:   hangover counter                vadreg:       intermediate VAD decision Outputs      : burst_count:  counter for the length of speech bursts                hang_count:   hangover counter Return value : VAD_flag indicating final VAD decision------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable                used to represent cycle count for each subroutine                called)     where: (cycle count variable) = cycle count for [subroutine                                     name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/static Word16 hangover_addition(    vadState1 *st,      /* i/o : State struct                     */    Word16 noise_level, /* i   : average level of the noise       */    /*       estimates                        */    Word16 low_power,   /* i   : flag power of the input frame    */    Flag  *pOverflow    /* o   : Flag set when overflow occurs    */){    Word16 hang_len;    Word16 burst_len;    /*       Calculate burst_len and hang_len       burst_len: number of consecutive intermediate vad flags with "1"-decision                  required for hangover addition       hang_len:  length of the hangover       */    if (noise_level > HANG_NOISE_THR)    {        burst_len = BURST_LEN_HIGH_NOISE;        hang_len = HANG_LEN_HIGH_NOISE;    }    else    {        burst_len = BURST_LEN_LOW_NOISE;        hang_len = HANG_LEN_LOW_NOISE;    }    /* if the input power (pow_sum) is lower than a threshold, clear       counters and set VAD_flag to "0"  "fast exit"                 */    if (low_power != 0)    {        st->burst_count = 0;        st->hang_count = 0;        st->complex_hang_count = 0;        st->complex_hang_timer = 0;        return 0;    }    if (st->complex_hang_timer > CVAD_HANG_LIMIT)    {        if (st->complex_hang_count < CVAD_HANG_LENGTH)        {            st->complex_hang_count = CVAD_HANG_LENGTH;        }    }    /* long time very complex signal override VAD output function */    if (st->complex_hang_count != 0)    {        st->burst_count = BURST_LEN_HIGH_NOISE;        st->complex_hang_count = sub(st->complex_hang_count, 1, pOverflow);        return 1;    }    else    {        /* let hp_corr work in from a noise_period indicated by the VAD */        if (((st->vadreg & 0x3ff0) == 0) &&                (st->corr_hp_fast > CVAD_THRESH_IN_NOISE))        {            return 1;        }    }    /* update the counters (hang_count, burst_count) */    if ((st->vadreg & 0x4000) != 0)    {        st->burst_count = add(st->burst_count, 1, pOverflow);        if (st->burst_count >= burst_len)        {            st->hang_count = hang_len;        }        return 1;    }    else    {        st->burst_count = 0;        if (st->hang_count > 0)        {            st->hang_count = sub(st->hang_count, 1, pOverflow);            return 1;        }    }    return 0;}/*------------------------------------------------------------------------------ FUNCTION NAME: noise_estimate_update------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st -- pointer to type vadState1 --  State struct    level -- array of type Word16 -- sub-band levels of the input frame Outputs:    st -- pointer to type vadState1 --  State struct    pOverflow -- pointer to type Flag -- overflow indicator Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose    : Update of background noise estimate Inputs     : bckr_est:   background noise estimate              pitch:      flags for pitch detection              stat_count: stationary counter Outputs    : bckr_est:   background noise estimate------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable                used to represent cycle count for each subroutine                called)     where: (cycle count variable) = cycle count for [subroutine                                     name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/static void noise_estimate_update(    vadState1 *st,    /* i/o : State struct                       */    Word16 level[],   /* i   : sub-band levels of the input frame */    Flag  *pOverflow  /* o : Flag set when overflow occurs        */){    Word16 i;    Word16 alpha_up;    Word16 alpha_down;    Word16 bckr_add;    /* Control update of bckr_est[] */    update_cntrl(st, level, pOverflow);    /* Choose update speed */    bckr_add = 2;    if (((0x7800 & st->vadreg) == 0) &&            ((st->pitch & 0x7800) == 0)            && (st->complex_hang_count == 0))    {        alpha_up = ALPHA_UP1;        alpha_down = ALPHA_DOWN1;    }    else    {        if ((st->stat_count == 0)                && (st->complex_hang_count == 0))        {            alpha_up = ALPHA_UP2;            alpha_down = ALPHA_DOWN2;        }        else        {            alpha_up = 0;            alpha_down = ALPHA3;            bckr_add = 0;        }    }    /* Update noise estimate (bckr_est) */    for (i = 0; i < COMPLEN; i++)    {        Word16 temp;        temp = sub(st->old_level[i], st->bckr_est[i], pOverflow);        if (temp < 0)        { /* update downwards*/            temp = mult_r(alpha_down, temp, pOverflow);            temp = add(st->bckr_est[i], temp, pOverflow);            st->bckr_est[i] = add(-2, temp, pOverflow);            /* limit minimum value of the noise estimate to NOISE_MIN */            if (st->bckr_est[i] < NOISE_MIN)            {                st->bckr_est[i] = NOISE_MIN;            }        }        else        { /* update upwards */            temp = mult_r(alpha_up, temp, pOverflow);            temp = add(st->bckr_est[i], temp, pOverflow);            st->bckr_est[i] = add(bckr_add, temp, pOverflow);            /* limit maximum value of the noise estimate to NOISE_MAX */            if (st->bckr_est[i] > NOISE_MAX)            {                st->bckr_est[i] = NOISE_MAX;            }        }    }    /* Update signal levels of the previous frame (old_level) */    for (i = 0; i < COMPLEN; i++)    {        st->old_level[i] = level[i];    }}/*------------------------------------------------------------------------------ FUNCTION NAME: complex_estimate_adapt------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st -- pointer to type vadState1 --  State struct    low_power -- Word16 -- very low level flag of the input frame Outputs:    st -- pointer to type vadState1 --  State struct    pOverflow -- pointer to type Flag -- overflow indicator Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Function   : complex_estimate_adapt Purpose    : Update/adapt of complex signal estimate Inputs     : low_power:   low signal power flag Outputs    : st->corr_hp_fast:   long term complex signal estimate------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES vad1.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODE------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable                used to represent cycle count for each subroutine                called)     where: (cycle count variable) = cycle count for [subroutine                                     name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/static void complex_estimate_adapt(    vadState1 *st,      /* i/o : VAD state struct                       */    Word16 low_power,   /* i   : very low level flag of the input frame */    Flag  *pOverflow    /* o : Flag set when overflow occurs            */){    Word16 alpha;            /* Q15 */    Word32 L_tmp;            /* Q31 */    /* adapt speed on own state */    if (st->best_corr_hp < st->corr_hp_fast) /* decrease */    {        if (st->corr_hp_fast < CVAD_THRESH_ADAPT_HIGH)        {  /* low state  */            alpha = CVAD_ADAPT_FAST;        }        else        {  /* high state */            alpha = CVAD_ADAPT_REALLY_FAST;        }    }    else  /* increase */    {        if (st->corr_hp_fast < CVAD_THRESH_ADAPT_HIGH)        {            alpha = CVAD_ADAPT_FAST;        }        else        {            alpha = CVAD_ADAPT_SLOW;        }    }    L_tmp = L_deposit_h(st->corr_hp_fast);    L_tmp = L_msu(L_tmp, alpha, st->corr_hp_fast, pOverflow);    L_tmp = L_mac(L_tmp, alpha, st->best_corr_hp, pOverflow);    st->corr_hp_fast = pv_round(L_tmp, pOverflow);           /* Q15 */    if (st->corr_hp_fast < CVAD_MIN_CORR)    {        st->corr_hp_fast = CVAD_MIN_CORR;    }    if (low_power != 0)    {        st->corr_hp_fast = CVAD_MIN_CORR;    }}/*------------------------------------------------------------------------------ FUNCTION NAME: complex_vad------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st -- pointer to type vadState1 --  State struct    low_power -- Word16 -- flag power of the input frame Outputs:    st -- pointer to type vadState1 --  State struct    pOverflow -- pointer to type Flag -- overflow indicator Returns:    the complex background decision Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION Purpose      : complex background decision Return value : the complex background decision

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -