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

📄 cod_ld8c.c

📁 语音编码G.729 语音编码G.729
💻 C
📖 第 1 页 / 共 2 页
字号:
      /* update mem_syn */      syn_filte(M, Aq, &state->exc[i_subfr], &synth[i_subfr], L_SUBFR, state->mem_syn, 1);      /* update mem_w0 */      for (i=0; i<L_SUBFR; i++)        state->error[i] = state->speech[i_subfr+i] - synth[i_subfr+i];      residue(M, Ap1, state->error, xn, L_SUBFR);      syn_filte(M, Ap2, xn, xn, L_SUBFR, state->mem_w0, 1);      /* update mem_err */      for (i = L_SUBFR-M, j = 0; i < L_SUBFR; i++, j++)        state->mem_err[j] = state->error[i];             A  += MP1;      Aq += MP1;    }        state->sharp = SHARPMIN;        /* Update memories for next frames */    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);        return;  }  /* End of inactive frame case */      /* -------------------- */  /* Case of Active frame */  /* -------------------- */    	*ana++ = 1;	state->seed = INIT_SEED;	state->ppastVad = state->pastVad;	state->pastVad = Vad;  /* LSP quantization */  qua_lspe(lsp_new, lsp_new_q, ana, state->lsp_s.freq_prev, freq_cur);  lsp_prev_update(freq_cur, state->lsp_s.freq_prev);  ana += 2;                         /* Advance analysis parameters pointer */  /*--------------------------------------------------------------------*   * Find interpolated LPC parameters in all subframes (quantized)      *   * The interpolated parameters are in array Aq_t[] of size (M+1)*4    *   *--------------------------------------------------------------------*/  int_qlpc(state->lsp_old_q, lsp_new_q, Aq_t);  /* update the LSPs for the next frame */  copy(lsp_new_q, state->lsp_old_q, M);  /* Find open loop pitch lag for whole speech frame */  T_op = pitch_ol(state->wsp, PIT_MIN, PIT_MAX, L_FRAME);  /* range for closed loop pitch search in 1st subframe */  t0_min = T_op - 3;  if (t0_min < PIT_MIN) t0_min = PIT_MIN;  t0_max = t0_min + 6;  if (t0_max > PIT_MAX)    {       t0_max = PIT_MAX;       t0_min = t0_max - 6;    } /*------------------------------------------------------------------------*  *          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 L_FRAME/L_SUBFR times.               *  *     - find the weighted LPC coefficients                               *  *     - find the LPC residual signal                                     *  *     - 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                                *  *------------------------------------------------------------------------*/  A  = A_t;     /* pointer to interpolated LPC parameters           */  Aq = Aq_t;    /* 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(A, gamma1[i_gamma], M, Ap1);    weight_az(A, gamma2[i_gamma], M, Ap2);    i_gamma++;   /*---------------------------------------------------------------*    * Compute impulse response, h1[], of weighted synthesis filter  *    *---------------------------------------------------------------*/    for (i = 0; i <= M; i++) state->ai_zero[i] = Ap1[i];    syn_filte(M, Aq, state->ai_zero, h1, L_SUBFR, state->zero, 0);    syn_filte(M, 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, &state->speech[i_subfr], &state->exc[i_subfr], L_SUBFR);   /* LPC residual */    syn_filte(M, Aq, &state->exc[i_subfr], state->error, L_SUBFR, state->mem_err, 0);    residue(M, Ap1, state->error, xn, L_SUBFR);    syn_filte(M, Ap2, xn, xn, L_SUBFR, state->mem_w0, 0);    /* target signal xn[]*/   /*----------------------------------------------------------------------*    *                 Closed-loop fractional pitch search                  *    *----------------------------------------------------------------------*/    t0 = pitch_fr3cp(&state->exc[i_subfr], xn, h1, L_SUBFR, t0_min, t0_max,                              i_subfr, &t0_frac, G729);    index = enc_lag3cp(t0, t0_frac, &t0_min, &t0_max,PIT_MIN,PIT_MAX,i_subfr, G729);    *ana++ = index;    if (i_subfr == 0)      *ana++ = parity_pitch(index);   /*-----------------------------------------------------------------*    *   - 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.                       *    *-----------------------------------------------------*/    index = ACELP_codebook(xn2, h1, t0, state->sharp, i_subfr, code, y2, &i, &state->d4i40_17_extra);    *ana++ = index;        /* Positions index */    *ana++ = i;            /* Signs index     */   /*-----------------------------------------------------*    * - Quantization of gains.                            *    *-----------------------------------------------------*/    corr_xy2(xn, y1, y2, g_coeff);    *ana++ = qua_gain(&state->gain_s, code, g_coeff, L_SUBFR, &gain_pit, &gain_code, taming);   /*------------------------------------------------------------*    * - Update pitch sharpening "sharp" with quantized gain_pit  *    *------------------------------------------------------------*/    state->sharp = gain_pit;    if (state->sharp > SHARPMAX) state->sharp = SHARPMAX;    if (state->sharp < SHARPMIN) state->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_w0[])                *     *   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, &state->exc[i_subfr], &synth[i_subfr], L_SUBFR, state->mem_syn, 1);    for (i = L_SUBFR-M, j = 0; i < L_SUBFR; i++, j++)      {         state->mem_err[j] = state->speech[i_subfr+i] - synth[i_subfr+i];         state->mem_w0[j]  = xn[i] - gain_pit*y1[i] - gain_code*y2[i];      }    A  += MP1;      /* interpolated LPC parameters for next subframe */    Aq += MP1;  }  /*--------------------------------------------------*   * 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);}

⌨️ 快捷键说明

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