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

📄 pitch_fr.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        return -1;    }    Pitch_fr_reset(s);    *state = s;    return 0;}------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/Word16 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 *) oscl_malloc(sizeof(Pitch_frState))) == NULL)    {        /* fprintf(stderr, "Pitch_fr_init: can not malloc state structure\n"); */        return -1;    }    Pitch_fr_reset(s);    *state = s;    return 0;}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: Pitch_fr_reset------------------------------------------------------------------------------ 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_reset  Purpose:    Initializes state memory to zero------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint Pitch_fr_reset (Pitch_frState *state){    if (state == (Pitch_frState *) NULL){        // fprintf(stderr, "Pitch_fr_reset: invalid parameter\n");        return -1;    }    state->T0_prev_subframe = 0;    return 0;}------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/Word16 Pitch_fr_reset(Pitch_frState *state){    if (state == (Pitch_frState *) NULL)    {        /* fprintf(stderr, "Pitch_fr_reset: invalid parameter\n"); */        return -1;    }    state->T0_prev_subframe = 0;    return 0;}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: Pitch_fr_exit------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    state = pointer to a pointer of structure type Pitch_fr_State. Outputs:    None Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION  Function:   Pitch_fr_exit  Purpose:    The memory for state is freed.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEvoid Pitch_fr_exit (Pitch_frState **state){    if (state == NULL || *state == NULL)        return;    // deallocate memory    free(*state);    *state = NULL;    return;}------------------------------------------------------------------------------ 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]------------------------------------------------------------------------------*/void Pitch_fr_exit(Pitch_frState **state){    if (state == NULL || *state == NULL)        return;    /* deallocate memory */    oscl_free(*state);    *state = NULL;    return;}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: Pitch_fr------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to stat structure of type Pitch_frState    mode = codec mode of type enum Mode    T_op[] = pointer to open loop pitch lags of type Word16    exc[] = pointer to excitation buffer of type Word16    xn[] = pointer to target vector of type Word16    h[] = pointer to impulse response of synthesis and weighting filters          of type Word16    L_subfr = length of subframe of type Word16    i_subfr = subframe offset of type Word16 Outputs:    pit_frac = pointer to pitch period (fractional) of type Word16    resu3 = pointer to subsample resolution of type Word16    ana_index = pointer to index of encoding of type Word16 Returns:    None Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION   FUNCTION:   Pitch_fr()   PURPOSE: Find the pitch period with 1/3 or 1/6 subsample resolution            (closed loop).   DESCRIPTION:         - find the normalized correlation between the target and filtered           past excitation in the search range.         - select the delay with maximum normalized correlation.         - interpolate the normalized correlation at fractions -3/6 to 3/6           with step 1/6 around the chosen delay.         - The fraction which gives the maximum interpolated value is chosen.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES pitch_fr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEWord16 Pitch_fr (        // o   : pitch period (integer)    Pitch_frState *st,   // i/o : State struct    enum Mode mode,      // i   : codec mode    Word16 T_op[],       // i   : open loop pitch lags    Word16 exc[],        // i   : excitation buffer                      Q0    Word16 xn[],         // i   : target vector                          Q0    Word16 h[],          // i   : impulse response of synthesis and                                  weighting filters                     Q12    Word16 L_subfr,      // i   : Length of subframe    Word16 i_subfr,      // i   : subframe offset    Word16 *pit_frac,    // o   : pitch period (fractional)    Word16 *resu3,       // o   : subsample resolution 1/3 (=1) or 1/6 (=0)    Word16 *ana_index    // o   : index of encoding){    Word16 i;    Word16 t_min, t_max;    Word16 t0_min, t0_max;    Word16 max, lag, frac;    Word16 tmp_lag;    Word16 *corr;    Word16 corr_v[40];    // Total length = t0_max-t0_min+1+2*L_INTER_SRCH    Word16 max_frac_lag;    Word16 flag3, flag4;    Word16 last_frac;    Word16 delta_int_low, delta_int_range;    Word16 delta_frc_low, delta_frc_range;    Word16 pit_min;    Word16 frame_offset;    Word16 delta_search;    //-----------------------------------------------------------------------     //                      set mode specific variables     //----------------------------------------------------------------------    max_frac_lag    = mode_dep_parm[mode].max_frac_lag;    flag3           = mode_dep_parm[mode].flag3;    frac            = mode_dep_parm[mode].first_frac;    last_frac       = mode_dep_parm[mode].last_frac;    delta_int_low   = mode_dep_parm[mode].delta_int_low;    delta_int_range = mode_dep_parm[mode].delta_int_range;    delta_frc_low   = mode_dep_parm[mode].delta_frc_low;    delta_frc_range = mode_dep_parm[mode].delta_frc_range;    pit_min         = mode_dep_parm[mode].pit_min;    //-----------------------------------------------------------------------    //                 decide upon full or differential search    //-----------------------------------------------------------------------    delta_search = 1;    if ((i_subfr == 0) || (sub(i_subfr,L_FRAME_BY2) == 0)) {        // Subframe 1 and 3        if (((sub((Word16)mode, (Word16)MR475) != 0) && (sub((Word16)mode,            (Word16)MR515) != 0)) ||            (sub(i_subfr,L_FRAME_BY2) != 0)) {            // set t0_min, t0_max for full search            // this is *not* done for mode MR475, MR515 in subframe 3            delta_search = 0; // no differential search            // calculate index into T_op which contains the open-loop            // pitch estimations for the 2 big subframes            frame_offset = 1;            if (i_subfr == 0)                frame_offset = 0;            // get T_op from the corresponding half frame and            // set t0_min, t0_max            getRange (T_op[frame_offset], delta_int_low, delta_int_range,                      pit_min, PIT_MAX, &t0_min, &t0_max);        }        else {            // mode MR475, MR515 and 3. Subframe: delta search as well            getRange (st->T0_prev_subframe, delta_frc_low, delta_frc_range,                      pit_min, PIT_MAX, &t0_min, &t0_max);        }    }    else {        // for Subframe 2 and 4        // get range around T0 of previous subframe for delta search        getRange (st->T0_prev_subframe, delta_frc_low, delta_frc_range,                  pit_min, PIT_MAX, &t0_min, &t0_max);    }    //-----------------------------------------------------------------------                Find interval to compute normalized correlation     -----------------------------------------------------------------------    t_min = sub (t0_min, L_INTER_SRCH);    t_max = add (t0_max, L_INTER_SRCH);

⌨️ 快捷键说明

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