LCOV - code coverage report
Current view: top level - lib_dec - dec_prm_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 665 1045 63.6 %
Date: 2025-05-03 01:55:50 Functions: 6 6 100.0 %

          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, &param_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, &param_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             : #ifdef IVAS_CODE_AVQ_LPC
    1008             :                                    ,
    1009             :                                    , ,
    1010             : #endif
    1011             :                 );
    1012           0 :                 move16();
    1013             :             }
    1014        1248 :             ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
    1015             :             {
    1016        1248 :                 test();
    1017        1248 :                 test();
    1018        1248 :                 IF( EQ_32( st->sr_core, 16000 ) && EQ_16( *coder_type, VOICED ) && ( st->core == ACELP_CORE ) )
    1019             :                 {
    1020         268 :                     lsf_bctcvq_decprm( st, param_lpc );
    1021             :                 }
    1022             :                 ELSE
    1023             :                 {
    1024         980 :                     lsf_msvq_ma_decprm( st, param_lpc );
    1025             :                 }
    1026             :             }
    1027             :             ELSE
    1028             :             {
    1029           0 :                 assert( 0 && "LPC quant not supported!" );
    1030             :             }
    1031             :         }
    1032             :     }
    1033             :     ELSE
    1034             :     {
    1035           0 :         st->numlpc = 1;
    1036           0 :         move16();
    1037             : 
    1038           0 :         test();
    1039           0 :         IF( EQ_16( st->rf_frame_type, RF_TCXFD ) )
    1040             :         {
    1041           0 :             param_lpc[0] = 0; // Q0
    1042           0 :             move16();
    1043           0 :             param_lpc[1] = get_next_indice_fx( st, lsf_numbits[0] ); /* VQ 1 */ // Q0
    1044           0 :             move16();
    1045           0 :             param_lpc[2] = get_next_indice_fx( st, lsf_numbits[1] ); /* VQ 2 */ // Q0
    1046           0 :             move16();
    1047           0 :             param_lpc[3] = get_next_indice_fx( st, lsf_numbits[2] ); /* VQ 3 */ // Q0
    1048           0 :             move16();
    1049             :         }
    1050           0 :         ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) )
    1051             :         {
    1052             :             /* LSF indices */
    1053           0 :             param_lpc[0] = get_next_indice_fx( st, 8 ); /* VQ 1 */ // Q0
    1054           0 :             move16();
    1055           0 :             param_lpc[1] = get_next_indice_fx( st, 8 ); /* VQ 2 */ // Q0
    1056           0 :             move16();
    1057             :         }
    1058             :     }
    1059             : 
    1060        1248 :     st->bits_common = sub( st->next_bit_pos, start_bit_pos ); // Q0
    1061        1248 :     move16();
    1062             : 
    1063             : 
    1064             :     /*--------------------------------------------------------------------------------*
    1065             :      * ACELP
    1066             :      *--------------------------------------------------------------------------------*/
    1067        1248 :     test();
    1068        1248 :     test();
    1069        1248 :     IF( ( st->core == ACELP_CORE ) && ( st->use_partial_copy == 0 ) )
    1070             :     {
    1071             :         /* Target Bits */
    1072         610 :         acelp_target_bits = sub( st->bits_frame_core, st->bits_common );
    1073             : 
    1074             :         {
    1075             :             Word16 acelp_bits;
    1076         610 :             move16();
    1077         610 :             acelp_bits = BITS_ALLOC_config_acelp( acelp_target_bits, *coder_type, &( st->acelp_cfg ), st->narrowBand, st->nb_subfr );
    1078             : 
    1079         610 :             if ( acelp_bits < 0 )
    1080             :             {
    1081           0 :                 st->BER_detect = 1;
    1082           0 :                 move16();
    1083             :             }
    1084             :         }
    1085             : 
    1086             :         /* Adaptive BPF (2 bits)*/
    1087         610 :         n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; // Q0
    1088         610 :         move16();
    1089             : 
    1090         610 :         st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); // Q0
    1091         610 :         IF( n != 0 )
    1092             :         {
    1093         584 :             st->bpf_gain_param = get_next_indice_fx( st, n ); // Q0
    1094         584 :             move16();
    1095             :         }
    1096             : 
    1097             :         /* Mean energy (2 or 3 bits) */
    1098         610 :         n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; // Q0
    1099         610 :         move16();
    1100         610 :         IF( n != 0 )
    1101             :         {
    1102         610 :             prm[j] = get_next_indice_fx( st, n ); // Q0
    1103         610 :             j = add( j, 1 );                      // Q0
    1104         610 :             move16();
    1105             :         }
    1106             : 
    1107             :         /* Subframe parameters */
    1108        3660 :         FOR( sfr = 0; sfr < nb_subfr; sfr++ )
    1109             :         {
    1110             :             /* Pitch lag (4, 5, 6, 8 or 9 bits) */
    1111        3050 :             n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; // Q0
    1112        3050 :             move16();
    1113             : 
    1114        3050 :             IF( n != 0 )
    1115             :             {
    1116        3050 :                 prm[j] = get_next_indice_fx( st, n ); // Q0
    1117        3050 :                 j = add( j, 1 );                      // Q0
    1118        3050 :                 move16();
    1119             :             }
    1120             : 
    1121             :             /* Adaptive codebook filtering (1 bit) */
    1122        3050 :             IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) )
    1123             :             {
    1124        1340 :                 prm[j] = get_next_indice_fx( st, 1 ); // Q0
    1125        1340 :                 j = add( j, 1 );                      // Q0
    1126        1340 :                 move16();
    1127             :             }
    1128             : 
    1129             :             /* Innovative codebook */
    1130             :             {
    1131             :                 /* Decode pulse positions. */
    1132        3050 :                 j_old = j; // Q0
    1133        3050 :                 move16();
    1134        3050 :                 wordcnt = shr( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 4 );    // Q0
    1135        3050 :                 bitcnt = s_and( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 0xF ); // Q0
    1136             : 
    1137             :                 /* sanity check for testing - not instrumented */
    1138        3050 :                 test();
    1139        3050 :                 IF( GE_16( st->acelp_cfg.fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB ) || ( st->acelp_cfg.fixed_cdk_index[sfr] < 0 ) )
    1140             :                 {
    1141           0 :                     st->acelp_cfg.fixed_cdk_index[sfr] = 0; // Q0
    1142           0 :                     move16();
    1143           0 :                     st->BER_detect = 1; // Q0
    1144           0 :                     move16();
    1145             :                 }
    1146             : 
    1147       12334 :                 FOR( ix = 0; ix < wordcnt; ix++ )
    1148             :                 {
    1149        9284 :                     prm[j] = (Word16) get_next_indice_fx( st, 16 ); // Q0
    1150        9284 :                     j = add( j, 1 );                                // Q0
    1151        9284 :                     move16();
    1152             :                 }
    1153        3050 :                 IF( bitcnt )
    1154             :                 {
    1155        3050 :                     prm[j] = get_next_indice_fx( st, bitcnt ); // Q0
    1156        3050 :                     move16();
    1157             :                 }
    1158             : 
    1159        3050 :                 j = add( j_old, 8 ); // Q0
    1160             :             }
    1161             : 
    1162             :             /* Gains (5b, 6b or 7b / subfr) */
    1163        3050 :             n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; // Q0
    1164        3050 :             move16();
    1165             : 
    1166        3050 :             prm[j] = get_next_indice_fx( st, n ); // Q0
    1167        3050 :             j = add( j, 1 );                      // Q0
    1168        3050 :             move16();
    1169             :         } /*end of subfr loop*/
    1170             :     }
    1171             : 
    1172         638 :     ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && st->use_partial_copy )
    1173             :     {
    1174             :         Word16 acelp_bits =
    1175           0 :             BITS_ALLOC_config_acelp( st->rf_target_bits, /* target bits ranges from 56 to 72 depending on rf_type */
    1176           0 :                                      st->rf_frame_type,  /* already offset by 4 to parse the config elements for partial copy */
    1177             :                                      &( st->acelp_cfg ), /* acelp_cfg_rf*/
    1178             :                                      0,                  /* is narrowBand */
    1179           0 :                                      st->nb_subfr );
    1180             : 
    1181           0 :         if ( acelp_bits < 0 )
    1182             :         {
    1183           0 :             st->BER_detect = 1;
    1184           0 :             move16();
    1185             :         }
    1186             : 
    1187             :         /* rf_frame_type NELP: 7 */
    1188           0 :         IF( EQ_16( st->rf_frame_type, RF_NELP ) )
    1189             :         {
    1190             :             /* NELP gain indices */
    1191           0 :             st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); // Q0
    1192           0 :             move16();
    1193           0 :             st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); // Q0
    1194           0 :             move16();
    1195           0 :             st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); // Q0
    1196           0 :             move16();
    1197             : 
    1198             :             /* NELP filter selection index */
    1199           0 :             st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); // Q0
    1200           0 :             move16();
    1201             : 
    1202             :             /* tbe gainFr */
    1203           0 :             st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); // Q0
    1204           0 :             move16();
    1205             :         }
    1206             :         ELSE
    1207             :         {
    1208             :             /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/
    1209             :             /* ES pred */
    1210           0 :             prm[j] = get_next_indice_fx( st, 3 ); // Q0
    1211           0 :             move16();
    1212           0 :             j = add( j, 1 ); // Q0
    1213             : 
    1214           0 :             ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; // Q0
    1215           0 :             move16();
    1216           0 :             gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; // Q0
    1217           0 :             move16();
    1218             : 
    1219             :             /* Subframe parameters */
    1220           0 :             FOR( sfr = 0; sfr < nb_subfr; sfr++ )
    1221             :             {
    1222             :                 /* Pitch lag (5, or 8 bits) */
    1223           0 :                 n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; // Q0
    1224           0 :                 move16();
    1225           0 :                 IF( n != 0 )
    1226             :                 {
    1227           0 :                     prm[j] = get_next_indice_fx( st, n ); // Q0
    1228           0 :                     j = add( j, 1 );                      // Q0
    1229           0 :                     move16();
    1230             :                 }
    1231             : 
    1232             :                 /*Innovative codebook*/
    1233           0 :                 test();
    1234           0 :                 test();
    1235           0 :                 test();
    1236           0 :                 IF( EQ_16( st->rf_frame_type, RF_NOPRED ) || ( EQ_16( st->rf_frame_type, RF_GENPRED ) && ( sfr == 0 || EQ_16( sfr, 2 ) ) ) )
    1237             :                 {
    1238             :                     /* NOTE: FCB actual bits need to be backed up as well */
    1239             :                     /*n = ACELP_FIXED_CDK_BITS(st->rf_indx_fcb[fec_offset][sfr]) & 15;*/
    1240           0 :                     prm[j] = get_next_indice_fx( st, 7 ); // Q0
    1241           0 :                     move16();
    1242           0 :                     j = add( j, 8 ); // Q0
    1243             :                 }
    1244             : 
    1245             :                 /* Gains (5b, 6b or 7b / subfr) */
    1246           0 :                 test();
    1247           0 :                 IF( sfr == 0 || EQ_16( sfr, 2 ) )
    1248             :                 {
    1249           0 :                     n = ACELP_GAINS_BITS[gains_mode]; // Q0
    1250           0 :                     move16();
    1251           0 :                     prm[j] = get_next_indice_fx( st, n ); // Q0
    1252           0 :                     j = add( j, 1 );                      // Q0
    1253           0 :                     move16();
    1254             :                 }
    1255             :             }
    1256             : 
    1257           0 :             st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); // Q0
    1258           0 :             move16();
    1259             :         }
    1260             :     }
    1261             : 
    1262             :     /*--------------------------------------------------------------------------------*
    1263             :      * TCX20
    1264             :      *--------------------------------------------------------------------------------*/
    1265        1248 :     test();
    1266        1248 :     IF( EQ_16( st->core, TCX_20_CORE ) && st->use_partial_copy == 0 )
    1267             :     {
    1268         638 :         flag_ctx_hm = 0;
    1269         638 :         move16();
    1270             : 
    1271         638 :         if ( st->enablePlcWaveadjust )
    1272             :         {
    1273           0 :             st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0
    1274           0 :             move16();
    1275             :         }
    1276             : 
    1277             :         /* TCX Gain = 7 bits */
    1278         638 :         prm[j] = get_next_indice_fx( st, 7 ); // Q0
    1279         638 :         j = add( j, 1 );                      // Q0
    1280         638 :         move16();
    1281             : 
    1282             :         /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */
    1283         638 :         prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0
    1284         638 :         j = add( j, 1 );                                           // Q0
    1285         638 :         move16();
    1286             : 
    1287             :         /* LTP data */
    1288             :         /* PLC pitch info for HB */
    1289         638 :         test();
    1290         638 :         IF( hTcxLtpDec->tcxltp != 0 || GT_32( st->sr_core, 25600 ) )
    1291             :         {
    1292             : 
    1293         638 :             prm[j] = get_next_indice_fx( st, 1 ); // Q0
    1294         638 :             move16();
    1295             : 
    1296         638 :             IF( prm[j] )
    1297             :             {
    1298         462 :                 prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0
    1299         462 :                 move16();
    1300         462 :                 prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0
    1301         462 :                 move16();
    1302             :             }
    1303             : 
    1304         638 :             st->BER_detect = s_or( st->BER_detect,
    1305         638 :                                    tcx_ltp_decode_params( &prm[j],
    1306             :                                                           &( hTcxLtpDec->tcxltp_pitch_int ),
    1307             :                                                           &( hTcxLtpDec->tcxltp_pitch_fr ),
    1308             :                                                           &( hTcxLtpDec->tcxltp_gain ),
    1309         638 :                                                           st->pit_min,
    1310         638 :                                                           st->pit_fr1,
    1311         638 :                                                           st->pit_fr2,
    1312         638 :                                                           st->pit_max,
    1313         638 :                                                           st->pit_res_max ) );
    1314             : 
    1315         638 :             hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15
    1316         638 :             move16();
    1317         638 :             hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15
    1318         638 :             move16();
    1319             : 
    1320         638 :             test();
    1321         638 :             IF( ( st->tcxonly == 0 ) && ( LT_16( hTcxLtpDec->tcxltp_pitch_int, L_frame ) ) )
    1322             :             {
    1323         638 :                 Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 );
    1324         638 :                 Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr );
    1325         638 :                 hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15
    1326         638 :                 move16();
    1327             :             }
    1328             :         }
    1329             : 
    1330         638 :         j = add( j, 3 ); // Q0
    1331             : 
    1332             :         /* TCX spectral data */
    1333         638 :         lg = L_frame;
    1334         638 :         move16();
    1335         638 :         lgFB = st->hTcxCfg->tcx_coded_lines;
    1336         638 :         move16();
    1337             : 
    1338         638 :         IF( st->last_core_from_bs == ACELP_CORE )
    1339             :         {
    1340             :             /* ACE->TCX transition */
    1341          36 :             lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0
    1342          36 :             if ( st->hTcxCfg->lfacNext < 0 )
    1343             :             {
    1344          36 :                 lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0
    1345             :             }
    1346             : 
    1347          36 :             lgFB = add( lgFB, shr( lgFB, 2 ) ); // Q0
    1348             :         }
    1349             : 
    1350             :         /* TNS data */
    1351         638 :         nTnsParams = 0;
    1352         638 :         move16();
    1353         638 :         nTnsBits = 0;
    1354         638 :         move16();
    1355             : 
    1356         638 :         IF( st->hTcxCfg->fIsTNSAllowed )
    1357             :         {
    1358         374 :             SetTnsConfig( st->hTcxCfg, 1, (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) );
    1359         374 :             ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams );
    1360             : 
    1361         374 :             j = add( j, nTnsParams ); // Q0
    1362             :         }
    1363         638 :         hm_size = shl( mult( st->TcxBandwidth, lg ), 1 );
    1364             : 
    1365         638 :         test();
    1366         638 :         IF( ( hTcxDec->tcx_lpc_shaped_ari != 0 ) && NE_16( st->last_core_from_bs, ACELP_CORE ) )
    1367             :         {
    1368           0 :             dec_prm_hm_fx( st, &prm[j], hm_size );
    1369             :         }
    1370             : 
    1371         638 :         nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) );
    1372         638 :         IF( st->enableGplc != 0 )
    1373             :         {
    1374         374 :             nbits_tcx = sub( nbits_tcx, 7 ); // Q0
    1375             :         }
    1376             : 
    1377             :         /*Context HM flag*/
    1378         638 :         test();
    1379         638 :         IF( st->hTcxCfg->ctx_hm && ( st->last_core_from_bs != ACELP_CORE ) )
    1380             :         {
    1381         602 :             prm[j] = get_next_indice_fx( st, 1 ); // Q0
    1382         602 :             move16();
    1383         602 :             nbits_tcx = sub( nbits_tcx, 1 ); // Q0
    1384             : 
    1385         602 :             IF( prm[j] )
    1386             :             {
    1387             :                 Word16 NumIndexBits;
    1388             : 
    1389          55 :                 tmp = 0;
    1390          55 :                 move16();
    1391          55 :                 IF( GE_16( hm_size, 256 ) )
    1392             :                 {
    1393          55 :                     tmp = 1;
    1394          55 :                     move16();
    1395             :                 }
    1396          55 :                 NumIndexBits = DecodeIndex_fx( st,
    1397             :                                                tmp,
    1398          55 :                                                prm + j + 1 );
    1399             : 
    1400          55 :                 flag_ctx_hm = 1;
    1401          55 :                 move16();
    1402             : 
    1403          55 :                 ConfigureContextHm(
    1404             :                     lgFB,
    1405             :                     nbits_tcx,
    1406          55 :                     *( prm + j + 1 ),
    1407          55 :                     hTcxDec->tcx_hm_LtpPitchLag,
    1408             :                     &hm_cfg );
    1409             : 
    1410          55 :                 nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0
    1411             :             }
    1412             :         }
    1413         638 :         j = add( j, NPRM_CTX_HM ); // Q0
    1414             : 
    1415             :         /* read IGF payload */
    1416         638 :         IF( st->igf )
    1417             :         {
    1418             : 
    1419         638 :             n = st->next_bit_pos;
    1420         638 :             move16();
    1421         638 :             IF( st->last_core_from_bs == ACELP_CORE )
    1422             :             {
    1423          36 :                 IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 );
    1424          36 :                 IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 );
    1425             :             }
    1426             :             ELSE
    1427             :             {
    1428         602 :                 IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 );
    1429         602 :                 IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_NORM, 1 );
    1430             :             }
    1431             : 
    1432         638 :             nbits_tcx = sub( nbits_tcx, sub( st->next_bit_pos, n ) ); // Q0
    1433             :         }
    1434         638 :         nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); // Q0
    1435         638 :         IF( hTcxDec->tcx_lpc_shaped_ari != 0 )
    1436             :         {
    1437           0 :             prm[j] = nbits_tcx; /* store length of buffer */ // Q0
    1438           0 :             j = add( j, 1 );                                 // Q0
    1439           0 :             move16();
    1440           0 :             prms = &prm[j];
    1441           0 :             FOR( ix = 0; ix < nbits_tcx; ix++ )
    1442             :             {
    1443           0 :                 prms[ix] = get_next_indice_1_fx( st ); // Q0
    1444           0 :                 move16();
    1445             :             }
    1446           0 :             set16_fx( prms + nbits_tcx, 1, 32 );
    1447           0 :             j = add( j, nbits_tcx ); // Q0
    1448             :         }
    1449             :         ELSE
    1450             :         {
    1451         638 :             phm_cfg = NULL;
    1452         638 :             move16();
    1453         638 :             if ( flag_ctx_hm )
    1454             :             {
    1455          55 :                 phm_cfg = &hm_cfg;
    1456          55 :                 move16();
    1457             :             }
    1458         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
    1459         638 :             move16();
    1460         638 :             j = add( j, lg ); // Q0
    1461             :         }
    1462             :     }
    1463             : 
    1464        1248 :     test();
    1465        1248 :     test();
    1466        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 ) )
    1467             :     {
    1468             :         /* classification */
    1469           0 :         ind = get_next_indice_fx( st, 2 ); // Q0
    1470           0 :         st->clas_dec = ONSET;
    1471           0 :         move16();
    1472             : 
    1473           0 :         IF( ind == 0 )
    1474             :         {
    1475           0 :             st->clas_dec = UNVOICED_CLAS;
    1476           0 :             move16();
    1477             :         }
    1478           0 :         ELSE IF( EQ_16( ind, 1 ) )
    1479             :         {
    1480           0 :             IF( GE_16( st->last_good, VOICED_TRANSITION ) )
    1481             :             {
    1482           0 :                 st->clas_dec = VOICED_TRANSITION;
    1483           0 :                 move16();
    1484             :             }
    1485             :             ELSE
    1486             :             {
    1487           0 :                 st->clas_dec = UNVOICED_TRANSITION;
    1488           0 :                 move16();
    1489             :             }
    1490             :         }
    1491           0 :         ELSE IF( EQ_16( ind, 2 ) )
    1492             :         {
    1493           0 :             st->clas_dec = VOICED_CLAS;
    1494           0 :             move16();
    1495             :         }
    1496             : 
    1497           0 :         IF( EQ_16( st->rf_frame_type, RF_TCXFD ) )
    1498             :         {
    1499             :             /* TCX Gain = 7 bits */
    1500           0 :             hTcxDec->old_gaintcx_bfi = get_next_indice_fx( st, 7 ); // Q0
    1501           0 :             move16();
    1502             :         }
    1503             :         ELSE
    1504             :         {
    1505             :             /* LTP data */
    1506           0 :             IF( hTcxLtpDec->tcxltp != 0 )
    1507             :             {
    1508           0 :                 test();
    1509           0 :                 IF( EQ_16( st->rf_frame_type, RF_TCXTD2 ) || EQ_16( st->rf_frame_type, RF_TCXTD1 ) )
    1510             :                 {
    1511           0 :                     prm_ltp[0] = 1;                           // Q0
    1512           0 :                     move16();                                 /* LTP active*/
    1513           0 :                     prm_ltp[1] = get_next_indice_fx( st, 9 ); // Q0
    1514           0 :                     prm_ltp[2] = 3;                           // Q0
    1515           0 :                     move16();                                 /* max ampl. quantizer output (2bits), anyway not used later*/
    1516             : 
    1517           0 :                     IF( st->prev_bfi == 0 )
    1518             :                     {
    1519           0 :                         st->BER_detect = s_or( st->BER_detect,
    1520           0 :                                                tcx_ltp_decode_params( &prm_ltp[0], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ),
    1521           0 :                                                                       st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ) );
    1522           0 :                         move16();
    1523           0 :                         hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15
    1524           0 :                         move16();
    1525             :                     }
    1526             :                 }
    1527             :             }
    1528             :         }
    1529             :     }
    1530             : 
    1531             : 
    1532             :     /*--------------------------------------------------------------------------------*
    1533             :      * TCX10
    1534             :      *--------------------------------------------------------------------------------*/
    1535        1248 :     IF( EQ_16( st->core, TCX_10_CORE ) )
    1536             :     {
    1537           0 :         Word16 tcxltp_prm_0 = 0;
    1538           0 :         Word16 tcxltp_prm_1 = 0;
    1539           0 :         Word16 tcxltp_prm_2 = 0;
    1540           0 :         Word16 nbits_igf = 0;
    1541           0 :         move16();
    1542           0 :         move16();
    1543           0 :         move16();
    1544           0 :         move16();
    1545           0 :         move16();
    1546             :         /* read IGF payload */
    1547           0 :         IF( st->igf )
    1548             :         {
    1549             : 
    1550           0 :             n = st->next_bit_pos;
    1551           0 :             move16();
    1552             : 
    1553           0 :             IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1 );
    1554           0 :             IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 1 );
    1555           0 :             IGFDecStoreTCX10SubFrameData( st->hIGFDec, 0 );
    1556             : 
    1557           0 :             IGFDecReadLevel( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0 );
    1558           0 :             IGFDecReadData( st->hIGFDec, st, IGF_GRID_LB_SHORT, 0 );
    1559           0 :             IGFDecStoreTCX10SubFrameData( st->hIGFDec, 1 );
    1560           0 :             nbits_igf = sub( st->next_bit_pos, n );
    1561             :         }
    1562           0 :         FOR( k = 0; k < 2; k++ )
    1563             :         {
    1564           0 :             flag_ctx_hm = 0;
    1565           0 :             move16();
    1566             : 
    1567           0 :             prm = param + ( k * DEC_NPRM_DIV );
    1568           0 :             j = 0;
    1569           0 :             move16();
    1570             : 
    1571           0 :             nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); // Q0
    1572             : 
    1573           0 :             test();
    1574           0 :             IF( st->enablePlcWaveadjust && k )
    1575             :             {
    1576           0 :                 st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0
    1577           0 :                 move16();
    1578             :             }
    1579             :             /* TCX Gain = 7 bits */
    1580           0 :             prm[j] = get_next_indice_fx( st, 7 ); // Q0
    1581           0 :             j = add( j, 1 );                      // Q0
    1582           0 :             move16();
    1583             : 
    1584             :             /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */
    1585           0 :             prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0
    1586           0 :             j = add( j, 1 );                                           // Q0
    1587           0 :             move16();
    1588             : 
    1589             :             /* LTP data */
    1590           0 :             test();
    1591           0 :             test();
    1592           0 :             IF( ( k == 0 ) && ( ( hTcxLtpDec->tcxltp != 0 ) || ( GT_32( st->sr_core, 25600 ) ) ) )
    1593             :             {
    1594           0 :                 prm[j] = get_next_indice_fx( st, 1 ); // Q0
    1595           0 :                 move16();
    1596             : 
    1597           0 :                 IF( prm[j] )
    1598             :                 {
    1599             : 
    1600           0 :                     prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0
    1601           0 :                     move16();
    1602           0 :                     prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0
    1603           0 :                     move16();
    1604             : 
    1605           0 :                     tcxltp_prm_0 = prm[j]; // Q0
    1606           0 :                     move16();
    1607           0 :                     tcxltp_prm_1 = prm[j + 1]; // Q0
    1608           0 :                     move16();
    1609           0 :                     tcxltp_prm_2 = prm[j + 2]; // Q0
    1610           0 :                     move16();
    1611             :                 }
    1612             : 
    1613           0 :                 st->BER_detect = s_or( st->BER_detect,
    1614           0 :                                        tcx_ltp_decode_params( &prm[j],
    1615             :                                                               &( hTcxLtpDec->tcxltp_pitch_int ),
    1616             :                                                               &( hTcxLtpDec->tcxltp_pitch_fr ),
    1617             :                                                               &( hTcxLtpDec->tcxltp_gain ),
    1618           0 :                                                               st->pit_min,
    1619           0 :                                                               st->pit_fr1,
    1620           0 :                                                               st->pit_fr2,
    1621           0 :                                                               st->pit_max,
    1622           0 :                                                               st->pit_res_max ) );
    1623           0 :                 move16();
    1624             : 
    1625           0 :                 hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15
    1626           0 :                 move16();
    1627           0 :                 hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15
    1628           0 :                 move16();
    1629             : 
    1630           0 :                 j = add( j, 3 ); // Q0
    1631             :             }
    1632             :             ELSE
    1633             :             {
    1634           0 :                 prm[j] = tcxltp_prm_0; // Q0
    1635           0 :                 j = add( j, 1 );       // Q0
    1636           0 :                 move16();
    1637           0 :                 prm[j] = tcxltp_prm_1; // Q0
    1638           0 :                 j = add( j, 1 );       // Q0
    1639           0 :                 move16();
    1640           0 :                 prm[j] = tcxltp_prm_2; // Q0
    1641           0 :                 j = add( j, 1 );       // Q0
    1642           0 :                 move16();
    1643             :             }
    1644             : 
    1645             :             /* TCX spectral data */
    1646           0 :             lg = shr( L_frame, 1 );                        // Q0
    1647           0 :             lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); // Q0
    1648             : 
    1649           0 :             test();
    1650           0 :             IF( k == 0 && ( st->last_core_from_bs == ACELP_CORE ) )
    1651             :             {
    1652             :                 /* ACE->TCX transition */
    1653           0 :                 lg = add( lg, st->hTcxCfg->tcx_offset );
    1654           0 :                 IF( st->hTcxCfg->lfacNext < 0 )
    1655             :                 {
    1656           0 :                     lg = sub( lg, st->hTcxCfg->lfacNext );
    1657             :                 }
    1658             : 
    1659           0 :                 lgFB = add( lgFB, shr( lgFB, 1 ) );
    1660             :             }
    1661             : 
    1662             :             /* TNS data */
    1663           0 :             nTnsParams = 0;
    1664           0 :             move16();
    1665           0 :             nTnsBits = 0;
    1666           0 :             move16();
    1667             : 
    1668           0 :             IF( st->hTcxCfg->fIsTNSAllowed )
    1669             :             {
    1670           0 :                 test();
    1671           0 :                 IF( st->last_core_from_bs == ACELP_CORE && ( k == 0 ) )
    1672             :                 {
    1673           0 :                     st->BER_detect = 1;
    1674           0 :                     move16();
    1675           0 :                     st->last_core = TCX_20_CORE;
    1676           0 :                     move16();
    1677           0 :                     st->last_core_from_bs = TCX_20_CORE;
    1678           0 :                     move16();
    1679             :                 }
    1680           0 :                 test();
    1681           0 :                 test();
    1682           0 :                 SetTnsConfig( st->hTcxCfg, 0, ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) );
    1683             : 
    1684           0 :                 ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams );
    1685           0 :                 j = add( j, nTnsParams );
    1686             :             }
    1687             : 
    1688           0 :             hm_size = shl( mult( st->TcxBandwidth, lgFB ), 1 );
    1689             : 
    1690             :             /*compute target bits*/
    1691           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
    1692             : 
    1693             :             /*Context HM flag*/
    1694           0 :             test();
    1695           0 :             test();
    1696           0 :             IF( st->hTcxCfg->ctx_hm && !( ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ) )
    1697             :             {
    1698           0 :                 prm[j] = get_next_indice_fx( st, 1 ); // Q0
    1699           0 :                 move16();
    1700           0 :                 nbits_tcx = sub( nbits_tcx, 1 ); // Q0
    1701           0 :                 move16();
    1702             : 
    1703           0 :                 IF( prm[j] ) /* Read PeriodicityIndex */
    1704             :                 {
    1705           0 :                     Word16 NumIndexBits = DecodeIndex_fx( st, (Word16) GE_16( hm_size, 256 ), prm + j + 1 ); // Q0
    1706             : 
    1707           0 :                     flag_ctx_hm = 1;
    1708           0 :                     move16();
    1709             : 
    1710           0 :                     ConfigureContextHm( lgFB, nbits_tcx, *( prm + j + 1 ), -1, &hm_cfg );
    1711             : 
    1712           0 :                     nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0
    1713             :                 }
    1714             :             }
    1715           0 :             j = add( j, NPRM_CTX_HM ); // Q0
    1716           0 :             phm_cfg = NULL;
    1717           0 :             move16();
    1718           0 :             if ( flag_ctx_hm )
    1719             :             {
    1720           0 :                 phm_cfg = &hm_cfg;
    1721           0 :                 move16();
    1722             :             }
    1723           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
    1724           0 :             move16();
    1725           0 :             j = add( j, lgFB ); // Q0
    1726             : 
    1727             :         } /* k, window index */
    1728             :     }
    1729             : 
    1730        1248 :     IF( !st->use_partial_copy )
    1731             :     {
    1732        1248 :         IF( LT_16( sub( *total_nbbits, bitsRead[0] ), sub( st->next_bit_pos, start_bit_pos ) ) )
    1733             :         {
    1734           0 :             st->BER_detect = 1;
    1735           0 :             move16();
    1736           0 :             st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); // Q0
    1737           0 :             move16();
    1738             :         }
    1739        1248 :         bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); // Q0
    1740        1248 :         move16();
    1741             :     }
    1742             : 
    1743        1248 :     return;
    1744             : }
    1745             : 
    1746             : 
    1747             : /*-------------------------------------------------------------------*
    1748             :  * getTCXMode_ivas()
    1749             :  *
    1750             :  * get TCX mode
    1751             :  *--------------------------------------------------------------------*/
    1752      773210 : void getTCXMode_ivas_fx(
    1753             :     Decoder_State *st,    /* i/o: decoder memory state                 */
    1754             :     Decoder_State *st0,   /* i  : bitstream                            */
    1755             :     const Word16 MCT_flag /* i  : hMCT handle allocated (1) or not (0) */
    1756             : )
    1757             : {
    1758             :     UWord16 ind;
    1759             : 
    1760      773210 :     IF( st->tcxonly )
    1761             :     {
    1762             :         /* get core */
    1763      662012 :         ind = get_next_indice_fx( st0, 1 ); /* Store decoder memory of last_core */
    1764      662012 :         st->core = add( ind, TCX_20_CORE );
    1765      662012 :         move16();
    1766             :         /* get class */
    1767      662012 :         ind = get_next_indice_fx( st0, 2 );
    1768             : 
    1769      662012 :         st->clas_dec = ONSET;
    1770      662012 :         move16();
    1771      662012 :         IF( ind == 0 )
    1772             :         {
    1773      344241 :             st->clas_dec = UNVOICED_CLAS;
    1774      344241 :             move16();
    1775             :         }
    1776      317771 :         ELSE IF( EQ_16( ind, 1 ) )
    1777             :         {
    1778       40065 :             IF( GE_16( st->last_good, VOICED_TRANSITION ) )
    1779             :             {
    1780       32488 :                 st->clas_dec = VOICED_TRANSITION;
    1781       32488 :                 move16();
    1782             :             }
    1783             :             ELSE
    1784             :             {
    1785        7577 :                 st->clas_dec = UNVOICED_TRANSITION;
    1786        7577 :                 move16();
    1787             :             }
    1788             :         }
    1789      277706 :         ELSE IF( EQ_16( ind, 2 ) )
    1790             :         {
    1791      241672 :             st->clas_dec = VOICED_CLAS;
    1792      241672 :             move16();
    1793             :         }
    1794             : 
    1795      662012 :         st->coder_type = INACTIVE;
    1796      662012 :         move16();
    1797      662012 :         test();
    1798      662012 :         IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag )
    1799             :         {
    1800      152892 :             st->VAD = get_next_indice_fx( st0, 1 );
    1801      152892 :             move16();
    1802             :         }
    1803             :         ELSE
    1804             :         {
    1805      509120 :             st->VAD = 0;
    1806      509120 :             move16();
    1807             :         }
    1808             :     }
    1809             :     ELSE
    1810             :     {
    1811      111198 :         IF( EQ_16( st->mdct_sw, MODE1 ) )
    1812             :         {
    1813             :             /* 2 bits instead of 3 as TCX is already signaled */
    1814      111198 :             st->core = TCX_20_CORE;
    1815      111198 :             move16();
    1816      111198 :             st->hTcxCfg->coder_type = get_next_indice_fx( st0, 2 );
    1817      111198 :             move16();
    1818      111198 :             st->coder_type = st->hTcxCfg->coder_type;
    1819      111198 :             move16();
    1820             :         }
    1821             :         ELSE
    1822             :         {
    1823           0 :             IF( EQ_16( st->mdct_sw_enable, MODE2 ) )
    1824             :             {
    1825           0 :                 IF( get_next_indice_1_fx( st0 ) )
    1826             :                 {
    1827           0 :                     ind = get_next_indice_fx( st0, 3 );
    1828           0 :                     assert( !( ind & 4 ) || !"HQ_CORE encountered in dec_prm_ivas" );
    1829           0 :                     st->core = TCX_20_CORE;
    1830           0 :                     move16();
    1831           0 :                     st->hTcxCfg->coder_type = ind;
    1832           0 :                     move16();
    1833           0 :                     st->coder_type = st->hTcxCfg->coder_type;
    1834           0 :                     move16();
    1835             :                 }
    1836             :                 ELSE /* ACELP */
    1837             :                 {
    1838           0 :                     st->core = ACELP_CORE;
    1839           0 :                     move16();
    1840           0 :                     st->coder_type = get_next_indice_fx( st0, 2 );
    1841           0 :                     move16();
    1842             :                 }
    1843             :             }
    1844             :             ELSE
    1845             :             {
    1846           0 :                 IF( EQ_16( st->rf_flag, 1 ) )
    1847             :                 {
    1848           0 :                     IF( !st->use_partial_copy )
    1849             :                     {
    1850           0 :                         ind = get_next_indice_fx( st0, 1 );
    1851           0 :                         IF( ind == 0 )
    1852             :                         {
    1853           0 :                             st->core = ACELP_CORE;
    1854           0 :                             move16();
    1855             :                         }
    1856             :                         ELSE
    1857             :                         {
    1858           0 :                             st->core = TCX_20_CORE;
    1859           0 :                             move16();
    1860           0 :                             st->hTcxCfg->coder_type = st->coder_type;
    1861           0 :                             move16();
    1862             :                         }
    1863             :                     }
    1864             :                 }
    1865             :                 ELSE
    1866             :                 {
    1867           0 :                     ind = get_next_indice_fx( st, 3 );
    1868           0 :                     IF( LT_16( ind, ACELP_MODE_MAX ) )
    1869             :                     {
    1870           0 :                         st->core = ACELP_CORE;
    1871           0 :                         move16();
    1872           0 :                         st->coder_type = ind;
    1873           0 :                         move16();
    1874             :                     }
    1875             :                     ELSE
    1876             :                     {
    1877           0 :                         st->core = TCX_20_CORE;
    1878           0 :                         move16();
    1879           0 :                         st->hTcxCfg->coder_type = sub( ind, ACELP_MODE_MAX );
    1880           0 :                         move16();
    1881           0 :                         st->coder_type = st->hTcxCfg->coder_type;
    1882           0 :                         move16();
    1883             :                     }
    1884             :                 }
    1885             :             }
    1886             :         }
    1887             : 
    1888      111198 :         IF( EQ_16( st->element_mode, EVS_MONO ) )
    1889             :         {
    1890           0 :             test();
    1891           0 :             IF( st->igf && EQ_16( st->core, ACELP_CORE ) )
    1892             :             {
    1893           0 :                 st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) );
    1894           0 :                 move16();
    1895             :             }
    1896             : 
    1897           0 :             IF( st->rf_flag )
    1898             :             {
    1899           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 */
    1900           0 :                 move16();
    1901             :             }
    1902             :         }
    1903             : 
    1904             :         /* Inactive frame detection on non-DTX mode */
    1905      111198 :         IF( EQ_16( st->coder_type, INACTIVE ) )
    1906             :         {
    1907       11517 :             st->VAD = 0;
    1908       11517 :             move16();
    1909             :         }
    1910             :         ELSE
    1911             :         {
    1912       99681 :             st->VAD = 1;
    1913       99681 :             move16();
    1914             :         }
    1915             :     }
    1916             : 
    1917             :     /*Core extended mode mapping for correct PLC classification*/
    1918      773210 :     st->core_ext_mode = st->coder_type;
    1919      773210 :     move16();
    1920      773210 :     if ( EQ_16( st->coder_type, INACTIVE ) )
    1921             :     {
    1922      673529 :         st->core_ext_mode = UNVOICED;
    1923      673529 :         move16();
    1924             :     }
    1925             : 
    1926      773210 :     return;
    1927             : }
    1928             : 
    1929             : /*-------------------------------------------------------------------*
    1930             :  * getTCXWindowing_ivas()
    1931             :  *
    1932             :  * get TCX transform type for each subframe
    1933             :  *--------------------------------------------------------------------*/
    1934      773210 : void getTCXWindowing_ivas_fx(
    1935             :     const Word16 core,         /* i  : current core                  */
    1936             :     const Word16 last_core,    /* i  : last frame core               */
    1937             :     const Word16 element_mode, /* i  : element mode                  */
    1938             :     TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle      */
    1939             :     Decoder_State *st0         /* i  : bitstream                     */
    1940             : )
    1941             : {
    1942             :     Word16 overlap_code;
    1943             : 
    1944             :     /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */
    1945      773210 :     test();
    1946      773210 :     test();
    1947      773210 :     test();
    1948      773210 :     IF( EQ_16( last_core, ACELP_CORE ) || EQ_16( last_core, AMR_WB_CORE ) )
    1949             :     {
    1950        8115 :         hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP;
    1951        8115 :         move16();
    1952             :     }
    1953      765095 :     ELSE IF( EQ_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) )
    1954             :     {
    1955       11160 :         hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP;
    1956       11160 :         move16();
    1957             :     }
    1958      753935 :     ELSE IF( NE_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) )
    1959             :     {
    1960       17852 :         hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
    1961       17852 :         move16();
    1962             :     }
    1963             :     ELSE
    1964             :     {
    1965      736083 :         hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
    1966      736083 :         move16();
    1967             :     }
    1968             : 
    1969             :     /* Set the current overlap mode based on the current frame type and coded overlap mode */
    1970      773210 :     hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
    1971      773210 :     move16();
    1972             : 
    1973      773210 :     IF( NE_16( core, ACELP_CORE ) )
    1974             :     {
    1975      773210 :         overlap_code = 0;
    1976      773210 :         move16();
    1977      773210 :         IF( get_next_indice_fx( st0, 1 ) )
    1978             :         {
    1979       14037 :             overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
    1980             :         }
    1981             : 
    1982             :         assert( MIN_OVERLAP == 2 && HALF_OVERLAP == 3 );
    1983      773210 :         hTcxCfg->tcx_curr_overlap_mode = overlap_code;
    1984      773210 :         move16();
    1985             :         /*TCX10 : always symmetric windows*/
    1986      773210 :         test();
    1987      773210 :         test();
    1988      773210 :         test();
    1989      773210 :         IF( EQ_16( core, TCX_20_CORE ) && ( overlap_code == 0 ) && NE_16( last_core, ACELP_CORE ) && NE_16( last_core, AMR_WB_CORE ) )
    1990             :         {
    1991      741735 :             hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
    1992      741735 :             move16();
    1993             :         }
    1994             :     }
    1995             : 
    1996      773210 :     test();
    1997      773210 :     IF( NE_16( element_mode, EVS_MONO ) && EQ_16( core, TCX_10_CORE ) )
    1998             :     {
    1999             :         /* also read last overlap */
    2000       14619 :         overlap_code = 0;
    2001       14619 :         move16();
    2002             : 
    2003       14619 :         IF( get_next_indice_fx( st0, 1 ) )
    2004             :         {
    2005        3385 :             overlap_code = add( 2, get_next_indice_fx( st0, 1 ) );
    2006             :         }
    2007             : 
    2008       14619 :         hTcxCfg->tcx_last_overlap_mode = overlap_code;
    2009       14619 :         move16();
    2010             :     }
    2011             : 
    2012      773210 :     return;
    2013             : }

Generated by: LCOV version 1.14