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

📄 cod_ld8a.c

📁 语音编码G.729 语音编码G.729
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   ITU-T G.729 Annex C - Reference C code for floating point                         implementation of G.729 Annex A                         Version 1.01 of 15.September.98*//*----------------------------------------------------------------------                    COPYRIGHT NOTICE----------------------------------------------------------------------   ITU-T G.729 Annex C ANSI C source code   Copyright (C) 1998, AT&T, France Telecom, NTT, University of   Sherbrooke.  All rights reserved.----------------------------------------------------------------------*//* File : COD_LD8A.C Used for the floating point version of G.729A only (not for G.729 main body)*//*-----------------------------------------------------------------* *   Functions coder_ld8a and init_coder_ld8a                      * *             ~~~~~~~~~~     ~~~~~~~~~~~~~~~                      * *                                                                 * *  init_coder_ld8a(void);                                         * *                                                                 * *   ->Initialization of variables for the coder section.          * *                                                                 * *                                                                 * *  coder_ld8a(Short ana[]);                                       * *                                                                 * *   ->Main coder function.                                        * *                                                                 * *                                                                 * *  Input:                                                         * *                                                                 * *    80 speech data should have beee copy to vector new_speech[]. * *    This vector is global and is declared in this function.      * *                                                                 * *  Ouputs:                                                        * *                                                                 * *    ana[]      ->analysis parameters.                            * *                                                                 * *-----------------------------------------------------------------*/#include <math.h>#include "typedef.h"#include "ld8a.h"#include "cst_ld8a.h"#include "tab_ld8a.h"/*-----------------------------------------------------------* *    Coder constant parameters (defined in "ld8a.h")        * *-----------------------------------------------------------* *   L_WINDOW    : LPC analysis window size.                 * *   L_NEXT      : Samples of next frame needed for autocor. * *   L_FRAME     : Frame size.                               * *   L_SUBFR     : Sub-frame size.                           * *   M           : LPC order.                                * *   MP1         : LPC order+1                               * *   L_TOTAL     : Total size of speech buffer.              * *   PIT_MIN     : Minimum pitch lag.                        * *   PIT_MAX     : Maximum pitch lag.                        * *   L_INTERPOL  : Length of filter for interpolation        * *-----------------------------------------------------------*//*-----------------------------------------------------------------* *   Function  init_coder_ld8a                                     * *            ~~~~~~~~~~~~~~~                                      * *                                                                 * *  init_coder_ld8a(void);                                         * *                                                                 * *   ->Initialization of variables for the coder section.          * *       - initialize pointers to speech buffer                    * *       - initialize static  pointers                             * *       - set static vectors to zero                              * *-----------------------------------------------------------------*/void init_coder_ld8a(struct cod_state_t * state){  /*----------------------------------------------------------------------*  *      Initialize pointers to speech vector.                            *  *                                                                       *  *                                                                       *  *   |--------------------|-------------|-------------|------------|     *  *     previous speech           sf1           sf2         L_NEXT        *  *                                                                       *  *   <----------------  Total speech vector (L_TOTAL)   ----------->     *  *   <----------------  LPC analysis window (L_WINDOW)  ----------->     *  *   |                   <-- present frame (L_FRAME) -->                 *  * old_speech            |              <-- new speech (L_FRAME) -->     *  * p_window              |              |                                *  *                     speech           |                                *  *                             new_speech                                *  *-----------------------------------------------------------------------*/	state->new_speech = state->old_speech + L_TOTAL - L_FRAME;         /* New speech     */	state->speech     = state->new_speech - L_NEXT;                    /* Present frame  */	state->p_window   = state->old_speech + L_TOTAL - L_WINDOW;        /* For LPC window */	/* Initialize static pointers */	state->wsp    = state->old_wsp + PIT_MAX;	state->exc    = state->old_exc + PIT_MAX + L_INTERPOL;	/* Static vectors to zero */	set_zero(state->old_speech, L_TOTAL);	set_zero(state->old_exc, PIT_MAX+L_INTERPOL);	set_zero(state->old_wsp, PIT_MAX);	set_zero(state->mem_w,   M);	set_zero(state->mem_w0,  M);	set_zero(state->mem_zero, M);	state->sharp = SHARPMIN;	copy(lsp_reset, state->lsp_old, M);	copy(state->lsp_old, state->lsp_old_q, M);	lsp_codw_reset(&state->lsp_s);	init_exc_err(state->cng_s.exc_err); // ?	/* For G.729B */	/* Initialize VAD/DTX parameters */	state->pastVad = 1;	state->ppastVad = 1;	state->seed = INIT_SEED;	vad_init(&state->vad_s);	init_lsfq_noise(&state->cng_s.lsfq_s); // ?	gain_past_reset(&state->gain_s);}/*-----------------------------------------------------------------* *   Function coder_ld8a                                           * *            ~~~~~~~~~~                                           * *  coder_ld8a(int    ana[]);                                      * *                                                                 * *   ->Main coder function.                                        * *                                                                 * *                                                                 * *  Input:                                                         * *                                                                 * *    80 speech data should have beee copy to vector new_speech[]. * *    This vector is global and is declared in this function.      * *                                                                 * *  Ouputs:                                                        * *                                                                 * *    ana[]      ->analysis parameters.                            * *                                                                 * *-----------------------------------------------------------------*/void coder_ld8a(struct cod_state_t * state,  int ana[],        /* output: analysis parameters */  int frame,        /* input   : frame counter       */  int vad_enable    /* input   : VAD enable flag     */){   /* 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[NP+1];                   /* Autocorrelations       */     FLOAT rc[M];                     /* Reflexion coefficients */     FLOAT lsp_new[M];                /* lsp coefficients       */     FLOAT lsp_new_q[M];              /* Quantized lsp coeff.   */	 FLOAT lsf_new[M]; 	 /* For G.729B */     FLOAT r_nbe[MP1];     FLOAT lsfq_mem[MA_NP][M];     int Vad;     FLOAT Energy_db;     /* LP analysis */     autocorr(state->p_window, NP, r);        /* Autocorrelations */     copy(r, r_nbe, MP1);     lag_window(NP, r);                       /* Lag windowing    */     levinson(r, Ap_t, rc);                   /* Levinson Durbin  */     az_lsp(Ap_t, lsp_new, state->lsp_old);   /* Convert A(z) to lsp */	/* For G.729B */	/* ------ VAD ------- */	if (vad_enable)	{		lsp_lsf(lsp_new, lsf_new, M);		vad(&state->vad_s, rc[1], lsf_new, r, state->p_window, frame,			state->pastVad, state->ppastVad, &Vad, &Energy_db);		update_cng(&state->cng_s, r_nbe, Vad);	}	else		Vad = 1;	/* ---------------------- */	/* Case of Inactive frame */	/* ---------------------- */	if (!Vad)	{	  get_freq_prev((const FLOAT (*)[M]) state->lsp_s.freq_prev, lsfq_mem);	  cod_cng(&state->cng_s, state->exc, state->pastVad, state->lsp_old_q, Aq_t, ana, lsfq_mem, &state->seed);

⌨️ 快捷键说明

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