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

📄 codld8cp.c

📁 语音编码G.729 语音编码G.729
💻 C
📖 第 1 页 / 共 3 页
字号:
/*   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 : CODLD8CP.C*//*-----------------------------------------------------------------* *   Functions coder_ld8c and init_coder_ld8c                      * *             ~~~~~~~~~~     ~~~~~~~~~~~~~~~                      * *-----------------------------------------------------------------*/#include <math.h>#include "typedef.h"#include "cst_ld8c.h"#include "tab_ld8k.h" /*-----------------------------------------------------------* *    Coder constant parameters (defined in "ld8k.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        * *-----------------------------------------------------------*/#define         AVG(a,b,c,d) (int)(((a)+(b)+(c)+(d))/((F)4.0)+(F)0.5)/*---------------------------------------------------------------------------- * init_coder_ld8c - initialization of variables for the encoder *---------------------------------------------------------------------------- */void init_coder_ld8c(	struct cod_state_t *state,	int dtx_enable   /* input : DTX enable flag */){/*-----------------------------------------------------------------------**      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_wind            |              |                                **                     speech           |                                **                             new_speech                                **-----------------------------------------------------------------------*/    int   i;    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;    state->zero   = state->ai_zero + M_BWDP1;    state->error  = state->mem_err + M_BWD;    /* 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_syn, M_BWD);    set_zero(state->mem_w,   M_BWD);    set_zero(state->mem_w0,  M_BWD);    set_zero(state->mem_err, M_BWD);    set_zero(state->zero, L_SUBFR);    state->pit_sharp = SHARPMIN;        /* Initialize lsp_old_q[] */    copy(lsp_old_reset, state->lsp_old, M);	copy(lsp_old_reset, 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 */    if (dtx_enable)	{        state->pastVad = 1;        state->ppastVad = 1;        state->seed = INIT_SEED;        vad_init(&state->vad_s);        init_lsfq_noise(&state->cng_s.lsfq_s);    }    /* for G.729E */    /* for the backward analysis */    set_zero(state->synth, L_ANA_BWD);    state->synth_ptr = state->synth + MEM_SYN_BWD;    state->prev_lp_mode = 0;    state->bwd_dominant = 0;              /* See file bwfw.c */    state->C_int = (F)1.1;       /* Filter interpolation parameter */    state->glob_stat = 10000;  /* Mesure of global stationnarity */    state->stat_bwd = 0;       /* Nbre of consecutive backward frames */    state->val_stat_bwd = 0;   /* Value associated with stat_bwd */    for(i=0; i<M_BWDP1; i++) state->rexp[i] = (F)0.;    state->A_t_bwd_mem[0] = (F)1.;    for (i=1; i<M_BWDP1; i++) state->A_t_bwd_mem[i] = (F)0.;    set_zero(state->prev_filter, M_BWDP1);    state->prev_filter[0] = (F)1.;    set_zero(state->old_A_bwd, M_BWDP1);    state->old_A_bwd[0] = (F)1.;    set_zero(state->old_rc_bwd, 2);    set_zero(state->old_A_fwd, MP1);    state->old_A_fwd[0] = (F)1.;    set_zero(state->old_rc_fwd, 2);	for (i=0; i<5; ++i) state->lag_buf[i] = 20;	for (i=0; i<5; ++i) state->pgain_buf[i]= (F)0.7;	/* init added during 'unstaticing' */	state->d4i40_17_extra = 0;	gain_past_reset(&state->gain_s);	init_bwd_dominant(&state->bwd_s);	init_musdetect(&state->mus_s);	init_pwf(&state->pwf_s);}/*---------------------------------------------------------------------------- * coder_ld8c - encoder routine ( speech data should be in new_speech ) *---------------------------------------------------------------------------- */void coder_ld8c(	struct cod_state_t *state,	int ana[],        /* output: analysis parameters */	int frame,        /* input : frame counter */	int dtx_enable,   /* input : DTX enable flag */	int rate          /* input : rate selector/ G729, G729D, and G729E */){    /* LPC analysis */    FLOAT r_fwd[NP+1];          /* Autocorrelations (forward) */    FLOAT r_bwd[M_BWDP1];      /* Autocorrelations (backward) */    FLOAT rc_fwd[M];           /* Reflection coefficients : forward analysis */    FLOAT rc_bwd[M_BWD];       /* Reflection coefficients : backward analysis */    FLOAT A_t_fwd[MP1*2];      /* A(z) forward unquantized for the 2 subframes */    FLOAT A_t_fwd_q[MP1*2];    /* A(z) forward quantized for the 2 subframes */    FLOAT A_t_bwd[2*M_BWDP1];  /* A(z) backward for the 2 subframes */    FLOAT *Aq;           /* A(z) "quantized" for the 2 subframes */    FLOAT *Ap;           /* A(z) "unquantized" for the 2 subframes */    FLOAT *pAp, *pAq;    FLOAT Ap1[M_BWDP1];          /* A(z) with spectral expansion         */    FLOAT Ap2[M_BWDP1];          /* A(z) with spectral expansion         */    FLOAT lsp_new[M], lsp_new_q[M]; /* LSPs at 2th subframe                 */    FLOAT lsf_int[M];               /* Interpolated LSF 1st subframe.       */    FLOAT lsf_new[M];    int lp_mode;                  /* LP Backward (1) / Forward (0) Indication mode */    int m_ap, m_aq;    int code_lsp[2];        /* 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 res2[L_SUBFR];         /* Pitch prediction residual          */    FLOAT g_coeff[5];            /* Correlations between xn, y1, & y2:                                 <y1,y1>, <xn,y1>, <y2,y2>, <xn,y2>,<y1,y2>*/                                     /* Scalars */    int   i, j, i_gamma, i_subfr;    int   T_op, t0, t0_min, t0_max, t0_frac;    int   index, taming;    FLOAT gain_pit, gain_code;    /* for G.729E */    int sat_filter;    FLOAT freq_cur[M];        /* For G.729B */    FLOAT r_nbe[MP1];    FLOAT lsfq_mem[MA_NP][M];    int Vad;    FLOAT Energy_db;    int avg_lag;        /*------------------------------------------------------------------------*    *  - 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)                     *    *------------------------------------------------------------------------*/    /* ------------------- */    /* LP Forward analysis */    /* ------------------- */    autocorr(state->p_window, NP, r_fwd);                     /* Autocorrelations */    copy(r_fwd, r_nbe, MP1);    lag_window(NP, r_fwd);                             /* Lag windowing    */    levinsone(M, r_fwd, &A_t_fwd[MP1], rc_fwd,         /* Levinson Durbin  */        state->old_A_fwd, state->old_rc_fwd);    az_lsp(&A_t_fwd[MP1], lsp_new, state->lsp_old);           /* From A(z) to lsp */    /* For G.729B */    /* ------ VAD ------- */    if (dtx_enable == 1) {        lsp_lsf(lsp_new, lsf_new, M);        vad(&state->vad_s, rc_fwd[1], lsf_new, r_fwd, state->p_window, frame,            state->pastVad, state->ppastVad, &Vad, &Energy_db);        musdetect(&state->mus_s, rate, r_fwd[0],rc_fwd, state->lag_buf, state->pgain_buf,                      state->prev_lp_mode, frame, state->pastVad, &Vad, Energy_db);        update_cng(&state->cng_s, r_nbe, Vad);    }    else Vad = 1;    /* -------------------- */    /* LP Backward analysis */    /* -------------------- */    if ( (rate-(1-Vad))== G729E) {        /* LPC recursive Window as in G728 */        autocorr_hyb_window(state->synth, r_bwd, state->rexp); /* Autocorrelations */        lag_window_bwd(r_bwd);  /* Lag windowing    */        levinsone(M_BWD, r_bwd, &A_t_bwd[M_BWDP1], rc_bwd,

⌨️ 快捷键说明

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