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

📄 dec_ld8e.c

📁 E729国际标准的语音编码
💻 C
📖 第 1 页 / 共 2 页
字号:
    /* ---------------------------- */
    if (mode == 0) {

        /* Decode the LSPs */
        D_lspe(parm, lsp_new, bfi, freq_prev, prev_lsp, &prev_ma);
        parm += 2;
        if( prev_mode == 0) { /* Interpolation of LPC for the 2 subframes */
            Int_qlpc(lsp_old, lsp_new, A_t_fwd);
        }
        else {
            /* no interpolation */
            Lsp_Az(lsp_new, A_t_fwd);           /* Subframe 1*/
            Copy(A_t_fwd, &A_t_fwd[MP1], MP1); /* Subframe 2 */
        }

        /* update the LSFs for the next frame */
        Copy(lsp_new, lsp_old, M);

        C_int = 4506;
        pA_t = A_t_fwd;
        m_aq = M;
        /* update the previous filter for the next frame */
        Copy(&A_t_fwd[MP1], prev_filter, MP1);
        for(i=MP1; i<M_BWDP1; i++) prev_filter[i] = 0;
    }
    else {
        Int_bwd(A_t_bwd, prev_filter, &C_int);
        pA_t = A_t_bwd;
        m_aq = M_BWD;
        /* update the previous filter for the next frame */
        Copy(&A_t_bwd[M_BWDP1], prev_filter, M_BWDP1);
     }

    /*------------------------------------------------------------------------*
    *          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                 *
    *------------------------------------------------------------------------*/

    synth = synth_buf + MEM_SYN_BWD;
    for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) {

        index = *parm++;            /* pitch index */

        if(i_subfr == 0) {

            i = *parm++;             /* get parity check result */
            bad_pitch = add(bfi, i);
            if( bad_pitch == 0) {
                Dec_lag3(index, PIT_MIN, PIT_MAX, i_subfr, &T0, &T0_frac);
                prev_T0 = T0;
                prev_T0_frac = T0_frac;
            }
            else {                     /* Bad frame, or parity error */
                if (bfi == 0) printf(" ! Wrong Pitch 1st subfr. !   ");
                T0  =  prev_T0;
                if (rate == 1) {
                    T0_frac = prev_T0_frac;
                }
                else {
                    T0_frac = 0;
                    prev_T0 = add( prev_T0, 1);
                    if( sub(prev_T0, PIT_MAX) > 0) {
                        prev_T0 = PIT_MAX;
                    }
                }
            }
            *T0_first = T0;         /* If first frame */
        }
        else {                       /* second subframe */

            if( bfi == 0) {
                Dec_lag3(index, PIT_MIN, PIT_MAX, i_subfr, &T0, &T0_frac);
                prev_T0 = T0;
                prev_T0_frac = T0_frac;
            }
            else {
                T0  =  prev_T0;
                if (rate == 1) {
                    T0_frac = prev_T0_frac;
                }
                else {
                    T0_frac = 0;
                    prev_T0 = add( prev_T0, 1);
                    if( sub(prev_T0, PIT_MAX) > 0) prev_T0 = PIT_MAX;
                }
            }
        }
       /*-------------------------------------------------*
        * - Find the adaptive codebook vector.            *
        *-------------------------------------------------*/
        Pred_lt_3(&exc[i_subfr], T0, T0_frac, L_SUBFR);

        /* --------------------------------- */
        /* pitch tracking for frame erasures */
        /* --------------------------------- */
        if( rate == 1) {
            track_pit(&prev_T0, &prev_T0_frac, &prev_pitch, &stat_pitch,
                        &pitch_sta, &frac_sta);
        }
        else {
            i = prev_T0;
            j = prev_T0_frac;
            track_pit(&i, &j, &prev_pitch, &stat_pitch,
                        &pitch_sta, &frac_sta);
        }

       /*-------------------------------------------------------*
        * - Decode innovative codebook.                         *
        *-------------------------------------------------------*/
        if(bfi != 0) {        /* Bad frame */

            parm[0] = Random();

            if (rate == 0) parm[1] = Random();
            else {
                parm[1] = Random();
                parm[2] = Random();
                parm[3] = Random();
                parm[4] = Random();
            }
        }

        if (rate == 0) {
            /* case 8 kbps */
            Decod_ACELP(parm[1], parm[0], code);
            parm += 2;
            /* for gain decoding in case of frame erasure */
            stat_bwd = 0;
            stationnary = 0;
        }
        else {
            /* case 11.8 kbps */
            if (mode == 0) {
                Dec_ACELP_10i40_35bits(parm, code);
                /* for gain decoding in case of frame erasure */
                stat_bwd = 0;
                stationnary = 0;
            }
            else {
                Dec_ACELP_12i40_44bits(parm, code);
                /* for gain decoding in case of frame erasure */
                stat_bwd += 1;
                if (stat_bwd >= 30) {
                    stationnary = 1;
                    stat_bwd = 30;
                }
                else stationnary = 0;
            }
            parm += 5;
        }


       /*-------------------------------------------------------*
        * - Add the fixed-gain pitch contribution to code[].    *
        *-------------------------------------------------------*/
        j = shl(sharp, 1);          /* From Q14 to Q15 */
        if(sub(T0, L_SUBFR) <0 ) {
            for (i = T0; i < L_SUBFR; i++) {
                code[i] = add(code[i], mult(code[i-T0], j));
            }
        }

       /*-------------------------------------------------*
        * - Decode pitch and codebook gains.              *
        *-------------------------------------------------*/
        index = *parm++;      /* index of energy VQ */

        Dec_gaine(index, code, L_SUBFR, bfi, &gain_pitch, &gain_code, rate,
           gain_pit_mem, gain_cod_mem, &c_muting, count_bfi, stationnary);
       /*-------------------------------------------------------------*
        * - Update previous gains
        *-------------------------------------------------------------*/
        gain_pit_mem = gain_pitch;
        gain_cod_mem = gain_code;

       /*-------------------------------------------------------------*
        * - Update pitch sharpening "sharp" with quantized gain_pitch *
        *-------------------------------------------------------------*/
        sharp = gain_pitch;
        if (sub(sharp, SHARPMAX) > 0) sharp = SHARPMAX;
        if (sub(sharp, SHARPMIN) < 0) sharp = SHARPMIN;

       /*-------------------------------------------------------*
        * - Find the total excitation.                          *
        * - Find synthesis speech corresponding to exc[].       *
        *-------------------------------------------------------*/
        if(bfi != 0) {       /* Bad frame */
            count_bfi += 1;
            if (voicing == 0 ) {
                g_p = 0;
                g_c = gain_code;
            }
            else {
                g_p = gain_pitch;
                g_c = 0;
            }
        }
        else {
            g_p = gain_pitch;
            g_c = gain_code;
        }
        for (i = 0; i < L_SUBFR;  i++) {
            /* exc[i] = g_p*exc[i] + g_c*code[i]; */
            /* exc[i]  in Q0   g_p in Q14         */
            /* code[i] in Q13  g_code in Q1       */

            L_temp = L_mult(exc[i+i_subfr], g_p);
            L_temp = L_mac(L_temp, code[i], g_c);
            L_temp = L_shl(L_temp, 1);
            exc[i+i_subfr] = round(L_temp);
        }

        Overflow = 0;
        Syn_filte(m_aq, pA_t, &exc[i_subfr], &synth[i_subfr], L_SUBFR,
                                                &mem_syn[M_BWD-m_aq], 0);
        if(Overflow != 0) {
            /* In case of overflow in the synthesis          */
            /* -> Scale down vector exc[] and redo synthesis */
            for(i=0; i<PIT_MAX+L_INTERPOL+L_FRAME; i++) old_exc[i] = shr(old_exc[i], 2);
            Syn_filte(m_aq, pA_t, &exc[i_subfr], &synth[i_subfr], L_SUBFR,
                    &mem_syn[M_BWD-m_aq], 0);
        }
        pA_t += m_aq+1;    /* interpolated LPC parameters for next subframe */
        Copy(&synth[i_subfr+L_SUBFR-M_BWD], mem_syn, M_BWD);

    }

    energy = ener_dB(synth, L_FRAME);
    if (energy >= 8192) tst_bwd_dominant(bwd_dominant, mode);

    /*--------------------------------------------------*
    * Update signal for next frame.                    *
    * -> shift to the left by L_FRAME  exc[]           *
    *--------------------------------------------------*/
    Copy(&old_exc[L_FRAME], &old_exc[0], PIT_MAX+L_INTERPOL);

    if( mode == 0) {
        Copy(A_t_fwd, Az_dec, 2*MP1);
        *m_pst = M;
    }
    else {
        Copy(A_t_bwd, Az_dec, 2*M_BWDP1);
        *m_pst = M_BWD;
    }


    prev_bfi = bfi;
    prev_mode = mode;
    prev_voicing = voicing;

    if (bfi != 0) C_fe_fix = 4096;
    else {
        if (mode == 0) C_fe_fix = 0;
        else {
            if (*bwd_dominant == 1) C_fe_fix = sub(C_fe_fix, 410);
            else C_fe_fix = sub(C_fe_fix, 2048);
            if (C_fe_fix < 0)  C_fe_fix= 0;
        }
    }
    return;

}

⌨️ 快捷键说明

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