comparison libgsmefr/d_plsf_5.c @ 53:49dd1ac8e75b

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