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

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include "options.h"    /* Compilation switches                   */
       7             : #include "cnst.h"       /* Common constants                       */
       8             : #include "rom_com.h"    /* Static table prototypes                */
       9             : #include "prot_fx.h"    /* Function prototypes                    */
      10             : #include "basop_util.h" /* Function prototypes                    */
      11             : #include "ivas_prot_fx.h"
      12             : 
      13             : 
      14             : /*---------------------------------------------------------------------*
      15             :  * bandwidth_switching_detect_fx()
      16             :  *
      17             :  *
      18             :  *---------------------------------------------------------------------*/
      19             : 
      20             : static void smoothTransitionDtxToTcx_fx( Word16 synth[], const Word16 output_frame, const Word16 delay_comp );
      21             : static void core_switch_lb_upsamp_fx( Decoder_State *st, Word32 *output );
      22             : 
      23        1852 : void bandwidth_switching_detect_fx(
      24             :     Decoder_State *st_fx /* i/o: encoder state structure */
      25             : )
      26             : {
      27        1852 :     test();
      28        1852 :     test();
      29        1852 :     IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) )
      30             :     {
      31             :         /* there is no BWE in TD stereo secondary channel and in MDCT stereo, IGF is part of the core decoding -> no BW switching -> reset BWS counters */
      32           0 :         st_fx->prev_bws_cnt = 0;
      33           0 :         st_fx->bws_cnt = 0;
      34           0 :         st_fx->bws_cnt1 = 0;
      35           0 :         move16();
      36           0 :         move16();
      37           0 :         move16();
      38             : 
      39           0 :         return;
      40             :     }
      41             :     /* update band-width switching counter */
      42        1852 :     test();
      43        1852 :     test();
      44        1852 :     test();
      45        1852 :     IF( GE_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) )
      46             :     {
      47           2 :         st_fx->bws_cnt1 = 0;
      48           2 :         move16();
      49             :     }
      50        1850 :     ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) )
      51             :     {
      52           0 :         st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); /* Q0 */
      53           0 :         move16();
      54             :     }
      55        1850 :     ELSE IF( st_fx->bws_cnt1 > 0 )
      56             :     {
      57           0 :         IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) )
      58             :         {
      59           0 :             st_fx->bws_cnt = sub( shl( sub( N_NS2W_FRAMES, st_fx->bws_cnt1 ), 1 ), 1 ); /* Q0 */
      60           0 :             move16();
      61             :         }
      62             :         ELSE
      63             :         {
      64           0 :             st_fx->bws_cnt = 0;
      65           0 :             move16();
      66             :         }
      67             : 
      68           0 :         IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) )
      69             :         {
      70           0 :             st_fx->bws_cnt1 = 0;
      71           0 :             move16();
      72             :         }
      73             :         ELSE
      74             :         {
      75           0 :             IF( EQ_16( st_fx->bwidth, SWB ) )
      76             :             {
      77           0 :                 st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 ); /* Q0 */
      78           0 :                 move16();
      79             :             }
      80             :             ELSE
      81             :             {
      82           0 :                 st_fx->bws_cnt1 = 0;
      83           0 :                 move16();
      84             :             }
      85             :         }
      86             :     }
      87             : 
      88             :     /* update band-width switching counter */
      89        1852 :     test();
      90        1852 :     test();
      91        1852 :     test();
      92        1852 :     IF( GE_16( st_fx->bws_cnt, N_WS2N_FRAMES ) )
      93             :     {
      94           2 :         st_fx->bws_cnt = 0;
      95           2 :         move16();
      96             :     }
      97        1850 :     ELSE IF( LT_32( st_fx->total_brate, ACELP_9k60 ) && GT_32( st_fx->last_core_brate, ACELP_9k60 ) && LT_16( st_fx->bwidth, st_fx->last_bwidth ) && EQ_16( st_fx->bwidth, WB ) )
      98             :     {
      99           0 :         st_fx->bws_cnt = add( st_fx->bws_cnt, 1 ); /* Q0 */
     100           0 :         move16();
     101             :     }
     102        1850 :     ELSE IF( st_fx->bws_cnt > 0 )
     103             :     {
     104           0 :         IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) )
     105             :         {
     106           0 :             st_fx->bws_cnt1 = shr( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 1 ); /* Q0 */
     107           0 :             move16();
     108             :         }
     109             :         ELSE
     110             :         {
     111           0 :             st_fx->bws_cnt1 = 0;
     112           0 :             move16();
     113             :         }
     114             : 
     115           0 :         IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) )
     116             :         {
     117           0 :             st_fx->bws_cnt = 0;
     118           0 :             move16();
     119             :         }
     120             :         ELSE
     121             :         {
     122           0 :             IF( EQ_16( st_fx->bwidth, WB ) )
     123             :             {
     124           0 :                 st_fx->bws_cnt = add( st_fx->bws_cnt, 1 );
     125           0 :                 move16();
     126             :             }
     127             :             ELSE
     128             :             {
     129           0 :                 st_fx->bws_cnt = 0;
     130           0 :                 move16();
     131             :             }
     132             :         }
     133             :     }
     134             : 
     135        1852 :     return;
     136             : }
     137             : 
     138             : /*---------------------------------------------------------------------*
     139             :  * Calc_freq_ener_fx()
     140             :  *
     141             :  *
     142             :  *---------------------------------------------------------------------*/
     143             : 
     144        3704 : static Word32 Calc_freq_ener_fx(
     145             :     Word32 L_tmp, /* 2 * st->Q_syn2 */
     146             :     const Word16 Q_syn2 )
     147             : {
     148             :     Word32 enerLL_fx;
     149             :     Word16 exp, tmp;
     150        3704 :     IF( L_tmp == 0 )
     151             :     {
     152          72 :         enerLL_fx = L_deposit_l( 0 );
     153          72 :         move32();
     154             :     }
     155             :     ELSE
     156             :     {
     157        3632 :         exp = norm_l( L_tmp );
     158        3632 :         tmp = extract_h( L_shl( L_tmp, exp ) );
     159        3632 :         exp = sub( exp, sub( 30, shl( Q_syn2, 1 ) ) );
     160             : 
     161        3632 :         tmp = div_s( 16384, tmp );  /* Q15 */
     162        3632 :         L_tmp = L_deposit_h( tmp ); /* Q31 */
     163        3632 :         L_tmp = Isqrt_lc( L_tmp, &exp );
     164             : 
     165        3632 :         enerLL_fx = L_shr( L_tmp, sub( sub( 31, exp ), Q_syn2 ) ); /* st->Q_syn2 */
     166             :     }
     167        3704 :     return enerLL_fx;
     168             : }
     169             : 
     170             : /*---------------------------------------------------------------------*
     171             :  * bw_switching_pre_proc_fx()
     172             :  *
     173             :  *
     174             :  *---------------------------------------------------------------------*/
     175             : 
     176        1852 : void bw_switching_pre_proc_fx(
     177             :     const Word16 *old_syn_12k8_16k_fx, /* i  : ACELP core synthesis at 12.8kHz or 16kHz         Qx*/
     178             :     Decoder_State *st_fx               /* i/o: decoder state structure     */
     179             : )
     180             : {
     181             :     Word16 i;
     182             :     Word16 syn_dct_fx[L_FRAME];
     183             :     Word32 L_tmp;
     184             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     185        1852 :     Flag Overflow = 0;
     186        1852 :     move32();
     187             : #endif
     188             : 
     189        1852 :     IF( st_fx->element_mode > EVS_MONO )
     190             :     {
     191             :     }
     192             : 
     193        1852 :     test();
     194        1852 :     test();
     195        1852 :     IF( EQ_16( st_fx->core, ACELP_CORE ) && !( EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) )
     196             :     {
     197             :         /*----------------------------------------------------------------------*
     198             :          * Calculate tilt of the ACELP core synthesis
     199             :          *----------------------------------------------------------------------*/
     200             : 
     201        1423 :         st_fx->tilt_wb_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( old_syn_12k8_16k_fx, -1, st_fx->L_frame ), 3, &Overflow ), &Overflow ); /* Q11 */
     202        1423 :         move16();
     203             :         /*-------------------------------------------------------------------------------*
     204             :          * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis
     205             :          *-------------------------------------------------------------------------------*/
     206             : 
     207        1423 :         edct_16fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6, st_fx->element_mode );
     208             : 
     209        1423 :         L_tmp = L_deposit_l( 0 );
     210      183567 :         FOR( i = 0; i < L_FRAME / 2; i++ )
     211             :         {
     212      182144 :             L_tmp = L_mac0_o( L_tmp, syn_dct_fx[i], syn_dct_fx[i], &Overflow ); /* (2 * Q_syn2) */
     213             :         }
     214        1423 :         L_tmp = L_shr( L_tmp, 7 );                                              /* 2 * Q_syn2 */
     215        1423 :         st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */
     216        1423 :         move32();
     217        1423 :         L_tmp = L_deposit_l( 0 );
     218      183567 :         FOR( ; i < L_FRAME; i++ )
     219             :         {
     220      182144 :             L_tmp = L_mac0_o( L_tmp, syn_dct_fx[i], syn_dct_fx[i], &Overflow );
     221             :         }
     222        1423 :         L_tmp = L_shr( L_tmp, 7 );                                              /* 2 * Q_syn2 */
     223        1423 :         st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */
     224        1423 :         move32();
     225             :     }
     226             :     ELSE
     227             :     {
     228         429 :         IF( st_fx->hHQ_core->old_is_transient[0] )
     229             :         {
     230          37 :             L_tmp = L_deposit_l( 0 );
     231        1221 :             FOR( i = 0; i < 32; i++ )
     232             :             {
     233        1184 :                 L_tmp = L_mac0_o( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow ); /* 2 * Q_syn2 */
     234             :             }
     235          37 :             L_tmp = L_shr( L_tmp, 5 );                                              /* 2 * Q_syn2 */
     236          37 :             st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */
     237          37 :             move32();
     238          37 :             L_tmp = L_deposit_l( 0 );
     239        1221 :             FOR( ; i < 64; i++ )
     240             :             {
     241        1184 :                 L_tmp = L_mac0_o( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow ); /* 2 * Q_syn2 */
     242             :             }
     243          37 :             L_tmp = L_shr( L_tmp, 5 );                                              /* 2 * Q_syn2 */
     244          37 :             st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */
     245          37 :             move32();
     246             :         }
     247             :         ELSE
     248             :         {
     249         392 :             L_tmp = L_deposit_l( 0 );
     250       50568 :             FOR( i = 0; i < L_FRAME / 2; i++ )
     251             :             {
     252       50176 :                 L_tmp = L_mac0_o( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow ); /* 2 * Q_syn2 */
     253             :             }
     254         392 :             L_tmp = L_shr( L_tmp, 7 );                                              /* 2 * Q_syn2 */
     255         392 :             st_fx->enerLL_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */
     256         392 :             move32();
     257         392 :             L_tmp = L_deposit_l( 0 );
     258       50568 :             FOR( ; i < L_FRAME; i++ )
     259             :             {
     260       50176 :                 L_tmp = L_mac0_o( L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i], &Overflow ); /* 2 * Q_syn2 */
     261             :             }
     262         392 :             L_tmp = L_shr( L_tmp, 7 );                                              /* 2 * Q_syn2 */
     263         392 :             st_fx->enerLH_fx = Calc_freq_ener_fx( L_tmp, shl( st_fx->Q_syn2, 1 ) ); /* Q_syn2 */
     264         392 :             move32();
     265             :         }
     266             :     }
     267             : 
     268             : 
     269        1852 :     test();
     270        1852 :     test();
     271        1852 :     test();
     272        1852 :     test();
     273        1852 :     test();
     274        1852 :     test();
     275        1852 :     test();
     276        1852 :     IF( st_fx->last_bwidth == 0 && LE_16( st_fx->extl, SWB_CNG ) )
     277             :     {
     278           0 :         st_fx->prev_ener_shb_fx = 0;
     279           0 :         move16();
     280           0 :         set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV );
     281             :     }
     282        1852 :     ELSE IF( ( ( st_fx->core == ACELP_CORE && ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st_fx->core, st_fx->last_core ) && NE_16( st_fx->extl, st_fx->last_extl ) ) ) && GE_16( st_fx->last_bwidth, SWB ) )
     283             :     {
     284          43 :         st_fx->attenu_fx = 3277; /* Q15 */
     285          43 :         move16();
     286             :     }
     287             : 
     288        1852 :     test();
     289        1852 :     test();
     290        1852 :     test();
     291        1852 :     test();
     292        1852 :     test();
     293        1852 :     IF( EQ_16( st_fx->last_core, HQ_CORE ) || ( EQ_16( st_fx->last_core, ACELP_CORE ) && !( EQ_16( st_fx->last_extl, WB_TBE ) || EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && GT_32( st_fx->core_brate, ACELP_8k00 ) ) )
     294             :     {
     295        1110 :         st_fx->prev_fractive = 0;
     296        1110 :         move16();
     297             :     }
     298        1852 :     return;
     299             : }
     300             : 
     301             : 
     302             : /*---------------------------------------------------------------------*
     303             :  * core_switching_pre_dec_fx()
     304             :  *
     305             :  * Preprocessing/preparation for ACELP/HQ core switching
     306             :  *---------------------------------------------------------------------*/
     307        1852 : ivas_error core_switching_pre_dec_fx(
     308             :     Decoder_State *st_fx,     /* i/o: decoder state structure     */
     309             :     const Word16 output_frame /* i  : frame length              Q0*/
     310             : )
     311             : {
     312             :     Word16 oldLenClasBuff, newLenClasBuff, i;
     313             :     BPF_DEC_HANDLE hBPF;
     314             :     TD_BWE_DEC_HANDLE hBWE_TD;
     315             :     FD_BWE_DEC_HANDLE hBWE_FD;
     316             :     HQ_DEC_HANDLE hHQ_core;
     317             :     TCX_DEC_HANDLE hTcxDec;
     318             :     ivas_error error;
     319             : 
     320        1852 :     hBWE_TD = st_fx->hBWE_TD;
     321        1852 :     hBWE_FD = st_fx->hBWE_FD;
     322        1852 :     hHQ_core = st_fx->hHQ_core;
     323        1852 :     hBPF = st_fx->hBPF;
     324        1852 :     hTcxDec = st_fx->hTcxDec;
     325             : 
     326        1852 :     error = IVAS_ERR_OK;
     327        1852 :     move32();
     328        1852 :     test();
     329        1852 :     test();
     330        1852 :     test();
     331             :     /* Codec switching */
     332        1852 :     IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && st_fx->element_mode > EVS_MONO ) )
     333             :     {
     334          32 :         st_fx->mem_deemph_fx = st_fx->syn[M]; /* Q_syn */
     335          32 :         move16();
     336          32 :         set16_fx( st_fx->agc_mem_fx, 0, 2 );                     /* Q0 */
     337          32 :         Scale_sig( &( st_fx->mem_deemph_fx ), 1, st_fx->Q_syn ); /* Brings mem_deemph to Qsyn */
     338             : 
     339          32 :         Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/
     340             : 
     341          32 :         st_fx->bpf_off = 1;
     342          32 :         move16();
     343          32 :         Scale_sig( st_fx->hPFstat->mem_pf_in, L_SUBFR, st_fx->Q_syn ); /* Post_filter mem */       /* st_fx->Q_syn*/
     344          32 :         Scale_sig( st_fx->hPFstat->mem_res2, DECMEM_RES2, st_fx->Q_syn ); /* NB post_filter mem */ /* st_fx->Q_syn */
     345          32 :         Scale_sig( st_fx->hPFstat->mem_stp, L_SUBFR, st_fx->Q_syn ); /* Post_filter mem */         /* st_fx->Q_syn */
     346          32 :         IF( hBPF != NULL )
     347             :         {
     348          32 :             set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX );                                             /* BPF mem*/
     349          32 :             hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st_fx->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10  */
     350          32 :             hBPF->pst_mem_deemp_err_fx = 0;
     351          32 :             move16();
     352          32 :             move16();
     353             :         }
     354          32 :         move16();
     355          32 :         st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) ); /* 2 * lp_noise_q - 16 */
     356             : 
     357             :         /* reset old HB synthesis buffer */
     358          32 :         IF( EQ_16( st_fx->last_L_frame, L_FRAME ) )
     359             :         {
     360          20 :             st_fx->old_bwe_delay = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); /* Q0 */
     361             :         }
     362             :         ELSE
     363             :         {
     364          12 :             st_fx->old_bwe_delay = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); /* Q0 */
     365             :         }
     366          32 :         move16();
     367          32 :         set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) );
     368             : 
     369             :         /* reset upd_cnt */
     370          32 :         st_fx->upd_cnt = MAX_UPD_CNT;
     371          32 :         move16();
     372          32 :         st_fx->igf = 0;
     373          32 :         move16();
     374             : 
     375             : 
     376          32 :         test();
     377          32 :         IF( hBWE_TD != NULL && NE_16( st_fx->last_core, ACELP_CORE ) )
     378             :         {
     379          25 :             hBWE_TD->prev_hb_synth_fx_exp = 31;
     380          25 :             move16();
     381             :             /* reset BWE memories */
     382          25 :             set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); /* Q_exc */
     383          25 :             hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 );
     384          25 :             move32();
     385             :         }
     386             : 
     387          32 :         test();
     388          32 :         IF( GE_32( st_fx->output_Fs, 16000 ) && st_fx->hBWE_zero != NULL )
     389             :         {
     390          32 :             hf_synth_reset_fx( st_fx->hBWE_zero );
     391             :         }
     392          32 :         IF( st_fx->hBWE_FD != NULL )
     393             :         {
     394          32 :             set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
     395             :         }
     396          32 :         IF( st_fx->hHQ_core != NULL )
     397             :         {
     398          32 :             set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB );
     399          32 :             set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB );
     400             : 
     401          32 :             set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
     402          32 :             set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX );
     403          32 :             hHQ_core->last_max_pos_pulse = 0;
     404          32 :             move16();
     405             : 
     406          32 :             IF( GT_32( st_fx->output_Fs, 16000 ) )
     407             :             {
     408          32 :                 set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE );
     409             :             }
     410             : 
     411             :             /* pre-echo */
     412          32 :             hHQ_core->pastpre = 0;
     413          32 :             move16();
     414             :         }
     415             :         /* reset the GSC pre echo energy threshold in case of switching */
     416          32 :         IF( st_fx->hGSCDec != NULL )
     417             :         {
     418          32 :             st_fx->hGSCDec->Last_frame_ener_fx = MAX_32;
     419             :         }
     420          32 :         move32();
     421             : 
     422          32 :         test();
     423          32 :         IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) )
     424             :         {
     425          25 :             IF( st_fx->element_mode == EVS_MONO )
     426             :             {
     427          25 :                 st_fx->last_core = HQ_CORE;
     428          25 :                 move16();
     429          25 :                 Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); /* st_fx->q_prev_synth_buffer_fx */
     430             :             }
     431          25 :             IF( hHQ_core != NULL )
     432             :             {
     433          25 :                 set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
     434          25 :                 set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX );
     435          25 :                 hHQ_core->last_max_pos_pulse = 0;
     436          25 :                 move16();
     437             : 
     438          25 :                 set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM );
     439          25 :                 hHQ_core->prev_frm_hfe2 = 0;
     440          25 :                 move16();
     441          25 :                 hHQ_core->prev_stab_hfe2 = 0;
     442          25 :                 move16();
     443             :             }
     444             :         }
     445             : 
     446          32 :         IF( st_fx->prev_bfi != 0 )
     447             :         {
     448             :             Word16 delay_comp;
     449             : 
     450             :             /*switch off Hq Voicing as it was not uodated in MODE2*/
     451           0 :             IF( hHQ_core != NULL )
     452             :             {
     453           0 :                 hHQ_core->oldHqVoicing = 0;
     454           0 :                 hHQ_core->HqVoicing = 0;
     455           0 :                 move16();
     456           0 :                 move16();
     457             :             }
     458             : 
     459           0 :             delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS );
     460             : 
     461           0 :             test();
     462           0 :             test();
     463           0 :             IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16( st_fx->core, HQ_CORE ) )
     464             :             {
     465             : 
     466             :                 Word16 no_col;
     467             :                 Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH];
     468             :                 Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX];
     469             :                 CLDFB_SCALE_FACTOR scaleFactor;
     470             :                 Word32 workBuffer[128 * 3];
     471             : 
     472           0 :                 FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ )
     473             :                 {
     474           0 :                     set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
     475           0 :                     set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
     476           0 :                     realBuffer[i] = realBufferTmp[i];
     477           0 :                     move32();
     478           0 :                     imagBuffer[i] = imagBufferTmp[i];
     479           0 :                     move32();
     480             :                 }
     481             : 
     482           0 :                 no_col = s_min( st_fx->cldfbAna->no_col, idiv1616( sub( add( delay_comp, st_fx->cldfbAna->no_channels ), 1 ), st_fx->cldfbAna->no_channels ) ); /* Q0 */
     483             : 
     484             :                 /* CLDFB analysis of the synthesis at internal sampling rate */
     485           0 :                 IF( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK )
     486             :                 {
     487           0 :                     return error;
     488             :                 }
     489           0 :                 cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, hTcxDec->syn_Overl, 0, no_col, workBuffer );
     490           0 :                 cldfb_restore_memory( st_fx->cldfbAna );
     491             : 
     492           0 :                 scaleFactor.hb_scale = scaleFactor.lb_scale;
     493           0 :                 move16();
     494             : 
     495             :                 /* CLDFB synthesis of the combined signal */
     496           0 :                 IF( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK )
     497             :                 {
     498           0 :                     return error;
     499             :                 }
     500           0 :                 cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, hHQ_core->fer_samples_fx, 0, no_col, workBuffer );
     501           0 :                 cldfb_restore_memory( st_fx->cldfbSyn );
     502             :             }
     503             : 
     504           0 :             test();
     505           0 :             test();
     506           0 :             IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16( st_fx->core, HQ_CORE ) )
     507             :             {
     508           0 :                 lerp( hTcxDec->syn_Overl, hHQ_core->fer_samples_fx + delay_comp, shr( st_fx->output_frame_fx, 1 ), shr( st_fx->last_L_frame, 1 ) );
     509             :                 /*Set to zero the remaining part*/
     510           0 :                 set16_fx( hHQ_core->fer_samples_fx + delay_comp + shr( st_fx->output_frame_fx, 1 ), 0, shr( st_fx->output_frame_fx, 1 ) - delay_comp );
     511             :             }
     512             :         }
     513             : 
     514          32 :         st_fx->use_acelp_preq = 0;
     515          32 :         move16();
     516          32 :         st_fx->reset_mem_AR = 0;
     517          32 :         move16();
     518             :     }
     519             : 
     520             :     /*FEC*/
     521        1852 :     IF( LE_16( st_fx->L_frame, L_FRAME16k ) )
     522             :     {
     523        1852 :         test();
     524        1852 :         IF( LE_16( st_fx->last_L_frame, L_FRAME16k ) && NE_16( st_fx->core, HQ_CORE ) )
     525             :         {
     526        1423 :             IF( NE_16( st_fx->L_frame, st_fx->last_L_frame ) )
     527             :             {
     528           0 :                 IF( GT_16( st_fx->L_frame, st_fx->last_L_frame ) )
     529             :                 {
     530           0 :                     oldLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st_fx->last_L_frame, getInvFrameLen( st_fx->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ );
     531           0 :                     newLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
     532           0 :                     move16();
     533             :                 }
     534             :                 ELSE
     535             :                 {
     536           0 :                     oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
     537           0 :                     move16();
     538           0 :                     newLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st_fx->L_frame, getInvFrameLen( st_fx->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ );
     539             :                 }
     540           0 :                 lerp( &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff );
     541             :             }
     542             :         }
     543             :         ELSE
     544             :         {
     545         429 :             set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM );
     546         429 :             st_fx->classifier_Q_mem_syn = 0;
     547         429 :             move16();
     548             :         }
     549             :     }
     550             : 
     551             :     /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores
     552             :        within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */
     553        1852 :     test();
     554        1852 :     test();
     555        1852 :     IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) )
     556             :     {
     557          29 :         st_fx->last_ppp_mode_dec = 0;
     558          29 :         move16();
     559          29 :         st_fx->last_nelp_mode_dec = 0;
     560          29 :         move16();
     561             :     }
     562             : 
     563        1852 :     test();
     564        1852 :     test();
     565        1852 :     test();
     566        1852 :     IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || LE_32( st_fx->last_total_brate, PPP_NELP_2k80 ) ) )
     567             :     {
     568          31 :         st_fx->act_count = 3;
     569          31 :         move16();
     570          31 :         st_fx->uv_count = 0;
     571          31 :         move16();
     572             :     }
     573             : 
     574        1852 :     test();
     575        1852 :     test();
     576        1852 :     IF( ( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) )
     577             :     {
     578          29 :         test();
     579          29 :         IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) )
     580             :         {
     581           0 :             st_fx->hPFstat->reset = 1;
     582           0 :             move16();
     583             :         }
     584             : 
     585          29 :         IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     586             :         {
     587          11 :             Copy( TRWB2_Ave_fx, st_fx->lsf_old_fx, M );           /* Q2.56 */
     588          11 :             Copy( TRWB2_Ave_fx, st_fx->lsfoldbfi1_fx, M );        /* Q2.56 */
     589          11 :             Copy( TRWB2_Ave_fx, st_fx->lsfoldbfi0_fx, M );        /* Q2.56*/
     590          11 :             Copy( TRWB2_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); /* Q2.56 */
     591          11 :             lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_16k );
     592             :         }
     593             :         ELSE
     594             :         {
     595          18 :             Copy( TRWB_Ave_fx, st_fx->lsf_old_fx, M ); /* init of LSP */ /* Q2.56 */
     596          18 :             Copy( TRWB_Ave_fx, st_fx->lsfoldbfi1_fx, M );                /* Q2.56 */
     597          18 :             Copy( TRWB_Ave_fx, st_fx->lsfoldbfi0_fx, M );                /* Q2.56 */
     598          18 :             Copy( TRWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M );         /* Q2.56 */
     599          18 :             lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX );
     600             :         }
     601             : 
     602             : 
     603          29 :         set16_fx( st_fx->agc_mem_fx, 0, 2 );
     604          29 :         st_fx->mem_deemph_fx = 0;
     605          29 :         move16();
     606          29 :         IF( !st_fx->last_con_tcx )
     607             :         {
     608          29 :             set16_fx( st_fx->mem_syn2_fx, 0, M );
     609             :         }
     610          29 :         set16_fx( st_fx->mem_syn1_fx, 0, M );
     611          29 :         IF( hBWE_TD != NULL )
     612             :         {
     613          29 :             hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
     614          29 :             move16();
     615             :         }
     616             :         /* Reset ACELP parameters */
     617          29 :         set16_fx( st_fx->mem_MA_fx, 0, M );
     618          29 :         IF( EQ_32( st_fx->sr_core, INT_FS_16k ) )
     619             :         {
     620          11 :             Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); /* Q2.56 */
     621             :         }
     622             :         ELSE
     623             :         {
     624          18 :             Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); /* Q2.56 */
     625             :         }
     626          29 :         st_fx->tilt_code_fx = 0;
     627          29 :         move16();
     628          29 :         st_fx->gc_threshold_fx = 0;
     629          29 :         move16();
     630          29 :         st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); /* Q16 */
     631          29 :         move32();
     632          29 :         set16_fx( st_fx->dm_fx.prev_gain_pit, 0, 6 );
     633          29 :         st_fx->dm_fx.prev_state = 0;
     634          29 :         move16();
     635             : 
     636          29 :         st_fx->last_coder_type = GENERIC;
     637          29 :         move16();
     638             : 
     639          29 :         frame_ener_fx( output_frame, UNVOICED_CLAS, st_fx->previoussynth_fx, -1, &st_fx->enr_old_fx, 1, 0, 0, 0 );
     640          29 :         st_fx->lp_gainp_fx = 0;
     641          29 :         move16();
     642             : 
     643             :         /* the sqrt below needs to be changed to use basop Sqrt16 */
     644             :         /*st_fx->lp_gainc_fx = (float)sqrt( st_fx->lp_ener_fx ); */
     645          29 :         IF( st_fx->lp_ener_fx != 0 )
     646             :         {
     647             :             Word32 L_tmp;
     648             :             Word16 tmp, exp;
     649           0 :             exp = norm_l( st_fx->lp_ener_fx ); /* In Q6 */
     650           0 :             tmp = extract_h( L_shl( st_fx->lp_ener_fx, exp ) );
     651           0 :             exp = sub( exp, 30 - 6 );
     652             : 
     653           0 :             tmp = div_s( 16384, tmp );
     654           0 :             L_tmp = L_deposit_h( tmp );
     655           0 :             L_tmp = Isqrt_lc( L_tmp, &exp );
     656             : 
     657           0 :             st_fx->lp_gainc_fx = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */
     658           0 :             move16();
     659             :         }
     660             : 
     661             : 
     662          29 :         st_fx->last_voice_factor_fx = 0;
     663          29 :         move16();
     664          29 :         st_fx->Last_GSC_noisy_speech_flag = 0;
     665          29 :         move16();
     666             : 
     667             :         /* reset CLDFB memories */
     668          29 :         cldfb_reset_memory( st_fx->cldfbAna );
     669          29 :         cldfb_reset_memory( st_fx->cldfbBPF );
     670          29 :         cldfb_reset_memory( st_fx->cldfbSyn );
     671             : 
     672             :         /* reset TBE memories */
     673          29 :         test();
     674          29 :         test();
     675             : 
     676          29 :         IF( !st_fx->last_con_tcx && !( ( EQ_16( st_fx->last_core, HQ_CORE ) ) && st_fx->element_mode > EVS_MONO ) )
     677             :         {
     678          29 :             set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC );
     679             :         }
     680           0 :         ELSE IF( LT_16( st_fx->L_frame, L_FRAME16k ) )
     681             :         {
     682             :             /* resample from 16kHz to 12.8kHZ */
     683           0 :             synth_mem_updt2( st_fx->L_frame, L_FRAME16k, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC );
     684             :         }
     685             : 
     686          29 :         IF( hBWE_TD != NULL )
     687             :         {
     688          29 :             set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
     689             :         }
     690             : 
     691          29 :         test();
     692          29 :         IF( GE_32( st_fx->output_Fs, 16000L ) && st_fx->hBWE_zero != NULL )
     693             :         {
     694          29 :             hf_synth_reset_fx( st_fx->hBWE_zero );
     695             :         }
     696          29 :         IF( hBWE_FD != NULL )
     697             :         {
     698          29 :             set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) );
     699             :         }
     700             :     }
     701             : 
     702        1852 :     test();
     703        1852 :     test();
     704        1852 :     test();
     705        1852 :     test();
     706        1852 :     test();
     707        1852 :     IF( hHQ_core != NULL && EQ_16( st_fx->core, HQ_CORE ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) || ( st_fx->element_mode != EVS_MONO && NE_16( st_fx->last_core, HQ_CORE ) ) ) )
     708             :     {
     709          24 :         set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB );
     710          24 :         set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB );
     711             : 
     712          24 :         set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
     713          24 :         set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX );
     714          24 :         hHQ_core->last_max_pos_pulse = 0;
     715          24 :         move16();
     716             : 
     717          24 :         set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM );
     718          24 :         hHQ_core->prev_frm_hfe2 = 0;
     719          24 :         hHQ_core->prev_stab_hfe2 = 0;
     720          24 :         move16();
     721          24 :         move16();
     722          24 :         IF( GT_32( st_fx->output_Fs, 16000 ) )
     723             :         {
     724          24 :             set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE );
     725             :         }
     726             : 
     727          24 :         if ( st_fx->element_mode != EVS_MONO )
     728             :         {
     729             :         }
     730             :         else
     731             :         {
     732          24 :             set16_fx( hHQ_core->old_out_fx, 0, output_frame );
     733          24 :             hHQ_core->Q_old_wtda_LB = 15;
     734          24 :             hHQ_core->Q_old_wtda = 15;
     735          24 :             move16();
     736             :         }
     737             :     }
     738             : 
     739        1852 :     test();
     740             :     /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */
     741        1852 :     IF( hHQ_core != NULL )
     742             :     {
     743        1852 :         hHQ_core->pastpre = sub( hHQ_core->pastpre, 1 ); /* Q0 */
     744        1852 :         move16();
     745        1852 :         IF( hHQ_core->pastpre <= 0 )
     746             :         {
     747        1773 :             reset_preecho_dec_fx( hHQ_core );
     748             :         }
     749             :     }
     750        1852 :     IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) )
     751             :     {
     752           0 :         st_fx->VAD = 0;
     753           0 :         move16();
     754           0 :         st_fx->m_frame_type = ZERO_FRAME;
     755           0 :         move16();
     756             :     }
     757        1852 :     ELSE IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) )
     758             :     {
     759           0 :         st_fx->VAD = 0;
     760           0 :         move16();
     761           0 :         st_fx->m_frame_type = SID_FRAME;
     762           0 :         move16();
     763             :     }
     764             :     ELSE
     765             :     {
     766        1852 :         st_fx->VAD = 1;
     767        1852 :         move16();
     768        1852 :         st_fx->m_frame_type = ACTIVE_FRAME;
     769        1852 :         move16();
     770             :     }
     771             : 
     772             :     /*switch on CNA on active frames*/
     773        1852 :     IF( st_fx->element_mode == EVS_MONO ) /* for IVAS modes, st->flag_cna is set earlier */
     774             :     {
     775        1852 :         test();
     776        1852 :         test();
     777        1852 :         test();
     778        1852 :         test();
     779        1852 :         test();
     780        1852 :         test();
     781        1852 :         IF( NE_16( st_fx->core, AMR_WB_CORE ) && st_fx->VAD && LE_32( st_fx->total_brate, CNA_MAX_BRATE ) )
     782             :         {
     783         786 :             st_fx->flag_cna = 1;
     784         786 :             move16();
     785             :         }
     786        1066 :         ELSE IF( EQ_16( st_fx->core, AMR_WB_CORE ) && st_fx->VAD && LE_32( st_fx->total_brate, ACELP_8k85 ) )
     787             :         {
     788           0 :             st_fx->flag_cna = 1;
     789           0 :             move16();
     790             :         }
     791        1066 :         ELSE IF( st_fx->VAD || ( EQ_16( st_fx->cng_type, FD_CNG ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) )
     792             :         {
     793        1066 :             st_fx->flag_cna = 0;
     794        1066 :             move16();
     795             :         }
     796             :     }
     797        1852 :     if ( EQ_16( st_fx->core, AMR_WB_CORE ) )
     798             :     {
     799           0 :         st_fx->cng_type = LP_CNG;
     800           0 :         move16();
     801             :     }
     802             : 
     803        1852 :     test();
     804        1852 :     test();
     805        1852 :     test();
     806        1852 :     test();
     807        1852 :     IF( st_fx->hFdCngDec && ( ( NE_16( st_fx->last_L_frame, st_fx->L_frame ) ) ||
     808             :                               ( NE_16( st_fx->hFdCngDec->hFdCngCom->frameSize, st_fx->L_frame ) ) ||
     809             :                               st_fx->ini_frame == 0 || NE_16( st_fx->bwidth, st_fx->last_bwidth ) ) )
     810             :     {
     811             : 
     812           2 :         IF( NE_16( st_fx->core, AMR_WB_CORE ) )
     813             :         {
     814             :             Word32 tmp;
     815             : 
     816           2 :             tmp = st_fx->total_brate;
     817           2 :             move32();
     818           2 :             test();
     819           2 :             if ( EQ_16( st_fx->rf_flag, 1 ) && EQ_32( st_fx->total_brate, ACELP_13k20 ) )
     820             :             {
     821           0 :                 tmp = ACELP_9k60;
     822           0 :                 move32();
     823             :             }
     824           2 :             configureFdCngDec_fx( st_fx->hFdCngDec, st_fx->bwidth, tmp, st_fx->L_frame, st_fx->last_L_frame, st_fx->element_mode );
     825             :         }
     826             :         ELSE
     827             :         {
     828           0 :             configureFdCngDec_fx( st_fx->hFdCngDec, 1, ACELP_8k00, st_fx->L_frame, st_fx->last_L_frame, st_fx->element_mode );
     829             : 
     830           0 :             if ( st_fx->VAD )
     831             :             {
     832           0 :                 st_fx->hFdCngDec->hFdCngCom->CngBitrate = st_fx->total_brate;
     833           0 :                 move32();
     834             :             }
     835             :         }
     836             : 
     837           2 :         test();
     838           2 :         test();
     839           2 :         IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && LE_16( st_fx->L_frame, L_FRAME16k ) && LE_16( st_fx->last_L_frame, L_FRAME16k ) )
     840             :         {
     841           0 :             test();
     842           0 :             IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) )
     843             :             {
     844             :             }
     845             : 
     846           0 :             lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st_fx->L_frame, 1 ), shl( st_fx->last_L_frame, 1 ) );
     847           0 :             test();
     848           0 :             IF( LE_32( st_fx->total_brate, SID_2k40 ) && LE_32( st_fx->last_total_brate, SID_2k40 ) )
     849             :             {
     850           0 :                 lerp( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth, st_fx->hFdCngDec->hFdCngCom->olapBufferSynth, shl( st_fx->L_frame, 1 ), shl( st_fx->last_L_frame, 1 ) );
     851           0 :                 IF( EQ_16( st_fx->L_frame, L_FRAME ) )
     852             :                 {
     853           0 :                     FOR( i = 0; i < shl( st_fx->L_frame, 1 ); i++ )
     854             :                     {
     855           0 :                         st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i], 20480 /* Q15*/ ); /* q_olapBuffer */
     856           0 :                         move16();
     857             :                     }
     858             :                 }
     859             :                 ELSE
     860             :                 {
     861           0 :                     FOR( i = 0; i < shl( st_fx->L_frame, 1 ); i++ )
     862             :                     {
     863           0 :                         st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( shl( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth[i], 1 ), 26214 /* Q14*/ ); /* q_olapBuffer */
     864           0 :                         move16();
     865             :                     }
     866             :                 }
     867             :             }
     868             :         }
     869             :     }
     870             : 
     871        1852 :     return error;
     872             : }
     873             : 
     874             : /*---------------------------------------------------------------------*
     875             :  * core_switching_post_dec()
     876             :  *
     877             :  * Postprocessing for ACELP/HQ core switching
     878             :  *---------------------------------------------------------------------*/
     879             : 
     880        1852 : ivas_error core_switching_post_dec_fx(
     881             :     Decoder_State *st_fx,             /* i/o: decoder state structure     */
     882             :     Word16 *synth,                    /* i/o: output synthesis                  Qsynth*/
     883             :     const Word16 output_frame,        /* i  : frame length                Q0*/
     884             :     const Word16 core_switching_flag, /* i  : ACELP->HQ switching flag    Q0*/
     885             :     const Word16 last_element_mode,   /* i  : element mode of previous frame      Q0*/
     886             :     Word16 *Qsynth                    /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */
     887             : )
     888             : {
     889             :     Word16 i, delay_comp, delta;
     890             :     Word16 tmpF, tmp, Fs_kHz, shift, *ptmp1, *ptmp2;
     891             :     Word32 L_tmp;
     892             :     Word16 synth_subfr_out[SWITCH_MAX_GAP], synth_subfr_bwe[SWITCH_MAX_GAP];
     893             :     Word16 mem_synth[NS2SA( 16000, DELAY_CLDFB_NS ) + 2];
     894             :     Word16 Qtmp;
     895             :     Word16 Qsubfr;
     896             :     TD_BWE_DEC_HANDLE hBWE_TD;
     897             :     FD_BWE_DEC_HANDLE hBWE_FD;
     898             :     HQ_DEC_HANDLE hHQ_core;
     899             :     ivas_error error;
     900             : 
     901             :     (void) ( last_element_mode );
     902        1852 :     hBWE_TD = st_fx->hBWE_TD;
     903        1852 :     hBWE_FD = st_fx->hBWE_FD;
     904        1852 :     hHQ_core = st_fx->hHQ_core;
     905        1852 :     error = IVAS_ERR_OK;
     906        1852 :     move32();
     907             : 
     908             :     /* Rescale synthesis in Q0 to avoid multiple rescaling after */
     909        1852 :     tmp = Find_Max_Norm16( synth, output_frame );
     910        1852 :     Scale_sig( synth, output_frame, tmp );
     911        1852 :     *Qsynth = add( *Qsynth, tmp );
     912        1852 :     move16();
     913             : 
     914        1852 :     test();
     915        1852 :     test();
     916        1852 :     test();
     917        1852 :     IF( st_fx->core == ACELP_CORE && st_fx->bfi && hHQ_core != NULL && !st_fx->con_tcx )
     918             :     {
     919           0 :         if ( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK )
     920             :         {
     921           0 :             return error;
     922             :         } /*the output at Q0*/
     923             :     }
     924             : 
     925             :     /* set multiplication factor according to the sampling rate */
     926        1852 :     tmp = extract_l( L_shr( st_fx->output_Fs, 13 ) ); /* Q0 */
     927        1852 :     Fs_kHz = shl( add( tmp, 1 ), 3 );                 /* Q0 */
     928             : 
     929        1852 :     delta = 1;
     930        1852 :     move16();
     931        1852 :     if ( GE_16( output_frame, L_FRAME16k ) )
     932             :     {
     933        1852 :         delta = shr( Fs_kHz, 3 ); /* Q0 */
     934             :     }
     935             : 
     936             :     /* set delay compensation between HQ synthesis and ACELP synthesis */
     937        1852 :     delay_comp = i_mult2( delta, HQ_DELAY_COMP ); /* Q0 */
     938             : 
     939        1852 :     IF( EQ_16( st_fx->core, HQ_CORE ) )
     940             :     {
     941         429 :         st_fx->use_acelp_preq = 0;
     942         429 :         move16();
     943             :         /* rescaling to the min exp of the 2 */
     944             :         /* Qtmp=s_min(*Qsynth,st_fx->Q_old_postdec);
     945             :          Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth));
     946             :          Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec));*/
     947             : 
     948         429 :         hBWE_FD->mem_deemph_old_syn_fx = 0;
     949         429 :         move16();
     950             : 
     951         429 :         test();
     952         429 :         test();
     953         429 :         test();
     954         429 :         IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) )
     955             :         {
     956          24 :             if ( ( error = acelp_core_switch_dec_fx( st_fx, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, &Qsubfr ) ) != IVAS_ERR_OK )
     957             :             {
     958           0 :                 return error;
     959             :             }
     960             :         }
     961         429 :         test();
     962         429 :         test();
     963         429 :         IF( core_switching_flag && EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi )
     964             :         {
     965           0 :             Copy( st_fx->delay_buf_out_fx, synth_subfr_out, delay_comp ); /* hHQ_core->Q_old_postdec */
     966           0 :             Qsubfr = hHQ_core->Q_old_postdec;
     967           0 :             move16();
     968             :         }
     969             : 
     970             :         /* delay HQ synthesis to synchronize with ACELP synthesis */
     971             :         /* rescaling to the min exp of the 2 */
     972         429 :         Qtmp = s_min( *Qsynth, hHQ_core->Q_old_postdec );
     973         429 :         Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); /* Qtmp */
     974         429 :         *Qsynth = Qtmp;
     975         429 :         move16();
     976         429 :         Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( Qtmp, hHQ_core->Q_old_postdec ) ); /* Qtmp */
     977         429 :         hHQ_core->Q_old_postdec = Qtmp;
     978         429 :         move16();
     979         429 :         delay_signal_fx( synth, output_frame, st_fx->delay_buf_out_fx, delay_comp ); /* Qsynth, Q0 */
     980             : 
     981         429 :         test();
     982         429 :         test();
     983         429 :         test();
     984         429 :         test();
     985         429 :         test();
     986         429 :         test();
     987         429 :         test();
     988         429 :         test();
     989         429 :         test();
     990         429 :         test();
     991         429 :         test();
     992         429 :         IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) )
     993             :         {
     994             :             /* mem_over_hp_fx : Qsubfr */
     995          24 :             core_switching_OLA_fx( mem_synth, st_fx->last_L_frame, st_fx->output_Fs, synth, synth_subfr_out, synth_subfr_bwe, output_frame, st_fx->bwidth, Qsynth, &Qsubfr );
     996             :         }
     997         405 :         ELSE IF( core_switching_flag && EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi ) /* HQ | ACELP | TRANSITION  with ACELP frame lost */
     998             :         {
     999             :             /* Overlapp between old->out (stocked in st_fx->fer_samples)and good HQ frame on L/2 */
    1000           0 :             ptmp1 = &synth[delay_comp]; /* Qsynth */
    1001           0 :             shift = i_mult2( Fs_kHz, 10 );
    1002           0 :             tmp = i_mult2( delta, shr( N16_CORE_SW, 1 ) );
    1003             : 
    1004           0 :             Scale_sig( hHQ_core->fer_samples_fx, output_frame, *Qsynth ); /* Qsynth */
    1005           0 :             ptmp2 = &hHQ_core->fer_samples_fx[tmp];
    1006           0 :             tmp = div_s( 1, shift ); /*Q15*/
    1007           0 :             tmpF = 0;
    1008           0 :             move16();
    1009             : 
    1010           0 :             FOR( i = 0; i < shift; i++ )
    1011             :             {
    1012           0 :                 L_tmp = L_mult( ( *ptmp1 ), tmpF );                                                           /*Qsynth + 16*/
    1013           0 :                 *ptmp1 = round_fx_sat( L_mac_sat( L_tmp, add_sat( sub( 24576, tmpF ), 8192 ), ( *ptmp2 ) ) ); /*Qsynth*/
    1014           0 :                 ptmp1++;
    1015           0 :                 ptmp2++;
    1016           0 :                 tmpF = add( tmpF, tmp );
    1017             :             }
    1018             :         }
    1019         405 :         ELSE IF( ( !core_switching_flag && EQ_16( st_fx->core, HQ_CORE ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* ACELP | TRANSITION | HQ with TRANSITION lost */
    1020             :                  || ( core_switching_flag && st_fx->prev_bfi && NE_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) ) )
    1021             :         {
    1022             :             /* Overlapp between CELP estimation (BFI) and good HQ frame on L/2 */
    1023           0 :             shift = i_mult2( Fs_kHz, 10 );
    1024           0 :             tmp = div_s( 1, shift ); /*Q15*/
    1025           0 :             tmpF = 0;
    1026           0 :             move16();
    1027           0 :             ptmp1 = synth;
    1028           0 :             Scale_sig( hHQ_core->fer_samples_fx, output_frame, *Qsynth ); /* Qsynth */
    1029           0 :             ptmp2 = hHQ_core->fer_samples_fx;
    1030           0 :             FOR( i = 0; i < shift; i++ )
    1031             :             {
    1032           0 :                 L_tmp = L_mult( ( *ptmp1 ), tmpF );                                                           /*Qsynth + 16*/
    1033           0 :                 *ptmp1 = round_fx_sat( L_mac_sat( L_tmp, add_sat( sub( 24576, tmpF ), 8192 ), ( *ptmp2 ) ) ); /*Qsynth*/
    1034           0 :                 move16();
    1035           0 :                 tmpF = add( tmpF, tmp );
    1036           0 :                 ptmp1++;
    1037           0 :                 ptmp2++;
    1038             :             }
    1039             :         }
    1040             : 
    1041         429 :         hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 );
    1042         429 :         move32();
    1043         429 :         IF( !( EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && EQ_32( st_fx->core_brate, HQ_32k ) ) )
    1044             :         {
    1045         429 :             set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB );
    1046         429 :             set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB );
    1047             :         }
    1048         429 :         Copy_Scale_sig( synth, st_fx->previoussynth_fx, output_frame, negate( *Qsynth ) ); /*scaling of st_fx->previoussynth_fx set at Q0*/
    1049             : 
    1050             :         /*Set post-filtering flag to zero*/
    1051         429 :         st_fx->hPFstat->on = 0;
    1052         429 :         move16();
    1053             :     }
    1054             :     ELSE
    1055             :     {
    1056        1423 :         IF( EQ_16( st_fx->last_core, HQ_CORE ) ) /*  MDCT to ACELP transition */
    1057             :         {
    1058          29 :             Qtmp = s_min( s_min( *Qsynth, hHQ_core->Q_old_postdec ), hHQ_core->Q_old_wtda );
    1059             : 
    1060          29 :             Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) );                                 /* Qsynth */
    1061          29 :             Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( Qtmp, hHQ_core->Q_old_postdec ) ); /* Qtmp */
    1062          29 :             Scale_sig( hHQ_core->old_out_fx, L_FRAME48k, sub( Qtmp, hHQ_core->Q_old_wtda ) );       /* Qtmp */
    1063          29 :             *Qsynth = Qtmp;
    1064          29 :             move16();
    1065          29 :             hHQ_core->Q_old_postdec = Qtmp;
    1066          29 :             move16();
    1067          29 :             hHQ_core->Q_old_wtda = Qtmp;
    1068          29 :             move16();
    1069             : 
    1070          29 :             Copy( st_fx->delay_buf_out_fx, synth, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame     Q0*/
    1071             : 
    1072          29 :             tmp = i_mult2( delta, N_ZERO_8 );
    1073          29 :             shift = i_mult2( Fs_kHz, 3 );
    1074          29 :             test();
    1075          29 :             IF( st_fx->prev_bfi && hHQ_core->HqVoicing )
    1076             :             {
    1077           0 :                 Copy_Scale_sig( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[tmp], shift, *Qsynth ); /* Qsynth */
    1078             :             }
    1079             : 
    1080          29 :             ptmp2 = &hHQ_core->old_out_fx[tmp];
    1081          29 :             tmp = div_s( 1, shift );
    1082          29 :             ptmp1 = &synth[delay_comp];
    1083          29 :             tmpF = 0;
    1084          29 :             move16();
    1085        3341 :             FOR( i = 0; i < shift; i++ )
    1086             :             {
    1087        3312 :                 *ptmp1 = add( mult_r( tmpF, *ptmp1 ), mult_r( sub( 32767, tmpF ), *ptmp2++ ) ); /* Q0 */
    1088        3312 :                 move16();
    1089        3312 :                 ptmp1++;
    1090        3312 :                 tmpF = add( tmpF, tmp );
    1091             :             }
    1092             :         }
    1093             : 
    1094        1423 :         set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP );
    1095        1423 :         hHQ_core->oldHqVoicing = 0;
    1096        1423 :         move16();
    1097             : 
    1098        1423 :         set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM );
    1099        1423 :         hHQ_core->prev_frm_hfe2 = 0;
    1100        1423 :         move16();
    1101        1423 :         hHQ_core->prev_stab_hfe2 = 0;
    1102        1423 :         move16();
    1103             :     }
    1104             : 
    1105             :     /* reset SWB BWE buffers */
    1106        1852 :     test();
    1107        1852 :     test();
    1108        1852 :     test();
    1109        1852 :     IF( st_fx->bws_cnt == 0 || ( st_fx->bws_cnt > 0 && NE_16( st_fx->coder_type, INACTIVE ) && NE_16( st_fx->coder_type, AUDIO ) ) )
    1110             :     {
    1111        1852 :         st_fx->attenu_fx = 3277; /* Q15 */
    1112        1852 :         move16();
    1113             :     }
    1114             : 
    1115        1852 :     test();
    1116        1852 :     test();
    1117        1852 :     test();
    1118        1852 :     test();
    1119        1852 :     test();
    1120        1852 :     test();
    1121        1852 :     test();
    1122        1852 :     test();
    1123        1852 :     test();
    1124        1852 :     test();
    1125        1852 :     test();
    1126        1852 :     test();
    1127        1852 :     test();
    1128        1852 :     IF( ( NE_16( st_fx->last_extl, SWB_BWE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || ( NE_16( st_fx->last_extl, FB_BWE ) && EQ_16( st_fx->extl, FB_BWE ) ) ||
    1129             :         ( ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_extl, SWB_TBE ) ) && st_fx->extl < 0 && NE_16( st_fx->core, HQ_CORE ) ) || ( st_fx->last_core == ACELP_CORE && st_fx->core == ACELP_CORE && ( ( NE_16( st_fx->prev_coder_type, INACTIVE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) || ( NE_16( st_fx->prev_coder_type, AUDIO ) && EQ_16( st_fx->coder_type, AUDIO ) ) ) && st_fx->bws_cnt > 0 ) )
    1130             :     {
    1131           2 :         set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame );
    1132           2 :         hBWE_FD->old_wtda_swb_fx_exp = 0;
    1133           2 :         move16();
    1134           2 :         if ( NE_16( st_fx->last_extl, WB_BWE ) )
    1135             :         {
    1136           2 :             hBWE_FD->prev_mode = NORMAL;
    1137           2 :             move16();
    1138             :         }
    1139             : 
    1140           2 :         hBWE_FD->prev_Energy_fx = 0;
    1141           2 :         move16();
    1142           2 :         hBWE_FD->prev_L_swb_norm = 8;
    1143           2 :         move16();
    1144           2 :         hBWE_FD->prev_frica_flag = 0;
    1145           2 :         move16();
    1146           2 :         set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k );
    1147           2 :         hBWE_FD->prev_td_energy_fx = 0;
    1148           2 :         move16();
    1149           2 :         hBWE_FD->prev_weight_fx = 6554;
    1150           2 :         move16(); /*0.2 in Q15*/
    1151           2 :         hBWE_FD->prev_fb_ener_adjust_fx = 0;
    1152           2 :         move16();
    1153             :     }
    1154             : 
    1155             :     /* reset WB BWE buffers */
    1156        1852 :     test();
    1157        1852 :     IF( NE_16( st_fx->last_extl, WB_BWE ) && EQ_16( st_fx->extl, WB_BWE ) )
    1158             :     {
    1159           0 :         set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame );
    1160             : 
    1161           0 :         test();
    1162           0 :         IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) )
    1163             :         {
    1164           0 :             hBWE_FD->prev_mode = NORMAL;
    1165           0 :             move16();
    1166             :         }
    1167           0 :         hBWE_FD->prev_Energy_wb_fx = 0;
    1168           0 :         move16();
    1169           0 :         hBWE_FD->prev_L_swb_norm = 8;
    1170           0 :         move16();
    1171           0 :         set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k );
    1172           0 :         hBWE_FD->prev_flag = 0;
    1173           0 :         move16();
    1174             :     }
    1175             : 
    1176             :     /* reset SWB TBE buffers */
    1177        1852 :     test();
    1178        1852 :     test();
    1179        1852 :     test();
    1180        1852 :     test();
    1181        1852 :     test();
    1182        1852 :     test();
    1183        1852 :     test();
    1184        1852 :     test();
    1185        1852 :     test();
    1186        1852 :     test();
    1187        1852 :     test();
    1188        1852 :     test();
    1189        1852 :     test();
    1190        1852 :     test();
    1191        1852 :     test();
    1192        1852 :     test();
    1193        1852 :     test();
    1194        1852 :     test();
    1195        1852 :     test();
    1196        1852 :     IF( ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || EQ_16( st_fx->extl, SWB_CNG ) ) &&
    1197             :           ( NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || EQ_16( st_fx->last_core, HQ_CORE ) ) ) ||
    1198             :         ( LT_16( st_fx->bwidth, st_fx->last_bwidth ) && NE_16( st_fx->last_extl, SWB_TBE ) ) || st_fx->old_ppp_mode || ( ( EQ_16( st_fx->prev_coder_type, AUDIO ) || EQ_16( st_fx->prev_coder_type, INACTIVE ) ) && st_fx->bws_cnt > 0 ) || ( st_fx->bws_cnt == 0 && EQ_16( st_fx->prev_bws_cnt, N_WS2N_FRAMES ) ) )
    1199             :     {
    1200          20 :         swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
    1201          20 :                           hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) );
    1202             : 
    1203          20 :         set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 );
    1204          20 :         swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 );
    1205             : 
    1206          20 :         IF( EQ_16( output_frame, L_FRAME16k ) )
    1207             :         {
    1208             :             /* reset in case that SWB TBE layer is transmitted, but the output is 16kHz sampled */
    1209           0 :             set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 );
    1210           0 :             set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 );
    1211             :         }
    1212          20 :         set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN );
    1213          20 :         set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN );
    1214             :     }
    1215        1832 :     ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) &&
    1216             :              ( NE_32( st_fx->last_total_brate, st_fx->total_brate ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) ||
    1217             :                NE_16( st_fx->last_codec_mode, MODE1 ) || NE_16( st_fx->rf_flag, st_fx->rf_flag_last ) ) )
    1218             :     {
    1219           1 :         set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER );
    1220           1 :         set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD );
    1221           1 :         set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER );
    1222           1 :         set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER );
    1223           1 :         hBWE_TD->gain_prec_swb_fx = 16384;
    1224           1 :         move16(); /*Q14 = 1 */
    1225             :     }
    1226             : 
    1227             :     /* Interp_3_2 CNG buffers reset */
    1228        1852 :     test();
    1229        1852 :     test();
    1230        1852 :     test();
    1231        1852 :     IF( st_fx->hTdCngDec != NULL && EQ_32( st_fx->output_Fs, 48000 ) && ( ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) && ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) ) )
    1232             :     {
    1233           0 :         set16_fx( st_fx->hTdCngDec->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN );
    1234             :     }
    1235             : 
    1236             :     /* reset FB TBE buffers */
    1237        1852 :     test();
    1238        1852 :     test();
    1239        1852 :     IF( EQ_16( st_fx->extl, FB_TBE ) && ( NE_16( st_fx->last_extl, FB_TBE ) || NE_16( st_fx->L_frame, st_fx->last_L_frame ) ) )
    1240             :     {
    1241           0 :         set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER );
    1242           0 :         hBWE_TD->fb_tbe_demph_fx = 0;
    1243           0 :         move16();
    1244           0 :         fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx );
    1245             :     }
    1246             : 
    1247             :     /* reset WB TBE buffers */
    1248        1852 :     test();
    1249        1852 :     IF( NE_16( st_fx->last_extl, WB_TBE ) && EQ_16( st_fx->extl, WB_TBE ) )
    1250             :     {
    1251           0 :         wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx );
    1252           0 :         wb_tbe_extras_reset_synth_fx( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx );
    1253             : 
    1254           0 :         set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 );
    1255           0 :         set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD );
    1256           0 :         set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 );
    1257             :     }
    1258             : 
    1259        1852 :     return error;
    1260             : }
    1261             : 
    1262     1029590 : ivas_error core_switching_post_dec_ivas_fx(
    1263             :     Decoder_State *st_fx,               /* i/o: decoder state structure                                                           */
    1264             :     Word16 *synth,                      /* i/o: output synthesis                                                            Qsynth*/
    1265             :     Word32 *output_fx,                  /* i/o: LB synth/upsampled LB synth                                                                                                             Q4*/
    1266             :     Word16 output_mem_fx[],             /* i  : OLA memory from last TCX/HQ frame                                               Qx*/
    1267             :     const Word16 use_cldfb_for_dft,     /* i  : flag to use of CLDFB for DFT Stereo                                             Q0*/
    1268             :     const Word16 output_frame,          /* i  : frame length                                                                    Q0*/
    1269             :     const Word16 core_switching_flag,   /* i  : ACELP->HQ switching flag                                                        Q0*/
    1270             :     const Word16 sba_dirac_stereo_flag, /* i  : signal stereo output for SBA DirAC                                              Q0*/
    1271             :     const Word16 nchan_out,             /* i  : number of output channels                                                       Q0*/
    1272             :     const Word16 last_element_mode,     /* i  : element mode of previous frame                                                  Q0*/
    1273             :     Word16 *Qsynth                      /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */
    1274             : )
    1275             : {
    1276             :     Word16 i, delay_comp, delta, alpha;
    1277             :     Word16 tmpF, tmp, Fs_kHz, shift, *ptmp1, *ptmp2, tmpV, nzeroes;
    1278             :     Word32 L_tmp;
    1279             :     Word16 synth_subfr_out[SWITCH_MAX_GAP], synth_subfr_bwe[SWITCH_MAX_GAP];
    1280             :     Word16 mem_synth[NS2SA( 16000, DELAY_CLDFB_NS ) + 2];
    1281             :     Word16 Qtmp;
    1282             :     Word16 Qsubfr;
    1283             :     TD_BWE_DEC_HANDLE hBWE_TD;
    1284             :     FD_BWE_DEC_HANDLE hBWE_FD;
    1285             :     HQ_DEC_HANDLE hHQ_core;
    1286             :     ivas_error error;
    1287             :     Word16 offset;
    1288             : 
    1289     1029590 :     L_tmp = 0;
    1290     1029590 :     move32();
    1291             : 
    1292     1029590 :     hBWE_TD = st_fx->hBWE_TD;
    1293     1029590 :     hBWE_FD = st_fx->hBWE_FD;
    1294     1029590 :     hHQ_core = st_fx->hHQ_core;
    1295     1029590 :     error = IVAS_ERR_OK;
    1296     1029590 :     move32();
    1297             : 
    1298             :     /* Rescale synthesis in Q0 to avoid multiple rescaling after */
    1299     1029590 :     tmp = Find_Max_Norm16( synth, output_frame );
    1300     1029590 :     Scale_sig( synth, output_frame, tmp ); /* Qsynth + tmp */
    1301     1029590 :     *Qsynth = add( *Qsynth, tmp );
    1302     1029590 :     move16();
    1303             : 
    1304     1029590 :     test();
    1305     1029590 :     test();
    1306     1029590 :     test();
    1307     1029590 :     IF( st_fx->core == ACELP_CORE && st_fx->bfi && hHQ_core != NULL && !st_fx->con_tcx )
    1308             :     {
    1309             :         /*needed to be converted to fixed curretnly using evs implementation not in line*/
    1310        2883 :         if ( ( error = acelp_core_switch_dec_bfi_ivas_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK )
    1311             :         {
    1312           0 :             return error;
    1313             :         } /*the output at Q0*/
    1314             :     }
    1315             : 
    1316             :     /* set multiplication factor according to the sampling rate */
    1317     1029590 :     tmp = extract_l( L_shr( st_fx->output_Fs, 13 ) ); /* Q0 */
    1318     1029590 :     Fs_kHz = shl( add( tmp, 1 ), 3 );
    1319             : 
    1320     1029590 :     delta = 1;
    1321     1029590 :     move16();
    1322     1029590 :     IF( GE_16( output_frame, L_FRAME16k ) )
    1323             :     {
    1324     1029590 :         delta = shr( Fs_kHz, 3 );
    1325             :     }
    1326             : 
    1327             :     /* set delay compensation between HQ synthesis and ACELP synthesis */
    1328     1029590 :     delay_comp = i_mult2( delta, HQ_DELAY_COMP ); /* Q0 */
    1329             :     /*needed to add more condition in if*/
    1330     1029590 :     test();
    1331     1029590 :     test();
    1332     1029590 :     test();
    1333     1029590 :     test();
    1334     1029590 :     test();
    1335     1029590 :     IF( ( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) && ( !sba_dirac_stereo_flag || ( sba_dirac_stereo_flag && EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->cng_type, FD_CNG ) ) ) )
    1336             :     {
    1337      960606 :         test();
    1338      960606 :         test();
    1339      960606 :         test();
    1340      960606 :         test();
    1341      960606 :         test();
    1342      960606 :         IF( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) || ( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) )
    1343      824162 :         {
    1344      824162 :             st_fx->use_acelp_preq = 0;
    1345      824162 :             move16();
    1346             :             /* rescaling to the min exp of the 2 */
    1347             :             /* Qtmp=s_min(*Qsynth,st_fx->Q_old_postdec);
    1348             :              Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth));
    1349             :              Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec));*/
    1350      824162 :             IF( st_fx->hBWE_FD != NULL )
    1351             :             {
    1352      216360 :                 hBWE_FD->mem_deemph_old_syn_fx = 0;
    1353      216360 :                 move16();
    1354             :             }
    1355             : 
    1356      824162 :             test();
    1357      824162 :             IF( st_fx->element_mode == EVS_MONO && EQ_16( st_fx->core, HQ_CORE ) )
    1358             :             {
    1359           0 :                 test();
    1360           0 :                 test();
    1361           0 :                 test();
    1362           0 :                 IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) )
    1363             :                 {
    1364           0 :                     IF( ( error = acelp_core_switch_dec_fx( st_fx, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, &Qsubfr ) ) != IVAS_ERR_OK )
    1365             :                     {
    1366           0 :                         return error;
    1367             :                     }
    1368             :                 }
    1369             : 
    1370           0 :                 test();
    1371           0 :                 test();
    1372           0 :                 IF( core_switching_flag && EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi )
    1373             :                 {
    1374           0 :                     Copy( st_fx->delay_buf_out_fx, synth_subfr_out, delay_comp ); /* hHQ_core->Q_old_postdec */
    1375           0 :                     Qsubfr = hHQ_core->Q_old_postdec;
    1376           0 :                     move16();
    1377             :                 }
    1378             :             }
    1379             :             /* delay HQ synthesis to synchronize with ACELP synthesis */
    1380             :             /* rescaling to the min exp of the 2 */
    1381      824162 :             Word16 NonZero = 1;
    1382      824162 :             move16();
    1383     5093799 :             FOR( i = 0; i < delay_comp; i++ )
    1384             :             {
    1385     5014790 :                 IF( st_fx->delay_buf_out_fx[i] != 0 )
    1386             :                 {
    1387      745153 :                     NonZero = 0;
    1388      745153 :                     move16();
    1389      745153 :                     break;
    1390             :                 }
    1391             :             }
    1392      824162 :             test();
    1393      824162 :             IF( hHQ_core->Q_old_postdec >= 0 || EQ_16( NonZero, 1 ) )
    1394             :             {
    1395      818151 :                 Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); /* Q0 */
    1396      818151 :                 hHQ_core->Q_old_postdec = 0;
    1397      818151 :                 move16();
    1398             :             }
    1399      824162 :             move16();
    1400      824162 :             Qtmp = s_min( *Qsynth, hHQ_core->Q_old_postdec );
    1401      824162 :             Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); /* Qtmp */
    1402      824162 :             *Qsynth = Qtmp;
    1403      824162 :             move16();
    1404      824162 :             Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( Qtmp, hHQ_core->Q_old_postdec ) ); /* Qtmp */
    1405      824162 :             hHQ_core->Q_old_postdec = Qtmp;
    1406      824162 :             move16();
    1407      824162 :             delay_signal_fx( synth, output_frame, st_fx->delay_buf_out_fx, delay_comp ); /* Qsynth, Q0 */
    1408             : 
    1409      824162 :             test();
    1410      824162 :             test();
    1411      824162 :             test();
    1412      824162 :             test();
    1413      824162 :             test();
    1414      824162 :             IF( st_fx->element_mode == EVS_MONO && EQ_16( st_fx->core, HQ_CORE ) )
    1415             :             {
    1416           0 :                 test();
    1417           0 :                 test();
    1418           0 :                 test();
    1419           0 :                 test();
    1420           0 :                 test();
    1421           0 :                 test();
    1422           0 :                 test();
    1423           0 :                 test();
    1424           0 :                 test();
    1425           0 :                 test();
    1426           0 :                 test();
    1427           0 :                 IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) )
    1428             :                 {
    1429             :                     /* mem_over_hp_fx : Qsubfr */
    1430           0 :                     core_switching_OLA_fx( mem_synth, st_fx->last_L_frame, st_fx->output_Fs, synth, synth_subfr_out, synth_subfr_bwe, output_frame, st_fx->bwidth, Qsynth, &Qsubfr );
    1431             :                 }
    1432           0 :                 ELSE IF( core_switching_flag && EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi ) /* HQ | ACELP | TRANSITION  with ACELP frame lost */
    1433             :                 {
    1434             :                     /* Overlapp between old->out (stocked in st_fx->fer_samples)and good HQ frame on L/2 */
    1435           0 :                     ptmp1 = &synth[delay_comp];
    1436           0 :                     shift = i_mult2( Fs_kHz, 10 );
    1437           0 :                     tmp = i_mult2( delta, shr( N16_CORE_SW, 1 ) );
    1438             : 
    1439           0 :                     Scale_sig( hHQ_core->fer_samples_fx, output_frame, *Qsynth ); /* Qsynth */
    1440           0 :                     ptmp2 = &hHQ_core->fer_samples_fx[tmp];
    1441           0 :                     tmp = div_s( 1, shift ); /*Q15*/
    1442           0 :                     tmpF = 0;
    1443           0 :                     move16();
    1444             : 
    1445           0 :                     FOR( i = 0; i < shift; i++ )
    1446             :                     {
    1447           0 :                         L_tmp = L_mult( ( *ptmp1 ), tmpF );                                                           /*Qsynth + 16*/
    1448           0 :                         *ptmp1 = round_fx_sat( L_mac_sat( L_tmp, add_sat( sub( 24576, tmpF ), 8192 ), ( *ptmp2 ) ) ); /*Qsynth*/
    1449           0 :                         ptmp1++;
    1450           0 :                         ptmp2++;
    1451           0 :                         tmpF = add( tmpF, tmp );
    1452             :                     }
    1453             :                 }
    1454           0 :                 ELSE IF( ( !core_switching_flag && EQ_16( st_fx->core, HQ_CORE ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* ACELP | TRANSITION | HQ with TRANSITION lost */
    1455             :                          || ( core_switching_flag && st_fx->prev_bfi && NE_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) ) )
    1456             :                 {
    1457             :                     /* Overlapp between CELP estimation (BFI) and good HQ frame on L/2 */
    1458           0 :                     shift = i_mult2( Fs_kHz, 10 );
    1459           0 :                     tmp = div_s( 1, shift ); /*Q15*/
    1460           0 :                     tmpF = 0;
    1461           0 :                     move16();
    1462           0 :                     ptmp1 = synth;
    1463           0 :                     Scale_sig( hHQ_core->fer_samples_fx, output_frame, *Qsynth ); /* Qsynth */
    1464           0 :                     ptmp2 = hHQ_core->fer_samples_fx;
    1465           0 :                     FOR( i = 0; i < shift; i++ )
    1466             :                     {
    1467           0 :                         L_tmp = L_mult( ( *ptmp1 ), tmpF );                                                           /*Qsynth + 16*/
    1468           0 :                         *ptmp1 = round_fx_sat( L_mac_sat( L_tmp, add_sat( sub( 24576, tmpF ), 8192 ), ( *ptmp2 ) ) ); /*Qsynth*/
    1469           0 :                         move16();
    1470           0 :                         tmpF = add( tmpF, tmp );
    1471           0 :                         ptmp1++;
    1472           0 :                         ptmp2++;
    1473             :                     }
    1474             :                 }
    1475             :             }
    1476      824162 :             ELSE IF( ( ( st_fx->last_core == ACELP_CORE || st_fx->last_core_bfi == ACELP_CORE ) && !( EQ_16( st_fx->prev_bfi, 1 ) && EQ_16( st_fx->last_con_tcx, 1 ) ) ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) )
    1477        7327 :             {
    1478        7327 :                 test();
    1479        7327 :                 test();
    1480        7327 :                 test();
    1481        7327 :                 test();
    1482        7327 :                 test();
    1483        7327 :                 test();
    1484        7327 :                 test();
    1485        7327 :                 test();
    1486        7327 :                 IF( ( ( NE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_core_brate, FRAME_NO_DATA ) ) || ( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) && NE_16( st_fx->element_mode, IVAS_CPE_TD ) ) || EQ_16( nchan_out, 1 ) ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_fx->idchan, 1 ) && ( EQ_16( nchan_out, 1 ) || EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) )
    1487             :                 {
    1488        6795 :                     Scale_sig32( output_fx, L_FRAME48k, Q10 - Q4 ); /* Q10 */
    1489        6795 :                     core_switch_lb_upsamp_fx( st_fx, output_fx );
    1490             :                 }
    1491             : 
    1492        7327 :                 Copy_Scale_sig( st_fx->previoussynth_fx, synth, delay_comp, *Qsynth ); /* Qsynth */
    1493             : 
    1494             :                 /* Overlap between TCX-LB and TCX-FB*/
    1495        7327 :                 Word16 tmpDelta = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS );
    1496             :                 Word32 L_tmp2;
    1497      741370 :                 FOR( i = 0; i < tmpDelta; i++ )
    1498             :                 {
    1499      734043 :                     L_tmp = 0;
    1500      734043 :                     L_tmp2 = 0;
    1501      734043 :                     move32();
    1502      734043 :                     move32();
    1503      734043 :                     tmp = shl( st_fx->previoussynth_fx[i + delay_comp], *Qsynth );
    1504      734043 :                     L_tmp = L_mac0( L_tmp, div_s( i, tmpDelta ), synth[i + delay_comp] ); /* Qsynth */
    1505      734043 :                     L_tmp = L_shl( L_tmp, 1 );
    1506      734043 :                     L_tmp2 = L_mac0( L_tmp2, div_s( sub( tmpDelta, i ), tmpDelta ), tmp ); /* Qsynth */
    1507      734043 :                     L_tmp2 = L_shl( L_tmp2, 1 );
    1508      734043 :                     synth[i + delay_comp] = round_fx( L_add( L_tmp, L_tmp2 ) ); /* Qsynth */
    1509             :                 }
    1510        7327 :                 test();
    1511        7327 :                 test();
    1512        7327 :                 test();
    1513        7327 :                 test();
    1514        7327 :                 IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || ( st_fx->is_ism_format && EQ_16( st_fx->core, TCX_20_CORE ) /* <- means TCX in general, TCX10 is forbidden after ACELP */ ) ) && LE_32( st_fx->last_core_brate, SID_2k40 ) && GT_32( st_fx->core_brate, SID_2k40 ) )
    1515             :                 {
    1516             :                     /* smooth transitions to avoid pops in car noise items */
    1517         607 :                     smoothTransitionDtxToTcx_fx( synth, output_frame, delay_comp );
    1518             :                 }
    1519             : 
    1520             :                 /* Reset memories of CLDFBs */
    1521        7327 :                 IF( st_fx->cldfbAna != NULL )
    1522             :                 {
    1523        7327 :                     IF( NE_16( i_mult( st_fx->cldfbAna->no_channels, st_fx->cldfbAna->no_col ), st_fx->L_frame ) )
    1524             :                     {
    1525         524 :                         configureCldfb_ivas_fx( st_fx->cldfbAna, st_fx->L_frame * FRAMES_PER_SEC );
    1526         524 :                         configureCldfb_ivas_fx( st_fx->cldfbBPF, L_min( 16000, st_fx->L_frame * FRAMES_PER_SEC ) );
    1527             :                     }
    1528             : 
    1529        7327 :                     cldfb_reset_memory_fx( st_fx->cldfbAna );
    1530        7327 :                     cldfb_reset_memory_fx( st_fx->cldfbBPF );
    1531             :                 }
    1532        7327 :                 cldfb_reset_memory_fx( st_fx->cldfbSyn );
    1533             : 
    1534             :                 /* Update memories for CLDFB ana for eventual next ACELP frame */
    1535        7327 :                 IF( st_fx->cldfbAna != NULL )
    1536             :                 {
    1537        7327 :                     delta = st_fx->cldfbAna->no_channels; /* Q0 */
    1538        7327 :                     move16();
    1539        7327 :                     offset = sub( st_fx->cldfbAna->p_filter_length, st_fx->cldfbAna->no_channels ); /* Q0 */
    1540        7327 :                     tmp = div_s( 1, delta );
    1541        7327 :                     alpha = tmp; /* Q15 */
    1542        7327 :                     move16();
    1543      165879 :                     FOR( i = 0; i < delta; i++ )
    1544             :                     {
    1545      317104 :                         st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] =
    1546      158552 :                             Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */
    1547      158552 :                         move32();
    1548      158552 :                         IF( LT_16( alpha, sub( 32767, tmp ) ) )
    1549             :                         {
    1550      147539 :                             alpha = add( alpha, tmp ); /* Q15 */
    1551             :                         }
    1552             :                         ELSE
    1553             :                         {
    1554       11013 :                             alpha = 32767; /* Q15 */
    1555       11013 :                             move16();
    1556             :                         }
    1557             :                     }
    1558        7327 :                     st_fx->cldfbAna->Q_cldfb_state = Q10;
    1559        7327 :                     move16();
    1560             :                 }
    1561             :             }
    1562      816835 :             ELSE IF( st_fx->element_mode != EVS_MONO )
    1563             :             {
    1564             :                 /*needed to be filled with ivas specific code*/
    1565             :                 /* Reset memories of CLDFBs */
    1566      816835 :                 IF( st_fx->cldfbAna != NULL )
    1567             :                 {
    1568      224185 :                     IF( NE_16( i_mult( st_fx->cldfbAna->no_channels, st_fx->cldfbAna->no_col ), st_fx->L_frame ) )
    1569             :                     {
    1570        2282 :                         configureCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) );
    1571        2282 :                         configureCldfb_ivas_fx( st_fx->cldfbBPF, L_min( 16000, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ) );
    1572             :                     }
    1573             : 
    1574      224185 :                     cldfb_reset_memory_fx( st_fx->cldfbAna );
    1575      224185 :                     cldfb_reset_memory_fx( st_fx->cldfbBPF );
    1576             :                 }
    1577             : 
    1578      816835 :                 IF( st_fx->cldfbSyn != NULL )
    1579             :                 {
    1580      816835 :                     cldfb_reset_memory_fx( st_fx->cldfbSyn );
    1581             :                 }
    1582             : 
    1583             :                 /* Update memories for CLDFB ana for eventual next ACELP frame */
    1584             :                 /* Analysis CLDF memory is fed with ramped signal for last slot */
    1585      816835 :                 IF( st_fx->cldfbAna != NULL )
    1586             :                 {
    1587      224185 :                     delta = st_fx->cldfbAna->no_channels;
    1588      224185 :                     move16();
    1589      224185 :                     offset = sub( st_fx->cldfbAna->p_filter_length, st_fx->cldfbAna->no_channels );
    1590      224185 :                     tmp = div_s( 1, delta ); /* Q15 */
    1591      224185 :                     alpha = tmp;             /* Q15 */
    1592      224185 :                     move16();
    1593     6788769 :                     FOR( i = 0; i < delta; i++ )
    1594             :                     {
    1595    13129168 :                         st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] =
    1596     6564584 :                             Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */
    1597     6564584 :                         move32();
    1598     6564584 :                         IF( LT_16( alpha, sub( 32767, tmp ) ) )
    1599             :                         {
    1600     6281296 :                             alpha = add( alpha, tmp );
    1601             :                         }
    1602             :                         ELSE
    1603             :                         {
    1604      283288 :                             alpha = 32767; /* Q15 */
    1605      283288 :                             move16();
    1606             :                         }
    1607             :                     }
    1608      224185 :                     st_fx->cldfbAna->Q_cldfb_state = Q10;
    1609      224185 :                     move16();
    1610             :                 }
    1611             :             }
    1612      824162 :             IF( st_fx->hBWE_TD != NULL )
    1613             :             {
    1614      216360 :                 hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 );
    1615      216360 :                 move32();
    1616             :             }
    1617      824162 :             IF( st_fx->hHQ_core != NULL && !( EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && EQ_32( st_fx->core_brate, HQ_32k ) ) )
    1618             :             {
    1619      824162 :                 set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB );
    1620      824162 :                 set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB );
    1621             :             }
    1622      824162 :             Copy_Scale_sig( synth, st_fx->previoussynth_fx, output_frame, negate( *Qsynth ) ); /*scaling of st_fx->previoussynth_fx set at Q0*/
    1623             : 
    1624             :             /*Set post-filtering flag to zero*/
    1625      824162 :             IF( st_fx->hBPF != NULL )
    1626             :             {
    1627      207462 :                 st_fx->hPFstat->on = 0;
    1628      207462 :                 move16();
    1629             :             }
    1630             :         }
    1631             :         ELSE
    1632             :         {
    1633      136444 :             test();
    1634      136444 :             test();
    1635      136444 :             IF( EQ_16( st_fx->last_core, HQ_CORE ) || st_fx->last_core == TCX_20_CORE || st_fx->last_core == TCX_10_CORE ) /*  MDCT to ACELP transition */
    1636             :             {
    1637        5989 :                 Qtmp = s_min( *Qsynth, 0 );
    1638        5989 :                 IF( hHQ_core != NULL )
    1639             :                 {
    1640        5980 :                     Qtmp = s_min( s_min( *Qsynth, hHQ_core->Q_old_postdec ), hHQ_core->Q_old_wtda );
    1641             :                 }
    1642             : 
    1643        5989 :                 Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); /* Qtmp */
    1644        5989 :                 Scale_sig( st_fx->delay_buf_out_fx, delay_comp, Qtmp ); /*delay buff_out_fx is Q0*/
    1645        5989 :                 IF( hHQ_core != NULL )
    1646             :                 {
    1647        5980 :                     Scale_sig( hHQ_core->old_out_fx, L_FRAME48k, sub( Qtmp, hHQ_core->Q_old_wtda ) ); /* Qtmp */
    1648        5980 :                     hHQ_core->Q_old_postdec = Qtmp;
    1649        5980 :                     move16();
    1650        5980 :                     hHQ_core->Q_old_wtda = Qtmp;
    1651        5980 :                     move16();
    1652             :                 }
    1653        5989 :                 IF( output_mem_fx != NULL )
    1654             :                 {
    1655         936 :                     Scale_sig( output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), Qtmp ); /* Qtmp */
    1656             :                 }
    1657        5989 :                 *Qsynth = Qtmp;
    1658        5989 :                 move16();
    1659             : 
    1660        5989 :                 Copy( st_fx->delay_buf_out_fx, synth, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame Q0*/
    1661             : 
    1662        5989 :                 nzeroes = i_mult2( delta, N_ZERO_8 );
    1663        5989 :                 shift = i_mult2( Fs_kHz, 3 );
    1664        5989 :                 test();
    1665        5989 :                 test();
    1666        5989 :                 test();
    1667        5989 :                 IF( st_fx->prev_bfi && st_fx->hHQ_core != NULL && hHQ_core->HqVoicing && EQ_16( st_fx->last_core, HQ_CORE ) )
    1668             :                 {
    1669           0 :                     Copy_Scale_sig( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nzeroes], shift, *Qsynth ); /* Qsynth */
    1670             :                 }
    1671             : 
    1672        5989 :                 tmp = div_s( 1, shift );
    1673        5989 :                 tmpF = 0;
    1674        5989 :                 move16();
    1675        5989 :                 IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->hHQ_core == NULL )
    1676             :                 {
    1677           9 :                     ptmp2 = output_mem_fx;
    1678           9 :                     ptmp1 = &synth[delay_comp];
    1679        1065 :                     FOR( i = 0; i < NS2SA_FX2( st_fx->output_Fs, 3000000 ); i++ )
    1680             :                     {
    1681        1056 :                         *ptmp1 = add( mult_r( tmpF, *ptmp1 ), mult_r( sub( 32767, tmpF ), *ptmp2 ) ); /* Qsynth */
    1682        1056 :                         move16();
    1683        1056 :                         ptmp1++;
    1684        1056 :                         ptmp2++;
    1685        1056 :                         tmpF = add( tmpF, tmp ); /* Q15 */
    1686             :                     }
    1687             :                 }
    1688        5980 :                 ELSE IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->prev_bfi )
    1689             :                 {
    1690          14 :                     ptmp2 = &hHQ_core->old_out_fx[nzeroes]; /* Qsynth */
    1691          14 :                     ptmp1 = &synth[delay_comp];
    1692        1742 :                     FOR( i = 0; i < NS2SA_FX2( st_fx->output_Fs, 3000000 ); i++ )
    1693             :                     {
    1694        1728 :                         L_tmp = Mpy_32_16_1( st_fx->hTcxDec->conceal_eof_gain32, *ptmp2 ); /* Q15 */
    1695        1728 :                         L_tmp = L_shl( L_tmp, st_fx->hTcxDec->conceal_eof_gain_e );
    1696        1728 :                         tmpV = round_fx( L_tmp );
    1697             : 
    1698        1728 :                         *ptmp1 = add( mult_r( tmpF, *ptmp1 ), mult_r( sub( 32767, tmpF ), tmpV ) ); /* Qsynth */
    1699        1728 :                         move16();
    1700        1728 :                         ptmp1++;
    1701        1728 :                         ptmp2++;
    1702             :                     }
    1703             :                 }
    1704             :                 ELSE
    1705             :                 {
    1706        5966 :                     ptmp2 = &hHQ_core->old_out_fx[nzeroes]; /* Qsynth */
    1707        5966 :                     ptmp1 = &synth[delay_comp];
    1708      781070 :                     FOR( i = 0; i < shift; i++ )
    1709             :                     {
    1710      775104 :                         *ptmp1 = add( mult_r( tmpF, *ptmp1 ), mult_r( sub( 32767, tmpF ), *ptmp2 ) ); /* Qsynth */
    1711      775104 :                         move16();
    1712      775104 :                         ptmp1++;
    1713      775104 :                         ptmp2++;
    1714      775104 :                         tmpF = add( tmpF, tmp ); /* Q15 */
    1715             :                     }
    1716             :                 }
    1717             :             }
    1718             : 
    1719      136444 :             set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP );
    1720      136444 :             IF( hHQ_core != NULL )
    1721             :             {
    1722      132693 :                 hHQ_core->oldHqVoicing = 0;
    1723      132693 :                 move16();
    1724             :             }
    1725             :         }
    1726             :     }
    1727             :     ELSE
    1728             :     {
    1729             :         /* memory update needed for DFT stereo -> TD stereo switching, scaling synth to Q0 */
    1730       68984 :         Copy_Scale_sig( synth + sub( output_frame, delay_comp ), st_fx->delay_buf_out_fx, delay_comp, negate( *Qsynth ) ); /* Q0 */
    1731       68984 :         hHQ_core->Q_old_postdec = 0;
    1732       68984 :         move16();
    1733             :     }
    1734             : 
    1735             :     /* reset SWB BWE buffers */
    1736     1029590 :     test();
    1737     1029590 :     test();
    1738     1029590 :     test();
    1739     1029590 :     IF( st_fx->bws_cnt == 0 || ( st_fx->bws_cnt > 0 && NE_16( st_fx->coder_type, INACTIVE ) && NE_16( st_fx->coder_type, AUDIO ) ) )
    1740             :     {
    1741     1026848 :         st_fx->attenu_fx = 3277; /* Q15 */
    1742     1026848 :         move16();
    1743             :     }
    1744             : 
    1745     1029590 :     test();
    1746     1029590 :     test();
    1747     1029590 :     test();
    1748     1029590 :     test();
    1749     1029590 :     test();
    1750     1029590 :     test();
    1751     1029590 :     test();
    1752     1029590 :     test();
    1753     1029590 :     test();
    1754     1029590 :     test();
    1755     1029590 :     test();
    1756     1029590 :     test();
    1757     1029590 :     test();
    1758     1029590 :     test();
    1759     1029590 :     test();
    1760     1029590 :     IF( ( st_fx->hBWE_FD != NULL ) && ( ( NE_16( st_fx->last_extl, SWB_BWE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || ( NE_16( st_fx->last_extl, FB_BWE ) && EQ_16( st_fx->extl, FB_BWE ) ) ||
    1761             :                                         ( ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_extl, SWB_TBE ) ) && st_fx->extl < 0 && NE_16( st_fx->core, HQ_CORE ) ) || ( EQ_16( st_fx->last_core, ACELP_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) && ( ( NE_16( st_fx->prev_coder_type, INACTIVE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) || ( NE_16( st_fx->prev_coder_type, AUDIO ) && EQ_16( st_fx->coder_type, AUDIO ) ) ) && st_fx->bws_cnt > 0 ) ) )
    1762             :     {
    1763        2114 :         set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame );
    1764        2114 :         hBWE_FD->old_wtda_swb_fx_exp = 0;
    1765        2114 :         move16();
    1766        2114 :         IF( NE_16( st_fx->last_extl, WB_BWE ) )
    1767             :         {
    1768        2103 :             hBWE_FD->prev_mode = NORMAL;
    1769        2103 :             move16();
    1770             :         }
    1771             : 
    1772        2114 :         hBWE_FD->prev_Energy_fx = 0;
    1773        2114 :         move16();
    1774        2114 :         hBWE_FD->prev_L_swb_norm = 8;
    1775        2114 :         move16();
    1776        2114 :         hBWE_FD->prev_frica_flag = 0;
    1777        2114 :         move16();
    1778        2114 :         set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k );
    1779        2114 :         hBWE_FD->prev_td_energy_fx = 0;
    1780        2114 :         move16();
    1781        2114 :         hBWE_FD->prev_weight_fx = 6554;
    1782        2114 :         move16(); /*0.2 in Q15*/
    1783        2114 :         hBWE_FD->prev_fb_ener_adjust_fx = 0;
    1784        2114 :         move16();
    1785             :     }
    1786             : 
    1787             :     /* reset WB BWE buffers */
    1788     1029590 :     test();
    1789     1029590 :     test();
    1790     1029590 :     IF( NE_16( st_fx->last_extl, WB_BWE ) && EQ_16( st_fx->extl, WB_BWE ) && st_fx->hBWE_FD != NULL )
    1791             :     {
    1792         440 :         set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame );
    1793             : 
    1794         440 :         test();
    1795         440 :         IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) )
    1796             :         {
    1797         439 :             hBWE_FD->prev_mode = NORMAL;
    1798         439 :             move16();
    1799             :         }
    1800         440 :         hBWE_FD->prev_Energy_wb_fx = 0;
    1801         440 :         move16();
    1802         440 :         hBWE_FD->prev_L_swb_norm = 8;
    1803         440 :         move16();
    1804         440 :         set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k );
    1805         440 :         hBWE_FD->prev_flag = 0;
    1806         440 :         move16();
    1807             :     }
    1808             : 
    1809             :     /* reset TBE buffers */
    1810     1029590 :     IF( hBWE_TD != NULL )
    1811             :     {
    1812             :         /* reset SWB TBE buffers */
    1813      390912 :         test();
    1814      390912 :         test();
    1815      390912 :         test();
    1816      390912 :         test();
    1817      390912 :         test();
    1818      390912 :         test();
    1819      390912 :         test();
    1820      390912 :         test();
    1821      390912 :         test();
    1822      390912 :         test();
    1823      390912 :         test();
    1824      390912 :         test();
    1825      390912 :         test();
    1826      390912 :         test();
    1827      390912 :         test();
    1828      390912 :         test();
    1829      390912 :         test();
    1830      390912 :         test();
    1831      390912 :         test();
    1832      390912 :         test();
    1833      390912 :         test();
    1834      390912 :         test();
    1835      390912 :         test();
    1836             : 
    1837      390912 :         IF( ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || EQ_16( st_fx->extl, SWB_CNG ) ) &&
    1838             :               ( NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && NE_16( st_fx->last_core, TCX_20_CORE ) && NE_16( st_fx->last_core, TCX_10_CORE ) ) || EQ_16( st_fx->last_core, HQ_CORE ) ) ) ||
    1839             :             ( LT_16( st_fx->bwidth, st_fx->last_bwidth ) && NE_16( st_fx->last_extl, SWB_TBE ) ) || st_fx->old_ppp_mode || ( ( EQ_16( st_fx->prev_coder_type, AUDIO ) || EQ_16( st_fx->prev_coder_type, INACTIVE ) ) && st_fx->bws_cnt > 0 ) || ( st_fx->bws_cnt == 0 && EQ_16( st_fx->prev_bws_cnt, N_WS2N_FRAMES ) ) )
    1840             :         {
    1841       18373 :             swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
    1842       18373 :                               hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) );
    1843             : 
    1844       18373 :             set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 );
    1845       18373 :             swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 );
    1846             : 
    1847       18373 :             hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */
    1848       18373 :             hBWE_TD->prev_mix_factor_fx = 32767;    /* Q15 1.f */
    1849       18373 :             move16();
    1850       18373 :             move16();
    1851             : 
    1852       18373 :             IF( EQ_16( output_frame, L_FRAME16k ) )
    1853             :             {
    1854             :                 /* reset in case that SWB TBE layer is transmitted, but the output x`x`is 16kHz sampled */
    1855        1314 :                 set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 );
    1856        1314 :                 set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 );
    1857             :             }
    1858       18373 :             set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN );
    1859       18373 :             set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN );
    1860             :         }
    1861      372539 :         ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && ( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || ( NE_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) || NE_16( st_fx->last_codec_mode, MODE1 ) || NE_16( st_fx->rf_flag, st_fx->rf_flag_last ) ) )
    1862             :         {
    1863       79297 :             set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER );
    1864       79297 :             set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD );
    1865       79297 :             set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER );
    1866       79297 :             set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER );
    1867       79297 :             hBWE_TD->gain_prec_swb_fx = 16384;
    1868       79297 :             move16(); /*Q14 = 1 */
    1869             :         }
    1870      293242 :         ELSE IF( st_fx->hBWE_TD != NULL && ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) )
    1871             :         {
    1872      218742 :             TBEreset_dec_fx( st_fx );
    1873             :         }
    1874             : 
    1875             :         /* reset FB TBE buffers */
    1876      390912 :         test();
    1877      390912 :         test();
    1878      390912 :         IF( EQ_16( st_fx->extl, FB_TBE ) && ( NE_16( st_fx->last_extl, FB_TBE ) || NE_16( st_fx->L_frame, st_fx->last_L_frame ) ) )
    1879             :         {
    1880        2641 :             set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER );
    1881        2641 :             hBWE_TD->fb_tbe_demph_fx = 0;
    1882        2641 :             move16();
    1883        2641 :             fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx );
    1884             :         }
    1885             : 
    1886             :         /* reset WB TBE buffers */
    1887      390912 :         test();
    1888      390912 :         IF( NE_16( st_fx->last_extl, WB_TBE ) && EQ_16( st_fx->extl, WB_TBE ) )
    1889             :         {
    1890         257 :             wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx );
    1891         257 :             wb_tbe_extras_reset_synth_fx( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx );
    1892             : 
    1893         257 :             set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 );
    1894         257 :             set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD );
    1895         257 :             set32_fx( hBWE_TD->syn_overlap_fx_32, 0, L_SHB_LAHEAD );
    1896         257 :             set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 );
    1897             :         }
    1898             :     }
    1899             : 
    1900             :     /* Interp_3_2 CNG buffers reset */
    1901     1029590 :     test();
    1902     1029590 :     test();
    1903     1029590 :     test();
    1904     1029590 :     IF( st_fx->hTdCngDec != NULL && EQ_32( st_fx->output_Fs, 48000 ) && ( ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) && ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) ) )
    1905             :     {
    1906         554 :         set16_fx( st_fx->hTdCngDec->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN );
    1907             :     }
    1908             : 
    1909     1029590 :     return error;
    1910             : }
    1911             : 
    1912             : /*---------------------------------------------------------------------*
    1913             :  * core_switching_hq_prepare_dec()
    1914             :  *
    1915             :  * Preprocessing in the first HQ frame after ACELP frame
    1916             :  * - modify bit allocation for HQ core by removing CELP subframe budget
    1917             :  *---------------------------------------------------------------------*/
    1918             : 
    1919          24 : void core_switching_hq_prepare_dec_fx(
    1920             :     Decoder_State *st_fx,     /* i/o: encoder state structure   */
    1921             :     Word16 *num_bits,         /* i/o: bit budget update       Q0*/
    1922             :     const Word16 output_frame /* i  : output frame length     Q0*/
    1923             : )
    1924             : {
    1925             :     Word32 cbrate;
    1926             : 
    1927          24 :     test();
    1928          24 :     IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->prev_bfi )
    1929             :     {
    1930           0 :         Copy_Scale_sig( st_fx->hHQ_core->old_out_fx, st_fx->hHQ_core->fer_samples_fx, output_frame, negate( st_fx->hHQ_core->Q_old_wtda ) ); /*Q0*/
    1931             :     }
    1932             : 
    1933             :     /* set switching frame bitrate */
    1934          24 :     IF( EQ_16( st_fx->last_L_frame, L_FRAME ) )
    1935             :     {
    1936           5 :         cbrate = L_add( st_fx->core_brate, 0 ); /* Q0 */
    1937           5 :         IF( GT_32( st_fx->core_brate, ACELP_24k40 ) )
    1938             :         {
    1939           0 :             cbrate = L_add( ACELP_24k40, 0 );
    1940             :         }
    1941             : 
    1942             :         /* subtract ACELP switching frame bits */
    1943           5 :         IF( GE_32( st_fx->core_brate, ACELP_11k60 ) )
    1944             :         {
    1945           5 :             ( *num_bits ) = sub( ( *num_bits ), 1 ); /* LP_FLAG bit */
    1946           5 :             move16();
    1947             :         }
    1948           5 :         *num_bits = sub( ( *num_bits ), ACB_bits_tbl[BIT_ALLOC_IDX_fx( cbrate, GENERIC, 0, 0 )] );     /* pitch bits*/
    1949           5 :         *num_bits = sub( ( *num_bits ), gain_bits_tbl[BIT_ALLOC_IDX_fx( cbrate, TRANSITION, 0, 0 )] ); /* gain bits */
    1950           5 :         *num_bits = sub( ( *num_bits ), FCB_bits_tbl[BIT_ALLOC_IDX_fx( cbrate, GENERIC, 0, 0 )] );     /* FCB bits  */
    1951           5 :         move16();
    1952           5 :         move16();
    1953           5 :         move16();
    1954             :     }
    1955             :     ELSE /* L_frame == L_FRAME16k */
    1956             :     {
    1957          19 :         IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
    1958             :         {
    1959           0 :             cbrate = L_add( ACELP_8k00, 0 );
    1960             :         }
    1961          19 :         ELSE IF( LE_32( st_fx->core_brate, ACELP_14k80 ) )
    1962             :         {
    1963           0 :             cbrate = L_add( ACELP_14k80, 0 );
    1964             :         }
    1965             :         ELSE
    1966             :         {
    1967          19 :             cbrate = L_min( st_fx->core_brate, ACELP_22k60 );
    1968             :         }
    1969             : 
    1970             :         /* subtract ACELP switching frame bits */
    1971          19 :         IF( GE_32( st_fx->core_brate, ACELP_11k60 ) )
    1972             :         {
    1973          19 :             ( *num_bits ) = sub( ( *num_bits ), 1 ); /* LP_FLAG bit */
    1974          19 :             move16();
    1975             :         }
    1976          19 :         *num_bits = sub( ( *num_bits ), ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( cbrate, GENERIC, 0, 0 )] );  /* pitch bits*/
    1977          19 :         *num_bits = sub( ( *num_bits ), gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( cbrate, GENERIC, 0, 0 )] ); /* gain bits */
    1978          19 :         *num_bits = sub( ( *num_bits ), FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( cbrate, GENERIC, 0, 0 )] );  /* FCB bits  */
    1979          19 :         move16();
    1980          19 :         move16();
    1981          19 :         move16();
    1982             :     }
    1983             : 
    1984             :     /* subtract BWE bits */
    1985          24 :     test();
    1986          24 :     test();
    1987          24 :     IF( !( ( EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) ) || EQ_16( inner_frame_tbl[st_fx->bwidth], L_FRAME8k ) ) )
    1988             :     {
    1989          24 :         *num_bits = sub( ( *num_bits ), ( NOOFGAINBITS1 + AUDIODELAYBITS ) );
    1990          24 :         move16();
    1991             :     }
    1992             : 
    1993             :     /* reset state of old_out if switching */
    1994          24 :     set16_fx( st_fx->hHQ_core->old_out_fx, 0, output_frame );
    1995          24 :     return;
    1996             : }
    1997             : 
    1998        6795 : static void core_switch_lb_upsamp_fx(
    1999             :     Decoder_State *st, /* i/o: Decoder state                  */
    2000             :     Word32 *output     /* i/o: LB synth/upsampled LB synth Q10*/
    2001             : )
    2002             : {
    2003             :     Word16 i, no_col;
    2004             :     Word32 *realBuffer_fx[CLDFB_OVRLP_MIN_SLOTS], *imagBuffer_fx[CLDFB_OVRLP_MIN_SLOTS];
    2005             :     Word32 realBufferTmp_fx[CLDFB_OVRLP_MIN_SLOTS][CLDFB_NO_CHANNELS_MAX];
    2006             :     Word32 imagBufferTmp_fx[CLDFB_OVRLP_MIN_SLOTS][CLDFB_NO_CHANNELS_MAX];
    2007             : 
    2008             :     /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
    2009       27180 :     FOR( i = 0; i < CLDFB_OVRLP_MIN_SLOTS; i++ )
    2010             :     {
    2011       20385 :         set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
    2012       20385 :         set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
    2013       20385 :         realBuffer_fx[i] = realBufferTmp_fx[i];
    2014       20385 :         imagBuffer_fx[i] = imagBufferTmp_fx[i];
    2015       20385 :         move32();
    2016       20385 :         move32();
    2017             :     }
    2018             : 
    2019             :     /* check if the CLDFB works on the right sample rate */
    2020        6795 :     IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) )
    2021             :     {
    2022        1164 :         resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) );
    2023             : 
    2024        1164 :         IF( st->cldfbBPF != NULL && LE_16( st->L_frame, L_FRAME16k ) )
    2025             :         {
    2026         159 :             resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) );
    2027             :         }
    2028             : 
    2029        1164 :         IF( st->ini_frame > 0 )
    2030             :         {
    2031        1159 :             st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); /* Q10 */
    2032        1159 :             move16();
    2033             :         }
    2034             :     }
    2035             :     /* analysis of the synthesis at internal sampling rate */
    2036        6795 :     cldfbAnalysis_ivas_fx( output, realBuffer_fx, imagBuffer_fx, i_mult( CLDFB_OVRLP_MIN_SLOTS, st->cldfbAna->no_channels ), st->cldfbAna );
    2037             : 
    2038             :     /* analysis and add the BPF error signal */
    2039        6795 :     IF( st->p_bpf_noise_buf_32 )
    2040             :     {
    2041        5744 :         addBassPostFilter_ivas_fx( st->p_bpf_noise_buf_32, st->bpf_off ? 0 : i_mult( CLDFB_OVRLP_MIN_SLOTS, st->cldfbBPF->no_channels ), realBuffer_fx, imagBuffer_fx, st->cldfbBPF );
    2042             :     }
    2043             : 
    2044             :     /* set output mask for upsampling */
    2045        6795 :     IF( EQ_16( st->bwidth, NB ) )
    2046             :     {
    2047             :         /* set NB mask for upsampling */
    2048           0 :         st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 );
    2049           0 :         move16();
    2050             :     }
    2051        6795 :     ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) )
    2052             :     {
    2053             :         /* in case of BW switching, re-init to default */
    2054         346 :         st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels );
    2055         346 :         move16();
    2056             :     }
    2057             : 
    2058             :     /* synthesis of the combined signal */
    2059             : #ifdef OPT_AVOID_STATE_BUF_RESCALE
    2060        6795 :     cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, output, i_mult( CLDFB_OVRLP_MIN_SLOTS, st->cldfbSyn->no_channels ), 0, 0, st->cldfbSyn );
    2061             : #else  /* OPT_AVOID_STATE_BUF_RESCALE */
    2062             :     cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, output, i_mult( CLDFB_OVRLP_MIN_SLOTS, st->cldfbSyn->no_channels ), 0, st->cldfbSyn );
    2063             : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
    2064             : 
    2065             :     /*rescaling whole buffer to a common Q*/
    2066        6795 :     no_col = st->cldfbSyn->no_col;
    2067        6795 :     move16();
    2068             : 
    2069        6795 :     IF( GT_16( imult1616( CLDFB_OVRLP_MIN_SLOTS, st->cldfbSyn->no_channels ), -1 ) )
    2070             :     {
    2071             :         Word16 temp, temp_e;
    2072        6795 :         temp = BASOP_Util_Divide1616_Scale( ( add( imult1616( CLDFB_OVRLP_MIN_SLOTS, st->cldfbSyn->no_channels ), sub( st->cldfbSyn->no_channels, 1 ) ) ), st->cldfbSyn->no_channels, &temp_e ); /*Q=15-temp_e*/
    2073        6795 :         temp = shr( temp, sub( 15, temp_e ) );                                                                                                                                                   /*Shifting to make Q 0*/
    2074        6795 :         no_col = s_min( no_col, temp );
    2075             :     }
    2076             : 
    2077        6795 :     Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( L_FRAME48k, imult1616( no_col, st->cldfbSyn->no_channels ) ), 4 - 10 ); /* Q4 */
    2078             : 
    2079             :     /* save synthesis - needed in case of core switching */
    2080        6795 :     IF( st->hTcxDec != NULL )
    2081             :     {
    2082        6795 :         Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -4 ); /* Q0 */
    2083             :     }
    2084             : 
    2085        6795 :     return;
    2086             : }
    2087             : 
    2088             : #define TRANSITION_SMOOTHING_LEN_16k 15
    2089             : #define TRANSITION_SMOOTHING_LEN_32k 31
    2090             : #define TRANSITION_SMOOTHING_LEN_48k 47
    2091             : 
    2092         607 : static void smoothTransitionDtxToTcx_fx(
    2093             :     Word16 synth[],            /* i/o: synthesis                   Qsynth*/
    2094             :     const Word16 output_frame, /* i  : output frame length             Q0*/
    2095             :     const Word16 delay_comp    /* i  : delay compensation in samples   Q0*/
    2096             : )
    2097             : {
    2098             :     Word16 i, filter_len;
    2099             :     Word16 w, step, fade_in;
    2100             :     Word32 mem;
    2101             :     Word16 smoothing_input_buffer[2 * NS2SA( 48000, DELAY_CLDFB_NS ) + TRANSITION_SMOOTHING_LEN_48k];
    2102             :     Word16 smoothing_out_buffer[2 * NS2SA( 48000, DELAY_CLDFB_NS ) + TRANSITION_SMOOTHING_LEN_48k];
    2103             : 
    2104         607 :     set16_fx( smoothing_input_buffer, 0, 2 * NS2SA( 48000, DELAY_CLDFB_NS ) + TRANSITION_SMOOTHING_LEN_48k );
    2105         607 :     set16_fx( smoothing_out_buffer, 0, 2 * NS2SA( 48000, DELAY_CLDFB_NS ) + TRANSITION_SMOOTHING_LEN_48k );
    2106         607 :     filter_len = TRANSITION_SMOOTHING_LEN_16k;
    2107         607 :     move16();
    2108         607 :     IF( EQ_16( output_frame, L_FRAME32k ) )
    2109             :     {
    2110          90 :         filter_len = TRANSITION_SMOOTHING_LEN_32k;
    2111          90 :         move16();
    2112             :     }
    2113         517 :     ELSE IF( EQ_16( output_frame, L_FRAME48k ) )
    2114             :     {
    2115         469 :         filter_len = TRANSITION_SMOOTHING_LEN_48k;
    2116         469 :         move16();
    2117             :     }
    2118             : 
    2119             :     /* prepare buffer */
    2120       13080 :     FOR( i = 0; i < filter_len / 2; i++ )
    2121             :     {
    2122       12473 :         smoothing_input_buffer[i] = synth[0];
    2123       12473 :         move16();
    2124             :     }
    2125         607 :     Copy( synth, smoothing_input_buffer + shr( filter_len, 1 ), add( shl( delay_comp, 1 ), shr( filter_len, 1 ) ) ); /* Qsynth */
    2126             : 
    2127             :     /* apply Mean filter */
    2128         607 :     w = div_s( 1, filter_len ); /* Q15 */
    2129         607 :     mem = 0;
    2130         607 :     move32();
    2131       26160 :     FOR( i = 0; i < filter_len; i++ )
    2132             :     {
    2133       25553 :         mem = L_add( mem, L_deposit_l( smoothing_input_buffer[i] ) ); /* Qsynth */
    2134             :     }
    2135             :     // mem = sum32_fx( smoothing_input_buffer, filter_len );
    2136       66007 :     FOR( i = 0; i < shl( delay_comp, 1 ); i++ )
    2137             :     {
    2138       65400 :         smoothing_out_buffer[i] = extract_l( Mpy_32_16_1( mem, w ) ); /* Qsynth */
    2139       65400 :         move16();
    2140       65400 :         mem = L_add( mem, L_sub( L_deposit_l( smoothing_input_buffer[i + filter_len] ), L_deposit_l( smoothing_input_buffer[i] ) ) ); /* Qsynth */
    2141             :     }
    2142             : 
    2143             :     /* apply fades around transition */
    2144         607 :     step = div_s( 1, delay_comp );
    2145         607 :     fade_in = extract_l( 0 );
    2146       33307 :     FOR( i = 0; i < delay_comp; i++ )
    2147             :     {
    2148       32700 :         synth[i] = add( mult_r( smoothing_out_buffer[i], fade_in ), mult_r( synth[i], sub( ONE_IN_Q15 - 1, fade_in ) ) ); /* Qsynth */
    2149       32700 :         move16();
    2150       32700 :         fade_in = add( fade_in, step );
    2151             :     }
    2152             : 
    2153         607 :     fade_in = 0;
    2154         607 :     move16();
    2155       33307 :     FOR( ; i < shl( delay_comp, 1 ); i++ )
    2156             :     {
    2157       32700 :         synth[i] = add( mult_r( synth[i], fade_in ), mult_r( smoothing_out_buffer[i], sub( ONE_IN_Q15 - 1, fade_in ) ) ); /* Qsynth */
    2158       32700 :         move16();
    2159       32700 :         fade_in = add( fade_in, step );
    2160             :     }
    2161             : 
    2162         607 :     return;
    2163             : }
    2164             : 
    2165             : 
    2166             : /*---------------------------------------------------------------------*
    2167             :  * core_switching_pre_dec()
    2168             :  *
    2169             :  * Preprocessing/preparation for ACELP/HQ core switching
    2170             :  *---------------------------------------------------------------------*/
    2171     1029590 : ivas_error core_switching_pre_dec_ivas_fx(
    2172             :     Decoder_State *st,                /* i/o: decoder state structure      */
    2173             :     const Word16 output_frame,        /* i  : frame length                 */
    2174             :     const Word32 last_core_brate_st0, /* i  : channel 0 last core bitrate  */
    2175             :     const Word16 nchan_out,           /* i  : number of output channels    */
    2176             :     const Word16 last_element_mode,   /* i  : last_element_mode            */
    2177             :     const Word32 last_element_brate,  /* i  : last element bitrate         */
    2178             :     Word16 Q_old_synthFB,
    2179             :     Word16 *Q_olapBufferSynth,
    2180             :     Word16 *Q_olapBufferSynth2 )
    2181             : {
    2182             :     Word32 tmp_fx; /*Q-12*/
    2183             :     Word16 i, oldLenClasBuff, newLenClasBuff;
    2184             :     ivas_error error;
    2185     1029590 :     Word16 exp = 25;
    2186     1029590 :     move16();
    2187     1029590 :     error = IVAS_ERR_OK;
    2188     1029590 :     move32();
    2189             : 
    2190             :     /* Codec mode switching */
    2191     1029590 :     test();
    2192     1029590 :     test();
    2193     1029590 :     test();
    2194     1029590 :     IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && ( st->element_mode > EVS_MONO ) ) )
    2195             :     {
    2196      853024 :         st->mem_deemph_fx = st->syn[M];
    2197      853024 :         move16();
    2198      853024 :         set16_fx( st->agc_mem_fx, 0, 2 );
    2199      853024 :         Scale_sig( &( st->mem_deemph_fx ), 1, st->Q_syn ); /* Brings mem_deemph to Qsyn */
    2200             : 
    2201      853024 :         Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/
    2202             : 
    2203      853024 :         st->bpf_off = 1;
    2204      853024 :         move16();
    2205      853024 :         IF( st->hPFstat != NULL )
    2206             :         {
    2207      214853 :             Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn );    /* Post_filter mem  ,Q_syn*/
    2208      214853 :             Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem , Q_syn*/
    2209      214853 :             Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn );      /* Post_filter mem  ,Q_syn*/
    2210      214853 :             set16_fx( st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX );     /* BPF mem*/
    2211             :         }
    2212      853024 :         IF( st->hBPF != NULL )
    2213             :         {
    2214      214853 :             st->hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10  */
    2215      214853 :             st->hBPF->pst_mem_deemp_err_fx = 0;
    2216      214853 :             move16();
    2217      214853 :             move16();
    2218             :         }
    2219      853024 :         st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); // Q(23+1-16)->Q8
    2220      853024 :         move16();
    2221             : 
    2222             :         /* reset old HB synthesis buffer */
    2223      853024 :         IF( EQ_16( st->last_L_frame, L_FRAME ) )
    2224             :         {
    2225       45865 :             st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS );
    2226             :         }
    2227             :         ELSE
    2228             :         {
    2229      807159 :             st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS );
    2230             :         }
    2231      853024 :         move16();
    2232      853024 :         set16_fx( st->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) );
    2233             : 
    2234      853024 :         test();
    2235      853024 :         IF( st->hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) )
    2236             :         {
    2237      223152 :             st->hBWE_TD->prev_hb_synth_fx_exp = 31;
    2238      223152 :             move16();
    2239             :             /* reset BWE memories */
    2240      223152 :             set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
    2241      223152 :             st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
    2242      223152 :             move32();
    2243             :         }
    2244             : 
    2245             :         /* reset upd_cnt */
    2246      853024 :         st->upd_cnt = MAX_UPD_CNT;
    2247      853024 :         move16();
    2248             : 
    2249      853024 :         st->igf = 0;
    2250      853024 :         move16();
    2251             : 
    2252      853024 :         test();
    2253      853024 :         IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL )
    2254             :         {
    2255      203283 :             hf_synth_reset_fx( st->hBWE_zero );
    2256      203283 :             set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
    2257             :         }
    2258             : 
    2259      853024 :         IF( st->hBWE_FD != NULL )
    2260             :         {
    2261      223152 :             set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
    2262             :         }
    2263             : 
    2264      853024 :         IF( st->hHQ_core != NULL )
    2265             :         {
    2266      853015 :             set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB );
    2267      853015 :             set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB );
    2268             : 
    2269      853015 :             set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
    2270      853015 :             set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX );
    2271             : 
    2272      853015 :             st->hHQ_core->last_max_pos_pulse = 0;
    2273      853015 :             move16();
    2274             : 
    2275      853015 :             IF( GT_32( st->output_Fs, 16000 ) )
    2276             :             {
    2277      783479 :                 set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE );
    2278             :             }
    2279             : 
    2280             :             /* pre-echo */
    2281      853015 :             st->hHQ_core->pastpre = 0;
    2282      853015 :             move16();
    2283             :         }
    2284             : 
    2285             :         /* reset the GSC pre echo energy threshold in case of switching */
    2286      853024 :         if ( st->hGSCDec != NULL )
    2287             :         {
    2288      214853 :             st->hGSCDec->Last_frame_ener_fx = MAX_32;
    2289      214853 :             move32();
    2290             :         }
    2291             : 
    2292      853024 :         test();
    2293      853024 :         IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) )
    2294             :         {
    2295      853024 :             IF( st->element_mode == EVS_MONO )
    2296             :             {
    2297           0 :                 st->last_core = HQ_CORE;
    2298           0 :                 move16();
    2299             : 
    2300           0 :                 Copy32( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer32_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
    2301             :                 // Copy_Scale_sig_32_16( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); //Q11 -> Q0
    2302             :             }
    2303             : 
    2304      853024 :             IF( st->hHQ_core != NULL )
    2305             :             {
    2306      853015 :                 set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
    2307      853015 :                 set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX );
    2308      853015 :                 st->hHQ_core->last_max_pos_pulse = 0;
    2309      853015 :                 move16();
    2310             : 
    2311      853015 :                 set16_fx( st->hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM );
    2312      853015 :                 st->hHQ_core->prev_frm_hfe2 = 0;
    2313      853015 :                 st->hHQ_core->prev_stab_hfe2 = 0;
    2314      853015 :                 move16();
    2315      853015 :                 move16();
    2316             :             }
    2317             :         }
    2318             : 
    2319      853024 :         IF( st->prev_bfi != 0 )
    2320             :         {
    2321             :             Word16 delay_comp;
    2322             : 
    2323             :             /*switch off Hq Voicing as it was not updated in MODE2*/
    2324       13907 :             IF( st->hHQ_core != NULL )
    2325             :             {
    2326       13907 :                 st->hHQ_core->oldHqVoicing = 0;
    2327       13907 :                 st->hHQ_core->HqVoicing = 0;
    2328       13907 :                 move16();
    2329       13907 :                 move16();
    2330             :             }
    2331             : 
    2332       13907 :             delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
    2333             :             /*TODO To be tested:control not entering the block*/
    2334       13907 :             test();
    2335       13907 :             test();
    2336       13907 :             IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) )
    2337             :             {
    2338             :                 /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/
    2339           0 :                 assert( 0 );
    2340             :                 Word32 *realBuffer_fx[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer_fx[CLDFB_NO_COL_MAX_SWITCH];
    2341             :                 Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX];
    2342             :                 Word32 syn_Overl_fx[320];
    2343             :                 Word32 fer_samples_fx[960];
    2344             :                 Copy_Scale_sig_16_32_DEPREC( st->hTcxDec->syn_Overl, syn_Overl_fx, 320, 15 );
    2345             :                 Copy_Scale_sig_16_32_DEPREC( st->hHQ_core->fer_samples_fx, fer_samples_fx, 960, 15 );
    2346             : 
    2347             : 
    2348             :                 FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ )
    2349             :                 {
    2350             :                     set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
    2351             :                     set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
    2352             :                     realBuffer_fx[i] = realBufferTmp_fx[i];
    2353             :                     imagBuffer_fx[i] = imagBufferTmp_fx[i];
    2354             :                 }
    2355             : 
    2356             :                 /* CLDFB analysis of the synthesis at internal sampling rate */
    2357             :                 IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ), IVAS_ERR_OK ) )
    2358             :                 {
    2359             :                     return error;
    2360             :                 }
    2361             : 
    2362             :                 cldfbAnalysis_ivas_fx( syn_Overl_fx, realBuffer_fx, imagBuffer_fx, delay_comp, st->cldfbAna );
    2363             :                 cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/
    2364             : 
    2365             :                 /* CLDFB synthesis of the combined signal */
    2366             :                 IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ), IVAS_ERR_OK ) )
    2367             :                 {
    2368             :                     return error;
    2369             :                 }
    2370             : 
    2371             : #ifdef OPT_AVOID_STATE_BUF_RESCALE
    2372             :                 cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, fer_samples_fx, delay_comp, 0, 0, st->cldfbSyn );
    2373             : #else  /* OPT_AVOID_STATE_BUF_RESCALE */
    2374             :                 cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, fer_samples_fx, delay_comp, 0, st->cldfbSyn );
    2375             : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
    2376             :                 cldfb_restore_memory_ivas_fx( st->cldfbSyn );
    2377             :                 Copy_Scale_sig_32_16( syn_Overl_fx, st->hTcxDec->syn_Overl, 320, 15 );
    2378             :                 Copy_Scale_sig_32_16( fer_samples_fx, st->hHQ_core->fer_samples_fx, 960, 9 );
    2379             :             }
    2380             : 
    2381       13907 :             test();
    2382       13907 :             test();
    2383       13907 :             IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) )
    2384             :             {
    2385           0 :                 lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) );
    2386             :                 /*Set to zero the remaining part*/
    2387           0 :                 set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) );
    2388             :             }
    2389             :         }
    2390             : 
    2391      853024 :         st->use_acelp_preq = 0;
    2392      853024 :         st->reset_mem_AR = 0;
    2393      853024 :         move16();
    2394      853024 :         move16();
    2395             :     }
    2396             : 
    2397             :     /*FEC*/
    2398     1029590 :     IF( LE_16( st->L_frame, L_FRAME16k ) )
    2399             :     {
    2400     1020840 :         test();
    2401     1020840 :         IF( LE_16( st->last_L_frame, L_FRAME16k ) && NE_16( st->core, HQ_CORE ) )
    2402             :         {
    2403      347997 :             IF( NE_16( st->L_frame, st->last_L_frame ) )
    2404             :             {
    2405        2550 :                 IF( GT_16( st->L_frame, st->last_L_frame ) )
    2406             :                 {
    2407        1833 :                     oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) );
    2408        1833 :                     newLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
    2409        1833 :                     move16();
    2410             :                 }
    2411             :                 ELSE
    2412             :                 {
    2413         717 :                     oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
    2414         717 :                     move16();
    2415         717 :                     newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) );
    2416             :                 }
    2417        2550 :                 lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff );
    2418             :             }
    2419             :         }
    2420             :         ELSE
    2421             :         {
    2422      672843 :             set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM );
    2423             :         }
    2424             :     }
    2425             : 
    2426             :     /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores
    2427             :        within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */
    2428     1029590 :     test();
    2429     1029590 :     test();
    2430     1029590 :     IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) ) )
    2431             :     {
    2432        6969 :         st->last_ppp_mode_dec = 0;
    2433        6969 :         st->last_nelp_mode_dec = 0;
    2434        6969 :         move16();
    2435        6969 :         move16();
    2436             :     }
    2437             : 
    2438             :     /* Handle state reset of stat_noise_uv_mod memory */
    2439     1029590 :     test();
    2440     1029590 :     test();
    2441     1029590 :     test();
    2442     1029590 :     IF( ( st->core == ACELP_CORE ) && ( ( st->last_core != ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || LE_32( st->last_total_brate, PPP_NELP_2k80 ) ) )
    2443             :     {
    2444       40377 :         st->act_count = 3;
    2445       40377 :         st->uv_count = 0;
    2446       40377 :         move16();
    2447       40377 :         move16();
    2448             :     }
    2449             : 
    2450     1029590 :     test();
    2451     1029590 :     test();
    2452     1029590 :     test();
    2453     1029590 :     test();
    2454     1029590 :     test();
    2455     1029590 :     test();
    2456     1029590 :     test();
    2457     1029590 :     test();
    2458     1029590 :     test();
    2459     1029590 :     test();
    2460     1029590 :     test();
    2461     1029590 :     IF( ( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && EQ_16( st->last_core, HQ_CORE ) ) || ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( nchan_out, 2 ) &&
    2462             :                                                                                                                      NE_32( st->core_brate, SID_2k40 ) && ( st->core_brate != FRAME_NO_DATA ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) ) )
    2463             :     {
    2464         414 :         test();
    2465         414 :         if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) )
    2466             :         {
    2467         264 :             st->hPFstat->reset = 1;
    2468         264 :             move16();
    2469             :         }
    2470             : 
    2471         414 :         IF( EQ_16( st->L_frame, L_FRAME16k ) )
    2472             :         {
    2473         315 :             Copy( TRWB2_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */
    2474         315 :             Copy( TRWB2_Ave_fx, st->lsfoldbfi1_fx, M );
    2475         315 :             Copy( TRWB2_Ave_fx, st->lsfoldbfi0_fx, M );
    2476         315 :             Copy( TRWB2_Ave_fx, st->lsf_adaptive_mean_fx, M );
    2477         315 :             lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_16k );
    2478             :         }
    2479             :         ELSE
    2480             :         {
    2481          99 :             Copy( TRWB_Ave_fx, st->lsf_old_fx, M ); /* init of LSP */
    2482          99 :             Copy( TRWB_Ave_fx, st->lsfoldbfi1_fx, M );
    2483          99 :             Copy( TRWB_Ave_fx, st->lsfoldbfi0_fx, M );
    2484          99 :             Copy( TRWB_Ave_fx, st->lsf_adaptive_mean_fx, M );
    2485          99 :             lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_12k8 );
    2486             :         }
    2487             : 
    2488         414 :         test();
    2489         414 :         test();
    2490         414 :         test();
    2491         414 :         test();
    2492         414 :         test();
    2493         414 :         test();
    2494         414 :         IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL )
    2495             :         {
    2496             :             /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */
    2497         191 :             set16_fx( st->hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 );
    2498         191 :             set16_fx( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, 0, FFTLEN );
    2499         191 :             set16_fx( st->agc_mem_fx, 0, 2 );
    2500             :         }
    2501         414 :         st->mem_deemph_fx = 0;
    2502         414 :         move16();
    2503         414 :         IF( !st->last_con_tcx )
    2504             :         {
    2505         414 :             set16_fx( st->mem_syn2_fx, 0, M );
    2506             :         }
    2507         414 :         set16_fx( st->mem_syn1_fx, 0, M );
    2508         414 :         if ( st->hBWE_TD != NULL )
    2509             :         {
    2510         414 :             st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
    2511         414 :             move32();
    2512             :         }
    2513             : 
    2514             :         /* Reset ACELP parameters */
    2515         414 :         set16_fx( st->mem_MA_fx, 0, M );
    2516             : 
    2517         414 :         IF( EQ_32( st->sr_core, INT_FS_16k ) )
    2518             :         {
    2519         315 :             Copy( GEWB2_Ave_fx, st->mem_AR_fx, M );
    2520             :         }
    2521             :         ELSE
    2522             :         {
    2523          99 :             Copy( GEWB_Ave_fx, st->mem_AR_fx, M );
    2524             :         }
    2525             : 
    2526         414 :         st->tilt_code_fx = 0;
    2527         414 :         st->gc_threshold_fx = 0;
    2528         414 :         st->dm_fx.prev_gain_code = 0;
    2529         414 :         st->dm_fx.prev_state = 0;
    2530         414 :         move16();
    2531         414 :         move32();
    2532         414 :         move32();
    2533         414 :         move16();
    2534         414 :         set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
    2535             : 
    2536         414 :         st->last_coder_type = GENERIC;
    2537         414 :         move16();
    2538             : 
    2539         414 :         fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/
    2540         414 :         st->lp_gainp_fx = 0;
    2541         414 :         move16();
    2542         414 :         st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/
    2543         414 :         move16();
    2544         414 :         st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/
    2545         414 :         move16();
    2546             : 
    2547         414 :         st->last_voice_factor_fx = 0;
    2548         414 :         st->Last_GSC_noisy_speech_flag = 0;
    2549         414 :         move16();
    2550         414 :         move16();
    2551             : 
    2552             :         /* reset CLDFB memories */
    2553         414 :         cldfb_reset_memory_fx( st->cldfbAna );
    2554         414 :         cldfb_reset_memory_fx( st->cldfbBPF );
    2555         414 :         cldfb_reset_memory_fx( st->cldfbSyn );
    2556             : 
    2557             :         /* reset TBE memories */
    2558         414 :         test();
    2559         414 :         test();
    2560         414 :         IF( !st->last_con_tcx && !( ( EQ_16( st->last_core, HQ_CORE ) ) && ( st->element_mode > EVS_MONO ) ) )
    2561             :         {
    2562         198 :             set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC );
    2563             :         }
    2564         216 :         ELSE IF( LT_16( st->L_frame, L_FRAME16k ) )
    2565             :         {
    2566             :             /* resample from 16kHz to 12.8kHZ */
    2567           1 :             synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC );
    2568             :         }
    2569             : 
    2570         414 :         IF( st->hBWE_TD != NULL )
    2571             :         {
    2572         414 :             set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
    2573             :         }
    2574             : 
    2575         414 :         test();
    2576         414 :         IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL )
    2577             :         {
    2578         334 :             hf_synth_reset_fx( st->hBWE_zero );
    2579         334 :             set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
    2580             :         }
    2581             : 
    2582         414 :         IF( st->hBWE_FD != NULL )
    2583             :         {
    2584         414 :             set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
    2585             :         }
    2586             :     }
    2587             : 
    2588     1029590 :     test();
    2589     1029590 :     test();
    2590     1029590 :     test();
    2591     1029590 :     IF( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) )
    2592             :     {
    2593        6753 :         IF( st->hBWE_TD != NULL )
    2594             :         {
    2595        6457 :             st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
    2596        6457 :             move32();
    2597        6457 :             set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
    2598             :         }
    2599             : 
    2600        6753 :         st->tilt_code_fx = 0;
    2601        6753 :         st->gc_threshold_fx = 0;
    2602        6753 :         st->dm_fx.prev_gain_code = 0;
    2603        6753 :         st->dm_fx.prev_state = 0;
    2604        6753 :         move16();
    2605        6753 :         move32();
    2606        6753 :         move32();
    2607        6753 :         move16();
    2608        6753 :         set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
    2609        6753 :         st->last_coder_type = GENERIC;
    2610        6753 :         move16();
    2611        6753 :         fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/
    2612             : 
    2613        6753 :         st->lp_gainp_fx = 0;
    2614        6753 :         move16();
    2615        6753 :         st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/
    2616        6753 :         move16();
    2617        6753 :         st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/
    2618        6753 :         move16();
    2619             : 
    2620        6753 :         st->last_voice_factor_fx = 0;
    2621        6753 :         st->Last_GSC_noisy_speech_flag = 0;
    2622        6753 :         move16();
    2623        6753 :         move16();
    2624             : 
    2625        6753 :         test();
    2626        6753 :         IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL )
    2627             :         {
    2628        6007 :             hf_synth_reset_fx( st->hBWE_zero );
    2629        6007 :             set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
    2630             :         }
    2631             : 
    2632        6753 :         IF( st->hBWE_FD != NULL )
    2633             :         {
    2634        6457 :             set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
    2635             :         }
    2636             : 
    2637        6753 :         test();
    2638        6753 :         test();
    2639        6753 :         test();
    2640        6753 :         IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) )
    2641             :         {
    2642             :             /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */
    2643             :             Word16 offset;
    2644         470 :             offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels );
    2645             :             Word32 *old_synthFB_fx;
    2646         470 :             IF( ( old_synthFB_fx = (Word32 *) malloc( st->hTcxDec->old_synth_lenFB * sizeof( Word32 ) ) ) == NULL )
    2647             :             {
    2648           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for old_synth_lenFB (32 bit) \n" ) );
    2649             :             }
    2650         470 :             Copy_Scale_sig_16_32_no_sat( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10
    2651         470 :             Copy32( old_synthFB_fx + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset );
    2652         470 :             st->cldfbAna->Q_cldfb_state = Q10;
    2653         470 :             move16();
    2654         470 :             IF( old_synthFB_fx )
    2655         470 :             free( old_synthFB_fx );
    2656             :         }
    2657             :     }
    2658             : 
    2659     1029590 :     test();
    2660     1029590 :     test();
    2661     1029590 :     test();
    2662     1029590 :     test();
    2663     1029590 :     IF( EQ_16( st->core, HQ_CORE ) && ( ( st->last_core == ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( ( st->element_mode != EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) )
    2664             :     {
    2665         585 :         set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB );
    2666         585 :         set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB );
    2667             : 
    2668         585 :         set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
    2669         585 :         set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX );
    2670         585 :         st->hHQ_core->last_max_pos_pulse = 0;
    2671         585 :         move16();
    2672             : 
    2673         585 :         set16_fx( st->hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM );
    2674         585 :         st->hHQ_core->prev_frm_hfe2 = 0;
    2675         585 :         st->hHQ_core->prev_stab_hfe2 = 0;
    2676         585 :         move16();
    2677         585 :         move16();
    2678         585 :         IF( GT_32( st->output_Fs, 16000 ) )
    2679             :         {
    2680         555 :             set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE );
    2681             :         }
    2682             : 
    2683         585 :         IF( st->element_mode != EVS_MONO )
    2684             :         {
    2685             :             /* Estimate mem_env_delta to reinit env_stab */
    2686         585 :             tmp_fx = L_max( 0, L_add( ENV_STAB_EST1_FX, L_add( Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ), Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ) ) ); /*Q12*/
    2687             : 
    2688         585 :             st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */
    2689         585 :             move16();
    2690         585 :             test();
    2691         585 :             IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) )
    2692             :             {
    2693         185 :                 set16_fx( st->hHQ_core->old_out_fx, 0, output_frame );
    2694         185 :                 set32_fx( st->hHQ_core->old_out_LB_fx32, 0, L_FRAME16k );
    2695         185 :                 set16_fx( st->hHQ_core->old_out_LB_fx, 0, L_FRAME16k );
    2696             :             }
    2697             : 
    2698         585 :             st->hHQ_core->no_att_hangover = 0;
    2699         585 :             move16();
    2700         585 :             st->hHQ_core->energy_lt_fx = 2457600; /*300.0f Q13*/
    2701         585 :             move32();
    2702         585 :             set16_fx( st->hHQ_core->old_is_transient, 0, 3 );
    2703         585 :             set16_fx( st->hHQ_core->prev_noise_level_fx, 0, 2 );
    2704         585 :             st->hHQ_core->prev_R = 0;
    2705         585 :             move16();
    2706         585 :             set16_fx( st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 );
    2707         585 :             st->hHQ_core->prev_hqswb_clas = HQ_NORMAL;
    2708         585 :             st->hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/
    2709         585 :             move16();
    2710         585 :             move16();
    2711         585 :             set16_fx( st->hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS );
    2712             :         }
    2713             :         ELSE
    2714             :         {
    2715           0 :             set16_fx( st->hHQ_core->old_out_fx, 0, output_frame );
    2716           0 :             set32_fx( st->hHQ_core->old_out_LB_fx32, 0, L_FRAME16k );
    2717             :         }
    2718             :     }
    2719             : 
    2720             :     /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */
    2721     1029590 :     IF( st->hHQ_core != NULL )
    2722             :     {
    2723     1025839 :         st->hHQ_core->pastpre = sub( st->hHQ_core->pastpre, 1 );
    2724     1025839 :         move16();
    2725     1025839 :         IF( st->hHQ_core->pastpre < 0 )
    2726             :         {
    2727     1020609 :             reset_preecho_dec_fx( st->hHQ_core );
    2728             :         }
    2729             :     }
    2730     1029590 :     test();
    2731     1029590 :     IF( st->core_brate == FRAME_NO_DATA )
    2732             :     {
    2733       22598 :         st->VAD = 0;
    2734       22598 :         st->m_frame_type = ZERO_FRAME;
    2735             :     }
    2736     1006992 :     ELSE IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, SID_1k75 ) )
    2737             :     {
    2738        3484 :         st->VAD = 0;
    2739        3484 :         st->m_frame_type = SID_FRAME;
    2740             :     }
    2741             :     ELSE
    2742             :     {
    2743     1003508 :         st->VAD = 1;
    2744     1003508 :         st->m_frame_type = ACTIVE_FRAME;
    2745             :     }
    2746             : 
    2747     1029590 :     move16();
    2748     1029590 :     move16();
    2749             :     /*switch on CNA on active frames*/
    2750     1029590 :     IF( ( st->element_mode == EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */
    2751             :     {
    2752           0 :         test();
    2753           0 :         test();
    2754           0 :         test();
    2755           0 :         test();
    2756           0 :         test();
    2757           0 :         test();
    2758           0 :         IF( st->VAD && ( ( NE_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, CNA_MAX_BRATE ) ) || ( EQ_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, ACELP_8k85 ) ) ) )
    2759             :         {
    2760           0 :             st->flag_cna = 1;
    2761           0 :             move16();
    2762             :         }
    2763           0 :         ELSE IF( st->VAD || ( EQ_16( st->cng_type, FD_CNG ) && EQ_16( st->L_frame, L_FRAME16k ) ) )
    2764             :         {
    2765           0 :             st->flag_cna = 0;
    2766           0 :             move16();
    2767             :         }
    2768             :     }
    2769             : 
    2770     1029590 :     if ( EQ_16( st->core, AMR_WB_CORE ) )
    2771             :     {
    2772           0 :         st->cng_type = LP_CNG;
    2773           0 :         move16();
    2774             :     }
    2775             : 
    2776             :     /* Reconfigure CNG */
    2777     1029590 :     test();
    2778     1029590 :     test();
    2779     1029590 :     test();
    2780     1029590 :     test();
    2781     1029590 :     IF( st->hFdCngDec && ( NE_16( st->last_L_frame, st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize, st->L_frame ) || ( st->ini_frame == 0 ) || NE_16( st->bwidth, st->last_bwidth ) ) )
    2782             :     {
    2783             :         /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/
    2784      524777 :         IF( NE_16( st->core, AMR_WB_CORE ) )
    2785             :         {
    2786      524777 :             test();
    2787      524777 :             IF( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) )
    2788             :             {
    2789           0 :                 configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, ACELP_9k60, st->L_frame, st->last_L_frame, st->element_mode );
    2790             :             }
    2791             :             ELSE
    2792             :             {
    2793      524777 :                 configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode );
    2794             :             }
    2795             :         }
    2796             :         ELSE
    2797             :         {
    2798           0 :             configureFdCngDec_ivas_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode );
    2799             : 
    2800           0 :             if ( st->VAD )
    2801             :             {
    2802           0 :                 st->hFdCngDec->hFdCngCom->CngBitrate = st->total_brate;
    2803           0 :                 move32();
    2804             :             }
    2805             :         }
    2806      524777 :         test();
    2807      524777 :         test();
    2808      524777 :         IF( NE_16( st->last_L_frame, st->L_frame ) && LE_16( st->L_frame, L_FRAME16k ) && LE_16( st->last_L_frame, L_FRAME16k ) )
    2809             :         {
    2810        2535 :             test();
    2811        2535 :             IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) )
    2812             :             {
    2813         310 :                 lerp( st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->L_frame, st->L_frame, st->last_L_frame );
    2814             :             }
    2815             : 
    2816        2535 :             L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth2 );
    2817             : 
    2818        2535 :             test();
    2819        2535 :             IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) )
    2820             :             {
    2821          12 :                 L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth );
    2822             : 
    2823          12 :                 IF( EQ_16( st->L_frame, L_FRAME ) )
    2824             :                 {
    2825        3591 :                     FOR( i = 0; i < ( st->L_frame * 2 ); i++ )
    2826             :                     {
    2827        3584 :                         st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ );
    2828        3584 :                         move32();
    2829             :                     }
    2830             :                 }
    2831             :                 ELSE
    2832             :                 {
    2833        3205 :                     FOR( i = 0; i < ( st->L_frame * 2 ); i++ )
    2834             :                     {
    2835        3200 :                         st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ );
    2836        3200 :                         move32();
    2837             :                     }
    2838             :                 }
    2839             :             }
    2840             :         }
    2841             :     }
    2842             : 
    2843     1029590 :     return error;
    2844             : }
    2845             : /*---------------------------------------------------------------------*
    2846             :  * core_switching_hq_prepare_dec()
    2847             :  *
    2848             :  * Preprocessing in the first HQ frame after ACELP frame
    2849             :  * Modify bit allocation for HQ core by removing ACELP subframe budget
    2850             :  *---------------------------------------------------------------------*/
    2851             : 
    2852             : /*---------------------------------------------------------------------*
    2853             :  * bandwidth_switching_detect()
    2854             :  *
    2855             :  * Classification for band-width switching
    2856             :  *---------------------------------------------------------------------*/
    2857             : 
    2858     1029590 : void bandwidth_switching_detect_ivas_fx(
    2859             :     Decoder_State *st_fx /* i/o: encoder state structure */
    2860             : )
    2861             : {
    2862     1029590 :     test();
    2863     1029590 :     test();
    2864     1029590 :     IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) )
    2865             :     {
    2866             :         /* there is no BWE in TD stereo secondary channel and in MDCT stereo, IGF is part of the core decoding -> no BW switching -> reset BWS counters */
    2867      651235 :         st_fx->prev_bws_cnt = 0;
    2868      651235 :         st_fx->bws_cnt = 0;
    2869      651235 :         st_fx->bws_cnt1 = 0;
    2870      651235 :         move16();
    2871      651235 :         move16();
    2872      651235 :         move16();
    2873             : 
    2874      651235 :         return;
    2875             :     }
    2876             :     /* update band-width switching counter */
    2877      378355 :     test();
    2878      378355 :     test();
    2879      378355 :     test();
    2880      378355 :     test();
    2881      378355 :     IF( GE_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) )
    2882             :     {
    2883        2566 :         st_fx->bws_cnt1 = 0;
    2884        2566 :         move16();
    2885             :     }
    2886      375789 :     ELSE IF( GT_32( st_fx->total_brate, ACELP_9k60 ) && LT_32( st_fx->last_core_brate, ACELP_9k60 ) && EQ_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) && ( st_fx->last_low_rate_mode == 0 ) )
    2887             :     {
    2888          13 :         st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 );
    2889          13 :         move16();
    2890             :     }
    2891      375776 :     ELSE IF( st_fx->bws_cnt1 > 0 )
    2892             :     {
    2893         512 :         IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) )
    2894             :         {
    2895          56 :             st_fx->bws_cnt = sub( shl( sub( N_NS2W_FRAMES, st_fx->bws_cnt1 ), 1 ), 1 );
    2896          56 :             move16();
    2897             :         }
    2898             :         ELSE
    2899             :         {
    2900         456 :             st_fx->bws_cnt = 0;
    2901         456 :             move16();
    2902             :         }
    2903             : 
    2904         512 :         IF( LT_16( st_fx->bwidth, st_fx->last_bwidth ) )
    2905             :         {
    2906          56 :             st_fx->bws_cnt1 = 0;
    2907          56 :             move16();
    2908             :         }
    2909             :         ELSE
    2910             :         {
    2911         456 :             IF( EQ_16( st_fx->bwidth, SWB ) )
    2912             :             {
    2913         344 :                 st_fx->bws_cnt1 = add( st_fx->bws_cnt1, 1 );
    2914         344 :                 move16();
    2915             :             }
    2916             :             ELSE
    2917             :             {
    2918         112 :                 st_fx->bws_cnt1 = 0;
    2919         112 :                 move16();
    2920             :             }
    2921             :         }
    2922             :     }
    2923             : 
    2924             :     /* update band-width switching counter */
    2925      378355 :     test();
    2926      378355 :     test();
    2927      378355 :     test();
    2928      378355 :     IF( GE_16( st_fx->bws_cnt, N_WS2N_FRAMES ) )
    2929             :     {
    2930        2569 :         st_fx->bws_cnt = 0;
    2931        2569 :         move16();
    2932             :     }
    2933      375786 :     ELSE IF( LT_32( st_fx->total_brate, ACELP_9k60 ) && GT_32( st_fx->last_core_brate, ACELP_9k60 ) && LT_16( st_fx->bwidth, st_fx->last_bwidth ) && EQ_16( st_fx->bwidth, WB ) )
    2934             :     {
    2935         281 :         st_fx->bws_cnt = add( st_fx->bws_cnt, 1 );
    2936         281 :         move16();
    2937             :     }
    2938      375505 :     ELSE IF( st_fx->bws_cnt > 0 )
    2939             :     {
    2940        2750 :         IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) )
    2941             :         {
    2942         197 :             st_fx->bws_cnt1 = shr( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 1 );
    2943         197 :             move16();
    2944             :         }
    2945             :         ELSE
    2946             :         {
    2947        2553 :             st_fx->bws_cnt1 = 0;
    2948        2553 :             move16();
    2949             :         }
    2950             : 
    2951        2750 :         IF( GT_16( st_fx->bwidth, st_fx->last_bwidth ) )
    2952             :         {
    2953         197 :             st_fx->bws_cnt = 0;
    2954         197 :             move16();
    2955             :         }
    2956             :         ELSE
    2957             :         {
    2958        2553 :             IF( EQ_16( st_fx->bwidth, WB ) )
    2959             :             {
    2960        2553 :                 st_fx->bws_cnt = add( st_fx->bws_cnt, 1 );
    2961        2553 :                 move16();
    2962             :             }
    2963             :             ELSE
    2964             :             {
    2965           0 :                 st_fx->bws_cnt = 0;
    2966           0 :                 move16();
    2967             :             }
    2968             :         }
    2969             :     }
    2970             : 
    2971      378355 :     return;
    2972             : }
    2973             : 
    2974             : 
    2975             : /*---------------------------------------------------------------------*
    2976             :  * bw_switching_pre_proc()
    2977             :  *
    2978             :  * Band-width switching pre-processing
    2979             :  *---------------------------------------------------------------------*/
    2980      547314 : void ivas_bw_switching_pre_proc_fx(
    2981             :     Decoder_State *st,               /* i/o: decoder state structure                  */
    2982             :     const Word32 last_element_brate, /* i  : last element bitrate                     */
    2983             :     const Word16 nchan_out /* i  : number of output channels                */,
    2984             :     Word32 *old_syn_12k8_16k_fx,
    2985             :     Word16 Q,
    2986             :     Word16 Q_audio )
    2987             : {
    2988             :     Word16 i;
    2989             :     Word32 syn_dct_fx[L_FRAME];
    2990             : 
    2991             : 
    2992      547314 :     Flag Overflow = 0;
    2993      547314 :     move32();
    2994             : 
    2995      547314 :     IF( st->element_mode > EVS_MONO )
    2996             :     {
    2997      547314 :         test();
    2998      547314 :         test();
    2999      547314 :         test();
    3000      547314 :         test();
    3001      547314 :         test();
    3002      547314 :         test();
    3003      547314 :         test();
    3004      547314 :         test();
    3005      547314 :         test();
    3006      547314 :         test();
    3007      547314 :         IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) )
    3008             :         {
    3009             :             /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */
    3010             :             Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k];
    3011      153815 :             Copy_Scale_sig_32_16( old_syn_12k8_16k_fx, old_syn_12k8_16k_tmp_16fx, st->L_frame, sub( -1, Q ) );
    3012      153815 :             st->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st->L_frame ), sub( Q, 8 ) ) ); // Q24+(Q-8) - 16
    3013      153815 :             move16();
    3014             :         }
    3015             : 
    3016      547314 :         return;
    3017             :     }
    3018             : 
    3019             : 
    3020           0 :     test();
    3021           0 :     test();
    3022           0 :     IF( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) )
    3023           0 :     {
    3024             :         /*----------------------------------------------------------------------*
    3025             :          * Calculate tilt of the ACELP core synthesis
    3026             :          *----------------------------------------------------------------------*/
    3027             : 
    3028           0 :         st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q, st->L_frame );
    3029           0 :         move16();
    3030             :         /*-------------------------------------------------------------------------------*
    3031             :          * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis
    3032             :          *-------------------------------------------------------------------------------*/
    3033           0 :         edct_fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, &Q );
    3034           0 :         Word64 W_tmp = 0;
    3035           0 :         move64();
    3036             :         Word32 tmp;
    3037             :         Word16 shift;
    3038           0 :         FOR( i = 0; i < L_FRAME / 2; i++ )
    3039             :         {
    3040           0 :             W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) );
    3041             :         }
    3042           0 :         shift = W_norm( W_tmp );
    3043           0 :         W_tmp = W_shl( W_tmp, shift );
    3044           0 :         tmp = W_extract_h( W_tmp );
    3045           0 :         tmp = L_shr( tmp, 8 );
    3046             : 
    3047           0 :         tmp = getSqrtWord32( tmp );
    3048           0 :         st->enerLL_fx = tmp;
    3049           0 :         move32();
    3050           0 :         st->enerLL_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 );
    3051           0 :         move16();
    3052           0 :         W_tmp = 0;
    3053           0 :         move64();
    3054           0 :         FOR( ; i < L_FRAME; i++ )
    3055             :         {
    3056           0 :             W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) );
    3057             :         }
    3058           0 :         shift = W_norm( W_tmp );
    3059           0 :         W_tmp = W_shl( W_tmp, shift );
    3060           0 :         tmp = W_extract_h( W_tmp ); // Q = Q + shift - 32
    3061           0 :         tmp = L_shr( tmp, 7 );      // divide by 128
    3062           0 :         tmp = getSqrtWord32( tmp );
    3063           0 :         st->enerLH_fx = tmp;
    3064           0 :         move32();
    3065           0 :         st->enerLH_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 );
    3066           0 :         move16();
    3067             :     }
    3068             :     ELSE
    3069             :     {
    3070           0 :         IF( st->hHQ_core->old_is_transient[0] )
    3071             :         {
    3072           0 :             Word32 tmp, L_tmp = 0;
    3073           0 :             move32();
    3074           0 :             FOR( i = 0; i < 32; i++ )
    3075             :             {
    3076           0 :                 L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
    3077             :             }
    3078           0 :             tmp = L_shr( L_tmp, 5 ); // divide by 32
    3079           0 :             tmp = getSqrtWord32( tmp );
    3080           0 :             st->enerLL_fx = tmp;
    3081           0 :             move32();
    3082           0 :             st->enerLL_fx_Q = Q_audio;
    3083           0 :             move16();
    3084             : 
    3085           0 :             L_tmp = 0;
    3086           0 :             move32();
    3087           0 :             FOR( ; i < 64; i++ )
    3088             :             {
    3089           0 :                 L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
    3090             :             }
    3091             : 
    3092           0 :             tmp = L_shr( L_tmp, 5 ); // divide by 32
    3093           0 :             tmp = getSqrtWord32( tmp );
    3094           0 :             st->enerLH_fx = tmp;
    3095           0 :             move32();
    3096           0 :             st->enerLH_fx_Q = Q_audio;
    3097           0 :             move16();
    3098             :         }
    3099             :         ELSE
    3100             :         {
    3101           0 :             Word32 tmp, L_tmp = 0;
    3102           0 :             move32();
    3103           0 :             FOR( i = 0; i < L_FRAME / 2; i++ )
    3104             :             {
    3105           0 :                 L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
    3106             :             }
    3107           0 :             tmp = L_shr( L_tmp, 5 ); // divide by 32
    3108           0 :             tmp = getSqrtWord32( tmp );
    3109           0 :             st->enerLL_fx = tmp;
    3110           0 :             move32();
    3111           0 :             st->enerLL_fx_Q = Q_audio;
    3112           0 :             move16();
    3113             : 
    3114           0 :             L_tmp = 0;
    3115           0 :             move32();
    3116           0 :             FOR( ; i < L_FRAME; i++ )
    3117             :             {
    3118           0 :                 L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow );
    3119             :             }
    3120           0 :             tmp = L_shr( L_tmp, 5 ); // divide by 32
    3121           0 :             tmp = getSqrtWord32( tmp );
    3122           0 :             st->enerLL_fx = tmp;
    3123           0 :             move32();
    3124           0 :             st->enerLL_fx_Q = Q_audio;
    3125           0 :             move16();
    3126             :         }
    3127             :     }
    3128             : 
    3129           0 :     test();
    3130           0 :     test();
    3131           0 :     test();
    3132           0 :     test();
    3133           0 :     test();
    3134           0 :     test();
    3135           0 :     test();
    3136           0 :     IF( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) )
    3137             :     {
    3138           0 :         st->prev_ener_shb_fx = 0;
    3139           0 :         move16();
    3140           0 :         IF( st->hBWE_FD != NULL )
    3141             :         {
    3142           0 :             set16_fx( st->hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV );
    3143             :         }
    3144             :     }
    3145           0 :     ELSE IF( ( ( ( st->core == ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) )
    3146             :     {
    3147           0 :         st->attenu_fx = 3277; // 0.1f in Q15
    3148           0 :         move16();
    3149             :     }
    3150             : 
    3151           0 :     test();
    3152           0 :     test();
    3153           0 :     test();
    3154           0 :     test();
    3155           0 :     test();
    3156           0 :     if ( EQ_16( st->last_core, HQ_CORE ) || ( ( st->last_core == ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) )
    3157             :     {
    3158           0 :         st->prev_fractive = 0;
    3159           0 :         move16();
    3160             :     }
    3161             : 
    3162           0 :     return;
    3163             : }

Generated by: LCOV version 1.14