示例#1
0
/*-----------------------------------------------------------------*
 * Functions lsfq_noise                                            *
 *           ~~~~~~~~~~                                            *
 * Input:                                                          *
 *   lsp[]         : unquantized lsp vector                        *
 *   freq_prev[][] : memory of the lsf predictor                   *
 *                                                                 *
 * Output:                                                         *
 *                                                                 *
 *   lspq[]        : quantized lsp vector                          * 
 *   ana[]         : indices                                       *
 *                                                                 *
 *-----------------------------------------------------------------*/
void lsfq_noise(float * lsp, float * lspq, float freq_prev[MA_NP][M], int *ana)
{
	int i, MS[MODE] = { 32, 16 }, Clust[MODE], mode;
	float lsf[M], lsfq[M], weight[M], tmpbuf[M], errlsf[M * MODE];

	/* convert lsp to lsf */
	for (i = 0; i < M; i++)
		lsf[i] = (float) acos(lsp[i]);

	/* spacing to ~100Hz */
	if (lsf[0] < L_LIMIT)
		lsf[0] = L_LIMIT;
	for (i = 0; i < M - 1; i++) {
		if (lsf[i + 1] - lsf[i] < 2 * GAP3)
			lsf[i + 1] = lsf[i] + 2 * GAP3;
	}
	if (lsf[M - 1] > M_LIMIT)
		lsf[M - 1] = M_LIMIT;
	if (lsf[M - 1] < lsf[M - 2])
		lsf[M - 2] = lsf[M - 1] - GAP3;

	/* get the lsf weighting */
	get_wegt(lsf, weight);

    /**********************/
	/* quantize the lsf's */
    /**********************/
	/* get the prediction error vector */
	for (mode = 0; mode < MODE; mode++)
		lsp_prev_extract(lsf, errlsf + mode * M, noise_fg[mode],
				 freq_prev, noise_fg_sum_inv[mode]);

	/* quantize the lsf and get the corresponding indices */
	Qnt_e(errlsf, weight, MODE, tmpbuf, &mode, 1, Clust, MS);
	ana[0] = (int)mode;
	ana[1] = (int)Clust[0];
	ana[2] = (int)Clust[1];

	/* guarantee minimum distance of 0.0012 between tmpbuf[j]
	   and tmpbuf[j+1] */
	lsp_expand_1_2(tmpbuf, (float) 0.0012);

	/* compute the quantized lsf vector */
	lsp_prev_compose(tmpbuf, lsfq, noise_fg[mode], freq_prev,
			 noise_fg_sum[mode]);

	/* update the prediction memory */
	lsp_prev_update(tmpbuf, freq_prev);

	/* lsf stability check */
	lsp_stability(lsfq);

	/* convert lsf to lsp */
	for (i = 0; i < M; i++)
		lspq[i] = (float) cos(lsfq[i]);

	return;
}
示例#2
0
/*----------------------------------------------------------------------------
 * relspwed -
 *----------------------------------------------------------------------------
 */
static void relspwed(
 GFLOAT  lsp[],                  /*input: unquantized LSP parameters  */
 GFLOAT  wegt[],                 /*input: weight coef.                */
 GFLOAT  lspq[],                 /*output:quantized LSP parameters    */
 const GFLOAT  lspcb1[][M],            /*input: first stage LSP codebook    */
 const GFLOAT  lspcb2[][M],            /*input: Second stage LSP codebook   */
 const GFLOAT  fg[MODE][MA_NP][M],     /*input: MA prediction coef.         */
 GFLOAT  freq_prev[MA_NP][M],    /*input: previous LSP vector         */
 const GFLOAT  fg_sum[MODE][M],        /*input: present MA prediction coef. */
 const GFLOAT  fg_sum_inv[MODE][M],    /*input: inverse coef.               */
 int    code_ana[]              /*output:codes of the selected LSP   */
)
{
   int  mode, j;
   int  index, mode_index;
   int  cand[MODE], cand_cur;
   int  tindex1[MODE], tindex2[MODE];
   GFLOAT        tdist[MODE];
   GFLOAT        rbuf[M];
   GFLOAT        buf[M];

   for(mode = 0; mode<MODE; mode++)
   {
      lsp_prev_extract(lsp, rbuf, fg[mode], freq_prev, fg_sum_inv[mode]);

      /*----- search the first stage lsp codebook -----*/
      lsp_pre_select(rbuf, lspcb1, &cand_cur);
      cand[mode]=cand_cur;

      /*----- search the second stage lsp codebook (lower 0-4) ----- */
      lsp_select_1(rbuf, lspcb1[cand_cur], wegt, lspcb2, &index);

      tindex1[mode] = index;

      for(j=0; j<NC; j++)
        buf[j]=lspcb1[cand_cur][j]+lspcb2[index][j];

      lsp_expand_1(buf, GAP1);  /* check */

      /*----- search the second stage lsp codebook (Higher 5-9) ----- */
      lsp_select_2(rbuf, lspcb1[cand_cur], wegt, lspcb2,
                   &index);

      tindex2[mode] = index;

      for(j=NC; j<M; j++)
        buf[j]=lspcb1[cand_cur][j]+lspcb2[index][j];
      lsp_expand_2(buf, GAP1);  /* check */


      /* check */
      lsp_expand_1_2(buf, GAP2);

      lsp_get_tdist(wegt, buf, &tdist[mode], rbuf,
                    fg_sum[mode]);  /* calculate the distortion */

   } /* mode */


   lsp_last_select(tdist, &mode_index); /* select the codes */

   /* pack codes for lsp parameters */
   code_ana[0] = (mode_index<<NC0_B) | cand[mode_index];
   code_ana[1] = (tindex1[mode_index]<<NC1_B) | tindex2[mode_index];

   /* reconstruct quantized LSP parameter and check the stabilty */
   lsp_get_quant(lspcb1, lspcb2, cand[mode_index],
                 tindex1[mode_index], tindex2[mode_index],
                 fg[mode_index],
                 freq_prev,
                 lspq, fg_sum[mode_index]);
}