123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- /*
- *****************************************************************************
- *
- * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
- * R99 Version 3.3.0
- * REL-4 Version 4.1.0
- *
- ****************************************************************************
- *
- * File : q_plsf_3.c
- * Purpose : Quantization of LSF parameters with 1st order MA
- * prediction and split by 3 vector quantization
- * (split-VQ)
- *
- *****************************************************************************
- */
- /*
- *****************************************************************************
- * MODULE INCLUDE FILE AND VERSION ID
- *****************************************************************************
- */
- #include "q_plsf.h"
- const char q_plsf_3_id[] = "@(#)$Id $" q_plsf_h;
-
- /*
- *****************************************************************************
- * INCLUDE FILES
- *****************************************************************************
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include "typedef.h"
- #include "basic_op.h"
- #include "count.h"
- #include "lsp_lsf.h"
- #include "reorder.h"
- #include "lsfwt.h"
- #include "copy.h"
- /*
- *****************************************************************************
- * LOCAL VARIABLES AND TABLES
- *****************************************************************************
- */
- #include "q_plsf_3.tab" /* Codebooks of LSF prediction residual */
- #define PAST_RQ_INIT_SIZE 8
- /*
- *****************************************************************************
- * LOCAL PROGRAM CODE
- *****************************************************************************
- */
- /* Quantization of a 4 dimensional subvector */
- static Word16
- Vq_subvec4( /* o: quantization index, Q0 */
- Word16 * lsf_r1, /* i: 1st LSF residual vector, Q15 */
- Word16 * dico, /* i: quantization codebook, Q15 */
- Word16 * wf1, /* i: 1st LSF weighting factors, Q13 */
- Word16 dico_size) /* i: size of quantization codebook, Q0 */
- {
- Word16 i, index = 0;
- Word16 *p_dico, temp;
- Word32 dist_min, dist;
- dist_min = MAX_32; move32 ();
- p_dico = dico; move16 ();
- for (i = 0; i < dico_size; i++)
- {
- temp = sub_ex (lsf_r1[0], *p_dico++);
- temp = mult_ex (wf1[0], temp);
- dist = L_mult_ex (temp, temp);
- temp = sub_ex (lsf_r1[1], *p_dico++);
- temp = mult_ex (wf1[1], temp);
- dist = L_mac_ex (dist, temp, temp);
- temp = sub_ex (lsf_r1[2], *p_dico++);
- temp = mult_ex (wf1[2], temp);
- dist = L_mac_ex (dist, temp, temp);
- temp = sub_ex (lsf_r1[3], *p_dico++);
- temp = mult_ex (wf1[3], temp);
- dist = L_mac_ex (dist, temp, temp);
- test ();
- if (L_sub_ex (dist, dist_min) < (Word32) 0)
- {
- dist_min = dist; move32 ();
- index = i; move16 ();
- }
- }
- /* Reading the selected vector */
- p_dico = &dico[shl_ex (index, 2)]; move16 ();
- lsf_r1[0] = *p_dico++; move16 ();
- lsf_r1[1] = *p_dico++; move16 ();
- lsf_r1[2] = *p_dico++; move16 ();
- lsf_r1[3] = *p_dico++; move16 ();
- return index;
- }
- /* Quantization of a 3 dimensional subvector */
- static Word16
- Vq_subvec3( /* o: quantization index, Q0 */
- Word16 * lsf_r1, /* i: 1st LSF residual vector, Q15 */
- Word16 * dico, /* i: quantization codebook, Q15 */
- Word16 * wf1, /* i: 1st LSF weighting factors, Q13 */
- Word16 dico_size, /* i: size of quantization codebook, Q0 */
- Flag use_half) /* i: use every second entry in codebook */
- {
- Word16 i, index = 0;
- Word16 *p_dico, temp;
- Word32 dist_min, dist;
- dist_min = MAX_32; move32 ();
- p_dico = dico; move16 ();
- test ();
- if (use_half == 0) {
- for (i = 0; i < dico_size; i++)
- {
- temp = sub_ex(lsf_r1[0], *p_dico++);
- temp = mult_ex(wf1[0], temp);
- dist = L_mult_ex(temp, temp);
-
- temp = sub_ex(lsf_r1[1], *p_dico++);
- temp = mult_ex(wf1[1], temp);
- dist = L_mac_ex(dist, temp, temp);
-
- temp = sub_ex(lsf_r1[2], *p_dico++);
- temp = mult_ex(wf1[2], temp);
- dist = L_mac_ex(dist, temp, temp);
- test ();
- if (L_sub_ex(dist, dist_min) < (Word32) 0) {
- dist_min = dist; move32 ();
- index = i; move16 ();
- }
- }
- p_dico = &dico[add_ex(index, add_ex(index, index))]; move16 ();
- }
- else
- {
- for (i = 0; i < dico_size; i++)
- {
- temp = sub_ex(lsf_r1[0], *p_dico++);
- temp = mult_ex(wf1[0], temp);
- dist = L_mult_ex(temp, temp);
- temp = sub_ex(lsf_r1[1], *p_dico++);
- temp = mult_ex(wf1[1], temp);
- dist = L_mac_ex(dist, temp, temp);
-
- temp = sub_ex(lsf_r1[2], *p_dico++);
- temp = mult_ex(wf1[2], temp);
- dist = L_mac_ex(dist, temp, temp);
-
- test ();
- if (L_sub_ex(dist, dist_min) < (Word32) 0)
- {
- dist_min = dist; move32 ();
- index = i; move16 ();
- }
- p_dico = p_dico + 3; add_ex(0,0);
- }
- p_dico = &dico[shl_ex(add_ex(index, add_ex(index, index)),1)]; move16 ();
- }
-
- /* Reading the selected vector */
- lsf_r1[0] = *p_dico++; move16 ();
- lsf_r1[1] = *p_dico++; move16 ();
- lsf_r1[2] = *p_dico++; move16 ();
- return index;
- }
- /*
- *****************************************************************************
- * PUBLIC PROGRAM CODE
- *****************************************************************************
- */
- /***********************************************************************
- *
- * routine: Q_plsf_3()
- *
- * Quantization of LSF parameters with 1st order MA prediction and
- * split by 3 vector quantization (split-VQ)
- *
- ***********************************************************************/
- 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 */
- )
- {
- 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_ex(mode, MRDTX) != 0)
- {
- for (i = 0; i < M; i++)
- {
- lsf_p[i] = add_ex(mean_lsf[i],
- mult_ex(st->past_rq[i],
- pred_fac[i])); move16 ();
- lsf_r1[i] = sub_ex(lsf1[i], lsf_p[i]); move16 ();
- }
- }
- else
- {
- /* DTX mode, search the init vector that yields */
- /* lowest prediction resuidual energy */
- *pred_init_i = 0; move16 ();
- L_min_pred_init_err = 0x7fffffff; /* 2^31 - 1 */ move32 ();
- for (j = 0; j < PAST_RQ_INIT_SIZE; j++)
- {
- L_pred_init_err = 0; move32 ();
- for (i = 0; i < M; i++)
- {
- temp_p[i] = add_ex(mean_lsf[i], past_rq_init[j*M+i]);
- temp_r1[i] = sub_ex(lsf1[i],temp_p[i]);
- L_pred_init_err = L_mac_ex(L_pred_init_err, temp_r1[i], temp_r1[i]);
- } /* next i */
- test ();
- if (L_sub_ex(L_pred_init_err, L_min_pred_init_err) < (Word32) 0)
- {
- L_min_pred_init_err = L_pred_init_err; move32 ();
- 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; move16 ();
- } /* endif */
- } /* next j */
- } /* endif MRDTX */
-
- /*---- Split-VQ of prediction error ----*/
- if (sub_ex (mode, MR475) == 0 || sub_ex (mode, MR515) == 0)
- { /* MR475, MR515 */
- test (); test ();
-
- indice[0] = Vq_subvec3(&lsf_r1[0], dico1_lsf, &wf1[0], DICO1_SIZE, 0);
- move16 ();
- indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE/2, 1);
- move16 ();
- indice[2] = Vq_subvec4(&lsf_r1[6], mr515_3_lsf, &wf1[6], MR515_3_SIZE);
- move16 ();
- }
- else if (sub_ex (mode, MR795) == 0)
- { /* MR795 */
- test (); test (); test ();
-
- indice[0] = Vq_subvec3(&lsf_r1[0], mr795_1_lsf, &wf1[0], MR795_1_SIZE, 0);
- move16 ();
- indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE, 0);
- move16 ();
- indice[2] = Vq_subvec4(&lsf_r1[6], dico3_lsf, &wf1[6], DICO3_SIZE);
- move16 ();
- }
- else
- { /* MR59, MR67, MR74, MR102 , MRDTX */
- test (); test (); test ();
- indice[0] = Vq_subvec3(&lsf_r1[0], dico1_lsf, &wf1[0], DICO1_SIZE, 0);
- move16 ();
- indice[1] = Vq_subvec3(&lsf_r1[3], dico2_lsf, &wf1[3], DICO2_SIZE, 0);
- move16 ();
- indice[2] = Vq_subvec4(&lsf_r1[6], dico3_lsf, &wf1[6], DICO3_SIZE);
- move16 ();
- }
-
- /* Compute quantized LSFs and update the past quantized residual */
- for (i = 0; i < M; i++)
- {
- lsf1_q[i] = add_ex(lsf_r1[i], lsf_p[i]); move16 ();
- st->past_rq[i] = lsf_r1[i]; move16 ();
- }
- /* 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);
- }
|