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

📄 dec_amr.cpp

📁 实现3GPP的GSM中AMR语音的CODECS。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        }        else        {           Overflow = 0;           Syn_filt (Az, exc_enhanced, &synth[i_subfr], L_SUBFR,                     st->mem_syn, 0);        }        if (Overflow != 0)    // Test for overflow        {           for (i = 0; i < PIT_MAX + L_INTERPOL + L_SUBFR; i++)           {              st->old_exc[i] = shr(st->old_exc[i], 2);           }           for (i = 0; i < L_SUBFR; i++)           {              exc_enhanced[i] = shr(exc_enhanced[i], 2);           }           Syn_filt(Az, exc_enhanced, &synth[i_subfr], L_SUBFR, st->mem_syn, 1);        }        else        {           Copy(&synth[i_subfr+L_SUBFR-M], st->mem_syn, M);        }         *--------------------------------------------------*         * Update signal for next frame.                    *         * -> shift to the left by L_SUBFR  st->exc[]       *         *--------------------------------------------------*        Copy (&st->old_exc[L_SUBFR], &st->old_exc[0], PIT_MAX + L_INTERPOL);        // interpolated LPC parameters for next subframe        Az += MP1;        // store T0 for next subframe        st->old_T0 = T0;    }     *-------------------------------------------------------*     * Call the Source Characteristic Detector which updates *     * st->inBackgroundNoise and st->voicedHangover.         *     *-------------------------------------------------------*    st->inBackgroundNoise = Bgn_scd(st->background_state,                                    &(st->ltpGainHistory[0]),                                    &(synth[0]),                                    &(st->voicedHangover) );    dtx_dec_activity_update(st->dtxDecoderState,                            st->lsfState->past_lsf_q,                            synth);    // store bfi for next subframe    st->prev_bf = bfi;    st->prev_pdf = pdfi;     *--------------------------------------------------*     * Calculate the LSF averages on the eight          *     * previous frames                                  *     *--------------------------------------------------*    lsp_avg(st->lsp_avg_st, st->lsfState->past_lsf_q);the_end:    st->dtxDecoderState->dtxGlobalState = newDTXState;    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]------------------------------------------------------------------------------*/void 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;    Word16 i_subfr;    Word16 T0;    Word16 T0_frac;    Word16 index;    Word16 index_mr475 = 0;    Word16 gain_pit;    Word16 gain_code;    Word16 gain_code_mix;    Word16 pit_sharp;    Word16 pit_flag;    Word16 pitch_fac;    Word16 t0_min;    Word16 t0_max;    Word16 delta_frc_low;    Word16 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 */    Flag   *pOverflow = &(st->overflow);     /* Overflow flag            */    /* find the new  DTX state  SPEECH OR DTX */    newDTXState = rx_dtx_handler(&(st->dtxDecoderState), frame_type, pOverflow);    /* DTX actions */    if (newDTXState != SPEECH)    {        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, pOverflow);        /* update average lsp */        Lsf_lsp(            st->lsfState.past_lsf_q,            st->lsp_old,            M,            pOverflow);        lsp_avg(            &(st->lsp_avg_st),            st->lsfState.past_lsf_q,            pOverflow);        goto the_end;    }    /* SPEECH action state machine  */    if ((frame_type == RX_SPEECH_BAD) || (frame_type == RX_NO_DATA) ||            (frame_type == RX_ONSET))    {        bfi = 1;        if ((frame_type == RX_NO_DATA) || (frame_type == RX_ONSET))        {            build_CN_param(&st->nodataSeed,                           prmno[mode],                           bitno[mode],                           parm,                           pOverflow);        }    }    else if (frame_type == RX_SPEECH_DEGRADED)    {        pdfi = 1;    }    if (bfi != 0)    {        st->state += 1;    }    else if (st->state == 6)    {        st->state = 5;    }    else    {        st->state = 0;    }    if (st->state > 6)    {        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 (st->dtxDecoderState.dtxGlobalState == DTX)    {        st->state = 5;        st->prev_bf = 0;    }    else if (st->dtxDecoderState.dtxGlobalState == DTX_MUTE)    {        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 (mode != MR122)    {        D_plsf_3(            &(st->lsfState),            mode,            bfi,            parm,            lsp_new,            pOverflow);        /* Advance synthesis parameters pointer */        parm += 3;        Int_lpc_1to3(            st->lsp_old,            lsp_new,            A_t,            pOverflow);    }    else    {        D_plsf_5(            &(st->lsfState),            bfi,            parm,            lsp_mid,            lsp_new,            pOverflow);        /* Advance synthesis parameters pointer */        parm += 5;        Int_lpc_1and3(            st->lsp_old,            lsp_mid,            lsp_new,            A_t,            pOverflow);    }    /* 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 += 1;        evenSubfr = 1 - evenSubfr;        /* flag for first and 3th subframe */        pit_flag = i_subfr;        if (i_subfr == L_FRAME_BY2)        {            if ((mode != MR475) && (mode != MR515))            {                pit_flag = 0;            }        }        /* pitch index */        index = *parm++;        /*-------------------------------------------------------*        * - decode pitch lag and find adaptive codebook vector. *        *-------------------------------------------------------*/        if (mode != MR122)        {            /* flag4 indicates encoding with 4 bit resolution;     */            /* this is needed for mode MR475, MR515, MR59 and MR67 */            flag4 = 0;            if ((mode == MR475) || (mode == MR515) || (mode == MR59) ||                    (mode == MR67))            {                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 (mode == MR795)            {                delta_frc_low = 10;                delta_frc_range = 19;            }            t0_min = sub(st->old_T0, delta_frc_low, pOverflow);            if (t0_min < PIT_MIN)            {                t0_min = PIT_MIN;            }            t0_max = add(t0_min, delta_frc_range, pOverflow);            if (t0_max > PIT_MAX)            {                t0_max = PIT_MAX;                t0_min = t0_max - delta_frc_range;            }            Dec_lag3(index, t0_min, t0_max, pit_flag, st->old_T0,                     &T0, &T0_frac, flag4, pOverflow);            st->T0_lagBuff = T0;            if (bfi != 0)            {                if (st->old_T0 < PIT_MAX)                {                               /* Graceful pitch */                    st->old_T0 += 1;            /* degradation    */                }                T0 = st->old_T0;                T0_frac = 0;                if ((st->inBackgroundNoise != 0) && (st->voicedHangover > 4) &&                        ((mode == MR475) || (mode == MR515) || (mode == MR59)))                {                    T0 = st->T0_lagBuff;                }            }            Pred_lt_3or6(st->exc, T0, T0_frac, L_SUBFR, 1, pOverflow);        }        else        {            Dec_lag6(index, PIT_MIN_MR122,                     PIT_MAX, pit_flag, &T0, &T0_frac, pOverflow);            if (!(bfi == 0 && (pit_flag == 0 || index < 61)))            {                st->T0_lagBuff = T0;                T0 = st->old_T0;                T0_frac = 0;            }            Pred_lt_3or6(st->exc, T0, T0_frac, L_SUBFR, 0, pOverflow);        }        /*-------------------------------------------------------*         * - (MR122 only: Decode pitch gain.)                    *         * - Decode innovative codebook.                         *         * - set pitch sharpening factor                         *

⌨️ 快捷键说明

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