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

📄 dec_ld8c.c

📁 语音编码G.729 语音编码G.729
💻 C
字号:
/*   ITU-T G.729 Annex C+ - Reference C code for floating point                         implementation of G.729 Annex C+                         (integration of Annexes B, D and E)                          Version 2.1 of October 1999*//* File : DECLD8CP.C *//*-----------------------------------------------------------------**   Functions init_decod_ld8c  and decod_ld8c                     **-----------------------------------------------------------------*/#include "typedef.h"#include "cst_ld8c.h"#include "tab_ld8k.h"/*---------------------------------------------------------------**   Decoder constant parameters (defined in "ld8k.h")           **---------------------------------------------------------------**   L_FRAME     : Frame size.                                   **   L_SUBFR     : Sub-frame size.                               **   M           : LPC order.                                    **   MP1         : LPC order+1                                   **   PIT_MIN     : Minimum pitch lag.                            **   PIT_MAX     : Maximum pitch lag.                            **   L_INTERPOL  : Length of filter for interpolation            **   PRM_SIZE    : Size of vector containing analysis parameters **---------------------------------------------------------------*//*--------------------------------------------------------------------------* init_decod_ld8c - Initialization of variables for the decoder section.*--------------------------------------------------------------------------*/void init_decod_ld8c(struct dec_state_t *state){    /* Initialize static pointer */    state->exc = state->old_exc + PIT_MAX + L_INTERPOL;        /* Static vectors to zero */    set_zero(state->old_exc, PIT_MAX+L_INTERPOL);    set_zero(state->mem_syn, M);        state->sharp        = SHARPMIN;    state->old_t0      = 60;    //state->prev_t0_frac = 0;    state->gain_code    = (F)0.;    state->gain_pitch   = (F)0.;    copy(lsp_old_reset, state->lsp_old, M);        lsp_decw_reset(&state->lsp_s);        /* for G.729B */    state->seed_fer = (INT16)21845;    state->past_ftyp = 1;    state->seed = INIT_SEED;    state->sid_sav = (FLOAT)0.;    init_lsfq_noise(&state->cng_s.lsfq_s);	/* init added during 'unstaticing' */	gain_past_reset(&state->gain_s);	init_exc_err(state->cng_s.exc_err);}        /*--------------------------------------------------------------------------* decod_ld8c - decoder*--------------------------------------------------------------------------*/void decod_ld8c(	struct dec_state_t *state,	int    parm[],       /* (i)   : vector of synthesis parameters								  parm[0] = bad frame indicator (bfi)    */	int    voicing,      /* (i)   : voicing decision from previous frame */	FLOAT  *synth,  /* (i/o) : synthesis speech                     */	FLOAT  A_t[],     /* (o)   : decoded LP filter in 2 subframes     */	int    *t0_first,    /* (o)   : decoded pitch lag in first subframe  */	int    *Vad          /* (o)   : decoded frame type                   */){	FLOAT *Az;                  /* Pointer to A_t (LPC coefficients)  */	FLOAT lsp_new[M];           /* LSPs                               */	FLOAT code[L_SUBFR];        /* algebraic codevector               */	/* Scalars */	int   i, i_subfr;	int   t0, t0_frac, index;	int bfi;	int bad_pitch;	/* for G.729B */	int ftyp;	FLOAT lsfq_mem[MA_NP][M];  /* Test bad frame indicator (bfi) */  bfi = *parm++;   /* for G.729B */   ftyp = *parm;   if (bfi)   {     if(state->past_ftyp == 1)       ftyp = 1;     else       ftyp = 0;     *parm = ftyp;  /* modification introduced in version V1.3 */   }     *Vad = ftyp;  /* Processing non active frames (SID & not transmitted) */  if(ftyp != 1)  {    get_freq_prev((const FLOAT (*)[M])state->lsp_s.freq_prev, lsfq_mem);    dec_cng(&state->cng_s, state->past_ftyp, state->sid_sav, parm, state->exc, state->lsp_old,            A_t, &state->seed, lsfq_mem);    update_freq_prev(state->lsp_s.freq_prev, (const FLOAT (*)[M])lsfq_mem);    Az = A_t;    for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)	{      syn_filte(M, Az, &state->exc[i_subfr], &synth[i_subfr], L_SUBFR, state->mem_syn, 0);      copy(&synth[i_subfr+L_SUBFR-M], state->mem_syn, M);            Az += MP1;      *t0_first = state->old_t0;    }    state->sharp = SHARPMIN;      }  else /* Processing active frame */  {        state->seed = INIT_SEED;    parm++;	  /* Decode the LSPs */	  d_lspe(&state->lsp_s, parm, lsp_new, bfi);	  parm += 2;             /* Advance synthesis parameters pointer */	  /* Interpolation of LPC for the 2 subframes */	  int_qlpc(state->lsp_old, lsp_new, A_t);	  /* update the LSFs for the next frame */	  copy(lsp_new, state->lsp_old, M);	/*------------------------------------------------------------------------*	 *          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                 *	 *------------------------------------------------------------------------*/	  Az = A_t;            /* pointer to interpolated LPC parameters */	  for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)	  {	   index = *parm++;          /* pitch index */	   if (i_subfr == 0) {      /* if first subframe */		 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, G729);		   state->old_t0 = t0;		 }		 else                     /* Bad frame, or parity error */		 {		   t0  =  state->old_t0;		   t0_frac = 0;		   state->old_t0++;		   if( state->old_t0> PIT_MAX) {			   state->old_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, G729);		   state->old_t0 = t0;		 }		 else		 {		   t0  =  state->old_t0;		   t0_frac = 0;		   state->old_t0++;		   if( state->old_t0 >PIT_MAX) {			   state->old_t0 = PIT_MAX;		   }		 }	   }	   /*-------------------------------------------------*		*  - Find the adaptive codebook vector.            *		*--------------------------------------------------*/	   pred_lt_3(&state->exc[i_subfr], t0, t0_frac, L_SUBFR);	   /*-------------------------------------------------------*		* - Decode innovative codebook.                         *		* - Add the fixed-gain pitch contribution to code[].    *		*-------------------------------------------------------*/	   if(bfi != 0) {            /* Bad Frame Error Concealment */		 parm[0] = (int) (random_g729c(&state->seed_fer) & 0x1fff);      /* 13 bits random*/		 parm[1]= (int) (random_g729c(&state->seed_fer) & 0x000f);      /*  4 bits random */	   }	   decod_ACELP(parm[1], parm[0], code);	   parm +=2;	   for (i = t0; i < L_SUBFR; i++)   code[i] += state->sharp * code[i-t0];	   /*-------------------------------------------------*		* - Decode pitch and codebook gains.              *		*-------------------------------------------------*/	   index = *parm++;          /* index of energy VQ */	   dec_gain(&state->gain_s, index, code, L_SUBFR, bfi, &state->gain_pitch, &state->gain_code);	   /*-------------------------------------------------------------*		* - Update pitch sharpening "sharp" with quantized gain_pitch *		*-------------------------------------------------------------*/	   state->sharp = state->gain_pitch;	   if (state->sharp > SHARPMAX) state->sharp = SHARPMAX;	   if (state->sharp < SHARPMIN) state->sharp = SHARPMIN;	   /*-------------------------------------------------------*		* - Find the total excitation.                          *		*-------------------------------------------------------*/	   if(bfi != 0 ) {		 if(voicing  == 0) {     /* for unvoiced frame */			 for (i = 0; i < L_SUBFR;  i++) {				state->exc[i+i_subfr] = state->gain_code*code[i];			 }		  } else {               /* for voiced frame */			 for (i = 0; i < L_SUBFR;  i++) {				state->exc[i+i_subfr] = state->gain_pitch*state->exc[i+i_subfr];			 }		  }		} else {                  /* No frame errors */		  for (i = 0; i < L_SUBFR;  i++) {			 state->exc[i+i_subfr] = state->gain_pitch*state->exc[i+i_subfr] + state->gain_code*code[i];		  }		}		/*-------------------------------------------------------*		 * - Find synthesis speech corresponding to exc[].       *		 *-------------------------------------------------------*/		syn_filte(M, Az, &state->exc[i_subfr], &synth[i_subfr], L_SUBFR, state->mem_syn, 1);		Az  += MP1;        /* interpolated LPC parameters for next subframe */	  }  }  /*------------*   *  For G729b   *-----------*/  if (bfi == 0)  {     state->sid_sav = (F)0.0;     for (i=0; i<L_FRAME; i++)        state->sid_sav += state->exc[i] * state->exc[i];  }  state->past_ftyp = ftyp;	/*--------------------------------------------------*	* Update signal for next frame.                    *	* -> shift to the left by L_FRAME  exc[]           *	*--------------------------------------------------*/  copy(&state->old_exc[L_FRAME], &state->old_exc[0], PIT_MAX+L_INTERPOL);}

⌨️ 快捷键说明

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