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

📄 codld8cp.c

📁 语音编码G.729 语音编码G.729
💻 C
📖 第 1 页 / 共 3 页
字号:
    }        /*------------------------------------------------------------------------*    *          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 2 times.                             *    *     - find the weighted LPC coefficients                               *    *     - find the LPC residual signal res[]                               *    *     - 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                                           *    *     - update the impulse response h1[] by including fixed-gain pitch   *    *     - find target vector for codebook search                           *    *     - codebook search                                                  *    *     - encode codebook address                                          *    *     - VQ of pitch and codebook gains                                   *    *     - find synthesis speech                                            *    *     - update states of weighting filter                                *    *------------------------------------------------------------------------*/    pAp  = Ap;     /* pointer to interpolated "unquantized"LPC parameters           */    pAq = Aq;      /* pointer to interpolated "quantized" LPC parameters */            i_gamma = 0;        for (i_subfr = 0;  i_subfr < L_FRAME; i_subfr += L_SUBFR)	{		/*---------------------------------------------------------------*		* Find the weighted LPC coefficients for the weighting filter.  *		*---------------------------------------------------------------*/        weight_az(pAp, state->gamma1[i_gamma], m_ap, Ap1);        weight_az(pAp, state->gamma2[i_gamma], m_ap, Ap2);        i_gamma++;                /*---------------------------------------------------------------*        * Compute impulse response, h1[], of weighted synthesis filter  *        *---------------------------------------------------------------*/        /*for (i = 0; i <= m_ap; i++) state->ai_zero[i] = Ap1[i];*/		copy(Ap1, state->ai_zero, m_ap + 1);        syn_filte(m_aq,  pAq, state->ai_zero, h1, L_SUBFR, state->zero, 0);        syn_filte(m_ap,  Ap2, h1, h1, L_SUBFR, state->zero, 0);                /*------------------------------------------------------------------------*        *                                                                        *        *          Find the target vector for pitch search:                      *        *          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                       *        *                                                                        *        *              |------|  res[n]                                          *        *  speech[n]---| A(z) |--------                                          *        *              |------|       |   |--------| error[n]  |------|          *        *                    zero -- (-)--| 1/A(z) |-----------| W(z) |-- target *        *                    exc          |--------|           |------|          *        *                                                                        *        * Instead of subtracting the zero-input response of filters from         *        * the weighted input speech, the above configuration is used to          *        * compute the target vector. This configuration gives better performance *        * with fixed-point implementation. The memory of 1/A(z) is updated by    *        * filtering (res[n]-exc[n]) through 1/A(z), or simply by subtracting     *        * the synthesis speech from the input speech:                            *        *    error[n] = speech[n] - syn[n].                                      *        * The memory of W(z) is updated by filtering error[n] through W(z),      *        * or more simply by subtracting the filtered adaptive and fixed          *        * codebook excitations from the target:                                  *        *     target[n] - gain_pit*y1[n] - gain_code*y2[n]                       *        * as these signals are already available.                                *        *                                                                        *        *------------------------------------------------------------------------*/        residue(m_aq, pAq, &state->speech[i_subfr], &state->exc[i_subfr], L_SUBFR);   /* LPC residual */        /*for (i=0; i<L_SUBFR; i++) res2[i] = state->exc[i_subfr+i];*/		copy(state->exc+i_subfr, res2, L_SUBFR);        syn_filte(m_aq,  pAq, &state->exc[i_subfr], state->error, L_SUBFR,            &state->mem_err[M_BWD-m_aq], 0);        residue(m_ap, Ap1, state->error, xn, L_SUBFR);        syn_filte(m_ap,  Ap2, xn, xn, L_SUBFR, &state->mem_w0[M_BWD-m_ap], 0);    /* target signal xn[]*/                t0 = pitch_fr3cp(&state->exc[i_subfr], xn, h1, L_SUBFR, t0_min, t0_max,				i_subfr, &t0_frac, rate);                index = enc_lag3cp(t0, t0_frac, &t0_min, &t0_max,PIT_MIN,PIT_MAX,i_subfr, rate);                *ana++ = index;                if ( (i_subfr == 0) && (rate != G729D) )		{            *ana = parity_pitch(index);            if( rate == G729E) {                       *ana ^= ((index >> 1) & 0x0001);            }            ana++;        }        /*-----------------------------------------------------------------*        *   - find unity gain pitch excitation (adaptive codebook entry)  *        *     with fractional interpolation.                              *        *   - find filtered pitch exc. y1[]=exc[] convolve with h1[])     *        *   - compute pitch gain and limit between 0 and 1.2              *        *   - update target vector for codebook search                    *        *   - find LTP residual.                                          *        *-----------------------------------------------------------------*/        pred_lt_3(&state->exc[i_subfr], t0, t0_frac, L_SUBFR);                        convolve(&state->exc[i_subfr], h1, y1, L_SUBFR);                gain_pit = g_pitch(xn, y1, g_coeff, L_SUBFR);                /* clip pitch gain if taming is necessary */        taming = test_err(state->cng_s.exc_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.                       *        *-----------------------------------------------------*/                switch (rate)		{            case G729:    /* 8 kbit/s */            {                 index = ACELP_codebook(xn2, h1, t0, state->pit_sharp, i_subfr, code,                    y2, &i, &state->d4i40_17_extra);                *ana++ = index;        /* Positions index */                *ana++ = i;            /* Signs index     */                break;            }            case G729D:    /* 6.4 kbit/s */            {                index = ACELP_codebook64(xn2, h1, t0, state->pit_sharp, code, y2, &i);                *ana++ = index;        /* Positions index */                *ana++ = i;            /* Signs index     */                break;            }                            case G729E:    /* 11.8 kbit/s */            {            /*-----------------------------------------------------------------*            * Include fixed-gain pitch contribution into impulse resp. h[]    *                *-----------------------------------------------------------------*/                if (t0 < L_SUBFR) {                    for (i = t0; i < L_SUBFR; i++) {                        h1[i] += state->pit_sharp * h1[i-t0];                    }                }                                    /* calculate residual after long term prediction */                for (i = 0; i < L_SUBFR;  i++)                    res2[i] -= gain_pit * state->exc[i+i_subfr];                if (lp_mode == 0)                    ACELP_10i40_35bits(xn2, res2, h1, code, y2, ana); /* Forward */                else                    ACELP_12i40_44bits(xn2, res2, h1, code, y2, ana); /* Backward */                ana += 5;                                /*-----------------------------------------------------------------*                * Include fixed-gain pitch contribution into code[].              *                *-----------------------------------------------------------------*/                if(t0 < L_SUBFR)                    for (i = t0; i < L_SUBFR; i++)                        code[i] += state->pit_sharp * code[i-t0];                                    break;            }                        default : {                printf("Unrecognized bit rate\n");                return;            }                        }  /* end of switch */                                /*-----------------------------------------------------*        * - Quantization of gains.                            *        *-----------------------------------------------------*/        corr_xy2( xn, y1, y2, g_coeff);                if (rate == G729D)             index = qua_gain_6k(&state->gain_s, code, g_coeff, L_SUBFR, &gain_pit, &gain_code, taming);        else             index = qua_gain(&state->gain_s, code, g_coeff, L_SUBFR, &gain_pit, &gain_code, taming);                *ana++ = index;                /*------------------------------------------------------------*        * - Update pitch sharpening  with quantized gain_pit          *        *------------------------------------------------------------*/        for (i = 0; i < 4; i++)            state->pgain_buf[i] = state->pgain_buf[i+1];        state->pgain_buf[4] = gain_pit;        state->pit_sharp = gain_pit;        if (state->pit_sharp > SHARPMAX) state->pit_sharp = SHARPMAX;        if (state->pit_sharp < SHARPMIN) state->pit_sharp = SHARPMIN;                /*------------------------------------------------------*        * - Find the total excitation                          *        * - find synthesis speech corresponding to exc[]       *        * - update filters memories for finding the target     *        *   vector in the next subframe                        *        *   (update error[-m..-1] and mem_w_err[])             *        *   update error function for taming process           *        *------------------------------------------------------*/        for (i = 0; i < L_SUBFR;  i++)            state->exc[i+i_subfr] = gain_pit * state->exc[i+i_subfr] + gain_code*code[i];                update_exc_err(state->cng_s.exc_err, gain_pit, t0);                        syn_filte(m_aq,  pAq, &state->exc[i_subfr], &state->synth_ptr[i_subfr], L_SUBFR,            &state->mem_syn[M_BWD-m_aq], 0);        		/*for(j=0; j<M_BWD; j++) state->mem_syn[j] = state->synth_ptr[i_subfr+L_SUBFR-M_BWD+j];*/		copy(state->synth_ptr+i_subfr+L_SUBFR-M_BWD, state->mem_syn, M_BWD);                for (i = L_SUBFR-M_BWD, j = 0; i < L_SUBFR; i++, j++)		{            state->mem_err[j] = state->speech[i_subfr+i] - state->synth_ptr[i_subfr+i];            state->mem_w0[j]  = xn[i] - gain_pit*y1[i] - gain_code*y2[i];        }        pAp   += m_ap+1;        pAq   += m_aq+1;    }        /*--------------------------------------------------*    * Update signal for next frame.                    *    * -> shift to the left by L_FRAME:                 *    *     speech[], wsp[] and  exc[]                   *    *--------------------------------------------------*/    copy(&state->old_speech[L_FRAME], &state->old_speech[0], L_TOTAL-L_FRAME);    copy(&state->old_wsp[L_FRAME], &state->old_wsp[0], PIT_MAX);    copy(&state->old_exc[L_FRAME], &state->old_exc[0], PIT_MAX+L_INTERPOL);    state->prev_lp_mode = lp_mode;}

⌨️ 快捷键说明

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