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

📄 pitch_fr.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        /* Normalize correlation = correlation * (1/sqrt(energy)) */        s = Mpy_32(corr_h, corr_l, norm_h, norm_l, pOverflow);        corr_norm[i] = (Word16) s ;        /* modify the filtered excitation excf[] for the next iteration */        if (i != t_max)        {            k--;            temp = exc[k];            p_s_excf = &s_excf[L_subfr - 1];            p_h = &h[L_subfr - 1];            p_excf = &s_excf[L_subfr - 2];            for (j = (L_subfr - 1) >> 1; j != 0; j--)            {                s = ((Word32) temp * *(p_h--)) >> h_fac;                *(p_s_excf--) = (Word16) s  + *(p_excf--);                s = ((Word32) temp * *(p_h--)) >> h_fac;                *(p_s_excf--) = (Word16) s  + *(p_excf--);            }            s = ((Word32) temp * *(p_h)) >> h_fac;            *(p_s_excf--) = (Word16) s  + *(p_excf);            *(p_s_excf) = temp >> scaling;        }    }    return;}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: searchFrac------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    lag = pointer to integer pitch of type Word16    frac = pointer to starting point of search fractional pitch of type Word16    last_frac = endpoint of search  of type Word16    corr[] = pointer to normalized correlation of type Word16    flag3 = subsample resolution (3: =1 / 6: =0) of type Word16 Outputs:    None Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION   FUNCTION:   searchFrac()   PURPOSE: Find fractional pitch   DESCRIPTION:      The function interpolates the normalized correlation at the      fractional positions around lag T0. The position at which the      interpolation function reaches its maximum is the fractional pitch.      Starting point of the search is frac, end point is last_frac.      frac is overwritten with the fractional pitch.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEstatic void searchFrac (    Word16 *lag,       // i/o : integer pitch    Word16 *frac,      // i/o : start point of search -                               fractional pitch    Word16 last_frac,  // i   : endpoint of search    Word16 corr[],     // i   : normalized correlation    Word16 flag3       // i   : subsample resolution                                (3: =1 / 6: =0)){    Word16 i;    Word16 max;    Word16 corr_int;    // Test the fractions around T0 and choose the one which maximizes    // the interpolated normalized correlation.    max = Interpol_3or6 (&corr[*lag], *frac, flag3); // function result    for (i = add (*frac, 1); i <= last_frac; i++) {        corr_int = Interpol_3or6 (&corr[*lag], i, flag3);        if (sub (corr_int, max) > 0) {            max = corr_int;            *frac = i;        }    }    if (flag3 == 0) {        // Limit the fraction value in the interval [-2,-1,0,1,2,3]        if (sub (*frac, -3) == 0) {            *frac = 3;            *lag = sub (*lag, 1);        }    }    else {        // limit the fraction value between -1 and 1        if (sub (*frac, -2) == 0) {            *frac = 1;            *lag = sub (*lag, 1);        }        if (sub (*frac, 2) == 0) {            *frac = -1;            *lag = add (*lag, 1);        }    }}------------------------------------------------------------------------------ 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 searchFrac(    Word16 *lag,       /* i/o : integer pitch           */    Word16 *frac,      /* i/o : start point of search -                                fractional pitch        */    Word16 last_frac,  /* i   : endpoint of search      */    Word16 corr[],     /* i   : normalized correlation  */    Word16 flag3,      /* i   : subsample resolution                                (3: =1 / 6: =0)         */    Flag   *pOverflow){    Word16 i;    Word16 max;    Word16 corr_int;    /* Test the fractions around T0 and choose the one which maximizes   */    /* the interpolated normalized correlation.                          */    max = Interpol_3or6(&corr[*lag], *frac, flag3, pOverflow);    /* function result */    for (i = *frac + 1; i <= last_frac; i++)    {        corr_int = Interpol_3or6(&corr[*lag], i, flag3, pOverflow);        if (corr_int > max)        {            max = corr_int;            *frac = i;        }    }    if (flag3 == 0)    {        /* Limit the fraction value in the interval [-2,-1,0,1,2,3] */        if (*frac == -3)        {            *frac = 3;            (*lag)--;        }    }    else    {        /* limit the fraction value between -1 and 1 */        if (*frac == -2)        {            *frac = 1;            (*lag)--;        }        if (*frac == 2)        {            *frac = -1;            (*lag)++;        }    }}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: getRange------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    T0 = integer pitch of type Word16    delta_low = search start offset of type Word16    delta_range = search range of type Word16    pitmin = minimum pitch of type Word16    pitmax = maximum pitch of type Word16    t0_min = search range minimum of type Word16    t0_max = search range maximum of type Word16 Outputs:    pOverflow = 1 if the math functions called result in overflow else zero. Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION   FUNCTION:   getRange()   PURPOSE: Sets range around open-loop pitch or integer pitch of last subframe   DESCRIPTION:      Takes integer pitch T0 and calculates a range around it with        t0_min = T0-delta_low  and t0_max = (T0-delta_low) + delta_range      t0_min and t0_max are bounded by pitmin and pitmax------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEstatic void getRange (    Word16 T0,           // i : integer pitch    Word16 delta_low,    // i : search start offset    Word16 delta_range,  // i : search range    Word16 pitmin,       // i : minimum pitch    Word16 pitmax,       // i : maximum pitch    Word16 *t0_min,      // o : search range minimum    Word16 *t0_max)      // o : search range maximum{    *t0_min = sub(T0, delta_low);    if (sub(*t0_min, pitmin) < 0) {        *t0_min = pitmin;    }    *t0_max = add(*t0_min, delta_range);    if (sub(*t0_max, pitmax) > 0) {        *t0_max = pitmax;        *t0_min = sub(*t0_max, delta_range);    }}------------------------------------------------------------------------------ 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 getRange(    Word16 T0,           /* i : integer pitch          */    Word16 delta_low,    /* i : search start offset    */    Word16 delta_range,  /* i : search range           */    Word16 pitmin,       /* i : minimum pitch          */    Word16 pitmax,       /* i : maximum pitch          */    Word16 *t0_min,      /* o : search range minimum   */    Word16 *t0_max,      /* o : search range maximum   */    Flag   *pOverflow){    Word16 temp;    OSCL_UNUSED_ARG(pOverflow);    temp = *t0_min;    temp = T0 - delta_low;    if (temp < pitmin)    {        temp = pitmin;    }    *t0_min = temp;    temp +=  delta_range;    if (temp > pitmax)    {        temp = pitmax;        *t0_min = pitmax - delta_range;    }    *t0_max = temp;}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: Pitch_fr_init------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    state = pointer to a pointer of structure type Pitch_fr_State. Outputs:    None Returns:    Returns a zero if successful and -1 if not successful. Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION  Function:   Pitch_fr_init  Purpose:    Allocates state memory and initializes state memory------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint Pitch_fr_init (Pitch_frState **state){    Pitch_frState* s;    if (state == (Pitch_frState **) NULL){        // fprintf(stderr, "Pitch_fr_init: invalid parameter\n");        return -1;    }    *state = NULL;    // allocate memory    if ((s= (Pitch_frState *) malloc(sizeof(Pitch_frState))) == NULL){        // fprintf(stderr, "Pitch_fr_init: can not malloc state structure\n");

⌨️ 快捷键说明

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