📄 q_plsf_3.cpp
字号:
in DTX mode past_rq field of structure pointed to by st contains the current quantized LSF parameters pOverflow -- pointer to Flag -- Flag set when overflow occurs Returns: None Global Variables Used: pred_fac = table containing prediction factors (const Word16) dico1_lsf = quantization table for split_MQ of 2 sets of LSFs in a 20 ms frame (const Word16) dico2_lsf = quantization table for split_MQ of 2 sets of LSFs in a 20 ms frame (const Word16) dico3_lsf = quantization table for split_MQ of 2 sets of LSFs in a 20 ms frame (const Word16) mr515_3_lsf = third codebook for MR475 and MR515 modes (const Word16) mr795_1_lsf = first codebook for MR795 mode (const Word16) mean_lsf = table of mean LSFs (const Word16) past_rq_init = initalization table for MA predictor in DTX mode (const Word16) Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function performs quantization of LSF parameters with 1st order MA prediction and split by 3 vector quantization (split-VQ)------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES q_plsf_3.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001------------------------------------------------------------------------------ PSEUDO-CODEvoid Q_plsf_3( Q_plsfState *st, // i/o: state struct enum Mode mode, // i : coder mode Word16 *lsp1, // i : 1st LSP vector Q15 Word16 *lsp1_q, // o : quantized 1st LSP vector Q15 Word16 *indice, // o : quantization indices of 3 vectors Q0 Word16 *pred_init_i // o : init index for MA prediction in DTX mode){ Word16 i, j; Word16 lsf1[M], wf1[M], lsf_p[M], lsf_r1[M]; Word16 lsf1_q[M]; Word32 L_pred_init_err; Word32 L_min_pred_init_err; Word16 temp_r1[M]; Word16 temp_p[M]; // convert LSFs to normalize frequency domain 0..16384 Lsp_lsf(lsp1, lsf1, M); // compute LSF weighting factors (Q13) Lsf_wt(lsf1, wf1); // Compute predicted LSF and prediction error if (test(), sub(mode, MRDTX) != 0) { for (i = 0; i < M; i++) { lsf_p[i] = add(mean_lsf[i], mult(st->past_rq[i], pred_fac[i])); lsf_r1[i] = sub(lsf1[i], lsf_p[i]); } } else { // DTX mode, search the init vector that yields // lowest prediction resuidual energy *pred_init_i = 0; L_min_pred_init_err = 0x7fffffff; // 2^31 - 1 for (j = 0; j < PAST_RQ_INIT_SIZE; j++) { L_pred_init_err = 0; for (i = 0; i < M; i++) { temp_p[i] = add(mean_lsf[i], past_rq_init[j*M+i]); temp_r1[i] = sub(lsf1[i],temp_p[i]); L_pred_init_err = L_mac(L_pred_init_err, temp_r1[i], temp_r1[i]); } // next i if (L_sub(L_pred_init_err, L_min_pred_init_err) < (Word32) 0) { L_min_pred_init_err = L_pred_init_err; Copy(temp_r1, lsf_r1, M); Copy(temp_p, lsf_p, M); // Set zerom Copy(&past_rq_init[j*M], st->past_rq, M); *pred_init_i = j; } // endif } // next j } // endif MRDTX //---- Split-VQ of prediction error ---- if (sub (mode, MR475) == 0 || sub (mode, MR515) == 0) { // MR475, MR515 indice[0] = Vq_subvec3(&lsf_r1[0], dico1_lsf, &wf1[0], DICO1_SIZE, 0); indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE/2, 1); indice[2] = Vq_subvec4(&lsf_r1[6], mr515_3_lsf, &wf1[6], MR515_3_SIZE); } else if (sub (mode, MR795) == 0) { // MR795 indice[0] = Vq_subvec3(&lsf_r1[0], mr795_1_lsf, &wf1[0], MR795_1_SIZE, 0); indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE, 0); indice[2] = Vq_subvec4(&lsf_r1[6], dico3_lsf, &wf1[6], DICO3_SIZE); } else { // MR59, MR67, MR74, MR102 , MRDTX indice[0] = Vq_subvec3(&lsf_r1[0], dico1_lsf, &wf1[0], DICO1_SIZE, 0); indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE, 0); indice[2] = Vq_subvec4(&lsf_r1[6], dico3_lsf, &wf1[6], DICO3_SIZE); } // Compute quantized LSFs and update the past quantized residual for (i = 0; i < M; i++) { lsf1_q[i] = add(lsf_r1[i], lsf_p[i]); st->past_rq[i] = lsf_r1[i]; } // verification that LSFs has mimimum distance of LSF_GAP Hz Reorder_lsf(lsf1_q, LSF_GAP, M); // convert LSFs to the cosine domain Lsf_lsp(lsf1_q, lsp1_q, M);}------------------------------------------------------------------------------ RESOURCES USED [optional] When the code is written for a specific target processor the the resources used should be documented below. HEAP MEMORY USED: x bytes STACK MEMORY USED: x bytes CLOCK CYCLES: (cycle count equation for this function) + (variable used to represent cycle count for each subroutine called) where: (cycle count variable) = cycle count for [subroutine name]------------------------------------------------------------------------------ CAUTION [optional] [State any special notes, constraints or cautions for users of this function]------------------------------------------------------------------------------*/void Q_plsf_3( Q_plsfState *st, /* i/o: state struct */ enum Mode mode, /* i : coder mode */ Word16 *lsp1, /* i : 1st LSP vector Q15 */ Word16 *lsp1_q, /* o : quantized 1st LSP vector Q15 */ Word16 *indice, /* o : quantization indices of 3 vectors Q0 */ Word16 *pred_init_i,/* o : init index for MA prediction in DTX mode */ Flag *pOverflow /* o : Flag set when overflow occurs */){ register Word16 i, j; Word16 lsf1[M]; Word16 wf1[M]; Word16 lsf_p[M]; Word16 lsf_r1[M]; Word16 lsf1_q[M]; Word32 L_pred_init_err; Word32 L_min_pred_init_err; Word32 L_temp; Word16 temp_r1[M]; Word16 temp_p[M]; Word16 temp; /* convert LSFs to normalize frequency domain 0..16384 */ Lsp_lsf( lsp1, lsf1, M, pOverflow); /* compute LSF weighting factors (Q13) */ Lsf_wt( lsf1, wf1, pOverflow); /* Compute predicted LSF and prediction error */ if (mode != MRDTX) { for (i = 0; i < M; i++) { temp = (Word16)((((Word32) st->past_rq[i]) * (*(pred_fac_3 + i))) >> 15); *(lsf_p + i) = *(mean_lsf_3 + i) + temp; *(lsf_r1 + i) = *(lsf1 + i) - *(lsf_p + i); } } else { /* DTX mode, search the init vector that yields */ /* lowest prediction resuidual energy */ *pred_init_i = 0; L_min_pred_init_err = 0x7fffffff; /* 2^31 - 1 */ for (j = 0; j < PAST_RQ_INIT_SIZE; j++) { L_pred_init_err = 0; for (i = 0; i < M; i++) { *(temp_p + i) = *(mean_lsf_3 + i) + *(past_rq_init + j * M + i); *(temp_r1 + i) = *(lsf1 + i) - *(temp_p + i); L_temp = ((Word32) * (temp_r1 + i)) * *(temp_r1 + i); L_pred_init_err = L_pred_init_err + (L_temp << 1); } /* next i */ if (L_pred_init_err < L_min_pred_init_err) { L_min_pred_init_err = L_pred_init_err; oscl_memcpy( lsf_r1, temp_r1, M*sizeof(Word16)); oscl_memcpy( lsf_p, temp_p, M*sizeof(Word16)); /* Set zerom */ oscl_memcpy( st->past_rq, &past_rq_init[j*M], M*sizeof(Word16)); *pred_init_i = j; } /* endif */ } /* next j */ } /* endif MRDTX */ /*---- Split-VQ of prediction error ----*/ if ((mode == MR475) || (mode == MR515)) { /* MR475, MR515 */ *indice = Vq_subvec3( lsf_r1, dico1_lsf_3, wf1, DICO1_SIZE, 0, pOverflow); *(indice + 1) = Vq_subvec3( lsf_r1 + 3, dico2_lsf_3, wf1 + 3, DICO2_SIZE / 2, 1, pOverflow); *(indice + 2) = Vq_subvec4( lsf_r1 + 6, mr515_3_lsf, wf1 + 6, MR515_3_SIZE, pOverflow); } else if (mode == MR795) { /* MR795 */ *indice = Vq_subvec3( lsf_r1, mr795_1_lsf, wf1, MR795_1_SIZE, 0, pOverflow); *(indice + 1) = Vq_subvec3( lsf_r1 + 3, dico2_lsf_3, wf1 + 3, DICO2_SIZE, 0, pOverflow); *(indice + 2) = Vq_subvec4( lsf_r1 + 6, dico3_lsf_3, wf1 + 6, DICO3_SIZE, pOverflow); } else { /* MR59, MR67, MR74, MR102 , MRDTX */ *indice = Vq_subvec3( lsf_r1, dico1_lsf_3, wf1, DICO1_SIZE, 0, pOverflow); *(indice + 1) = Vq_subvec3( lsf_r1 + 3, dico2_lsf_3, wf1 + 3, DICO2_SIZE, 0, pOverflow); *(indice + 2) = Vq_subvec4( lsf_r1 + 6, dico3_lsf_3, wf1 + 6, DICO3_SIZE, pOverflow); } /* Compute quantized LSFs and update the past quantized residual */ for (i = 0; i < M; i++) { *(lsf1_q + i) = *(lsf_r1 + i) + *(lsf_p + i); st->past_rq[i] = *(lsf_r1 + i); } /* verification that LSFs has mimimum distance of LSF_GAP Hz */ Reorder_lsf( lsf1_q, LSF_GAP, M, pOverflow); /* convert LSFs to the cosine domain */ Lsf_lsp( lsf1_q, lsp1_q, M, pOverflow); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -