Example #1
0
void coder_ld8a(

				int ana[]                   /* output: analysis parameters */

)

{

	/* LPC coefficients */



	FLOAT Aq_t[(MP1)*2];         /* A(z) quantized for the 2 subframes   */

	FLOAT Ap_t[(MP1)*2];         /* A(z) with spectral expansion         */

	FLOAT *Aq, *Ap;              /* Pointer on Aq_t  and Ap_t            */



	/* Other vectors */



	FLOAT h1[L_SUBFR];           /* Impulse response h1[]              */

	FLOAT xn[L_SUBFR];           /* Target vector for pitch search     */

	FLOAT xn2[L_SUBFR];          /* Target vector for codebook search  */

	FLOAT code[L_SUBFR];         /* Fixed codebook excitation          */

	FLOAT y1[L_SUBFR];           /* Filtered adaptive excitation       */

	FLOAT y2[L_SUBFR];           /* Filtered fixed codebook excitation */

	FLOAT g_coeff[5];            /* Correlations between xn, y1, & y2:

								 <y1,y1>, <xn,y1>, <y2,y2>, <xn,y2>,<y1,y2>*/



	/* Scalars */



	int i, j, i_subfr;

	int T_op, T0, T0_min, T0_max, T0_frac;

	int index;

	FLOAT   gain_pit, gain_code;

	int     taming;



	/*------------------------------------------------------------------------*

	*  - Perform LPC analysis:                                               *

	*       * autocorrelation + lag windowing                                *

	*       * Levinson-durbin algorithm to find a[]                          *

	*       * convert a[] to lsp[]                                           *

	*       * quantize and code the LSPs                                     *

	*       * find the interpolated LSPs and convert to a[] for the 2        *

	*         subframes (both quantized and unquantized)                     *

	*------------------------------------------------------------------------*/

	{

		/* Temporary vectors */

		FLOAT r[MP1];                    /* Autocorrelations       */

		FLOAT rc[M];                     /* Reflexion coefficients */

		FLOAT lsp_new[M];                /* lsp coefficients       */

		FLOAT lsp_new_q[M];              /* Quantized lsp coeff.   */



		/* LP analysis */



		autocorr(p_window, M, r);             /* Autocorrelations */

		lag_window(M, r);                     /* Lag windowing    */

		levinson(r, Ap_t, rc);                /* Levinson Durbin  */

		az_lsp(Ap_t, lsp_new, lsp_old);       /* Convert A(z) to lsp */



		/* LSP quantization */



		qua_lsp(lsp_new, lsp_new_q, ana);

		ana += 2;                        /* Advance analysis parameters pointer */



		/*--------------------------------------------------------------------*

		* Find interpolated LPC parameters in all subframes                  *

		* The interpolated parameters are in array Aq_t[].                   *

		*--------------------------------------------------------------------*/



		int_qlpc(lsp_old_q, lsp_new_q, Aq_t);



		/* Compute A(z/gamma) */



		weight_az(&Aq_t[0],   GAMMA1, M, &Ap_t[0]);

		weight_az(&Aq_t[MP1], GAMMA1, M, &Ap_t[MP1]);



		/* update the LSPs for the next frame */



		copy(lsp_new,   lsp_old,   M);

		copy(lsp_new_q, lsp_old_q, M);

	}



	/*----------------------------------------------------------------------*

	* - Find the weighted input speech w_sp[] for the whole speech frame   *

	* - Find the open-loop pitch delay for the whole speech frame          *

	* - Set the range for searching closed-loop pitch in 1st subframe      *

	*----------------------------------------------------------------------*/



	residu(&Aq_t[0],   &speech[0],       &exc[0],       L_SUBFR);

	residu(&Aq_t[MP1], &speech[L_SUBFR], &exc[L_SUBFR], L_SUBFR);



	{

		FLOAT Ap1[MP1];



		Ap = Ap_t;

		Ap1[0] = (F)1.0;

		for(i=1; i<=M; i++)

			Ap1[i] = Ap[i] - (F)0.7 * Ap[i-1];

		syn_filt(Ap1, &exc[0], &wsp[0], L_SUBFR, mem_w, 1);



		Ap += MP1;

		for(i=1; i<=M; i++)

			Ap1[i] = Ap[i] - (F)0.7 * Ap[i-1];

		syn_filt(Ap1, &exc[L_SUBFR], &wsp[L_SUBFR], L_SUBFR, mem_w, 1);

	}





	/* Find open loop pitch lag for whole speech frame */



	T_op = pitch_ol_fast(wsp, L_FRAME);



	/* Range for closed loop pitch search in 1st subframe */



	T0_min = T_op - 3;

	if (T0_min < PIT_MIN) T0_min = PIT_MIN;

	T0_max = T0_min + 6;

	if (T0_max > PIT_MAX)

	{

		T0_max = PIT_MAX;

		T0_min = T0_max - 6;

	}



	/*------------------------------------------------------------------------*

	*          Loop for every subframe in the analysis frame                 *

	*------------------------------------------------------------------------*

	*  To find the pitch and innovation parameters. The subframe size is     *

	*  L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times.               *

	*     - find the weighted LPC coefficients                               *

	*     - find the LPC residual signal                                     *

	*     - compute the target signal for pitch search                       *

	*     - compute impulse response of weighted synthesis filter (h1[])     *

	*     - find the closed-loop pitch parameters                            *

	*     - encode the pitch delay                                           *

	*     - find target vector for codebook search                           *

	*     - codebook search                                                  *

	*     - VQ of pitch and codebook gains                                   *

	*     - update states of weighting filter                                *

	*------------------------------------------------------------------------*/



	Aq = Aq_t;    /* pointer to interpolated quantized LPC parameters */

	Ap = Ap_t;    /* pointer to weighted LPC coefficients             */



	for (i_subfr = 0;  i_subfr < L_FRAME; i_subfr += L_SUBFR)

	{

		/*---------------------------------------------------------------*

		* Compute impulse response, h1[], of weighted synthesis filter  *

		*---------------------------------------------------------------*/



		h1[0] = (F)1.0;

		set_zero(&h1[1], L_SUBFR-1);

		syn_filt(Ap, h1, h1, L_SUBFR, &h1[1], 0);



		/*-----------------------------------------------*

		* Find the target vector for pitch search:      *

		*----------------------------------------------*/



		syn_filt(Ap, &exc[i_subfr], xn, L_SUBFR, mem_w0, 0);



		/*-----------------------------------------------------------------*

		*    Closed-loop fractional pitch search                          *

		*-----------------------------------------------------------------*/



		T0 = pitch_fr3_fast(&exc[i_subfr], xn, h1, L_SUBFR, T0_min, T0_max,

			i_subfr, &T0_frac);



		index = enc_lag3(T0, T0_frac, &T0_min, &T0_max, PIT_MIN, PIT_MAX,

			i_subfr);



		*ana++ = index;



		if (i_subfr == 0)

			*ana++ = parity_pitch(index);



		/*-----------------------------------------------------------------*

		*   - find filtered pitch exc                                     *

		*   - compute pitch gain and limit between 0 and 1.2              *

		*   - update target vector for codebook search                    *

		*   - find LTP residual.                                          *

		*-----------------------------------------------------------------*/



		syn_filt(Ap, &exc[i_subfr], y1, L_SUBFR, mem_zero, 0);



		gain_pit = g_pitch(xn, y1, g_coeff, L_SUBFR);



		/* clip pitch gain if taming is necessary */



		taming = test_err(T0, T0_frac);



		if( taming == 1){

			if (gain_pit > GPCLIP) {

				gain_pit = GPCLIP;

			}

		}



		for (i = 0; i < L_SUBFR; i++)

			xn2[i] = xn[i] - y1[i]*gain_pit;



		/*-----------------------------------------------------*

		* - Innovative codebook search.                       *

		*-----------------------------------------------------*/



		index = ACELP_code_A(xn2, h1, T0, sharp, code, y2, &i);



		*ana++ = index;           /* Positions index */

		*ana++ = i;               /* Signs index     */



		/*------------------------------------------------------*

		*  - Compute the correlations <y2,y2>, <xn,y2>, <y1,y2>*

		*  - Vector quantize gains.                            *

		*------------------------------------------------------*/



		corr_xy2(xn, y1, y2, g_coeff);

		*ana++ =qua_gain(code, g_coeff, L_SUBFR, &gain_pit, &gain_code,

			taming);



		/*------------------------------------------------------------*

		* - Update pitch sharpening "sharp" with quantized gain_pit  *

		*------------------------------------------------------------*/



		sharp = gain_pit;

		if (sharp > SHARPMAX) sharp = SHARPMAX;

		if (sharp < SHARPMIN) sharp = SHARPMIN;



		/*------------------------------------------------------*

		* - Find the total excitation                          *

		* - update filters' memories for finding the target    *

		*   vector in the next subframe  (mem_w0[])            *

		*------------------------------------------------------*/



		for (i = 0; i < L_SUBFR;  i++)

			exc[i+i_subfr] = gain_pit*exc[i+i_subfr] + gain_code*code[i];



		update_exc_err(gain_pit, T0);



		for (i = L_SUBFR-M, j = 0; i < L_SUBFR; i++, j++)

			mem_w0[j]  = xn[i] - gain_pit*y1[i] - gain_code*y2[i];



		Aq += MP1;           /* interpolated LPC parameters for next subframe */

		Ap += MP1;

	}



	/*--------------------------------------------------*

	* Update signal for next frame.                    *

	* -> shift to the left by L_FRAME:                 *

	*     speech[], wsp[] and  exc[]                   *

	*--------------------------------------------------*/



	copy(&old_speech[L_FRAME], &old_speech[0], L_TOTAL-L_FRAME);

	copy(&old_wsp[L_FRAME], &old_wsp[0], PIT_MAX);

	copy(&old_exc[L_FRAME], &old_exc[0], PIT_MAX+L_INTERPOL);



	return;

}
Example #2
0
/*----------------------------------------------------------------------------
 * Post - adaptive postfilter main function
 *----------------------------------------------------------------------------
 */
