FreeCalypso > hg > gsm-codec-lib
comparison libgsmefr/dec_12k2.c @ 64:1cc2968f883f
libgsmefr: dec_12k2.c compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 26 Nov 2022 02:05:51 +0000 |
parents | 49dd1ac8e75b |
children | cb080ec1817e |
comparison
equal
deleted
inserted
replaced
63:6a623cb57d07 | 64:1cc2968f883f |
---|---|
12 * Decoder_12k2(): | 12 * Decoder_12k2(): |
13 * Speech decoder routine operating on a frame basis. | 13 * Speech decoder routine operating on a frame basis. |
14 * | 14 * |
15 ***************************************************************************/ | 15 ***************************************************************************/ |
16 | 16 |
17 #include "gsm_efr.h" | |
17 #include "typedef.h" | 18 #include "typedef.h" |
19 #include "namespace.h" | |
18 #include "basic_op.h" | 20 #include "basic_op.h" |
19 #include "sig_proc.h" | 21 #include "sig_proc.h" |
20 #include "count.h" | 22 #include "memops.h" |
23 #include "no_count.h" | |
21 #include "codec.h" | 24 #include "codec.h" |
22 #include "cnst.h" | 25 #include "cnst.h" |
26 #include "dec_state.h" | |
23 | 27 |
24 #include "dtx.h" | 28 #include "dtx.h" |
25 | |
26 extern Word16 dtx_mode; | |
27 | 29 |
28 /*---------------------------------------------------------------* | 30 /*---------------------------------------------------------------* |
29 * Decoder constant parameters (defined in "cnst.h") * | 31 * Decoder constant parameters (defined in "cnst.h") * |
30 *---------------------------------------------------------------* | 32 *---------------------------------------------------------------* |
31 * L_FRAME : Frame size. * | 33 * L_FRAME : Frame size. * |
41 | 43 |
42 /*--------------------------------------------------------* | 44 /*--------------------------------------------------------* |
43 * Static memory allocation. * | 45 * Static memory allocation. * |
44 *--------------------------------------------------------*/ | 46 *--------------------------------------------------------*/ |
45 | 47 |
46 /* Excitation vector */ | |
47 | |
48 static Word16 old_exc[L_FRAME + PIT_MAX + L_INTERPOL]; | |
49 static Word16 *exc; | |
50 | |
51 /* Lsp (Line spectral pairs) */ | |
52 | |
53 static Word16 lsp_old[M]; | |
54 | |
55 /* Filter's memory */ | |
56 | |
57 static Word16 mem_syn[M]; | |
58 | |
59 /* Memories for bad frame handling */ | |
60 | |
61 static Word16 prev_bf; | |
62 static Word16 state; | |
63 | |
64 /*************************************************************************** | 48 /*************************************************************************** |
65 * | 49 * |
66 * FUNCTION: Init_Decoder_12k2 | 50 * FUNCTION: Init_Decoder_12k2 |
67 * | 51 * |
68 * PURPOSE: Initialization of variables for the decoder section. | 52 * PURPOSE: Initialization of variables for the decoder section. |
69 * | 53 * |
70 ***************************************************************************/ | 54 ***************************************************************************/ |
71 | 55 |
72 void Init_Decoder_12k2 (void) | 56 void Init_Decoder_12k2 (struct EFR_decoder_state *st) |
73 { | 57 { |
74 /* Initialize static pointer */ | |
75 | |
76 exc = old_exc + PIT_MAX + L_INTERPOL; | |
77 | |
78 /* Static vectors to zero */ | 58 /* Static vectors to zero */ |
79 | 59 |
80 Set_zero (old_exc, PIT_MAX + L_INTERPOL); | 60 Set_zero (st->old_exc, PIT_MAX + L_INTERPOL); |
81 Set_zero (mem_syn, M); | 61 Set_zero (st->mem_syn, M); |
82 | 62 |
83 /* Initialize lsp_old [] */ | 63 /* Initialize lsp_old [] */ |
84 | 64 |
85 lsp_old[0] = 30000; | 65 st->lsp_old[0] = 30000; |
86 lsp_old[1] = 26000; | 66 st->lsp_old[1] = 26000; |
87 lsp_old[2] = 21000; | 67 st->lsp_old[2] = 21000; |
88 lsp_old[3] = 15000; | 68 st->lsp_old[3] = 15000; |
89 lsp_old[4] = 8000; | 69 st->lsp_old[4] = 8000; |
90 lsp_old[5] = 0; | 70 st->lsp_old[5] = 0; |
91 lsp_old[6] = -8000; | 71 st->lsp_old[6] = -8000; |
92 lsp_old[7] = -15000; | 72 st->lsp_old[7] = -15000; |
93 lsp_old[8] = -21000; | 73 st->lsp_old[8] = -21000; |
94 lsp_old[9] = -26000; | 74 st->lsp_old[9] = -26000; |
95 | 75 |
96 /* Initialize memories of bad frame handling */ | 76 /* Initialize memories of bad frame handling */ |
97 | 77 |
98 prev_bf = 0; | 78 st->prev_bf = 0; |
99 state = 0; | 79 st->bf_state = 0; |
100 | 80 |
101 return; | 81 return; |
102 } | 82 } |
103 | 83 |
104 /*************************************************************************** | 84 /*************************************************************************** |
108 * PURPOSE: Speech decoder routine. | 88 * PURPOSE: Speech decoder routine. |
109 * | 89 * |
110 ***************************************************************************/ | 90 ***************************************************************************/ |
111 | 91 |
112 void Decoder_12k2 ( | 92 void Decoder_12k2 ( |
113 Word16 parm[], /* input : vector of synthesis parameters | 93 struct EFR_decoder_state *st, |
114 parm[0] = bad frame indicator (bfi) */ | 94 Word16 bfi, /* input : Bad Frame Indication */ |
95 Word16 parm[], /* input : vector of synthesis parameters */ | |
115 Word16 synth[],/* output: synthesis speech */ | 96 Word16 synth[],/* output: synthesis speech */ |
116 Word16 A_t[], /* output: decoded LP filter in 4 subframes */ | 97 Word16 A_t[], /* output: decoded LP filter in 4 subframes */ |
117 Word16 TAF, | 98 Word16 TAF, |
118 Word16 SID_flag | 99 Word16 SID_flag |
119 ) | 100 ) |
120 { | 101 { |
102 Word16 *exc = st->old_exc + PIT_MAX + L_INTERPOL; | |
121 | 103 |
122 /* LPC coefficients */ | 104 /* LPC coefficients */ |
123 | 105 |
124 Word16 *Az; /* Pointer on A_t */ | 106 Word16 *Az; /* Pointer on A_t */ |
125 | 107 |
138 | 120 |
139 /* Scalars */ | 121 /* Scalars */ |
140 | 122 |
141 Word16 i, i_subfr; | 123 Word16 i, i_subfr; |
142 Word16 T0, T0_frac, index; | 124 Word16 T0, T0_frac, index; |
143 Word16 gain_pit, gain_code, bfi, pit_sharp; | 125 Word16 gain_pit, gain_code, pit_sharp; |
144 Word16 temp; | 126 Word16 temp; |
145 Word32 L_temp; | 127 Word32 L_temp; |
146 | 128 |
147 extern Word16 rxdtx_ctrl, rx_dtx_state; | |
148 extern Word32 L_pn_seed_rx; | |
149 | |
150 /* Test bad frame indicator (bfi) */ | |
151 | |
152 bfi = *parm++; move16 (); | |
153 | |
154 /* Set state machine */ | 129 /* Set state machine */ |
155 | 130 |
156 test (); test (); | |
157 if (bfi != 0) | 131 if (bfi != 0) |
158 { | 132 { |
159 state = add (state, 1); | 133 st->bf_state = add (st->bf_state, 1); |
160 } | 134 } |
161 else if (sub (state, 6) == 0) | 135 else if (sub (st->bf_state, 6) == 0) |
162 { | 136 { |
163 state = 5; | 137 st->bf_state = 5; |
164 } | 138 } |
165 else | 139 else |
166 { | 140 { |
167 state = 0; | 141 st->bf_state = 0; |
168 } | 142 } |
169 | 143 |
170 test (); | 144 if (sub (st->bf_state, 6) > 0) |
171 if (sub (state, 6) > 0) | 145 { |
172 { | 146 st->bf_state = 6; |
173 state = 6; | 147 } |
174 } | 148 rx_dtx (st, TAF, bfi, SID_flag); |
175 rx_dtx (&rxdtx_ctrl, TAF, bfi, SID_flag); | |
176 | 149 |
177 /* If this frame is the first speech frame after CNI period, */ | 150 /* If this frame is the first speech frame after CNI period, */ |
178 /* set the BFH state machine to an appropriate state depending */ | 151 /* set the BFH state machine to an appropriate state depending */ |
179 /* on whether there was DTX muting before start of speech or not */ | 152 /* on whether there was DTX muting before start of speech or not */ |
180 /* If there was DTX muting, the first speech frame is muted. */ | 153 /* If there was DTX muting, the first speech frame is muted. */ |
181 /* If there was no DTX muting, the first speech frame is not */ | 154 /* If there was no DTX muting, the first speech frame is not */ |
182 /* muted. The BFH state machine starts from state 5, however, to */ | 155 /* muted. The BFH state machine starts from state 5, however, to */ |
183 /* keep the audible noise resulting from a SID frame which is */ | 156 /* keep the audible noise resulting from a SID frame which is */ |
184 /* erroneously interpreted as a good speech frame as small as */ | 157 /* erroneously interpreted as a good speech frame as small as */ |
185 /* possible (the decoder output in this case is quickly muted) */ | 158 /* possible (the decoder output in this case is quickly muted) */ |
186 test (); logic16 (); | 159 if ((st->rxdtx_ctrl & RX_FIRST_SP_FLAG) != 0) |
187 if ((rxdtx_ctrl & RX_FIRST_SP_FLAG) != 0) | 160 { |
188 { | 161 if ((st->rxdtx_ctrl & RX_PREV_DTX_MUTING) != 0) |
189 test (); logic16 (); | 162 { |
190 if ((rxdtx_ctrl & RX_PREV_DTX_MUTING) != 0) | 163 st->bf_state = 5; |
191 { | 164 st->prev_bf = 1; |
192 state = 5; move16 (); | |
193 prev_bf = 1; move16 (); | |
194 } | 165 } |
195 else | 166 else |
196 { | 167 { |
197 state = 5; move16 (); | 168 st->bf_state = 5; |
198 prev_bf = 0; move16 (); | 169 st->prev_bf = 0; |
199 } | 170 } |
200 } | 171 } |
201 | 172 |
202 #if (WMOPS) | 173 D_plsf_5 (st, parm, lsp_mid, lsp_new, bfi, st->rxdtx_ctrl, |
203 fwc (); /* function worst case */ | 174 st->rx_dtx_state); |
204 | 175 |
205 /* Note! The following test is performed only for determining | |
206 whether or not DTX mode is active, in order to switch off | |
207 worst worst case complexity printout when DTX mode is active | |
208 */ | |
209 if ((rxdtx_ctrl & RX_SP_FLAG) == 0) | |
210 { | |
211 dtx_mode = 1; | |
212 } | |
213 #endif | |
214 | |
215 D_plsf_5 (parm, lsp_mid, lsp_new, bfi, rxdtx_ctrl, rx_dtx_state); | |
216 | |
217 #if (WMOPS) | |
218 fwc (); /* function worst case */ | |
219 #endif | |
220 /* Advance synthesis parameters pointer */ | 176 /* Advance synthesis parameters pointer */ |
221 parm += 5; move16 (); | 177 parm += 5; move16 (); |
222 | 178 |
223 test (); logic16 (); | 179 if ((st->rxdtx_ctrl & RX_SP_FLAG) != 0) |
224 if ((rxdtx_ctrl & RX_SP_FLAG) != 0) | |
225 { | 180 { |
226 /* Interpolation of LPC for the 4 subframes */ | 181 /* Interpolation of LPC for the 4 subframes */ |
227 | 182 |
228 Int_lpc (lsp_old, lsp_mid, lsp_new, A_t); | 183 Int_lpc (st->lsp_old, lsp_mid, lsp_new, A_t); |
229 } | 184 } |
230 else | 185 else |
231 { | 186 { |
232 /* Comfort noise: use the same parameters in each subframe */ | 187 /* Comfort noise: use the same parameters in each subframe */ |
233 Lsp_Az (lsp_new, A_t); | 188 Lsp_Az (lsp_new, A_t); |
241 } | 196 } |
242 | 197 |
243 /* update the LSPs for the next frame */ | 198 /* update the LSPs for the next frame */ |
244 for (i = 0; i < M; i++) | 199 for (i = 0; i < M; i++) |
245 { | 200 { |
246 lsp_old[i] = lsp_new[i]; move16 (); | 201 st->lsp_old[i] = lsp_new[i]; |
247 } | 202 } |
248 #if (WMOPS) | |
249 fwc (); /* function worst case */ | |
250 #endif | |
251 | 203 |
252 /*---------------------------------------------------------------------* | 204 /*---------------------------------------------------------------------* |
253 * Loop for every subframe in the analysis frame * | 205 * Loop for every subframe in the analysis frame * |
254 *---------------------------------------------------------------------* | 206 *---------------------------------------------------------------------* |
255 * The subframe size is L_SUBFR and the loop is repeated * | 207 * The subframe size is L_SUBFR and the loop is repeated * |
266 for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) | 218 for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) |
267 { | 219 { |
268 | 220 |
269 index = *parm++; move16 (); /* pitch index */ | 221 index = *parm++; move16 (); /* pitch index */ |
270 | 222 |
271 test (); logic16 (); | 223 if ((st->rxdtx_ctrl & RX_SP_FLAG) != 0) |
272 if ((rxdtx_ctrl & RX_SP_FLAG) != 0) | 224 { |
273 { | 225 T0 = Dec_lag6 (st, index, PIT_MIN, PIT_MAX, i_subfr, L_FRAME_BY2, |
274 T0 = Dec_lag6 (index, PIT_MIN, PIT_MAX, i_subfr, L_FRAME_BY2, | |
275 &T0_frac, bfi); | 226 &T0_frac, bfi); |
276 #if (WMOPS) | |
277 fwc (); /* function worst case */ | |
278 #endif | |
279 | 227 |
280 /*-------------------------------------------------* | 228 /*-------------------------------------------------* |
281 * - Find the adaptive codebook vector. * | 229 * - Find the adaptive codebook vector. * |
282 *-------------------------------------------------*/ | 230 *-------------------------------------------------*/ |
283 | 231 |
284 Pred_lt_6 (&exc[i_subfr], T0, T0_frac, L_SUBFR); | 232 Pred_lt_6 (&exc[i_subfr], T0, T0_frac, L_SUBFR); |
285 #if (WMOPS) | |
286 fwc (); /* function worst case */ | |
287 #endif | |
288 } | 233 } |
289 else | 234 else |
290 { | 235 { |
291 T0 = L_SUBFR; move16 (); | 236 T0 = L_SUBFR; move16 (); |
292 } | 237 } |
295 * - Decode pitch gain. * | 240 * - Decode pitch gain. * |
296 *-------------------------------------------------------*/ | 241 *-------------------------------------------------------*/ |
297 | 242 |
298 index = *parm++; move16 (); | 243 index = *parm++; move16 (); |
299 | 244 |
300 gain_pit = d_gain_pitch (index, bfi, state, prev_bf, rxdtx_ctrl); | 245 gain_pit = d_gain_pitch (st, index, bfi, st->bf_state, st->prev_bf, |
301 move16 (); | 246 st->rxdtx_ctrl); |
302 #if (WMOPS) | |
303 fwc (); /* function worst case */ | |
304 #endif | |
305 | 247 |
306 /*-------------------------------------------------------* | 248 /*-------------------------------------------------------* |
307 * - Decode innovative codebook. * | 249 * - Decode innovative codebook. * |
308 *-------------------------------------------------------*/ | 250 *-------------------------------------------------------*/ |
309 | 251 |
310 test (); logic16 (); | 252 if ((st->rxdtx_ctrl & RX_SP_FLAG) != 0) |
311 if ((rxdtx_ctrl & RX_SP_FLAG) != 0) | |
312 { | 253 { |
313 dec_10i40_35bits (parm, code); | 254 dec_10i40_35bits (parm, code); |
314 } | 255 } |
315 else | 256 else |
316 { /* Use pseudo noise for excitation when SP_flag == 0 */ | 257 { /* Use pseudo noise for excitation when SP_flag == 0 */ |
317 build_CN_code (code, &L_pn_seed_rx); | 258 build_CN_code (code, &st->L_pn_seed_rx); |
318 } | 259 } |
319 | 260 |
320 parm += 10; move16 (); | 261 parm += 10; move16 (); |
321 #if (WMOPS) | |
322 fwc (); /* function worst case */ | |
323 #endif | |
324 | 262 |
325 /*-------------------------------------------------------* | 263 /*-------------------------------------------------------* |
326 * - Add the pitch contribution to code[]. * | 264 * - Add the pitch contribution to code[]. * |
327 *-------------------------------------------------------*/ | 265 *-------------------------------------------------------*/ |
328 | 266 |
336 { | 274 { |
337 temp = mult (code[i - T0], pit_sharp); | 275 temp = mult (code[i - T0], pit_sharp); |
338 code[i] = add (code[i], temp); | 276 code[i] = add (code[i], temp); |
339 move16 (); | 277 move16 (); |
340 } | 278 } |
341 #if (WMOPS) | 279 |
342 fwc (); /* function worst case */ | |
343 #endif | |
344 /* post processing of excitation elements */ | 280 /* post processing of excitation elements */ |
345 | 281 |
346 test (); /* This test is not passed when SP_FLAG is 0 */ | 282 test (); /* This test is not passed when SP_FLAG is 0 */ |
347 if (sub (pit_sharp, 16384) > 0) | 283 if (sub (pit_sharp, 16384) > 0) |
348 { | 284 { |
359 * - Decode codebook gain. * | 295 * - Decode codebook gain. * |
360 *-------------------------------------------------*/ | 296 *-------------------------------------------------*/ |
361 | 297 |
362 index = *parm++; move16 (); /* index of energy VQ */ | 298 index = *parm++; move16 (); /* index of energy VQ */ |
363 | 299 |
364 d_gain_code (index, code, L_SUBFR, &gain_code, bfi, state, prev_bf, | 300 d_gain_code (st, index, code, L_SUBFR, &gain_code, bfi, st->bf_state, |
365 rxdtx_ctrl, i_subfr, rx_dtx_state); | 301 st->prev_bf, st->rxdtx_ctrl, i_subfr, st->rx_dtx_state); |
366 #if (WMOPS) | |
367 fwc (); /* function worst case */ | |
368 #endif | |
369 | 302 |
370 /*-------------------------------------------------------* | 303 /*-------------------------------------------------------* |
371 * - Find the total excitation. * | 304 * - Find the total excitation. * |
372 * - Find synthesis speech corresponding to exc[]. * | 305 * - Find synthesis speech corresponding to exc[]. * |
373 *-------------------------------------------------------*/ | 306 *-------------------------------------------------------*/ |
380 L_temp = L_shl (L_temp, 3); | 313 L_temp = L_shl (L_temp, 3); |
381 | 314 |
382 exc[i + i_subfr] = round (L_temp); | 315 exc[i + i_subfr] = round (L_temp); |
383 move16 (); | 316 move16 (); |
384 } | 317 } |
385 #if (WMOPS) | 318 |
386 fwc (); /* function worst case */ | |
387 #endif | |
388 | |
389 test (); | |
390 if (sub (pit_sharp, 16384) > 0) | 319 if (sub (pit_sharp, 16384) > 0) |
391 { | 320 { |
392 for (i = 0; i < L_SUBFR; i++) | 321 for (i = 0; i < L_SUBFR; i++) |
393 { | 322 { |
394 excp[i] = add (excp[i], exc[i + i_subfr]); | 323 excp[i] = add (excp[i], exc[i + i_subfr]); |
395 move16 (); | |
396 } | 324 } |
397 agc2 (&exc[i_subfr], excp, L_SUBFR); | 325 agc2 (&exc[i_subfr], excp, L_SUBFR); |
398 Syn_filt (Az, excp, &synth[i_subfr], L_SUBFR, mem_syn, 1); | 326 Syn_filt (Az, excp, &synth[i_subfr], L_SUBFR, st->mem_syn, 1); |
399 } | 327 } |
400 else | 328 else |
401 { | 329 { |
402 Syn_filt (Az, &exc[i_subfr], &synth[i_subfr], L_SUBFR, mem_syn, 1); | 330 Syn_filt (Az, &exc[i_subfr], &synth[i_subfr], L_SUBFR, |
403 } | 331 st->mem_syn, 1); |
404 | 332 } |
405 #if (WMOPS) | 333 |
406 fwc (); /* function worst case */ | |
407 #endif | |
408 /* interpolated LPC parameters for next subframe */ | 334 /* interpolated LPC parameters for next subframe */ |
409 Az += MP1; move16 (); | 335 Az += MP1; move16 (); |
410 } | 336 } |
411 | 337 |
412 /*--------------------------------------------------* | 338 /*--------------------------------------------------* |
413 * Update signal for next frame. * | 339 * Update signal for next frame. * |
414 * -> shift to the left by L_FRAME exc[] * | 340 * -> shift to the left by L_FRAME exc[] * |
415 *--------------------------------------------------*/ | 341 *--------------------------------------------------*/ |
416 | 342 |
417 Copy (&old_exc[L_FRAME], &old_exc[0], PIT_MAX + L_INTERPOL); | 343 Copy (&st->old_exc[L_FRAME], &st->old_exc[0], PIT_MAX + L_INTERPOL); |
418 #if (WMOPS) | 344 st->prev_bf = bfi; |
419 fwc (); /* function worst case */ | |
420 #endif | |
421 prev_bf = bfi; move16 (); | |
422 | 345 |
423 return; | 346 return; |
424 } | 347 } |