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

📄 dec_amr.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
 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 Decoder_amr_reset(Decoder_amrState *state, enum Mode mode){    Word16 i;    if (state == (Decoder_amrState *) NULL)    {        /* fprint(stderr, "Decoder_amr_reset: invalid parameter\n");  */        return(-1);    }    /* Initialize static pointer */    state->exc = state->old_exc + PIT_MAX + L_INTERPOL;    /* Static vectors to zero */    oscl_memset(state->old_exc, 0, sizeof(Word16)*(PIT_MAX + L_INTERPOL));    if (mode != MRDTX)    {        oscl_memset(state->mem_syn, 0, sizeof(Word16)*M);    }    /* initialize pitch sharpening */    state->sharp = SHARPMIN;    state->old_T0 = 40;    /* Initialize overflow Flag */    state->overflow = 0;    /* Initialize state->lsp_old [] */    if (mode != MRDTX)    {        state->lsp_old[0] = 30000;        state->lsp_old[1] = 26000;        state->lsp_old[2] = 21000;        state->lsp_old[3] = 15000;        state->lsp_old[4] = 8000;        state->lsp_old[5] = 0;        state->lsp_old[6] = -8000;        state->lsp_old[7] = -15000;        state->lsp_old[8] = -21000;        state->lsp_old[9] = -26000;    }    /* Initialize memories of bad frame handling */    state->prev_bf = 0;    state->prev_pdf = 0;    state->state = 0;    state->T0_lagBuff = 40;    state->inBackgroundNoise = 0;    state->voicedHangover = 0;    if (mode != MRDTX)    {        for (i = 0;i < EXC_ENERGY_HIST_LEN;i++)        {            state->excEnergyHist[i] = 0;        }    }    for (i = 0; i < LTP_GAIN_HISTORY_LEN; i++)    {        state->ltpGainHistory[i] = 0;    }    Cb_gain_average_reset(&(state->Cb_gain_averState));    if (mode != MRDTX)    {        lsp_avg_reset(&(state->lsp_avg_st));    }    D_plsf_reset(&(state->lsfState));    ec_gain_pitch_reset(&(state->ec_gain_p_st));    ec_gain_code_reset(&(state->ec_gain_c_st));    if (mode != MRDTX)    {        gc_pred_reset(&(state->pred_state));    }    Bgn_scd_reset(&(state->background_state));    state->nodataSeed = 21845;    ph_disp_reset(&(state->ph_disp_st));    if (mode != MRDTX)    {        dtx_dec_reset(&(state->dtxDecoderState));    }    return(0);}/****************************************************************************//*------------------------------------------------------------------------------ FUNCTION NAME: Decoder_amr------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs:    st = pointer to a structure of type Decoder_amrState    mode = codec mode (enum Mode)    parm = buffer of synthesis parameters (Word16)    frame_type = received frame type (enum RXFrameType)    synth = buffer containing synthetic speech (Word16)    A_t = buffer containing decoded LP filter in 4 subframes (Word16) Outputs:    structure pointed to by st contains the newly calculated decoder      parameters    synth buffer contains the decoded speech samples    A_t buffer contains the decoded LP filter parameters Returns:    return_value = 0 (int) Global Variables Used:    None Local Variables Needed:    None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function performs the decoding of one speech frame for a given codec mode.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES dec_amr.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEint Decoder_amr (    Decoder_amrState *st,      // i/o : State variables    enum Mode mode,            // i   : AMR mode    Word16 parm[],             // i   : vector of synthesis parameters                                        (PRM_SIZE)    enum RXFrameType frame_type, // i   : received frame type    Word16 synth[],            // o   : synthesis speech (L_FRAME)    Word16 A_t[]               // o   : decoded LP filter in 4 subframes                                        (AZ_SIZE)){    // LPC coefficients    Word16 *Az;                // Pointer on A_t    // LSPs    Word16 lsp_new[M];    Word16 lsp_mid[M];    // LSFs    Word16 prev_lsf[M];    Word16 lsf_i[M];    // Algebraic codevector    Word16 code[L_SUBFR];    // excitation    Word16 excp[L_SUBFR];    Word16 exc_enhanced[L_SUBFR];    // Scalars    Word16 i, i_subfr;    Word16 T0, T0_frac, index, index_mr475 = 0;    Word16 gain_pit, gain_code, gain_code_mix, pit_sharp, pit_flag, pitch_fac;    Word16 t0_min, t0_max;    Word16 delta_frc_low, delta_frc_range;    Word16 tmp_shift;    Word16 temp;    Word32 L_temp;    Word16 flag4;    Word16 carefulFlag;    Word16 excEnergy;    Word16 subfrNr;    Word16 evenSubfr = 0;    Word16 bfi = 0;   // bad frame indication flag    Word16 pdfi = 0;  // potential degraded bad frame flag    enum DTXStateType newDTXState;  // SPEECH , DTX, DTX_MUTE    // find the new  DTX state  SPEECH OR DTX    newDTXState = rx_dtx_handler(st->dtxDecoderState, frame_type);    // DTX actions    if (sub(newDTXState, SPEECH) != 0 )    {       Decoder_amr_reset (st, MRDTX);       dtx_dec(st->dtxDecoderState,               st->mem_syn,               st->lsfState,               st->pred_state,               st->Cb_gain_averState,               newDTXState,               mode,               parm, synth, A_t);       // update average lsp       Lsf_lsp(st->lsfState->past_lsf_q, st->lsp_old, M);       lsp_avg(st->lsp_avg_st, st->lsfState->past_lsf_q);       goto the_end;    }    // SPEECH action state machine    if ((sub(frame_type, RX_SPEECH_BAD) == 0) ||        (sub(frame_type, RX_NO_DATA) == 0) ||        (sub(frame_type, RX_ONSET) == 0))    {       bfi = 1;       if ((sub(frame_type, RX_NO_DATA) == 0) ||           (sub(frame_type, RX_ONSET) == 0))       {	  build_CN_param(&st->nodataSeed,			 prmno[mode],			 bitno[mode],			 parm);       }    }    else if (sub(frame_type, RX_SPEECH_DEGRADED) == 0)    {       pdfi = 1;    }    if (bfi != 0)    {        st->state = add (st->state, 1);    }    else if (sub (st->state, 6) == 0)    {        st->state = 5;    }    else    {        st->state = 0;    }    if (sub (st->state, 6) > 0)    {        st->state = 6;    }    // If this frame is the first speech frame after CNI period,    // set the BFH state machine to an appropriate state depending    // on whether there was DTX muting before start of speech or not    // If there was DTX muting, the first speech frame is muted.    // If there was no DTX muting, the first speech frame is not    // muted. The BFH state machine starts from state 5, however, to    // keep the audible noise resulting from a SID frame which is    // erroneously interpreted as a good speech frame as small as    // possible (the decoder output in this case is quickly muted)    if (sub(st->dtxDecoderState->dtxGlobalState, DTX) == 0)    {       st->state = 5;       st->prev_bf = 0;    }    else if (sub(st->dtxDecoderState->dtxGlobalState, DTX_MUTE) == 0)    {       st->state = 5;       st->prev_bf = 1;    }    // save old LSFs for CB gain smoothing    Copy (st->lsfState->past_lsf_q, prev_lsf, M);    // decode LSF parameters and generate interpolated lpc coefficients       for the 4 subframes    if (sub (mode, MR122) != 0)    {       D_plsf_3(st->lsfState, mode, bfi, parm, lsp_new);       // Advance synthesis parameters pointer       parm += 3;       Int_lpc_1to3(st->lsp_old, lsp_new, A_t);    }    else    {       D_plsf_5 (st->lsfState, bfi, parm, lsp_mid, lsp_new);       // Advance synthesis parameters pointer       parm += 5;       Int_lpc_1and3 (st->lsp_old, lsp_mid, lsp_new, A_t);    }    // update the LSPs for the next frame    for (i = 0; i < M; i++)    {       st->lsp_old[i] = lsp_new[i];    }    *------------------------------------------------------------------------*    *          Loop for every subframe in the analysis frame                 *    *------------------------------------------------------------------------*    * The subframe size is L_SUBFR and the loop is repeated L_FRAME/L_SUBFR  *    *  times                                                                 *    *     - decode the pitch delay                                           *    *     - decode algebraic code                                            *    *     - decode pitch and codebook gains                                  *    *     - find the excitation and compute synthesis speech                 *    *------------------------------------------------------------------------*    // pointer to interpolated LPC parameters    Az = A_t;    evenSubfr = 0;    subfrNr = -1;    for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)    {       subfrNr = add(subfrNr, 1);       evenSubfr = sub(1, evenSubfr);       // flag for first and 3th subframe       pit_flag = i_subfr;       if (sub (i_subfr, L_FRAME_BY2) == 0)       {          if (sub(mode, MR475) != 0 && sub(mode, MR515) != 0)          {             pit_flag = 0;          }       }       // pitch index       index = *parm++;        *-------------------------------------------------------*        * - decode pitch lag and find adaptive codebook vector. *        *-------------------------------------------------------*       if (sub(mode, MR122) != 0)       {          // flag4 indicates encoding with 4 bit resolution;          // this is needed for mode MR475, MR515, MR59 and MR67          flag4 = 0;          if ((sub (mode, MR475) == 0) ||              (sub (mode, MR515) == 0) ||              (sub (mode, MR59) == 0) ||              (sub (mode, MR67) == 0) ) {             flag4 = 1;          }           *-------------------------------------------------------*           * - get ranges for the t0_min and t0_max                *           * - only needed in delta decoding                       *           *-------------------------------------------------------*          delta_frc_low = 5;          delta_frc_range = 9;          if ( sub(mode, MR795) == 0 )          {             delta_frc_low = 10;             delta_frc_range = 19;          }          t0_min = sub(st->old_T0, delta_frc_low);          if (sub(t0_min, PIT_MIN) < 0)          {             t0_min = PIT_MIN;          }          t0_max = add(t0_min, delta_frc_range);          if (sub(t0_max, PIT_MAX) > 0)          {             t0_max = PIT_MAX;             t0_min = sub(t0_max, delta_frc_range);          }          Dec_lag3 (index, t0_min, t0_max, pit_flag, st->old_T0,                    &T0, &T0_frac, flag4);          st->T0_lagBuff = T0;          if (bfi != 0)          {             if (sub (st->old_T0, PIT_MAX) < 0)             {                                      // Graceful pitch                st->old_T0 = add(st->old_T0, 1);    // degradation             }             T0 = st->old_T0;             T0_frac = 0;             if ( st->inBackgroundNoise != 0 &&                  sub(st->voicedHangover, 4) > 0 &&                  ((sub(mode, MR475) == 0 ) ||                   (sub(mode, MR515) == 0 ) ||                   (sub(mode, MR59) == 0) )                  )             {                T0 = st->T0_lagBuff;             }          }          Pred_lt_3or6 (st->exc, T0, T0_frac, L_SUBFR, 1);       }       else

⌨️ 快捷键说明

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