123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- /*
- ********************************************************************************
- *
- * 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_5.c
- * Purpose : Quantization of 2 sets of LSF parameters using 1st
- * order MA prediction and split by 5 matrix
- * quantization (split-MQ)
- *
- ********************************************************************************
- */
-
-
- /*
- ********************************************************************************
- * MODULE INCLUDE FILE AND VERSION ID
- ********************************************************************************
- */
- #include "q_plsf.h"
- const char q_plsf_5_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"
- /*
- ********************************************************************************
- * LOCAL VARIABLES AND TABLES
- ********************************************************************************
- */
- #include "q_plsf_5.tab" /* Codebooks of LSF prediction residual */
-
- /*
- ********************************************************************************
- * LOCAL PROGRAM CODE
- ********************************************************************************
- */
- /* Quantization of a 4 dimensional subvector */
- static Word16 Vq_subvec (/* o : quantization index, Q0 */
- Word16 *lsf_r1, /* i : 1st LSF residual vector, Q15 */
- Word16 *lsf_r2, /* i : 2nd LSF residual vector, Q15 */
- const Word16 *dico, /* i : quantization codebook, Q15 */
- Word16 *wf1, /* i : 1st LSF weighting factors Q13 */
- Word16 *wf2, /* i : 2nd LSF weighting factors Q13 */
- Word16 dico_size /* i : size of quantization codebook, Q0 */
- )
- {
- Word16 index = 0; /* initialization only needed to keep gcc silent */
- Word16 i, temp;
- const Word16 *p_dico;
- 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_r2[0], *p_dico++);
- temp = mult_ex (wf2[0], temp);
- dist = L_mac_ex (dist, temp, temp);
- temp = sub_ex (lsf_r2[1], *p_dico++);
- temp = mult_ex (wf2[1], 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_r2[0] = *p_dico++; move16 ();
- lsf_r2[1] = *p_dico++; move16 ();
- return index;
- }
- /* Quantization of a 4 dimensional subvector with a signed codebook */
- static Word16 Vq_subvec_s ( /* o : quantization index Q0 */
- Word16 *lsf_r1, /* i : 1st LSF residual vector Q15 */
- Word16 *lsf_r2, /* i : and LSF residual vector Q15 */
- const Word16 *dico, /* i : quantization codebook Q15 */
- Word16 *wf1, /* i : 1st LSF weighting factors Q13 */
- Word16 *wf2, /* i : 2nd LSF weighting factors Q13 */
- Word16 dico_size) /* i : size of quantization codebook Q0 */
- {
- Word16 index = 0; /* initialization only needed to keep gcc silent */
- Word16 sign = 0; /* initialization only needed to keep gcc silent */
- Word16 i, temp;
- const Word16 *p_dico;
- Word32 dist_min, dist;
- dist_min = MAX_32; move32 ();
- p_dico = dico; move16 ();
- for (i = 0; i < dico_size; i++)
- {
- /* test positive */
- 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_r2[0], *p_dico++);
- temp = mult_ex (wf2[0], temp);
- dist = L_mac_ex (dist, temp, temp);
- temp = sub_ex (lsf_r2[1], *p_dico++);
- temp = mult_ex (wf2[1], 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 ();
- sign = 0; move16 ();
- }
- /* test negative */
- p_dico -= 4; move16 ();
- temp = add_ex (lsf_r1[0], *p_dico++);
- temp = mult_ex (wf1[0], temp);
- dist = L_mult_ex (temp, temp);
- temp = add_ex (lsf_r1[1], *p_dico++);
- temp = mult_ex (wf1[1], temp);
- dist = L_mac_ex (dist, temp, temp);
- temp = add_ex (lsf_r2[0], *p_dico++);
- temp = mult_ex (wf2[0], temp);
- dist = L_mac_ex (dist, temp, temp);
- temp = add_ex (lsf_r2[1], *p_dico++);
- temp = mult_ex (wf2[1], 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 ();
- sign = 1; move16 ();
- }
- }
- /* Reading the selected vector */
- p_dico = &dico[shl_ex (index, 2)]; move16 ();
- test ();
- if (sign == 0)
- {
- lsf_r1[0] = *p_dico++; move16 ();
- lsf_r1[1] = *p_dico++; move16 ();
- lsf_r2[0] = *p_dico++; move16 ();
- lsf_r2[1] = *p_dico++; move16 ();
- }
- else
- {
- lsf_r1[0] = negate_ex (*p_dico++); move16 ();
- lsf_r1[1] = negate_ex (*p_dico++); move16 ();
- lsf_r2[0] = negate_ex (*p_dico++); move16 ();
- lsf_r2[1] = negate_ex (*p_dico++); move16 ();
- }
- index = shl_ex (index, 1);
- index = add_ex (index, sign);
- return index;
- }
- /*
- ********************************************************************************
- * PUBLIC PROGRAM CODE
- ********************************************************************************
- */
-
- /*************************************************************************
- * FUNCTION: Q_plsf_5()
- *
- * PURPOSE: Quantization of 2 sets of LSF parameters using 1st order MA
- * prediction and split by 5 matrix quantization (split-MQ)
- *
- * DESCRIPTION:
- *
- * p[i] = pred_factor*past_rq[i]; i=0,...,m-1
- * r1[i]= lsf1[i] - p[i]; i=0,...,m-1
- * r2[i]= lsf2[i] - p[i]; i=0,...,m-1
- * where:
- * lsf1[i] 1st mean-removed LSF vector.
- * lsf2[i] 2nd mean-removed LSF vector.
- * r1[i] 1st residual prediction vector.
- * r2[i] 2nd residual prediction vector.
- * past_r2q[i] Past quantized residual (2nd vector).
- *
- * The residual vectors r1[i] and r2[i] are jointly quantized using
- * split-MQ with 5 codebooks. Each 4th dimension submatrix contains 2
- * elements from each residual vector. The 5 submatrices are as follows:
- * {r1[0], r1[1], r2[0], r2[1]}; {r1[2], r1[3], r2[2], r2[3]};
- * {r1[4], r1[5], r2[4], r2[5]}; {r1[6], r1[7], r2[6], r2[7]};
- * {r1[8], r1[9], r2[8], r2[9]};
- *
- *************************************************************************/
- void Q_plsf_5 (
- Q_plsfState *st,
- Word16 *lsp1, /* i : 1st LSP vector, Q15 */
- Word16 *lsp2, /* i : 2nd LSP vector, Q15 */
- Word16 *lsp1_q, /* o : quantized 1st LSP vector, Q15 */
- Word16 *lsp2_q, /* o : quantized 2nd LSP vector, Q15 */
- Word16 *indice /* o : quantization indices of 5 matrices, Q0 */
- )
- {
- Word16 i;
- Word16 lsf1[M], lsf2[M], wf1[M], wf2[M], lsf_p[M], lsf_r1[M], lsf_r2[M];
- Word16 lsf1_q[M], lsf2_q[M];
- /* convert LSFs to normalize frequency domain 0..16384 */
- Lsp_lsf (lsp1, lsf1, M);
- Lsp_lsf (lsp2, lsf2, M);
- /* Compute LSF weighting factors (Q13) */
-
- Lsf_wt (lsf1, wf1);
- Lsf_wt (lsf2, wf2);
- /* Compute predicted LSF and prediction error */
- for (i = 0; i < M; i++)
- {
- lsf_p[i] = add_ex (mean_lsf[i], mult_ex (st->past_rq[i], LSP_PRED_FAC_MR122));
- move16 ();
- lsf_r1[i] = sub_ex (lsf1[i], lsf_p[i]); move16 ();
- lsf_r2[i] = sub_ex (lsf2[i], lsf_p[i]); move16 ();
- }
- /*---- Split-MQ of prediction error ----*/
- indice[0] = Vq_subvec (&lsf_r1[0], &lsf_r2[0], dico1_lsf,
- &wf1[0], &wf2[0], DICO1_SIZE);
- move16 ();
- indice[1] = Vq_subvec (&lsf_r1[2], &lsf_r2[2], dico2_lsf,
- &wf1[2], &wf2[2], DICO2_SIZE);
- move16 ();
- indice[2] = Vq_subvec_s (&lsf_r1[4], &lsf_r2[4], dico3_lsf,
- &wf1[4], &wf2[4], DICO3_SIZE);
- move16 ();
- indice[3] = Vq_subvec (&lsf_r1[6], &lsf_r2[6], dico4_lsf,
- &wf1[6], &wf2[6], DICO4_SIZE);
- move16 ();
- indice[4] = Vq_subvec (&lsf_r1[8], &lsf_r2[8], dico5_lsf,
- &wf1[8], &wf2[8], DICO5_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 ();
- lsf2_q[i] = add_ex (lsf_r2[i], lsf_p[i]); move16 ();
- st->past_rq[i] = lsf_r2[i]; move16 ();
- }
- /* verification that LSFs has minimum distance of LSF_GAP */
- Reorder_lsf (lsf1_q, LSF_GAP, M);
- Reorder_lsf (lsf2_q, LSF_GAP, M);
- /* convert LSFs to the cosine domain */
-
- Lsf_lsp (lsf1_q, lsp1_q, M);
- Lsf_lsp (lsf2_q, lsp2_q, M);
- }
|