LCOV - code coverage report
Current view: top level - lib_dec - core_dec_init_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 1090 1243 87.7 %
Date: 2025-05-17 01:59:02 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <assert.h>
       6             : #include <stdint.h>
       7             : #include <stdio.h>
       8             : #include <string.h>
       9             : #include "options.h"
      10             : #include "prot_fx.h"
      11             : #include "basop_util.h"
      12             : #include "rom_com.h"
      13             : #include "cnst.h" /* for MIN_CNG_LEV */
      14             : 
      15             : /*-----------------------------------------------------------------------*
      16             :  * open_decoder_LPD_fx()
      17             :  *
      18             :  * Initialization of state variables
      19             :  *-----------------------------------------------------------------------*/
      20          35 : void open_decoder_LPD_fx(
      21             :     Decoder_State *st,
      22             :     const Word32 total_brate, /* Q0 */
      23             :     const Word16 bwidth       /* Q0 */
      24             : )
      25             : {
      26             :     Word16 i;
      27             :     Word16 mem_syn_r_size_new;
      28             :     Word16 mem_syn_r_size_old;
      29             :     Word16 fscaleFB;
      30             :     BPF_DEC_HANDLE hBPF;
      31             :     TD_BWE_DEC_HANDLE hBWE_TD;
      32             :     TCX_LTP_DEC_HANDLE hTcxLtpDec;
      33             :     HQ_DEC_HANDLE hHQ_core;
      34             :     TCX_DEC_HANDLE hTcxDec;
      35             : 
      36          35 :     hBPF = st->hBPF;
      37          35 :     hBWE_TD = st->hBWE_TD;
      38          35 :     hHQ_core = st->hHQ_core;
      39          35 :     hTcxLtpDec = st->hTcxLtpDec;
      40          35 :     hTcxDec = st->hTcxDec;
      41             : 
      42          35 :     st->total_brate = total_brate;
      43          35 :     move32();
      44             : 
      45          35 :     if ( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/
      46             :     {
      47          32 :         st->fscale_old = st->fscale;
      48          32 :         move16();
      49             :     }
      50          35 :     st->sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format );
      51          35 :     move32();
      52             : 
      53          35 :     st->fscale = sr2fscale_fx( st->sr_core );
      54          35 :     move16();
      55          35 :     fscaleFB = sr2fscale_fx( st->output_Fs );
      56             : 
      57             :     /* initializing variables for frame lengths etc. right in the beginning */
      58          35 :     st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) );
      59          35 :     move16();
      60          35 :     hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) );
      61          35 :     move16();
      62          35 :     IF( st->ini_frame == 0 )
      63             :     {
      64           4 :         st->last_L_frame = st->L_frame_past = st->L_frame;
      65           4 :         move16();
      66           4 :         move16();
      67           4 :         st->L_frameTCX_past = hTcxDec->L_frameTCX;
      68           4 :         move16();
      69             :     }
      70          35 :     st->tcxonly = getTcxonly(
      71             :         st->total_brate
      72             :         /*, st->is_ism_format Needed in the last version of float IVAS */
      73             :     );
      74          35 :     move16();
      75             : 
      76             :     /* the TD TCX PLC in MODE1 still runs with 80ms subframes */
      77          35 :     st->nb_subfr = NB_SUBFR;
      78          35 :     move16();
      79          35 :     test();
      80          35 :     test();
      81          35 :     test();
      82          35 :     test();
      83          35 :     test();
      84          35 :     test();
      85          35 :     test();
      86          35 :     test();
      87             : 
      88          35 :     IF( ( st->element_mode == EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) ||
      89             :         ( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) ||
      90             :         ( ( st->tcxonly != 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) )
      91             :     {
      92          12 :         st->nb_subfr = NB_SUBFR16k;
      93          12 :         move16();
      94             :     }
      95             : 
      96             :     /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate */
      97          35 :     st->bits_frame = extract_l( L_shr( Mpy_32_16_1( L_shl( st->total_brate, 1 ), 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */
      98          35 :     move16();
      99             : 
     100             :     assert( FSCALE_DENOM == 512 );
     101          35 :     assert( st->fscale == 2 * st->L_frame ); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */
     102          35 :     assert( st->bits_frame == (int) ( (float) st->L_frame / (float) st->fscale * (float) FSCALE_DENOM / 128.0f * (float) st->total_brate / 100.0f + 0.49f ) );
     103             : 
     104          35 :     st->TcxBandwidth = getTcxBandwidth( bwidth );
     105          35 :     move16();
     106          35 :     st->narrowBand = 0;
     107          35 :     move16();
     108          35 :     if ( EQ_16( bwidth, NB ) )
     109             :     {
     110           3 :         st->narrowBand = 1;
     111           3 :         move16();
     112             :     }
     113             : 
     114          35 :     IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
     115             :     {
     116           0 :         st->pit_res_max = initPitchLagParameters( INT_FS_12k8, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
     117           0 :         move16();
     118           0 :         IF( hTcxDec != NULL )
     119             :         {
     120             :             // st->pit_res_max = initPitchLagParameters(12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max);
     121             :             // hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / 12800);
     122             :             // hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / 12800);
     123           0 :             i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( L_FRAME ) );             /* Q6 */
     124           0 :             hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */
     125           0 :             move16();
     126           0 :             hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */
     127           0 :             move16();
     128             :         }
     129             :     }
     130             :     ELSE
     131             :     {
     132          35 :         st->pit_res_max = initPitchLagParameters( st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
     133          35 :         move16();
     134          35 :         IF( hTcxDec != NULL )
     135             :         {
     136          35 :             i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) );         /* Q6 */
     137          35 :             hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */
     138          35 :             move16();
     139          35 :             hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */
     140          35 :             move16();
     141             :         }
     142             :     }
     143          35 :     if ( !st->ini_frame )
     144             :     {
     145           4 :         st->pit_res_max_past = st->pit_res_max;
     146           4 :         move16();
     147             :     }
     148             : 
     149             :     /*Preemphasis param*/
     150          35 :     st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/
     151          35 :     move16();
     152          35 :     IF( LT_16( st->fscale, 640 ) ) /*( 16000 * FSCALE_DENOM ) / INT_FS_12k8 )*/
     153             :     {
     154          23 :         st->preemph_fac = PREEMPH_FAC; /*WB*/
     155          23 :         move16();
     156             :     }
     157          12 :     ELSE IF( LT_16( st->fscale, 960 ) ) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) */
     158             :     {
     159          12 :         st->preemph_fac = PREEMPH_FAC_16k; /*WB*/
     160          12 :         move16();
     161             :     }
     162             : 
     163          35 :     st->gamma = GAMMA1;
     164          35 :     move16();
     165          35 :     st->inv_gamma = GAMMA1_INV;
     166          35 :     move16();
     167          35 :     test();
     168          35 :     test();
     169          35 :     IF( EQ_32( st->sr_core, INT_FS_16k ) ||
     170             :         ( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) )
     171             :     {
     172          12 :         st->gamma = GAMMA16k;
     173          12 :         move16();
     174          12 :         st->inv_gamma = GAMMA16k_INV;
     175          12 :         move16();
     176             :     }
     177             : 
     178             :     /* LPC quantization */
     179          35 :     st->lpcQuantization = 0;
     180          35 :     move16();
     181          35 :     test();
     182          35 :     if ( ( st->tcxonly == 0 ) && LE_32( st->sr_core, INT_FS_16k ) )
     183             :     {
     184          35 :         st->lpcQuantization = 1;
     185          35 :         move16();
     186             :     }
     187             : 
     188          35 :     st->numlpc = 2;
     189          35 :     move16();
     190          35 :     if ( st->tcxonly == 0 )
     191             :     {
     192          35 :         st->numlpc = 1;
     193          35 :         move16();
     194             :     }
     195             : 
     196             :     /* Initialize TBE */
     197          35 :     st->prev_coder_type = GENERIC;
     198          35 :     move16();
     199          35 :     IF( st->hBWE_TD != NULL )
     200             :     {
     201          35 :         set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); /* Q15 */
     202          35 :         hBWE_TD->prev_tilt_para_fx = 0;
     203          35 :         move16();
     204          35 :         set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); /* Q12 */
     205             :     }
     206             : 
     207             :     /*TCX config*/
     208          35 :     st->hTcxCfg->preemph_fac = st->preemph_fac;
     209          35 :     move16();
     210          35 :     st->hTcxCfg->tcx_mdct_window_length_old = st->hTcxCfg->tcx_mdct_window_length;
     211          35 :     move16();
     212          35 :     init_TCX_config( st->hTcxCfg, st->L_frame, st->fscale, hTcxDec->L_frameTCX, fscaleFB ); // TEMPORARY  should be rename to  init_TCX_config
     213          35 :     IF( st->ini_frame == 0 )
     214             :     {
     215           4 :         st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
     216           4 :         move16();
     217           4 :         move16();
     218             :     }
     219             : 
     220             :     /* TCX Offset */
     221          35 :     st->hTcxCfg->tcx_offset = shr( st->hTcxCfg->tcx_mdct_window_delay, 1 ); /* Q0 */
     222          35 :     move16();
     223          35 :     st->hTcxCfg->tcx_offsetFB = shr( st->hTcxCfg->tcx_mdct_window_delayFB, 1 ); /* Q0 */
     224          35 :     move16();
     225             : 
     226             :     /* Initialize FAC */
     227          35 :     st->hTcxCfg->lfacNext = sub( st->hTcxCfg->tcx_offset, shr( st->L_frame, 2 ) ); /* Q0 */
     228          35 :     move16();
     229          35 :     st->hTcxCfg->lfacNextFB = sub( st->hTcxCfg->tcx_offsetFB, shr( hTcxDec->L_frameTCX, 2 ) ); /* Q0 */
     230          35 :     move16();
     231             : 
     232             :     /* set number of coded lines */
     233          35 :     st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( st->bwidth );
     234          35 :     move16();
     235             : 
     236             :     /* TNS in TCX */
     237          35 :     st->hTcxCfg->pCurrentTnsConfig = NULL;
     238          35 :     st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf, st->element_mode );
     239          35 :     move16();
     240             : 
     241          35 :     IF( st->hTcxCfg->fIsTNSAllowed != 0 )
     242             :     {
     243          12 :         InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ );
     244             :     }
     245             :     /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/
     246          35 :     if ( st->tcxonly == 0 )
     247             :     {
     248          35 :         assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) );
     249             :     }
     250             : 
     251             :     IF( 1 ) // st->element_mode == EVS_MONO)
     252             :     {
     253          35 :         IF( st->hTECDec == NULL )
     254             :         {
     255           3 :             IF( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL )
     256             :             {
     257             :                 // return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n"));
     258           0 :                 assert( 0 );
     259             :             }
     260             :         }
     261             :     }
     262             :     ELSE
     263             :     {
     264             :         st->hTECDec = NULL;
     265             :     }
     266          35 :     resetTecDec_Fx( st->hTECDec );
     267             : 
     268             :     /* Initialize decoder delay */
     269             : 
     270             : 
     271          35 :     if ( NE_16( st->element_mode, IVAS_SCE ) )
     272             :     {
     273          35 :         st->flag_cna = 0;
     274          35 :         move16();
     275             :     }
     276          35 :     IF( st->ini_frame == 0 )
     277             :     {
     278           4 :         st->flag_cna = 0;
     279           4 :         st->last_flag_cna = 0;
     280           4 :         move16();
     281           4 :         move16();
     282             :     }
     283             : 
     284             :     /* Static vectors to zero */
     285          35 :     IF( st->ini_frame == 0 )
     286             :     {
     287             : 
     288           4 :         st->last_is_cng = 0;
     289           4 :         move16();
     290             : 
     291           4 :         st->rate_switching_reset = 0;
     292           4 :         move16();
     293           4 :         IF( hTcxDec != NULL )
     294             :         {
     295           4 :             set16_fx( hTcxDec->old_syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /* hTcxDec->Q_syn_Overl_TDACFB */
     296             : 
     297           4 :             set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr( L_FRAME32k, 1 ) );    /* hTcxDec->Q_syn_Overl_TDAC */
     298           4 :             set16_fx( hTcxDec->syn_OverlFB, 0, shr( L_FRAME_MAX, 1 ) );      /* hTcxDec-> Q_syn_OverlFB */
     299           4 :             set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr( L_FRAME_MAX, 1 ) ); /* hTcxDec->Q_syn_Overl_TDACFB */
     300             : 
     301           4 :             set16_fx( hTcxDec->syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /* hTcxDec->Q_syn_Overl */
     302             : 
     303           4 :             set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */
     304           4 :             hTcxDec->q_old_synth = 0;
     305           4 :             move16();
     306           4 :             set16_fx( hTcxDec->synth_history_fx, 0, add( L_PROT48k, L_FRAME_MAX ) ); /* hTcxDec->q_synth_history_fx */
     307           4 :             hTcxDec->q_synth_history_fx = 0;
     308           4 :             move16();
     309             :         }
     310           4 :         set16_fx( st->syn, 0, add( M, 1 ) ); /* Qx */
     311             : 
     312           4 :         set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); /* Qx */
     313             : 
     314           4 :         mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */
     315           4 :         move16();
     316           4 :         mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */
     317           4 :         move16();
     318             : 
     319           4 :         st->con_tcx = 0; /* Q0 */
     320           4 :         move16();
     321             :     }
     322             :     ELSE
     323             :     {
     324             :         /* Reset old_synth in case of core sampling rate switching and codec switching*/
     325          31 :         test();
     326          31 :         test();
     327          31 :         IF( st->hTcxDec != NULL && ( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_codec_mode, MODE1 ) ) ) )
     328             :         {
     329          31 :             set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */
     330          31 :             hTcxDec->q_old_synth = 0;
     331          31 :             move16();
     332             :         }
     333             : 
     334             :         /*Size of LPC syn memory*/
     335             :         /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */
     336          31 :         mem_syn_r_size_old = shr( st->last_L_frame, 4 ); /* Q0 */
     337          31 :         mem_syn_r_size_new = shr( st->L_frame, 4 );      /* Q0 */
     338             : 
     339             :         /*Reset LPC mem*/
     340          31 :         test();
     341          31 :         test();
     342          31 :         IF( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || EQ_16( st->last_core, HQ_CORE ) )
     343             :         {
     344             :             /*LPC quant. mem*/
     345          18 :             set16_fx( st->mem_MA_fx, 0, M ); /* (Qx2.56) */
     346          18 :             IF( EQ_32( st->sr_core, INT_FS_16k ) )
     347             :             {
     348          11 :                 Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /* (Qx2.56) */
     349             :             }
     350             :             ELSE
     351             :             {
     352           7 :                 Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /* (Qx2.56) */
     353             :             }
     354             :         }
     355             : 
     356             :         /*Codec switching*/
     357          31 :         test();
     358          31 :         IF( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO )
     359             :         {
     360          31 :             Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15      */
     361          31 :             Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
     362          31 :             set16_fx( st->syn, 0, M );                /* Q_syn */
     363             :         }
     364          31 :         IF( EQ_16( st->last_core, AMR_WB_CORE ) )
     365             :         {
     366           0 :             st->last_core = ACELP_CORE;
     367           0 :             move16();
     368           0 :             st->last_core_bfi = ACELP_CORE;
     369           0 :             move16();
     370             :         }
     371             : 
     372             :         /*Codec switching from ACELP-A */
     373          31 :         test();
     374          31 :         test();
     375          31 :         test();
     376          31 :         test();
     377          31 :         IF( ( NE_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->prev_bfi ) ) && EQ_16( st->last_codec_mode, MODE1 ) && ( st->last_core == ACELP_CORE ) )
     378             :         {
     379          13 :             st->last_core_bfi = ACELP_CORE;
     380          13 :             move16();
     381             : 
     382             :             /*PLC*/
     383          13 :             IF( st->prev_bfi != 0 )
     384             :             {
     385             :                 PWord16 const *w;
     386             :                 Word16 W1, W2, nz, delay_comp;
     387             : 
     388           0 :                 W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; /* Q0 */
     389           0 :                 move16();
     390           0 :                 W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 );
     391           0 :                 w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/
     392             : 
     393           0 :                 nz = NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS );
     394           0 :                 move16();
     395           0 :                 delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/
     396           0 :                 move16();
     397             : 
     398           0 :                 Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* hHQ_core->Q_fer_samples*/
     399             : 
     400           0 :                 lerp( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( hTcxDec->L_frameTCX, 1 ) ); /*Q0: ACELP(bfi)->TCX(rect)*/
     401             : 
     402             :                 /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/
     403           0 :                 hHQ_core->Q_old_wtda = -1;
     404           0 :                 move16();
     405           0 :                 set16_fx( hHQ_core->old_out_fx, 0, nz );                                                                      /* exp(exp_old_out) */
     406           0 :                 Copy_Scale_sig( hHQ_core->fer_samples_fx + delay_comp, hHQ_core->old_out_fx + nz, W1, hHQ_core->Q_old_wtda ); /*Q-1*/
     407             : 
     408           0 :                 FOR( i = 0; i < W2; i++ )
     409             :                 {
     410           0 :                     hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[i + nz] ) ); /* exp(exp_old_out) */
     411           0 :                     move16();
     412             :                 }
     413           0 :                 FOR( ; i < W1; i++ )
     414             :                 {
     415           0 :                     hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - ( 1 + ( i - W2 ) )].v.im, w[W2 - ( 1 + ( i - W2 ) )].v.im ), hHQ_core->old_out_fx[i + nz] ) ); /* exp(exp_old_out) */
     416           0 :                     move16();
     417             :                 }
     418           0 :                 set16_fx( &hHQ_core->old_out_fx[W1 + nz], 0, nz );
     419             : 
     420           0 :                 lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX );
     421             : 
     422           0 :                 Copy( hHQ_core->old_out_fx + nz, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* exp(exp_old_out) */
     423           0 :                 hTcxDec->Q_syn_Overl_TDACFB = hHQ_core->Q_old_wtda;
     424           0 :                 move16();
     425           0 :                 nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS );
     426           0 :                 move16();
     427           0 :                 Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); /* hHQ_core->q_old_outLB_fx */
     428           0 :                 hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda;
     429           0 :                 move16();
     430           0 :                 hTcxDec->Q_syn_Overl_TDAC = hHQ_core->Q_old_wtda_LB;
     431           0 :                 move16();
     432             :             }
     433             :         }
     434             : 
     435          31 :         test();
     436          31 :         test();
     437          31 :         test();
     438          31 :         test();
     439          31 :         test();
     440          31 :         test();
     441          31 :         IF( EQ_16( st->last_codec_mode, MODE2 ) &&
     442             :             NE_16( st->L_frame, st->last_L_frame ) &&
     443             :             ( ( EQ_16( st->m_frame_type, SID_FRAME ) && ( st->last_core > ACELP_CORE ) ) ||
     444             :               ( ( st->last_core > ACELP_CORE ) && ( st->core > ACELP_CORE ) ) ||
     445             :               st->prev_bfi ) )
     446             :         {
     447           0 :             lerp( hHQ_core->old_out_LB_fx, hHQ_core->old_out_LB_fx, st->L_frame, st->last_L_frame );
     448             :         }
     449             : 
     450             :         /* Rate switching */
     451          31 :         test();
     452          31 :         test();
     453          31 :         test();
     454          31 :         test();
     455          31 :         test();
     456          31 :         IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) )
     457             :         {
     458             :             /*Codec switching from MDCT */
     459             : 
     460             :             /*Reset of ACELP memories*/
     461          18 :             st->rate_switching_reset = 1;
     462          18 :             st->tilt_code_fx = TILT_CODE;
     463          18 :             move16();
     464          18 :             move16();
     465          18 :             set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */
     466          18 :             set16_fx( st->syn, 0, 1 + M );                /* Q_syn */
     467          18 :             set16_fx( st->mem_syn2_fx, 0, M );            /* Q_syn */
     468             : 
     469             :             /*OLA -> zero */
     470          18 :             IF( st->hTcxDec != NULL )
     471             :             {
     472          18 :                 set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/     /* Q_old_syn_Overl */
     473          18 :                 set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/    /* Q_syn_Overl_TDAC */
     474          18 :                 set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_syn_Overl_TDACFB */
     475          18 :                 set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/         /* Q_syn_Overl */
     476             :             }
     477          18 :             IF( st->hTcxCfg != NULL )
     478             :             {
     479          18 :                 Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); /* exp(exp_old_out) */
     480             : 
     481          18 :                 st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ /* Q0 */
     482          18 :                 st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
     483          18 :                 move16();
     484          18 :                 move16();
     485             :             }
     486             :             /*OLA for MDCT-LB always reset in codec switching cases*/
     487          18 :             IF( st->hHQ_core != NULL )
     488             :             {
     489          18 :                 set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); /* hHQ_core->q_old_outLB_fx */
     490             :             }
     491          18 :             st->last_core_bfi = TCX_20_CORE;
     492          18 :             move16();
     493             : 
     494          18 :             if ( st->hPFstat != NULL )
     495             :             {
     496          18 :                 st->hPFstat->on = 0;
     497          18 :                 move16();
     498             :             }
     499             :             /* reset CLDFB memories */
     500          18 :             cldfb_reset_memory( st->cldfbAna );
     501          18 :             cldfb_reset_memory( st->cldfbBPF );
     502          18 :             cldfb_reset_memory( st->cldfbSyn );
     503             :         }
     504          13 :         ELSE IF( ( NE_16( st->L_frame, st->last_L_frame ) ) && ( LE_16( st->L_frame, L_FRAME16k ) ) && ( LE_16( st->last_L_frame, L_FRAME16k ) ) ) /* Rate switching between 12.8 and 16 kHz*/
     505             :         {
     506             :             /*Interpolation of ACELP memories*/
     507             : 
     508             :             /* convert quantized LSP vector */
     509           0 :             st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
     510           0 :             move16();
     511           0 :             IF( st->tcxonly == 0 )
     512             :             {
     513           0 :                 lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
     514             :             }
     515             :             ELSE
     516             :             {
     517           0 :                 E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
     518             :             }
     519           0 :             E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M );
     520             : 
     521             : 
     522           0 :             Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
     523           0 :             Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.5 */
     524             : 
     525           0 :             IF( !st->last_con_tcx )
     526             :             {
     527           0 :                 synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC );
     528             :             }
     529             : 
     530             :             /*mem of deemphasis stayed unchanged.*/
     531             :         }
     532          13 :         ELSE IF( NE_16( st->L_frame, st->last_L_frame ) ) /* Rate switching involving TCX only modes */
     533             :         {
     534             :             /*Partial reset of ACELP memories*/
     535           0 :             st->rate_switching_reset = 1;
     536           0 :             move16();
     537             : 
     538             :             /*reset partly some memories*/
     539           0 :             st->tilt_code_fx = TILT_CODE;
     540           0 :             move16();
     541           0 :             IF( !st->last_con_tcx )
     542             :             {
     543           0 :                 set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */
     544             :             }
     545           0 :             set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); /* Q12 */
     546             : 
     547             :             /*Resamp others memories*/
     548             :             /*Size of LPC syn memory*/
     549           0 :             lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); /* Q_mem_syn_r */
     550           0 :             Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M );                                                                                                  /* Q_mem_syn_r */
     551             : 
     552             :             /*Untouched memories : st->syn */
     553             :         }
     554          13 :         ELSE IF( !st->tcxonly && EQ_16( st->L_frame, L_FRAME16k ) && GT_32( st->last_total_brate, ACELP_32k ) )
     555             :         {
     556           0 :             lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
     557             :         }
     558             :     }
     559             : 
     560          35 :     test();
     561          35 :     test();
     562          35 :     IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 )
     563             :     {
     564           0 :         st->rate_switching_reset = 1;
     565           0 :         move16();
     566             :     }
     567          35 :     IF( st->hTcxDec != NULL )
     568             :     {
     569          35 :         hTcxDec->old_synth_len = shl( st->L_frame, 1 ); /* Q0 */
     570          35 :         move16();
     571          35 :         hTcxDec->old_synth_lenFB = shl( hTcxDec->L_frameTCX, 1 ); /* Q0 */
     572          35 :         move16();
     573             :     }
     574             :     /* bass pf reset */
     575          35 :     st->bpf_gain_param = 0;
     576          35 :     move16();
     577          35 :     IF( st->hBPF != NULL )
     578             :     {
     579          35 :         set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX );
     580             :     }
     581             :     /* Formant postfilter */
     582          35 :     IF( st->ini_frame == 0 )
     583             :     {
     584             :         /*do nothing*/
     585             :     }
     586          31 :     ELSE IF( EQ_16( st->last_codec_mode, MODE2 ) )
     587             :     {
     588           0 :         IF( st->tcxonly == 0 )
     589             :         {
     590           0 :             IF( st->hPFstat->on != 0 )
     591             :             {
     592           0 :                 lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
     593           0 :                 lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
     594             :             }
     595             :             ELSE
     596             :             {
     597           0 :                 set16_fx( st->hPFstat->mem_stp, 0, L_SYN_MEM );
     598           0 :                 set16_fx( st->hPFstat->mem_pf_in, 0, L_SYN_MEM );
     599           0 :                 st->hPFstat->reset = 1;
     600           0 :                 move16();
     601           0 :                 st->hPFstat->gain_prec = 16384; /* Q14 */
     602           0 :                 move16();
     603             :             }
     604             :         }
     605           0 :         ELSE IF( st->hPFstat->on != 0 )
     606             :         {
     607           0 :             lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
     608           0 :             lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
     609             :         }
     610             :     }
     611             :     ELSE
     612             :     {
     613             :         /*codec switching*/
     614             :         /*reset post-filter except for Narrowband*/
     615          31 :         IF( NE_32( st->output_Fs, 8000 ) )
     616             :         {
     617          31 :             IF( st->hPFstat != NULL )
     618             :             {
     619          31 :                 st->hPFstat->reset = 1;
     620          31 :                 move16();
     621          31 :                 IF( st->hPFstat->on != 0 )
     622             :                 {
     623           0 :                     st->hPFstat->reset = 0;
     624           0 :                     move16();
     625           0 :                     Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ /* q_mem - st->Q_syn */
     626           0 :                     Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */   /* q_mem - st->Q_syn */
     627           0 :                     lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
     628           0 :                     lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
     629             :                 }
     630             :             }
     631             :         }
     632             :         ELSE
     633             :         {
     634           0 :             IF( st->hPFstat != NULL )
     635             :             {
     636           0 :                 Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */    /* q_mem - st->Q_syn */
     637           0 :                 Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, negate( st->Q_syn ) ); /* NB post_filter mem */ /* q_mem - st->Q_syn */
     638           0 :                 Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */      /* q_mem - st->Q_syn */
     639             :             }
     640             :             /*feed last value old_synth as it is used for pre-emphasis mem*/
     641           0 :             if ( st->hTcxDec != NULL )
     642             :             {
     643           0 :                 hTcxDec->old_synth[hTcxDec->old_synth_len - 1] = st->syn[M]; /* Q_syn */
     644           0 :                 move16();
     645             :             }
     646           0 :             if ( st->hBPF != NULL )
     647             :             {
     648           0 :                 hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; /* Q_syn */
     649           0 :                 move16();
     650             :             }
     651             :         }
     652             :     }
     653             : 
     654             :     /* lsf and lsp initialization */
     655          35 :     IF( st->ini_frame == 0 )
     656             :     {
     657           4 :         Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
     658           4 :         Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
     659             : 
     660           4 :         set16_fx( st->lsf_cng, 0, M );
     661             :     }
     662             : 
     663          35 :     st->seed_tcx_plc = RANDOM_INITSEED;
     664          35 :     move16();
     665          35 :     st->past_gpit = 0;
     666          35 :     move16();
     667          35 :     st->past_gcode = L_deposit_l( 0 );
     668          35 :     move32();
     669          35 :     st->gc_threshold_fx = L_deposit_l( 0 );
     670          35 :     move32();
     671             : 
     672          35 :     E_LPC_lsf_lsp_conversion( st->lsf_cng, st->lspold_cng, M );
     673          35 :     E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M );
     674          35 :     st->plcBackgroundNoiseUpdated = 0;
     675          35 :     move16();
     676          35 :     Copy( st->lsf_old_fx, st->lsf_q_cng, M );     /* Q2.56 */
     677          35 :     Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); /* Q2.56 */
     678          35 :     Copy( st->lsp_old_fx, st->lsp_q_cng, M );     /* Q15 */
     679          35 :     Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); /* Q15 */
     680          35 :     set16_fx( st->mem_syn_unv_back, 0, M );
     681             : 
     682          35 :     st->last_gain_syn_deemph = 32768 / 2; /* Q15 */
     683          35 :     move16();
     684          35 :     st->last_gain_syn_deemph_e = 1;
     685          35 :     move16();
     686          35 :     test();
     687          35 :     IF( EQ_16( st->last_codec_mode, MODE1 ) || st->ini_frame == 0 )
     688             :     {
     689             :         /* this assumes that MODE1 fades out in the frequency domain -
     690             :         otherwise some data from MODE1 would be needed here */
     691          35 :         st->last_concealed_gain_syn_deemph = 32768 / 2; /* Q15 */
     692          35 :         move16();
     693          35 :         st->last_concealed_gain_syn_deemph_e = 1;
     694          35 :         move16();
     695          35 :         if ( hTcxDec != NULL )
     696             :         {
     697          35 :             hTcxDec->conceal_eof_gain = 32768 / 2; /*Q14*/
     698          35 :             move16();
     699             :         }
     700             :     }
     701             : 
     702             :     /* Post processing */
     703          35 :     set16_fx( st->mem_Aq, 0, i_mult( NB_SUBFR16k, ( M + 1 ) ) );
     704          35 :     st->lp_ener_FER_fx = 15360;
     705          35 :     move16(); /*60 in Q8*/
     706          35 :     IF( st->ini_frame == 0 )
     707             :     {
     708           4 :         st->prev_bfi = 0;
     709           4 :         move16();
     710           4 :         st->last_core_bfi = -1;
     711           4 :         move16();
     712             :     }
     713          35 :     st->prev_old_bfi = 0;
     714          35 :     move16();
     715             : 
     716             :     /*st->noise_filling_index = 0;*/ /* not in BASOP */
     717             : 
     718          35 :     Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /* Q2.56 */
     719          35 :     Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M );        /* Q2.56 */
     720          35 :     Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M );        /* Q2.56 */
     721             : 
     722          35 :     st->clas_dec = UNVOICED_CLAS;
     723          35 :     move16();
     724          35 :     if ( !st->last_con_tcx )
     725             :     {
     726          35 :         move16();
     727          35 :         st->old_enr_LP = 0; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */
     728             :     }
     729             : 
     730          35 :     IF( st->prev_bfi )
     731             :     {
     732             :         /* calculate energy at the end of the previous frame */
     733           0 :         test();
     734           0 :         IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, HQ_CORE ) )
     735             :         {
     736           0 :             frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 );
     737             :         }
     738             :     }
     739             :     ELSE
     740             :     {
     741          35 :         st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */
     742          35 :         move16();
     743          35 :         st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame  */ /* Q0 */
     744          35 :         move32();
     745             :     }
     746          35 :     st->Mode2_lp_gainc = L_deposit_l( 0 ); /* 15Q16 */
     747          35 :     move32();
     748          35 :     st->Mode2_lp_gainp = L_deposit_l( 0 ); /* 15Q16 */
     749          35 :     move32();
     750             : 
     751          35 :     st->hTcxDec->prev_widow_left_rect = 0;
     752          35 :     move16();
     753          35 :     if ( st->hTcxDec != NULL )
     754             :     {
     755          35 :         hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/
     756          35 :         move16();
     757          35 :         hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; /* Q0 */
     758          35 :         move16();
     759          35 :         hTcxDec->conCurrLevelIndex = 0; /* Q0 */
     760          35 :         move16();
     761          35 :         hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/
     762          35 :         move16();
     763          35 :         set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/
     764          35 :         set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE );
     765          35 :         hTcxDec->conLastFrameLevel_e = 0; /* Q15 */
     766          35 :         move16();
     767          35 :         hTcxDec->conCngLevelBackgroundTrace_e = -6;
     768          35 :         move16();
     769             : 
     770          35 :         hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/;
     771          35 :         move16();
     772             :     }
     773          35 :     st->cummulative_damping = 32767 /*1.0f Q15*/;
     774          35 :     move16();
     775             : 
     776         455 :     FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
     777             :     {
     778         420 :         st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min );
     779         420 :         move16();
     780             :     }
     781             : 
     782         455 :     FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
     783             :     {
     784         420 :         st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/
     785         420 :         move16();
     786             :     }
     787             : 
     788             : 
     789          35 :     st->old_fpitch = L_deposit_h( st->pit_min );
     790          35 :     move32();
     791          35 :     st->old_fpitchFB = L_deposit_h( hTcxDec->pit_min_TCX );
     792          35 :     move32();
     793          35 :     st->rate_switching_init = 1;
     794          35 :     move16();
     795             : 
     796          35 :     st->reset_mem_AR = 0;
     797          35 :     move16();
     798             : 
     799             :     /* For phase dispersion */
     800          35 :     st->dm_fx.prev_gain_code = L_deposit_l( 0 );
     801          35 :     move32();
     802          35 :     set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
     803          35 :     st->dm_fx.prev_state = 0;
     804          35 :     move16();
     805             : 
     806          35 :     st->voice_fac = -1; /* purely unvoiced  */
     807          35 :     move16();
     808             : 
     809             :     /* TCX-LTP */
     810          35 :     if ( hTcxLtpDec != NULL )
     811             :     {
     812          35 :         hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core );
     813          35 :         move16();
     814             :     }
     815          35 :     move16();
     816             : 
     817          35 :     test();
     818          35 :     test();
     819          35 :     test();
     820          35 :     IF( hTcxLtpDec != NULL && ( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) ) )
     821             :     {
     822          35 :         hTcxLtpDec->tcxltp_pitch_int = st->pit_max; /* Q0 */
     823          35 :         move16();
     824          35 :         hTcxLtpDec->tcxltp_pitch_fr = 0; /* Q0 */
     825          35 :         move16();
     826          35 :         if ( hTcxDec != NULL )
     827             :         {
     828          35 :             hTcxDec->tcxltp_last_gain_unmodified = 0; /* Q15 */
     829          35 :             move16();
     830             :         }
     831          35 :         IF( st->ini_frame == 0 )
     832             :         {
     833           4 :             set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); /* hTcxLtpDec->exp_tcxltp_mem_out */
     834           4 :             set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k );      /* hTcxLtpDec->exp_tcxltp_mem_out */
     835           4 :             hTcxLtpDec->tcxltp_pitch_int_post_prev = 0;
     836           4 :             move16();
     837           4 :             hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0;
     838           4 :             move16();
     839           4 :             hTcxLtpDec->tcxltp_gain_post_prev = 0;
     840           4 :             move16();
     841           4 :             hTcxLtpDec->tcxltp_filt_idx_prev = -1;
     842           4 :             move16();
     843             :         }
     844             :     }
     845             : 
     846             :     /* in floating point implementation, different buffers are used: lp_error_ener <-> pst_lp_ener, mem_error <-> pst_mem_deemp_err */
     847          35 :     IF( st->hBPF != NULL )
     848             :     {
     849             : 
     850          35 :         st->lp_error_ener = Mpy_32_16_1( L_shl( hBPF->pst_lp_ener_fx, 8 ), 0x2a86 ); /* convert from 7Q8 10*log10 -> 15Q16, log2 */
     851          35 :         move32();
     852             :     }
     853             :     ELSE
     854             :     {
     855           0 :         st->lp_error_ener = 0;
     856           0 :         move16();
     857             :     }
     858          35 :     st->mem_error = L_deposit_l( 0 );
     859          35 :     move32();
     860          35 :     st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag );
     861          35 :     move16();
     862          35 :     st->last_ctx_hm_enabled = 0; /* Q0 */
     863          35 :     move16();
     864             : 
     865          35 :     st->hTcxCfg->resq = getResq( total_brate ); /* Q0 */
     866          35 :     move16();
     867             : 
     868          35 :     st->hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
     869          35 :     move16();
     870          35 :     IF( hTcxDec != NULL )
     871             :     {
     872          35 :         hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode );
     873          35 :         move16();
     874          35 :         hTcxDec->envWeighted = 0;
     875          35 :         move16();
     876             :     }
     877             : 
     878          35 :     st->p_bpf_noise_buf = NULL;
     879          35 :     if ( st->tcxonly == 0 )
     880             :     {
     881          35 :         st->p_bpf_noise_buf = st->bpf_noise_buf; /* q_p_bpf_noise_buf */
     882             :     }
     883             : 
     884          35 :     st->tec_tfa = 0; /* Q0 */
     885          35 :     move16();
     886          35 :     test();
     887          35 :     test();
     888          35 :     test();
     889          35 :     IF( EQ_16( bwidth, SWB ) &&
     890             :         ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
     891             :     {
     892          12 :         st->tec_tfa = 1;
     893          12 :         move16();
     894             :     }
     895             : 
     896          35 :     st->tec_flag = 0;
     897          35 :     move16();
     898          35 :     st->tfa_flag = 0;
     899          35 :     move16();
     900             : 
     901          35 :     st->enableGplc = 0;
     902          35 :     move16();
     903             : 
     904          35 :     st->flagGuidedAcelp = 0;
     905          35 :     move16();
     906          35 :     st->T0_4th = L_SUBFR;
     907          35 :     move16();
     908          35 :     st->guidedT0 = st->T0_4th;
     909          35 :     move16();
     910             : 
     911          35 :     st->enablePlcWaveadjust = 0;
     912          35 :     move16();
     913          35 :     test();
     914          35 :     test();
     915          35 :     IF( st->hTcxDec != NULL && GE_32( st->total_brate, 48000 ) && st->element_mode == EVS_MONO )
     916             :     {
     917           0 :         st->enablePlcWaveadjust = 1;
     918           0 :         move16();
     919           0 :         test();
     920           0 :         test();
     921           0 :         test();
     922           0 :         IF( EQ_16( st->ini_frame, 0 ) || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset )
     923             :         {
     924           0 :             concealment_init_x( hTcxDec->L_frameTCX, st->hPlcInfo );
     925             :         }
     926             :     }
     927             : 
     928             :     /* PLC: [TCX: Tonal Concealment] */
     929          35 :     test();
     930          35 :     test();
     931          35 :     IF( st->hTonalMDCTConc != NULL && !( st->element_mode > EVS_MONO && NE_16( st->ini_frame, 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) )
     932             :     {
     933          35 :         st->hTonalMDCTConc->nScaleFactors = 0;
     934          35 :         move16();
     935          35 :         st->hTonalMDCTConc->nSamples = 0;
     936          35 :         move16();
     937          35 :         st->hTonalMDCTConc->lastPcmOut = 0x0;
     938          35 :         move16();
     939          35 :         st->hTonalMDCTConc->q_lastPcmOut = Q15;
     940          35 :         move16();
     941          35 :         st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0;
     942          35 :         move16();
     943          35 :         st->hTonalMDCTConc->lastBlockData.nSamples = 0;
     944          35 :         move16();
     945             : 
     946          35 :         TonalMDCTConceal_Init( st->hTonalMDCTConc, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
     947             :     }
     948          35 :     st->last_tns_active = 0;
     949          35 :     move16();
     950          35 :     st->second_last_tns_active = 0;
     951          35 :     move16();
     952          35 :     st->second_last_core = -1;
     953          35 :     move16();
     954          35 :     IF( hTcxDec != NULL )
     955             :     {
     956          35 :         hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; /*15Q16*/
     957          35 :         move16();
     958          35 :         hTcxDec->tcxltp_third_last_pitch = st->old_fpitch; /*15Q16*/
     959          35 :         move16();
     960             :     }
     961          35 :     move16();
     962          35 :     st->dec_glr = 0;
     963          35 :     test();
     964          35 :     test();
     965          35 :     test();
     966          35 :     IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
     967             :     {
     968          12 :         test();
     969          12 :         test();
     970          12 :         test();
     971          12 :         IF( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) ||
     972             :               ( EQ_32( st->total_brate, 24400 ) ) ) &&
     973             :             st->element_mode == EVS_MONO )
     974             :         {
     975          12 :             move16();
     976          12 :             st->dec_glr = 1;
     977             :         }
     978             :     }
     979          35 :     move16();
     980          35 :     st->dec_glr_idx = 0;
     981          35 :     IF( hTcxDec != NULL )
     982             :     {
     983          35 :         hTcxDec->enableTcxLpc = 1;
     984          35 :         move16();
     985          35 :         st->VAD = 0;
     986          35 :         move16();
     987          35 :         hTcxDec->old_gaintcx_bfi = 0;
     988          35 :         move16();
     989          35 :         hTcxDec->old_gaintcx_bfi_e = 0;
     990          35 :         move16();
     991          35 :         hTcxDec->tcx_hm_LtpPitchLag = -1;
     992          35 :         move16();
     993             :     }
     994          35 :     st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
     995          35 :     move16();
     996          35 :     if ( hTcxLtpDec != NULL )
     997             :     {
     998          35 :         hTcxLtpDec->tcxltp_gain = 0; /* Q15 */
     999          35 :         move16();
    1000             :     }
    1001          35 :     return;
    1002             : }
    1003             : 
    1004       30029 : void tcxltp_dec_init_fx(
    1005             :     TCX_LTP_DEC_HANDLE hTcxLtpDec, /* Q0 */
    1006             :     const Word16 ini_frame,        /* Q0 */
    1007             :     const Word16 last_codec_mode,  /* Q0 */
    1008             :     const Word16 element_mode,     /* Q0 */
    1009             :     const Word16 pit_max,          /* Q0 */
    1010             :     const Word32 sr_core           /* Q0 */
    1011             : )
    1012             : {
    1013       30029 :     hTcxLtpDec->tcxltp_gain = 0; /* Q15 */
    1014       30029 :     move16();
    1015             : 
    1016       30029 :     hTcxLtpDec->tcxltp = getTcxLtp( sr_core );
    1017       30029 :     test();
    1018       30029 :     test();
    1019       30029 :     IF( EQ_16( ini_frame, 0 ) || ( EQ_16( last_codec_mode, MODE1 ) && element_mode == EVS_MONO ) )
    1020             :     {
    1021       13943 :         hTcxLtpDec->tcxltp_pitch_int = pit_max; /* Q0 */
    1022       13943 :         move16();
    1023       13943 :         hTcxLtpDec->tcxltp_pitch_fr = 0; /* Q0 */
    1024       13943 :         move16();
    1025             : 
    1026       13943 :         IF( ini_frame == 0 )
    1027             :         {
    1028       13943 :             set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY );    /* exp_tcxltp_mem_in */
    1029       13943 :             set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k );         /* exp_tcxltp_mem_out */
    1030       13943 :             set32_fx( hTcxLtpDec->tcxltp_mem_in_32, 0, TCXLTP_MAX_DELAY ); /* exp_tcxltp_mem_in */
    1031       13943 :             set32_fx( hTcxLtpDec->tcxltp_mem_out_32, 0, L_FRAME48k );      /* exp_tcxltp_mem_out */
    1032       13943 :             hTcxLtpDec->exp_tcxltp_mem_in = 0;
    1033       13943 :             move16();
    1034       13943 :             hTcxLtpDec->exp_tcxltp_mem_out = 0;
    1035       13943 :             move16();
    1036       13943 :             hTcxLtpDec->tcxltp_pitch_int_post_prev = 0;
    1037       13943 :             move16();
    1038       13943 :             hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0;
    1039       13943 :             move16();
    1040       13943 :             hTcxLtpDec->tcxltp_gain_post_prev = 0;
    1041       13943 :             move16();
    1042       13943 :             hTcxLtpDec->tcxltp_filt_idx_prev = -1;
    1043       13943 :             move16();
    1044             :         }
    1045             :     }
    1046             : 
    1047       30029 :     return;
    1048             : }
    1049             : 
    1050         156 : void acelp_plc_mdct_transition_fx(
    1051             :     Decoder_State *st /* i/o: Decoder state */
    1052             : )
    1053             : {
    1054             :     PWord16 const *w;
    1055             :     Word16 W1, W2, nz, delay_comp;
    1056             :     Word16 i;
    1057             : 
    1058             :     /*PLC*/
    1059         156 :     test();
    1060         156 :     IF( st->prev_bfi != 0 && st->hTcxCfg != NULL )
    1061             :     {
    1062         156 :         W1 = st->hTcxCfg->tcx_mdct_window_lengthFB;
    1063         156 :         move16();
    1064         156 :         W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 );
    1065         156 :         w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/
    1066             : 
    1067         156 :         nz = NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS );
    1068         156 :         move16();
    1069         156 :         delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS );
    1070         156 :         move16(); /*CLDFB delay*/
    1071             : 
    1072         156 :         Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) );                      /* Q_fer_samples */
    1073         156 :         lerp( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( st->hTcxDec->L_frameTCX, 1 ) ); /*ACELP(bfi)->TCX(rect)*/
    1074             :         /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/
    1075         156 :         st->hHQ_core->Q_old_wtda = -1;
    1076         156 :         move16();
    1077         156 :         set16_fx( st->hHQ_core->old_out_fx, 0, nz );                                                                              // Q_old_out is 0
    1078         156 :         Copy_Scale_sig( st->hHQ_core->fer_samples_fx + delay_comp, st->hHQ_core->old_out_fx + nz, W1, st->hHQ_core->Q_old_wtda ); /*Q-1*/
    1079             : 
    1080       25216 :         FOR( i = 0; i < W2; i++ )
    1081             :         {
    1082       25060 :             st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[i + nz] ) ); /* exp_old_out */
    1083       25060 :             move16();
    1084             :         }
    1085       25216 :         FOR( ; i < W1; i++ )
    1086             :         {
    1087       25060 :             st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - 1 - ( i - W2 )].v.im, w[W2 - 1 - ( i - W2 )].v.im ), st->hHQ_core->old_out_fx[i + nz] ) ); /* exp_old_out */
    1088       25060 :             move16();
    1089             :         }
    1090         156 :         set16_fx( &st->hHQ_core->old_out_fx[W1 + nz], 0, nz );
    1091             : 
    1092         156 :         lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, st->hTcxDec->L_frameTCX );
    1093         156 :         Copy( st->hHQ_core->old_out_fx + nz, st->hTcxDec->syn_Overl_TDACFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); /* exp_old_out */
    1094         156 :         st->hTcxDec->Q_syn_Overl_TDACFB = st->hHQ_core->Q_old_wtda;
    1095         156 :         move16();
    1096             : 
    1097         156 :         nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS );
    1098         156 :         Copy( st->hHQ_core->old_out_LB_fx + nz, st->hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); /* exp_old_out */
    1099         156 :         st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda;
    1100         156 :         move16();
    1101         156 :         st->hTcxDec->Q_syn_Overl_TDAC = st->hHQ_core->Q_old_wtda_LB;
    1102         156 :         move16();
    1103             :     }
    1104             : 
    1105         156 :     return;
    1106             : }
    1107             : 
    1108       28535 : void open_decoder_LPD_ivas_fx(
    1109             :     Decoder_State *st,              /* i/o: decoder state structure                                             */
    1110             :     const Word32 total_brate,       /* i  : total bitrate                                                         Q0*/
    1111             :     const Word32 last_total_brate,  /* i  : last total bitrate                                            Q0*/
    1112             :     const Word16 bwidth,            /* i  : audio bandwidth                                                       Q0*/
    1113             :     const Word16 MCT_flag,          /* i  : hMCT handle allocated (1) or not (0)      Q0*/
    1114             :     const Word16 last_element_mode, /* i  : last element mode                         Q0*/
    1115             :     const Word16 is_init,           /* i  : indicate call from init_decoder() to avoid double TC initialization Q0*/
    1116             :     Word16 *Q_syn_Overl_TDAC,
    1117             :     Word16 *Q_fer_samples,
    1118             :     Word16 *Q_syn_Overl,
    1119             :     Word16 *Q_syn_Overl_TDACFB,
    1120             :     Word16 *Q_syn_OverlFB,
    1121             :     Word16 *Q_old_out,
    1122             :     Word16 *Q_old_outLB,
    1123             :     Word16 *Q_old_Aq_12_8 )
    1124             : {
    1125             :     Word16 i;
    1126             :     Word16 mem_syn_r_size_new;
    1127             :     Word16 mem_syn_r_size_old;
    1128             :     Word16 fscaleFB;
    1129             :     BPF_DEC_HANDLE hBPF;
    1130             :     TD_BWE_DEC_HANDLE hBWE_TD;
    1131             :     TCX_LTP_DEC_HANDLE hTcxLtpDec;
    1132             :     HQ_DEC_HANDLE hHQ_core;
    1133             :     TCX_DEC_HANDLE hTcxDec;
    1134             : 
    1135       28535 :     hBPF = st->hBPF;
    1136       28535 :     hBWE_TD = st->hBWE_TD;
    1137       28535 :     hHQ_core = st->hHQ_core;
    1138       28535 :     hTcxLtpDec = st->hTcxLtpDec;
    1139       28535 :     hTcxDec = st->hTcxDec;
    1140             : 
    1141       28535 :     if ( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/
    1142             :     {
    1143           0 :         st->fscale_old = st->fscale; /* Q0 */
    1144           0 :         move16();
    1145             :     }
    1146             : 
    1147       28535 :     st->sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format );
    1148       28535 :     move16();
    1149       28535 :     st->fscale = sr2fscale_fx( st->sr_core );
    1150       28535 :     move16();
    1151       28535 :     fscaleFB = sr2fscale_fx( st->output_Fs );
    1152       28535 :     move16();
    1153             : 
    1154             :     /* initializing variables for frame lengths etc. right in the beginning */
    1155       28535 :     st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); /* 0.02 in Q15 */
    1156       28535 :     move16();
    1157       28535 :     if ( st->ini_frame == 0 )
    1158             :     {
    1159       12449 :         st->last_L_frame = st->L_frame_past = st->L_frame; /* Q0 */
    1160       12449 :         move16();
    1161       12449 :         move16();
    1162             :     }
    1163       28535 :     IF( st->hTcxDec != NULL )
    1164             :     {
    1165       28438 :         st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); /* 0.02 in Q15 */
    1166       28438 :         move16();
    1167       28438 :         st->output_frame_fx = st->hTcxDec->L_frameTCX; /* Q0 */
    1168       28438 :         move16();
    1169       28438 :         if ( st->ini_frame == 0 )
    1170             :         {
    1171       12352 :             st->L_frameTCX_past = st->hTcxDec->L_frameTCX;
    1172       12352 :             move16();
    1173             :         }
    1174             :     }
    1175             : 
    1176       28535 :     st->tcxonly = getTcxonly_fx( st->element_mode, total_brate, MCT_flag, st->is_ism_format );
    1177       28535 :     move16();
    1178             : 
    1179             :     /* the TD TCX PLC in MODE1 still runs with 80ms subframes */
    1180       28535 :     test();
    1181       28535 :     test();
    1182       28535 :     test();
    1183       28535 :     test();
    1184       28535 :     test();
    1185       28535 :     test();
    1186       28535 :     test();
    1187       28535 :     test();
    1188       28535 :     IF( ( st->element_mode == EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) ||
    1189             :         ( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) ||
    1190             :         ( ( st->tcxonly != 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) )
    1191             :     {
    1192       10902 :         st->nb_subfr = NB_SUBFR16k;
    1193       10902 :         move16();
    1194             :     }
    1195             :     ELSE
    1196             :     {
    1197       17633 :         st->nb_subfr = NB_SUBFR;
    1198       17633 :         move16();
    1199             :     }
    1200       28535 :     st->bits_frame = extract_l( L_shr( Mpy_32_16_1( L_shl( st->total_brate, 1 ), 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */
    1201             :                                                                                                  // assert(FSCALE_DENOM == 512);
    1202             :                                                                                                  // assert(st->fscale == 2 * st->L_frame); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */
    1203             :                                                                                                  // assert(st->bits_frame == (int16_t)(((float)st->L_frame / (float)st->fscale) * (float)FSCALE_DENOM / 128.0f * (float)total_brate / 100.0f + 0.49f));
    1204       28535 :     move16();
    1205       28535 :     st->TcxBandwidth = getTcxBandwidth( bwidth );
    1206       28535 :     move16();
    1207       28535 :     st->narrowBand = 0;
    1208       28535 :     move16();
    1209       28535 :     if ( EQ_16( bwidth, NB ) )
    1210             :     {
    1211        7233 :         st->narrowBand = 1;
    1212        7233 :         move16();
    1213             :     }
    1214             : 
    1215       28535 :     IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
    1216             :     {
    1217       15828 :         st->pit_res_max = initPitchLagParameters( INT_FS_12k8, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
    1218       15828 :         move16();
    1219       15828 :         IF( hTcxDec != NULL )
    1220             :         {
    1221       15828 :             i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( L_FRAME ) );             /* Q6 */
    1222       15828 :             hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */
    1223       15828 :             move16();
    1224       15828 :             hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */
    1225       15828 :             move16();
    1226             :         }
    1227             :     }
    1228             :     ELSE
    1229             :     {
    1230       12707 :         st->pit_res_max = initPitchLagParameters( st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
    1231       12707 :         move16();
    1232       12707 :         IF( hTcxDec != NULL )
    1233             :         {
    1234       12610 :             i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) );         /* Q6 */
    1235       12610 :             hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */
    1236       12610 :             move16();
    1237       12610 :             hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */
    1238       12610 :             move16();
    1239             :         }
    1240             :     }
    1241             : 
    1242       28535 :     if ( st->ini_frame == 0 )
    1243             :     {
    1244       12449 :         st->pit_res_max_past = st->pit_res_max;
    1245       12449 :         move16();
    1246             :     }
    1247             : 
    1248             :     /*Preemphasis param*/
    1249       28535 :     IF( LT_16( st->fscale, 640 ) ) /*16000 * FSCALE_DENOM ) / INT_FS_12k8*/
    1250             :     {
    1251       11029 :         st->preemph_fac = PREEMPH_FAC; /*WB*/
    1252       11029 :         move16();
    1253             :     }
    1254       17506 :     ELSE IF( LT_16( st->fscale, 960 ) ) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 )*/
    1255             :     {
    1256        5598 :         st->preemph_fac = PREEMPH_FAC_16k; /*WB*/
    1257        5598 :         move16();
    1258             :     }
    1259             :     ELSE
    1260             :     {
    1261       11908 :         st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/
    1262       11908 :         move16();
    1263             :     }
    1264             : 
    1265       28535 :     st->inv_gamma = GAMMA1_INV;
    1266       28535 :     move16();
    1267       28535 :     test();
    1268       28535 :     IF( EQ_32( st->sr_core, INT_FS_16k ) )
    1269             :     {
    1270        5598 :         st->gamma = GAMMA16k;
    1271        5598 :         move16();
    1272        5598 :         st->inv_gamma = GAMMA16k_INV;
    1273        5598 :         move16();
    1274             :     }
    1275       22937 :     ELSE IF( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
    1276             :     {
    1277       10612 :         st->gamma = GAMMA16k;
    1278       10612 :         move16();
    1279       10612 :         st->inv_gamma = GAMMA16k_INV;
    1280       10612 :         move16();
    1281             :     }
    1282             :     ELSE
    1283             :     {
    1284       12325 :         st->gamma = GAMMA1;
    1285       12325 :         move16();
    1286             :     }
    1287             : 
    1288             :     /* LPC quantization */
    1289       28535 :     test();
    1290       28535 :     IF( LE_32( st->sr_core, INT_FS_16k ) && EQ_16( st->tcxonly, 0 ) )
    1291             :     {
    1292       15994 :         st->lpcQuantization = 1;
    1293       15994 :         move16();
    1294             :     }
    1295             :     ELSE
    1296             :     {
    1297       12541 :         st->lpcQuantization = 0;
    1298       12541 :         move16();
    1299             :     }
    1300             : 
    1301       28535 :     IF( ( st->tcxonly == 0 ) )
    1302             :     {
    1303       15994 :         st->numlpc = 1;
    1304       15994 :         move16();
    1305             :     }
    1306             :     ELSE
    1307             :     {
    1308       12541 :         st->numlpc = 2;
    1309       12541 :         move16();
    1310             :     }
    1311             : 
    1312             :     /* Initialize TBE */
    1313       28535 :     st->prev_coder_type = GENERIC;
    1314       28535 :     move16();
    1315       28535 :     IF( st->hBWE_TD != NULL )
    1316             :     {
    1317       13966 :         set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); /* Q15 */
    1318       13966 :         hBWE_TD->prev_tilt_para_fx = 0;
    1319       13966 :         move16();
    1320       13966 :         set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); /* Q12 */
    1321             :     }
    1322             : 
    1323       28535 :     IF( st->hIGFDec != NULL )
    1324             :     {
    1325       28438 :         test();
    1326       28438 :         IF( !is_init || NE_16( st->element_mode, IVAS_CPE_MDCT ) )
    1327             :         {
    1328       23830 :             init_tcx_cfg_fx( st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, st->preemph_fac, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag, fscaleFB );
    1329             :         }
    1330             :         ELSE
    1331             :         {
    1332        4608 :             st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
    1333        4608 :             move16();
    1334        4608 :             move16();
    1335        4608 :             st->hTcxCfg->last_aldo = 1;
    1336        4608 :             move16();
    1337             :         }
    1338             :     }
    1339       28535 :     IF( st->hTECDec != NULL )
    1340             :     {
    1341             :         /*constraint for adaptive bpf, otherwise parameter estimation and post-processing not time aligned*/
    1342           0 :         resetTecDec_Fx( st->hTECDec );
    1343             :     }
    1344             : 
    1345       28535 :     if ( NE_16( st->element_mode, IVAS_SCE ) )
    1346             :     {
    1347       18889 :         st->flag_cna = 0;
    1348       18889 :         move16();
    1349             :     }
    1350       28535 :     IF( st->ini_frame == 0 )
    1351             :     {
    1352       12449 :         st->flag_cna = 0;
    1353       12449 :         move16();
    1354       12449 :         st->last_flag_cna = 0;
    1355       12449 :         move16();
    1356             :     }
    1357             : 
    1358             :     /* Static vectors to zero */
    1359       28535 :     IF( ( st->ini_frame == 0 ) )
    1360             :     {
    1361       12449 :         st->last_is_cng = 0;
    1362       12449 :         move16();
    1363             : 
    1364       12449 :         st->rate_switching_reset = 0;
    1365       12449 :         move16();
    1366             : 
    1367       12449 :         IF( st->hTcxDec != NULL )
    1368             :         {
    1369       12352 :             reset_tcx_overl_buf_fx( st->hTcxDec );
    1370       12352 :             set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 );      /* Qx */
    1371       12352 :             set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */
    1372       12352 :             hTcxDec->q_old_synth = 0;
    1373       12352 :             move16();
    1374       12352 :             set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); /* hTcxDec->q_synth_history_fx */
    1375       12352 :             hTcxDec->q_synth_history_fx = 0;
    1376       12352 :             move16();
    1377             :         }
    1378       12449 :         set16_fx( st->syn, 0, M + 1 );           /* Q_syn */
    1379       12449 :         set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); /* Qx */
    1380             : 
    1381       12449 :         mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */
    1382       12449 :         move16();
    1383       12449 :         mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */
    1384       12449 :         move16();
    1385             : 
    1386       12449 :         st->con_tcx = 0;
    1387       12449 :         move16();
    1388             :     }
    1389             :     ELSE
    1390             :     {
    1391             :         /* Reset old_synth in case of core sampling rate switching and Mode 1/2 switching*/
    1392       16086 :         test();
    1393       16086 :         test();
    1394       16086 :         test();
    1395       16086 :         IF( st->hTcxDec != NULL && ( NE_16( st->L_frame, st->last_L_frame ) || ( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) ) )
    1396             :         {
    1397        5927 :             set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* q_old_synth */
    1398        5927 :             hTcxDec->q_old_synth = 0;
    1399        5927 :             move16();
    1400             :         }
    1401             : 
    1402             :         /*Compute size of old and new memories*/
    1403             :         /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */
    1404       16086 :         mem_syn_r_size_old = shr( st->last_L_frame, 4 );
    1405       16086 :         mem_syn_r_size_new = shr( st->L_frame, 4 );
    1406             : 
    1407             :         /*Reset LPC mem*/
    1408       16086 :         test();
    1409       16086 :         test();
    1410       16086 :         IF( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || EQ_16( st->last_core, HQ_CORE ) )
    1411             :         {
    1412        6272 :             set16_fx( st->mem_MA_fx, 0, M ); /* Qx2.56 */
    1413        6272 :             IF( EQ_32( st->sr_core, INT_FS_16k ) )
    1414             :             {
    1415        1502 :                 Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /* Qx2.56 */
    1416             :             }
    1417             :             ELSE
    1418             :             {
    1419        4770 :                 Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /* Qx2.56 */
    1420             :             }
    1421             :         }
    1422             : 
    1423             :         /*Mode 1/2 switching*/
    1424       16086 :         test();
    1425       16086 :         IF( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO )
    1426             :         {
    1427           0 :             Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
    1428           0 :             Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
    1429           0 :             set16_fx( st->syn, 0, M );
    1430             :         }
    1431       16086 :         IF( EQ_16( st->last_core, AMR_WB_CORE ) )
    1432             :         {
    1433           0 :             st->last_core = ACELP_CORE;
    1434           0 :             move16();
    1435           0 :             st->last_core_bfi = ACELP_CORE;
    1436           0 :             move16();
    1437             :         }
    1438             : 
    1439             :         /*Codec switching from ACELP-A */
    1440       16086 :         test();
    1441       16086 :         test();
    1442       16086 :         test();
    1443       16086 :         test();
    1444       16086 :         IF( ( NE_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->prev_bfi ) ) && EQ_16( st->last_codec_mode, MODE1 ) && ( st->last_core == ACELP_CORE ) )
    1445             :         {
    1446             :             /* Switching from Mode 1 ACELP */
    1447        7168 :             st->last_core_bfi = ACELP_CORE;
    1448        7168 :             move16();
    1449        7168 :             test();
    1450        7168 :             IF( NE_16( st->prev_bfi, 0 ) && st->hTcxCfg != NULL )
    1451             :             {
    1452         156 :                 acelp_plc_mdct_transition_fx( st );
    1453         156 :                 *Q_syn_Overl_TDAC = sub( *Q_fer_samples, 1 );
    1454         156 :                 move16();
    1455         156 :                 *Q_syn_Overl = *Q_fer_samples;
    1456         156 :                 move16();
    1457         156 :                 *Q_syn_Overl_TDACFB = sub( *Q_fer_samples, 1 );
    1458         156 :                 move16();
    1459         156 :                 *Q_syn_OverlFB = *Q_fer_samples;
    1460         156 :                 move16();
    1461         156 :                 *Q_old_out = sub( *Q_fer_samples, 1 );
    1462         156 :                 move16();
    1463         156 :                 *Q_old_outLB = sub( *Q_fer_samples, 1 );
    1464         156 :                 move16();
    1465             :             }
    1466             :         }
    1467       16086 :         test();
    1468       16086 :         test();
    1469       16086 :         test();
    1470       16086 :         test();
    1471       16086 :         test();
    1472       16086 :         test();
    1473       16086 :         IF( EQ_16( st->last_codec_mode, MODE2 ) && NE_16( st->L_frame, st->last_L_frame ) &&
    1474             :             ( ( EQ_16( st->m_frame_type, SID_FRAME ) && ( st->last_core > ACELP_CORE ) ) ||
    1475             :               ( ( st->last_core > ACELP_CORE ) && ( st->core > ACELP_CORE ) ) || st->prev_bfi ) )
    1476             :         {
    1477           0 :             lerp( st->hHQ_core->old_out_LB_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, st->last_L_frame );
    1478             :         }
    1479             : 
    1480             :         /* Rate switching */
    1481       16086 :         test();
    1482       16086 :         test();
    1483       16086 :         test();
    1484       16086 :         IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) )
    1485             :         {
    1486             :             /* Switching from MDCT */
    1487             : 
    1488             :             /*Reset of ACELP memories*/
    1489         359 :             st->rate_switching_reset = 1;
    1490         359 :             move16();
    1491             :             // To be removed later
    1492         359 :             st->tilt_code_fx = TILT_CODE;
    1493         359 :             move16();
    1494         359 :             set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */
    1495         359 :             set16_fx( st->syn, 0, 1 + M );                /* Q_syn */
    1496         359 :             set16_fx( st->mem_syn2_fx, 0, M );            /* Q_syn */
    1497             : 
    1498             :             /*OLA -> zero */
    1499         359 :             IF( st->hTcxDec != NULL )
    1500             :             {
    1501         359 :                 reset_tcx_overl_buf_fx( st->hTcxDec );
    1502             :             }
    1503             : 
    1504         359 :             IF( st->hTcxCfg != NULL )
    1505             :             {
    1506         359 :                 Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); /* Q_old_out */
    1507         359 :                 *Q_syn_OverlFB = *Q_old_out;
    1508         359 :                 move16();
    1509         359 :                 st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/
    1510         359 :                 move16();
    1511         359 :                 st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
    1512         359 :                 move16();
    1513             :             }
    1514             : 
    1515             :             /*OLA for Mode 2 TCX always reset in Mode switching cases*/
    1516         359 :             IF( st->hHQ_core != NULL )
    1517             :             {
    1518         359 :                 set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); /* q_old_outLB_fx */
    1519             :             }
    1520             : 
    1521         359 :             st->last_core_bfi = TCX_20_CORE;
    1522         359 :             move16();
    1523             : 
    1524         359 :             IF( st->hPFstat != NULL )
    1525             :             {
    1526         359 :                 st->hPFstat->on = 0;
    1527         359 :                 move16();
    1528             :             }
    1529             : 
    1530             :             /* reset CLDFB memories */
    1531         359 :             cldfb_reset_memory_fx( st->cldfbAna );
    1532         359 :             cldfb_reset_memory_fx( st->cldfbBPF );
    1533         359 :             cldfb_reset_memory_fx( st->cldfbSyn );
    1534         359 :             IF( st->cldfbSynHB != NULL )
    1535             :             {
    1536           2 :                 cldfb_reset_memory_fx( st->cldfbSynHB );
    1537             :             }
    1538             :         }
    1539       15727 :         ELSE IF( ( NE_16( st->L_frame, st->last_L_frame ) ) && ( LE_16( st->L_frame, L_FRAME16k ) ) && ( LE_16( st->last_L_frame, L_FRAME16k ) ) ) /* Rate switching between 12.8 and 16 kHz*/
    1540             :         {
    1541             :             /*Interpolation of ACELP memories*/
    1542             : 
    1543             :             /* convert quantized LSP vector */
    1544         500 :             st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
    1545         500 :             move16();
    1546         500 :             IF( EQ_16( st->tcxonly, 0 ) )
    1547             :             {
    1548         500 :                 lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
    1549             :             }
    1550             :             ELSE
    1551             :             {
    1552           0 :                 E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
    1553             :             }
    1554         500 :             E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M );
    1555         500 :             Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
    1556         500 :             Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
    1557         500 :             *Q_old_Aq_12_8 = 14;
    1558         500 :             move16();
    1559         500 :             IF( !st->last_con_tcx )
    1560             :             {
    1561         498 :                 ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC );
    1562             :             }
    1563             : 
    1564             :             /*mem of deemphasis stayed unchanged.*/
    1565             :         }
    1566       15227 :         ELSE IF( NE_16( st->L_frame, st->last_L_frame ) ) /* Rate switching involving TCX only modes */
    1567             :         {
    1568             :             /*Partial reset of ACELP memories*/
    1569        5413 :             st->rate_switching_reset = 1;
    1570        5413 :             move16();
    1571             : 
    1572             :             /*reset partly some memories*/
    1573        5413 :             st->tilt_code_fx = TILT_CODE;
    1574        5413 :             move16();
    1575        5413 :             IF( !st->last_con_tcx )
    1576             :             {
    1577        5391 :                 set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */
    1578             :             }
    1579        5413 :             set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); /* Q12 */
    1580             : 
    1581             :             /*Resamp others memories*/
    1582             :             /*Size of LPC syn memory*/
    1583        5413 :             lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
    1584        5413 :             Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Qx */
    1585             :         }
    1586             :         /* update of lsf_old only needed in BASOP */
    1587             :         /* ELSE IF( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */
    1588             :         /* { */
    1589             :         /*     lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */
    1590             :         /* } */
    1591             :     }
    1592       28535 :     test();
    1593       28535 :     test();
    1594       28535 :     if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) )
    1595             :     {
    1596           0 :         st->rate_switching_reset = 1;
    1597           0 :         move16();
    1598             :     }
    1599             : 
    1600       28535 :     IF( st->hTcxDec != NULL )
    1601             :     {
    1602       28438 :         st->hTcxDec->old_synth_len = shl( st->L_frame, 1 );
    1603       28438 :         st->hTcxDec->old_synth_lenFB = shl( hTcxDec->L_frameTCX, 1 );
    1604       28438 :         move16();
    1605       28438 :         move16();
    1606             :     }
    1607             : 
    1608             :     /* bass pf reset */
    1609       28535 :     st->bpf_gain_param = 0;
    1610       28535 :     move16();
    1611       28535 :     IF( st->hBPF != NULL )
    1612             :     {
    1613       12610 :         set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* q_pst_old_syn */
    1614             :     }
    1615             : 
    1616             :     /* Formant postfilter */
    1617       28535 :     IF( ( st->ini_frame == 0 ) )
    1618             :     {
    1619             :         /* do nothing */
    1620             :     }
    1621       16086 :     ELSE IF( EQ_16( st->last_codec_mode, MODE2 ) )
    1622             :     {
    1623           0 :         IF( !st->tcxonly )
    1624             :         {
    1625           0 :             IF( st->hPFstat->on )
    1626             :             {
    1627           0 :                 lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
    1628           0 :                 lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
    1629             :             }
    1630             :             ELSE
    1631             :             {
    1632           0 :                 set16_fx( st->hPFstat->mem_stp, 0, L_SYN_MEM );   /* Qx */
    1633           0 :                 set16_fx( st->hPFstat->mem_pf_in, 0, L_SYN_MEM ); /* Qx */
    1634           0 :                 st->hPFstat->reset = 1;
    1635           0 :                 st->hPFstat->gain_prec = 16384; /* Q14 */
    1636           0 :                 move16();
    1637           0 :                 move16();
    1638             :             }
    1639             :         }
    1640           0 :         ELSE IF( st->hPFstat->on )
    1641             :         {
    1642           0 :             lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
    1643           0 :             lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
    1644             :         }
    1645             :     }
    1646             :     ELSE
    1647             :     {
    1648             :         /*codec mode switching*/
    1649             : 
    1650             :         /*reset post-filter except for Narrowband*/
    1651       16086 :         IF( NE_32( st->output_Fs, i_mult( L_FRAME8k, FRAMES_PER_SEC ) ) )
    1652             :         {
    1653       16086 :             IF( st->hPFstat != NULL )
    1654             :             {
    1655        9498 :                 st->hPFstat->reset = 1;
    1656        9498 :                 move16();
    1657        9498 :                 IF( st->hPFstat->on != 0 )
    1658             :                 {
    1659        5684 :                     st->hPFstat->reset = 0;
    1660        5684 :                     move16();
    1661             :                     //-------------Present in EVS
    1662             :                     // Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */
    1663             :                     // Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn));   /* WB post_filter mem */
    1664             :                     //--------------
    1665        5684 :                     lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
    1666        5684 :                     lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
    1667             :                 }
    1668             :             }
    1669             :         }
    1670             :         ELSE
    1671             :         {
    1672             :             //----------------Present in EVS
    1673             :             // IF(st->hPFstat != NULL)
    1674             :             //{
    1675             :             // Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn));    /* NB post_filter mem */
    1676             :             // Scale_sig(st->hPFstat->mem_res2, DECMEM_RES2, negate(st->Q_syn)); /* NB post_filter mem */
    1677             :             // Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn));      /* NB post_filter mem */
    1678             :             //}
    1679             :             //------------------
    1680             :             /*feed last value old_synth as it is used for pre-emphasis mem*/
    1681           0 :             if ( st->hTcxDec != NULL )
    1682             :             {
    1683           0 :                 st->hTcxDec->old_synth[st->hTcxDec->old_synth_len - 1] = st->syn[M]; /* q_old_synth */
    1684           0 :                 move16();
    1685             :             }
    1686           0 :             if ( st->hBPF != NULL )
    1687             :             {
    1688           0 :                 st->hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; /* q_pst_old_syn */
    1689           0 :                 move16();
    1690             :             }
    1691             :         }
    1692             :     }
    1693             : 
    1694             :     /* lsf and lsp initialization */
    1695       28535 :     IF( ( st->ini_frame == 0 ) )
    1696             :     {
    1697       12449 :         Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
    1698       12449 :         Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
    1699       12449 :         set16_fx( st->lsf_cng, 0, M );
    1700             :     }
    1701             : 
    1702       28535 :     st->seed_tcx_plc = RANDOM_INITSEED;
    1703       28535 :     move16();
    1704       28535 :     st->past_gpit = 0;
    1705       28535 :     move16();
    1706       28535 :     st->past_gcode = L_deposit_l( 0 ); /*15Q16*/
    1707       28535 :     move32();
    1708       28535 :     st->gc_threshold_fx = L_deposit_l( 0 ); /* Q16 */
    1709       28535 :     move32();
    1710             : 
    1711       28535 :     E_LPC_lsf_lsp_conversion( st->lsf_cng, st->lspold_cng, M );
    1712       28535 :     E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M );
    1713       28535 :     st->plcBackgroundNoiseUpdated = 0;
    1714       28535 :     move16();
    1715       28535 :     Copy( st->lsf_old_fx, st->lsf_q_cng, M );     /* Q2.56 */
    1716       28535 :     Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); /* Q2.56 */
    1717       28535 :     Copy( st->lsp_old_fx, st->lsp_q_cng, M );     /* Q15 */
    1718       28535 :     Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); /* Q15 */
    1719       28535 :     set16_fx( st->mem_syn_unv_back, 0, M );
    1720       28535 :     st->last_gain_syn_deemph = 32768 / 2; /* 1.f Q14*/
    1721       28535 :     move16();
    1722             : 
    1723       28535 :     test();
    1724       28535 :     IF( EQ_16( st->last_codec_mode, MODE1 ) || ( st->ini_frame == 0 ) )
    1725             :     {
    1726             :         /* this assumes that MODE1 fades out in the frequency domain -
    1727             :            otherwise some data from MODE1 would be needed here */
    1728       28535 :         st->last_concealed_gain_syn_deemph = 32768 / 2;
    1729       28535 :         move16();
    1730       28535 :         st->last_concealed_gain_syn_deemph_e = 1;
    1731       28535 :         move16();
    1732       28535 :         if ( hTcxDec != NULL )
    1733             :         {
    1734       28438 :             hTcxDec->conceal_eof_gain32 = ONE_IN_Q30; /*Q30*/
    1735       28438 :             hTcxDec->conceal_eof_gain_e = 1;
    1736       28438 :             move16();
    1737       28438 :             move32();
    1738       28438 :             move16();
    1739             :         }
    1740             :     }
    1741             :     /* Post processing */
    1742       28535 :     set16_fx( st->mem_Aq, 0, i_mult( NB_SUBFR16k, ( M + 1 ) ) );
    1743             : 
    1744       28535 :     st->lp_ener_FER_fx = 15360; /*60.0f Q8*/
    1745       28535 :     move16();
    1746       28535 :     IF( EQ_16( st->ini_frame, 0 ) )
    1747             :     {
    1748       12449 :         st->prev_bfi = 0;
    1749       12449 :         move16();
    1750       12449 :         st->last_core_bfi = -1;
    1751       12449 :         move16();
    1752       12449 :         if ( st->hTcxDec != NULL )
    1753             :         {
    1754       12352 :             hTcxDec->tcxConceal_recalc_exc = 0;
    1755       12352 :             move16();
    1756             :         }
    1757             :     }
    1758       28535 :     st->prev_old_bfi = 0;
    1759       28535 :     move16();
    1760             : 
    1761       28535 :     IF( st->hTcxDec != NULL )
    1762             :     {
    1763       28438 :         st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0;
    1764       28438 :         move16();
    1765       28438 :         move16();
    1766       28438 :         st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0;
    1767       28438 :         move16();
    1768       28438 :         move16();
    1769       28438 :         set16_fx( st->hTcxDec->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); /* Q15 */
    1770             :     }
    1771             : 
    1772       28535 :     Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /* Q2.56 */
    1773       28535 :     Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M );        /* Q2.56 */
    1774       28535 :     Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M );        /* Q2.56 */
    1775             : 
    1776       28535 :     st->clas_dec = UNVOICED_CLAS;
    1777       28535 :     move16();
    1778             : 
    1779       28535 :     if ( !st->last_con_tcx )
    1780             :     {
    1781       28500 :         st->old_enr_LP = 0;
    1782       28500 :         move16(); /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */
    1783             :     }
    1784             : 
    1785       28535 :     IF( st->prev_bfi )
    1786             :     {
    1787             :         /* calculate energy at the end of the previous frame */
    1788         331 :         test();
    1789         331 :         IF( st->core == ACELP_CORE && EQ_16( st->last_core, HQ_CORE ) )
    1790             :         {
    1791           0 :             st->output_frame_fx = st->hTcxDec->L_frameTCX; /* Q0 */
    1792           0 :             move16();
    1793           0 :             frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 );
    1794             :         }
    1795             :     }
    1796             :     ELSE
    1797             :     {
    1798       28204 :         st->last_good = UNVOICED_CLAS;
    1799       28204 :         move16();                          /* last good received frame for concealment */
    1800       28204 :         st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame  */
    1801       28204 :         move32();
    1802             :     }
    1803       28535 :     st->Mode2_lp_gainc = L_deposit_l( 0 );
    1804       28535 :     move32();
    1805       28535 :     st->Mode2_lp_gainp = L_deposit_l( 0 );
    1806       28535 :     move32();
    1807       28535 :     st->lp_gainc_fx = 0; /* Q3 */
    1808       28535 :     move16();
    1809       28535 :     st->lp_gainp_fx = 0; /* Q14 */
    1810       28535 :     move16();
    1811             : 
    1812       28535 :     IF( st->hTcxDec != NULL )
    1813             :     {
    1814       28438 :         st->hTcxDec->prev_widow_left_rect = 0;
    1815       28438 :         move16();
    1816       28438 :         test();
    1817       28438 :         test();
    1818       28438 :         test();
    1819       28438 :         IF( is_init || MCT_flag || !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->element_mode, last_element_mode ) ) )
    1820             :         {
    1821       25608 :             st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1;
    1822       25608 :             move16();
    1823       25608 :             st->hTcxDec->CurrLevelIndex_bfi = 0;
    1824       25608 :             move16();
    1825       25608 :             st->hTcxDec->LastFrameLevel_bfi_fx = PLC_MIN_CNG_LEV;
    1826       25608 :             move16();
    1827       25608 :             set16_fx( st->hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE );
    1828       25608 :             set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE );
    1829       25608 :             st->hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/;
    1830       25608 :             move16();
    1831             : 
    1832       25608 :             hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/
    1833       25608 :             move16();
    1834       25608 :             hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1;
    1835       25608 :             move16();
    1836       25608 :             hTcxDec->conCurrLevelIndex = 0;
    1837       25608 :             move16();
    1838       25608 :             hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/
    1839       25608 :             move16();
    1840       25608 :             set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/
    1841       25608 :             set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE );
    1842       25608 :             hTcxDec->conLastFrameLevel_e = 0;
    1843       25608 :             move16();
    1844       25608 :             hTcxDec->conCngLevelBackgroundTrace_e = -6;
    1845       25608 :             move16();
    1846             : 
    1847       25608 :             hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/;
    1848       25608 :             move16();
    1849             :         }
    1850             :     }
    1851       28535 :     st->cummulative_damping = 32767 /*1.0f Q15*/;
    1852       28535 :     move16();
    1853             : 
    1854      370955 :     FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
    1855             :     {
    1856      342420 :         st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); /* 15Q16 */
    1857      342420 :         move32();
    1858             :     }
    1859             : 
    1860      370955 :     FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
    1861             :     {
    1862      342420 :         st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/
    1863      342420 :         move16();
    1864             :     }
    1865       28535 :     st->old_fpitch = L_deposit_h( st->pit_min );
    1866       28535 :     move32();
    1867       28535 :     st->rate_switching_init = 1;
    1868       28535 :     move16();
    1869             : 
    1870       28535 :     st->reset_mem_AR = 0;
    1871       28535 :     move16();
    1872             : 
    1873             :     /* For phase dispersion */
    1874       28535 :     st->dm_fx.prev_gain_code = L_deposit_l( 0 );
    1875       28535 :     move32();
    1876       28535 :     set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
    1877       28535 :     st->dm_fx.prev_state = 0;
    1878       28535 :     move16();
    1879       28535 :     st->voice_fac = -1;
    1880       28535 :     move16();
    1881             : 
    1882             :     /* TCX-LTP */
    1883       28535 :     IF( hTcxLtpDec != NULL )
    1884             :     {
    1885       28438 :         tcxltp_dec_init_fx( hTcxLtpDec, st->ini_frame, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core );
    1886             :     }
    1887             : 
    1888             :     /* TCX */
    1889       28535 :     IF( hTcxDec != NULL )
    1890             :     {
    1891       28438 :         st->old_fpitchFB = L_deposit_h( hTcxDec->pit_min_TCX );
    1892       28438 :         move32();
    1893       28438 :         test();
    1894       28438 :         test();
    1895       28438 :         IF( ( st->ini_frame == 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) )
    1896             :         {
    1897       12352 :             hTcxDec->tcxltp_last_gain_unmodified = 0;
    1898       12352 :             move16();
    1899             :         }
    1900             : 
    1901             :         /* TCX */
    1902       28438 :         hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode );
    1903       28438 :         move16();
    1904       28438 :         hTcxDec->envWeighted = 0;
    1905       28438 :         move16();
    1906             :     }
    1907             : 
    1908       28535 :     IF( st->hBPF != NULL )
    1909             :     {
    1910       12610 :         st->lp_error_ener = Mpy_32_16_1( L_shl( hBPF->pst_lp_ener_fx, 8 ), 0x2a86 ); /* convert from 7Q8 10*log10 -> 15Q16, log2 */
    1911       12610 :         move32();
    1912       12610 :         hBPF->pst_mem_deemp_err_fx = 0; /* Q_syn2 - 1 */
    1913       12610 :         move16();
    1914             :     }
    1915             :     ELSE
    1916             :     {
    1917       15925 :         st->lp_error_ener = 0;
    1918       15925 :         move32();
    1919             :     }
    1920       28535 :     st->mem_error = L_deposit_l( 0 );
    1921       28535 :     move32();
    1922       28535 :     IF( st->tcxonly )
    1923             :     {
    1924       12541 :         st->p_bpf_noise_buf = NULL;
    1925       12541 :         st->p_bpf_noise_buf_32 = NULL;
    1926             :     }
    1927             :     ELSE
    1928             :     {
    1929       15994 :         st->p_bpf_noise_buf = st->bpf_noise_buf;
    1930       15994 :         move32();
    1931       15994 :         st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32;
    1932       15994 :         move32();
    1933             :     }
    1934       28535 :     test();
    1935       28535 :     test();
    1936       28535 :     test();
    1937       28535 :     IF( EQ_16( bwidth, SWB ) && ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
    1938             :     {
    1939           0 :         st->tec_tfa = 1;
    1940           0 :         move16();
    1941             :     }
    1942             :     ELSE
    1943             :     {
    1944       28535 :         st->tec_tfa = 0;
    1945       28535 :         move16();
    1946             :     }
    1947             : 
    1948       28535 :     st->tec_flag = 0;
    1949       28535 :     move16();
    1950       28535 :     st->tfa_flag = 0;
    1951       28535 :     move16();
    1952             : 
    1953             :     /* needed in decoder to read the bitstream */
    1954       28535 :     st->enableGplc = 0;
    1955       28535 :     move16();
    1956             : 
    1957       28535 :     st->flagGuidedAcelp = 0;
    1958       28535 :     move16();
    1959       28535 :     st->tonal_mdct_plc_active = 0;
    1960       28535 :     move16();
    1961       28535 :     st->T0_4th = L_SUBFR;
    1962       28535 :     move16();
    1963       28535 :     st->guidedT0 = st->T0_4th;
    1964       28535 :     move16();
    1965       28535 :     test();
    1966       28535 :     test();
    1967       28535 :     IF( st->hPlcInfo != NULL && GE_32( total_brate, HQ_48k ) && st->element_mode == EVS_MONO )
    1968             :     {
    1969           0 :         st->enablePlcWaveadjust = 1;
    1970           0 :         move16();
    1971             : 
    1972           0 :         IF( st->hTcxDec != NULL && ( st->ini_frame == 0 || LT_32( last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) )
    1973             :         {
    1974           0 :             concealment_init_ivas_fx( st->hTcxDec->L_frameTCX, st->hPlcInfo );
    1975             :         }
    1976             :     }
    1977             :     ELSE
    1978             :     {
    1979       28535 :         st->enablePlcWaveadjust = 0;
    1980       28535 :         move16();
    1981             :     }
    1982             : 
    1983             :     /* PLC: [TCX: Tonal Concealment] */
    1984       28535 :     test();
    1985       28535 :     test();
    1986       28535 :     test();
    1987       28535 :     IF( st->hTonalMDCTConc != NULL && !( st->element_mode > EVS_MONO && ( st->ini_frame != 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) )
    1988             :     {
    1989       13011 :         st->hTonalMDCTConc->nScaleFactors = 0;
    1990       13011 :         move16();
    1991       13011 :         st->hTonalMDCTConc->nSamples = 0;
    1992       13011 :         move16();
    1993       13011 :         st->hTonalMDCTConc->lastPcmOut = 0x0;
    1994       13011 :         move16();
    1995       13011 :         st->hTonalMDCTConc->q_lastPcmOut = Q15;
    1996       13011 :         move16();
    1997       13011 :         st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0;
    1998       13011 :         move16();
    1999       13011 :         st->hTonalMDCTConc->lastBlockData.nSamples = 0;
    2000       13011 :         move16();
    2001       13011 :         TonalMDCTConceal_Init_ivas_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
    2002             :     }
    2003             : 
    2004       28535 :     st->last_tns_active = 0;
    2005       28535 :     move16();
    2006       28535 :     st->second_last_tns_active = 0;
    2007       28535 :     move16();
    2008       28535 :     st->second_last_core = -1;
    2009       28535 :     move16();
    2010             : 
    2011       28535 :     IF( st->hTcxCfg != NULL && st->element_mode != EVS_MONO )
    2012             :     {
    2013             :         Word32 gettns_temp;
    2014       28438 :         IF( is_init )
    2015             :         {
    2016        7136 :             gettns_temp = total_brate;
    2017        7136 :             move32();
    2018             :         }
    2019             :         ELSE
    2020             :         {
    2021       21302 :             gettns_temp = L_mult( st->bits_frame_nominal, ( FRAMES_PER_SEC >> 1 ) ); /* Q0 */
    2022             :         }
    2023       28438 :         st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( gettns_temp, st->igf, st->element_mode );
    2024       28438 :         move16();
    2025             :     }
    2026       28535 :     IF( hTcxDec != NULL )
    2027             :     {
    2028       28438 :         hTcxDec->tcxltp_second_last_pitch = st->old_fpitch;
    2029       28438 :         move16();
    2030       28438 :         hTcxDec->tcxltp_third_last_pitch = st->old_fpitch;
    2031       28438 :         move16();
    2032             :     }
    2033       28535 :     test();
    2034       28535 :     test();
    2035       28535 :     test();
    2036       28535 :     IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
    2037             :     {
    2038           0 :         st->dec_glr = 1;
    2039           0 :         move16();
    2040             :     }
    2041             :     ELSE
    2042             :     {
    2043       28535 :         st->dec_glr = 0;
    2044       28535 :         move16();
    2045             :     }
    2046             : 
    2047       28535 :     st->dec_glr_idx = 0;
    2048       28535 :     move16();
    2049             : 
    2050       28535 :     st->VAD = 0;
    2051       28535 :     move16();
    2052       28535 :     IF( hTcxDec != NULL )
    2053             :     {
    2054       28438 :         hTcxDec->enableTcxLpc = 1;
    2055       28438 :         move16();
    2056       28438 :         hTcxDec->old_gaintcx_bfi = 0;
    2057       28438 :         move16();
    2058       28438 :         hTcxDec->old_gaintcx_bfi_e = 0;
    2059       28438 :         move16();
    2060             : 
    2061       28438 :         hTcxDec->tcx_hm_LtpPitchLag = -1;
    2062       28438 :         move16();
    2063             :     }
    2064             : 
    2065       28535 :     IF( st->hTcxCfg != NULL )
    2066             :     {
    2067       28438 :         st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
    2068       28438 :         move16();
    2069             :     }
    2070             : 
    2071       28535 :     return;
    2072             : }
    2073             : 
    2074             : /*-----------------------------------------------------------------------*
    2075             :  * reset_tcx_overl_buf()
    2076             :  *
    2077             :  * Reset TCX core overlap buffers
    2078             :  *-----------------------------------------------------------------------*/
    2079             : 
    2080       13394 : void reset_tcx_overl_buf_fx(
    2081             :     TCX_DEC_HANDLE hTcxDec /* i/o: TCX decoder handle */
    2082             : )
    2083             : {
    2084       13394 :     set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
    2085       13394 :     hTcxDec->Q_old_syn_Overl = 0;
    2086       13394 :     move16();
    2087       13394 :     set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
    2088       13394 :     hTcxDec->Q_syn_Overl_TDAC = 0;
    2089       13394 :     move16();
    2090       13394 :     set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
    2091       13394 :     hTcxDec->Q_syn_Overl = 0;
    2092       13394 :     move16();
    2093       13394 :     set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
    2094       13394 :     hTcxDec->Q_syn_Overl_TDACFB = 0;
    2095       13394 :     move16();
    2096       13394 :     return;
    2097             : }

Generated by: LCOV version 1.14