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 736302 : 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 736302 : IF( st->use_partial_copy == 0 )
29 : {
30 : /* Number of sets of LPC parameters (does not include mid-lpc) */
31 736302 : test();
32 736302 : IF( ( st->tcxonly == 0 ) || LT_16( st->core, TCX_10_CORE ) )
33 : {
34 722492 : st->numlpc = 1;
35 722492 : move16();
36 : }
37 : ELSE
38 : {
39 13810 : st->numlpc = 2;
40 13810 : move16();
41 : }
42 :
43 : /* Decode LPC parameters */
44 736302 : test();
45 736302 : IF( st->hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) )
46 14042 : {
47 : Word16 tcx_lpc_cdk;
48 14042 : tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type );
49 14042 : dec_lsf_tcxlpc( st0, ¶m_lpc, st->narrowBand, tcx_lpc_cdk );
50 : }
51 : ELSE
52 : {
53 722260 : IF( st->lpcQuantization == 0 )
54 : {
55 620228 : decode_lpc_avq_ivas_fx( st0, st->numlpc, param_lpc, ch, st->element_mode, sns_low_br_mode );
56 : }
57 102032 : ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
58 : {
59 102032 : test();
60 102032 : test();
61 102032 : 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 102032 : 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 736302 : return;
104 : }
105 :
106 12764 : 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 12764 : test();
115 12764 : IF( NE_16( st->hTcxCfg->coder_type, VOICED ) && NE_16( st->hTcxCfg->coder_type, GENERIC ) )
116 : {
117 1991 : prm_hm[0] = 0;
118 1991 : move16();
119 :
120 1991 : return;
121 : }
122 :
123 10773 : prm_hm[1] = -1;
124 10773 : move16();
125 10773 : prm_hm[2] = 0;
126 10773 : move16();
127 :
128 : /* Flag */
129 10773 : prm_hm[0] = get_next_indice_fx( st, 1 ); // Q0
130 10773 : move16();
131 :
132 10773 : IF( prm_hm[0] != 0 )
133 : {
134 5347 : tmp = 0;
135 5347 : move16();
136 5347 : if ( GE_16( L_frame, 256 ) )
137 : {
138 5347 : tmp = 1;
139 5347 : move16();
140 : }
141 : /* Periodicity index */
142 5347 : DecodeIndex_fx( st, tmp, &prm_hm[1] );
143 :
144 : /* Gain index */
145 5347 : IF( EQ_16( st->hTcxCfg->coder_type, VOICED ) )
146 : {
147 1893 : prm_hm[2] = get_next_indice_fx( st, kTcxHmNumGainBits );
148 1893 : move16();
149 : }
150 : }
151 : }
152 :
153 : /*-------------------------------------------------------------------*
154 : * getTCXparam_fx()
155 : *
156 : * get TCX core parameters
157 : *-------------------------------------------------------------------*/
158 :
159 1445214 : 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 1445214 : TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
179 1445214 : TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
180 :
181 :
182 1445214 : IF( pre_past_flag == 0 )
183 : {
184 613798 : pre_part = 1;
185 613798 : move16();
186 613798 : post_part = 0;
187 613798 : move16();
188 : }
189 831416 : ELSE IF( EQ_16( pre_past_flag, 1 ) )
190 : {
191 613798 : pre_part = 0;
192 613798 : move16();
193 613798 : post_part = 1;
194 613798 : move16();
195 : }
196 : ELSE
197 : {
198 217618 : pre_part = 1;
199 217618 : move16();
200 217618 : post_part = 1;
201 217618 : move16();
202 : }
203 :
204 : /* initialization */
205 1445214 : tcxltp_prm_0 = 0;
206 1445214 : move16();
207 1445214 : tcxltp_prm_1 = 0;
208 1445214 : move16();
209 1445214 : tcxltp_prm_2 = 0;
210 1445214 : move16();
211 1445214 : nbits_igf = 0;
212 1445214 : move16();
213 :
214 1445214 : PeriodicityIndex = 0;
215 1445214 : move16();
216 1445214 : useHarmonicModel = 0;
217 1445214 : move16();
218 :
219 1445214 : core = st->core;
220 1445214 : move16();
221 1445214 : last_core = st->last_core;
222 1445214 : move16();
223 :
224 1445214 : nSubframes = 1;
225 1445214 : move16();
226 1445214 : if ( EQ_16( core, TCX_10_CORE ) )
227 : {
228 30361 : nSubframes = 2;
229 30361 : move16();
230 : }
231 :
232 1445214 : test();
233 1445214 : test();
234 1445214 : IF( LT_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf && EQ_16( core, TCX_10_CORE ) )
235 : {
236 : /* get IGF */
237 5628 : FOR( k = 0; k < nSubframes; k++ )
238 : {
239 3752 : ix = st->next_bit_pos;
240 3752 : move16();
241 3752 : IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k );
242 3752 : IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k );
243 3752 : IGFDecStoreTCX10SubFrameData( st->hIGFDec, k );
244 :
245 3752 : nbits_igf = add( nbits_igf, sub( st0->next_bit_pos, ix ) ); // Q0
246 : }
247 : }
248 : /* loop over subframes */
249 2920789 : FOR( k = 0; k < nSubframes; k++ )
250 : {
251 1475575 : flag_ctx_hm = 0;
252 1475575 : move16();
253 1475575 : prm = param + k * DEC_NPRM_DIV;
254 1475575 : j = 0;
255 1475575 : move16();
256 1475575 : nbits_tcx = sub( st0->next_bit_pos, start_bit_pos ); // Q0
257 :
258 1475575 : test();
259 1475575 : test();
260 1475575 : 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 1475575 : IF( post_part )
267 : {
268 : /* TCX Gain */
269 847566 : prm[j] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); // Q0
270 847566 : j = add( j, 1 ); // Q0
271 847566 : move16();
272 :
273 : /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */
274 847566 : prm[j] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); // Q0
275 847566 : j = add( j, 1 ); // Q0
276 :
277 847566 : move16();
278 : }
279 : ELSE
280 : {
281 628009 : j = add( j, 1 + NOISE_FILL_RANGES ); // Q0
282 : }
283 :
284 : /* LTP data */
285 1475575 : IF( pre_part )
286 : {
287 847566 : test();
288 847566 : test();
289 847566 : IF( ( k == 0 ) && ( hTcxLtpDec->tcxltp || GT_32( st->sr_core, 25600 ) ) ) /* PLC pitch info for HB */
290 : {
291 831416 : prm[j] = get_next_indice_fx( st0, 1 ); // Q0
292 831416 : move16();
293 831416 : IF( prm[j] )
294 : {
295 557073 : prm[add( j, 1 )] = get_next_indice_fx( st0, 9 ); // Q0
296 557073 : move16();
297 557073 : prm[add( j, 2 )] = get_next_indice_fx( st0, 2 ); // Q0
298 557073 : move16();
299 557073 : tcxltp_prm_0 = prm[j]; // Q0
300 557073 : move16();
301 557073 : tcxltp_prm_1 = prm[j + 1]; // Q0
302 557073 : move16();
303 557073 : tcxltp_prm_2 = prm[j + 2]; // Q0
304 557073 : move16();
305 : }
306 831416 : 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 831416 : move16();
308 831416 : hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15
309 831416 : move16();
310 :
311 831416 : test();
312 831416 : test();
313 831416 : IF( EQ_16( core, TCX_20_CORE ) && !st->tcxonly && LT_16( hTcxLtpDec->tcxltp_pitch_int, st->L_frame ) )
314 116074 : {
315 : // To be done at the end
316 116074 : Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 );
317 116074 : Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr );
318 116074 : hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15
319 116074 : move16();
320 : }
321 : ELSE
322 : {
323 715342 : hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15
324 715342 : move16();
325 : }
326 831416 : j = add( j, 3 ); // Q0
327 : }
328 : ELSE
329 : {
330 16150 : prm[j] = tcxltp_prm_0; // Q0
331 16150 : j = add( j, 1 ); // Q0
332 16150 : move16();
333 16150 : prm[j] = tcxltp_prm_1; // Q0
334 16150 : j = add( j, 1 ); // Q0
335 16150 : move16();
336 16150 : prm[j] = tcxltp_prm_2; // Q0
337 16150 : j = add( j, 1 ); // Q0
338 16150 : move16();
339 : }
340 : }
341 :
342 : /* TCX spectral data */
343 1475575 : lg = shr( st->L_frame, sub( nSubframes, 1 ) ); // Q0
344 1475575 : lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) ); // Q0
345 :
346 1475575 : test();
347 1475575 : test();
348 1475575 : IF( post_part && ( k == 0 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) )
349 : {
350 : /* ACE->TCX transition */
351 8343 : lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0
352 8343 : lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); // Q0
353 :
354 8343 : IF( st->hTcxCfg->lfacNext < 0 )
355 : {
356 8343 : lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0
357 : }
358 : }
359 :
360 1475575 : IF( pre_part )
361 : {
362 : /* TNS data */
363 847566 : nTnsParams = 0;
364 847566 : move16();
365 847566 : nTnsBits = 0;
366 847566 : move16();
367 :
368 847566 : IF( st->hTcxCfg->fIsTNSAllowed )
369 : {
370 780527 : test();
371 780527 : test();
372 780527 : 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 780527 : SetTnsConfig( st->hTcxCfg, (Word16) EQ_16( core, TCX_20_CORE ), (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) );
381 :
382 780527 : ix = 0;
383 780527 : move16();
384 780527 : IF( no_param_tns )
385 : {
386 10505 : ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */ // Q0
387 : }
388 780527 : IF( ix )
389 : {
390 2539 : prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */ // Q0
391 2539 : move16();
392 2539 : nTnsParams = no_param_tns[k]; // Q0
393 2539 : move16();
394 : }
395 : ELSE
396 : {
397 777988 : ReadTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams );
398 : }
399 780527 : hTcxDec->tnsActive[k] = 0; // Q0
400 780527 : move16();
401 780527 : if ( prm[j] != 0 )
402 : {
403 87148 : hTcxDec->tnsActive[k] = nTnsParams; // Q0
404 87148 : move16();
405 : }
406 780527 : IF( nTnsBitsTCX10 != NULL )
407 : {
408 628009 : IF( no_param_tns )
409 : {
410 10505 : nTnsBitsTCX10[k] = add( nTnsBits, 1 ); // Q0
411 10505 : move16();
412 : }
413 : ELSE
414 : {
415 617504 : nTnsBitsTCX10[k] = add( nTnsBits, 0 ); // Q0
416 617504 : move16();
417 : }
418 : }
419 :
420 780527 : j = add( j, nTnsParams ); // Q0
421 : }
422 :
423 847566 : IF( post_part )
424 : {
425 219557 : IF( EQ_16( core, TCX_20_CORE ) )
426 : {
427 : // Q-factor of TcxBandwidth is 15 : derived from getTcxBandwidth function
428 215679 : hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) ); // Q0
429 215679 : test();
430 215679 : IF( hTcxDec->tcx_lpc_shaped_ari && ( st->last_core_from_bs != ACELP_CORE ) )
431 : {
432 12764 : dec_prm_hm_fx( st0, &prm[j], hm_size );
433 : }
434 :
435 215679 : nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0
436 : }
437 : ELSE
438 : {
439 3878 : hm_size = mult( st->TcxBandwidth, shl( lgFB, 1 ) ); // Q0
440 3878 : 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 219557 : test();
445 219557 : test();
446 219557 : IF( st->hTcxCfg->ctx_hm && !( ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ) )
447 : {
448 171176 : useHarmonicModel = get_next_indice_fx( st0, 1 ); // Q0
449 171176 : prm[j] = useHarmonicModel; // Q0
450 171176 : move16();
451 171176 : nbits_tcx = sub( nbits_tcx, 1 ); // Q0
452 :
453 171176 : IF( useHarmonicModel )
454 : {
455 11890 : ix = DecodeIndex_fx( st0, (Word16) GE_16( hm_size, 256 ), prm + add( j, 1 ) );
456 11890 : flag_ctx_hm = 1; // Q0
457 11890 : move16();
458 11890 : PeriodicityIndex = *( prm + add( j, 1 ) );
459 11890 : IF( st->element_mode == EVS_MONO )
460 : {
461 0 : ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg );
462 : }
463 11890 : nbits_tcx = sub( nbits_tcx, ix ); // Q0
464 : }
465 : }
466 : }
467 847566 : j = add( j, NPRM_CTX_HM ); // Q0
468 :
469 : /* read IGF payload */
470 847566 : test();
471 847566 : IF( post_part && EQ_16( core, TCX_20_CORE ) )
472 : {
473 215679 : IF( st->igf )
474 : {
475 205267 : ix = st->next_bit_pos; // Q0
476 205267 : move16();
477 205267 : IF( st->last_core_from_bs == ACELP_CORE )
478 : {
479 6714 : IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 );
480 6714 : IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 );
481 : }
482 : ELSE
483 : {
484 198553 : IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 );
485 198553 : IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 );
486 : }
487 :
488 205267 : nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) ); // Q0
489 : }
490 215679 : nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0
491 : }
492 631887 : ELSE IF( p_param != NULL )
493 : {
494 628009 : p_param[k] = j; // Q0
495 628009 : move16();
496 : }
497 : }
498 : ELSE
499 : {
500 628009 : j = p_param[k]; // Q0
501 628009 : move16();
502 :
503 628009 : nbits_tcx = st->bits_frame_channel; // Q0
504 628009 : move16();
505 628009 : if ( EQ_16( st->core, TCX_10_CORE ) )
506 : {
507 28422 : nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); // Q0
508 : }
509 : }
510 :
511 1475575 : IF( post_part )
512 : {
513 847566 : test();
514 847566 : IF( hTcxDec->tcx_lpc_shaped_ari && EQ_16( core, TCX_20_CORE ) )
515 : {
516 14042 : prm[j] = nbits_tcx; /* store length of buffer */ // Q0
517 14042 : j = add( j, 1 ); // Q0
518 14042 : move16();
519 14042 : prms = &prm[j];
520 2294688 : FOR( ix = 0; ix < nbits_tcx; ix++ )
521 : {
522 2280646 : prms[ix] = get_next_indice_1_fx( st0 ); // Q0
523 : }
524 463386 : FOR( ix = 0; ix < 32; ix++ )
525 : {
526 449344 : prms[ix + nbits_tcx] = 1; // Q0
527 449344 : move16();
528 : }
529 14042 : j = add( j, nbits_tcx ); // Q0
530 : }
531 : ELSE
532 : {
533 833524 : IF( st->element_mode > EVS_MONO )
534 : {
535 833524 : IF( useHarmonicModel )
536 : {
537 11890 : ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg );
538 : }
539 833524 : IF( flag_ctx_hm )
540 : {
541 11890 : 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 11890 : move16();
543 : }
544 : ELSE
545 : {
546 821634 : 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 821634 : 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 1445214 : 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 1246 : 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 1246 : Word16 acelp_target_bits = -1;
591 1246 : 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 1246 : hTcxLtpDec = st->hTcxLtpDec;
614 1246 : hTcxDec = st->hTcxDec;
615 :
616 : /*--------------------------------------------------------------------------------*
617 : * INIT
618 : *--------------------------------------------------------------------------------*/
619 :
620 1246 : hm_cfg.indexBuffer = indexBuffer;
621 1246 : move16();
622 :
623 1246 : IF( EQ_16( st->mdct_sw, MODE1 ) )
624 : {
625 262 : start_bit_pos = 0; /* count from frame start */
626 262 : move16();
627 :
628 : /* Adjust st->bits_frame_core not to subtract MODE2 bandwidth signaling */
629 1572 : FOR( n = 0; n < FRAME_SIZE_NB; n++ )
630 : {
631 1572 : Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */
632 1572 : num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */
633 1572 : assert( num_bits == st->total_brate / 50 );
634 1572 : if ( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) )
635 : {
636 262 : st->bits_frame_core = add( st->bits_frame_core, FrameSizeConfig[n].bandwidth_bits );
637 262 : move16();
638 262 : 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 1246 : nb_subfr = st->nb_subfr; // Q0
658 1246 : move16();
659 :
660 : /* Initialize pointers */
661 1246 : prm = param;
662 :
663 : /* Init counters */
664 1246 : j = 0;
665 1246 : move16();
666 :
667 : /* Init LTP data */
668 1246 : hTcxDec->tcx_hm_LtpPitchLag = -1;
669 1246 : move16();
670 1246 : hTcxLtpDec->tcxltp_gain = 0;
671 1246 : move16();
672 :
673 : /*--------------------------------------------------------------------------------*
674 : * HEADER
675 : *--------------------------------------------------------------------------------*/
676 :
677 : /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */
678 1246 : 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 1246 : IF( EQ_16( st->mdct_sw, MODE1 ) )
713 : {
714 : /* 2 bits instead of 3 as TCX is already signaled */
715 262 : st->core = TCX_20_CORE;
716 262 : move16();
717 262 : st->hTcxCfg->coder_type = get_next_indice_fx( st, 2 ); // Q0
718 262 : move16();
719 262 : *coder_type = st->hTcxCfg->coder_type;
720 262 : 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 372 : tmp = get_next_indice_fx( st, 3 ); // Q0
729 372 : assert( !( tmp & 4 ) || !"HQ_CORE encountered in dec_prm_fx" );
730 372 : st->core = TCX_20_CORE;
731 372 : move16();
732 372 : st->hTcxCfg->coder_type = tmp;
733 372 : move16();
734 372 : *coder_type = st->hTcxCfg->coder_type;
735 372 : move16();
736 : }
737 : ELSE /* ACELP */
738 : {
739 612 : st->core = ACELP_CORE;
740 612 : move16();
741 612 : *coder_type = get_next_indice_fx( st, 2 ); // Q0
742 612 : 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 1246 : test();
786 1246 : IF( ( st->igf != 0 ) && ( st->core == ACELP_CORE ) )
787 : {
788 612 : st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); // Q0
789 612 : move16();
790 : }
791 :
792 1246 : 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 1246 : st->VAD = 1;
800 1246 : move16();
801 1246 : if ( *coder_type == INACTIVE )
802 : {
803 10 : st->VAD = 0;
804 10 : move16();
805 : }
806 : }
807 :
808 : /*Core extended mode mapping for correct PLC classification*/
809 1246 : st->core_ext_mode = *coder_type;
810 1246 : move16();
811 :
812 1246 : if ( *coder_type == INACTIVE )
813 : {
814 10 : st->core_ext_mode = UNVOICED;
815 10 : move16();
816 : }
817 :
818 : /* Decode previous mode for error concealment */
819 1246 : tmp = 0;
820 1246 : move16();
821 1246 : test();
822 1246 : test();
823 1246 : IF( ( ( st->core != ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 )
824 : {
825 634 : st->last_core_from_bs = get_next_indice_fx( st, 1 );
826 634 : 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 634 : test();
836 634 : test();
837 634 : 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 14 : st->last_core = st->last_core_from_bs;
840 14 : move16();
841 : }
842 : /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/
843 634 : 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 1246 : test();
853 1246 : test();
854 1246 : 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 1246 : 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 1246 : test();
869 1246 : IF( ( st->last_core == ACELP_CORE ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) )
870 : {
871 621 : st->hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP;
872 621 : move16();
873 : }
874 : ELSE
875 : {
876 625 : test();
877 625 : 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 625 : st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode;
885 625 : move16();
886 625 : test();
887 625 : if ( ( NE_16( st->core, TCX_10_CORE ) ) && ( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) )
888 : {
889 36 : st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
890 36 : move16();
891 : }
892 : }
893 : }
894 : /* Set the current overlap mode based on the current frame type and coded overlap mode */
895 1246 : st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
896 1246 : move16();
897 :
898 1246 : IF( st->core != ACELP_CORE )
899 : {
900 634 : tmp = 0;
901 634 : move16();
902 : /* if current TCX mode is not 0 (full overlap), read another bit */
903 634 : IF( get_next_indice_fx( st, 1 ) )
904 : {
905 11 : tmp = add( 2, get_next_indice_fx( st, 1 ) );
906 : }
907 634 : st->hTcxCfg->tcx_curr_overlap_mode = tmp;
908 634 : move16();
909 :
910 : /* TCX10 : always symmetric windows */
911 634 : test();
912 634 : test();
913 634 : test();
914 634 : 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 585 : st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
917 585 : move16();
918 : }
919 : }
920 :
921 : /* SIDE INFO. DECODING */
922 1246 : 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 437 : pitchDiff = get_next_indice_fx( st, bits_per_subfr ); // Q0
939 437 : move16();
940 437 : st->guidedT0 = sub( pitchDiff, search_range ); // Q0
941 437 : move16();
942 : }
943 984 : test();
944 984 : if ( ( pitchDiff == 0 ) && st->flagGuidedAcelp )
945 : {
946 15 : st->flagGuidedAcelp = 0; // Q0
947 15 : move16();
948 : }
949 : }
950 : ELSE
951 : {
952 262 : st->flagGuidedAcelp = 0; // Q0
953 262 : move16();
954 : }
955 :
956 1246 : IF( st->dec_glr )
957 : {
958 984 : move16();
959 984 : st->dec_glr_idx = -1;
960 984 : IF( st->core == ACELP_CORE )
961 : {
962 612 : st->dec_glr_idx = get_next_indice_fx( st, G_LPC_RECOVERY_BITS ); // Q0
963 612 : move16();
964 : }
965 : }
966 : }
967 : /*--------------------------------------------------------------------------------*
968 : * LPC PARAMETERS
969 : *--------------------------------------------------------------------------------*/
970 :
971 : /*Initialization of LPC Mid flag*/
972 1246 : st->acelp_cfg.midLpc = st->acelp_cfg.midLpc_enable;
973 1246 : move16();
974 1246 : test();
975 1246 : test();
976 1246 : if ( ( EQ_16( st->lpcQuantization, 1 ) && ( EQ_16( *coder_type, VOICED ) ) ) || ( st->use_partial_copy ) )
977 : {
978 524 : st->acelp_cfg.midLpc = 0;
979 524 : move16();
980 : }
981 :
982 1246 : IF( st->use_partial_copy == 0 )
983 : {
984 : /* Number of sets of LPC parameters (does not include mid-lpc) */
985 1246 : st->numlpc = 2;
986 1246 : move16();
987 1246 : test();
988 1246 : if ( ( st->tcxonly == 0 ) || LT_16( st->core, TCX_10_CORE ) )
989 : {
990 1246 : st->numlpc = 1;
991 1246 : move16();
992 : }
993 :
994 : /* Decode LPC parameters */
995 1246 : test();
996 1246 : 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 1246 : IF( st->lpcQuantization == 0 )
1005 : {
1006 0 : decode_lpc_avq_fx( st, st->numlpc, param_lpc );
1007 0 : move16();
1008 : }
1009 1246 : ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
1010 : {
1011 1246 : test();
1012 1246 : test();
1013 1246 : IF( EQ_32( st->sr_core, 16000 ) && EQ_16( *coder_type, VOICED ) && ( st->core == ACELP_CORE ) )
1014 : {
1015 270 : lsf_bctcvq_decprm( st, param_lpc );
1016 : }
1017 : ELSE
1018 : {
1019 976 : 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 1246 : st->bits_common = sub( st->next_bit_pos, start_bit_pos ); // Q0
1056 1246 : move16();
1057 :
1058 :
1059 : /*--------------------------------------------------------------------------------*
1060 : * ACELP
1061 : *--------------------------------------------------------------------------------*/
1062 1246 : test();
1063 1246 : test();
1064 1246 : IF( ( st->core == ACELP_CORE ) && ( st->use_partial_copy == 0 ) )
1065 : {
1066 : /* Target Bits */
1067 612 : acelp_target_bits = sub( st->bits_frame_core, st->bits_common );
1068 :
1069 : {
1070 : Word16 acelp_bits;
1071 612 : move16();
1072 612 : acelp_bits = BITS_ALLOC_config_acelp( acelp_target_bits, *coder_type, &( st->acelp_cfg ), st->narrowBand, st->nb_subfr );
1073 :
1074 612 : if ( acelp_bits < 0 )
1075 : {
1076 0 : st->BER_detect = 1;
1077 0 : move16();
1078 : }
1079 : }
1080 :
1081 : /* Adaptive BPF (2 bits)*/
1082 612 : n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; // Q0
1083 612 : move16();
1084 :
1085 612 : st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); // Q0
1086 612 : IF( n != 0 )
1087 : {
1088 585 : st->bpf_gain_param = get_next_indice_fx( st, n ); // Q0
1089 585 : move16();
1090 : }
1091 :
1092 : /* Mean energy (2 or 3 bits) */
1093 612 : n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; // Q0
1094 612 : move16();
1095 612 : IF( n != 0 )
1096 : {
1097 612 : prm[j] = get_next_indice_fx( st, n ); // Q0
1098 612 : j = add( j, 1 ); // Q0
1099 612 : move16();
1100 : }
1101 :
1102 : /* Subframe parameters */
1103 3672 : FOR( sfr = 0; sfr < nb_subfr; sfr++ )
1104 : {
1105 : /* Pitch lag (4, 5, 6, 8 or 9 bits) */
1106 3060 : n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; // Q0
1107 3060 : move16();
1108 :
1109 3060 : IF( n != 0 )
1110 : {
1111 3060 : prm[j] = get_next_indice_fx( st, n ); // Q0
1112 3060 : j = add( j, 1 ); // Q0
1113 3060 : move16();
1114 : }
1115 :
1116 : /* Adaptive codebook filtering (1 bit) */
1117 3060 : IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) )
1118 : {
1119 1350 : prm[j] = get_next_indice_fx( st, 1 ); // Q0
1120 1350 : j = add( j, 1 ); // Q0
1121 1350 : move16();
1122 : }
1123 :
1124 : /* Innovative codebook */
1125 : {
1126 : /* Decode pulse positions. */
1127 3060 : j_old = j; // Q0
1128 3060 : move16();
1129 3060 : wordcnt = shr( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 4 ); // Q0
1130 3060 : 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 3060 : test();
1134 3060 : 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 12378 : FOR( ix = 0; ix < wordcnt; ix++ )
1143 : {
1144 9318 : prm[j] = (Word16) get_next_indice_fx( st, 16 ); // Q0
1145 9318 : j = add( j, 1 ); // Q0
1146 9318 : move16();
1147 : }
1148 3060 : IF( bitcnt )
1149 : {
1150 3060 : prm[j] = get_next_indice_fx( st, bitcnt ); // Q0
1151 3060 : move16();
1152 : }
1153 :
1154 3060 : j = add( j_old, 8 ); // Q0
1155 : }
1156 :
1157 : /* Gains (5b, 6b or 7b / subfr) */
1158 3060 : n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; // Q0
1159 3060 : move16();
1160 :
1161 3060 : prm[j] = get_next_indice_fx( st, n ); // Q0
1162 3060 : j = add( j, 1 ); // Q0
1163 3060 : move16();
1164 : } /*end of subfr loop*/
1165 : }
1166 :
1167 634 : 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 1246 : test();
1261 1246 : IF( EQ_16( st->core, TCX_20_CORE ) && st->use_partial_copy == 0 )
1262 : {
1263 634 : flag_ctx_hm = 0;
1264 634 : move16();
1265 :
1266 634 : 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 634 : prm[j] = get_next_indice_fx( st, 7 ); // Q0
1274 634 : j = add( j, 1 ); // Q0
1275 634 : move16();
1276 :
1277 : /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */
1278 634 : prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0
1279 634 : j = add( j, 1 ); // Q0
1280 634 : move16();
1281 :
1282 : /* LTP data */
1283 : /* PLC pitch info for HB */
1284 634 : test();
1285 634 : IF( hTcxLtpDec->tcxltp != 0 || GT_32( st->sr_core, 25600 ) )
1286 : {
1287 :
1288 634 : prm[j] = get_next_indice_fx( st, 1 ); // Q0
1289 634 : move16();
1290 :
1291 634 : IF( prm[j] )
1292 : {
1293 452 : prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0
1294 452 : move16();
1295 452 : prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0
1296 452 : move16();
1297 : }
1298 :
1299 634 : st->BER_detect = s_or( st->BER_detect,
1300 634 : tcx_ltp_decode_params( &prm[j],
1301 : &( hTcxLtpDec->tcxltp_pitch_int ),
1302 : &( hTcxLtpDec->tcxltp_pitch_fr ),
1303 : &( hTcxLtpDec->tcxltp_gain ),
1304 634 : st->pit_min,
1305 634 : st->pit_fr1,
1306 634 : st->pit_fr2,
1307 634 : st->pit_max,
1308 634 : st->pit_res_max ) );
1309 :
1310 634 : hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15
1311 634 : move16();
1312 634 : hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15
1313 634 : move16();
1314 :
1315 634 : test();
1316 634 : IF( ( st->tcxonly == 0 ) && ( LT_16( hTcxLtpDec->tcxltp_pitch_int, L_frame ) ) )
1317 : {
1318 634 : Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 );
1319 634 : Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr );
1320 634 : hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15
1321 634 : move16();
1322 : }
1323 : }
1324 :
1325 634 : j = add( j, 3 ); // Q0
1326 :
1327 : /* TCX spectral data */
1328 634 : lg = L_frame;
1329 634 : move16();
1330 634 : lgFB = st->hTcxCfg->tcx_coded_lines;
1331 634 : move16();
1332 :
1333 634 : IF( st->last_core_from_bs == ACELP_CORE )
1334 : {
1335 : /* ACE->TCX transition */
1336 38 : lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0
1337 38 : if ( st->hTcxCfg->lfacNext < 0 )
1338 : {
1339 38 : lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0
1340 : }
1341 :
1342 38 : lgFB = add( lgFB, shr( lgFB, 2 ) ); // Q0
1343 : }
1344 :
1345 : /* TNS data */
1346 634 : nTnsParams = 0;
1347 634 : move16();
1348 634 : nTnsBits = 0;
1349 634 : move16();
1350 :
1351 634 : IF( st->hTcxCfg->fIsTNSAllowed )
1352 : {
1353 372 : SetTnsConfig( st->hTcxCfg, 1, (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) );
1354 372 : ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams );
1355 :
1356 372 : j = add( j, nTnsParams ); // Q0
1357 : }
1358 634 : hm_size = shl( mult( st->TcxBandwidth, lg ), 1 );
1359 :
1360 634 : test();
1361 634 : 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 634 : nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) );
1367 634 : IF( st->enableGplc != 0 )
1368 : {
1369 372 : nbits_tcx = sub( nbits_tcx, 7 ); // Q0
1370 : }
1371 :
1372 : /*Context HM flag*/
1373 634 : test();
1374 634 : IF( st->hTcxCfg->ctx_hm && ( st->last_core_from_bs != ACELP_CORE ) )
1375 : {
1376 596 : prm[j] = get_next_indice_fx( st, 1 ); // Q0
1377 596 : move16();
1378 596 : nbits_tcx = sub( nbits_tcx, 1 ); // Q0
1379 :
1380 596 : IF( prm[j] )
1381 : {
1382 : Word16 NumIndexBits;
1383 :
1384 54 : tmp = 0;
1385 54 : move16();
1386 54 : IF( GE_16( hm_size, 256 ) )
1387 : {
1388 54 : tmp = 1;
1389 54 : move16();
1390 : }
1391 54 : NumIndexBits = DecodeIndex_fx( st,
1392 : tmp,
1393 54 : prm + j + 1 );
1394 :
1395 54 : flag_ctx_hm = 1;
1396 54 : move16();
1397 :
1398 54 : ConfigureContextHm(
1399 : lgFB,
1400 : nbits_tcx,
1401 54 : *( prm + j + 1 ),
1402 54 : hTcxDec->tcx_hm_LtpPitchLag,
1403 : &hm_cfg );
1404 :
1405 54 : nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0
1406 : }
1407 : }
1408 634 : j = add( j, NPRM_CTX_HM ); // Q0
1409 :
1410 : /* read IGF payload */
1411 634 : IF( st->igf )
1412 : {
1413 :
1414 634 : n = st->next_bit_pos;
1415 634 : move16();
1416 634 : IF( st->last_core_from_bs == ACELP_CORE )
1417 : {
1418 38 : IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 );
1419 38 : IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 );
1420 : }
1421 : ELSE
1422 : {
1423 596 : IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 );
1424 596 : IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 );
1425 : }
1426 :
1427 634 : nbits_tcx = sub( nbits_tcx, sub( st->next_bit_pos, n ) ); // Q0
1428 : }
1429 634 : nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); // Q0
1430 634 : 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 634 : phm_cfg = NULL;
1447 634 : move16();
1448 634 : if ( flag_ctx_hm )
1449 : {
1450 54 : phm_cfg = &hm_cfg;
1451 54 : move16();
1452 : }
1453 634 : 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 634 : move16();
1455 634 : j = add( j, lg ); // Q0
1456 : }
1457 : }
1458 :
1459 1246 : test();
1460 1246 : test();
1461 1246 : 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 1246 : 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 1246 : IF( !st->use_partial_copy )
1726 : {
1727 1246 : 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 1246 : bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); // Q0
1735 1246 : move16();
1736 : }
1737 :
1738 1246 : return;
1739 : }
1740 :
1741 :
1742 : /*-------------------------------------------------------------------*
1743 : * getTCXMode_ivas()
1744 : *
1745 : * get TCX mode
1746 : *--------------------------------------------------------------------*/
1747 831416 : 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 831416 : IF( st->tcxonly )
1756 : {
1757 : /* get core */
1758 715342 : ind = get_next_indice_fx( st0, 1 ); /* Store decoder memory of last_core */
1759 715342 : st->core = add( ind, TCX_20_CORE );
1760 715342 : move16();
1761 : /* get class */
1762 715342 : ind = get_next_indice_fx( st0, 2 );
1763 :
1764 715342 : st->clas_dec = ONSET;
1765 715342 : move16();
1766 715342 : IF( ind == 0 )
1767 : {
1768 373376 : st->clas_dec = UNVOICED_CLAS;
1769 373376 : move16();
1770 : }
1771 341966 : ELSE IF( EQ_16( ind, 1 ) )
1772 : {
1773 43017 : IF( GE_16( st->last_good, VOICED_TRANSITION ) )
1774 : {
1775 34429 : st->clas_dec = VOICED_TRANSITION;
1776 34429 : move16();
1777 : }
1778 : ELSE
1779 : {
1780 8588 : st->clas_dec = UNVOICED_TRANSITION;
1781 8588 : move16();
1782 : }
1783 : }
1784 298949 : ELSE IF( EQ_16( ind, 2 ) )
1785 : {
1786 260329 : st->clas_dec = VOICED_CLAS;
1787 260329 : move16();
1788 : }
1789 :
1790 715342 : st->coder_type = INACTIVE;
1791 715342 : move16();
1792 715342 : test();
1793 715342 : IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag )
1794 : {
1795 161298 : st->VAD = get_next_indice_fx( st0, 1 );
1796 161298 : move16();
1797 : }
1798 : ELSE
1799 : {
1800 554044 : st->VAD = 0;
1801 554044 : move16();
1802 : }
1803 : }
1804 : ELSE
1805 : {
1806 116074 : IF( EQ_16( st->mdct_sw, MODE1 ) )
1807 : {
1808 : /* 2 bits instead of 3 as TCX is already signaled */
1809 116074 : st->core = TCX_20_CORE;
1810 116074 : move16();
1811 116074 : st->hTcxCfg->coder_type = get_next_indice_fx( st0, 2 );
1812 116074 : move16();
1813 116074 : st->coder_type = st->hTcxCfg->coder_type;
1814 116074 : 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 116074 : 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 116074 : IF( EQ_16( st->coder_type, INACTIVE ) )
1901 : {
1902 13223 : st->VAD = 0;
1903 13223 : move16();
1904 : }
1905 : ELSE
1906 : {
1907 102851 : st->VAD = 1;
1908 102851 : move16();
1909 : }
1910 : }
1911 :
1912 : /*Core extended mode mapping for correct PLC classification*/
1913 831416 : st->core_ext_mode = st->coder_type;
1914 831416 : move16();
1915 831416 : if ( EQ_16( st->coder_type, INACTIVE ) )
1916 : {
1917 728565 : st->core_ext_mode = UNVOICED;
1918 728565 : move16();
1919 : }
1920 :
1921 831416 : return;
1922 : }
1923 :
1924 : /*-------------------------------------------------------------------*
1925 : * getTCXWindowing_ivas()
1926 : *
1927 : * get TCX transform type for each subframe
1928 : *--------------------------------------------------------------------*/
1929 831416 : 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 831416 : test();
1941 831416 : test();
1942 831416 : test();
1943 831416 : IF( EQ_16( last_core, ACELP_CORE ) || EQ_16( last_core, AMR_WB_CORE ) )
1944 : {
1945 8363 : hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP;
1946 8363 : move16();
1947 : }
1948 823053 : ELSE IF( EQ_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) )
1949 : {
1950 12454 : hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP;
1951 12454 : move16();
1952 : }
1953 810599 : ELSE IF( NE_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) )
1954 : {
1955 19472 : hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
1956 19472 : move16();
1957 : }
1958 : ELSE
1959 : {
1960 791127 : hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
1961 791127 : move16();
1962 : }
1963 :
1964 : /* Set the current overlap mode based on the current frame type and coded overlap mode */
1965 831416 : hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
1966 831416 : move16();
1967 :
1968 831416 : IF( NE_16( core, ACELP_CORE ) )
1969 : {
1970 831416 : overlap_code = 0;
1971 831416 : move16();
1972 831416 : IF( get_next_indice_fx( st0, 1 ) )
1973 : {
1974 14869 : overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
1975 : }
1976 :
1977 : assert( MIN_OVERLAP == 2 && HALF_OVERLAP == 3 );
1978 831416 : hTcxCfg->tcx_curr_overlap_mode = overlap_code;
1979 831416 : move16();
1980 : /*TCX10 : always symmetric windows*/
1981 831416 : test();
1982 831416 : test();
1983 831416 : test();
1984 831416 : 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 797677 : hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
1987 797677 : move16();
1988 : }
1989 : }
1990 :
1991 831416 : test();
1992 831416 : IF( NE_16( element_mode, EVS_MONO ) && EQ_16( core, TCX_10_CORE ) )
1993 : {
1994 : /* also read last overlap */
1995 16150 : overlap_code = 0;
1996 16150 : move16();
1997 :
1998 16150 : IF( get_next_indice_fx( st0, 1 ) )
1999 : {
2000 3624 : overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
2001 : }
2002 :
2003 16150 : hTcxCfg->tcx_last_overlap_mode = overlap_code;
2004 16150 : move16();
2005 : }
2006 :
2007 831416 : return;
2008 : }
|