/** * LSP main quantization routine * * @param prm input : codes of the selected LSP * @param prm_offset input : codes offset * @param lsp_q output: Quantized LSP parameters * @param erase input : frame erase information */ private void lsp_iqua_cs( int[] prm, int prm_offset, float[] lsp_q, int erase ) { var NC0 = Ld8k.NC0; var NC0_B = Ld8k.NC0_B; var NC1 = Ld8k.NC1; var NC1_B = Ld8k.NC1_B; var fg = TabLd8k.fg; var fg_sum = TabLd8k.fg_sum; var fg_sum_inv = TabLd8k.fg_sum_inv; var lspcb1 = TabLd8k.lspcb1; var lspcb2 = TabLd8k.lspcb2; int mode_index; int code0; int code1; int code2; var buf = new float[M]; if (erase == 0) /* Not frame erasure */ { mode_index = ZFRS(prm[prm_offset + 0], NC0_B) & 1; code0 = prm[prm_offset + 0] & (short)(NC0 - 1); code1 = ZFRS(prm[prm_offset + 1], NC1_B) & (short)(NC1 - 1); code2 = prm[prm_offset + 1] & (short)(NC1 - 1); Lspgetq.lsp_get_quant( lspcb1, lspcb2, code0, code1, code2, fg[mode_index], freq_prev, lsp_q, fg_sum[mode_index]); Util.copy(lsp_q, prev_lsp, M); prev_ma = mode_index; } else /* Frame erased */ { Util.copy(prev_lsp, lsp_q, M); /* update freq_prev */ Lspgetq.lsp_prev_extract( prev_lsp, buf, fg[prev_ma], freq_prev, fg_sum_inv[prev_ma]); Lspgetq.lsp_prev_update(buf, freq_prev); } }
/** * * @param lsp input: unquantized LSP parameters * @param wegt input: weight coef. * @param lspq output:quantized LSP parameters * @param lspcb1 input : first stage LSP codebook * @param lspcb2 input: Second stage LSP codebook * @param fg input: MA prediction coef. * @param freq_prev input: previous LSP vector * @param fg_sum input: present MA prediction coef. * @param fg_sum_inv input: inverse coef. * @param code_ana output:codes of the selected LSP */ private void relspwed( float[] lsp, float[] wegt, float[] lspq, float[][] /* M */ lspcb1, float[][] /* M */ lspcb2, float[] /* MODE */ [] /* MA_NP */ [] /* M */ fg, float[] /* MA_NP */ [] /* M */ freq_prev, float[] /* MODE */ [] /* M */ fg_sum, float[] /* MODE */ [] /* M */ fg_sum_inv, int[] code_ana ) { var GAP1 = Ld8k.GAP1; var GAP2 = Ld8k.GAP2; var M = Ld8k.M; var MODE = Ld8k.MODE; var NC = Ld8k.NC; var NC0_B = Ld8k.NC0_B; var NC1_B = Ld8k.NC1_B; int mode, j; int index, mode_index; var cand = new int[MODE]; int cand_cur; int[] tindex1 = new int[MODE], tindex2 = new int[MODE]; var tdist = new float[MODE]; var rbuf = new float[M]; var buf = new float[M]; for (mode = 0; mode < MODE; mode++) { Lspgetq.lsp_prev_extract(lsp, rbuf, fg[mode], freq_prev, fg_sum_inv[mode]); /*----- search the first stage lsp codebook -----*/ cand_cur = lsp_pre_select(rbuf, lspcb1); cand[mode] = cand_cur; /*----- search the second stage lsp codebook (lower 0-4) ----- */ index = lsp_select_1(rbuf, lspcb1[cand_cur], wegt, lspcb2); tindex1[mode] = index; for (j = 0; j < NC; j++) { buf[j] = lspcb1[cand_cur][j] + lspcb2[index][j]; } Lspgetq.lsp_expand_1(buf, GAP1); /* check */ /*----- search the second stage lsp codebook (Higher 5-9) ----- */ index = lsp_select_2(rbuf, lspcb1[cand_cur], wegt, lspcb2); tindex2[mode] = index; for (j = NC; j < M; j++) { buf[j] = lspcb1[cand_cur][j] + lspcb2[index][j]; } Lspgetq.lsp_expand_2(buf, GAP1); /* check */ /* check */ Lspgetq.lsp_expand_1_2(buf, GAP2); tdist[mode] = lsp_get_tdist(wegt, buf, rbuf, fg_sum[mode]); /* calculate the distortion */ } /* mode */ mode_index = lsp_last_select(tdist); /* 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 */ Lspgetq.lsp_get_quant( lspcb1, lspcb2, cand[mode_index], tindex1[mode_index], tindex2[mode_index], fg[mode_index], freq_prev, lspq, fg_sum[mode_index]); }