void poste(
    int   t0,             /* input : pitch delay given by coder */
    FLOAT *signal_ptr,    /* input : input signal (pointer to current subframe */
    FLOAT *coeff,         /* input : LPC coefficients for current subframe */
    FLOAT *sig_out,       /* output: postfiltered output */
    int   *vo,            /* output: voicing decision 0 = uv,  > 0 delay */
    FLOAT gamma1,         /* input: short term postfilt. den. weighting factor*/
    FLOAT gamma2,         /* input: short term postfilt. num. weighting factor*/
    FLOAT gamma_harm,     /* input: long term postfilter weighting factor*/
    int   long_h_st,      /* input: impulse response length*/
    int   m_pst,          /* input:  LPC order */
    int Vad               /* input : VAD information (frame type)  */
)
{

    /* Local variables and arrays */
    FLOAT apond1[M_BWDP1];             /* s.t. denominator coeff.      */
    FLOAT sig_ltp[L_SUBFRP1];      /* H0 output signal             */
    FLOAT *sig_ltp_ptr;
    FLOAT parcor0;

    /* Compute weighted LPC coefficients */
    weight_az(coeff, gamma1, m_pst, apond1);
    weight_az(coeff, gamma2, m_pst, apond2);
    set_zero(&apond2[m_pst+1], (M_BWD-m_pst));

    /* Compute A(gamma2) residual */
    residue(m_pst, apond2, signal_ptr, res2_ptr, L_SUBFR);

    /* Harmonic filtering */
    sig_ltp_ptr = sig_ltp + 1;

    if (Vad > 1)
      pst_ltpe(t0, res2_ptr, sig_ltp_ptr, vo, gamma_harm);
    else {
      *vo = 0;
      copy(res2_ptr, sig_ltp_ptr, L_SUBFR);
    }

    /* Save last output of 1/A(gamma1)  */
    /* (from preceding subframe)        */
    sig_ltp[0] = *ptr_mem_stp;

    /* Controls short term pst filter gain and compute parcor0   */
    calc_st_filte(apond2, apond1, &parcor0, sig_ltp_ptr, long_h_st, m_pst);

    /* 1/A(gamma1) filtering, mem_stp is updated */
    syn_filte(m_pst, apond1, sig_ltp_ptr, sig_ltp_ptr, L_SUBFR,
            &mem_stp[M_BWD-m_pst], 0);
    copy(&sig_ltp_ptr[L_SUBFR-M_BWD], mem_stp, M_BWD);

    /* Tilt filtering */
    filt_mu(sig_ltp, sig_out, parcor0);

    /* Gain control */
    scale_st(signal_ptr, sig_out, &gain_prec);

    /**** Update for next subframe */
    copy(&res2[L_SUBFR], &res2[0], MEM_RES2);

    return;
}
Example #3
0
/*--------------------------------------------------------------------------
* decod_ld8c - decoder
*--------------------------------------------------------------------------
*/
void decod_ld8c(
    int    parm[],       /* (i)   : vector of synthesis parameters
                                  parm[0] = bad frame indicator (bfi)    */
    int    voicing,      /* (i)   : voicing decision from previous frame */
    FLOAT  synth_buf[],  /* (i/o) : synthesis speech                     */
    FLOAT  Az_dec[],     /* (o)   : decoded LP filter in 2 subframes     */
    int    *t0_first,    /* (o)   : decoded pitch lag in first subframe  */
    int    *bwd_dominant,/* (o)   : bwd dominant indicator               */
    int    *m_pst,        /* (o)   : LPC order for postfilter             */
    int    *Vad          /* output: decoded frame type                         */
)
{
    /* Scalars */
    int i, j, i_subfr;
    int t0, t0_frac, index;
    int bfi;
    int lp_mode;                   /* Backward / Forward mode indication */
    FLOAT g_p, g_c;               /* fixed and adaptive codebook gain */
    int bad_pitch;              /* bad pitch indicator */
    FLOAT tmp;
    FLOAT energy;
    int  rate;
    
    /* Tables */
    FLOAT A_t_bwd[2*M_BWDP1];   /* LPC Backward filter */
    FLOAT A_t_fwd[2*MP1];     /* LPC Forward filter */
    FLOAT rc_bwd[M_BWD];      /* LPC backward reflection coefficients */
    FLOAT r_bwd[M_BWDP1];   /* Autocorrelations (backward) */
    FLOAT lsp_new[M];         /* LSPs             */
    FLOAT code[L_SUBFR];      /* ACELP codevector */
    FLOAT exc_phdisp[L_SUBFR]; /* excitation after phase dispersion */
    FLOAT *pA_t;                /* Pointer on A_t   */
    int stationnary;
    int m_aq;
    FLOAT *synth;
    int sat_filter;
    
    /* for G.729B */
    int ftyp;
    FLOAT lsfq_mem[MA_NP][M];
    
    synth = synth_buf + MEM_SYN_BWD;
    
    /* Test bad frame indicator (bfi) */
    bfi = *parm++;
    
    /* Test frame type */
    ftyp = *parm++;
    
    if(bfi == 1) {
        ftyp = past_ftyp;
        if(ftyp == 1) ftyp = 0;
        if(ftyp > 2) {    /* G.729 maintenance */
          if(ftyp == 3) parm[4] = 1;
          else {
            if(prev_lp_mode == 0) parm[5] = 1;
            else parm[3] = 1;
          }
        }
        parm[-1] = ftyp;
    }
    
    *Vad = ftyp;
    
    rate = ftyp - 2;
    /* Decoding the Backward/Forward LPC decision */
    /* ------------------------------------------ */
    if( rate != G729E) lp_mode = 0;
    else {
        if (bfi != 0) {
            lp_mode = prev_lp_mode; /* Frame erased => lp_mode = previous lp_mode */
            *parm++ = lp_mode;
        }
        else {
            lp_mode = *parm++;
        }
        if(prev_bfi != 0) voicing = prev_voicing;
    }
    if( bfi == 0) {
        c_muting = (F)1.;
        count_bfi = 0;
    }
    
    /* -------------------- */
    /* Backward LP analysis */
    /* -------------------- */
    if (rate == G729E) {
        /* LPC recursive Window as in G728 */
        autocorr_hyb_window(synth_buf, r_bwd, rexp); /* Autocorrelations */
        
        lag_window_bwd(r_bwd); /* Lag windowing    */
        
        /* Levinson (as in G729) */
        levinsone(M_BWD, r_bwd, &A_t_bwd[M_BWDP1], rc_bwd,
            old_A_bwd, old_rc_bwd );
        
        /* Tests saturation of A_t_bwd */
        sat_filter = 0;
        for (i=M_BWDP1; i<2*M_BWDP1; i++) if (A_t_bwd[i] >= (F)8.) sat_filter = 1;
        if (sat_filter == 1) copy(A_t_bwd_mem, &A_t_bwd[M_BWDP1], M_BWDP1);
        else copy(&A_t_bwd[M_BWDP1], A_t_bwd_mem, M_BWDP1);
        
        /* Additional bandwidth expansion on backward filter */
        weight_az(&A_t_bwd[M_BWDP1], GAMMA_BWD, M_BWD, &A_t_bwd[M_BWDP1]);
    }
    /*--------------------------------------------------*
     * Update synthesis signal for next frame.          *
     *--------------------------------------------------*/
    copy(&synth_buf[L_FRAME], &synth_buf[0], MEM_SYN_BWD);
    
    if(lp_mode == 1) {
        if ((c_fe != (F)0.)) {
            /* Interpolation of the backward filter after a bad frame */
            /* A_t_bwd(z) = c_fe . A_bwd_mem(z) + (1 - c_fe) . A_t_bwd(z) */
            /* ---------------------------------------------------------- */
            tmp = (F)1. - c_fe;
            pA_t = A_t_bwd + M_BWDP1;
            for (i=0; i<M_BWDP1; i++) {
                pA_t[i] *= tmp;
                pA_t[i] += c_fe * A_bwd_mem[i];
            }
        }
    }

    /* Memorize the last good backward filter when the frame is erased */
    if ((bfi != 0)&&(prev_bfi == 0) && (past_ftyp >3))
        copy(&A_t_bwd[M_BWDP1], A_bwd_mem, M_BWDP1);
    
    /* for G.729B */
    /* Processing non active frames (SID & not transmitted: ftyp = 1 or 0) */
    if(ftyp < 2) {
        /* get_decfreq_prev(lsfq_mem); */
        for (i=0; i<MA_NP; i++) 
            copy(&freq_prev[i][0], &lsfq_mem[i][0], M);
        
        dec_cng(past_ftyp, sid_sav, &parm[-1], exc, lsp_old,
            A_t_fwd, &seed, lsfq_mem);
        
        /*   update_decfreq_prev(lsfq_mem); */
        for (i=0; i<MA_NP; i++) 
            copy(&lsfq_mem[i][0], &freq_prev[i][0], M);
        
        pA_t = A_t_fwd;
        for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) {
            syn_filte(M, pA_t, &exc[i_subfr], &synth[i_subfr], L_SUBFR, &mem_syn[M_BWD-M], 0);
            copy(&synth[i_subfr+L_SUBFR-M_BWD], mem_syn, M_BWD);

            *t0_first = prev_t0;
            pA_t += MP1;
        }
        sharp = SHARPMIN;
        c_int = (F)1.1;
        /* for gain decoding in case of frame erasure */
        stat_bwd = 0;
        stationnary = 0;
        /* for pitch tracking  in case of frame erasure */
        stat_pitch = 0;
        /* 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] = (F)0.;
    }

    /***************************/
    /* Processing active frame */
    /***************************/
    else {
        seed = INIT_SEED;
        
        /* ---------------------------- */
        /* LPC decoding in forward mode */
        /* ---------------------------- */
        if (lp_mode == 0) {

            /* Decode the LSPs */
            d_lspe(parm, lsp_new, bfi, freq_prev, prev_lsp, &prev_ma);
            parm += 2;
            if( prev_lp_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 = (F)1.1;
            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] = (F)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                 *
        *------------------------------------------------------------------------*/

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

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

            if(i_subfr == 0) {

                if (rate == G729D)
                    i = 0;      /* no pitch parity at 6.4 kb/s */
                else
                    i = *parm++;             /* get parity check result */
                bad_pitch = bfi + i;     
                if( bad_pitch == 0) {
                    dec_lag3cp(index, PIT_MIN, PIT_MAX, i_subfr, &t0, &t0_frac, rate);
                    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 == G729E) {
                        t0_frac = prev_t0_frac;
                    }
                    else {
                        t0_frac = 0;
                        prev_t0++;
                        if(prev_t0 > PIT_MAX) {
                            prev_t0 = PIT_MAX;
                        }
                    }
                }
                *t0_first = t0;         /* If first frame */
            }
            else {                       /* second subframe */
                
                if( bfi == 0) {
                    dec_lag3cp(index, PIT_MIN, PIT_MAX, i_subfr, &t0, &t0_frac, rate);
                    prev_t0 = t0;
                    prev_t0_frac = t0_frac;
                }
                else {
                    t0  =  prev_t0;
                    if (rate == G729E) {
                        t0_frac = prev_t0_frac;
                    }
                    else {
                        t0_frac = 0;
                        prev_t0++;
                        if(prev_t0 > PIT_MAX) 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 == G729E) {
                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] = (int)random_g729c(&seed_fer);
                parm[1] = (int)random_g729c(&seed_fer);
                if (rate == G729E) {
                    parm[2] = (int)random_g729c(&seed_fer);
                    parm[3] = (int)random_g729c(&seed_fer);
                    parm[4] = (int)random_g729c(&seed_fer);
                }
                
            }
            
            stationnary = 0; /* to avoid visual warning */
            if (rate == G729) {
                /* 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 if (rate == G729D) {
                /* case 8 kbps */
                decod_ACELP64(parm[1], parm[0], code);
                parm += 2;
                /* for gain decoding in case of frame erasure */
                stat_bwd = 0;
                stationnary = 0;
            }
            else if (rate == G729E) {
                /* case 11.8 kbps */
                if (lp_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++;
                    if (stat_bwd >= 30) {
                        stationnary = 1;
                        stat_bwd = 30;
                    }
                    else stationnary = 0;
                }
                parm += 5;
            }
            
            /*-------------------------------------------------------*
            * - Add the fixed-gain pitch contribution to code[].    *
            *-------------------------------------------------------*/
            for (i = t0; i < L_SUBFR; i++)   code[i] += sharp * code[i-t0];

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

            if (rate == G729D)
                dec_gain_6k(index, code, L_SUBFR, bfi, &gain_pitch, &gain_code);
            else
                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 (sharp > SHARPMAX) sharp = SHARPMAX;
            if (sharp < SHARPMIN) sharp = SHARPMIN;
            
            /*-------------------------------------------------------*
            * - Find the total excitation.                          *
            * - Find synthesis speech corresponding to exc[].       *
            *-------------------------------------------------------*/
            if(bfi != 0) {       /* Bad frame */
                count_bfi++;
                if (voicing == 0 ) {
                    g_p = (F)0.;
                    g_c = gain_code;
                }
                else {
                    g_p = gain_pitch;
                    g_c = (F)0.;
                }
            }
            else {
                g_p = gain_pitch;
                g_c = gain_code;
            }
        
            for (i = 0; i < L_SUBFR;  i++) {
                exc[i+i_subfr] = g_p * exc[i+i_subfr] + g_c * code[i];
            }
            
            if (rate == G729D) {
                PhDisp(&exc[i_subfr], exc_phdisp, gain_code, gain_pitch, code);
                syn_filte(m_aq, pA_t, exc_phdisp, &synth[i_subfr], L_SUBFR,
                                &mem_syn[M_BWD-m_aq], 0);
            }
            else {
                syn_filte(m_aq, pA_t, &exc[i_subfr], &synth[i_subfr], L_SUBFR,
                                    &mem_syn[M_BWD-m_aq], 0);

                /* Updates state machine for phase dispersion in
                6.4 kbps mode, if running at other rate */
                Update_PhDisp(gain_pitch, gain_code);
            }

            copy(&synth[i_subfr+L_SUBFR-M_BWD], mem_syn, M_BWD);

            pA_t += m_aq+1;    /* interpolated LPC parameters for next subframe */

        }

    }

    /*------------*
     *  For G729b
     *-----------*/
    if(bfi == 0) {
        sid_sav = (FLOAT)0.0;
        for(i=0; i<L_FRAME; i++) {
            sid_sav += exc[i] * exc[i];
        }
    }
    past_ftyp = ftyp;

    /*------------*
     *  For G729E
     *-----------*/
    energy = ener_dB(synth, L_FRAME);
    if (energy >= (F)40.) tst_bwd_dominant(bwd_dominant, lp_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( lp_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_lp_mode    = lp_mode;
    prev_voicing = voicing;
    
    if (bfi != 0) c_fe = (F)1.;
    else {
        if (lp_mode == 0) c_fe = 0;
        else {
            if (*bwd_dominant == 1) c_fe -= (F)0.1;
            else c_fe -= (F)0.5;
            if (c_fe < 0)  c_fe= 0;
        }
    }
    
    return;
}