LCOV - code coverage report
Current view: top level - lib_dec - acelp_core_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 1056 1138 92.8 %
Date: 2025-08-23 01:22:27 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : #include <stdint.h>
      37             : #include <assert.h>
      38             : #include <math.h>
      39             : #include "options.h"
      40             : #include "cnst.h"
      41             : #include "rom_com.h"
      42             : #include "prot_fx.h"
      43             : #include "ivas_cnst.h"
      44             : #include "ivas_rom_com.h"
      45             : #include "wmc_auto.h"
      46             : #include "ivas_prot_fx.h"
      47             : 
      48             : 
      49             : /*-------------------------------------------------------------------*
      50             :  * acelp_core_dec_fx()
      51             :  *
      52             :  * ACELP core decoder
      53             :  *-------------------------------------------------------------------*/
      54             : 
      55      171583 : ivas_error acelp_core_dec_fx(
      56             :     Decoder_State *st,                   /* i/o: decoder state structure                                                 */
      57             :     Word16 output_fx[],                  /* o  : synthesis @internal Fs                                                  Q_syn*/
      58             :     Word16 synth_fx16[],                 /* o  : synthesis                                                               Q_syn2*/
      59             :     Word16 save_hb_synth_fx16[],         /* o  : HB synthesis                                                            Q0*/
      60             :     Word32 bwe_exc_extended_fx[],        /* i/o: bandwidth extended excitation                                           2*Q_exc*/
      61             :     Word16 *voice_factors_fx,            /* o  : voicing factors                                                         Q15*/
      62             :     Word16 old_syn_12k8_16k_fx[],        /* o  : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE  Q_syn2-1*/
      63             :     const Word16 sharpFlag,              /* i  : formant sharpening flag                                                 */
      64             :     Word16 pitch_buf_fx[NB_SUBFR16k],    /* o  : Word16 pitch for each subframe                                        Q6*/
      65             :     Word16 *unbits,                      /* o  : number of unused bits                       */
      66             :     Word16 *sid_bw,                      /* o  : 0-NB/WB, 1-SWB SID                          */
      67             :     STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle                                                Qlog2(2.56)*/
      68             : #ifndef NONBE_1325_TD_STEREO_QUANT_LSF_SEC
      69             :     const Word16 tdm_lspQ_PCh_fx[M], /* i  : Q LSPs for primary channel                                              Q15*/
      70             : #endif
      71             :     const Word16 tdm_lsfQ_PCh_fx[M],  /* i  : Q LSFs for primary channel                                              */
      72             :     const Word16 use_cldfb_for_dft,   /* i  : flag to use of CLDFB for DFT Stereo         */
      73             :     const Word16 last_element_mode,   /* i  : last element mode                           */
      74             :     const Word32 last_element_brate,  /* i  : last element bitrate                        */
      75             :     const Word16 flag_sec_CNA,        /* i  : CNA flag for secondary channel              */
      76             :     const Word16 nchan_out,           /* i  : number of output channels                   */
      77             :     STEREO_CNG_DEC_HANDLE hStereoCng, /* i  : stereo CNG handle                           */
      78             :     const Word16 read_sid_info        /* i  : read SID info flag                          */
      79             : )
      80             : {
      81             :     Word32 synth_fx[960], save_hb_synth_fx[960] /*, bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]*/;
      82             :     Word16 old_exc_fx[L_EXC_DEC], *exc_fx;                                           /* excitation signal buffer              */
      83             :     Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx;                               /* synthesis signal buffer               */
      84             :     Word16 output_frame;                                                             /* frame length at output sampling freq. */
      85             :     Word16 lsf_new_fx[M];                                                            /* LSFs at the end of the frame  Qlog2(2.56)        */
      86             :     Word16 lsp_new_fx[M];                                                            /* LSPs at the end of the frame    Q15   */
      87             :     Word16 lsp_mid_fx[M];                                                            /* LSPs in the middle of the frame       */
      88             :     Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )];                                           /* A(q) quantized for the 4 subframes    */
      89             :     Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx;                            /* total excitation buffer               */
      90             :     Word16 mem_tmp_fx[M];                                                            /* temporary synthesis filter memory     */
      91             :     Word32 enr_q_fx;                                                                 /* E information for FER protection      */
      92             :     Word16 tmp_noise_fx;                                                             /* Long term temporary noise energy      */
      93             :     Word16 Es_pred_fx;                                                               /* predicted scaled innov. energy Q8     */
      94             :     Word16 FEC_pitch_fx;                                                             /* FEC pitch                             */
      95             :     Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer                     */
      96             :     Word16 *bwe_exc_fx;                                                              /* Excitation for SWB TBE                */
      97             :     Word16 i, j, int_fs;
      98             :     Word16 tc_subfr;
      99             :     Word16 allow_cn_step;
     100             :     Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM];
     101             :     Word16 last_pulse_pos;
     102             :     Word16 T0_tmp;
     103             :     Word16 do_WI;
     104             :     Word16 dct_buffer_fx[DCT_L_POST];
     105             :     Word16 exc_buffer_fx[DCT_L_POST];
     106             :     Word16 dct_exc_tmp_fx[L_FRAME16k];
     107             :     Word16 nb_bits; /* number of bits                       */
     108             :     Word16 indice;  /* parameter indices to write           */
     109             :     Word16 gain_buf_fx[NB_SUBFR16k];
     110             :     Word16 syn_fx_tmp2[L_FRAME_16k];
     111             :     Word16 pitch_buf_tmp[NB_SUBFR16k];
     112             :     Word16 update_flg;
     113             :     Word32 q_env_fx[20];
     114             :     Word16 exc3_fx[L_FRAME16k];
     115             :     Word16 syn1_tmp_fx[L_FRAME16k + 2], *syn1_fx;
     116             :     Word32 *realBuffer_fx[CLDFB_NO_COL_MAX], *imagBuffer_fx[CLDFB_NO_COL_MAX];
     117             :     Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
     118             :     Word32 imagBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
     119             :     Word16 LSF_Q_prediction; /* LSF prediction mode                  */
     120             :     Word16 avoid_lpc_burst_on_recovery;
     121             :     Word16 tmpF_fx;
     122             :     Word16 uc_two_stage_flag;
     123             :     Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag;
     124             :     Word16 *old_exc_s_fx; /* Start of last excitation frame       */
     125             :     Word16 *p_tdm_Pri_pitch_buf_fx;
     126             :     Word16 tmp, exp, local_element_mode;
     127             :     ivas_error error;
     128             :     Word32 bpf_error_signal_fx[L_FRAME16k];
     129             :     Word16 bpf_error_signal_16fx[L_FRAME16k];
     130             :     Word16 Q_real;
     131             :     Word32 max_real, max_imag, max_val;
     132             : 
     133      171583 :     set32_fx( bpf_error_signal_fx, 0, L_FRAME16k );
     134      171583 :     set16_fx( bpf_error_signal_16fx, 0, L_FRAME16k );
     135      171583 :     set16_fx( Aq_fx, 0, NB_SUBFR16k * ( M + 1 ) );
     136      171583 :     set16_fx( old_bwe_exc_fx, 0, ( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ) );
     137             : 
     138      171583 :     error = IVAS_ERR_OK;
     139      171583 :     move32();
     140             : 
     141      171583 :     test();
     142      171583 :     test();
     143      171583 :     test();
     144      171583 :     IF( 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 ) )
     145             :     {
     146             :         /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */
     147        1090 :         return error;
     148             :     }
     149             : 
     150      170493 :     push_wmops( "acelp_core_dec" );
     151             : 
     152             :     /* output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); */
     153      170493 :     output_frame = extract_l( Mpy_32_32( st->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) );
     154             : 
     155             :     /*----------------------------------------------------------------*
     156             :      * stereo SID and CNG frames processing
     157             :      *----------------------------------------------------------------*/
     158             : 
     159      170493 :     test();
     160      170493 :     test();
     161      170493 :     IF( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) )
     162             :     {
     163        5470 :         IF( EQ_16( st->cng_type, FD_CNG ) )
     164             :         {
     165        4233 :             configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
     166             : 
     167             :             Word16 old_NoiseEstExp;
     168        4233 :             old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp;
     169        4233 :             move16();
     170             : 
     171             :             /* Only run parameter decoding in SID frames */
     172        4233 :             IF( EQ_32( st->core_brate, SID_2k40 ) )
     173             :             {
     174         571 :                 FdCng_decodeSID_ivas_fx( st );
     175             : 
     176             :                 Word16 n1, n2;
     177         571 :                 n1 = L_norm_arr( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART );
     178         571 :                 n2 = L_norm_arr( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART );
     179             : 
     180         571 :                 Word16 common_e = s_max( sub( old_NoiseEstExp, n2 ), sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, n1 ) );
     181         571 :                 scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, common_e ) );
     182         571 :                 scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( old_NoiseEstExp, common_e ) );
     183         571 :                 st->hFdCngDec->hFdCngCom->sidNoiseEstExp = common_e;
     184         571 :                 move16();
     185             :             }
     186             : 
     187      105825 :             FOR( i = 0; i < NPART; i++ )
     188             :             {
     189      101592 :                 st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ),
     190      101592 :                                                                          STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] );
     191      101592 :                 move32();
     192             :             }
     193             : 
     194        4233 :             ApplyFdCng_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 );
     195             :         }
     196             :         ELSE
     197             :         {
     198        1237 :             configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
     199             : 
     200             :             /* decode CNG parameters */
     201        1237 :             CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx );
     202             : 
     203             :             /* comfort noise generation */
     204        1237 :             CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode );
     205             : 
     206        1237 :             Copy( Aq_fx, st->Aq_cng, M + 1 ); /*Q12*/
     207             : 
     208             :             /* update old LSP and LSF vector */
     209        1237 :             Copy( lsf_new_fx, st->lsf_old_fx, M ); /*Qlog2(2.56)*/
     210        1237 :             Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/
     211             :         }
     212             : 
     213        5470 :         set16_fx( output_fx, 0, output_frame );  /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */
     214        5470 :         set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */
     215             : 
     216             :         /* CN generation done in DFT domain */
     217        5470 :         pop_wmops();
     218             : 
     219        5470 :         return error;
     220             :     }
     221             : 
     222             :     /*----------------------------------------------------------------*
     223             :      * Active frames processing
     224             :      *----------------------------------------------------------------*/
     225             : 
     226             :     /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
     227     2805391 :     FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
     228             :     {
     229     2640368 :         set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
     230     2640368 :         set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
     231     2640368 :         realBuffer_fx[i] = realBufferTmp_fx[i];
     232     2640368 :         imagBuffer_fx[i] = imagBufferTmp_fx[i];
     233             :     }
     234             : 
     235             :     /*----------------------------------------------------------------*
     236             :      * Initialization
     237             :      *----------------------------------------------------------------*/
     238             : 
     239      165023 :     LSF_Q_prediction = -1;
     240      165023 :     move16();
     241      165023 :     set16_fx( syn_tmp_fx, 0, L_SUBFR );
     242      165023 :     psyn_fx = syn_tmp_fx + L_SUBFR;
     243      165023 :     syn1_tmp_fx[0] = 0;
     244      165023 :     move16();
     245      165023 :     syn1_tmp_fx[1] = 0;
     246      165023 :     move16();
     247      165023 :     syn1_fx = syn1_tmp_fx + 2;
     248      165023 :     st->bpf_off = 0;
     249      165023 :     move16();
     250             : 
     251      165023 :     test();
     252      165023 :     test();
     253      165023 :     test();
     254      165023 :     test();
     255      165023 :     test();
     256      165023 :     test();
     257      165023 :     IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->last_core_brate, SID_2k40 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->last_core_brate, SID_2k40 ) ) )
     258             :     {
     259             :         /* in case of HQ->ACELP switching, do not apply BPF */
     260       19059 :         st->bpf_off = 1;
     261       19059 :         move16();
     262       19059 :         if ( st->hPFstat != NULL )
     263             :         {
     264             :             /* in case of core switching, reset post-filter memories */
     265       11805 :             st->hPFstat->on = 0;
     266       11805 :             move16();
     267             :         }
     268             : 
     269       19059 :         if ( st->hGSCDec != NULL )
     270             :         {
     271             :             /* reset the GSC pre echo energy threshold in case of switching */
     272       11805 :             st->hGSCDec->Last_frame_ener_fx = MAX_32;
     273       11805 :             move32();
     274             :         }
     275             :     }
     276             : 
     277      165023 :     test();
     278      165023 :     if ( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) )
     279             :     {
     280             :         /* reset the GSC pre echo energy threshold in case of FEC */
     281        2992 :         st->hGSCDec->Last_frame_ener_fx = MAX_32;
     282        2992 :         move32();
     283             :     }
     284             : 
     285      165023 :     test();
     286      165023 :     test();
     287      165023 :     test();
     288      165023 :     test();
     289      165023 :     IF( st->hFdCngDec != NULL && ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || st->last_core_brate == FRAME_NO_DATA ) )
     290             :     {
     291        5001 :         set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN );
     292        5001 :         set16_fx( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN );
     293             :     }
     294             : 
     295      165023 :     st->clas_dec = st->last_good;
     296      165023 :     move16();
     297      165023 :     enr_q_fx = 0;
     298      165023 :     move32();
     299      165023 :     Es_pred_fx = 0;
     300      165023 :     move16();
     301      165023 :     tmp_noise_fx = 0;
     302      165023 :     move16();
     303      165023 :     Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/
     304      165023 :     exc_fx = old_exc_fx + L_EXC_MEM_DEC;
     305             : 
     306      165023 :     IF( st->hWIDec != NULL )
     307             :     {
     308           0 :         Copy( st->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM );
     309             :     }
     310             :     ELSE
     311             :     {
     312      165023 :         set16_fx( old_exc2_fx, 0, L_EXC_MEM );
     313             :     }
     314      165023 :     exc2_fx = old_exc2_fx + L_EXC_MEM;
     315             : 
     316      165023 :     IF( st->hBWE_TD != NULL )
     317             :     {
     318      157719 :         Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); /*Q_exc*/
     319      157719 :         bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2;
     320             :     }
     321             :     ELSE
     322             :     {
     323        7304 :         bwe_exc_fx = NULL;
     324             :     }
     325             : 
     326      165023 :     last_pulse_pos = 0;
     327      165023 :     move16();
     328      165023 :     do_WI = 0;
     329      165023 :     move16();
     330      165023 :     st->GSC_noisy_speech = 0;
     331      165023 :     move16();
     332      165023 :     st->relax_prev_lsf_interp = 0;
     333      165023 :     move16();
     334      165023 :     set16_fx( gain_buf_fx, 0, NB_SUBFR16k );
     335             : 
     336      165023 :     IF( EQ_16( st->L_frame, L_FRAME ) )
     337             :     {
     338       81826 :         st->gamma = GAMMA1;
     339       81826 :         move16();
     340       81826 :         st->inv_gamma = GAMMA1_INV;
     341       81826 :         move16();
     342       81826 :         st->preemph_fac = PREEMPH_FAC;
     343       81826 :         move16();
     344       81826 :         int_fs = INT_FS_12k8;
     345       81826 :         move16();
     346             :     }
     347             :     ELSE
     348             :     {
     349       83197 :         st->gamma = GAMMA16k;
     350       83197 :         move16();
     351       83197 :         st->inv_gamma = GAMMA16k_INV;
     352       83197 :         move16();
     353       83197 :         st->preemph_fac = PREEMPH_FAC_16k;
     354       83197 :         move16();
     355       83197 :         int_fs = INT_FS_16k;
     356       83197 :         move16();
     357             :     }
     358             : 
     359      165023 :     test();
     360             :     /* reset post-filter in case of switching */
     361      165023 :     if ( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) )
     362             :     {
     363       23530 :         st->hPFstat->reset = 1;
     364       23530 :         move16();
     365             :     }
     366             : 
     367      165023 :     avoid_lpc_burst_on_recovery = 0;
     368      165023 :     move16();
     369      165023 :     test();
     370      165023 :     test();
     371      165023 :     if ( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && ( st->last_core != 0 ) )
     372             :     {
     373          28 :         avoid_lpc_burst_on_recovery = 1;
     374          28 :         move16();
     375             :     }
     376      165023 :     test();
     377             : 
     378             :     /* TD stereo parameters */
     379      165023 :     IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) )
     380             :     {
     381        3686 :         tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag;
     382        3686 :         move16();
     383        3686 :         tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode;
     384        3686 :         move16();
     385        3686 :         tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag;
     386        3686 :         move16();
     387        3686 :         p_tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx;
     388             :     }
     389             :     ELSE
     390             :     {
     391      161337 :         tdm_lp_reuse_flag = 0;
     392      161337 :         move16();
     393      161337 :         tdm_low_rate_mode = 0;
     394      161337 :         move16();
     395      161337 :         test();
     396      161337 :         if ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode )
     397             :         {
     398        7145 :             tdm_low_rate_mode = 1;
     399        7145 :             move16();
     400             :         }
     401      161337 :         tdm_Pitch_reuse_flag = 0;
     402      161337 :         move16();
     403      161337 :         p_tdm_Pri_pitch_buf_fx = NULL;
     404             :     }
     405             : 
     406             :     /*----------------------------------------------------------------*
     407             :      * Updates in case of internal sampling rate switching
     408             :      *----------------------------------------------------------------*/
     409             : 
     410      165023 :     test();
     411      165023 :     test();
     412      165023 :     IF( NE_16( st->last_L_frame, st->L_frame ) && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) )
     413             :     {
     414             :         Word16 dec;
     415             : 
     416         707 :         IF( ( st->hPFstat->on != 0 ) )
     417             :         {
     418             :             Word16 mem_syn_r_size_old, mem_syn_r_size_new;
     419         639 :             mem_syn_r_size_old = mult_r( 2048, st->last_L_frame ); /* 1.25/20.f = 2048 (Q15)*/
     420         639 :             mem_syn_r_size_new = mult_r( 2048, st->L_frame );      /* 1.25/20.f = 2048 (Q15)*/
     421         639 :             lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
     422         639 :             lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
     423             :         }
     424             : 
     425             :         /* convert quantized LSP vector */
     426         707 :         st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
     427         707 :         move16();
     428             : 
     429             :         /* convert old quantized LSF vector */
     430         707 :         lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, int_fs );
     431             : 
     432             :         /* FEC - update adaptive LSF mean vector */
     433         707 :         Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M );        /*Qlog2(2.56)*/
     434         707 :         Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M );        /*Qlog2(2.56)*/
     435         707 :         Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /*Qlog2(2.56)*/
     436             : 
     437             :         /* Reset LPC mem */
     438         707 :         IF( EQ_32( st->sr_core, INT_FS_16k ) )
     439             :         {
     440         430 :             Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/
     441             :         }
     442             :         ELSE
     443             :         {
     444         277 :             Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/
     445             :         }
     446         707 :         set16_fx( st->mem_MA_fx, 0, M );
     447             : 
     448             :         /* update synthesis filter memories */
     449         707 :         dec = DEC;
     450         707 :         move16();
     451         707 :         if ( st->element_mode != EVS_MONO )
     452             :         {
     453         707 :             dec = DEC_IVAS;
     454         707 :             move16();
     455             :         }
     456         707 :         ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec );
     457         707 :         Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC );                           /*Q_exc*/
     458         707 :         Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/
     459         707 :         Copy( st->mem_syn2_fx, st->mem_syn3_fx, M );                                 /*Q_syn*/
     460             :     }
     461             : 
     462             :     /* update buffer of old subframe pitch values */
     463      165023 :     IF( NE_16( st->last_L_frame, st->L_frame ) )
     464             :     {
     465        2004 :         IF( EQ_16( st->L_frame, L_FRAME ) )
     466             :         {
     467        1224 :             IF( EQ_16( st->last_L_frame, L_FRAME32k ) )
     468             :             {
     469         322 :                 tmpF_fx = 13107; // Q15
     470         322 :                 move16();
     471             :             }
     472         902 :             ELSE IF( EQ_16( st->last_L_frame, 512 ) )
     473             :             {
     474         330 :                 tmpF_fx = 16384; // Q15
     475         330 :                 move16();
     476             :             }
     477             :             ELSE /* st->last_L_frame == L_FRAME16k */
     478             :             {
     479         572 :                 tmpF_fx = 26214; // Q15
     480         572 :                 move16();
     481             :             }
     482             : 
     483        6120 :             FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ )
     484             :             {
     485        4896 :                 st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16
     486        4896 :                 move32();
     487             :             }
     488             : 
     489        6120 :             FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ )
     490             :             {
     491        4896 :                 st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16
     492        4896 :                 move32();
     493             :             }
     494             :         }
     495             :         ELSE
     496             :         {
     497         780 :             exp = 0;
     498         780 :             move16();
     499         780 :             IF( EQ_16( st->last_L_frame, L_FRAME32k ) )
     500             :             {
     501          42 :                 tmpF_fx = 16384; // Q15
     502          42 :                 move16();
     503             :             }
     504         738 :             ELSE IF( EQ_16( st->last_L_frame, 512 ) )
     505             :             {
     506         264 :                 tmpF_fx = 20480; // Q15
     507         264 :                 move16();
     508             :             }
     509             :             ELSE /* st->last_L_frame == L_FRAME12k8 */
     510             :             {
     511         474 :                 tmpF_fx = 20480; // Q14
     512         474 :                 move16();
     513         474 :                 exp = 1;
     514         474 :                 move16();
     515             :             }
     516        3900 :             FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- )
     517             :             {
     518        3120 :                 st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15
     519        3120 :                 move32();
     520             :             }
     521         780 :             st->old_pitch_buf_fx[NB_SUBFR + 1] = st->old_pitch_buf_fx[NB_SUBFR + 2];
     522         780 :             move32();
     523             : 
     524        3900 :             FOR( i = NB_SUBFR - 1; i >= 0; i-- )
     525             :             {
     526        3120 :                 st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15
     527        3120 :                 move32();
     528             :             }
     529         780 :             st->old_pitch_buf_fx[0] = st->old_pitch_buf_fx[1];
     530         780 :             move32();
     531             :         }
     532             :     }
     533             : 
     534      165023 :     IF( NE_16( st->bfi_pitch_frame, st->L_frame ) )
     535             :     {
     536        3225 :         IF( EQ_16( st->L_frame, L_FRAME ) )
     537             :         {
     538        1205 :             IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) )
     539             :             {
     540         322 :                 tmpF_fx = 13107; // Q15
     541         322 :                 move16();
     542             :             }
     543         883 :             ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) )
     544             :             {
     545         330 :                 tmpF_fx = 16384; // Q15
     546         330 :                 move16();
     547             :             }
     548             :             ELSE /* st->bfi_pitch_frame == L_FRAME16k */
     549             :             {
     550         553 :                 tmpF_fx = 26214; // Q15
     551         553 :                 move16();
     552             :             }
     553        1205 :             st->bfi_pitch_fx = mult_r( st->bfi_pitch_fx, tmpF_fx );
     554        1205 :             move16();
     555        1205 :             st->bfi_pitch_frame = L_FRAME;
     556        1205 :             move16();
     557             :         }
     558             :         ELSE
     559             :         {
     560        2020 :             exp = 0;
     561        2020 :             move16();
     562        2020 :             IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) )
     563             :             {
     564          42 :                 tmpF_fx = 16384; // Q15
     565          42 :                 move16();
     566             :             }
     567        1978 :             ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) )
     568             :             {
     569         266 :                 tmpF_fx = 20480; // Q15
     570         266 :                 move16();
     571             :             }
     572             :             ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */
     573             :             {
     574        1712 :                 tmpF_fx = 20480; // Q14
     575        1712 :                 move16();
     576        1712 :                 exp = 1;
     577        1712 :                 move16();
     578             :             }
     579             : 
     580        2020 :             st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx );
     581        2020 :             move16();
     582        2020 :             st->bfi_pitch_frame = L_FRAME16k;
     583        2020 :             move16();
     584             :         }
     585             :     }
     586             : 
     587      165023 :     test();
     588      165023 :     test();
     589      165023 :     if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) )
     590             :     {
     591           0 :         st->rate_switching_reset = 1;
     592           0 :         move16();
     593             :     }
     594             : 
     595             :     /*----------------------------------------------------------------------*
     596             :      * GOOD frame
     597             :      *----------------------------------------------------------------------*/
     598             : 
     599      165023 :     IF( !st->bfi )
     600             :     {
     601             : 
     602             :         /*----------------------------------------------------------------*
     603             :          * Decoding of TC subframe classification
     604             :          *----------------------------------------------------------------*/
     605             : 
     606      162064 :         tc_subfr = -1;
     607      162064 :         move16();
     608      162064 :         IF( EQ_16( st->coder_type, TRANSITION ) )
     609             :         {
     610       13093 :             tc_subfr = tc_classif_fx( st, st->L_frame );
     611             :         }
     612             : 
     613             :         /*----------------------------------------------------------------*
     614             :          * Decoding of GSC IVAS mode
     615             :          *----------------------------------------------------------------*/
     616             : 
     617      162064 :         test();
     618      162064 :         test();
     619      162064 :         test();
     620      162064 :         test();
     621      162064 :         IF( st->element_mode > EVS_MONO && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode )
     622             :         {
     623      130777 :             test();
     624      130777 :             test();
     625      130777 :             IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && EQ_16( st->inactive_coder_type_flag, 1 ) ) )
     626             :             {
     627       13834 :                 st->GSC_IVAS_mode = get_next_indice_fx( st, 2 );
     628       13834 :                 move16();
     629             :             }
     630             :         }
     631             : 
     632             :         /*----------------------------------------------------------------*
     633             :          * Decoding of inactive CNG frames
     634             :          *----------------------------------------------------------------*/
     635             : 
     636      162064 :         test();
     637      162064 :         IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) )
     638       19522 :         {
     639             :             /* decode CNG parameters */
     640       19522 :             IF( st->cng_type == LP_CNG )
     641             :             {
     642        1141 :                 CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx );
     643        1141 :                 Copy( Aq_fx, st->Aq_cng, add( M, 1 ) );
     644             : 
     645             :                 /* comfort noise generation */
     646        1141 :                 local_element_mode = st->element_mode;
     647        1141 :                 move16();
     648             : 
     649        1141 :                 test();
     650        1141 :                 test();
     651        1141 :                 if ( ( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st->masa_sid_format, 1 ) )
     652             :                 {
     653        1141 :                     local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */
     654        1141 :                     move16();
     655             :                 }
     656        1141 :                 CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, local_element_mode );
     657             :             }
     658             :             ELSE
     659             :             {
     660       18381 :                 test();
     661       18381 :                 IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     662             :                 {
     663        1342 :                     IF( EQ_16( st->element_mode, EVS_MONO ) )
     664             :                     {
     665           0 :                         FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st );
     666             :                     }
     667             :                     ELSE
     668             :                     {
     669        1342 :                         Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp;
     670        1342 :                         move16();
     671             : 
     672        1342 :                         FdCng_decodeSID_ivas_fx( st );
     673             : 
     674        1342 :                         Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) );
     675        1342 :                         Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); // Qx
     676             :                     }
     677             : 
     678        1342 :                     *sid_bw = 0;
     679        1342 :                     move16();
     680             :                 }
     681             : 
     682       18381 :                 IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
     683             :                 {
     684        3740 :                     assert( nchan_out == 1 );
     685             : 
     686       93500 :                     FOR( i = 0; i < NPART; i++ )
     687             :                     {
     688       89760 :                         st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ),
     689       89760 :                                                                                  STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] );
     690       89760 :                         move32();
     691             :                     }
     692             : 
     693        3740 :                     ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
     694             : 
     695        3740 :                     Word16 new_sidNoiseEstExp = 31 - Q4;
     696        3740 :                     move16();
     697        3740 :                     Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp)
     698        3740 :                     Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) );   // Q(31-sidNoiseEstExp)
     699        3740 :                     st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp;
     700        3740 :                     move16();
     701        3740 :                     Word16 new_cngNoiseLevelExp = 31 - Q4;
     702        3740 :                     move16();
     703        3740 :                     Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, new_cngNoiseLevelExp ) ); // Q(31-cngNoiseLevelExp)
     704        3740 :                     st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp;
     705        3740 :                     move16();
     706             : 
     707        3740 :                     test();
     708        3740 :                     ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) );
     709             : 
     710        3740 :                     IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 )
     711             :                     {
     712        1192 :                         Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); // Q(31-cngNoiseLevelExp)
     713        1192 :                         st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0;
     714        1192 :                         move16();
     715             :                     }
     716             :                 }
     717             : 
     718       18381 :                 IF( !read_sid_info )
     719             :                 {
     720             :                     Word32 noise_lvl_highest_fx;
     721             : 
     722        3159 :                     noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) - 1];
     723        3159 :                     move32();
     724             : 
     725       65931 :                     FOR( Word16 b = ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); b < st->hFdCngDec->hFdCngCom->stopBand; b++ )
     726             :                     {
     727       62772 :                         st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx;
     728       62772 :                         move32();
     729             :                     }
     730             :                 }
     731             : 
     732       18381 :                 IF( EQ_16( st->element_mode, EVS_MONO ) )
     733             :                 {
     734           0 :                     generate_comfort_noise_dec_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 2, -1 );
     735             :                 }
     736             :                 ELSE
     737             :                 {
     738       18381 :                     generate_comfort_noise_dec_ivas_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 1, nchan_out );
     739             :                 }
     740             : 
     741       18381 :                 FdCng_exc( st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old_fx, st->first_CNG, st->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx );
     742             : 
     743       18381 :                 Copy( exc2_fx, exc3_fx, st->L_frame );
     744             :             }
     745             : 
     746       19522 :             Word16 delta_mem_scale = 3;
     747       19522 :             move16();
     748       19522 :             test();
     749       19522 :             if ( LT_32( st->lp_ener_fx, 40 ) && st->cng_type == LP_CNG ) /* very low energy frames, less than 0.3125 */
     750             :             {
     751          72 :                 delta_mem_scale = 0;
     752          72 :                 move16();
     753             :             }
     754       19522 :             i = st->Q_exc;
     755       19522 :             move16();
     756             : 
     757       19522 :             test();
     758       19522 :             IF( st->hMusicPF && st->hGSCDec )
     759             :             {
     760       12268 :                 IF( EQ_16( st->element_mode, EVS_MONO ) )
     761             :                 {
     762             :                     // VE: TBV:  should 'st_fx->L_frame * HIBND_ACB_L_FAC' be corrected in EVS?
     763           0 :                     Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame,
     764           0 :                                  st->L_frame * HIBND_ACB_L_FAC, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE );
     765             :                 }
     766             :                 ELSE
     767             :                 {
     768       12268 :                     Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame,
     769       12268 :                                  L_FRAME32k, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE );
     770             :                 }
     771             :             }
     772             : 
     773       19522 :             IF( st->hPFstat != NULL )
     774             :             {
     775       12268 :                 Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale,
     776       12268 :                              &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL );
     777             :             }
     778             :             ELSE
     779             :             {
     780        7254 :                 Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale,
     781             :                              &st->mem_deemph_fx, NULL, NULL, &st->agc_mem_fx[1], NULL, 0, 0, NULL );
     782             :             }
     783             : 
     784       19522 :             Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); // Q_exc
     785             : 
     786             :             /* update past excitation signals for LD music post-filter */
     787       19522 :             IF( st->hMusicPF != NULL )
     788             :             {
     789       12268 :                 Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 );
     790       12268 :                 Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
     791             : 
     792             :                 /* Update music post processing values */
     793             :                 /* Filter energies update */
     794       12268 :                 IF( EQ_16( st->element_mode, EVS_MONO ) )
     795             :                 {
     796           0 :                     FOR( i = 0; i < DCT_L_POST; i++ )
     797             :                     {
     798           0 :                         st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) );
     799           0 :                         move16();
     800             :                     }
     801             :                 }
     802             :                 ELSE
     803             :                 {
     804     7863788 :                     FOR( i = 0; i < DCT_L_POST; i++ )
     805             :                     {
     806     7851520 :                         st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) ); // Q15,  9830 =.3f in Q15, 22937=.7f in Q15
     807     7851520 :                         move16();
     808             :                     }
     809             :                 }
     810             :             }
     811             : 
     812             :             /* synthesis at 12.8kHz sampling rate */
     813       19522 :             move16();
     814       19522 :             syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn );
     815       19522 :             syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, st->mem_syn3_fx, 1, st->Q_exc, st->Q_syn );
     816             : 
     817             :             /* reset the decoder */
     818       19522 :             CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx );
     819             : 
     820       19522 :             IF( EQ_16( st->element_mode, EVS_MONO ) )
     821             :             {
     822             :                 /* update st_fx->mem_syn1 for ACELP core switching */
     823           0 :                 Copy( st->mem_syn3_fx, st->mem_syn1_fx, M );
     824             :             }
     825             :             ELSE
     826             :             {
     827       19522 :                 st->Q_syn_cng = st->Q_syn;
     828       19522 :                 move16();
     829       19522 :                 st->Q_exc_cng = st->Q_exc;
     830       19522 :                 move16();
     831             : 
     832             :                 /* update st->mem_syn1 for ACELP core switching */
     833       19522 :                 Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); // Q(-1)
     834             :             }
     835             : 
     836             :             /* update old synthesis for classification */
     837       19522 :             Copy( syn1_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM );
     838             : 
     839             :             /* save and delay synthesis to be used by SWB BWE */
     840       19522 :             Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); // Q_syn -> Q(-1)
     841       19522 :             IF( st->hBWE_FD != NULL )
     842             :             {
     843       12299 :                 save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
     844             :             }
     845             :         }
     846             : 
     847             :         /*----------------------------------------------------------------*
     848             :          * Decoding of all other frames
     849             :          *----------------------------------------------------------------*/
     850             : 
     851             :         ELSE
     852             :         {
     853             : 
     854             :             /*-----------------------------------------------------------------*
     855             :              * Configure ACELP bit allocation
     856             :              *-----------------------------------------------------------------*/
     857             : 
     858      142542 :             nb_bits = 0;
     859      142542 :             move16();
     860      142542 :             st->acelp_cfg.FEC_mode = 0;
     861      142542 :             move16();
     862      142542 :             uc_two_stage_flag = 0;
     863      142542 :             move16();
     864             : 
     865      142542 :             test();
     866      142542 :             IF( !st->nelp_mode_dec && !st->ppp_mode_dec )
     867             :             {
     868             :                 Word16 tc_subfr_tmp;
     869             : 
     870      142542 :                 tc_subfr_tmp = tc_subfr;
     871      142542 :                 move16();
     872      142542 :                 if ( LT_16( tc_subfr_tmp, L_SUBFR ) )
     873             :                 {
     874      135777 :                     tc_subfr_tmp = 0;
     875      135777 :                     move16();
     876             :                 }
     877             : 
     878      142542 :                 if ( EQ_16( tc_subfr, TC_0_192 ) )
     879             :                 {
     880         201 :                     nb_bits = -1;
     881         201 :                     move16();
     882             :                 }
     883             : 
     884             : #ifdef NONBE_1325_TD_STEREO_QUANT_LSF_SEC
     885      142542 :                 config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
     886             : #else
     887             :                 config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
     888             : #endif
     889             : 
     890      142542 :                 test();
     891      142542 :                 test();
     892      142542 :                 IF( EQ_16( st->coder_type, TRANSITION ) && LT_16( tc_subfr, L_SUBFR ) && EQ_16( st->L_frame, L_FRAME ) )
     893             :                 {
     894             : #ifdef NONBE_1325_TD_STEREO_QUANT_LSF_SEC
     895        3672 :                     config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
     896             : #else
     897             :                     config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
     898             : #endif
     899             :                 }
     900             :             }
     901             : 
     902             :             /*-----------------------------------------------------------------*
     903             :              * After CNG period, use the most up-to-date LSPs
     904             :              *-----------------------------------------------------------------*/
     905             : 
     906      142542 :             test();
     907      142542 :             test();
     908      142542 :             IF( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) )
     909             :             {
     910         614 :                 Copy( st->lspCNG_fx, st->lsp_old_fx, M ); /*Q15*/
     911         614 :                 lsp2lsf_fx( st->lspCNG_fx, st->lsf_old_fx, M, int_fs );
     912             :             }
     913             : 
     914             :             /*-----------------------------------------------------------------*
     915             :              * Reset higher ACELP pre-quantizer in case of switching
     916             :              *-----------------------------------------------------------------*/
     917             : 
     918      142542 :             IF( !st->use_acelp_preq )
     919             :             {
     920      131042 :                 st->mem_preemp_preQ_fx = 0;
     921      131042 :                 move16();
     922      131042 :                 st->last_nq_preQ = 0;
     923      131042 :                 move16();
     924      131042 :                 st->last_code_preq = 0;
     925      131042 :                 move16();
     926             :             }
     927             : 
     928      142542 :             st->use_acelp_preq = 0;
     929      142542 :             move16();
     930             : 
     931             :             /*-----------------------------------------------------------------*
     932             :              * LSF de-quantization and interpolation
     933             :              *-----------------------------------------------------------------*/
     934             : 
     935      142542 :             IF( !tdm_lp_reuse_flag )
     936             :             {
     937      142401 :                 lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx );
     938             :             }
     939             :             ELSE
     940             :             {
     941             :                 const Word16 *pt_interp_2_fx;
     942             : #ifndef NONBE_1325_TD_STEREO_QUANT_LSF_SEC
     943             :                 IF( NE_16( st->active_cnt, 1 ) )
     944             :                 {
     945             : #endif
     946             :                     Word16 beta_index;
     947             : 
     948         141 :                     beta_index = get_next_indice_fx( st, TDM_IC_LSF_PRED_BITS );
     949         141 :                     tdm_SCh_lsf_reuse_fx( DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index );
     950             : #ifndef NONBE_1325_TD_STEREO_QUANT_LSF_SEC
     951             :                 }
     952             :                 ELSE
     953             :                 {
     954             :                     Copy( tdm_lspQ_PCh_fx, lsp_new_fx, M );
     955             :                     Copy( tdm_lsfQ_PCh_fx, lsf_new_fx, M );
     956             :                 }
     957             : #endif
     958             : 
     959         141 :                 IF( st->rate_switching_reset )
     960             :                 {
     961             :                     /* extrapolation in case of unstable LSF convert */
     962           0 :                     Copy( lsp_new_fx, st->lsp_old_fx, M );
     963           0 :                     Copy( lsf_new_fx, st->lsf_old_fx, M );
     964             :                 }
     965             : 
     966         141 :                 pt_interp_2_fx = interpol_frac_fx;
     967         141 :                 test();
     968         141 :                 if ( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) )
     969             :                 {
     970           0 :                     pt_interp_2_fx = interpol_frac2_fx;
     971             :                 }
     972             : 
     973         141 :                 IF( EQ_16( st->active_cnt, 1 ) )
     974             :                 {
     975           0 :                     Copy( lsp_new_fx, st->lsp_old_fx, M );
     976           0 :                     lsp2lsf_fx( lsp_new_fx, st->lsf_old_fx, M, st->sr_core );
     977             :                 }
     978             : 
     979             :                 /* LSP interpolation and conversion of LSPs to A(z) */
     980         141 :                 int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new_fx, Aq_fx, M, pt_interp_2_fx, 0 );
     981             : 
     982             :                 /* Check LSF stability (distance between old LSFs and current LSFs) */
     983         141 :                 st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame );
     984         141 :                 move16();
     985             :             }
     986             : 
     987      142542 :             test();
     988      142542 :             IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO )
     989             :             {
     990             :                 /* Prepare ACB memory from last HQ frame */
     991         220 :                 old_exc_s_fx = st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame );
     992         220 :                 tmpF_fx = *old_exc_s_fx;
     993         220 :                 st->mem_deemph_fx = shl_sat( old_exc_s_fx[st->L_frame - 1], st->Q_syn ); /* Q0 -> Q_syn */
     994         220 :                 move16();
     995             : #ifdef NONBE_1131_ACELP_OOB
     996         220 :                 PREEMPH_FX( old_exc_s_fx, st->preemph_fac, st->L_frame, &tmpF_fx );
     997             : #else
     998             :                 PREEMPH_FX( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx );
     999             : #endif
    1000         220 :                 Copy( old_exc_s_fx + sub( st->L_frame, M ), st->mem_syn2_fx, M );
    1001         220 :                 Scale_sig( st->mem_syn2_fx, M, st->Q_syn ); /* Q0 -> Q_syn */
    1002         220 :                 Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, 0 );
    1003         220 :                 Scale_sig( old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, st->Q_exc ); /* Q0 -> Q_exc */
    1004             :             }
    1005             : 
    1006      142542 :             test();
    1007      142542 :             IF( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO )
    1008             :             {
    1009             :                 /* Prepare ACB memory of old_bwe_exc */
    1010        6195 :                 IF( EQ_16( st->L_frame, L_FRAME ) )
    1011             :                 {
    1012        3103 :                     lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
    1013             :                 }
    1014             :                 ELSE
    1015             :                 {
    1016        3092 :                     lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC << 1, L_EXC_MEM_DEC );
    1017             :                 }
    1018             :             }
    1019             : 
    1020             :             /*-----------------------------------------------------------------*
    1021             :              * FEC - first good frame after lost frame(s) (possibility to correct the ACB)
    1022             :              *-----------------------------------------------------------------*/
    1023             : 
    1024      142542 :             IF( st->acelp_cfg.FEC_mode > 0 )
    1025             :             {
    1026      111602 :                 last_pulse_pos = 0;
    1027      111602 :                 move16();
    1028             : 
    1029             :                 /* decode the last glottal pulse position */
    1030      111602 :                 T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits );
    1031             : 
    1032      111602 :                 test();
    1033      111602 :                 test();
    1034      111602 :                 IF( NE_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, HQ_CORE ) && st->last_con_tcx ) )
    1035             :                 {
    1036      111350 :                     test();
    1037      111350 :                     test();
    1038      111350 :                     test();
    1039      111350 :                     test();
    1040      111350 :                     test();
    1041      111350 :                     test();
    1042      111350 :                     IF( EQ_16( st->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st->prev_bfi, 1 ) )
    1043             :                     {
    1044           3 :                         FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc );
    1045             :                     }
    1046      111347 :                     ELSE IF( ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st->old_bfi_cnt, 1 ) && st->hWIDec != NULL )
    1047             :                     {
    1048           0 :                         do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx );
    1049             :                     }
    1050             :                 }
    1051             :             }
    1052             : 
    1053             :             /*------------------------------------------------------------*
    1054             :              * In case of first frame after an erasure and transition from voiced to unvoiced or inactive
    1055             :              * redo the LPC interpolation
    1056             :              *------------------------------------------------------------*/
    1057             : 
    1058      142542 :             test();
    1059      142542 :             test();
    1060      142542 :             test();
    1061      142542 :             test();
    1062      142542 :             test();
    1063      142542 :             test();
    1064      142542 :             IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) )
    1065             :             {
    1066          96 :                 int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 );
    1067             :             }
    1068             : 
    1069             :             /*---------------------------------------------------------------*
    1070             :              * Decoding of the scaled predicted innovation energy
    1071             :              *---------------------------------------------------------------*/
    1072             : 
    1073      142542 :             IF( nb_bits > 0 )
    1074             :             {
    1075      118734 :                 indice = get_next_indice_fx( st, nb_bits );
    1076      118734 :                 Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag );
    1077             :             }
    1078             : 
    1079             :             /*------------------------------------------------------------*
    1080             :              * Decode excitation according to coding type
    1081             :              *------------------------------------------------------------*/
    1082             : 
    1083      142542 :             test();
    1084      142542 :             test();
    1085      142542 :             IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */
    1086             :             {
    1087        6751 :                 IF( LE_16( st->coder_type, UNVOICED ) )
    1088             :                 {
    1089        6751 :                     tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx );
    1090        6751 :                     tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
    1091             :                 }
    1092             :                 ELSE /* GENERIC */
    1093             :                 {
    1094           0 :                     decod_gen_2sbfr_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx );
    1095             : 
    1096           0 :                     IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
    1097             :                     {
    1098           0 :                         tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
    1099             :                     }
    1100             :                 }
    1101             :             }
    1102      135791 :             ELSE IF( st->nelp_mode_dec )
    1103             :             {
    1104           0 :                 Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0
    1105           0 :                 st->Q_exc = 0;
    1106           0 :                 move16();
    1107             : 
    1108             :                 /* SC-VBR - NELP frames */
    1109           0 :                 decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx );
    1110             : 
    1111           0 :                 Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type );
    1112             :             }
    1113      135791 :             ELSE IF( EQ_16( st->coder_type, UNVOICED ) )
    1114             :             {
    1115             :                 /* UNVOICED frames */
    1116        1371 :                 decod_unvoiced_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx );
    1117             : 
    1118        1371 :                 tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
    1119             :             }
    1120      134420 :             ELSE IF( st->ppp_mode_dec )
    1121             :             {
    1122           0 :                 Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0
    1123           0 :                 st->Q_exc = 0;
    1124           0 :                 move16();
    1125             : 
    1126             :                 /* SC-VBR - PPP frames */
    1127           0 :                 IF( NE_32( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ), IVAS_ERR_OK ) )
    1128             :                 {
    1129           0 :                     return error;
    1130             :                 }
    1131             : 
    1132           0 :                 Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type );
    1133             :             }
    1134      134420 :             ELSE IF( EQ_16( st->coder_type, TRANSITION ) )
    1135             :             {
    1136       13093 :                 decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx );
    1137             :             }
    1138      121327 :             ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( ( st->coder_type == INACTIVE ) && st->inactive_coder_type_flag ) )
    1139             :             {
    1140             :                 /* AUDIO and INACTIVE frames (coded by GSC technology) */
    1141       13840 :                 decod_audio_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx,
    1142             :                                 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx );
    1143             : 
    1144       13840 :                 tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
    1145             :             }
    1146             :             ELSE
    1147             :             {
    1148             :                 /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */
    1149      107487 :                 IF( NE_32( ( error = decod_gen_voic_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) )
    1150             :                 {
    1151           0 :                     return error;
    1152             :                 }
    1153             : 
    1154      107487 :                 IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
    1155             :                 {
    1156        6689 :                     tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
    1157             :                 }
    1158             :             }
    1159             : 
    1160             :             /* synthesis for ACELP core switching and SWB BWE */
    1161      142542 :             syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 );
    1162             : 
    1163             :             /* save and delay synthesis to be used by SWB BWE */
    1164      142542 :             IF( st->hBWE_FD != NULL )
    1165             :             {
    1166      142461 :                 save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
    1167             :             }
    1168             : 
    1169             :             /*-----------------------------------------------------------------*
    1170             :              * Apply energy matching when switching to inactive frames
    1171             :              *-----------------------------------------------------------------*/
    1172             : 
    1173      142542 :             Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode );
    1174             : 
    1175             :             /*------------------------------------------------------------*
    1176             :              * Decode information and modify the excitation signal of stationary unvoiced frames
    1177             :              *------------------------------------------------------------*/
    1178             : 
    1179      142542 :             test();
    1180      142542 :             test();
    1181      142542 :             test();
    1182      142542 :             test();
    1183      142542 :             IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) )
    1184             :             {
    1185      132187 :                 Word16 temp_q_exc = st->Q_exc;
    1186      132187 :                 move16();
    1187      132187 :                 stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag );
    1188      132187 :                 IF( NE_16( temp_q_exc, st->Q_exc ) )
    1189             :                 {
    1190           0 :                     scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM + st->L_frame, sub( st->Q_exc, temp_q_exc ) );
    1191             :                 }
    1192             :             }
    1193             : 
    1194             :             /*------------------------------------------------------------*
    1195             :              * Save filter memory in case the synthesis is redone after scaling
    1196             :              * Synthesis at 12k8 Hz sampling rate
    1197             :              *------------------------------------------------------------*/
    1198             : 
    1199             :             /* update past excitation signals for LD music post-filter */
    1200      142542 :             IF( st->hMusicPF != NULL )
    1201             :             {
    1202      142542 :                 Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 );
    1203      142542 :                 Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
    1204      142542 :                 Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 );
    1205             :             }
    1206             : 
    1207      142542 :             test();
    1208      142542 :             test();
    1209      142542 :             test();
    1210      142542 :             IF( ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && EQ_16( st->L_frame, L_FRAME ) ) )
    1211        9327 :             {
    1212        9327 :                 Word16 last_coder_type = st->last_coder_type;
    1213        9327 :                 move16();
    1214             : 
    1215        9327 :                 test();
    1216        9327 :                 test();
    1217        9327 :                 test();
    1218        9327 :                 if ( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && ( st->GSC_noisy_speech == 0 ) ) )
    1219             :                 {
    1220        4053 :                     last_coder_type = AUDIO;
    1221        4053 :                     move16();
    1222             :                 }
    1223             : 
    1224        9327 :                 Word16 qdct = 0;
    1225        9327 :                 move16();
    1226             : 
    1227             :                 /* Extrapolation of the last future part, windowing and high resolution DCT transform */
    1228        9327 :                 IF( EQ_16( st->element_mode, EVS_MONO ) )
    1229             :                 {
    1230             :                     // VE: TBV: this is likely a bug in EVS - 'st->last_coder_type' should be replaced by 'st->core_brate'
    1231           0 :                     Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_coder_type, st->element_mode, pitch_buf_fx,
    1232           0 :                                          st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct );
    1233             :                 }
    1234             :                 ELSE
    1235             :                 {
    1236        9327 :                     Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct );
    1237             :                 }
    1238             : 
    1239             :                 /* LD music post-filter */
    1240        9327 :                 LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct );
    1241             : 
    1242             :                 /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */
    1243        9327 :                 IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBC whether needed in IVAS
    1244             :                 {
    1245        9327 :                     Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/
    1246             :                 }
    1247             : 
    1248        9327 :                 Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn,
    1249        9327 :                                      &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx,
    1250        9327 :                                      &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx );
    1251             :             }
    1252             :             ELSE
    1253             :             {
    1254             :                 /* Core synthesis at 12.8kHz or 16kHz */
    1255      133215 :                 i = 1;
    1256      133215 :                 move16();
    1257      133215 :                 test();
    1258      133215 :                 if ( st->coder_type == INACTIVE && st->element_mode == EVS_MONO )
    1259             :                 {
    1260           6 :                     i = 0;
    1261           6 :                     move16();
    1262             :                 }
    1263             : 
    1264             :                 /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */
    1265      133215 :                 Word16 k = 0;
    1266      133215 :                 move16();
    1267      133215 :                 test();
    1268      133215 :                 test();
    1269      133215 :                 if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) )
    1270             :                 {
    1271         711 :                     k = 1;
    1272         711 :                     move16();
    1273             :                 }
    1274             : 
    1275      133215 :                 Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx,
    1276      133215 :                              st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx );
    1277             : 
    1278      133215 :                 Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/
    1279      133215 :                 syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn );
    1280             : 
    1281      133215 :                 IF( st->hMusicPF != NULL )
    1282             :                 {
    1283    85390815 :                     FOR( i = 0; i < DCT_L_POST; i++ )
    1284             :                     {
    1285    85257600 :                         st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) );
    1286    85257600 :                         move16();
    1287             :                     }
    1288             :                 }
    1289             :             }
    1290             : 
    1291             :             /*------------------------------------------------------------*
    1292             :              * FEC - Estimate the classification information
    1293             :              *------------------------------------------------------------*/
    1294             : 
    1295      142542 :             FEC_clas_estim_fx( st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst,
    1296      142542 :                                NULL, NULL, NULL, NULL, 0, NULL, st->Q_syn, temp_buf_fx, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode );
    1297             : 
    1298             :             /*------------------------------------------------------------*
    1299             :              * FEC - Estimate pitch
    1300             :              *------------------------------------------------------------*/
    1301             : 
    1302      142542 :             FEC_pitch_estim_fx( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx,
    1303      142542 :                                 &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode );
    1304             : 
    1305             :             /*------------------------------------------------------------*
    1306             :              * FEC - Smooth the speech energy evolution when recovering after a BAD frame
    1307             :              * (smoothing is performed in the excitation domain and signal is resynthesized after)
    1308             :              *------------------------------------------------------------*/
    1309             : 
    1310      142542 :             Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0
    1311             : 
    1312      142542 :             FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction,
    1313      142542 :                               &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate,
    1314      142542 :                               exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 );
    1315             : 
    1316      142542 :             test();
    1317      142542 :             test();
    1318      142542 :             test();
    1319      142542 :             test();
    1320             :             /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */
    1321      142542 :             IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) )
    1322             :             {
    1323         113 :                 frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[( ( st->L_frame ) >> 6 ) - 1], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 );
    1324             :             }
    1325             :         }
    1326             : 
    1327             :     } /* End of GOOD FRAME */
    1328             : 
    1329             :     /*----------------------------------------------------------------*
    1330             :      * BAD frame
    1331             :      *----------------------------------------------------------------*/
    1332             : 
    1333             :     ELSE
    1334             :     {
    1335             :         /* SC-VBR */
    1336        2959 :         if ( EQ_16( st->last_nelp_mode_dec, 1 ) )
    1337             :         {
    1338           0 :             st->nelp_mode_dec = 1;
    1339           0 :             move16();
    1340             :         }
    1341             : 
    1342        2959 :         test();
    1343        2959 :         test();
    1344             :         /* long burst frame erasures */
    1345        2959 :         if ( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) )
    1346             :         {
    1347          19 :             st->last_good = VOICED_TRANSITION;
    1348          19 :             move16();
    1349             :         }
    1350             : 
    1351             :         /* LSF estimation and A(z) calculation */
    1352        2959 :         lsf_dec_bfi( MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth );
    1353             : 
    1354        2959 :         FEC_lsf2lsp_interp( st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx );
    1355        2959 :         IF( EQ_16( st->nelp_mode_dec, 1 ) )
    1356             :         {
    1357             :             /* SC-VBR */
    1358           0 :             Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0
    1359           0 :             st->Q_exc = 0;
    1360           0 :             move16();
    1361             : 
    1362           0 :             decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx );
    1363           0 :             FEC_pitch_fx = pitch_buf_fx[3];
    1364           0 :             move16();
    1365           0 :             Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type );
    1366             :         }
    1367             :         ELSE
    1368             :         {
    1369             :             /* calculation of excitation signal */
    1370        2959 :             FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx );
    1371             : 
    1372        2959 :             Rescale_exc( NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32) 0,
    1373        2959 :                          &( st->Q_exc ), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type );
    1374             : 
    1375        2959 :             tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
    1376             : 
    1377             :             /* SC-VBR */
    1378        2959 :             st->prev_gain_pit_dec_fx = st->lp_gainp_fx;
    1379        2959 :             move16();
    1380             :         }
    1381             : 
    1382             :         /* synthesis for ACELP core switching and SWB BWE */
    1383        2959 :         syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 );
    1384             : 
    1385             :         /* save and delay synthesis to be used by SWB BWE */
    1386        2959 :         IF( st->hBWE_FD != NULL )
    1387             :         {
    1388        2959 :             save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
    1389             :         }
    1390             : 
    1391             :         /* Apply energy matching when switching to inactive frames */
    1392        2959 :         Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode );
    1393             : 
    1394             :         /* update past excitation signals for LD music post-filter */
    1395        2959 :         IF( st->hMusicPF != NULL )
    1396             :         {
    1397        2959 :             Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 );
    1398        2959 :             Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
    1399             : 
    1400             :             /* Update music post processing values */
    1401             :             /* Filter energies update */
    1402     1896719 :             FOR( i = 0; i < DCT_L_POST; i++ )
    1403             :             {
    1404     1893760 :                 st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( 1228 << 16, 22938, st->hMusicPF->filt_lfE_fx[i] ) );
    1405     1893760 :                 move16();
    1406             :             }
    1407             : 
    1408             :             /* Update circular buffer, keep last energy difference unchanged */
    1409      118360 :             FOR( i = 1; i < MAX_LT; i++ )
    1410             :             {
    1411      115401 :                 st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i];
    1412      115401 :                 move16();
    1413             :             }
    1414             :         }
    1415             : 
    1416             :         /* synthesis at 12k8 Hz sampling rate */
    1417             :         /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */
    1418        2959 :         Word16 k = 0;
    1419        2959 :         move16();
    1420        2959 :         test();
    1421        2959 :         test();
    1422        2959 :         if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) )
    1423             :         {
    1424           0 :             k = 1;
    1425           0 :             move16();
    1426             :         }
    1427             : 
    1428        2959 :         Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx,
    1429        2959 :                      st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx );
    1430             : 
    1431        2959 :         test();
    1432        2959 :         IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) )
    1433             :         {
    1434           0 :             Copy( st->mem_syn2_fx, mem_tmp_fx, M );
    1435             :         }
    1436        2959 :         syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn );
    1437             : 
    1438             :         /* update buffer for classifier */
    1439        2959 :         IF( st->hWIDec != NULL )
    1440             :         {
    1441           0 :             Copy( exc2_fx + sub( st->L_frame, L_EXC_MEM ), st->hWIDec->old_exc2_fx, L_EXC_MEM );
    1442           0 :             Copy( psyn_fx + sub( st->L_frame, L_EXC_MEM ), st->hWIDec->old_syn2_fx, L_EXC_MEM );
    1443             :         }
    1444        2959 :         st->prev_Q_exc_fr = st->Q_exc;
    1445        2959 :         move16();
    1446        2959 :         st->prev_Q_syn_fr = st->Q_syn;
    1447        2959 :         move16();
    1448        2959 :         Copy( psyn_fx + sub( st->L_frame, L_SYN_MEM_CLAS_ESTIM ), st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM );
    1449             : 
    1450             :         /*------------------------------------------------------------*
    1451             :          * FEC - Smooth the speech energy evolution when recovering after a BAD frame
    1452             :          * (smoothing is performed in the excitation domain and signal is resynthesized after)
    1453             :          *------------------------------------------------------------*/
    1454             : 
    1455        2959 :         test();
    1456        2959 :         IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) )
    1457             :         {
    1458           0 :             Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0
    1459             : 
    1460           0 :             FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction,
    1461           0 :                               &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate,
    1462           0 :                               exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 );
    1463             :         }
    1464             : 
    1465             :         /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */
    1466        2959 :         frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 );
    1467             : 
    1468        2959 :         IF( NE_16( st->nelp_mode_dec, 1 ) )
    1469             :         {
    1470             :             /* modify the excitation signal of stationary unvoiced frames */
    1471        2959 :             stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx,
    1472        2959 :                                   &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx,
    1473        2959 :                                   &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge );
    1474             :         }
    1475             :     }
    1476             : 
    1477      165023 :     IF( st->hBWE_TD != NULL )
    1478             :     {
    1479      157719 :         IF( EQ_16( st->L_frame, L_FRAME ) )
    1480             :         {
    1481       81745 :             Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
    1482             :         }
    1483             :         ELSE
    1484             :         {
    1485       75974 :             Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
    1486             :         }
    1487             :     }
    1488             : 
    1489             :     /*--------------------------------------------------------*
    1490             :      * Apply NB postfilter in case of 8kHz output
    1491             :      *--------------------------------------------------------*/
    1492             : 
    1493      165023 :     test();
    1494      165023 :     IF( st->last_bwidth == NB && st->hPFstat != NULL )
    1495             :     {
    1496        2113 :         Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0
    1497             : 
    1498        2113 :         IF( st->bwidth == NB )
    1499             :         {
    1500           0 :             st->hPFstat->on = 1;
    1501           0 :             move16();
    1502           0 :             nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 );
    1503             :         }
    1504             :         ELSE
    1505             :         {
    1506        2113 :             st->hPFstat->on = 0;
    1507        2113 :             move16();
    1508        2113 :             nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 );
    1509             :         }
    1510             :     }
    1511             :     ELSE
    1512             :     {
    1513      162910 :         st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) );
    1514      162910 :         move16();
    1515             :     }
    1516             : 
    1517             :     /*------------------------------------------------------------------*
    1518             :      * Perform fixed deemphasis through 1/(1 - g*z^-1)
    1519             :      *-----------------------------------------------------------------*/
    1520             : 
    1521             :     /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
    1522      165023 :     Copy( psyn_fx + sub( st->L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM );
    1523      165023 :     deemph_fx( psyn_fx, st->preemph_fac, st->L_frame, &( st->mem_deemph_fx ) );
    1524      165023 :     unscale_AGC( psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame );
    1525      165023 :     Copy( syn_fx_tmp2, psyn_fx, st->L_frame );
    1526      165023 :     IF( st->hTcxDec != NULL )
    1527             :     {
    1528      161337 :         Copy_Scale_sig( psyn_fx + shr( st->L_frame, 1 ), st->hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, st->Q_syn ) ); /*Q-1*/
    1529      161337 :         st->hTcxDec->Q_old_syn_Overl = -1;
    1530             :     }
    1531      165023 :     Copy_Scale_sig( psyn_fx + sub( st->L_frame, M + 1 ), st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/
    1532             : 
    1533             :     /*------------------------------------------------------------------*
    1534             :      * Formant post-filter
    1535             :      *-----------------------------------------------------------------*/
    1536             : 
    1537      165023 :     test();
    1538      165023 :     test();
    1539      165023 :     test();
    1540      165023 :     test();
    1541      165023 :     IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || st->element_mode > EVS_MONO ) && LE_32( st->core_brate, ACELP_32k ) )
    1542             :     {
    1543      146687 :         st->hPFstat->on = 1;
    1544      146687 :         move16();
    1545      146687 :         Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k );
    1546      146687 :         set16_fx( st->hPFstat->mem_zero, 0, M );
    1547             : 
    1548      146687 :         formant_post_filt_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 );
    1549             :     }
    1550       18336 :     ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) )
    1551             :     {
    1552        8969 :         IF( st->hPFstat->on )
    1553             :         {
    1554         992 :             Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M );
    1555         992 :             Copy( psyn_fx, temp_buf_fx + M, L_SUBFR );
    1556             : 
    1557         992 :             Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 );
    1558         992 :             E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M );
    1559         992 :             scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR );
    1560         992 :             Copy( temp_buf_fx, psyn_fx, ( L_SUBFR >> 1 ) );
    1561         992 :             blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 );
    1562             :         }
    1563        8969 :         st->hPFstat->on = 0;
    1564        8969 :         move16();
    1565             :     }
    1566             : 
    1567             :     /*----------------------------------------------------------------*
    1568             :      * Comfort noise addition
    1569             :      *----------------------------------------------------------------*/
    1570             : 
    1571      165023 :     test();
    1572      165023 :     test();
    1573      165023 :     IF( ( st->hFdCngDec != NULL || EQ_16( st->idchan, 1 ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
    1574             :     {
    1575      157769 :         test();
    1576      157769 :         test();
    1577      157769 :         test();
    1578      157769 :         test();
    1579      157769 :         test();
    1580      157769 :         IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) )
    1581             :         {
    1582             :             /*VAD only for non inactive frame*/
    1583      138481 :             test();
    1584      138481 :             st->VAD = st->VAD && st->coder_type != INACTIVE;
    1585      138481 :             move16();
    1586      138481 :             test();
    1587      138481 :             test();
    1588      138481 :             test();
    1589      138481 :             test();
    1590      138481 :             test();
    1591      138481 :             IF( st->idchan == 0 && ( st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) )
    1592             :             {
    1593             :                 /*Noisy speech detector*/
    1594      133326 :                 noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn );
    1595             : 
    1596      133326 :                 st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ );
    1597      133326 :                 move16();
    1598      133326 :                 IF( st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 )
    1599             :                 {
    1600       19837 :                     st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ );
    1601       19837 :                     move16();
    1602             :                 }
    1603      133326 :                 move32();
    1604             :             }
    1605             : 
    1606      138481 :             if ( st->idchan == 0 )
    1607             :             {
    1608      134795 :                 st->lp_noise = st->hFdCngDec->lp_noise;
    1609      134795 :                 move32();
    1610             :             }
    1611             : 
    1612      138481 :             test();
    1613      138481 :             IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag )
    1614             :             {
    1615             :                 /* Noise estimate */
    1616      125918 :                 ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
    1617             :             }
    1618             : 
    1619      138481 :             IF( !st->cna_dirac_flag )
    1620             :             {
    1621      135710 :                 test();
    1622      135710 :                 test();
    1623      135710 :                 test();
    1624      135710 :                 test();
    1625      135710 :                 test();
    1626      135710 :                 test();
    1627      135710 :                 test();
    1628      135710 :                 test();
    1629      135710 :                 test();
    1630             :                 /* CNA: Generate additional comfort noise to mask potential coding artefacts */
    1631      135710 :                 IF( st->flag_cna && !( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) )
    1632             :                 {
    1633       73779 :                     test();
    1634       73779 :                     IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) )
    1635             :                     {
    1636         902 :                         IF( hStereoCng->flag_cna_fade )
    1637             :                         {
    1638          12 :                             generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out );
    1639          12 :                             hStereoCng->flag_cna_fade = 0;
    1640          12 :                             move16();
    1641             :                         }
    1642             :                         ELSE
    1643             :                         {
    1644         890 :                             test();
    1645         890 :                             IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) )
    1646             :                             {
    1647             :                                 /* Clear memory for secondary channel CNA */
    1648           2 :                                 set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) );
    1649             :                             }
    1650             : 
    1651         890 :                             generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out );
    1652             :                         }
    1653             :                     }
    1654       72877 :                     ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) )
    1655             :                     {
    1656       36070 :                         IF( EQ_16( st->element_mode, EVS_MONO ) )
    1657             :                         {
    1658         741 :                             generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 );
    1659             :                         }
    1660             :                         ELSE
    1661             :                         {
    1662       35329 :                             IF( st->idchan == 0 )
    1663             :                             {
    1664       35218 :                                 IF( NE_16( st->element_mode, last_element_mode ) )
    1665             :                                 {
    1666           0 :                                     set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen );
    1667             :                                 }
    1668             : 
    1669             :                                 Word32 psyn_32_fx[L_FRAME16k];
    1670       35218 :                                 Copy_Scale_sig_16_32_no_sat( psyn_fx, psyn_32_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( Q6, st->Q_syn ) );                                                                // Q6
    1671       35218 :                                 Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); // Q15
    1672             : 
    1673       35218 :                                 generate_masking_noise_ivas_fx( psyn_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out );
    1674             : 
    1675       35218 :                                 Copy_Scale_sig_32_16( psyn_32_fx, psyn_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( st->Q_syn, exp ) );                                                                // Q = st->Q_syn
    1676       35218 :                                 Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0
    1677             :                             }
    1678             :                         }
    1679             :                     }
    1680             :                 }
    1681       61931 :                 ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) )
    1682             :                 {
    1683        1256 :                     test();
    1684        1256 :                     IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) )
    1685             :                     {
    1686           0 :                         generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out );
    1687           0 :                         hStereoCng->flag_cna_fade = 1;
    1688           0 :                         move16();
    1689             :                     }
    1690             :                     ELSE
    1691             :                     {
    1692      162024 :                         FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ )
    1693             :                         {
    1694      160768 :                             psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), negate( st->Q_syn ) ) );
    1695      160768 :                             move16();
    1696             :                         }
    1697             :                     }
    1698             :                 }
    1699             :                 ELSE
    1700             :                 {
    1701       60675 :                     IF( hStereoCng != NULL )
    1702             :                     {
    1703        7672 :                         hStereoCng->flag_cna_fade = 1;
    1704        7672 :                         move16();
    1705        7672 :                         hStereoCng->enableSecCNA = 0;
    1706        7672 :                         move16();
    1707             :                     }
    1708             :                 }
    1709             : 
    1710      135710 :                 IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
    1711             :                 {
    1712        7253 :                     test();
    1713        7253 :                     test();
    1714        7253 :                     test();
    1715             :                     /*Noise estimate*/
    1716        7253 :                     IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) ) ) )
    1717             :                     {
    1718        3567 :                         ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
    1719             :                     }
    1720             :                 }
    1721             :             }
    1722             :         }
    1723             : 
    1724      157769 :         IF( !st->cna_dirac_flag )
    1725             :         {
    1726      151566 :             test();
    1727      151566 :             test();
    1728      151566 :             test();
    1729      151566 :             test();
    1730      151566 :             test();
    1731      151566 :             test();
    1732      151566 :             test();
    1733      151566 :             IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) )
    1734             :             {
    1735         100 :                 IF( EQ_16( st->element_mode, EVS_MONO ) )
    1736             :                 {
    1737             :                     // VE: TBV - is it correct in EVS? in FLP, it is:
    1738             :                     // v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, temp_buf, st->L_frame / 2 );
    1739             :                     // v_add( temp_buf, syn, syn, st->L_frame / 2 );
    1740           0 :                     FOR( i = 0; i < st->L_frame / 2; i++ )
    1741             :                     {
    1742           0 :                         psyn_fx[i] = add( psyn_fx[i], shr_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->L_frame / 4], negate( st->Q_syn ) ) );
    1743           0 :                         move16();
    1744             :                     }
    1745             :                 }
    1746             :                 ELSE
    1747             :                 {
    1748       16100 :                     FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ )
    1749             :                     {
    1750       16000 :                         psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) );
    1751       16000 :                         move16();
    1752             :                     }
    1753             :                 }
    1754             :             }
    1755             : 
    1756      151566 :             test();
    1757      151566 :             test();
    1758      151566 :             test();
    1759      151566 :             IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) )
    1760             :             {
    1761       77787 :                 IF( st->idchan == 0 )
    1762             :                 {
    1763       74669 :                     set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen );
    1764             :                 }
    1765       77787 :                 IF( hStereoCng != NULL && ( st->idchan == 0 ) )
    1766             :                 {
    1767        5045 :                     set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen );
    1768             :                 }
    1769             :             }
    1770             :         }
    1771             :     }
    1772             : 
    1773             :     /*----------------------------------------------------------------*
    1774             :      * Resample to the output sampling rate (8/16/32/48 kHz)
    1775             :      * Bass post-filter
    1776             :      *----------------------------------------------------------------*/
    1777             : 
    1778      165023 :     IF( EQ_16( st->element_mode, EVS_MONO ) )
    1779             :     {
    1780             :         CLDFB_SCALE_FACTOR scaleFactor;
    1781             :         Word32 workBuffer[128 * 3];
    1782             : 
    1783             :         /* check if the CLDFB works on the right sample rate */
    1784        1410 :         IF( ( st->cldfbAna->usb * st->cldfbAna->no_col ) != st->L_frame )
    1785             :         {
    1786             :             /* resample to ACELP internal sampling rate */
    1787           1 :             Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, FRAMES_PER_SEC ) );
    1788           1 :             resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 );
    1789           1 :             resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 );
    1790             : 
    1791           1 :             IF( st->ini_frame > 0 )
    1792             :             {
    1793           0 :                 st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels );
    1794           0 :                 move16();
    1795             :             }
    1796             :         }
    1797             : 
    1798        1410 :         test();
    1799        1410 :         IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) )
    1800             :         {
    1801           0 :             IF( EQ_16( st->L_frame, L_FRAME ) )
    1802             :             {
    1803           0 :                 retro_interp5_4_fx( st->hBPF->pst_old_syn_fx );
    1804             :             }
    1805           0 :             ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) )
    1806             :             {
    1807           0 :                 retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx );
    1808             :             }
    1809             :         }
    1810             : 
    1811        1410 :         bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off,
    1812        1410 :                           st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx );
    1813             : 
    1814             :         /* analysis of the synthesis at internal sampling rate */
    1815        1410 :         cldfbAnalysis_fx( st->cldfbAna, realBuffer_fx, imagBuffer_fx, &scaleFactor, psyn_fx, negate( st->Q_syn ), CLDFB_NO_COL_MAX, workBuffer );
    1816             : 
    1817        1410 :         scaleFactor.hb_scale = scaleFactor.lb_scale;
    1818        1410 :         move16();
    1819             : 
    1820             :         /* analysis and add the BPF error signal */
    1821        1410 :         i = 0;
    1822        1410 :         move16();
    1823        1410 :         if ( st->bpf_off == 0 )
    1824             :         {
    1825        1378 :             i = CLDFB_NO_COL_MAX;
    1826        1378 :             move16();
    1827             :         }
    1828             : 
    1829        1410 :         addBassPostFilter_fx( bpf_error_signal_16fx, realBuffer_fx, imagBuffer_fx, st->cldfbBPF, workBuffer, negate( st->Q_syn ),
    1830        1410 :                               i, st->cldfbAna->no_col, st->cldfbAna->no_channels, &scaleFactor );
    1831             : 
    1832             :         /* set output mask for upsampling */
    1833        1410 :         IF( EQ_16( st->bwidth, NB ) )
    1834             :         {
    1835             :             /* set NB mask for upsampling */
    1836           0 :             st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 );
    1837           0 :             move16();
    1838             :         }
    1839        1410 :         ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) )
    1840             :         {
    1841             :             /* in case of BW switching, re-init to default */
    1842          21 :             st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels );
    1843          21 :             move16();
    1844             :         }
    1845             : 
    1846             :         /*WB/SWB-FD_CNG*/
    1847        1410 :         scaleFactor.hb_scale = scaleFactor.lb_scale;
    1848        1410 :         move16();
    1849             : 
    1850        1410 :         test();
    1851        1410 :         test();
    1852        1410 :         test();
    1853        1410 :         IF( ( ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) )
    1854             :         {
    1855           0 :             generate_comfort_noise_dec_hf_fx( realBuffer_fx, imagBuffer_fx, &scaleFactor.hb_scale, st );
    1856             : 
    1857           0 :             st->cldfbSyn->bandsToZero = 0;
    1858           0 :             move16();
    1859           0 :             IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) )
    1860             :             {
    1861           0 :                 st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand );
    1862           0 :                 move16();
    1863             :             }
    1864           0 :             st->cldfbSyn->lsb = st->cldfbAna->no_channels;
    1865           0 :             move16();
    1866             :         }
    1867             : 
    1868             :         /* synthesis of the combined signal */
    1869        1410 :         st->Q_syn2 = st->Q_syn;
    1870        1410 :         move16();
    1871        1410 :         cldfbSynthesis_fx( st->cldfbSyn, realBuffer_fx, imagBuffer_fx, &scaleFactor, synth_fx16, negate( st->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer );
    1872             : 
    1873             :         /* Bring CLDFB output to Q0 */
    1874        1410 :         Scale_sig( synth_fx16, output_frame, negate( st->Q_syn2 ) );
    1875        1410 :         st->Q_syn2 = 0;
    1876        1410 :         move16();
    1877             : 
    1878             :         /* save synthesis - needed in case of core switching */
    1879        1410 :         Copy( synth_fx16, st->previoussynth_fx, output_frame );
    1880             :     }
    1881             :     ELSE
    1882             :     {
    1883             :         /* check if the CLDFB works on the right sample rate */
    1884      163613 :         IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) )
    1885             :         {
    1886        3333 :             resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) );
    1887        3333 :             resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) );
    1888             : 
    1889        3333 :             IF( st->ini_frame > 0 )
    1890             :             {
    1891        2064 :                 st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels );
    1892        2064 :                 move16();
    1893             :             }
    1894             :         }
    1895             : 
    1896             :         /* analyze pitch coherence for bass post-filter */
    1897             :         Word32 pitch_buf_fx_q20[12];
    1898      163613 :         Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); // Q(x+4)
    1899      163613 :         Word16 lim = shr( st->L_frame, 6 );
    1900      900593 :         FOR( Word16 lp = 0; lp < lim; lp++ )
    1901             :         {
    1902      736980 :             pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 );
    1903      736980 :             move32();
    1904             :         }
    1905      163613 :         bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 );
    1906      163613 :         Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); // Qx
    1907             : 
    1908      163613 :         test();
    1909      163613 :         IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) )
    1910             :         {
    1911      156359 :             test();
    1912      156359 :             IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) )
    1913             :             {
    1914        1766 :                 IF( EQ_16( st->L_frame, L_FRAME ) )
    1915             :                 {
    1916        1222 :                     retro_interp5_4_fx( st->hBPF->pst_old_syn_fx );
    1917             :                 }
    1918         544 :                 ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) )
    1919             :                 {
    1920         544 :                     retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx );
    1921             :                 }
    1922             :             }
    1923             : 
    1924      156359 :             bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off,
    1925      156359 :                               st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx );
    1926             :         }
    1927             : 
    1928             :         Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx;
    1929      163613 :         set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR );
    1930      163613 :         syn_32_fx = syn_tmp_32_fx + L_SUBFR;
    1931      163613 :         test();
    1932      163613 :         IF( NE_16( st->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft )
    1933      139557 :         {
    1934             :             /* analysis of the synthesis at internal sampling rate */
    1935             :             Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1936             :             Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1937             :             Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX];
    1938     2372469 :             FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    1939             :             {
    1940     2232912 :                 pRealSave_fx[i] = realBufferSave_fx[i];
    1941     2232912 :                 pImagSave_fx[i] = imagBufferSave_fx[i];
    1942             :             }
    1943      139557 :             IF( st->p_bpf_noise_buf_32 )
    1944             :             {
    1945      126558 :                 Copy_Scale_sig_16_32_DEPREC( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1
    1946      126558 :                 Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame );
    1947      126558 :                 Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11
    1948             :             }
    1949             : 
    1950    40190501 :             FOR( i = 0; i < st->L_frame; i++ )
    1951             :             {
    1952    40050944 :                 syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); // Q12
    1953    40050944 :                 move32();
    1954             :             }
    1955             : 
    1956      139557 :             Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels );
    1957      139557 :             Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12
    1958      139557 :             st->cldfbAna->Q_cldfb_state = Q12;
    1959      139557 :             move16();
    1960             : 
    1961      139557 :             cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna );
    1962             : 
    1963      139557 :             Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11
    1964      139557 :             st->cldfbAna->Q_cldfb_state = Q11;
    1965      139557 :             move16();
    1966             :             /* analysis and add the BPF error signal */
    1967             :             Word32 tmp_bpf_error_signal_fx[L_FRAME16k];
    1968             :             Word16 q_bpf_error_signal;
    1969      139557 :             Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels );
    1970             : 
    1971      139557 :             q_bpf_error_signal = Q6;
    1972      139557 :             move16();
    1973      139557 :             Copy_Scale_sig_16_32_no_sat( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6
    1974     2372469 :             FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    1975             :             {
    1976     2232912 :                 Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0
    1977     2232912 :                 Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0
    1978             :             }
    1979      139557 :             Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6)
    1980      139557 :             st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal;
    1981      139557 :             move16();
    1982      139557 :             tmp = -1;
    1983      139557 :             move16();
    1984      139557 :             if ( st->bpf_off )
    1985             :             {
    1986       25909 :                 tmp = 0;
    1987       25909 :                 move16();
    1988             :             }
    1989             : 
    1990      139557 :             addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF );
    1991             : 
    1992      139557 :             Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( ( sub( q_bpf_error_signal, Q10 ) ) ) ); // Q10
    1993      139557 :             st->cldfbBPF->Q_cldfb_state = Q10;
    1994      139557 :             move16();
    1995             :             /* set output mask for upsampling */
    1996      139557 :             IF( EQ_16( st->bwidth, NB ) )
    1997             :             {
    1998             :                 /* set NB mask for upsampling */
    1999           0 :                 st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 );
    2000           0 :                 move16();
    2001             :             }
    2002      139557 :             ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) )
    2003             :             {
    2004             :                 /* in case of BW switching, re-init to default */
    2005       15016 :                 st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels );
    2006       15016 :                 move16();
    2007             :             }
    2008      139557 :             test();
    2009      139557 :             IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
    2010             :             {
    2011      128488 :                 test();
    2012      128488 :                 test();
    2013      128488 :                 test();
    2014             :                 /*WB/SWB-FD_CNG*/
    2015      128488 :                 IF( ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) )
    2016             :                 {
    2017       15059 :                     Word16 tmpBufferScale = 0;
    2018       15059 :                     move16();
    2019       15059 :                     generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag );
    2020             : 
    2021      256003 :                     FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ )
    2022             :                     {
    2023      240944 :                         Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0
    2024      240944 :                         Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0
    2025             :                     }
    2026             : 
    2027       15059 :                     IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) )
    2028             :                     {
    2029       11403 :                         st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand );
    2030       11403 :                         move16();
    2031             :                     }
    2032             :                     ELSE
    2033             :                     {
    2034        3656 :                         st->cldfbSyn->bandsToZero = 0;
    2035        3656 :                         move16();
    2036             :                     }
    2037             :                 }
    2038             :             }
    2039             : 
    2040      139557 :             IF( save_hb_synth_fx16 != NULL )
    2041             :             {
    2042             :                 /* save and then zero-out lowband */
    2043          91 :                 max_real = 0;
    2044          91 :                 max_imag = 0;
    2045          91 :                 move32();
    2046          91 :                 move32();
    2047        1547 :                 FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    2048             :                 {
    2049       88816 :                     FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
    2050             :                     {
    2051       87360 :                         max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) );
    2052       87360 :                         max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) );
    2053             :                     }
    2054             :                 }
    2055          91 :                 max_val = L_max( max_real, max_imag );
    2056          91 :                 Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */;
    2057        1547 :                 FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    2058             :                 {
    2059        1456 :                     scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
    2060        1456 :                     scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
    2061             :                 }
    2062             : 
    2063        5551 :                 FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
    2064             :                 {
    2065       92820 :                     FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    2066             :                     {
    2067       87360 :                         realBufferSave_fx[i][j] = realBuffer_fx[i][j];
    2068       87360 :                         imagBufferSave_fx[i][j] = imagBuffer_fx[i][j];
    2069       87360 :                         move32();
    2070       87360 :                         move32();
    2071       87360 :                         IF( LT_16( j, st->hFdCngDec->hFdCngCom->numCoreBands ) && LT_16( i, st->hFdCngDec->hFdCngCom->numSlots ) )
    2072             :                         {
    2073       29120 :                             realBuffer_fx[i][j] = 0;
    2074       29120 :                             imagBuffer_fx[i][j] = 0;
    2075       29120 :                             move32();
    2076       29120 :                             move32();
    2077             :                         }
    2078             :                     }
    2079             :                 }
    2080             : 
    2081          91 :                 cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB );
    2082             : 
    2083             :                 /* restore lowband */
    2084        5551 :                 FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
    2085             :                 {
    2086       92820 :                     FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    2087             :                     {
    2088       87360 :                         realBuffer_fx[i][j] = realBufferSave_fx[i][j];
    2089       87360 :                         imagBuffer_fx[i][j] = imagBufferSave_fx[i][j];
    2090       87360 :                         move32();
    2091       87360 :                         move32();
    2092             :                     }
    2093             :                 }
    2094             : 
    2095          91 :                 cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, sub( Q11, Q_real ), -10, st->cldfbSyn );
    2096             :             }
    2097             :             ELSE
    2098             :             {
    2099             :                 /* synthesis of the combined signal */
    2100      139466 :                 max_real = 0;
    2101      139466 :                 max_imag = 0;
    2102      139466 :                 move32();
    2103      139466 :                 move32();
    2104     2370922 :                 FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    2105             :                 {
    2106   136118816 :                     FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
    2107             :                     {
    2108   133887360 :                         max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) );
    2109   133887360 :                         max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) );
    2110             :                     }
    2111             :                 }
    2112      139466 :                 max_val = L_max( max_real, max_imag );
    2113      139466 :                 Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */;
    2114     2370922 :                 FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    2115             :                 {
    2116     2231456 :                     scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
    2117     2231456 :                     scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
    2118             :                 }
    2119      139466 :                 scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1)
    2120      139466 :                 st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 );
    2121      139466 :                 move16();
    2122             : 
    2123      139466 :                 cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, 0, 0, st->cldfbSyn );
    2124      139466 :                 scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) );                                        // Q0
    2125      139466 :                 scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10
    2126      139466 :                 st->cldfbSyn->Q_cldfb_state = Q10;
    2127      139466 :                 move16();
    2128             :             }
    2129             : 
    2130             :             /* save synthesis - needed in case of core switching */
    2131      139557 :             Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0
    2132             :         }
    2133             :         ELSE
    2134             :         {
    2135       24056 :             Word16 nSamples = NS2SA_FX2( i_mult( st->L_frame, FRAMES_PER_SEC ), FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */
    2136             : 
    2137             :             /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */
    2138     7139832 :             FOR( i = 0; i < st->L_frame; i++ )
    2139             :             {
    2140     7115776 :                 syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) );
    2141     7115776 :                 move32();
    2142             :             }
    2143             : 
    2144       24056 :             Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels );
    2145       24056 :             Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12
    2146       24056 :             st->cldfbAna->Q_cldfb_state = Q12;
    2147       24056 :             move16();
    2148             : 
    2149       24056 :             cldfbAnalysis_ivas_fx( syn_32_fx + sub( st->L_frame, nSamples ), realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna );
    2150             : 
    2151       24056 :             Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11
    2152       24056 :             st->cldfbAna->Q_cldfb_state = Q11;
    2153       24056 :             move16(); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */
    2154             :             Word32 tmp_bpf_error_signal_fx[L_FRAME16k];
    2155             :             Word16 q_bpf_error_signal;
    2156             :             Word16 cldfb_state_offset;
    2157       24056 :             cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels );
    2158             : 
    2159             :             // Get Q-factor
    2160       24056 :             q_bpf_error_signal = Q6;
    2161       24056 :             move16();
    2162       24056 :             Copy_Scale_sig_16_32_no_sat( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6
    2163      408952 :             FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    2164             :             {
    2165      384896 :                 Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0
    2166      384896 :                 Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0
    2167             :             }
    2168       24056 :             Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6)
    2169       24056 :             st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal;
    2170       24056 :             move16();
    2171       24056 :             tmp = 0;
    2172       24056 :             move16();
    2173       24056 :             if ( !st->bpf_off )
    2174             :             {
    2175       22888 :                 tmp = nSamples;
    2176       22888 :                 move16();
    2177             :             }
    2178             : 
    2179       24056 :             addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF );
    2180             : 
    2181       24056 :             Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( sub( q_bpf_error_signal, Q10 ) ) ); // Q10
    2182       24056 :             st->cldfbBPF->Q_cldfb_state = Q10;
    2183       24056 :             move16();
    2184             :             /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */
    2185       24056 :             max_real = 0;
    2186       24056 :             max_imag = 0;
    2187       24056 :             move32();
    2188       24056 :             move32();
    2189      408952 :             FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    2190             :             {
    2191    23478656 :                 FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
    2192             :                 {
    2193    23093760 :                     max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) );
    2194    23093760 :                     max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) );
    2195             :                 }
    2196             :             }
    2197       24056 :             max_val = L_max( max_real, max_imag );
    2198       24056 :             Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */;
    2199      408952 :             FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
    2200             :             {
    2201      384896 :                 scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
    2202      384896 :                 scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
    2203             :             }
    2204             : 
    2205       24056 :             cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), sub( Q10, sub( Q_real, 1 ) ), -10, st->cldfbSyn );
    2206             : 
    2207       24056 :             IF( st->p_bpf_noise_buf_32 )
    2208             :             {
    2209       23251 :                 Copy_Scale_sig_16_32_DEPREC( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1
    2210       23251 :                 Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame );
    2211             : 
    2212       23251 :                 Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11
    2213             :             }
    2214             : 
    2215       24056 :             set32_fx( synth_fx, 0, output_frame );
    2216             :         }
    2217             : 
    2218             :         /* Copy output signal */
    2219      163613 :         Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0
    2220      163613 :         IF( st->element_mode > EVS_MONO )
    2221             :         {
    2222      163613 :             Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/
    2223             :         }
    2224             : 
    2225      163613 :         st->Q_syn2 = 0;
    2226      163613 :         move16();
    2227             :     }
    2228             : 
    2229             :     /*-----------------------------------------------------------------*
    2230             :      * Bandwidth extension 6kHz-7kHz
    2231             :      *-----------------------------------------------------------------*/
    2232             : 
    2233      165023 :     IF( st->hBWE_zero != NULL )
    2234             :     {
    2235      157769 :         test();
    2236      157769 :         test();
    2237      157769 :         test();
    2238      157769 :         test();
    2239      157769 :         test();
    2240      157769 :         test();
    2241      157769 :         test();
    2242      157769 :         IF( ( EQ_16( st->L_frame, L_FRAME ) && ( st->bwidth != NB ) && GE_16( output_frame, L_FRAME16k ) &&
    2243             :               ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) )
    2244             :         {
    2245       14889 :             IF( EQ_16( st->element_mode, EVS_MONO ) )
    2246             :             {
    2247           0 :                 hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 );
    2248             :             }
    2249             :             ELSE
    2250             :             {
    2251       14889 :                 Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0
    2252       14889 :                 hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 );
    2253       14889 :                 Copy_Scale_sig_16_32_DEPREC( synth_fx16, synth_fx, output_frame, 0 );
    2254             :             }
    2255             :         }
    2256             :         ELSE
    2257             :         {
    2258      142880 :             hf_synth_reset_fx( st->hBWE_zero );
    2259      142880 :             IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBV: tmp hack - it is a bug in EVS but condition is here to keep EVS bit-exact for the moment
    2260             :             {
    2261      141470 :                 set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
    2262             :             }
    2263             :         }
    2264             :     }
    2265             : 
    2266             :     /*-----------------------------------------------------------------*
    2267             :      * Populate parameters for SWB TBE
    2268             :      *-----------------------------------------------------------------*/
    2269             : 
    2270      165023 :     IF( st->hBWE_TD != NULL )
    2271             :     {
    2272      157719 :         test();
    2273      157719 :         test();
    2274      157719 :         test();
    2275      157719 :         test();
    2276      157719 :         test();
    2277      157719 :         test();
    2278      157719 :         test();
    2279      157719 :         test();
    2280      157719 :         test();
    2281      157719 :         test();
    2282      157719 :         test();
    2283      157719 :         test();
    2284      157719 :         IF( ( !st->bfi && st->prev_bfi ) || ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) )
    2285             :         {
    2286        8360 :             st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
    2287        8360 :             move32();
    2288        8360 :             set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET );
    2289        8360 :             if ( NE_16( st->element_mode, EVS_MONO ) )
    2290             :             {
    2291        8337 :                 st->hBWE_TD->q_old_bwe_exc_extended_fx = Q15;
    2292        8337 :                 move16();
    2293             :             }
    2294             :         }
    2295             : 
    2296      157719 :         test();
    2297      157719 :         test();
    2298      157719 :         test();
    2299      157719 :         test();
    2300      157719 :         test();
    2301      157719 :         IF( !st->ppp_mode_dec && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) )
    2302             :         {
    2303      157719 :             IF( EQ_16( st->element_mode, EVS_MONO ) )
    2304             :             {
    2305        1410 :                 non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame );
    2306             :             }
    2307             :             ELSE
    2308             :             {
    2309      156309 :                 Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), st->hBWE_TD->q_old_bwe_exc_extended_fx ) ) ); /* Q(q_old_bwe_exc_extended_fx) -> Q(2 * Q_exc) */
    2310      156309 :                 non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame );
    2311      156309 :                 exp = sub( L_norm_arr( bwe_exc_extended_fx + L_FRAME32k, NL_BUFF_OFFSET ), 16 );
    2312      156309 :                 Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, exp ); /* Q(2 * Q_exc) -> Q(q_old_bwe_exc_extended_fx) */
    2313      156309 :                 st->hBWE_TD->q_old_bwe_exc_extended_fx = add( shl( st->Q_exc, 1 ), exp );
    2314      156309 :                 move16();
    2315             :             }
    2316             :         }
    2317             : 
    2318      157719 :         test();
    2319      157719 :         if ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) )
    2320             :         {
    2321       12299 :             st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
    2322       12299 :             move32();
    2323             :         }
    2324             :     }
    2325             : 
    2326             :     /*----------------------------------------------------------------------*
    2327             :      * Updates
    2328             :      *----------------------------------------------------------------------*/
    2329             : 
    2330      165023 :     updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx );
    2331             : 
    2332      165023 :     test();
    2333      165023 :     test();
    2334      165023 :     IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL )
    2335             :     {
    2336             :         /* update CNG parameters in active frames */
    2337      100323 :         IF( EQ_16( st->element_mode, EVS_MONO ) )
    2338             :         {
    2339        1410 :             cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx,
    2340        1410 :                                st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate );
    2341             :         }
    2342             :         ELSE
    2343             :         {
    2344       98913 :             cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size,
    2345       98913 :                                     st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode,
    2346       98913 :                                     st->hFdCngDec->hFdCngCom->CngBandwidth );
    2347             :         }
    2348             : 
    2349             :         /* Set 16k LSP flag for CNG buffer */
    2350      100323 :         st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0;
    2351      100323 :         move16();
    2352      100323 :         if ( NE_16( st->L_frame, L_FRAME ) )
    2353             :         {
    2354       53016 :             st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1;
    2355       53016 :             move16();
    2356             :         }
    2357             :     }
    2358             : 
    2359      165023 :     IF( NE_16( st->element_mode, EVS_MONO ) )
    2360             :     {
    2361      163613 :         IF( save_hb_synth_fx16 )
    2362             :         {
    2363          91 :             Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); // Q0
    2364             :         }
    2365      163613 :         Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2
    2366             :     }
    2367             : 
    2368      165023 :     pop_wmops();
    2369      165023 :     return error;
    2370             : }

Generated by: LCOV version 1.14