annotate src/d_plsf_5.c @ 2:c511bfb36c2a

beginning of EFR2 decoder, using AMR version of AGC module
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 03 Apr 2024 05:47:51 +0000
parents 56410792419a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*************************************************************************
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * FUNCTION: D_plsf_5()
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * PURPOSE: Decodes the 2 sets of LSP parameters in a frame using the
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * received quantization indices.
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * DESCRIPTION:
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * The two sets of LSFs are quantized using split by 5 matrix
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * quantization (split-MQ) with 1st order MA prediction.
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * See "q_plsf_5.c" for more details about the quantization procedure
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 *
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 *************************************************************************/
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "typedef.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "basic_op.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "count.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "sig_proc.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "q_plsf_5.tab" /* Codebooks of LSF prediction residual */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #include "cnst.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #include "dtx.h"
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 /* M ->order of linear prediction filter */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 /* LSF_GAP -> Minimum distance between LSF after quantization */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 /* 50 Hz = 205 */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /* PRED_FAC -> Prediction factor = 0.65 */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 /* ALPHA -> 0.9 */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 /* ONE_ALPHA-> (1.0-ALPHA) */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #define M 10
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #define LSF_GAP 205
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #define PRED_FAC 21299
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #define ALPHA 31128
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #define ONE_ALPHA 1639
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 /* Past quantized prediction error */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 Word16 past_r2_q[M];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 /* Past dequantized lsfs */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 Word16 past_lsf_q[M];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 /* Reference LSF parameter vector (comfort noise) */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 Word16 lsf_p_CN[M];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 /* LSF memories for comfort noise interpolation */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 Word16 lsf_old_CN[M], lsf_new_CN[M];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 /* LSF parameter buffer */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 extern Word16 lsf_old_rx[DTX_HANGOVER][M];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 void D_plsf_5 (
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 Word16 *indice, /* input : quantization indices of 5 submatrices */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 Word16 *lsp1_q, /* output: quantized 1st LSP vector */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Word16 *lsp2_q, /* output: quantized 2nd LSP vector */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 Word16 bfi, /* input : bad frame indicator (set to 1 if a bad
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 frame is received) */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 Word16 rxdtx_ctrl, /* input : RX DTX control word */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 Word16 rx_dtx_state /* input : state of the comfort noise insertion
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 period */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 )
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 Word16 i;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 const Word16 *p_dico;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 Word16 temp, sign;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 Word16 lsf1_r[M], lsf2_r[M];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 Word16 lsf1_q[M], lsf2_q[M];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 /* Update comfort noise LSF quantizer memory */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 test (); logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if ((rxdtx_ctrl & RX_UPD_SID_QUANT_MEM) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 update_lsf_p_CN (lsf_old_rx, lsf_p_CN);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 /* Handle cases of comfort noise LSF decoding in which past
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 valid SID frames are repeated */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 test (); logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 test (); logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 test (); logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (((rxdtx_ctrl & RX_NO_TRANSMISSION) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 || ((rxdtx_ctrl & RX_INVALID_SID_FRAME) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 || ((rxdtx_ctrl & RX_LOST_SID_FRAME) != 0))
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 test (); logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if ((rxdtx_ctrl & RX_NO_TRANSMISSION) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 /* DTX active: no transmission. Interpolate LSF values in memory */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 interpolate_CN_lsf (lsf_old_CN, lsf_new_CN, lsf2_q, rx_dtx_state);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 else
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 { /* Invalid or lost SID frame: use LSFs
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 from last good SID frame */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 lsf_old_CN[i] = lsf_new_CN[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 lsf2_q[i] = lsf_new_CN[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 past_r2_q[i] = 0; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 past_lsf_q[i] = lsf2_q[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 /* convert LSFs to the cosine domain */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 Lsf_lsp (lsf2_q, lsp2_q, M);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 return;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 test ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 if (bfi != 0) /* if bad frame */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 /* use the past LSFs slightly shifted towards their mean */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 /* lsfi_q[i] = ALPHA*past_lsf_q[i] + ONE_ALPHA*mean_lsf[i]; */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 lsf1_q[i] = add (mult (past_lsf_q[i], ALPHA),
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 mult (mean_lsf[i], ONE_ALPHA));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 lsf2_q[i] = lsf1_q[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 /* estimate past quantized residual to be used in next frame */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 /* temp = mean_lsf[i] + past_r2_q[i] * PRED_FAC; */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 temp = add (mean_lsf[i], mult (past_r2_q[i], PRED_FAC));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 past_r2_q[i] = sub (lsf2_q[i], temp);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 else
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 /* if good LSFs received */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 /* decode prediction residuals from 5 received indices */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 p_dico = &dico1_lsf[shl (indice[0], 2)];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 lsf1_r[0] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 lsf1_r[1] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 lsf2_r[0] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 lsf2_r[1] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 p_dico = &dico2_lsf[shl (indice[1], 2)];
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 lsf1_r[2] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 lsf1_r[3] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 lsf2_r[2] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 lsf2_r[3] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 sign = indice[2] & 1; logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 i = shr (indice[2], 1);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 p_dico = &dico3_lsf[shl (i, 2)]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 test ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 if (sign == 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 lsf1_r[4] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 lsf1_r[5] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 lsf2_r[4] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 lsf2_r[5] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 else
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 lsf1_r[4] = negate (*p_dico++); move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 lsf1_r[5] = negate (*p_dico++); move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 lsf2_r[4] = negate (*p_dico++); move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 lsf2_r[5] = negate (*p_dico++); move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 p_dico = &dico4_lsf[shl (indice[3], 2)];move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 lsf1_r[6] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 lsf1_r[7] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 lsf2_r[6] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 lsf2_r[7] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 p_dico = &dico5_lsf[shl (indice[4], 2)];move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 lsf1_r[8] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 lsf1_r[9] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 lsf2_r[8] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 lsf2_r[9] = *p_dico++; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 /* Compute quantized LSFs and update the past quantized residual */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 /* Use lsf_p_CN as predicted LSF vector in case of no speech
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 activity */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 test (); logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 if ((rxdtx_ctrl & RX_SP_FLAG) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 temp = add (mean_lsf[i], mult (past_r2_q[i], PRED_FAC));
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 lsf1_q[i] = add (lsf1_r[i], temp);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 lsf2_q[i] = add (lsf2_r[i], temp);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 past_r2_q[i] = lsf2_r[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 else
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 { /* Valid SID frame */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 lsf2_q[i] = add (lsf2_r[i], lsf_p_CN[i]);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 /* Use the dequantized values of lsf2 also for lsf1 */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 lsf1_q[i] = lsf2_q[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 past_r2_q[i] = 0; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 /* verification that LSFs have minimum distance of LSF_GAP Hz */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 Reorder_lsf (lsf1_q, LSF_GAP, M);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 Reorder_lsf (lsf2_q, LSF_GAP, M);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 test (); logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 if ((rxdtx_ctrl & RX_FIRST_SID_UPDATE) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 lsf_new_CN[i] = lsf2_q[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 test (); logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 if ((rxdtx_ctrl & RX_CONT_SID_UPDATE) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 lsf_old_CN[i] = lsf_new_CN[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 lsf_new_CN[i] = lsf2_q[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 test (); logic16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 if ((rxdtx_ctrl & RX_SP_FLAG) != 0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 /* Update lsf history with quantized LSFs
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 when speech activity is present. If the current frame is
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 a bad one, update with most recent good comfort noise LSFs */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 if (bfi==0)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 update_lsf_history (lsf1_q, lsf2_q, lsf_old_rx);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 else
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 update_lsf_history (lsf_new_CN, lsf_new_CN, lsf_old_rx);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 lsf_old_CN[i] = lsf2_q[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 else
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 interpolate_CN_lsf (lsf_old_CN, lsf_new_CN, lsf2_q, rx_dtx_state);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 for (i = 0; i < M; i++)
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 {
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 past_lsf_q[i] = lsf2_q[i]; move16 ();
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 }
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 /* convert LSFs to the cosine domain */
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 Lsf_lsp (lsf1_q, lsp1_q, M);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 Lsf_lsp (lsf2_q, lsp2_q, M);
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 return;
56410792419a src: original EFR source from ETSI
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 }