LCOV - code coverage report
Current view: top level - lib_dec - dec_prm.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 373 396 94.2 %
Date: 2025-09-14 08:49:17 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <assert.h>
      38             : #include <stdint.h>
      39             : #include "options.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include "cnst.h"
      44             : #include "rom_com.h"
      45             : #include "prot.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : 
      49             : /*-------------------------------------------------------------------*
      50             :  * getTCXMode()
      51             :  *
      52             :  * get TCX mode
      53             :  *--------------------------------------------------------------------*/
      54             : 
      55    27434599 : void getTCXMode(
      56             :     Decoder_State *st,     /* i/o: decoder memory state                 */
      57             :     Decoder_State *st0,    /* i  : bitstream                            */
      58             :     const int16_t MCT_flag /* i  : hMCT handle allocated (1) or not (0) */
      59             : )
      60             : {
      61             :     uint16_t ind;
      62             : 
      63    27434599 :     if ( st->tcxonly )
      64             :     {
      65             :         /* get core */
      66    23589973 :         ind = get_next_indice( st0, 1 );
      67    23589973 :         st->core = ind + TCX_20_CORE;
      68             : 
      69             :         /* get class */
      70    23589973 :         ind = get_next_indice( st0, 2 );
      71             : 
      72    23589973 :         st->clas_dec = ONSET;
      73    23589973 :         if ( ind == 0 )
      74             :         {
      75    11358569 :             st->clas_dec = UNVOICED_CLAS;
      76             :         }
      77    12231404 :         else if ( ind == 1 )
      78             :         {
      79     1597781 :             if ( st->last_good >= VOICED_TRANSITION )
      80             :             {
      81     1318194 :                 st->clas_dec = VOICED_TRANSITION;
      82             :             }
      83             :             else
      84             :             {
      85      279587 :                 st->clas_dec = UNVOICED_TRANSITION;
      86             :             }
      87             :         }
      88    10633623 :         else if ( ind == 2 )
      89             :         {
      90     9451793 :             st->clas_dec = VOICED_CLAS;
      91             :         }
      92             : 
      93    23589973 :         st->coder_type = INACTIVE;
      94    23589973 :         if ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag )
      95             :         {
      96     5526558 :             st->VAD = get_next_indice( st0, 1 );
      97             :         }
      98             :         else
      99             :         {
     100    18063415 :             st->VAD = 0;
     101             :         }
     102             :     }
     103             :     else
     104             :     {
     105     3844626 :         if ( st->mdct_sw == MODE1 )
     106             :         {
     107             :             /* 2 bits instead of 3 as TCX is already signaled */
     108     3811624 :             st->core = TCX_20_CORE;
     109     3811624 :             st->hTcxCfg->coder_type = get_next_indice( st0, 2 );
     110     3811624 :             st->coder_type = st->hTcxCfg->coder_type;
     111             :         }
     112             :         else
     113             :         {
     114       33002 :             if ( st->mdct_sw_enable == MODE2 )
     115             :             {
     116       24626 :                 if ( get_next_indice_1( st0 ) ) /* TCX */
     117             :                 {
     118       11711 :                     ind = get_next_indice( st0, 3 );
     119       11711 :                     assert( !( ind & 4 ) || !"HQ_CORE encountered in dec_prm" );
     120       11711 :                     st->core = TCX_20_CORE;
     121       11711 :                     st->hTcxCfg->coder_type = ind;
     122       11711 :                     st->coder_type = st->hTcxCfg->coder_type;
     123             :                 }
     124             :                 else /* ACELP */
     125             :                 {
     126       12915 :                     st->core = ACELP_CORE;
     127       12915 :                     st->coder_type = get_next_indice( st0, 2 );
     128             :                 }
     129             :             }
     130             :             else
     131             :             {
     132        8376 :                 if ( st->rf_flag == 1 )
     133             :                 {
     134        3000 :                     if ( !st->use_partial_copy )
     135             :                     {
     136        2816 :                         ind = get_next_indice( st0, 1 );
     137        2816 :                         if ( ind == 0 )
     138             :                         {
     139        2448 :                             st->core = ACELP_CORE;
     140             :                         }
     141             :                         else
     142             :                         {
     143         368 :                             st->core = TCX_20_CORE;
     144         368 :                             st->hTcxCfg->coder_type = st->coder_type;
     145             :                         }
     146             :                     }
     147             :                 }
     148             :                 else
     149             :                 {
     150        5376 :                     ind = get_next_indice( st, 3 );
     151        5376 :                     if ( ind < ACELP_MODE_MAX )
     152             :                     {
     153        3373 :                         st->core = ACELP_CORE;
     154        3373 :                         st->coder_type = ind;
     155             :                     }
     156             :                     else
     157             :                     {
     158        2003 :                         st->core = TCX_20_CORE;
     159        2003 :                         st->hTcxCfg->coder_type = ind - ACELP_MODE_MAX;
     160        2003 :                         st->coder_type = st->hTcxCfg->coder_type;
     161             :                     }
     162             :                 }
     163             :             }
     164             :         }
     165             : 
     166     3844626 :         if ( st->element_mode == EVS_MONO )
     167             :         {
     168       38875 :             if ( st->igf && st->core == ACELP_CORE )
     169             :             {
     170       15215 :                 st->bits_frame_core -= get_tbe_bits( st->total_brate, st->bwidth, st->rf_flag );
     171             :             }
     172             : 
     173       38875 :             if ( st->rf_flag )
     174             :             {
     175        3000 :                 st->bits_frame_core -= ( st->rf_target_bits + 1 ); /* +1 as flag-bit not considered in rf_target_bits */
     176             :             }
     177             :         }
     178             : 
     179             :         /* Inactive frame detection on non-DTX mode */
     180     3844626 :         if ( st->coder_type == INACTIVE )
     181             :         {
     182      388396 :             st->VAD = 0;
     183             :         }
     184             :         else
     185             :         {
     186     3456230 :             st->VAD = 1;
     187             :         }
     188             :     }
     189             : 
     190             :     /*Core extended mode mapping for correct PLC classification*/
     191    27434599 :     st->core_ext_mode = st->coder_type;
     192    27434599 :     if ( st->coder_type == INACTIVE )
     193             :     {
     194    23978369 :         st->core_ext_mode = UNVOICED;
     195             :     }
     196             : 
     197    27434599 :     return;
     198             : }
     199             : 
     200             : 
     201             : /*-------------------------------------------------------------------*
     202             :  * getTCXWindowing()
     203             :  *
     204             :  * get TCX transform type for each subframe
     205             :  *--------------------------------------------------------------------*/
     206             : 
     207    27434415 : void getTCXWindowing(
     208             :     const int16_t core,         /* i  : current core                  */
     209             :     const int16_t last_core,    /* i  : last frame core               */
     210             :     const int16_t element_mode, /* i  : element mode                  */
     211             :     TCX_CONFIG_HANDLE hTcxCfg,  /* i/o: TCX configuration handle      */
     212             :     Decoder_State *st0          /* i  : bitstream                     */
     213             : )
     214             : {
     215             :     int16_t overlap_code;
     216             : 
     217             :     /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */
     218    27434415 :     if ( last_core == ACELP_CORE || last_core == AMR_WB_CORE )
     219             :     {
     220      230504 :         hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP;
     221             :     }
     222    27203911 :     else if ( core == TCX_10_CORE && hTcxCfg->tcx_curr_overlap_mode == ALDO_WINDOW )
     223             :     {
     224      535523 :         hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP;
     225             :     }
     226    26668388 :     else if ( core != TCX_10_CORE && hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP )
     227             :     {
     228      865772 :         hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
     229             :     }
     230             :     else
     231             :     {
     232    25802616 :         hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode;
     233             :     }
     234             : 
     235             :     /* Set the current overlap mode based on the current frame type and coded overlap mode */
     236    27434415 :     hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
     237             : 
     238    27434415 :     if ( core != ACELP_CORE )
     239             :     {
     240    27415679 :         overlap_code = 0;
     241    27415679 :         if ( get_next_indice( st0, 1 ) )
     242             :         {
     243      496830 :             overlap_code = 2 + get_next_indice( st0, 1 );
     244             :         }
     245             : 
     246             :         assert( MIN_OVERLAP == 2 && HALF_OVERLAP == 3 );
     247    27415679 :         hTcxCfg->tcx_curr_overlap_mode = overlap_code;
     248             : 
     249             :         /*TCX10 : always symmetric windows*/
     250    27415679 :         if ( core == TCX_20_CORE && overlap_code == 0 && last_core != ACELP_CORE && last_core != AMR_WB_CORE )
     251             :         {
     252    26311543 :             hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
     253             :         }
     254             :     }
     255             : 
     256    27434415 :     if ( element_mode != EVS_MONO && core == TCX_10_CORE )
     257             :     {
     258             :         /* also read last overlap */
     259      616098 :         overlap_code = 0;
     260             : 
     261      616098 :         if ( get_next_indice( st0, 1 ) )
     262             :         {
     263       76467 :             overlap_code = 2 + get_next_indice( st0, 1 );
     264             :         }
     265             : 
     266      616098 :         hTcxCfg->tcx_last_overlap_mode = overlap_code;
     267             :     }
     268             : 
     269    27434415 :     return;
     270             : }
     271             : 
     272             : 
     273             : /*-------------------------------------------------------------------*
     274             :  * getLPCparam()
     275             :  *
     276             :  * get LPC parameters
     277             :  *--------------------------------------------------------------------*/
     278             : 
     279    24849733 : void getLPCparam(
     280             :     Decoder_State *st,            /* i/o: decoder memory state          */
     281             :     int16_t param_lpc[],          /* o  : LTP parameters                */
     282             :     Decoder_State *st0,           /* i  : bitstream                     */
     283             :     const int16_t ch,             /* i  : channel                       */
     284             :     const int16_t sns_low_br_mode /* i  : SNS low-bitrate mode          */
     285             : )
     286             : {
     287    24849733 :     if ( st->use_partial_copy == 0 )
     288             :     {
     289             :         /* Number of sets of LPC parameters (does not include mid-lpc) */
     290    24849549 :         if ( st->tcxonly == 0 || st->core < TCX_10_CORE )
     291             :         {
     292    24306183 :             st->numlpc = 1;
     293             :         }
     294             :         else
     295             :         {
     296      543366 :             st->numlpc = 2;
     297             :         }
     298             : 
     299             :         /* Decode LPC parameters */
     300    24849549 :         if ( st->hTcxDec->enableTcxLpc && st->core != ACELP_CORE )
     301      371149 :         {
     302             :             int16_t tcx_lpc_cdk;
     303      371149 :             tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type );
     304      371149 :             dec_lsf_tcxlpc( st0, &param_lpc, st->narrowBand, tcx_lpc_cdk );
     305             :         }
     306             :         else
     307             :         {
     308    24478400 :             if ( st->lpcQuantization == 0 )
     309             :             {
     310    21005107 :                 decode_lpc_avq( st0, st->numlpc, param_lpc, ch, st->element_mode, sns_low_br_mode );
     311             :             }
     312     3473293 :             else if ( st->lpcQuantization == 1 )
     313             :             {
     314     3473293 :                 if ( st->sr_core == INT_FS_16k && st->coder_type == VOICED && st->core == ACELP_CORE )
     315             :                 {
     316        5849 :                     assert( st->element_mode == EVS_MONO );
     317             : 
     318        5849 :                     lsf_bctcvq_decprm( st0, param_lpc );
     319             :                 }
     320             :                 else
     321             :                 {
     322     3467444 :                     lsf_msvq_ma_decprm( st0, param_lpc );
     323             :                 }
     324             :             }
     325             :             else
     326             :             {
     327           0 :                 assert( 0 );
     328             :             }
     329             :         }
     330             :     }
     331             :     else
     332             :     {
     333         184 :         st->numlpc = 1;
     334             : 
     335         184 :         if ( st->rf_frame_type == RF_TCXFD )
     336             :         {
     337           0 :             param_lpc[0] = 0;
     338           0 :             param_lpc[1] = get_next_indice( st0, lsf_numbits[0] ); /* VQ 1 */
     339           0 :             param_lpc[2] = get_next_indice( st0, lsf_numbits[1] ); /* VQ 2 */
     340           0 :             param_lpc[3] = get_next_indice( st0, lsf_numbits[2] ); /* VQ 3 */
     341             :         }
     342         184 :         else if ( st->rf_frame_type >= RF_ALLPRED && st->rf_frame_type <= RF_NELP )
     343             :         {
     344             :             /* LSF indices */
     345         172 :             param_lpc[0] = get_next_indice( st0, 8 ); /* VQ 1 */
     346         172 :             param_lpc[1] = get_next_indice( st0, 8 ); /* VQ 2 */
     347             :         }
     348             :     }
     349             : 
     350    24849733 :     return;
     351             : }
     352             : 
     353             : /*-------------------------------------------------------------------*
     354             :  * getTCXparam()
     355             :  *
     356             :  * get TCX core parameters
     357             :  *-------------------------------------------------------------------*/
     358             : 
     359    48833881 : void getTCXparam(
     360             :     Decoder_State *st,           /* i/o: Decoder State handle        */
     361             :     Decoder_State *st0,          /* i  : bitstream                   */
     362             :     CONTEXT_HM_CONFIG hm_cfg,    /* i/o: HM config                   */
     363             :     int16_t param[],             /* o  : decoded parameters          */
     364             :     const int16_t bits_common,   /* i  : number of common bits       */
     365             :     const int16_t start_bit_pos, /* i  : position of the start bit   */
     366             :     const int16_t *no_param_tns, /* i  : number of TNS parameters per subframe */
     367             :     int16_t p_param[2],          /* o  : pointer to parameters for next round of bs reading*/
     368             :     int16_t nTnsBitsTCX10[2],
     369             :     const int16_t pre_past_flag )
     370             : {
     371             :     int16_t ix, j, k, core, last_core, nSubframes;
     372             :     int16_t lg, lgFB, flag_ctx_hm, hm_size;
     373             :     int16_t PeriodicityIndex, useHarmonicModel;
     374             :     int16_t tcxltp_prm_0, tcxltp_prm_1, tcxltp_prm_2, nbits_igf, nbits_tcx;
     375             :     int16_t *prm, *prms;
     376             :     int16_t nTnsParams, nTnsBits;
     377             :     int16_t pre_part, post_part;
     378    48833881 :     TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
     379    48833881 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
     380             : 
     381             : 
     382    48833881 :     if ( pre_past_flag == 0 )
     383             :     {
     384    21418202 :         pre_part = 1;
     385    21418202 :         post_part = 0;
     386             :     }
     387    27415679 :     else if ( pre_past_flag == 1 )
     388             :     {
     389    21418202 :         pre_part = 0;
     390    21418202 :         post_part = 1;
     391             :     }
     392             :     else
     393             :     {
     394     5997477 :         pre_part = 1;
     395     5997477 :         post_part = 1;
     396             :     }
     397             : 
     398             :     /* initialization */
     399    48833881 :     tcxltp_prm_0 = 0;
     400    48833881 :     tcxltp_prm_1 = 0;
     401    48833881 :     tcxltp_prm_2 = 0;
     402    48833881 :     nbits_igf = 0;
     403             : 
     404    48833881 :     PeriodicityIndex = 0;
     405    48833881 :     useHarmonicModel = 0;
     406             : 
     407    48833881 :     core = st->core;
     408    48833881 :     last_core = st->last_core;
     409             : 
     410    48833881 :     nSubframes = 1;
     411    48833881 :     if ( core == TCX_10_CORE )
     412             :     {
     413     1186525 :         nSubframes = 2;
     414             :     }
     415             : 
     416    48833881 :     if ( st->element_mode < IVAS_CPE_MDCT && st->igf && core == TCX_10_CORE )
     417             :     {
     418             :         /* get IGF */
     419       72519 :         for ( k = 0; k < nSubframes; k++ )
     420             :         {
     421       48346 :             ix = st->next_bit_pos;
     422             : 
     423       48346 :             IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k );
     424             : 
     425       48346 :             IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k );
     426             : 
     427       48346 :             IGFDecStoreTCX10SubFrameData( st->hIGFDec, k );
     428             : 
     429       48346 :             nbits_igf += st0->next_bit_pos - ix;
     430             :         }
     431             :     }
     432             : 
     433             :     /* loop over subframes */
     434    98854287 :     for ( k = 0; k < nSubframes; k++ )
     435             :     {
     436    50020406 :         flag_ctx_hm = 0;
     437             : 
     438    50020406 :         prm = param + ( k * DEC_NPRM_DIV );
     439    50020406 :         j = 0;
     440             : 
     441    50020406 :         nbits_tcx = st0->next_bit_pos - start_bit_pos;
     442             : 
     443    50020406 :         if ( pre_part && st->enablePlcWaveadjust && k == ( nSubframes - 1 ) )
     444             :         {
     445       13166 :             st->tonality_flag = get_next_indice( st0, 1 );
     446             :         }
     447             : 
     448    50020406 :         if ( post_part )
     449             :         {
     450             :             /* TCX Gain */
     451    28032295 :             prm[j++] = get_next_indice( st0, NBITS_TCX_GAIN );
     452             : 
     453             :             /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */
     454    28032295 :             prm[j++] = get_next_indice( st0, NBITS_NOISE_FILL_LEVEL );
     455             :         }
     456             :         else
     457             :         {
     458    21988111 :             j += 1 + NOISE_FILL_RANGES;
     459             :         }
     460             : 
     461             :         /* LTP data */
     462    50020406 :         if ( pre_part )
     463             :         {
     464    28032295 :             if ( ( k == 0 ) && ( hTcxLtpDec->tcxltp || ( st->sr_core > 25600 ) ) ) /* PLC pitch info for HB */
     465             :             {
     466    27415679 :                 prm[j] = get_next_indice( st0, 1 );
     467             : 
     468    27415679 :                 if ( prm[j] )
     469             :                 {
     470    16353372 :                     prm[j + 1] = get_next_indice( st0, 9 );
     471    16353372 :                     prm[j + 2] = get_next_indice( st0, 2 );
     472             : 
     473    16353372 :                     tcxltp_prm_0 = prm[j];
     474    16353372 :                     tcxltp_prm_1 = prm[j + 1];
     475    16353372 :                     tcxltp_prm_2 = prm[j + 2];
     476             :                 }
     477    27415679 :                 st->BER_detect = 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 );
     478             : 
     479    27415679 :                 hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain;
     480             : 
     481    27415679 :                 if ( core == TCX_20_CORE && !st->tcxonly && hTcxLtpDec->tcxltp_pitch_int < st->L_frame )
     482             :                 {
     483     3825706 :                     hTcxDec->tcx_hm_LtpPitchLag = ( ( 2 * st->L_frame * st->pit_res_max ) << kLtpHmFractionalResolution ) / ( hTcxLtpDec->tcxltp_pitch_int * st->pit_res_max + hTcxLtpDec->tcxltp_pitch_fr );
     484             :                 }
     485             :                 else
     486             :                 {
     487    23589973 :                     hTcxDec->tcx_hm_LtpPitchLag = -1;
     488             :                 }
     489    27415679 :                 j += 3;
     490             :             }
     491             :             else
     492             :             {
     493      616616 :                 prm[j++] = tcxltp_prm_0;
     494      616616 :                 prm[j++] = tcxltp_prm_1;
     495      616616 :                 prm[j++] = tcxltp_prm_2;
     496             :             }
     497             :         }
     498             : 
     499             :         /* TCX spectral data */
     500    50020406 :         lg = st->L_frame >> ( nSubframes - 1 );
     501    50020406 :         lgFB = st->hTcxCfg->tcx_coded_lines >> ( nSubframes - 1 );
     502             : 
     503    50020406 :         if ( post_part && k == 0 && st->last_core_from_bs == ACELP_CORE )
     504             :         {
     505             :             /* ACE->TCX transition */
     506      212407 :             lg += st->hTcxCfg->tcx_offset;
     507      212407 :             lgFB += lgFB >> ( 3 - nSubframes );
     508             : 
     509      212407 :             if ( st->hTcxCfg->lfacNext < 0 )
     510             :             {
     511      212407 :                 lg -= st->hTcxCfg->lfacNext;
     512             :             }
     513             :         }
     514             : 
     515    50020406 :         if ( pre_part )
     516             :         {
     517             :             /* TNS data */
     518    28032295 :             nTnsParams = 0;
     519    28032295 :             nTnsBits = 0;
     520             : 
     521    28032295 :             if ( st->hTcxCfg->fIsTNSAllowed )
     522             :             {
     523    25895515 :                 if ( core == TCX_10_CORE && last_core == ACELP_CORE && k == 0 )
     524             :                 {
     525           0 :                     st0->BER_detect = 1;
     526           0 :                     last_core = TCX_20_CORE;
     527             :                 }
     528             : 
     529    25895515 :                 SetTnsConfig( st->hTcxCfg, core == TCX_20_CORE, ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) );
     530    25895515 :                 ix = 0;
     531    25895515 :                 if ( no_param_tns )
     532             :                 {
     533      348387 :                     ix = get_next_indice( st0, 1 ); /* common_tns_data[] for subframe k */
     534             :                 }
     535    25895515 :                 if ( ix )
     536             :                 {
     537       86566 :                     prm[j] = no_param_tns[k] * -1; /* - signals common TNS and its size */
     538       86566 :                     nTnsParams = no_param_tns[k];
     539             :                 }
     540             :                 else
     541             :                 {
     542    25808949 :                     ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams );
     543             :                 }
     544    25895515 :                 hTcxDec->tnsActive[k] = ( prm[j] != 0 ? 1 : 0 ) * nTnsParams;
     545    25895515 :                 if ( nTnsBitsTCX10 != NULL )
     546             :                 {
     547    21988111 :                     nTnsBitsTCX10[k] = nTnsBits + ( no_param_tns ? 1 : 0 );
     548             :                 }
     549             : 
     550    25895515 :                 j += nTnsParams;
     551             :             }
     552             : 
     553    28032295 :             if ( post_part )
     554             :             {
     555     6044184 :                 if ( core == TCX_20_CORE )
     556             :                 {
     557     5950770 :                     hm_size = (int16_t) ( 2.0f * st->TcxBandwidth * (float) lg );
     558             : 
     559     5950770 :                     if ( hTcxDec->tcx_lpc_shaped_ari && st->last_core_from_bs != ACELP_CORE )
     560             :                     {
     561      341695 :                         dec_prm_hm( st0, &prm[j], hm_size );
     562             :                     }
     563             : 
     564     5950770 :                     nbits_tcx = st->bits_frame_core - ( st0->next_bit_pos - start_bit_pos );
     565             :                 }
     566             :                 else
     567             :                 {
     568       93414 :                     hm_size = (int16_t) ( 2.0f * st->TcxBandwidth * (float) lgFB );
     569             : 
     570       93414 :                     nbits_tcx = ( ( st->bits_frame_core - bits_common - nbits_igf + 1 - k ) >> 1 ) - ( ( st0->next_bit_pos - start_bit_pos ) - nbits_tcx );
     571             :                 }
     572             : 
     573             :                 /*Context HM flag*/
     574     6044184 :                 if ( st->hTcxCfg->ctx_hm && !( st->last_core_from_bs == ACELP_CORE && k == 0 ) )
     575             :                 {
     576     4458583 :                     useHarmonicModel = get_next_indice( st0, 1 );
     577     4458583 :                     prm[j] = useHarmonicModel;
     578     4458583 :                     nbits_tcx--;
     579             : 
     580     4458583 :                     if ( useHarmonicModel )
     581             :                     {
     582      287185 :                         ix = DecodeIndex( st0, hm_size >= 256, prm + j + 1 );
     583      287185 :                         flag_ctx_hm = 1;
     584             : 
     585      287185 :                         PeriodicityIndex = *( prm + j + 1 );
     586      287185 :                         if ( st->element_mode == EVS_MONO )
     587             :                         {
     588        3673 :                             ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg );
     589             :                         }
     590      287185 :                         nbits_tcx -= ix;
     591             :                     }
     592             :                 }
     593             :             }
     594    28032295 :             j += NPRM_CTX_HM;
     595             : 
     596             :             /* read IGF payload */
     597    28032295 :             if ( post_part && core == TCX_20_CORE )
     598             :             {
     599     5950770 :                 if ( st->igf )
     600             :                 {
     601     4559977 :                     ix = st->next_bit_pos;
     602     4559977 :                     IGFDecReadLevel( st->hIGFDec, st0, ( st->last_core_from_bs == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 );
     603             : 
     604     4559977 :                     IGFDecReadData( st->hIGFDec, st0, ( st->last_core_from_bs == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 );
     605             : 
     606     4559977 :                     nbits_tcx -= ( st0->next_bit_pos - ix );
     607             :                 }
     608     5950770 :                 nbits_tcx = st->bits_frame_core - ( st0->next_bit_pos - start_bit_pos );
     609             :             }
     610    22081525 :             else if ( p_param != NULL )
     611             :             {
     612    21988111 :                 p_param[k] = j;
     613             :             }
     614             :         }
     615             :         else
     616             :         {
     617    21988111 :             j = p_param[k];
     618             : 
     619    21988111 :             nbits_tcx = st->bits_frame_channel;
     620    21988111 :             if ( st->core == TCX_10_CORE )
     621             :             {
     622     1139818 :                 nbits_tcx = nTnsBitsTCX10[k] - NBITS_TCX_GAIN - NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL;
     623             :             }
     624             :         }
     625             : 
     626    50020406 :         if ( post_part )
     627             :         {
     628    28032295 :             if ( hTcxDec->tcx_lpc_shaped_ari && core == TCX_20_CORE )
     629             :             {
     630      371149 :                 prm[j++] = nbits_tcx; /* store length of buffer */
     631      371149 :                 prms = &prm[j];
     632    66364699 :                 for ( ix = 0; ix < nbits_tcx; ix++ )
     633             :                 {
     634    65993550 :                     prms[ix] = get_next_indice_1( st0 );
     635             :                 }
     636    12247917 :                 for ( ix = 0; ix < 32; ix++ )
     637             :                 {
     638    11876768 :                     prms[ix + nbits_tcx] = 1;
     639             :                 }
     640      371149 :                 j += nbits_tcx;
     641             :             }
     642             :             else
     643             :             {
     644    27661146 :                 if ( st->element_mode > EVS_MONO )
     645             :                 {
     646    27629878 :                     if ( useHarmonicModel )
     647             :                     {
     648      283512 :                         ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg );
     649             :                     }
     650    27629878 :                     hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS( st0, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, flag_ctx_hm ? &hm_cfg : NULL );
     651             :                 }
     652             :                 else
     653             :                 {
     654       31268 :                     hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, flag_ctx_hm ? &hm_cfg : NULL );
     655             :                 }
     656             :             }
     657             :         }
     658             :     }
     659             : 
     660    48833881 :     return;
     661             : }
     662             : 
     663             : 
     664             : /*-----------------------------------------------------------------*
     665             :  * dec_prm_hm()
     666             :  *
     667             :  *
     668             :  *-----------------------------------------------------------------*/
     669             : 
     670      341695 : void dec_prm_hm(
     671             :     Decoder_State *st,
     672             :     int16_t *prm_hm,
     673             :     const int16_t hm_size )
     674             : {
     675             :     /* Disable HM for non-GC,VC modes */
     676      341695 :     if ( st->hTcxCfg->coder_type != VOICED && st->hTcxCfg->coder_type != GENERIC )
     677             :     {
     678       59791 :         prm_hm[0] = 0;
     679             : 
     680       59791 :         return;
     681             :     }
     682             : 
     683      281904 :     prm_hm[1] = -1;
     684      281904 :     prm_hm[2] = 0;
     685             : 
     686             :     /* Flag */
     687      281904 :     prm_hm[0] = get_next_indice( st, 1 );
     688             : 
     689      281904 :     if ( prm_hm[0] )
     690             :     {
     691             :         /* Periodicity index */
     692      159558 :         DecodeIndex( st, hm_size >= 256, &prm_hm[1] );
     693             : 
     694             :         /* Gain index */
     695      159558 :         if ( st->hTcxCfg->coder_type == VOICED )
     696             :         {
     697       73543 :             prm_hm[2] = get_next_indice( st, kTcxHmNumGainBits );
     698             :         }
     699             :     }
     700             : 
     701      281904 :     return;
     702             : }
     703             : 
     704             : 
     705             : /*-----------------------------------------------------------------*
     706             :  * Function  dec_prm()                                             *
     707             :  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                   *
     708             :  *
     709             :  * SQ is used for TCX modes
     710             :  *
     711             :  * decode parameters according to selected mode                    *
     712             :  *-----------------------------------------------------------------*/
     713             : 
     714       52041 : void dec_prm(
     715             :     Decoder_State *st,     /* i/o: decoder memory state            */
     716             :     int16_t param[],       /* o  : decoded parameters              */
     717             :     int16_t param_lpc[],   /* o  : LPC parameters                  */
     718             :     int16_t *total_nbbits, /* i/o: number of bits / decoded bits   */
     719             :     int16_t *bitsRead )
     720             : {
     721             :     int16_t j, n, sfr, core, nb_subfr;
     722             :     int16_t *prm;
     723             :     int16_t start_bit_pos, bits_common, acelp_target_bits;
     724             :     int16_t ix, j_old, wordcnt, bitcnt;
     725             :     CONTEXT_HM_CONFIG hm_cfg;
     726             :     int16_t indexBuffer[N_MAX + 1];
     727             :     int16_t ind;
     728             :     int16_t ltp_mode, gains_mode;
     729             :     int16_t prm_ltp[LTPSIZE];
     730       52041 :     TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
     731       52041 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
     732             : 
     733             :     /*--------------------------------------------------------------------------------*
     734             :      * INIT
     735             :      *--------------------------------------------------------------------------------*/
     736             : 
     737       52041 :     hm_cfg.indexBuffer = indexBuffer;
     738             : 
     739       52041 :     core = st->core;
     740             : 
     741       52041 :     if ( st->mdct_sw == MODE1 )
     742             :     {
     743        5873 :         start_bit_pos = 0; /* count from frame start */
     744             : 
     745             :         /* Adjust st->bits_frame_core not to subtract MODE2 bandwidth signaling */
     746       35613 :         for ( n = 0; n < FRAME_SIZE_NB; n++ )
     747             :         {
     748       35613 :             if ( FrameSizeConfig[n].frame_bits == st->total_brate / FRAMES_PER_SEC )
     749             :             {
     750        5873 :                 st->bits_frame_core += FrameSizeConfig[n].bandwidth_bits;
     751        5873 :                 break;
     752             :             }
     753             :         }
     754             :     }
     755             :     else
     756             :     {
     757       46168 :         if ( st->rf_flag == 1 )
     758             :         {
     759             :             /*Inherent adjustment to accommodate the compact packing used in the RF mode*/
     760        3000 :             start_bit_pos = st->next_bit_pos - 2;
     761             :         }
     762             :         else
     763             :         {
     764       43168 :             start_bit_pos = st->next_bit_pos;
     765             :         }
     766             :     }
     767             : 
     768             :     /* Framing parameters */
     769       52041 :     nb_subfr = st->nb_subfr;
     770             : 
     771             :     /* Initialize pointers */
     772       52041 :     prm = param;
     773             : 
     774             :     /* Init counters */
     775       52041 :     j = 0;
     776             : 
     777             :     /* Init LTP data */
     778       52041 :     if ( hTcxDec != NULL )
     779             :     {
     780       52041 :         hTcxDec->tcx_hm_LtpPitchLag = -1;
     781       52041 :         hTcxLtpDec->tcxltp_gain = 0.0f;
     782             :     }
     783             : 
     784             :     /*--------------------------------------------------------------------------------*
     785             :      * core-coder header
     786             :      *--------------------------------------------------------------------------------*/
     787             : 
     788             :     /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */
     789       52041 :     getTCXMode( st, st, 0 /* <- MCT_flag */ );
     790       52041 :     core = st->core;
     791             : 
     792             :     /* Decode last_core for error concealment */
     793       52041 :     if ( !( core == ACELP_CORE && st->hTcxCfg->lfacNext <= 0 ) && !st->use_partial_copy )
     794             :     {
     795             : 
     796       33121 :         st->last_core_from_bs = get_next_indice( st, 1 );
     797             :         /*
     798             :            need to introduce special error handling for lost transition frames from CNG:
     799             :            in such cases, the bitstream reader continues with CNG, setting bfi = 0, total_brate = 0
     800             :            this might result in a not matching last_core transmitted in the BS - we should use this
     801             :            only for interpreting the bitstream and re-use the internal state for the proper
     802             :            transition handling; still, for voiced onsets rather stick to wrong windowing...
     803             :         */
     804       33121 :         if ( ( !( ( st->last_total_brate == 0 ) && ( st->clas_dec != VOICED_CLAS ) ) ) && ( st->last_core_from_bs != st->last_core ) )
     805             :         {
     806         876 :             st->last_core = st->last_core_from_bs;
     807             :         }
     808             : 
     809             :         /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/
     810       33121 :         if ( core == TCX_10_CORE )
     811             :         {
     812         518 :             st->last_core = TCX_20_CORE;
     813         518 :             st->last_core_from_bs = TCX_20_CORE;
     814             :         }
     815             :     }
     816             : 
     817       52041 :     if ( st->rf_flag && st->use_partial_copy && !st->tcxonly )
     818             :     {
     819             :         int32_t nbits_total;
     820         184 :         nbits_total = st->total_brate / FRAMES_PER_SEC;
     821         184 :         st->bits_frame_core = st->rf_target_bits;
     822             :         /* offset the indices to read the acelp partial copy */
     823         184 :         get_next_indice_tmp( st, (int16_t) ( start_bit_pos + nbits_total - st->rf_target_bits - 3 - st->next_bit_pos ) );
     824             :     }
     825             : 
     826       52041 :     if ( !st->use_partial_copy )
     827             :     {
     828       51857 :         getTCXWindowing( st->core, st->last_core, st->element_mode, st->hTcxCfg, st );
     829             : 
     830       51857 :         if ( st->enableGplc ) /* SIDE INFO. DECODING */
     831             :         {
     832             :             int16_t pitchDiff;
     833             :             int16_t bits_per_subfr, search_range;
     834       16910 :             bits_per_subfr = 4;
     835       16910 :             search_range = 8;
     836       16910 :             st->flagGuidedAcelp = get_next_indice( st, 1 );
     837             : 
     838       16910 :             pitchDiff = 0;
     839       16910 :             if ( st->flagGuidedAcelp )
     840             :             {
     841        7415 :                 pitchDiff = get_next_indice( st, bits_per_subfr );
     842        7415 :                 st->guidedT0 = ( pitchDiff - search_range );
     843             :             }
     844       16910 :             if ( pitchDiff == 0 && st->flagGuidedAcelp )
     845             :             {
     846         198 :                 st->flagGuidedAcelp = 0;
     847             :             }
     848             :         }
     849             :         else
     850             :         {
     851       34947 :             st->flagGuidedAcelp = 0;
     852             :         }
     853             : 
     854       51857 :         if ( st->dec_glr )
     855             :         {
     856       30002 :             if ( core == ACELP_CORE )
     857             :             {
     858       16288 :                 st->dec_glr_idx = get_next_indice( st, G_LPC_RECOVERY_BITS );
     859             :             }
     860             :             else
     861             :             {
     862       13714 :                 st->dec_glr_idx = -1;
     863             :             }
     864             :         }
     865             :     }
     866             : 
     867             :     /*--------------------------------------------------------------------------------*
     868             :      * LPC parameters
     869             :      *--------------------------------------------------------------------------------*/
     870             : 
     871             :     /*Initialization of LPC Mid flag*/
     872       52041 :     if ( ( st->lpcQuantization == 1 && st->coder_type == VOICED ) || ( st->use_partial_copy ) )
     873             :     {
     874       14832 :         ( &( st->acelp_cfg ) )->midLpc = 0;
     875             :     }
     876             :     else
     877             :     {
     878       37209 :         ( &( st->acelp_cfg ) )->midLpc = st->acelp_cfg.midLpc_enable;
     879             :     }
     880             : 
     881       52041 :     getLPCparam( st, param_lpc, st, -1, 0 );
     882             : 
     883       52041 :     bits_common = st->next_bit_pos - start_bit_pos;
     884             : 
     885             :     /*--------------------------------------------------------------------------------*
     886             :      * ACELP parameters
     887             :      *--------------------------------------------------------------------------------*/
     888             : 
     889       52041 :     if ( core == ACELP_CORE && st->use_partial_copy == 0 )
     890       18736 :     {
     891             :         int16_t tmp;
     892             : 
     893             :         /* Target Bits */
     894             : 
     895             :         /* needed in decoder to read the bitstream */
     896       18736 :         acelp_target_bits = st->bits_frame_core - bits_common;
     897             : 
     898             :         /* Configure ACELP */
     899       18736 :         tmp = BITS_ALLOC_config_acelp( acelp_target_bits, st->coder_type, &( st->acelp_cfg ), st->narrowBand, st->nb_subfr );
     900       18736 :         if ( tmp < 0 )
     901             :         {
     902             :             /* erroneous configuration, resulting from a corrupt bitstream */
     903           0 :             st->BER_detect = 1;
     904             :         }
     905             : 
     906             :         /* Adaptive BPF (2 bits)*/
     907       18736 :         n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode];
     908       18736 :         if ( n != 0 )
     909             :         {
     910       14487 :             st->bpf_gain_param = get_next_indice( st, n );
     911             :         }
     912             :         else
     913             :         {
     914        4249 :             st->bpf_gain_param = ( st->acelp_cfg.bpf_mode ) * 2;
     915             :         }
     916             : 
     917             :         /* Mean energy (2 or 3 bits) */
     918       18736 :         n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode];
     919       18736 :         if ( n != 0 )
     920             :         {
     921       18680 :             prm[j++] = get_next_indice( st, n );
     922             :         }
     923             : 
     924             :         /* Subframe parameters */
     925      106240 :         for ( sfr = 0; sfr < nb_subfr; sfr++ )
     926             :         {
     927             :             /* Pitch lag (4, 5, 6, 8 or 9 bits) */
     928       87504 :             n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr];
     929             : 
     930       87504 :             if ( n != 0 )
     931             :             {
     932       86216 :                 prm[j] = get_next_indice( st, n );
     933       86216 :                 j++;
     934             :             }
     935             : 
     936             :             /* Adaptive codebook filtering (1 bit) */
     937       87504 :             if ( st->acelp_cfg.ltf_mode == 2 )
     938             :             {
     939       36125 :                 prm[j] = get_next_indice( st, 1 );
     940       36125 :                 j++;
     941             :             }
     942             : 
     943             :             /* Innovative codebook */
     944             :             {
     945             :                 /* Decode pulse positions. */
     946       87504 :                 j_old = j;
     947             : 
     948       87504 :                 wordcnt = ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ) / 16;
     949       87504 :                 bitcnt = ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ) & 15;
     950             : 
     951             :                 /* sanity check - can happen in case of bit errors */
     952       87504 :                 if ( ( st->acelp_cfg.fixed_cdk_index[sfr] >= ACELP_FIXED_CDK_NB ) || ( st->acelp_cfg.fixed_cdk_index[sfr] < 0 ) )
     953             :                 {
     954           0 :                     st->acelp_cfg.fixed_cdk_index[sfr] = 0;
     955           0 :                     st->BER_detect = 1;
     956             :                 }
     957             : 
     958      296435 :                 for ( ix = 0; ix < wordcnt; ix++ )
     959             :                 {
     960      208931 :                     prm[j] = get_next_indice( st, 16 );
     961      208931 :                     j++;
     962             :                 }
     963             : 
     964       87504 :                 if ( bitcnt )
     965             :                 {
     966       86471 :                     prm[j] = get_next_indice( st, bitcnt );
     967             :                 }
     968       87504 :                 j = j_old + 8;
     969             :             }
     970             : 
     971             :             /* Gains (5b, 6b or 7b / subfr) */
     972       87504 :             n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]];
     973       87504 :             prm[j++] = get_next_indice( st, n );
     974             :         } /*end of subfr loop*/
     975             :     }
     976       33305 :     else if ( st->rf_frame_type >= RF_ALLPRED && st->use_partial_copy )
     977             :     {
     978         172 :         int16_t tmp = BITS_ALLOC_config_acelp( st->rf_target_bits, /* target bits ranges from 56 to 72 depending on rf_type */
     979         172 :                                                st->rf_frame_type,  /* already offset by 4 to parse the config elements for partial copy */
     980             :                                                &( st->acelp_cfg ), /* acelp_cfg_rf*/
     981             :                                                0,                  /* is narrowBand */
     982         172 :                                                st->nb_subfr );
     983         172 :         if ( tmp < 0 )
     984             :         {
     985             :             /* erroneous configuration, resulting from a corrupt bitstream */
     986           0 :             st->BER_detect = 1;
     987             :         }
     988             : 
     989             :         /* rf_frame_type NELP: 7 */
     990         172 :         if ( st->rf_frame_type == RF_NELP )
     991             :         {
     992             :             /* NELP gain indices */
     993           0 :             st->rf_indx_nelp_iG1 = get_next_indice( st, 5 );
     994           0 :             st->rf_indx_nelp_iG2[0] = get_next_indice( st, 6 );
     995           0 :             st->rf_indx_nelp_iG2[1] = get_next_indice( st, 6 );
     996             : 
     997             :             /* NELP filter selection index */
     998           0 :             st->rf_indx_nelp_fid = get_next_indice( st, 2 );
     999             : 
    1000             :             /* tbe gainFr */
    1001           0 :             st->rf_indx_tbeGainFr = get_next_indice( st, 5 );
    1002             :         }
    1003             :         else
    1004             :         {
    1005             :             /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/
    1006             :             /* ES pred */
    1007         172 :             prm[j++] = get_next_indice( st, 3 );
    1008             : 
    1009         172 :             ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type];
    1010         172 :             gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type];
    1011             : 
    1012             :             /* Subframe parameters */
    1013         860 :             for ( sfr = 0; sfr < nb_subfr; sfr++ )
    1014             :             {
    1015             :                 /* Pitch lag (5, or 8 bits) */
    1016         688 :                 n = ACELP_LTP_BITS_SFR[ltp_mode][sfr];
    1017         688 :                 if ( n != 0 )
    1018             :                 {
    1019         688 :                     prm[j++] = get_next_indice( st, n );
    1020             :                 }
    1021             : 
    1022             : 
    1023             :                 /*Innovative codebook*/
    1024         688 :                 if ( ( st->rf_frame_type == RF_NOPRED ) || ( st->rf_frame_type == RF_GENPRED && ( sfr == 0 || sfr == 2 ) ) )
    1025             :                 {
    1026             :                     /* NOTE: FCB actual bits need to be backed up as well */
    1027             :                     /*n = ACELP_FIXED_CDK_BITS(st->rf_indx_fcb[fec_offset][sfr]) & 15;*/
    1028          96 :                     prm[j] = get_next_indice( st, 7 );
    1029          96 :                     j = j + 8;
    1030             :                 }
    1031             : 
    1032             :                 /* Gains (5b, 6b or 7b / subfr) */
    1033         688 :                 if ( sfr == 0 || sfr == 2 )
    1034             :                 {
    1035         344 :                     n = ACELP_GAINS_BITS[gains_mode];
    1036         344 :                     prm[j++] = get_next_indice( st, n );
    1037             :                 }
    1038             :             }
    1039         172 :             st->rf_indx_tbeGainFr = get_next_indice( st, 2 );
    1040             :         }
    1041             :     }
    1042             : 
    1043             :     /*--------------------------------------------------------------------------------*
    1044             :      * TCX20/10 parameters
    1045             :      *--------------------------------------------------------------------------------*/
    1046             : 
    1047       52041 :     if ( ( core == TCX_20_CORE || core == TCX_10_CORE ) && st->use_partial_copy == 0 )
    1048             :     {
    1049       33121 :         getTCXparam( st, st, hm_cfg, param, bits_common, start_bit_pos, NULL, NULL, NULL, -1 );
    1050             :     }
    1051             : 
    1052       52041 :     if ( st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 && st->use_partial_copy == 1 )
    1053             :     {
    1054             :         /* classification */
    1055          12 :         ind = get_next_indice( st, 2 );
    1056          12 :         st->clas_dec = ONSET;
    1057          12 :         if ( ind == 0 )
    1058             :         {
    1059           0 :             st->clas_dec = UNVOICED_CLAS;
    1060             :         }
    1061          12 :         else if ( ind == 1 )
    1062             :         {
    1063           0 :             if ( st->last_good >= VOICED_TRANSITION )
    1064             :             {
    1065           0 :                 st->clas_dec = VOICED_TRANSITION;
    1066             :             }
    1067             :             else
    1068             :             {
    1069           0 :                 st->clas_dec = UNVOICED_TRANSITION;
    1070             :             }
    1071             :         }
    1072          12 :         else if ( ind == 2 )
    1073             :         {
    1074          12 :             st->clas_dec = VOICED_CLAS;
    1075             :         }
    1076             : 
    1077          12 :         if ( st->rf_frame_type == RF_TCXFD )
    1078             :         {
    1079             :             /* TCX Gain */
    1080           0 :             hTcxDec->old_gaintcx_bfi = get_next_indice( st, NBITS_TCX_GAIN );
    1081             :         }
    1082             :         else
    1083             :         {
    1084             :             /* LTP data */
    1085          12 :             if ( hTcxLtpDec->tcxltp )
    1086             :             {
    1087          12 :                 if ( st->rf_frame_type == RF_TCXTD2 || st->rf_frame_type == RF_TCXTD1 )
    1088             :                 {
    1089          12 :                     prm_ltp[0] = 1; /* LTP active*/
    1090          12 :                     prm_ltp[1] = get_next_indice( st, 9 );
    1091          12 :                     prm_ltp[2] = 3; /* max ampl. quantizer output (2bits), anyway not used later*/
    1092             : 
    1093          12 :                     if ( !st->prev_bfi )
    1094             :                     {
    1095          24 :                         st->BER_detect = st->BER_detect |
    1096          12 :                                          tcx_ltp_decode_params( &prm_ltp[0], &( 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 );
    1097             : 
    1098          12 :                         hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain;
    1099             :                     }
    1100             :                 }
    1101             :             }
    1102             :         }
    1103             :     }
    1104             : 
    1105       52041 :     if ( !st->use_partial_copy )
    1106             :     {
    1107       51857 :         if ( *total_nbbits - bitsRead[0] < ( st->next_bit_pos - start_bit_pos ) )
    1108             :         {
    1109           0 :             st->BER_detect = 1;
    1110           0 :             st->next_bit_pos = start_bit_pos + *total_nbbits - bitsRead[0];
    1111             :         }
    1112       51857 :         bitsRead[0] = st->next_bit_pos - start_bit_pos;
    1113             :     }
    1114       52041 :     return;
    1115             : }

Generated by: LCOV version 1.14