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

📄 decld8cp.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 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_BWD);        state->sharp        = SHARPMIN;    state->prev_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);        set_zero(state->A_bwd_mem, M_BWDP1);    set_zero(state->A_t_bwd_mem, M_BWDP1);    state->A_bwd_mem[0]   = (F)1.;    state->A_t_bwd_mem[0] = (F)1.;        state->prev_voicing = 0;    state->prev_bfi     = 0;    state->prev_lp_mode = 0;    state->c_fe     = (F)0.;    state->c_int    = (F)1.1;       /* Filter interpolation parameter */    set_zero(state->prev_filter, M_BWDP1);    state->prev_filter[0] = (F)1.;    state->prev_pitch     = 30;    state->stat_pitch     = 0;    set_zero(state->old_A_bwd, M_BWDP1);    set_zero(state->rexp, M_BWDP1);    state->old_A_bwd[0]   = (F)1.;    set_zero(state->old_rc_bwd, 2);    state->gain_pit_mem   = (F)0.;    state->gain_cod_mem   = (F)0.;    state->c_muting       = (F)1.;    state->count_bfi      = 0;    state->stat_bwd       = 0;        /* for G.729B */    state->seed_fer = (INT16)21845;    state->past_ftyp = 3;    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);	init_bwd_dominant(&state->bwd_s);}        /*--------------------------------------------------------------------------* 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_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          /* (o)   : 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 = state->past_ftyp;        if(ftyp == 1) ftyp = 0;        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 = state->prev_lp_mode; /* Frame erased => lp_mode = previous lp_mode */            *parm++ = lp_mode;        }        else {            lp_mode = *parm++;        }        if (state->prev_bfi != 0) voicing = state->prev_voicing;    }    if (bfi == 0) {        state->c_muting = (F)1.;        state->count_bfi = 0;    }        /* -------------------- */    /* Backward LP analysis */    /* -------------------- */    if (rate == G729E) {        /* LPC recursive Window as in G728 */        autocorr_hyb_window(synth_buf, r_bwd, state->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,            state->old_A_bwd, state->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(state->A_t_bwd_mem, &A_t_bwd[M_BWDP1], M_BWDP1);        else copy(&A_t_bwd[M_BWDP1], state->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 ((state->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. - state->c_fe;            pA_t = A_t_bwd + M_BWDP1;            for (i=0; i<M_BWDP1; i++) {                pA_t[i] *= tmp;                pA_t[i] += state->c_fe * state->A_bwd_mem[i];            }        }    }    /* Memorize the last good backward filter when the frame is erased */    if ((bfi != 0) && (state->prev_bfi == 0) && (state->past_ftyp > 3))        copy(&A_t_bwd[M_BWDP1], state->A_bwd_mem, M_BWDP1);        /* for G.729B */    /* Processing non active frames (SID & not transmitted: ftyp = 1 or 0) */    if (ftyp < 2)	{        /*for (i=0; i<MA_NP; i++) copy(&state->lsp_s.freq_prev[i][0], &lsfq_mem[i][0], M);*/        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[-1], state->exc, state->lsp_old,            A_t_fwd, &state->seed, lsfq_mem);                /*for (i=0; i<MA_NP; i++) copy(&lsfq_mem[i][0], &state->lsp_s.freq_prev[i][0], M);*/        update_freq_prev(state->lsp_s.freq_prev, (const FLOAT (*)[M])lsfq_mem);                pA_t = A_t_fwd;        for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) {            syn_filte(M, pA_t, &state->exc[i_subfr], &synth[i_subfr], L_SUBFR, &state->mem_syn[M_BWD-M], 0);            copy(&synth[i_subfr+L_SUBFR-M_BWD], state->mem_syn, M_BWD);            *t0_first = state->prev_t0;            pA_t += MP1;        }        state->sharp = SHARPMIN;        state->c_int = (F)1.1;        /* for gain decoding in case of frame erasure */        state->stat_bwd = 0;        stationnary = 0;        /* for pitch tracking  in case of frame erasure */        state->stat_pitch = 0;        /* update the previous filter for the next frame */        copy(&A_t_fwd[MP1], state->prev_filter, MP1);        /*for(i=MP1; i<M_BWDP1; i++) state->prev_filter[i] = (F)0.;*/		set_zero(state->prev_filter + MP1, M_BWDP1 - MP1);    }    /***************************/    /* Processing active frame */    /***************************/    else {        state->seed = INIT_SEED;                /* ---------------------------- */        /* LPC decoding in forward mode */        /* ---------------------------- */        if (lp_mode == 0) {            /* Decode the LSPs */            d_lspe(&state->lsp_s, parm, lsp_new, bfi);            parm += 2;            if (state->prev_lp_mode == 0) { /* Interpolation of LPC for the 2 subframes */                int_qlpc(state->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, state->lsp_old, M);            state->c_int = (F)1.1;

⌨️ 快捷键说明

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