Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 :
6 : #include <stdlib.h>
7 : #include <stdio.h>
8 : #include <assert.h>
9 : #include <string.h>
10 : #include "rom_com.h"
11 : #include "stl.h"
12 : #include "prot_fx.h"
13 : #include "basop_util.h"
14 : /*-------------------------------------------------------------------*
15 : * getLPCparam_ivas()
16 : *
17 : * get LPC parameters
18 : *--------------------------------------------------------------------*/
19 :
20 684374 : void getLPCparam_fx(
21 : Decoder_State *st, /* i/o: decoder memory state */
22 : Word16 param_lpc[], /* o : LTP parameters Q0 */
23 : Decoder_State *st0, /* i : bitstream */
24 : const Word16 ch, /* i : channel Q0 */
25 : const Word16 sns_low_br_mode /* i : SNS low-bitrate mode Q0 */
26 : )
27 : {
28 684374 : IF( st->use_partial_copy == 0 )
29 : {
30 : /* Number of sets of LPC parameters (does not include mid-lpc) */
31 684374 : test();
32 684374 : IF( ( st->tcxonly == 0 ) || LT_16( st->core, TCX_10_CORE ) )
33 : {
34 671963 : st->numlpc = 1;
35 671963 : move16();
36 : }
37 : ELSE
38 : {
39 12411 : st->numlpc = 2;
40 12411 : move16();
41 : }
42 :
43 : /* Decode LPC parameters */
44 684374 : test();
45 684374 : IF( st->hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) )
46 13989 : {
47 : Word16 tcx_lpc_cdk;
48 13989 : tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type );
49 13989 : dec_lsf_tcxlpc( st0, ¶m_lpc, st->narrowBand, tcx_lpc_cdk );
50 : }
51 : ELSE
52 : {
53 670385 : IF( st->lpcQuantization == 0 )
54 : {
55 573176 : decode_lpc_avq_ivas_fx( st0, st->numlpc, param_lpc, ch, st->element_mode, sns_low_br_mode );
56 : }
57 97209 : ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
58 : {
59 97209 : test();
60 97209 : test();
61 97209 : IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && ( st->core == ACELP_CORE ) )
62 : {
63 0 : assert( st->element_mode == EVS_MONO );
64 0 : lsf_bctcvq_decprm( st0, param_lpc );
65 : }
66 : ELSE
67 : {
68 97209 : lsf_msvq_ma_decprm( st0, param_lpc );
69 : }
70 : }
71 : ELSE
72 : {
73 0 : assert( 0 );
74 : }
75 : }
76 : }
77 : ELSE
78 : {
79 0 : st->numlpc = 1;
80 0 : move16();
81 0 : test();
82 0 : IF( EQ_16( st->rf_frame_type, RF_TCXFD ) )
83 : {
84 0 : param_lpc[0] = 0; // Q0
85 0 : move16();
86 0 : param_lpc[1] = get_next_indice_fx( st0, lsf_numbits[0] ); /* VQ 1 */ // Q0
87 0 : move16();
88 0 : param_lpc[2] = get_next_indice_fx( st0, lsf_numbits[1] ); /* VQ 2 */ // Q0
89 0 : move16();
90 0 : param_lpc[3] = get_next_indice_fx( st0, lsf_numbits[2] ); /* VQ 3 */ // Q0
91 0 : move16();
92 : }
93 0 : ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) )
94 : {
95 : /* LSF indices */
96 0 : param_lpc[0] = get_next_indice_fx( st0, 8 ); /* VQ 1 */ // Q0
97 0 : move16();
98 0 : param_lpc[1] = get_next_indice_fx( st0, 8 ); /* VQ 2 */ // Q0
99 0 : move16();
100 : }
101 : }
102 :
103 684374 : return;
104 : }
105 :
106 12695 : void dec_prm_hm_fx(
107 : Decoder_State *st,
108 : Word16 *prm_hm, /* Q0 */
109 : const Word16 L_frame )
110 : {
111 : Word16 tmp;
112 :
113 : /* Disable HM for non-GC,VC modes */
114 12695 : test();
115 12695 : IF( NE_16( st->hTcxCfg->coder_type, VOICED ) && NE_16( st->hTcxCfg->coder_type, GENERIC ) )
116 : {
117 1984 : prm_hm[0] = 0;
118 1984 : move16();
119 :
120 1984 : return;
121 : }
122 :
123 10711 : prm_hm[1] = -1;
124 10711 : move16();
125 10711 : prm_hm[2] = 0;
126 10711 : move16();
127 :
128 : /* Flag */
129 10711 : prm_hm[0] = get_next_indice_fx( st, 1 ); // Q0
130 10711 : move16();
131 :
132 10711 : IF( prm_hm[0] != 0 )
133 : {
134 5210 : tmp = 0;
135 5210 : move16();
136 5210 : if ( GE_16( L_frame, 256 ) )
137 : {
138 5210 : tmp = 1;
139 5210 : move16();
140 : }
141 : /* Periodicity index */
142 5210 : DecodeIndex_fx( st, tmp, &prm_hm[1] );
143 :
144 : /* Gain index */
145 5210 : IF( EQ_16( st->hTcxCfg->coder_type, VOICED ) )
146 : {
147 1848 : prm_hm[2] = get_next_indice_fx( st, kTcxHmNumGainBits );
148 1848 : move16();
149 : }
150 : }
151 : }
152 :
153 : /*-------------------------------------------------------------------*
154 : * getTCXparam_fx()
155 : *
156 : * get TCX core parameters
157 : *-------------------------------------------------------------------*/
158 :
159 1334052 : void getTCXparam_fx(
160 : Decoder_State *st, /* i/o: Decoder State handle */
161 : Decoder_State *st0, /* i : bitstream */
162 : CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */
163 : Word16 param[], /* o : decoded parameters Q0 */
164 : const Word16 bits_common, /* i : number of common bits Q0 */
165 : const Word16 start_bit_pos, /* i : position of the start bit Q0 */
166 : const Word16 *no_param_tns, /* i : number of TNS parameters per subframe Q0 */
167 : Word16 p_param[2], /* o : pointer to parameters for next round of bs reading Q0 */
168 : Word16 nTnsBitsTCX10[2], /*Q0*/
169 : const Word16 pre_past_flag /*Q0*/ )
170 : {
171 : Word16 ix, j, k, core, last_core, nSubframes;
172 : Word16 lg, lgFB, flag_ctx_hm, hm_size;
173 : Word16 PeriodicityIndex, useHarmonicModel;
174 : Word16 tcxltp_prm_0, tcxltp_prm_1, tcxltp_prm_2, nbits_igf, nbits_tcx;
175 : Word16 *prm, *prms;
176 : Word16 nTnsParams, nTnsBits;
177 : Word16 pre_part, post_part;
178 1334052 : TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
179 1334052 : TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
180 :
181 :
182 1334052 : IF( pre_past_flag == 0 )
183 : {
184 560842 : pre_part = 1;
185 560842 : move16();
186 560842 : post_part = 0;
187 560842 : move16();
188 : }
189 773210 : ELSE IF( EQ_16( pre_past_flag, 1 ) )
190 : {
191 560842 : pre_part = 0;
192 560842 : move16();
193 560842 : post_part = 1;
194 560842 : move16();
195 : }
196 : ELSE
197 : {
198 212368 : pre_part = 1;
199 212368 : move16();
200 212368 : post_part = 1;
201 212368 : move16();
202 : }
203 :
204 : /* initialization */
205 1334052 : tcxltp_prm_0 = 0;
206 1334052 : move16();
207 1334052 : tcxltp_prm_1 = 0;
208 1334052 : move16();
209 1334052 : tcxltp_prm_2 = 0;
210 1334052 : move16();
211 1334052 : nbits_igf = 0;
212 1334052 : move16();
213 :
214 1334052 : PeriodicityIndex = 0;
215 1334052 : move16();
216 1334052 : useHarmonicModel = 0;
217 1334052 : move16();
218 :
219 1334052 : core = st->core;
220 1334052 : move16();
221 1334052 : last_core = st->last_core;
222 1334052 : move16();
223 :
224 1334052 : nSubframes = 1;
225 1334052 : move16();
226 1334052 : if ( EQ_16( core, TCX_10_CORE ) )
227 : {
228 27296 : nSubframes = 2;
229 27296 : move16();
230 : }
231 :
232 1334052 : test();
233 1334052 : test();
234 1334052 : IF( LT_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf && EQ_16( core, TCX_10_CORE ) )
235 : {
236 : /* get IGF */
237 5649 : FOR( k = 0; k < nSubframes; k++ )
238 : {
239 3766 : ix = st->next_bit_pos;
240 3766 : move16();
241 3766 : IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k );
242 3766 : IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k );
243 3766 : IGFDecStoreTCX10SubFrameData( st->hIGFDec, k );
244 :
245 3766 : nbits_igf = add( nbits_igf, sub( st0->next_bit_pos, ix ) ); // Q0
246 : }
247 : }
248 : /* loop over subframes */
249 2695400 : FOR( k = 0; k < nSubframes; k++ )
250 : {
251 1361348 : flag_ctx_hm = 0;
252 1361348 : move16();
253 1361348 : prm = param + k * DEC_NPRM_DIV;
254 1361348 : j = 0;
255 1361348 : move16();
256 1361348 : nbits_tcx = sub( st0->next_bit_pos, start_bit_pos ); // Q0
257 :
258 1361348 : test();
259 1361348 : test();
260 1361348 : IF( pre_part && st->enablePlcWaveadjust && EQ_16( k, sub( nSubframes, 1 ) ) )
261 : {
262 0 : st->tonality_flag = get_next_indice_fx( st0, 1 ); // Q0
263 0 : move16();
264 : }
265 :
266 1361348 : IF( post_part )
267 : {
268 : /* TCX Gain */
269 787829 : prm[j] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); // Q0
270 787829 : j = add( j, 1 ); // Q0
271 787829 : move16();
272 :
273 : /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */
274 787829 : prm[j] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); // Q0
275 787829 : j = add( j, 1 ); // Q0
276 :
277 787829 : move16();
278 : }
279 : ELSE
280 : {
281 573519 : j = add( j, 1 + NOISE_FILL_RANGES ); // Q0
282 : }
283 :
284 : /* LTP data */
285 1361348 : IF( pre_part )
286 : {
287 787829 : test();
288 787829 : test();
289 787829 : IF( ( k == 0 ) && ( hTcxLtpDec->tcxltp || GT_32( st->sr_core, 25600 ) ) ) /* PLC pitch info for HB */
290 : {
291 773210 : prm[j] = get_next_indice_fx( st0, 1 ); // Q0
292 773210 : move16();
293 773210 : IF( prm[j] )
294 : {
295 518666 : prm[add( j, 1 )] = get_next_indice_fx( st0, 9 ); // Q0
296 518666 : move16();
297 518666 : prm[add( j, 2 )] = get_next_indice_fx( st0, 2 ); // Q0
298 518666 : move16();
299 518666 : tcxltp_prm_0 = prm[j]; // Q0
300 518666 : move16();
301 518666 : tcxltp_prm_1 = prm[j + 1]; // Q0
302 518666 : move16();
303 518666 : tcxltp_prm_2 = prm[j + 2]; // Q0
304 518666 : move16();
305 : }
306 773210 : st->BER_detect = s_or( st->BER_detect, tcx_ltp_decode_params( &prm[j], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ) ); // Q0
307 773210 : move16();
308 773210 : hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15
309 773210 : move16();
310 :
311 773210 : test();
312 773210 : test();
313 773210 : IF( EQ_16( core, TCX_20_CORE ) && !st->tcxonly && LT_16( hTcxLtpDec->tcxltp_pitch_int, st->L_frame ) )
314 111198 : {
315 : // To be done at the end
316 111198 : Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 );
317 111198 : Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr );
318 111198 : hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15
319 111198 : move16();
320 : }
321 : ELSE
322 : {
323 662012 : hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15
324 662012 : move16();
325 : }
326 773210 : j = add( j, 3 ); // Q0
327 : }
328 : ELSE
329 : {
330 14619 : prm[j] = tcxltp_prm_0; // Q0
331 14619 : j = add( j, 1 ); // Q0
332 14619 : move16();
333 14619 : prm[j] = tcxltp_prm_1; // Q0
334 14619 : j = add( j, 1 ); // Q0
335 14619 : move16();
336 14619 : prm[j] = tcxltp_prm_2; // Q0
337 14619 : j = add( j, 1 ); // Q0
338 14619 : move16();
339 : }
340 : }
341 :
342 : /* TCX spectral data */
343 1361348 : lg = shr( st->L_frame, sub( nSubframes, 1 ) ); // Q0
344 1361348 : lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) ); // Q0
345 :
346 1361348 : test();
347 1361348 : test();
348 1361348 : IF( post_part && ( k == 0 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) )
349 : {
350 : /* ACE->TCX transition */
351 8099 : lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0
352 8099 : lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); // Q0
353 :
354 8099 : IF( st->hTcxCfg->lfacNext < 0 )
355 : {
356 8099 : lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0
357 : }
358 : }
359 :
360 1361348 : IF( pre_part )
361 : {
362 : /* TNS data */
363 787829 : nTnsParams = 0;
364 787829 : move16();
365 787829 : nTnsBits = 0;
366 787829 : move16();
367 :
368 787829 : IF( st->hTcxCfg->fIsTNSAllowed )
369 : {
370 721991 : test();
371 721991 : test();
372 721991 : IF( EQ_16( core, TCX_10_CORE ) && EQ_16( last_core, ACELP_CORE ) && ( k == 0 ) )
373 : {
374 0 : st0->BER_detect = 1;
375 0 : move16();
376 0 : last_core = TCX_20_CORE;
377 0 : move16();
378 : }
379 :
380 721991 : SetTnsConfig( st->hTcxCfg, (Word16) EQ_16( core, TCX_20_CORE ), (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) );
381 :
382 721991 : ix = 0;
383 721991 : move16();
384 721991 : IF( no_param_tns )
385 : {
386 10035 : ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */ // Q0
387 : }
388 721991 : IF( ix )
389 : {
390 2394 : prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */ // Q0
391 2394 : move16();
392 2394 : nTnsParams = no_param_tns[k]; // Q0
393 2394 : move16();
394 : }
395 : ELSE
396 : {
397 719597 : ReadTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams );
398 : }
399 721991 : hTcxDec->tnsActive[k] = 0; // Q0
400 721991 : move16();
401 721991 : if ( prm[j] != 0 )
402 : {
403 81009 : hTcxDec->tnsActive[k] = nTnsParams; // Q0
404 81009 : move16();
405 : }
406 721991 : IF( nTnsBitsTCX10 != NULL )
407 : {
408 573519 : IF( no_param_tns )
409 : {
410 10035 : nTnsBitsTCX10[k] = add( nTnsBits, 1 ); // Q0
411 10035 : move16();
412 : }
413 : ELSE
414 : {
415 563484 : nTnsBitsTCX10[k] = add( nTnsBits, 0 ); // Q0
416 563484 : move16();
417 : }
418 : }
419 :
420 721991 : j = add( j, nTnsParams ); // Q0
421 : }
422 :
423 787829 : IF( post_part )
424 : {
425 214310 : IF( EQ_16( core, TCX_20_CORE ) )
426 : {
427 : // Q-factor of TcxBandwidth is 15 : derived from getTcxBandwidth function
428 210426 : hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) ); // Q0
429 210426 : test();
430 210426 : IF( hTcxDec->tcx_lpc_shaped_ari && ( st->last_core_from_bs != ACELP_CORE ) )
431 : {
432 12695 : dec_prm_hm_fx( st0, &prm[j], hm_size );
433 : }
434 :
435 210426 : nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0
436 : }
437 : ELSE
438 : {
439 3884 : hm_size = mult( st->TcxBandwidth, shl( lgFB, 1 ) ); // Q0
440 3884 : nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st0->next_bit_pos, start_bit_pos ), nbits_tcx ) ); // Q0
441 : }
442 :
443 : /*Context HM flag*/
444 214310 : test();
445 214310 : test();
446 214310 : IF( st->hTcxCfg->ctx_hm && !( ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ) )
447 : {
448 166700 : useHarmonicModel = get_next_indice_fx( st0, 1 ); // Q0
449 166700 : prm[j] = useHarmonicModel; // Q0
450 166700 : move16();
451 166700 : nbits_tcx = sub( nbits_tcx, 1 ); // Q0
452 :
453 166700 : IF( useHarmonicModel )
454 : {
455 11959 : ix = DecodeIndex_fx( st0, (Word16) GE_16( hm_size, 256 ), prm + add( j, 1 ) );
456 11959 : flag_ctx_hm = 1; // Q0
457 11959 : move16();
458 11959 : PeriodicityIndex = *( prm + add( j, 1 ) );
459 11959 : IF( st->element_mode == EVS_MONO )
460 : {
461 0 : ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg );
462 : }
463 11959 : nbits_tcx = sub( nbits_tcx, ix ); // Q0
464 : }
465 : }
466 : }
467 787829 : j = add( j, NPRM_CTX_HM ); // Q0
468 :
469 : /* read IGF payload */
470 787829 : test();
471 787829 : IF( post_part && EQ_16( core, TCX_20_CORE ) )
472 : {
473 210426 : IF( st->igf )
474 : {
475 201130 : ix = st->next_bit_pos; // Q0
476 201130 : move16();
477 201130 : IF( st->last_core_from_bs == ACELP_CORE )
478 : {
479 6500 : IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 );
480 6500 : IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 );
481 : }
482 : ELSE
483 : {
484 194630 : IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 );
485 194630 : IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 );
486 : }
487 :
488 201130 : nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) ); // Q0
489 : }
490 210426 : nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0
491 : }
492 577403 : ELSE IF( p_param != NULL )
493 : {
494 573519 : p_param[k] = j; // Q0
495 573519 : move16();
496 : }
497 : }
498 : ELSE
499 : {
500 573519 : j = p_param[k]; // Q0
501 573519 : move16();
502 :
503 573519 : nbits_tcx = st->bits_frame_channel; // Q0
504 573519 : move16();
505 573519 : if ( EQ_16( st->core, TCX_10_CORE ) )
506 : {
507 25354 : nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); // Q0
508 : }
509 : }
510 :
511 1361348 : IF( post_part )
512 : {
513 787829 : test();
514 787829 : IF( hTcxDec->tcx_lpc_shaped_ari && EQ_16( core, TCX_20_CORE ) )
515 : {
516 13989 : prm[j] = nbits_tcx; /* store length of buffer */ // Q0
517 13989 : j = add( j, 1 ); // Q0
518 13989 : move16();
519 13989 : prms = &prm[j];
520 2283547 : FOR( ix = 0; ix < nbits_tcx; ix++ )
521 : {
522 2269558 : prms[ix] = get_next_indice_1_fx( st0 ); // Q0
523 : }
524 461637 : FOR( ix = 0; ix < 32; ix++ )
525 : {
526 447648 : prms[ix + nbits_tcx] = 1; // Q0
527 447648 : move16();
528 : }
529 13989 : j = add( j, nbits_tcx ); // Q0
530 : }
531 : ELSE
532 : {
533 773840 : IF( st->element_mode > EVS_MONO )
534 : {
535 773840 : IF( useHarmonicModel )
536 : {
537 11959 : ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg );
538 : }
539 773840 : IF( flag_ctx_hm )
540 : {
541 11959 : hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), &hm_cfg ); // Q0
542 11959 : move16();
543 : }
544 : ELSE
545 : {
546 761881 : hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), NULL ); // Q0
547 761881 : move16();
548 : }
549 : }
550 : ELSE
551 : {
552 0 : IF( flag_ctx_hm )
553 : {
554 0 : hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), &hm_cfg ); // Q0
555 0 : move16();
556 : }
557 : ELSE
558 : {
559 0 : hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), NULL ); // Q0
560 0 : move16();
561 : }
562 : }
563 : }
564 : }
565 : }
566 :
567 1334052 : return;
568 : }
569 : /*-----------------------------------------------------------------*
570 : * Funtion dec_prm_fx() *
571 : * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
572 : *
573 : * SQ is used for TCX modes
574 : *
575 : * decode parameters according to selected mode *
576 : *-----------------------------------------------------------------*/
577 1248 : void dec_prm_fx(
578 : Word16 *coder_type,
579 : Word16 param[], /* (o) : decoded parameters Q0 */
580 : Word16 param_lpc[], /* (o) : LPC parameters Q0 */
581 : Word16 *total_nbbits, /* i/o : number of bits / decoded bits Q0 */
582 : Decoder_State *st,
583 : Word16 L_frame,
584 : Word16 *bitsRead )
585 : {
586 : Word16 j, k, n, sfr, *prm;
587 : Word16 lg;
588 : Word16 lgFB;
589 : Word16 start_bit_pos;
590 1248 : Word16 acelp_target_bits = -1;
591 1248 : move16();
592 : Word16 tmp;
593 : Word16 nTnsParams;
594 : Word16 nTnsBits;
595 : Word16 nb_subfr;
596 : Word16 nbits_tcx;
597 : Word16 ix, j_old, wordcnt, bitcnt;
598 : Word16 hm_size;
599 : Word16 *prms;
600 : CONTEXT_HM_CONFIG hm_cfg;
601 : CONTEXT_HM_CONFIG *phm_cfg;
602 : Word16 indexBuffer[N_MAX + 1];
603 : Word8 flag_ctx_hm;
604 : Word32 L_tmp;
605 : Word16 num_bits;
606 : UWord16 lsb;
607 : Word16 ltp_mode, gains_mode;
608 : Word16 ind;
609 : Word16 prm_ltp[LTPSIZE];
610 : TCX_LTP_DEC_HANDLE hTcxLtpDec;
611 : TCX_DEC_HANDLE hTcxDec;
612 :
613 1248 : hTcxLtpDec = st->hTcxLtpDec;
614 1248 : hTcxDec = st->hTcxDec;
615 :
616 : /*--------------------------------------------------------------------------------*
617 : * INIT
618 : *--------------------------------------------------------------------------------*/
619 :
620 1248 : hm_cfg.indexBuffer = indexBuffer;
621 1248 : move16();
622 :
623 1248 : IF( EQ_16( st->mdct_sw, MODE1 ) )
624 : {
625 264 : start_bit_pos = 0; /* count from frame start */
626 264 : move16();
627 :
628 : /* Adjust st->bits_frame_core not to subtract MODE2 bandwidth signaling */
629 1584 : FOR( n = 0; n < FRAME_SIZE_NB; n++ )
630 : {
631 1584 : Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */
632 1584 : num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */
633 1584 : assert( num_bits == st->total_brate / 50 );
634 1584 : if ( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) )
635 : {
636 264 : st->bits_frame_core = add( st->bits_frame_core, FrameSizeConfig[n].bandwidth_bits );
637 264 : move16();
638 264 : BREAK;
639 : }
640 : }
641 : }
642 : ELSE
643 : {
644 984 : IF( EQ_16( st->rf_flag, 1 ) )
645 : {
646 : /*Inherent adjustment to accommodate the compact packing used in the RF mode*/
647 0 : start_bit_pos = sub( st->next_bit_pos, 2 ); // Q0
648 : }
649 : ELSE
650 : {
651 984 : start_bit_pos = st->next_bit_pos; // Q0
652 984 : move16();
653 : }
654 : }
655 :
656 : /* Framing parameters */
657 1248 : nb_subfr = st->nb_subfr; // Q0
658 1248 : move16();
659 :
660 : /* Initialize pointers */
661 1248 : prm = param;
662 :
663 : /* Init counters */
664 1248 : j = 0;
665 1248 : move16();
666 :
667 : /* Init LTP data */
668 1248 : hTcxDec->tcx_hm_LtpPitchLag = -1;
669 1248 : move16();
670 1248 : hTcxLtpDec->tcxltp_gain = 0;
671 1248 : move16();
672 :
673 : /*--------------------------------------------------------------------------------*
674 : * HEADER
675 : *--------------------------------------------------------------------------------*/
676 :
677 : /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */
678 1248 : IF( st->tcxonly )
679 : {
680 0 : st->core = add( get_next_indice_fx( st, 1 ), 1 ); // Q0
681 0 : move16();
682 0 : ind = get_next_indice_fx( st, 2 ); // Q0
683 0 : st->clas_dec = ONSET;
684 0 : move16();
685 0 : IF( ind == 0 )
686 : {
687 0 : st->clas_dec = UNVOICED_CLAS;
688 0 : move16();
689 : }
690 0 : ELSE IF( EQ_16( ind, 1 ) )
691 : {
692 0 : st->clas_dec = UNVOICED_TRANSITION;
693 0 : move16();
694 0 : if ( GE_16( st->last_good, VOICED_TRANSITION ) )
695 : {
696 0 : st->clas_dec = VOICED_TRANSITION;
697 0 : move16();
698 : }
699 : }
700 0 : ELSE IF( EQ_16( ind, 2 ) )
701 : {
702 0 : st->clas_dec = VOICED_CLAS;
703 0 : move16();
704 : }
705 0 : *coder_type = INACTIVE;
706 0 : move16();
707 0 : st->VAD = 0;
708 0 : move16();
709 : }
710 : ELSE
711 : {
712 1248 : IF( EQ_16( st->mdct_sw, MODE1 ) )
713 : {
714 : /* 2 bits instead of 3 as TCX is already signaled */
715 264 : st->core = TCX_20_CORE;
716 264 : move16();
717 264 : st->hTcxCfg->coder_type = get_next_indice_fx( st, 2 ); // Q0
718 264 : move16();
719 264 : *coder_type = st->hTcxCfg->coder_type;
720 264 : move16();
721 : }
722 : ELSE
723 : {
724 984 : IF( EQ_16( st->mdct_sw_enable, MODE2 ) )
725 : {
726 984 : IF( get_next_indice_1_fx( st ) != 0 ) /* TCX */
727 : {
728 374 : tmp = get_next_indice_fx( st, 3 ); // Q0
729 374 : assert( !( tmp & 4 ) || !"HQ_CORE encountered in dec_prm_fx" );
730 374 : st->core = TCX_20_CORE;
731 374 : move16();
732 374 : st->hTcxCfg->coder_type = tmp;
733 374 : move16();
734 374 : *coder_type = st->hTcxCfg->coder_type;
735 374 : move16();
736 : }
737 : ELSE /* ACELP */
738 : {
739 610 : st->core = ACELP_CORE;
740 610 : move16();
741 610 : *coder_type = get_next_indice_fx( st, 2 ); // Q0
742 610 : move16();
743 : }
744 : }
745 : ELSE
746 : {
747 0 : IF( EQ_16( st->rf_flag, 1 ) )
748 : {
749 0 : IF( !( st->use_partial_copy ) )
750 : {
751 0 : tmp = get_next_indice_fx( st, 1 );
752 0 : IF( tmp == 0 )
753 : {
754 0 : st->core = ACELP_CORE;
755 0 : move16();
756 : }
757 : ELSE
758 : {
759 0 : st->core = TCX_20_CORE;
760 0 : move16();
761 0 : st->hTcxCfg->coder_type = *coder_type;
762 0 : move16();
763 : }
764 : }
765 : }
766 : ELSE
767 : {
768 0 : st->core = ACELP_CORE;
769 0 : move16();
770 0 : *coder_type = get_next_indice_fx( st, 3 ); // Q0
771 0 : move16();
772 0 : IF( GE_16( *coder_type, ACELP_MODE_MAX ) )
773 : {
774 0 : st->core = TCX_20_CORE;
775 0 : move16();
776 0 : *coder_type = sub( *coder_type, ACELP_MODE_MAX );
777 0 : move16();
778 0 : st->hTcxCfg->coder_type = *coder_type;
779 0 : move16();
780 : }
781 : }
782 : }
783 : }
784 :
785 1248 : test();
786 1248 : IF( ( st->igf != 0 ) && ( st->core == ACELP_CORE ) )
787 : {
788 610 : st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); // Q0
789 610 : move16();
790 : }
791 :
792 1248 : IF( EQ_16( st->rf_flag, 1 ) )
793 : {
794 0 : st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ // Q0
795 0 : move16();
796 : }
797 :
798 : /* Inactive frame detection on non-DTX mode */
799 1248 : st->VAD = 1;
800 1248 : move16();
801 1248 : if ( *coder_type == INACTIVE )
802 : {
803 9 : st->VAD = 0;
804 9 : move16();
805 : }
806 : }
807 :
808 : /*Core extended mode mapping for correct PLC classification*/
809 1248 : st->core_ext_mode = *coder_type;
810 1248 : move16();
811 :
812 1248 : if ( *coder_type == INACTIVE )
813 : {
814 9 : st->core_ext_mode = UNVOICED;
815 9 : move16();
816 : }
817 :
818 : /* Decode previous mode for error concealment */
819 1248 : tmp = 0;
820 1248 : move16();
821 1248 : test();
822 1248 : test();
823 1248 : IF( ( ( st->core != ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 )
824 : {
825 638 : st->last_core_from_bs = get_next_indice_fx( st, 1 );
826 638 : move16();
827 :
828 : /*
829 : need to introduce special error handling for lost transition frames from CNG:
830 : in such cases, the bitstream reader continues with CNG, setting bfi = 0, total_brate = 0
831 : this might result in a not matching last_core transmitted in the BS - we should use this
832 : only for interpreting the bitstream and re-use the internal state for the proper
833 : transition handling; still, for voiced onsets rather stick to wrong windowing...
834 : */
835 638 : test();
836 638 : test();
837 638 : if ( ( !( ( st->last_total_brate == 0 ) && ( sub( st->clas_dec, VOICED_CLAS ) != 0 ) ) ) && ( sub( st->last_core_from_bs, st->last_core ) != 0 ) )
838 : {
839 12 : st->last_core = st->last_core_from_bs;
840 12 : move16();
841 : }
842 : /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/
843 638 : IF( EQ_16( st->core, TCX_10_CORE ) )
844 : {
845 0 : st->last_core = TCX_20_CORE;
846 0 : move16();
847 0 : st->last_core_from_bs = TCX_20_CORE;
848 0 : move16();
849 : }
850 : }
851 :
852 1248 : test();
853 1248 : test();
854 1248 : IF( EQ_16( st->rf_flag, 1 ) && EQ_16( st->use_partial_copy, 1 ) && !st->tcxonly )
855 : {
856 0 : st->bits_frame_core = st->rf_target_bits;
857 0 : move16();
858 : /* offset the indices to read the acelp partial copy */
859 0 : Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */
860 0 : num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */
861 :
862 0 : get_next_indice_tmp_fx( st, sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), 3 ), st->next_bit_pos ) ); // Q0
863 : }
864 :
865 1248 : IF( st->use_partial_copy == 0 )
866 : {
867 : /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */
868 1248 : test();
869 1248 : IF( ( st->last_core == ACELP_CORE ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) )
870 : {
871 616 : st->hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP;
872 616 : move16();
873 : }
874 : ELSE
875 : {
876 632 : test();
877 632 : IF( ( EQ_16( st->core, TCX_10_CORE ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) ) )
878 : {
879 0 : st->hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP;
880 0 : move16();
881 : }
882 : ELSE
883 : {
884 632 : st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode;
885 632 : move16();
886 632 : test();
887 632 : if ( ( NE_16( st->core, TCX_10_CORE ) ) && ( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) )
888 : {
889 33 : st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
890 33 : move16();
891 : }
892 : }
893 : }
894 : /* Set the current overlap mode based on the current frame type and coded overlap mode */
895 1248 : st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
896 1248 : move16();
897 :
898 1248 : IF( st->core != ACELP_CORE )
899 : {
900 638 : tmp = 0;
901 638 : move16();
902 : /* if current TCX mode is not 0 (full overlap), read another bit */
903 638 : IF( get_next_indice_fx( st, 1 ) )
904 : {
905 11 : tmp = add( 2, get_next_indice_fx( st, 1 ) );
906 : }
907 638 : st->hTcxCfg->tcx_curr_overlap_mode = tmp;
908 638 : move16();
909 :
910 : /* TCX10 : always symmetric windows */
911 638 : test();
912 638 : test();
913 638 : test();
914 638 : if ( ( EQ_16( st->core, TCX_20_CORE ) ) && ( tmp == 0 ) && ( st->last_core != ACELP_CORE ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) )
915 : {
916 591 : st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
917 591 : move16();
918 : }
919 : }
920 :
921 : /* SIDE INFO. DECODING */
922 1248 : IF( st->enableGplc )
923 : {
924 : Word16 pitchDiff;
925 : Word16 bits_per_subfr, search_range;
926 984 : bits_per_subfr = 4;
927 984 : move16();
928 984 : search_range = 8;
929 984 : move16();
930 :
931 984 : st->flagGuidedAcelp = get_next_indice_fx( st, 1 ); // Q0
932 984 : move16();
933 :
934 984 : pitchDiff = 0;
935 984 : move16();
936 984 : IF( st->flagGuidedAcelp )
937 : {
938 439 : pitchDiff = get_next_indice_fx( st, bits_per_subfr ); // Q0
939 439 : move16();
940 439 : st->guidedT0 = sub( pitchDiff, search_range ); // Q0
941 439 : move16();
942 : }
943 984 : test();
944 984 : if ( ( pitchDiff == 0 ) && st->flagGuidedAcelp )
945 : {
946 10 : st->flagGuidedAcelp = 0; // Q0
947 10 : move16();
948 : }
949 : }
950 : ELSE
951 : {
952 264 : st->flagGuidedAcelp = 0; // Q0
953 264 : move16();
954 : }
955 :
956 1248 : IF( st->dec_glr )
957 : {
958 984 : move16();
959 984 : st->dec_glr_idx = -1;
960 984 : IF( st->core == ACELP_CORE )
961 : {
962 610 : st->dec_glr_idx = get_next_indice_fx( st, G_LPC_RECOVERY_BITS ); // Q0
963 610 : move16();
964 : }
965 : }
966 : }
967 : /*--------------------------------------------------------------------------------*
968 : * LPC PARAMETERS
969 : *--------------------------------------------------------------------------------*/
970 :
971 : /*Initialization of LPC Mid flag*/
972 1248 : st->acelp_cfg.midLpc = st->acelp_cfg.midLpc_enable;
973 1248 : move16();
974 1248 : test();
975 1248 : test();
976 1248 : if ( ( EQ_16( st->lpcQuantization, 1 ) && ( EQ_16( *coder_type, VOICED ) ) ) || ( st->use_partial_copy ) )
977 : {
978 514 : st->acelp_cfg.midLpc = 0;
979 514 : move16();
980 : }
981 :
982 1248 : IF( st->use_partial_copy == 0 )
983 : {
984 : /* Number of sets of LPC parameters (does not include mid-lpc) */
985 1248 : st->numlpc = 2;
986 1248 : move16();
987 1248 : test();
988 1248 : if ( ( st->tcxonly == 0 ) || LT_16( st->core, TCX_10_CORE ) )
989 : {
990 1248 : st->numlpc = 1;
991 1248 : move16();
992 : }
993 :
994 : /* Decode LPC parameters */
995 1248 : test();
996 1248 : IF( hTcxDec->enableTcxLpc && ( st->core != ACELP_CORE ) )
997 0 : {
998 : Word16 tcx_lpc_cdk;
999 0 : tcx_lpc_cdk = tcxlpc_get_cdk( *coder_type );
1000 0 : dec_lsf_tcxlpc( st, ¶m_lpc, st->narrowBand, tcx_lpc_cdk );
1001 : }
1002 : ELSE
1003 : {
1004 1248 : IF( st->lpcQuantization == 0 )
1005 : {
1006 0 : decode_lpc_avq_fx( st, st->numlpc, param_lpc );
1007 0 : move16();
1008 : }
1009 1248 : ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
1010 : {
1011 1248 : test();
1012 1248 : test();
1013 1248 : IF( EQ_32( st->sr_core, 16000 ) && EQ_16( *coder_type, VOICED ) && ( st->core == ACELP_CORE ) )
1014 : {
1015 268 : lsf_bctcvq_decprm( st, param_lpc );
1016 : }
1017 : ELSE
1018 : {
1019 980 : lsf_msvq_ma_decprm( st, param_lpc );
1020 : }
1021 : }
1022 : ELSE
1023 : {
1024 0 : assert( 0 && "LPC quant not supported!" );
1025 : }
1026 : }
1027 : }
1028 : ELSE
1029 : {
1030 0 : st->numlpc = 1;
1031 0 : move16();
1032 :
1033 0 : test();
1034 0 : IF( EQ_16( st->rf_frame_type, RF_TCXFD ) )
1035 : {
1036 0 : param_lpc[0] = 0; // Q0
1037 0 : move16();
1038 0 : param_lpc[1] = get_next_indice_fx( st, lsf_numbits[0] ); /* VQ 1 */ // Q0
1039 0 : move16();
1040 0 : param_lpc[2] = get_next_indice_fx( st, lsf_numbits[1] ); /* VQ 2 */ // Q0
1041 0 : move16();
1042 0 : param_lpc[3] = get_next_indice_fx( st, lsf_numbits[2] ); /* VQ 3 */ // Q0
1043 0 : move16();
1044 : }
1045 0 : ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) )
1046 : {
1047 : /* LSF indices */
1048 0 : param_lpc[0] = get_next_indice_fx( st, 8 ); /* VQ 1 */ // Q0
1049 0 : move16();
1050 0 : param_lpc[1] = get_next_indice_fx( st, 8 ); /* VQ 2 */ // Q0
1051 0 : move16();
1052 : }
1053 : }
1054 :
1055 1248 : st->bits_common = sub( st->next_bit_pos, start_bit_pos ); // Q0
1056 1248 : move16();
1057 :
1058 :
1059 : /*--------------------------------------------------------------------------------*
1060 : * ACELP
1061 : *--------------------------------------------------------------------------------*/
1062 1248 : test();
1063 1248 : test();
1064 1248 : IF( ( st->core == ACELP_CORE ) && ( st->use_partial_copy == 0 ) )
1065 : {
1066 : /* Target Bits */
1067 610 : acelp_target_bits = sub( st->bits_frame_core, st->bits_common );
1068 :
1069 : {
1070 : Word16 acelp_bits;
1071 610 : move16();
1072 610 : acelp_bits = BITS_ALLOC_config_acelp( acelp_target_bits, *coder_type, &( st->acelp_cfg ), st->narrowBand, st->nb_subfr );
1073 :
1074 610 : if ( acelp_bits < 0 )
1075 : {
1076 0 : st->BER_detect = 1;
1077 0 : move16();
1078 : }
1079 : }
1080 :
1081 : /* Adaptive BPF (2 bits)*/
1082 610 : n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; // Q0
1083 610 : move16();
1084 :
1085 610 : st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); // Q0
1086 610 : IF( n != 0 )
1087 : {
1088 584 : st->bpf_gain_param = get_next_indice_fx( st, n ); // Q0
1089 584 : move16();
1090 : }
1091 :
1092 : /* Mean energy (2 or 3 bits) */
1093 610 : n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; // Q0
1094 610 : move16();
1095 610 : IF( n != 0 )
1096 : {
1097 610 : prm[j] = get_next_indice_fx( st, n ); // Q0
1098 610 : j = add( j, 1 ); // Q0
1099 610 : move16();
1100 : }
1101 :
1102 : /* Subframe parameters */
1103 3660 : FOR( sfr = 0; sfr < nb_subfr; sfr++ )
1104 : {
1105 : /* Pitch lag (4, 5, 6, 8 or 9 bits) */
1106 3050 : n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; // Q0
1107 3050 : move16();
1108 :
1109 3050 : IF( n != 0 )
1110 : {
1111 3050 : prm[j] = get_next_indice_fx( st, n ); // Q0
1112 3050 : j = add( j, 1 ); // Q0
1113 3050 : move16();
1114 : }
1115 :
1116 : /* Adaptive codebook filtering (1 bit) */
1117 3050 : IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) )
1118 : {
1119 1340 : prm[j] = get_next_indice_fx( st, 1 ); // Q0
1120 1340 : j = add( j, 1 ); // Q0
1121 1340 : move16();
1122 : }
1123 :
1124 : /* Innovative codebook */
1125 : {
1126 : /* Decode pulse positions. */
1127 3050 : j_old = j; // Q0
1128 3050 : move16();
1129 3050 : wordcnt = shr( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 4 ); // Q0
1130 3050 : bitcnt = s_and( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 0xF ); // Q0
1131 :
1132 : /* sanity check for testing - not instrumented */
1133 3050 : test();
1134 3050 : IF( GE_16( st->acelp_cfg.fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB ) || ( st->acelp_cfg.fixed_cdk_index[sfr] < 0 ) )
1135 : {
1136 0 : st->acelp_cfg.fixed_cdk_index[sfr] = 0; // Q0
1137 0 : move16();
1138 0 : st->BER_detect = 1; // Q0
1139 0 : move16();
1140 : }
1141 :
1142 12334 : FOR( ix = 0; ix < wordcnt; ix++ )
1143 : {
1144 9284 : prm[j] = (Word16) get_next_indice_fx( st, 16 ); // Q0
1145 9284 : j = add( j, 1 ); // Q0
1146 9284 : move16();
1147 : }
1148 3050 : IF( bitcnt )
1149 : {
1150 3050 : prm[j] = get_next_indice_fx( st, bitcnt ); // Q0
1151 3050 : move16();
1152 : }
1153 :
1154 3050 : j = add( j_old, 8 ); // Q0
1155 : }
1156 :
1157 : /* Gains (5b, 6b or 7b / subfr) */
1158 3050 : n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; // Q0
1159 3050 : move16();
1160 :
1161 3050 : prm[j] = get_next_indice_fx( st, n ); // Q0
1162 3050 : j = add( j, 1 ); // Q0
1163 3050 : move16();
1164 : } /*end of subfr loop*/
1165 : }
1166 :
1167 638 : ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && st->use_partial_copy )
1168 : {
1169 : Word16 acelp_bits =
1170 0 : BITS_ALLOC_config_acelp( st->rf_target_bits, /* target bits ranges from 56 to 72 depending on rf_type */
1171 0 : st->rf_frame_type, /* already offset by 4 to parse the config elements for partial copy */
1172 : &( st->acelp_cfg ), /* acelp_cfg_rf*/
1173 : 0, /* is narrowBand */
1174 0 : st->nb_subfr );
1175 :
1176 0 : if ( acelp_bits < 0 )
1177 : {
1178 0 : st->BER_detect = 1;
1179 0 : move16();
1180 : }
1181 :
1182 : /* rf_frame_type NELP: 7 */
1183 0 : IF( EQ_16( st->rf_frame_type, RF_NELP ) )
1184 : {
1185 : /* NELP gain indices */
1186 0 : st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); // Q0
1187 0 : move16();
1188 0 : st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); // Q0
1189 0 : move16();
1190 0 : st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); // Q0
1191 0 : move16();
1192 :
1193 : /* NELP filter selection index */
1194 0 : st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); // Q0
1195 0 : move16();
1196 :
1197 : /* tbe gainFr */
1198 0 : st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); // Q0
1199 0 : move16();
1200 : }
1201 : ELSE
1202 : {
1203 : /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/
1204 : /* ES pred */
1205 0 : prm[j] = get_next_indice_fx( st, 3 ); // Q0
1206 0 : move16();
1207 0 : j = add( j, 1 ); // Q0
1208 :
1209 0 : ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; // Q0
1210 0 : move16();
1211 0 : gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; // Q0
1212 0 : move16();
1213 :
1214 : /* Subframe parameters */
1215 0 : FOR( sfr = 0; sfr < nb_subfr; sfr++ )
1216 : {
1217 : /* Pitch lag (5, or 8 bits) */
1218 0 : n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; // Q0
1219 0 : move16();
1220 0 : IF( n != 0 )
1221 : {
1222 0 : prm[j] = get_next_indice_fx( st, n ); // Q0
1223 0 : j = add( j, 1 ); // Q0
1224 0 : move16();
1225 : }
1226 :
1227 : /*Innovative codebook*/
1228 0 : test();
1229 0 : test();
1230 0 : test();
1231 0 : IF( EQ_16( st->rf_frame_type, RF_NOPRED ) || ( EQ_16( st->rf_frame_type, RF_GENPRED ) && ( sfr == 0 || EQ_16( sfr, 2 ) ) ) )
1232 : {
1233 : /* NOTE: FCB actual bits need to be backed up as well */
1234 : /*n = ACELP_FIXED_CDK_BITS(st->rf_indx_fcb[fec_offset][sfr]) & 15;*/
1235 0 : prm[j] = get_next_indice_fx( st, 7 ); // Q0
1236 0 : move16();
1237 0 : j = add( j, 8 ); // Q0
1238 : }
1239 :
1240 : /* Gains (5b, 6b or 7b / subfr) */
1241 0 : test();
1242 0 : IF( sfr == 0 || EQ_16( sfr, 2 ) )
1243 : {
1244 0 : n = ACELP_GAINS_BITS[gains_mode]; // Q0
1245 0 : move16();
1246 0 : prm[j] = get_next_indice_fx( st, n ); // Q0
1247 0 : j = add( j, 1 ); // Q0
1248 0 : move16();
1249 : }
1250 : }
1251 :
1252 0 : st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); // Q0
1253 0 : move16();
1254 : }
1255 : }
1256 :
1257 : /*--------------------------------------------------------------------------------*
1258 : * TCX20
1259 : *--------------------------------------------------------------------------------*/
1260 1248 : test();
1261 1248 : IF( EQ_16( st->core, TCX_20_CORE ) && st->use_partial_copy == 0 )
1262 : {
1263 638 : flag_ctx_hm = 0;
1264 638 : move16();
1265 :
1266 638 : if ( st->enablePlcWaveadjust )
1267 : {
1268 0 : st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0
1269 0 : move16();
1270 : }
1271 :
1272 : /* TCX Gain = 7 bits */
1273 638 : prm[j] = get_next_indice_fx( st, 7 ); // Q0
1274 638 : j = add( j, 1 ); // Q0
1275 638 : move16();
1276 :
1277 : /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */
1278 638 : prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0
1279 638 : j = add( j, 1 ); // Q0
1280 638 : move16();
1281 :
1282 : /* LTP data */
1283 : /* PLC pitch info for HB */
1284 638 : test();
1285 638 : IF( hTcxLtpDec->tcxltp != 0 || GT_32( st->sr_core, 25600 ) )
1286 : {
1287 :
1288 638 : prm[j] = get_next_indice_fx( st, 1 ); // Q0
1289 638 : move16();
1290 :
1291 638 : IF( prm[j] )
1292 : {
1293 462 : prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0
1294 462 : move16();
1295 462 : prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0
1296 462 : move16();
1297 : }
1298 :
1299 638 : st->BER_detect = s_or( st->BER_detect,
1300 638 : tcx_ltp_decode_params( &prm[j],
1301 : &( hTcxLtpDec->tcxltp_pitch_int ),
1302 : &( hTcxLtpDec->tcxltp_pitch_fr ),
1303 : &( hTcxLtpDec->tcxltp_gain ),
1304 638 : st->pit_min,
1305 638 : st->pit_fr1,
1306 638 : st->pit_fr2,
1307 638 : st->pit_max,
1308 638 : st->pit_res_max ) );
1309 :
1310 638 : hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15
1311 638 : move16();
1312 638 : hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15
1313 638 : move16();
1314 :
1315 638 : test();
1316 638 : IF( ( st->tcxonly == 0 ) && ( LT_16( hTcxLtpDec->tcxltp_pitch_int, L_frame ) ) )
1317 : {
1318 638 : Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 );
1319 638 : Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr );
1320 638 : hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15
1321 638 : move16();
1322 : }
1323 : }
1324 :
1325 638 : j = add( j, 3 ); // Q0
1326 :
1327 : /* TCX spectral data */
1328 638 : lg = L_frame;
1329 638 : move16();
1330 638 : lgFB = st->hTcxCfg->tcx_coded_lines;
1331 638 : move16();
1332 :
1333 638 : IF( st->last_core_from_bs == ACELP_CORE )
1334 : {
1335 : /* ACE->TCX transition */
1336 36 : lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0
1337 36 : if ( st->hTcxCfg->lfacNext < 0 )
1338 : {
1339 36 : lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0
1340 : }
1341 :
1342 36 : lgFB = add( lgFB, shr( lgFB, 2 ) ); // Q0
1343 : }
1344 :
1345 : /* TNS data */
1346 638 : nTnsParams = 0;
1347 638 : move16();
1348 638 : nTnsBits = 0;
1349 638 : move16();
1350 :
1351 638 : IF( st->hTcxCfg->fIsTNSAllowed )
1352 : {
1353 374 : SetTnsConfig( st->hTcxCfg, 1, (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) );
1354 374 : ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams );
1355 :
1356 374 : j = add( j, nTnsParams ); // Q0
1357 : }
1358 638 : hm_size = shl( mult( st->TcxBandwidth, lg ), 1 );
1359 :
1360 638 : test();
1361 638 : IF( ( hTcxDec->tcx_lpc_shaped_ari != 0 ) && NE_16( st->last_core_from_bs, ACELP_CORE ) )
1362 : {
1363 0 : dec_prm_hm_fx( st, &prm[j], hm_size );
1364 : }
1365 :
1366 638 : nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) );
1367 638 : IF( st->enableGplc != 0 )
1368 : {
1369 374 : nbits_tcx = sub( nbits_tcx, 7 ); // Q0
1370 : }
1371 :
1372 : /*Context HM flag*/
1373 638 : test();
1374 638 : IF( st->hTcxCfg->ctx_hm && ( st->last_core_from_bs != ACELP_CORE ) )
1375 : {
1376 602 : prm[j] = get_next_indice_fx( st, 1 ); // Q0
1377 602 : move16();
1378 602 : nbits_tcx = sub( nbits_tcx, 1 ); // Q0
1379 :
1380 602 : IF( prm[j] )
1381 : {
1382 : Word16 NumIndexBits;
1383 :
1384 55 : tmp = 0;
1385 55 : move16();
1386 55 : IF( GE_16( hm_size, 256 ) )
1387 : {
1388 55 : tmp = 1;
1389 55 : move16();
1390 : }
1391 55 : NumIndexBits = DecodeIndex_fx( st,
1392 : tmp,
1393 55 : prm + j + 1 );
1394 :
1395 55 : flag_ctx_hm = 1;
1396 55 : move16();
1397 :
1398 55 : ConfigureContextHm(
1399 : lgFB,
1400 : nbits_tcx,
1401 55 : *( prm + j + 1 ),
1402 55 : hTcxDec->tcx_hm_LtpPitchLag,
1403 : &hm_cfg );
1404 :
1405 55 : nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0
1406 : }
1407 : }
1408 638 : j = add( j, NPRM_CTX_HM ); // Q0
1409 :
1410 : /* read IGF payload */
1411 638 : IF( st->igf )
1412 : {
1413 :
1414 638 : n = st->next_bit_pos;
1415 638 : move16();
1416 638 : IF( st->last_core_from_bs == ACELP_CORE )
1417 : {
1418 36 : IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 );
1419 36 : IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 );
1420 : }
1421 : ELSE
1422 : {
1423 602 : IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 );
1424 602 : IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 );
1425 : }
1426 :
1427 638 : nbits_tcx = sub( nbits_tcx, sub( st->next_bit_pos, n ) ); // Q0
1428 : }
1429 638 : nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); // Q0
1430 638 : IF( hTcxDec->tcx_lpc_shaped_ari != 0 )
1431 : {
1432 0 : prm[j] = nbits_tcx; /* store length of buffer */ // Q0
1433 0 : j = add( j, 1 ); // Q0
1434 0 : move16();
1435 0 : prms = &prm[j];
1436 0 : FOR( ix = 0; ix < nbits_tcx; ix++ )
1437 : {
1438 0 : prms[ix] = get_next_indice_1_fx( st ); // Q0
1439 0 : move16();
1440 : }
1441 0 : set16_fx( prms + nbits_tcx, 1, 32 );
1442 0 : j = add( j, nbits_tcx ); // Q0
1443 : }
1444 : ELSE
1445 : {
1446 638 : phm_cfg = NULL;
1447 638 : move16();
1448 638 : if ( flag_ctx_hm )
1449 : {
1450 55 : phm_cfg = &hm_cfg;
1451 55 : move16();
1452 : }
1453 638 : hTcxDec->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), phm_cfg ); // Q0
1454 638 : move16();
1455 638 : j = add( j, lg ); // Q0
1456 : }
1457 : }
1458 :
1459 1248 : test();
1460 1248 : test();
1461 1248 : IF( GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) && EQ_16( st->use_partial_copy, 1 ) )
1462 : {
1463 : /* classification */
1464 0 : ind = get_next_indice_fx( st, 2 ); // Q0
1465 0 : st->clas_dec = ONSET;
1466 0 : move16();
1467 :
1468 0 : IF( ind == 0 )
1469 : {
1470 0 : st->clas_dec = UNVOICED_CLAS;
1471 0 : move16();
1472 : }
1473 0 : ELSE IF( EQ_16( ind, 1 ) )
1474 : {
1475 0 : IF( GE_16( st->last_good, VOICED_TRANSITION ) )
1476 : {
1477 0 : st->clas_dec = VOICED_TRANSITION;
1478 0 : move16();
1479 : }
1480 : ELSE
1481 : {
1482 0 : st->clas_dec = UNVOICED_TRANSITION;
1483 0 : move16();
1484 : }
1485 : }
1486 0 : ELSE IF( EQ_16( ind, 2 ) )
1487 : {
1488 0 : st->clas_dec = VOICED_CLAS;
1489 0 : move16();
1490 : }
1491 :
1492 0 : IF( EQ_16( st->rf_frame_type, RF_TCXFD ) )
1493 : {
1494 : /* TCX Gain = 7 bits */
1495 0 : hTcxDec->old_gaintcx_bfi = get_next_indice_fx( st, 7 ); // Q0
1496 0 : move16();
1497 : }
1498 : ELSE
1499 : {
1500 : /* LTP data */
1501 0 : IF( hTcxLtpDec->tcxltp != 0 )
1502 : {
1503 0 : test();
1504 0 : IF( EQ_16( st->rf_frame_type, RF_TCXTD2 ) || EQ_16( st->rf_frame_type, RF_TCXTD1 ) )
1505 : {
1506 0 : prm_ltp[0] = 1; // Q0
1507 0 : move16(); /* LTP active*/
1508 0 : prm_ltp[1] = get_next_indice_fx( st, 9 ); // Q0
1509 0 : prm_ltp[2] = 3; // Q0
1510 0 : move16(); /* max ampl. quantizer output (2bits), anyway not used later*/
1511 :
1512 0 : IF( st->prev_bfi == 0 )
1513 : {
1514 0 : st->BER_detect = s_or( st->BER_detect,
1515 0 : tcx_ltp_decode_params( &prm_ltp[0], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ),
1516 0 : st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ) );
1517 0 : move16();
1518 0 : hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15
1519 0 : move16();
1520 : }
1521 : }
1522 : }
1523 : }
1524 : }
1525 :
1526 :
1527 : /*--------------------------------------------------------------------------------*
1528 : * TCX10
1529 : *--------------------------------------------------------------------------------*/
1530 1248 : IF( EQ_16( st->core, TCX_10_CORE ) )
1531 : {
1532 0 : Word16 tcxltp_prm_0 = 0;
1533 0 : Word16 tcxltp_prm_1 = 0;
1534 0 : Word16 tcxltp_prm_2 = 0;
1535 0 : Word16 nbits_igf = 0;
1536 0 : move16();
1537 0 : move16();
1538 0 : move16();
1539 0 : move16();
1540 0 : move16();
1541 : /* read IGF payload */
1542 0 : IF( st->igf )
1543 : {
1544 :
1545 0 : n = st->next_bit_pos;
1546 0 : move16();
1547 :
1548 0 : IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1 );
1549 0 : IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1 );
1550 0 : IGFDecStoreTCX10SubFrameData( st->hIGFDec, 0 );
1551 :
1552 0 : IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0 );
1553 0 : IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0 );
1554 0 : IGFDecStoreTCX10SubFrameData( st->hIGFDec, 1 );
1555 0 : nbits_igf = sub( st->next_bit_pos, n );
1556 : }
1557 0 : FOR( k = 0; k < 2; k++ )
1558 : {
1559 0 : flag_ctx_hm = 0;
1560 0 : move16();
1561 :
1562 0 : prm = param + ( k * DEC_NPRM_DIV );
1563 0 : j = 0;
1564 0 : move16();
1565 :
1566 0 : nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); // Q0
1567 :
1568 0 : test();
1569 0 : IF( st->enablePlcWaveadjust && k )
1570 : {
1571 0 : st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0
1572 0 : move16();
1573 : }
1574 : /* TCX Gain = 7 bits */
1575 0 : prm[j] = get_next_indice_fx( st, 7 ); // Q0
1576 0 : j = add( j, 1 ); // Q0
1577 0 : move16();
1578 :
1579 : /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */
1580 0 : prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0
1581 0 : j = add( j, 1 ); // Q0
1582 0 : move16();
1583 :
1584 : /* LTP data */
1585 0 : test();
1586 0 : test();
1587 0 : IF( ( k == 0 ) && ( ( hTcxLtpDec->tcxltp != 0 ) || ( GT_32( st->sr_core, 25600 ) ) ) )
1588 : {
1589 0 : prm[j] = get_next_indice_fx( st, 1 ); // Q0
1590 0 : move16();
1591 :
1592 0 : IF( prm[j] )
1593 : {
1594 :
1595 0 : prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0
1596 0 : move16();
1597 0 : prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0
1598 0 : move16();
1599 :
1600 0 : tcxltp_prm_0 = prm[j]; // Q0
1601 0 : move16();
1602 0 : tcxltp_prm_1 = prm[j + 1]; // Q0
1603 0 : move16();
1604 0 : tcxltp_prm_2 = prm[j + 2]; // Q0
1605 0 : move16();
1606 : }
1607 :
1608 0 : st->BER_detect = s_or( st->BER_detect,
1609 0 : tcx_ltp_decode_params( &prm[j],
1610 : &( hTcxLtpDec->tcxltp_pitch_int ),
1611 : &( hTcxLtpDec->tcxltp_pitch_fr ),
1612 : &( hTcxLtpDec->tcxltp_gain ),
1613 0 : st->pit_min,
1614 0 : st->pit_fr1,
1615 0 : st->pit_fr2,
1616 0 : st->pit_max,
1617 0 : st->pit_res_max ) );
1618 0 : move16();
1619 :
1620 0 : hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15
1621 0 : move16();
1622 0 : hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15
1623 0 : move16();
1624 :
1625 0 : j = add( j, 3 ); // Q0
1626 : }
1627 : ELSE
1628 : {
1629 0 : prm[j] = tcxltp_prm_0; // Q0
1630 0 : j = add( j, 1 ); // Q0
1631 0 : move16();
1632 0 : prm[j] = tcxltp_prm_1; // Q0
1633 0 : j = add( j, 1 ); // Q0
1634 0 : move16();
1635 0 : prm[j] = tcxltp_prm_2; // Q0
1636 0 : j = add( j, 1 ); // Q0
1637 0 : move16();
1638 : }
1639 :
1640 : /* TCX spectral data */
1641 0 : lg = shr( L_frame, 1 ); // Q0
1642 0 : lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); // Q0
1643 :
1644 0 : test();
1645 0 : IF( k == 0 && ( st->last_core_from_bs == ACELP_CORE ) )
1646 : {
1647 : /* ACE->TCX transition */
1648 0 : lg = add( lg, st->hTcxCfg->tcx_offset );
1649 0 : IF( st->hTcxCfg->lfacNext < 0 )
1650 : {
1651 0 : lg = sub( lg, st->hTcxCfg->lfacNext );
1652 : }
1653 :
1654 0 : lgFB = add( lgFB, shr( lgFB, 1 ) );
1655 : }
1656 :
1657 : /* TNS data */
1658 0 : nTnsParams = 0;
1659 0 : move16();
1660 0 : nTnsBits = 0;
1661 0 : move16();
1662 :
1663 0 : IF( st->hTcxCfg->fIsTNSAllowed )
1664 : {
1665 0 : test();
1666 0 : IF( st->last_core_from_bs == ACELP_CORE && ( k == 0 ) )
1667 : {
1668 0 : st->BER_detect = 1;
1669 0 : move16();
1670 0 : st->last_core = TCX_20_CORE;
1671 0 : move16();
1672 0 : st->last_core_from_bs = TCX_20_CORE;
1673 0 : move16();
1674 : }
1675 0 : test();
1676 0 : test();
1677 0 : SetTnsConfig( st->hTcxCfg, 0, ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) );
1678 :
1679 0 : ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams );
1680 0 : j = add( j, nTnsParams );
1681 : }
1682 :
1683 0 : hm_size = shl( mult( st->TcxBandwidth, lgFB ), 1 );
1684 :
1685 : /*compute target bits*/
1686 0 : nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, st->bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st->next_bit_pos, start_bit_pos ), nbits_tcx ) ); // Q0
1687 :
1688 : /*Context HM flag*/
1689 0 : test();
1690 0 : test();
1691 0 : IF( st->hTcxCfg->ctx_hm && !( ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ) )
1692 : {
1693 0 : prm[j] = get_next_indice_fx( st, 1 ); // Q0
1694 0 : move16();
1695 0 : nbits_tcx = sub( nbits_tcx, 1 ); // Q0
1696 0 : move16();
1697 :
1698 0 : IF( prm[j] ) /* Read PeriodicityIndex */
1699 : {
1700 0 : Word16 NumIndexBits = DecodeIndex_fx( st, (Word16) GE_16( hm_size, 256 ), prm + j + 1 ); // Q0
1701 :
1702 0 : flag_ctx_hm = 1;
1703 0 : move16();
1704 :
1705 0 : ConfigureContextHm( lgFB, nbits_tcx, *( prm + j + 1 ), -1, &hm_cfg );
1706 :
1707 0 : nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0
1708 : }
1709 : }
1710 0 : j = add( j, NPRM_CTX_HM ); // Q0
1711 0 : phm_cfg = NULL;
1712 0 : move16();
1713 0 : if ( flag_ctx_hm )
1714 : {
1715 0 : phm_cfg = &hm_cfg;
1716 0 : move16();
1717 : }
1718 0 : hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), phm_cfg ); // Q0
1719 0 : move16();
1720 0 : j = add( j, lgFB ); // Q0
1721 :
1722 : } /* k, window index */
1723 : }
1724 :
1725 1248 : IF( !st->use_partial_copy )
1726 : {
1727 1248 : IF( LT_16( sub( *total_nbbits, bitsRead[0] ), sub( st->next_bit_pos, start_bit_pos ) ) )
1728 : {
1729 0 : st->BER_detect = 1;
1730 0 : move16();
1731 0 : st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); // Q0
1732 0 : move16();
1733 : }
1734 1248 : bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); // Q0
1735 1248 : move16();
1736 : }
1737 :
1738 1248 : return;
1739 : }
1740 :
1741 :
1742 : /*-------------------------------------------------------------------*
1743 : * getTCXMode_ivas()
1744 : *
1745 : * get TCX mode
1746 : *--------------------------------------------------------------------*/
1747 773210 : void getTCXMode_ivas_fx(
1748 : Decoder_State *st, /* i/o: decoder memory state */
1749 : Decoder_State *st0, /* i : bitstream */
1750 : const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */
1751 : )
1752 : {
1753 : UWord16 ind;
1754 :
1755 773210 : IF( st->tcxonly )
1756 : {
1757 : /* get core */
1758 662012 : ind = get_next_indice_fx( st0, 1 ); /* Store decoder memory of last_core */
1759 662012 : st->core = add( ind, TCX_20_CORE );
1760 662012 : move16();
1761 : /* get class */
1762 662012 : ind = get_next_indice_fx( st0, 2 );
1763 :
1764 662012 : st->clas_dec = ONSET;
1765 662012 : move16();
1766 662012 : IF( ind == 0 )
1767 : {
1768 344241 : st->clas_dec = UNVOICED_CLAS;
1769 344241 : move16();
1770 : }
1771 317771 : ELSE IF( EQ_16( ind, 1 ) )
1772 : {
1773 40065 : IF( GE_16( st->last_good, VOICED_TRANSITION ) )
1774 : {
1775 32488 : st->clas_dec = VOICED_TRANSITION;
1776 32488 : move16();
1777 : }
1778 : ELSE
1779 : {
1780 7577 : st->clas_dec = UNVOICED_TRANSITION;
1781 7577 : move16();
1782 : }
1783 : }
1784 277706 : ELSE IF( EQ_16( ind, 2 ) )
1785 : {
1786 241672 : st->clas_dec = VOICED_CLAS;
1787 241672 : move16();
1788 : }
1789 :
1790 662012 : st->coder_type = INACTIVE;
1791 662012 : move16();
1792 662012 : test();
1793 662012 : IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag )
1794 : {
1795 152892 : st->VAD = get_next_indice_fx( st0, 1 );
1796 152892 : move16();
1797 : }
1798 : ELSE
1799 : {
1800 509120 : st->VAD = 0;
1801 509120 : move16();
1802 : }
1803 : }
1804 : ELSE
1805 : {
1806 111198 : IF( EQ_16( st->mdct_sw, MODE1 ) )
1807 : {
1808 : /* 2 bits instead of 3 as TCX is already signaled */
1809 111198 : st->core = TCX_20_CORE;
1810 111198 : move16();
1811 111198 : st->hTcxCfg->coder_type = get_next_indice_fx( st0, 2 );
1812 111198 : move16();
1813 111198 : st->coder_type = st->hTcxCfg->coder_type;
1814 111198 : move16();
1815 : }
1816 : ELSE
1817 : {
1818 0 : IF( EQ_16( st->mdct_sw_enable, MODE2 ) )
1819 : {
1820 0 : IF( get_next_indice_1_fx( st0 ) )
1821 : {
1822 0 : ind = get_next_indice_fx( st0, 3 );
1823 0 : assert( !( ind & 4 ) || !"HQ_CORE encountered in dec_prm_ivas" );
1824 0 : st->core = TCX_20_CORE;
1825 0 : move16();
1826 0 : st->hTcxCfg->coder_type = ind;
1827 0 : move16();
1828 0 : st->coder_type = st->hTcxCfg->coder_type;
1829 0 : move16();
1830 : }
1831 : ELSE /* ACELP */
1832 : {
1833 0 : st->core = ACELP_CORE;
1834 0 : move16();
1835 0 : st->coder_type = get_next_indice_fx( st0, 2 );
1836 0 : move16();
1837 : }
1838 : }
1839 : ELSE
1840 : {
1841 0 : IF( EQ_16( st->rf_flag, 1 ) )
1842 : {
1843 0 : IF( !st->use_partial_copy )
1844 : {
1845 0 : ind = get_next_indice_fx( st0, 1 );
1846 0 : IF( ind == 0 )
1847 : {
1848 0 : st->core = ACELP_CORE;
1849 0 : move16();
1850 : }
1851 : ELSE
1852 : {
1853 0 : st->core = TCX_20_CORE;
1854 0 : move16();
1855 0 : st->hTcxCfg->coder_type = st->coder_type;
1856 0 : move16();
1857 : }
1858 : }
1859 : }
1860 : ELSE
1861 : {
1862 0 : ind = get_next_indice_fx( st, 3 );
1863 0 : IF( LT_16( ind, ACELP_MODE_MAX ) )
1864 : {
1865 0 : st->core = ACELP_CORE;
1866 0 : move16();
1867 0 : st->coder_type = ind;
1868 0 : move16();
1869 : }
1870 : ELSE
1871 : {
1872 0 : st->core = TCX_20_CORE;
1873 0 : move16();
1874 0 : st->hTcxCfg->coder_type = sub( ind, ACELP_MODE_MAX );
1875 0 : move16();
1876 0 : st->coder_type = st->hTcxCfg->coder_type;
1877 0 : move16();
1878 : }
1879 : }
1880 : }
1881 : }
1882 :
1883 111198 : IF( EQ_16( st->element_mode, EVS_MONO ) )
1884 : {
1885 0 : test();
1886 0 : IF( st->igf && EQ_16( st->core, ACELP_CORE ) )
1887 : {
1888 0 : st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) );
1889 0 : move16();
1890 : }
1891 :
1892 0 : IF( st->rf_flag )
1893 : {
1894 0 : st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */
1895 0 : move16();
1896 : }
1897 : }
1898 :
1899 : /* Inactive frame detection on non-DTX mode */
1900 111198 : IF( EQ_16( st->coder_type, INACTIVE ) )
1901 : {
1902 11517 : st->VAD = 0;
1903 11517 : move16();
1904 : }
1905 : ELSE
1906 : {
1907 99681 : st->VAD = 1;
1908 99681 : move16();
1909 : }
1910 : }
1911 :
1912 : /*Core extended mode mapping for correct PLC classification*/
1913 773210 : st->core_ext_mode = st->coder_type;
1914 773210 : move16();
1915 773210 : if ( EQ_16( st->coder_type, INACTIVE ) )
1916 : {
1917 673529 : st->core_ext_mode = UNVOICED;
1918 673529 : move16();
1919 : }
1920 :
1921 773210 : return;
1922 : }
1923 :
1924 : /*-------------------------------------------------------------------*
1925 : * getTCXWindowing_ivas()
1926 : *
1927 : * get TCX transform type for each subframe
1928 : *--------------------------------------------------------------------*/
1929 773210 : void getTCXWindowing_ivas_fx(
1930 : const Word16 core, /* i : current core */
1931 : const Word16 last_core, /* i : last frame core */
1932 : const Word16 element_mode, /* i : element mode */
1933 : TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */
1934 : Decoder_State *st0 /* i : bitstream */
1935 : )
1936 : {
1937 : Word16 overlap_code;
1938 :
1939 : /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */
1940 773210 : test();
1941 773210 : test();
1942 773210 : test();
1943 773210 : IF( EQ_16( last_core, ACELP_CORE ) || EQ_16( last_core, AMR_WB_CORE ) )
1944 : {
1945 8115 : hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP;
1946 8115 : move16();
1947 : }
1948 765095 : ELSE IF( EQ_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) )
1949 : {
1950 11160 : hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP;
1951 11160 : move16();
1952 : }
1953 753935 : ELSE IF( NE_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) )
1954 : {
1955 17852 : hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
1956 17852 : move16();
1957 : }
1958 : ELSE
1959 : {
1960 736083 : hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
1961 736083 : move16();
1962 : }
1963 :
1964 : /* Set the current overlap mode based on the current frame type and coded overlap mode */
1965 773210 : hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
1966 773210 : move16();
1967 :
1968 773210 : IF( NE_16( core, ACELP_CORE ) )
1969 : {
1970 773210 : overlap_code = 0;
1971 773210 : move16();
1972 773210 : IF( get_next_indice_fx( st0, 1 ) )
1973 : {
1974 14037 : overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
1975 : }
1976 :
1977 : assert( MIN_OVERLAP == 2 && HALF_OVERLAP == 3 );
1978 773210 : hTcxCfg->tcx_curr_overlap_mode = overlap_code;
1979 773210 : move16();
1980 : /*TCX10 : always symmetric windows*/
1981 773210 : test();
1982 773210 : test();
1983 773210 : test();
1984 773210 : IF( EQ_16( core, TCX_20_CORE ) && ( overlap_code == 0 ) && NE_16( last_core, ACELP_CORE ) && NE_16( last_core, AMR_WB_CORE ) )
1985 : {
1986 741735 : hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
1987 741735 : move16();
1988 : }
1989 : }
1990 :
1991 773210 : test();
1992 773210 : IF( NE_16( element_mode, EVS_MONO ) && EQ_16( core, TCX_10_CORE ) )
1993 : {
1994 : /* also read last overlap */
1995 14619 : overlap_code = 0;
1996 14619 : move16();
1997 :
1998 14619 : IF( get_next_indice_fx( st0, 1 ) )
1999 : {
2000 3385 : overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
2001 : }
2002 :
2003 14619 : hTcxCfg->tcx_last_overlap_mode = overlap_code;
2004 14619 : move16();
2005 : }
2006 :
2007 773210 : return;
2008 : }
|