LCOV - code coverage report
Current view: top level - lib_enc - ext_sig_ana_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ e95243e9e67ddeb69dddf129509de1b3d95b402e Lines: 422 646 65.3 %
Date: 2025-09-14 03:13:15 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <assert.h>
       6             : #include <stdint.h>
       7             : #include "options.h"
       8             : #include "cnst.h"
       9             : // #include "prot_fx.h"
      10             : #include "rom_com.h"
      11             : #include "basop_util.h"
      12             : #include "prot_fx.h"     /* Function prototypes                    */
      13             : #include "prot_fx_enc.h" /* Function prototypes                    */
      14             : #include <stdlib.h>
      15             : #include <math.h>
      16             : 
      17             : 
      18             : /*-------------------------------------------------------------------*
      19             :  * core_signal_analysis_high_bitrate_fx()
      20             :  *
      21             :  *
      22             :  *-------------------------------------------------------------------*/
      23             : 
      24           0 : void core_signal_analysis_high_bitrate_fx(
      25             :     const Word16 *new_samples, /*i: 0Q15*/
      26             :     const Word16 T_op[3],      /* i  : open-loop pitch values for quantiz. Q0*/
      27             :     Word16 lsp_new[],          /* Q15 */
      28             :     Word16 lsp_mid[],          /* Q15 */
      29             :     Encoder_State *st,
      30             :     Word16 pTnsSize[],              /* Q0 */
      31             :     Word16 pTnsBits[],              /* Q0 */
      32             :     Word16 param_core[],            /* Q0 */
      33             :     Word16 *ltpBits,                /* Q0 */
      34             :     const Word16 L_frame,           /* Q0 */
      35             :     const Word16 L_frameTCX,        /* Q0 */
      36             :     const Word16 last_element_mode, /* Q0 */
      37             :     const Word16 vad_hover_flag,    /* i  : VAD hangover flag                          Q0*/
      38             :     Word32 **spectrum,              /* spectrum_e */
      39             :     Word16 *spectrum_e,
      40             :     Word16 *Q_new )
      41             : {
      42           0 :     const Word16 last_overlap = st->hTcxCfg->tcx_last_overlap_mode;
      43           0 :     const Word16 curr_overlap = st->hTcxCfg->tcx_curr_overlap_mode;
      44             :     Word16 i, frameno;
      45             :     Word16 L_subframe;
      46             :     Word16 left_overlap, right_overlap, folding_offset;
      47             :     Word32 buf[N_MAX]; /* Buffer for TCX20/TCX10 windowing, power spectrum */
      48             :     Word16 A[M + 1];
      49             :     Word16 mdstWin[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for MDST windowing */
      50             :     Word16 *pMdstWin;
      51             :     Word16 lpc_left_overlap_mode, lpc_right_overlap_mode;
      52           0 :     Word16 *tcx20Win = (Word16 *) buf;
      53             :     Word32 powerSpec[N_MAX];
      54             :     Word16 powerSpec_e;
      55             :     Word32 interleaveBuf[N_TCX10_MAX];
      56           0 :     Word16 *tcx5Win = (Word16 *) interleaveBuf; /* Buffer for TCX5 windowing and interleaving. */
      57             :     Word16 r_h[NB_DIV][M + 1], r_l[NB_DIV][M + 1];
      58             :     Word32 r[M + 1], epsP[M + 1];
      59             :     Word16 *lsp[2];
      60             :     Word8 tmp8;
      61           0 :     Word16 alw_pitch_lag_12k8[2], alw_pitch_lag_12k8_wc = -1;
      62           0 :     Word16 alw_voicing[2], alw_voicing_wc = -1;
      63             :     Word16 nSubframes;
      64             :     Word16 overlap_mode[3];
      65             :     Word16 transform_type[2];
      66             :     Word16 tcx10SizeFB;
      67             :     Word16 tcx5SizeFB;
      68             :     Word16 tcx10Size;
      69             :     Word16 tmp, *tmpP16;
      70             :     Word32 *tmpP32;
      71             :     Word16 Q_exp;
      72             : 
      73           0 :     TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
      74             : 
      75             :     /* dummy */
      76             :     (void) vad_hover_flag;
      77             :     (void) last_element_mode;
      78             : 
      79           0 :     left_overlap = -1;
      80           0 :     move16();
      81           0 :     right_overlap = -1;
      82           0 :     move16();
      83             : 
      84           0 :     tcx10SizeFB = shl( st->hTcxCfg->tcx5SizeFB, 1 ); /* Q0 */
      85           0 :     tcx5SizeFB = st->hTcxCfg->tcx5SizeFB;            /* Q0 */
      86           0 :     move16();
      87           0 :     tcx10Size = shl( st->hTcxCfg->tcx5Size, 1 ); /* Q0 */
      88             : 
      89             :     /*--------------------------------------------------------------*
      90             :      * Input Signal Processing: copy, HP filter, pre-emphasis
      91             :      *---------------------------------------------------------------*/
      92             : 
      93             :     /* Copy Samples */
      94           0 :     IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
      95             :     {
      96           0 :         Copy( new_samples, st->new_speech_enc, L_frame ); /* Q0 */
      97           0 :         Scale_sig( st->new_speech_enc, L_frame, 1 );      /* Q1 */
      98             :     }
      99             : 
     100             :     /*--------------------------------------------------------------*
     101             :      * TCX-LTP
     102             :      *---------------------------------------------------------------*/
     103             : 
     104           0 :     tmp8 = 0;
     105           0 :     move16();
     106           0 :     if ( GT_32( st->sr_core, 25600 ) )
     107             :     {
     108           0 :         tmp8 = 1;
     109           0 :         move16();
     110             :     }
     111           0 :     IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
     112             :     {
     113             :         // PMT("tcx_ltp_encode_fx should be verified for IVAS")
     114           0 :         tcx_ltp_encode_fx( hTcxEnc->tcxltp, (Word8) st->tcxonly, hTcxEnc->tcxMode,
     115           0 :                            L_frame, L_SUBFR, st->speech_enc + st->encoderLookahead_enc,
     116           0 :                            hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->speech_enc + st->encoderLookahead_enc,
     117           0 :                            T_op[1], &param_core[1 + NOISE_FILL_RANGES], ltpBits,
     118             :                            &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain,
     119             :                            &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past,
     120           0 :                            &hTcxEnc->tcxltp_norm_corr_past, st->last_core, st->pit_min, st->pit_fr1,
     121           0 :                            st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection,
     122             :                            tmp8, NULL, M );
     123             :     }
     124             :     ELSE
     125             :     {
     126           0 :         tcx_ltp_encode_fx( hTcxEnc->tcxltp, (Word8) st->tcxonly, hTcxEnc->tcxMode,
     127           0 :                            L_frame, L_SUBFR, st->speech_enc + st->encoderLookahead_enc,
     128           0 :                            hTcxEnc->speech_ltp + st->encoderLookahead_enc, st->speech_enc + st->encoderLookahead_enc,
     129           0 :                            T_op[1], &param_core[1 + NOISE_FILL_RANGES], ltpBits,
     130             :                            &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain,
     131             :                            &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past,
     132           0 :                            &hTcxEnc->tcxltp_norm_corr_past, st->last_core, st->pit_min, st->pit_fr1,
     133           0 :                            st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection,
     134             :                            tmp8, NULL, M );
     135             :     }
     136             : 
     137           0 :     test();
     138           0 :     IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     139             :     {
     140           0 :         Copy( st->speech_enc + st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame );
     141             : 
     142           0 :         Preemph_scaled( st->new_speech_enc_pe, Q_new, &( st->mem_preemph_enc ),
     143           0 :                         st->Q_max_enc, st->preemph_fac, 1, 0, 2, L_frame, st->coder_type_raw, 1 );
     144             :     }
     145           0 :     Q_exp = sub( *Q_new, st->prev_Q_new );
     146           0 :     move16();
     147             : 
     148             :     /* Rescale Memory */
     149           0 :     Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( *Q_new, st->Q_old ) ); /* Q_new */
     150           0 :     IF( Q_exp != 0 )
     151             :     {
     152           0 :         Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, Q_exp ); /* Q15 - exp_buf_speech_enc_pe + Q_exp */
     153           0 :         Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp );
     154             :     }
     155             : 
     156           0 :     IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) )
     157             :     {
     158           0 :         Copy( &param_core[1 + NOISE_FILL_RANGES], &param_core[NPRM_DIV + 1 + NOISE_FILL_RANGES], LTPSIZE ); /* Q0 */
     159             :     }
     160             : 
     161             : 
     162             :     /*-------------------------------------------------------------------------*
     163             :      * Decision matrix for the transform and overlap length
     164             :      *--------------------------------------------------------------------------*/
     165           0 :     IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     166             :     {
     167           0 :         lsp[0] = lsp_new;
     168           0 :         lsp[1] = lsp_mid;
     169           0 :         alw_pitch_lag_12k8[0] = st->pitch[0]; /* Q0 */
     170           0 :         move16();
     171           0 :         alw_pitch_lag_12k8[1] = st->pitch[1]; /* Q0 */
     172           0 :         move16();
     173           0 :         alw_voicing[0] = st->voicing_fx[0]; /* Q15 */
     174           0 :         move16();
     175           0 :         alw_voicing[1] = st->voicing_fx[1]; /* Q15 */
     176           0 :         move16();
     177             : 
     178           0 :         alw_pitch_lag_12k8_wc = s_min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); /* Q0 */
     179           0 :         alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] );                      /* Q15 */
     180             :     }
     181           0 :     overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame   Q0*/
     182           0 :     move16();
     183             : 
     184           0 :     IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) )
     185             :     {
     186           0 :         nSubframes = 1;
     187           0 :         move16();
     188           0 :         transform_type[0] = TCX_20;
     189           0 :         transform_type[1] = TCX_20;
     190           0 :         move16();
     191           0 :         overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame       Q0*/
     192           0 :         move16();
     193             : 
     194           0 :         IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     195             :         {
     196           0 :             alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; /* Q0 */
     197           0 :             move16();
     198           0 :             alw_voicing[0] = alw_voicing_wc; /* Q15 */
     199           0 :             move16();
     200             :         }
     201             :     }
     202             :     ELSE
     203             :     {
     204           0 :         nSubframes = 2;
     205           0 :         move16();
     206           0 :         IF( EQ_16( curr_overlap, FULL_OVERLAP ) )
     207             :         {
     208           0 :             transform_type[0] = TCX_5;
     209           0 :             move16();
     210           0 :             transform_type[1] = TCX_10;
     211           0 :             move16();
     212             : 
     213           0 :             overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */
     214           0 :             move16();
     215           0 :             if ( EQ_16( last_overlap, HALF_OVERLAP ) )
     216             :             {
     217           0 :                 overlap_mode[1] = HALF_OVERLAP;
     218           0 :                 move16();
     219             :             }
     220             :         }
     221           0 :         ELSE IF( EQ_16( last_overlap, FULL_OVERLAP ) )
     222             :         {
     223           0 :             transform_type[0] = TCX_10;
     224           0 :             move16();
     225           0 :             transform_type[1] = TCX_5;
     226           0 :             move16();
     227             : 
     228           0 :             overlap_mode[1] = MIN_OVERLAP; /* Overlap between 1st and 2nd sub-frame */
     229           0 :             move16();
     230           0 :             if ( EQ_16( curr_overlap, HALF_OVERLAP ) )
     231             :             {
     232           0 :                 overlap_mode[1] = HALF_OVERLAP;
     233           0 :                 move16();
     234             :             }
     235             :         }
     236             :         ELSE
     237             :         {
     238           0 :             transform_type[0] = transform_type[1] = TCX_5;
     239           0 :             move16();
     240           0 :             move16();
     241             : 
     242           0 :             overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */
     243           0 :             move16();
     244           0 :             test();
     245           0 :             if ( EQ_16( last_overlap, HALF_OVERLAP ) && EQ_16( curr_overlap, HALF_OVERLAP ) )
     246             :             {
     247           0 :                 overlap_mode[1] = HALF_OVERLAP;
     248           0 :                 move16();
     249             :             }
     250             :         }
     251           0 :         overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame       Q0*/
     252           0 :         move16();
     253             :     }
     254           0 :     IF( NE_16( transform_type[0], TCX_20 ) )
     255             :     {
     256           0 :         IGFEncResetTCX10BitCounter_fx( st->hIGFEnc );
     257             :     }
     258             :     /*-------------------------------------------------------------------------*
     259             :      * Get MDCT output and TNS parameters. Apply TNS in the spectrum if needed
     260             :      *--------------------------------------------------------------------------*/
     261             : 
     262           0 :     FOR( frameno = 0; frameno < nSubframes; frameno++ )
     263             :     {
     264           0 :         L_subframe = L_frameTCX; /* Q0 */
     265           0 :         move16();
     266           0 :         if ( NE_16( nSubframes, 1 ) )
     267           0 :             L_subframe = shr( L_frameTCX, 1 );
     268             : 
     269           0 :         lpc_left_overlap_mode = overlap_mode[frameno]; /* Q0 */
     270           0 :         move16();
     271           0 :         lpc_right_overlap_mode = overlap_mode[frameno + 1]; /* Q0 */
     272           0 :         move16();
     273           0 :         if ( EQ_16( lpc_left_overlap_mode, ALDO_WINDOW ) )
     274             :         {
     275           0 :             lpc_left_overlap_mode = FULL_OVERLAP;
     276           0 :             move16();
     277             :         }
     278           0 :         if ( EQ_16( lpc_right_overlap_mode, ALDO_WINDOW ) )
     279             :         {
     280           0 :             lpc_right_overlap_mode = FULL_OVERLAP;
     281           0 :             move16();
     282             :         }
     283             : 
     284           0 :         test();
     285           0 :         IF( ( NE_16( transform_type[frameno], TCX_20 ) ) || ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) )
     286             :         {
     287             :             /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */
     288           0 :             WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno],
     289           0 :                           overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB],
     290           0 :                           &L_subframe, tcx20Win, st->element_mode != IVAS_CPE_MDCT /* truncate_aldo */, 1 );
     291             :         }
     292             : 
     293           0 :         IF( EQ_16( transform_type[frameno], TCX_5 ) )
     294             :         {
     295           0 :             folding_offset = shr( left_overlap, 1 );
     296             : 
     297             :             /* Outter left folding */
     298           0 :             FOR( i = 0; i < folding_offset; i++ )
     299             :             {
     300           0 :                 tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); // Q0
     301           0 :                 move16();
     302             :             }
     303             :             /* Outter right folding */
     304           0 :             tmp = shr( right_overlap, 1 );
     305           0 :             FOR( i = 0; i < tmp; i++ )
     306             :             {
     307           0 :                 tcx20Win[L_subframe + folding_offset - 1 - i] = add_sat( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); // Q0
     308           0 :                 move16();
     309             :             }
     310             :             /* 2xTCX5 */
     311           0 :             L_subframe = tcx5SizeFB; /* Q0 */
     312           0 :             move16();
     313             : 
     314           0 :             tmpP16 = tcx20Win;
     315           0 :             tmpP32 = spectrum[frameno]; /* exp(spectrum) */
     316           0 :             assert( st->mct_chan_mode != MCT_CHAN_MODE_LFE );
     317           0 :             FOR( i = 0; i < 2; i++ )
     318             :             {
     319           0 :                 test();
     320           0 :                 test();
     321           0 :                 WindowSignal( st->hTcxCfg,
     322             :                               folding_offset,
     323           0 :                               mac_r( -( 1 << 16 ), 3 << 8, shl( i, 7 ) ), /* equivalent to: i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */
     324           0 :                               mac_r( 2 << 16, -( 3 << 8 ), shl( i, 7 ) ), /* equivalent to: sub(i, 1) == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */
     325           0 :                               &left_overlap, &right_overlap, tmpP16, &L_subframe, tcx5Win, st->element_mode != IVAS_CPE_MDCT, 1 );
     326             : 
     327           0 :                 spectrum_e[frameno] = 16;
     328           0 :                 move16();
     329           0 :                 TCX_MDCT( tcx5Win,
     330             :                           tmpP32,
     331           0 :                           &spectrum_e[frameno],
     332             :                           left_overlap,
     333           0 :                           sub( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ),
     334           0 :                           right_overlap, st->element_mode );
     335             : 
     336           0 :                 tmpP16 += tcx5SizeFB;
     337           0 :                 tmpP32 += tcx5SizeFB;
     338             :             }
     339             :         }
     340             :         ELSE /* transform_type[frameno] != TCX_5 */
     341             :         {
     342           0 :             assert( transform_type[frameno] == TCX_10 || transform_type[frameno] == TCX_20 );
     343             : 
     344             :             /* TCX20/TCX10 */
     345           0 :             spectrum_e[frameno] = 16;
     346           0 :             move16();
     347           0 :             test();
     348           0 :             test();
     349           0 :             IF( ( EQ_16( transform_type[frameno], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) && NE_16( st->mct_chan_mode, MCT_CHAN_MODE_LFE ) )
     350           0 :             {
     351             :                 Word32 tmp_buf[L_FRAME_PLUS];
     352             :                 Word16 Q, tmp1, tmp2;
     353             : 
     354           0 :                 Q = 0;
     355           0 :                 move16();
     356             : 
     357           0 :                 wtda_fx( hTcxEnc->new_speech_TCX, &Q, tmp_buf, NULL, NULL, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX );
     358             : 
     359           0 :                 WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, lpc_left_overlap_mode, lpc_right_overlap_mode, &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, st->element_mode != IVAS_CPE_MDCT, 1 );
     360             : 
     361             :                 /* scale by NORM_MDCT_FACTOR / L */
     362           0 :                 tmp1 = mult_r( shl( L_subframe, 4 ), 26214 /*128.f / NORM_MDCT_FACTOR Q15*/ ); /* 4Q11 */
     363           0 :                 tmp2 = 4;
     364           0 :                 move16();
     365           0 :                 tmp1 = ISqrt16( tmp1, &tmp2 );
     366             : 
     367           0 :                 FOR( i = 0; i < L_subframe; i++ )
     368             :                 {
     369           0 :                     tmp_buf[i] = Mpy_32_16_1( tmp_buf[i], tmp1 ); /* Q - 4 */
     370           0 :                     move32();
     371             :                 }
     372           0 :                 Q = sub( Q, tmp2 );
     373             : 
     374             :                 /* DCT */
     375           0 :                 edct_fx( tmp_buf, spectrum[frameno], L_subframe, &Q );
     376           0 :                 *spectrum_e = sub( 31, Q );
     377             :             }
     378             :             ELSE
     379             :             {
     380           0 :                 TCX_MDCT( tcx20Win, spectrum[frameno], &spectrum_e[frameno], left_overlap, sub( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode );
     381             :             }
     382             : 
     383             :             /* For TCX20 at bitrates up to 64 kbps we need the power spectrum */
     384             : 
     385             :             /* high-band gain control in case of BWS */
     386           0 :             IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     387             :             {
     388           0 :                 test();
     389           0 :                 test();
     390           0 :                 IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) && ( ( LT_32( st->total_brate, HQ_96k ) ) || st->igf ) )
     391             :                 {
     392             : 
     393           0 :                     pMdstWin = tcx20Win;
     394           0 :                     test();
     395           0 :                     if ( ( ( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) )
     396             :                     {
     397           0 :                         pMdstWin = mdstWin;
     398             :                     }
     399             : 
     400             :                     /* Compute noise-measure flags for spectrum filling and quantization */
     401           0 :                     AnalyzePowerSpectrum_fx( st, div_l( L_mult( L_subframe, st->L_frame ), hTcxEnc->L_frameTCX ),
     402           0 :                                              L_subframe, left_overlap, right_overlap, spectrum[frameno], spectrum_e[frameno],
     403             :                                              pMdstWin, powerSpec, &powerSpec_e );
     404             :                 }
     405             :             }
     406             :         }
     407             : 
     408           0 :         IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     409             :         {
     410           0 :             test();
     411           0 :             test();
     412           0 :             TNSAnalysis_fx( st->hTcxCfg, L_frameTCX,
     413           0 :                             st->hTcxCfg->tcx_coded_lines,
     414           0 :                             transform_type[frameno], ( frameno == 0 ) && ( st->last_core == ACELP_CORE ),
     415           0 :                             spectrum[frameno], &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL );
     416             :             {
     417           0 :                 EncodeTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno],
     418           0 :                                   param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno );
     419             :             }
     420           0 :             IF( EQ_16( transform_type[frameno], TCX_5 ) )
     421             :             {
     422             :                 /* group sub-windows: interleave bins according to their frequencies */
     423           0 :                 FOR( i = 0; i < tcx5SizeFB; i++ )
     424             :                 {
     425           0 :                     interleaveBuf[2 * i] = spectrum[frameno][i]; /* exp(spectrum_e) */
     426           0 :                     move32();
     427           0 :                     interleaveBuf[2 * i + 1] = spectrum[frameno][tcx5SizeFB + i]; /* exp(spectrum_e) */
     428           0 :                     move32();
     429             :                 }
     430           0 :                 MVR2R_WORD32( interleaveBuf, spectrum[frameno], tcx10SizeFB );
     431             :             }
     432             : 
     433             :             /*--------------------------------------------------------------*
     434             :              * LPC analysis
     435             :              *---------------------------------------------------------------*/
     436             : 
     437             :             {
     438           0 :                 HBAutocorrelation_fx( st->hTcxCfg, lpc_left_overlap_mode, lpc_right_overlap_mode, &st->speech_enc_pe[frameno * tcx10Size],
     439           0 :                                       shr( L_frame, sub( nSubframes, 1 ) ), r, M );
     440             : 
     441           0 :                 FOR( i = 0; i <= M; i++ )
     442             :                 {
     443           0 :                     move16();
     444           0 :                     move16();
     445           0 :                     r_l[frameno][i] = L_Extract_lc( r[i], &r_h[frameno][i] );
     446             :                 }
     447             : 
     448           0 :                 adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core );
     449             : 
     450           0 :                 E_LPC_lev_dur( r_h[frameno], r_l[frameno], A, epsP, M, NULL );
     451             : 
     452           0 :                 E_LPC_a_lsp_conversion( A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M );
     453             :             }
     454           0 :             IF( st->igf )
     455             :             {
     456           0 :                 ProcessIGF_fx( st->hIGFEnc, st, spectrum[frameno], &( spectrum_e[frameno] ), powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, hTcxEnc->fUseTns[frameno], ( st->last_core == ACELP_CORE ), frameno );
     457             :             }
     458             : 
     459             :             /* Copy memory */
     460           0 :             MVR2R_WORD16( lsp_new, st->lspold_enc_fx, M ); /* Q15 */
     461             :         }
     462             :     }
     463             : 
     464           0 :     return;
     465             : }
     466             : 
     467             : /*-------------------------------------------------------------------*
     468             :  * core_signal_analysis_high_bitrate_ivas_fx()
     469             :  *
     470             :  *
     471             :  *-------------------------------------------------------------------*/
     472             : 
     473      885784 : void core_signal_analysis_high_bitrate_ivas_fx(
     474             :     const Word16 *new_samples, /*i: Q0 */
     475             :     const Word16 T_op[3],      /* i  : open-loop pitch values for quantiz. Q0*/
     476             :     Word16 lsp_new[],          /* Q15 */
     477             :     Word16 lsp_mid[],          /* Q15 */
     478             :     Encoder_State *st,
     479             :     Word16 pTnsSize[],              /* Q0 */
     480             :     Word16 pTnsBits[],              /* Q0 */
     481             :     Word16 param_core[],            /* Q0 */
     482             :     Word16 *ltpBits,                /* Q0 */
     483             :     Word32 *windowed_samples,       /* q_win */
     484             :     const Word16 L_frame,           /* Q0 */
     485             :     const Word16 L_frameTCX,        /* Q0 */
     486             :     const Word16 last_element_mode, /* Q0 */
     487             :     const Word16 vad_hover_flag,    /* i  : VAD hangover flag                          Q0*/
     488             :     Word32 **spectrum,              /* exp(spectrum_e) */
     489             :     Word16 *spectrum_e,
     490             :     Word16 *Q_new,
     491             :     Word16 *q_win )
     492             : {
     493      885784 :     TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
     494      885784 :     const Word16 last_overlap = st->hTcxCfg->tcx_last_overlap_mode;
     495      885784 :     const Word16 curr_overlap = st->hTcxCfg->tcx_curr_overlap_mode;
     496      885784 :     const Word16 minWindowLen = sub( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 );
     497             :     Word16 i, frameno;
     498             :     Word16 L_subframe;
     499      885784 :     Word16 left_overlap = -1, right_overlap = -1, folding_offset;
     500             :     Word32 buf[N_MAX + L_MDCT_OVLP_MAX];               /* Buffer for TCX20/TCX10 windowing */
     501             :     Word32 buf_powerSPec[N_MAX + L_MDCT_OVLP_MAX];     /* Buffer for TCX20/TCX10 windowing */
     502             :     Word16 buf_powerSPec_exp[N_MAX + L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */
     503             :     Word16 mdstWin[N_MAX + L_MDCT_OVLP_MAX];           /* Buffer for MDST windowing */
     504             :     Word16 *pMdstWin;
     505             :     Word16 lpc_left_overlap_mode, lpc_right_overlap_mode;
     506      885784 :     Word32 *powerSpec = buf_powerSPec;
     507      885784 :     Word16 *powerSpec_e = buf_powerSPec_exp;
     508      885784 :     Word16 *tcx20Win = (Word16 *) buf;
     509      885784 :     Word32 *tcx20Win_32 = buf;
     510             :     Word32 interleaveBuf[N_TCX10_MAX];
     511      885784 :     Word16 *tcx5Win = (Word16 *) interleaveBuf; /* Buffer for TCX5 windowing and interleaving. */
     512             :     Word16 nSubframes;
     513             :     Word16 overlap_mode[3];
     514      885784 :     Word16 *transform_type = hTcxEnc->transform_type;
     515             :     Word32 r[M + 1];
     516             :     Word16 A[M + 1];
     517             :     Word16 r_h[NB_DIV][M + 1], r_l[NB_DIV][M + 1];
     518             :     Word16 *lsp[2];
     519      885784 :     const Word16 tcx10SizeFB = shl( st->hTcxCfg->tcx5SizeFB, 1 );
     520      885784 :     const Word16 tcx5SizeFB = st->hTcxCfg->tcx5SizeFB;
     521      885784 :     const Word16 tcx10Size = shl( st->hTcxCfg->tcx5Size, 1 );
     522      885784 :     Word16 alw_pitch_lag_12k8[2], alw_pitch_lag_12k8_wc = -1;
     523      885784 :     Word16 alw_voicing[2], alw_voicing_wc = -1;
     524      885784 :     Word16 disable_ltp = 0;
     525             :     Word16 tmp, *tmpP16;
     526      885784 :     Word16 q_mdstWin = st->q_inp, q_tcx20Win = st->q_inp;
     527             :     Word32 *tmpP32;
     528             :     Word16 Q_exp;
     529             :     Word32 L_tmpbuf[N_MAX + L_MDCT_OVLP_MAX];
     530      885784 :     move16();
     531      885784 :     move16();
     532      885784 :     move16();
     533      885784 :     move16();
     534      885784 :     move16();
     535      885784 :     move16();
     536      885784 :     move16();
     537      885784 :     move16();
     538             :     (void) vad_hover_flag;
     539             :     Word16 Q_win_temp[2];
     540      885784 :     Word16 *speech_ltp_fx = NULL;
     541      885784 :     Word16 *wspeech_fx = NULL;
     542      885784 :     Word16 *speech_fx = NULL;
     543      885784 :     Word16 q_out_wtda = st->q_inp;
     544      885784 :     move16();
     545             :     Word16 win_len[2];
     546      885784 :     move16();
     547             :     Word16 shift;
     548      885784 :     set32_fx( buf_powerSPec, 0, N_MAX + L_MDCT_OVLP_MAX );
     549      885784 :     set16_fx( buf_powerSPec_exp, 0, N_MAX + L_MDCT_OVLP_MAX );
     550             : 
     551      885784 :     if ( NE_16( last_element_mode, st->element_mode ) )
     552             :     {
     553        1754 :         disable_ltp = 1; /* disable TCX-LTP in stereo switching to avoid discontinuities in synthesis */
     554        1754 :         move16();
     555             :     }
     556             : 
     557             :     /*--------------------------------------------------------------*
     558             :      * Input Signal Processing: copy, HP filter, pre-emphasis
     559             :      *---------------------------------------------------------------*/
     560             : 
     561             :     /* Copy Samples */
     562      885784 :     test();
     563      885784 :     IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     564             :     {
     565      106889 :         Copy_Scale_sig( new_samples, st->new_speech_enc, L_frame, sub( 15, st->exp_buf_speech_enc ) );
     566             :         /* st->new_speech_enc copied from new_samples in Q  st->exp_buf_speech_enc
     567             :         This is considering new_samples is in q 0 in current code*/
     568             :     }
     569             : 
     570             :     /*--------------------------------------------------------------*
     571             :      * TCX-LTP
     572             :      *---------------------------------------------------------------*/
     573             : 
     574      885784 :     if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
     575             :     {
     576       14304 :         if ( st->element_mode > EVS_MONO )
     577             :         {
     578       14304 :             wspeech_fx = st->buf_wspeech_enc + st->L_frame + L_SUBFR;
     579             :         }
     580             :         else
     581             :         {
     582           0 :             wspeech_fx = st->buf_wspeech_enc + st->L_frame + idiv1616( st->L_frame, st->nb_subfr );
     583             :         }
     584             :     }
     585      871480 :     else if ( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     586             :     {
     587      222127 :         speech_fx = st->buf_speech_enc + st->encoderPastSamples_enc;
     588      222127 :         speech_ltp_fx = st->hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc;
     589             :     }
     590             : 
     591      885784 :     IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
     592             :     {
     593       14304 :         tcx_ltp_encode_ivas_fx( st, hTcxEnc->tcxMode, L_frame, wspeech_fx, NULL, wspeech_fx, T_op, &param_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode );
     594             :     }
     595      871480 :     ELSE IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     596             :     {
     597      222127 :         tcx_ltp_encode_ivas_fx( st, hTcxEnc->tcxMode, L_frame, speech_fx + st->encoderLookahead_enc, speech_ltp_fx + st->encoderLookahead_enc, speech_fx + st->encoderLookahead_enc, T_op, &param_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode );
     598             :     }
     599             : 
     600      885784 :     test();
     601      885784 :     IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     602             :     {
     603      106889 :         Copy( st->speech_enc + st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame ); // Assuming both exp_buf_speech_enc_pe and exp_buf_speech_enc are same
     604             : 
     605      106889 :         PREEMPH_FX( st->new_speech_enc_pe, st->preemph_fac, L_frame, &( st->mem_preemph_enc ) ); // using this to keep values alligned in Q-1
     606             :     }
     607             : 
     608             :     /* Rescale Memory */
     609      885784 :     Q_exp = sub( *Q_new, st->prev_Q_new );
     610      885784 :     move16();
     611             : 
     612      885784 :     Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( *Q_new, sub( Q15, st->exp_old_inp_16k ) ) ); // *Q_new
     613      885784 :     st->exp_old_inp_16k = sub( Q15, *Q_new );
     614      885784 :     move16();
     615      885784 :     IF( Q_exp != 0 )
     616             :     {
     617         498 :         Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, sub( Q_exp, sub( Q15, st->exp_buf_speech_enc_pe ) ) ); // *Q_new
     618         498 :         st->exp_buf_speech_enc_pe = sub( Q15, Q_exp );
     619         498 :         move16();
     620         498 :         Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp ); // *Q_new
     621             :     }
     622             : 
     623      885784 :     IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) )
     624             :     {
     625       16847 :         Copy( &param_core[1 + NOISE_FILL_RANGES], &param_core[NPRM_DIV + 1 + NOISE_FILL_RANGES], LTPSIZE ); // Q0
     626             :     }
     627             : 
     628      885784 :     IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     629             :     {
     630      236431 :         lsp[0] = lsp_new; // Q15
     631      236431 :         move16();
     632      236431 :         lsp[1] = lsp_mid; // Q15
     633      236431 :         move16();
     634             :     }
     635             : 
     636             :     /*-------------------------------------------------------------------------*
     637             :      * Decision matrix for the transform and overlap length
     638             :      *--------------------------------------------------------------------------*/
     639             : 
     640      885784 :     IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     641             :     {
     642      236431 :         alw_pitch_lag_12k8[0] = st->pitch[0]; // Q0
     643      236431 :         move16();
     644      236431 :         alw_pitch_lag_12k8[1] = st->pitch[1]; // Q0
     645      236431 :         move16();
     646      236431 :         alw_voicing[0] = st->voicing_fx[0]; // Q15
     647      236431 :         move16();
     648      236431 :         alw_voicing[1] = st->voicing_fx[1]; // Q15
     649      236431 :         move16();
     650      236431 :         alw_pitch_lag_12k8_wc = s_min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); // Q0
     651      236431 :         alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] );                      // Q15
     652             :     }
     653             : 
     654      885784 :     overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame   Q0*/
     655      885784 :     move16();
     656             : 
     657      885784 :     IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) )
     658             :     {
     659      868937 :         nSubframes = 1;
     660      868937 :         move16();
     661      868937 :         transform_type[0] = TCX_20;
     662      868937 :         move16();
     663      868937 :         transform_type[1] = TCX_20;
     664      868937 :         move16();
     665      868937 :         overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame       Q0*/
     666      868937 :         move16();
     667             : 
     668      868937 :         IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     669             :         {
     670      234372 :             alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; // Q0
     671      234372 :             move16();
     672      234372 :             alw_voicing[0] = alw_voicing_wc; // Q15
     673      234372 :             move16();
     674             :         }
     675             :     }
     676             :     ELSE
     677             :     {
     678       16847 :         nSubframes = 2;
     679       16847 :         move16();
     680       16847 :         IF( curr_overlap == FULL_OVERLAP )
     681             :         {
     682       11064 :             transform_type[0] = TCX_5;
     683       11064 :             move16();
     684       11064 :             transform_type[1] = TCX_10;
     685       11064 :             move16();
     686             : 
     687       11064 :             overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */
     688       11064 :             move16();
     689       11064 :             if ( EQ_16( last_overlap, HALF_OVERLAP ) )
     690             :             {
     691        1992 :                 overlap_mode[1] = HALF_OVERLAP;
     692        1992 :                 move16();
     693             :             }
     694             :         }
     695        5783 :         ELSE IF( last_overlap == FULL_OVERLAP )
     696             :         {
     697        5155 :             transform_type[0] = TCX_10;
     698        5155 :             move16();
     699        5155 :             transform_type[1] = TCX_5;
     700        5155 :             move16();
     701             : 
     702        5155 :             overlap_mode[1] = MIN_OVERLAP; /* Overlap between 1st and 2nd sub-frame */
     703        5155 :             move16();
     704        5155 :             if ( EQ_16( curr_overlap, HALF_OVERLAP ) )
     705             :             {
     706        2624 :                 overlap_mode[1] = HALF_OVERLAP;
     707        2624 :                 move16();
     708             :             }
     709             :         }
     710             :         ELSE
     711             :         {
     712         628 :             transform_type[0] = transform_type[1] = TCX_5;
     713         628 :             move16();
     714         628 :             move16();
     715             : 
     716         628 :             overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */
     717         628 :             move16();
     718         628 :             test();
     719         628 :             if ( EQ_16( last_overlap, HALF_OVERLAP ) && EQ_16( curr_overlap, HALF_OVERLAP ) )
     720             :             {
     721         180 :                 overlap_mode[1] = HALF_OVERLAP;
     722         180 :                 move16();
     723             :             }
     724             :         }
     725       16847 :         overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame       Q0*/
     726       16847 :         move16();
     727             :     }
     728             : 
     729      885784 :     test();
     730      885784 :     IF( st->igf && NE_16( transform_type[0], TCX_20 ) )
     731             :     {
     732       11764 :         IGFEncResetTCX10BitCounter_fx( st->hIGFEnc );
     733             :     }
     734             : 
     735             :     /*-------------------------------------------------------------------------*
     736             :      * Get MDCT output and TNS parameters. Apply TNS in the spectrum if needed
     737             :      *--------------------------------------------------------------------------*/
     738             : 
     739     1788415 :     FOR( frameno = 0; frameno < nSubframes; frameno++ )
     740             :     {
     741      902631 :         L_subframe = L_frameTCX; // Q0
     742      902631 :         move16();
     743      902631 :         IF( NE_16( nSubframes, 1 ) )
     744             :         {
     745       33694 :             L_subframe = shr( L_frameTCX, 1 );
     746             :         }
     747             : 
     748      902631 :         lpc_left_overlap_mode = overlap_mode[frameno]; // Q0
     749      902631 :         move16();
     750      902631 :         lpc_right_overlap_mode = overlap_mode[frameno + 1]; // Q0
     751      902631 :         move16();
     752      902631 :         if ( EQ_16( lpc_left_overlap_mode, ALDO_WINDOW ) )
     753             :         {
     754      848292 :             lpc_left_overlap_mode = FULL_OVERLAP;
     755      848292 :             move16();
     756             :         }
     757      902631 :         if ( EQ_16( lpc_right_overlap_mode, ALDO_WINDOW ) )
     758             :         {
     759      850005 :             lpc_right_overlap_mode = FULL_OVERLAP;
     760      850005 :             move16();
     761             :         }
     762             : 
     763      902631 :         test();
     764      902631 :         IF( ( EQ_16( transform_type[frameno], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) )
     765             :         {
     766      859675 :             wtda_fx( hTcxEnc->new_speech_TCX, &q_out_wtda, tcx20Win_32, NULL, NULL, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX );
     767             : 
     768      859675 :             IF( windowed_samples != NULL ) /* store overlap data for later */
     769             :             {
     770      633234 :                 assert( frameno == 0 );
     771      633234 :                 windowed_samples[0] = L_deposit_l( overlap_mode[frameno] );     // Q0
     772      633234 :                 windowed_samples[1] = L_deposit_l( overlap_mode[frameno + 1] ); // Q0
     773      633234 :                 *q_win = 0;
     774      633234 :                 move16();
     775             :             }
     776      859675 :             IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     777             :             {
     778             :                 Word16 left_overlap_mode, right_overlap_mode;
     779      226441 :                 if ( EQ_16( overlap_mode[frameno], ALDO_WINDOW ) )
     780             :                 {
     781      224521 :                     left_overlap_mode = FULL_OVERLAP;
     782             :                 }
     783             :                 else
     784             :                 {
     785        1920 :                     left_overlap_mode = overlap_mode[frameno]; // Q0
     786             :                 }
     787             : 
     788      226441 :                 if ( EQ_16( overlap_mode[frameno + 1], ALDO_WINDOW ) )
     789             :                 {
     790      224790 :                     right_overlap_mode = FULL_OVERLAP;
     791             :                 }
     792             :                 else
     793             :                 {
     794        1651 :                     right_overlap_mode = overlap_mode[frameno + 1]; // Q0
     795             :                 }
     796             :                 /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */
     797      226441 :                 WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, left_overlap_mode, right_overlap_mode, &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, 1, 1 );
     798             :             }
     799             :         }
     800             :         ELSE
     801             :         {
     802             :             /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */
     803       42956 :             WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno],
     804       42956 :                           overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB],
     805       42956 :                           &L_subframe, tcx20Win, st->element_mode != IVAS_CPE_MDCT /* truncate_aldo */, 1 );
     806             : 
     807       42956 :             IF( windowed_samples != NULL ) /* save windowed speech_TCX samples */
     808             :             {
     809       30907 :                 assert( L_subframe + ( left_overlap + right_overlap ) / 2 < 2 * L_FRAME_MAX / nSubframes - L_FRAME_MAX / 8 );
     810       30907 :                 win_len[frameno] = add( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) );
     811       30907 :                 move16();
     812       30907 :                 windowed_samples[frameno * L_FRAME_MAX + 0] = L_deposit_l( overlap_mode[frameno] ); // Q0
     813       30907 :                 move32();
     814       30907 :                 windowed_samples[frameno * L_FRAME_MAX + 1] = L_deposit_l( overlap_mode[frameno + 1] ); // Q0
     815       30907 :                 move32();
     816       30907 :                 Copy_Scale_sig_16_32_DEPREC( tcx20Win, windowed_samples + add( imult1616( frameno, L_FRAME_MAX ), 2 ), add( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ), negate( q_tcx20Win ) );
     817       30907 :                 *q_win = s_min( *q_win, sub( L_norm_arr( windowed_samples + add( imult1616( frameno, L_FRAME_MAX ), 2 ), add( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ) ), 1 ) );
     818       30907 :                 move16();
     819       30907 :                 Q_win_temp[frameno] = *q_win;
     820       30907 :                 move16();
     821             : 
     822       30907 :                 Scale_sig32( windowed_samples + frameno * L_FRAME_MAX + 2, win_len[frameno], *q_win ); // q_win
     823             : 
     824       30907 :                 IF( EQ_16( frameno, 1 ) )
     825             :                 {
     826       14788 :                     Scale_sig32( windowed_samples + 2, win_len[0], sub( *q_win, Q_win_temp[0] ) ); // q_win
     827             :                 }
     828             :             }
     829             :         }
     830             : 
     831      902631 :         IF( EQ_16( transform_type[frameno], TCX_5 ) )
     832             :         {
     833       17475 :             folding_offset = shr( left_overlap, 1 );
     834             : 
     835             :             /* Outter left folding */
     836     2089175 :             FOR( i = 0; i < folding_offset; i++ )
     837             :             {
     838     2071700 :                 tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); // q_tcx20Win
     839     2071700 :                 move16();
     840             :             }
     841             : 
     842       17475 :             test();
     843       17475 :             test();
     844       17475 :             test();
     845       17475 :             IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && frameno == 0 && overlap_mode[0] == FULL_OVERLAP && GT_16( sub( L_subframe, left_overlap ), minWindowLen ) )
     846             :             {
     847        7327 :                 tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 );
     848             :                 Word32 L_tmp;
     849      211047 :                 FOR( i = minWindowLen; i >= tmp; i-- ) /* outer left folding of shortened long ALDO slope */
     850             :                 {
     851      203720 :                     L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (q_tcx20Win, Q15) -> Q16 + q_tcx20Win
     852      203720 :                     L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i].v.im );                           // (Q16 + q_tcx20Win, Q15) -> Q16 + q_tcx20Win
     853      203720 :                     tcx20Win[left_overlap + i] = sub_sat( tcx20Win[left_overlap + i], extract_h( L_tmp ) );                                // q_tcx20Win
     854      203720 :                     move32();
     855             :                 }
     856      211047 :                 FOR( i = tmp - 1; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */
     857             :                 {
     858      203720 :                     L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (q_tcx20Win, Q15) -> Q16 + q_tcx20Win
     859      203720 :                     L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re );                                          // (Q16 + q_tcx20Win, Q15) -> Q16 + q_tcx20Win
     860      203720 :                     tcx20Win[left_overlap + i] = sub_sat( tcx20Win[left_overlap + i], extract_h( L_tmp ) );                                // q_tcx20Win
     861      203720 :                     move32();
     862             :                 }
     863             :             }
     864             : 
     865             :             /* Outter right folding */
     866       17475 :             tmp = shr( right_overlap, 1 );
     867      747835 :             FOR( i = 0; i < tmp; i++ )
     868             :             {
     869      730360 :                 tcx20Win[L_subframe + folding_offset - 1 - i] = add_sat( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); // q_tcx20Win
     870      730360 :                 move16();
     871             :             }
     872             : 
     873             :             /* 2xTCX5 */
     874       17475 :             L_subframe = tcx5SizeFB;
     875       17475 :             move16();
     876             : 
     877       17475 :             tmpP16 = tcx20Win;
     878       17475 :             tmpP32 = hTcxEnc->spectrum_fx[frameno];
     879       17475 :             assert( st->mct_chan_mode != MCT_CHAN_MODE_LFE );
     880             :             Word16 len[2], exp[2];
     881       17475 :             hTcxEnc->spectrum_e[frameno] = sub( 16, q_tcx20Win );
     882       17475 :             exp[0] = exp[1] = hTcxEnc->spectrum_e[frameno];
     883       17475 :             move16();
     884       17475 :             move16();
     885       17475 :             move16();
     886       52425 :             FOR( i = 0; i < 2; i++ )
     887             :             {
     888       34950 :                 test();
     889       34950 :                 test();
     890       34950 :                 WindowSignal( st->hTcxCfg,
     891             :                               folding_offset,
     892       34950 :                               mac_r( -( 1 << 16 ), 3 << 8, shl( i, 7 ) ), /* equivalent to: i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */
     893       34950 :                               mac_r( 2 << 16, -( 3 << 8 ), shl( i, 7 ) ), /* equivalent to: sub(i, 1) == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */
     894       34950 :                               &left_overlap, &right_overlap, tmpP16, &L_subframe, tcx5Win, st->element_mode != IVAS_CPE_MDCT, 1 );
     895             : 
     896       69900 :                 TCX_MDCT( tcx5Win,
     897             :                           tmpP32,
     898       34950 :                           &exp[i],
     899             :                           left_overlap,
     900       34950 :                           sub( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ),
     901       34950 :                           right_overlap, st->element_mode );
     902             : 
     903       34950 :                 tmpP16 += tcx5SizeFB;
     904       34950 :                 tmpP32 += tcx5SizeFB;
     905       34950 :                 len[i] = L_subframe;
     906       34950 :                 move16();
     907             : 
     908             :                 /* high-band gain control in case of BWS */
     909       34950 :                 IF( st->bwidth_sw_cnt > 0 )
     910             :                 {
     911             :                     Word16 exp_diff;
     912             :                     Word32 factor;
     913             : 
     914          86 :                     tmp = BASOP_Util_Divide1616_Scale( st->bwidth_sw_cnt, BWS_TRAN_PERIOD, &exp_diff );
     915          86 :                     factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31
     916             : 
     917          86 :                     v_multc_fixed( hTcxEnc->spectrum_fx[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ),
     918             :                                    factor,
     919          86 :                                    hTcxEnc->spectrum_fx[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ),
     920          86 :                                    L_subframe - L_FRAME16k / ( 2 * nSubframes ) );
     921             :                 }
     922             :             }
     923       17475 :             hTcxEnc->spectrum_e[frameno] = s_max( exp[0], exp[1] );
     924       17475 :             move16();
     925             : 
     926       52425 :             FOR( i = 0; i < 2; i++ )
     927             :             {
     928       34950 :                 scale_sig32( hTcxEnc->spectrum_fx[frameno] + i * L_subframe, len[i], sub( exp[i], hTcxEnc->spectrum_e[frameno] ) );
     929             :             }
     930             :         }
     931             :         ELSE /* transform_type[frameno] != TCX_5 */
     932             :         {
     933      885156 :             assert( transform_type[frameno] == TCX_10 || transform_type[frameno] == TCX_20 );
     934             : 
     935             :             /* TCX20/TCX10 */
     936      885156 :             hTcxEnc->spectrum_e[frameno] = 16;
     937      885156 :             move16();
     938      885156 :             test();
     939      885156 :             test();
     940      885156 :             IF( ( EQ_16( transform_type[frameno], TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) )
     941      859675 :             {
     942             :                 /* DCT */
     943             :                 Word16 Q;
     944             : 
     945      859675 :                 Q = q_out_wtda;
     946      859675 :                 edct_ivas_fx( tcx20Win_32, hTcxEnc->spectrum_fx[frameno], L_subframe, &Q );
     947      859675 :                 hTcxEnc->spectrum_e[frameno] = sub( 31, Q );
     948      859675 :                 move16();
     949             : 
     950             :                 Word16 exp_diff;
     951             :                 Word32 factor;
     952             : 
     953      859675 :                 tmp = BASOP_Util_Divide1616_Scale( NORM_MDCT_FACTOR, L_subframe, &exp_diff );
     954      859675 :                 tmp = Sqrt16( tmp, &exp_diff );
     955      859675 :                 factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31
     956             : 
     957      859675 :                 v_multc_fixed( hTcxEnc->spectrum_fx[frameno], factor, hTcxEnc->spectrum_fx[frameno], L_subframe );
     958             :             }
     959             :             ELSE
     960             :             {
     961       25481 :                 test();
     962       25481 :                 test();
     963       25481 :                 test();
     964       25481 :                 test();
     965       25481 :                 IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && frameno == 0 && EQ_16( transform_type[0], TCX_10 ) && overlap_mode[0] == FULL_OVERLAP && GT_16( sub( L_subframe, left_overlap ), minWindowLen ) )
     966             :                 {
     967        4266 :                     tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 );
     968             :                     Word32 L_tmp;
     969      111166 :                     FOR( i = minWindowLen; i >= tmp; i-- ) /* outer left folding of shortened long ALDO slope */
     970             :                     {
     971      106900 :                         L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (q_tcx20Win, Q15) -> Q16 + q_tcx20Win
     972      106900 :                         L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i].v.im );                           // (Q16, Q15) -> Q16 + q_tcx20Win
     973      106900 :                         tcx20Win[left_overlap + i] = sub_sat( tcx20Win[left_overlap + i], extract_h( L_tmp ) );                                // q_tcx20Win
     974      106900 :                         move32();
     975             :                     }
     976      111166 :                     FOR( i = tmp - 1; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */
     977             :                     {
     978      106900 :                         L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (q_tcx20Win, Q15) -> Q16 + q_tcx20Win
     979      106900 :                         L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re );                                          // (Q16 + q_tcx20Win, Q15) -> Q16 + q_tcx20Win
     980      106900 :                         tcx20Win[left_overlap + i] = sub_sat( tcx20Win[left_overlap + i], extract_h( L_tmp ) );                                // q_tcx20Win
     981      106900 :                         move32();
     982             :                     }
     983             :                 }
     984             : 
     985       25481 :                 TCX_MDCT( tcx20Win, hTcxEnc->spectrum_fx[frameno], &hTcxEnc->spectrum_e[frameno], left_overlap, sub( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode );
     986       25481 :                 hTcxEnc->spectrum_e[frameno] = sub( hTcxEnc->spectrum_e[frameno], q_tcx20Win );
     987       25481 :                 move16();
     988             :             }
     989             : 
     990             :             /* high-band gain control in case of BWS */
     991      885156 :             IF( st->bwidth_sw_cnt > 0 )
     992             :             {
     993             :                 Word16 exp_diff;
     994             :                 Word32 factor;
     995             : 
     996        2932 :                 tmp = BASOP_Util_Divide1616_Scale( st->bwidth_sw_cnt, BWS_TRAN_PERIOD, &exp_diff );
     997        2932 :                 factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31
     998             : 
     999        2932 :                 v_multc_fixed( hTcxEnc->spectrum_fx[frameno] + L_FRAME16k / nSubframes,
    1000             :                                factor,
    1001        2932 :                                hTcxEnc->spectrum_fx[frameno] + L_FRAME16k / nSubframes,
    1002        2932 :                                L_subframe - L_FRAME16k / nSubframes );
    1003             :             }
    1004             : 
    1005      885156 :             IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
    1006             :             {
    1007             :                 /* For TCX20 at bitrates up to 64 kbps we need the power spectrum */
    1008      236293 :                 test();
    1009      236293 :                 test();
    1010      236293 :                 IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) && ( ( LT_32( st->total_brate, HQ_96k ) ) || st->igf ) )
    1011             :                 {
    1012      233208 :                     pMdstWin = tcx20Win;
    1013      233208 :                     Word16 q_pmdstWin = q_tcx20Win;
    1014      233208 :                     move16();
    1015      233208 :                     test();
    1016      233208 :                     if ( ( ( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) && ( NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) ) )
    1017             :                     {
    1018      225281 :                         pMdstWin = mdstWin;
    1019      225281 :                         q_pmdstWin = q_mdstWin;
    1020      225281 :                         move16();
    1021             :                     }
    1022             : 
    1023             :                     /* Compute noise-measure flags for spectrum filling and quantization */
    1024      233208 :                     AnalyzePowerSpectrum_ivas_fx( st, div_l( L_mult( L_subframe, st->L_frame ), hTcxEnc->L_frameTCX ),
    1025      233208 :                                                   L_subframe, left_overlap, right_overlap, hTcxEnc->spectrum_fx[frameno], hTcxEnc->spectrum_e[frameno],
    1026             :                                                   pMdstWin, q_pmdstWin, powerSpec, powerSpec_e );
    1027             :                 }
    1028             :             }
    1029             :         }
    1030             : 
    1031      902631 :         IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
    1032             :         {
    1033             :             Word16 scale;
    1034      664141 :             L_subframe = L_frameTCX; /* Q0 */ /* L_subframe = idiv1616( L_frameTCX, nSubframes ); */
    1035      664141 :             IF( EQ_16( nSubframes, 2 ) )
    1036             :             {
    1037       29576 :                 L_subframe = shr( L_frameTCX, 1 );
    1038             :             }
    1039             : 
    1040      664141 :             test();
    1041      664141 :             IF( EQ_16( transform_type[frameno], TCX_20 ) && NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) )
    1042             :             {
    1043      633234 :                 wtda_ext_fx( hTcxEnc->new_speech_TCX, mdstWin, overlap_mode[frameno], overlap_mode[frameno + 1], L_frameTCX, 3 );
    1044      633234 :                 scale = sub( norm_arr( mdstWin, L_frameTCX ), 1 );
    1045      633234 :                 scale = s_min( 1, scale ); // restricting the Q to zero or less
    1046      633234 :                 scale_sig( mdstWin, L_frameTCX, scale );
    1047      633234 :                 q_mdstWin = add( add( st->q_inp, -1 ), scale );
    1048             :             }
    1049             :             ELSE
    1050             :             {
    1051             :                 Word16 sig_len;
    1052             :                 /* Windowing for the MDST */
    1053       30907 :                 WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, 0, 1 );
    1054       30907 :                 sig_len = add( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) );
    1055       30907 :                 scale = sub( norm_arr( mdstWin, sig_len ), 1 );
    1056       30907 :                 scale = s_min( 0, scale ); // restricting the Q to zero or less
    1057       30907 :                 scale_sig( mdstWin, sig_len, scale );
    1058       30907 :                 q_mdstWin = add( scale, st->q_inp );
    1059             :             }
    1060             : 
    1061      664141 :             IF( EQ_16( transform_type[frameno], TCX_5 ) )
    1062             :             {
    1063             :                 /* Outer left folding */
    1064     1868768 :                 FOR( i = 0; i < left_overlap / 2; i++ )
    1065             :                 {
    1066     1853490 :                     mdstWin[left_overlap / 2 + i] = add( mdstWin[left_overlap / 2 + i], mdstWin[left_overlap / 2 - 1 - i] ); // q_mdstWin
    1067             :                 }
    1068             : 
    1069       15278 :                 test();
    1070       15278 :                 test();
    1071       15278 :                 IF( frameno == 0 && overlap_mode[0] == FULL_OVERLAP && GT_16( sub( L_subframe, left_overlap ), minWindowLen ) )
    1072             :                 {
    1073        7327 :                     tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 );
    1074        7327 :                     shift = sub( q_mdstWin, add( Q16, st->q_inp ) );
    1075             :                     Word32 L_tmp;
    1076      211047 :                     FOR( i = minWindowLen; i >= tmp; i-- ) /* outer left folding of shortened long ALDO slope */
    1077             :                     {
    1078      203720 :                         L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (q_inp, Q15) -> Q16 + q_inp
    1079      203720 :                         L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i].v.im );                           // (Q16 + q_inp, Q15) -> Q16 + q_inp
    1080      203720 :                         L_tmp = L_shl( L_tmp, shift );                                                                                         // q_mdstWin
    1081      203720 :                         mdstWin[left_overlap + i] = add( mdstWin[left_overlap + i], extract_l( L_tmp ) );                                      // q_mdstWin
    1082      203720 :                         move32();
    1083             :                     }
    1084      211047 :                     FOR( i = tmp - 1; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */
    1085             :                     {
    1086      203720 :                         L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (q_inp, Q15) -> Q16 + q_inp
    1087      203720 :                         L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re );                                          // (Q16 + q_inp, Q15) -> Q16 + q_inp
    1088      203720 :                         L_tmp = L_shl( L_tmp, shift );                                                                                         // q_mdstWin
    1089      203720 :                         mdstWin[left_overlap + i] = add( mdstWin[left_overlap + i], extract_l( L_tmp ) );                                      // q_mdstWin
    1090      203720 :                         move32();
    1091             :                     }
    1092             :                 }
    1093             : 
    1094             :                 /* Outer right folding */
    1095      632608 :                 FOR( i = 0; i < right_overlap / 2; i++ )
    1096             :                 {
    1097      617330 :                     mdstWin[L_subframe + left_overlap / 2 - 1 - i] = sub( mdstWin[L_subframe + left_overlap / 2 - 1 - i], mdstWin[L_subframe + left_overlap / 2 + i] ); // q_mdstWin
    1098      617330 :                     move16();
    1099             :                 }
    1100             : 
    1101             :                 /* 2xTCX5 */
    1102       15278 :                 L_subframe = tcx5SizeFB;
    1103       15278 :                 move16();
    1104       15278 :                 folding_offset = shr( left_overlap, 1 );
    1105       15278 :                 move16();
    1106             : 
    1107       45834 :                 FOR( i = 0; i < 2; i++ )
    1108             :                 {
    1109       30556 :                     assert( st->mct_chan_mode != MCT_CHAN_MODE_LFE );
    1110       30556 :                     WindowSignal( st->hTcxCfg, folding_offset, i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, i == 1 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, &left_overlap, &right_overlap, mdstWin + i * tcx5SizeFB, &L_subframe, tcx5Win, 0, 1 );
    1111             : 
    1112       30556 :                     spectrum_e[frameno] = sub( 16, q_mdstWin );
    1113       30556 :                     move16();
    1114       30556 :                     TCX_MDST( tcx5Win, spectrum[frameno] + i * tcx5SizeFB, &spectrum_e[frameno], left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode );
    1115             :                     /* high-band gain control in case of BWS */
    1116       30556 :                     IF( st->bwidth_sw_cnt > 0 )
    1117             :                     {
    1118             :                         Word16 exp_diff;
    1119             :                         Word32 factor;
    1120             : 
    1121          84 :                         tmp = BASOP_Util_Divide1616_Scale( st->bwidth_sw_cnt, BWS_TRAN_PERIOD, &exp_diff );
    1122          84 :                         factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31
    1123             : 
    1124          84 :                         v_multc_fixed( spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ),
    1125             :                                        factor,
    1126          84 :                                        spectrum[frameno] + i * tcx5SizeFB + L_FRAME16k / ( 2 * nSubframes ),
    1127          84 :                                        L_subframe - L_FRAME16k / ( 2 * nSubframes ) );
    1128             :                     }
    1129             :                 }
    1130             :             }
    1131             :             ELSE /* transform_type[frameno] != TCX_5 */
    1132             :             {
    1133      648863 :                 spectrum_e[frameno] = sub( 16, q_mdstWin );
    1134      648863 :                 test();
    1135      648863 :                 IF( EQ_16( transform_type[frameno], TCX_20 ) && NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) )
    1136      633234 :                 {
    1137             :                     Word16 Q;
    1138      633234 :                     Copy_Scale_sig_16_32_no_sat( mdstWin, L_tmpbuf, N_MAX + L_MDCT_OVLP_MAX, 16 );
    1139             : 
    1140      633234 :                     Q = add( q_mdstWin, 16 );
    1141      633234 :                     move16();
    1142      633234 :                     edst_fx( L_tmpbuf, spectrum[frameno], L_subframe, &Q );
    1143      633234 :                     spectrum_e[frameno] = 31 - Q;
    1144             : 
    1145             :                     Word16 exp_diff;
    1146             :                     Word32 factor;
    1147             : 
    1148      633234 :                     tmp = BASOP_Util_Divide1616_Scale( NORM_MDCT_FACTOR, L_subframe, &exp_diff );
    1149      633234 :                     tmp = Sqrt16( tmp, &exp_diff );
    1150      633234 :                     factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31
    1151             : 
    1152      633234 :                     v_multc_fixed( spectrum[frameno], factor, spectrum[frameno], L_subframe );
    1153             :                 }
    1154             :                 ELSE
    1155             :                 {
    1156       15629 :                     test();
    1157       15629 :                     test();
    1158       15629 :                     test();
    1159       15629 :                     IF( frameno == 0 && EQ_16( transform_type[0], TCX_10 ) && overlap_mode[0] == FULL_OVERLAP && GT_16( sub( L_subframe, left_overlap ), minWindowLen ) )
    1160             :                     {
    1161        4266 :                         tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 );
    1162             :                         Word32 L_tmp;
    1163        4266 :                         shift = sub( q_mdstWin, add( Q16, st->q_inp ) );
    1164      111166 :                         FOR( i = minWindowLen; i >= tmp; i-- ) /* outer left folding of shortened long ALDO slope */
    1165             :                         {
    1166      106900 :                             L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (q_inp, Q15) -> Q16 + q_inp
    1167      106900 :                             L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[minWindowLen - i].v.im );                           // (Q16 + q_inp, Q15) -> Q16 + q_inp
    1168      106900 :                             L_tmp = L_shl( L_tmp, shift );                                                                                         // q_mdstWin
    1169      106900 :                             mdstWin[left_overlap + i] = add( mdstWin[left_overlap + i], extract_l( L_tmp ) );                                      // q_mdstWin
    1170      106900 :                             move32();
    1171             :                         }
    1172      111166 :                         FOR( i = tmp - 1; i >= 0; i-- ) /* outer left folding of shortened long ALDO slope */
    1173             :                         {
    1174      106900 :                             L_tmp = L_mult( hTcxEnc->speech_TCX[-1 - i], st->hTcxCfg->tcx_aldo_window_1_FB[left_overlap / 2 + minWindowLen - i] ); // (q_inp, Q15) -> Q16 + q_inp
    1175      106900 :                             L_tmp = Mpy_32_16_1( L_tmp, st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re );                                          // (Q16 + q_inp, Q15) -> Q16 + q_inp
    1176      106900 :                             L_tmp = L_shl( L_tmp, shift );                                                                                         // q_mdstWin
    1177      106900 :                             mdstWin[left_overlap + i] = add( mdstWin[left_overlap + i], extract_l( L_tmp ) );                                      // q_mdstWin
    1178      106900 :                             move32();
    1179             :                         }
    1180             :                     }
    1181             : 
    1182       15629 :                     TCX_MDST( mdstWin, spectrum[frameno], &spectrum_e[frameno], left_overlap, L_subframe - ( left_overlap + right_overlap ) / 2, right_overlap, st->element_mode );
    1183             :                 }
    1184             : 
    1185             :                 /* high-band gain control in case of BWS */
    1186      648863 :                 IF( st->bwidth_sw_cnt > 0 )
    1187             :                 {
    1188             :                     Word16 exp_diff;
    1189             :                     Word32 factor;
    1190             : 
    1191        1912 :                     tmp = BASOP_Util_Divide1616_Scale( st->bwidth_sw_cnt, BWS_TRAN_PERIOD, &exp_diff );
    1192        1912 :                     factor = L_shl( L_deposit_h( tmp ), exp_diff ); // Q31
    1193             : 
    1194        1912 :                     v_multc_fixed( spectrum[frameno] + L_FRAME16k / nSubframes, factor, spectrum[frameno] + L_FRAME16k / nSubframes, L_subframe - L_FRAME16k / nSubframes );
    1195             :                 }
    1196             :             }
    1197             :         }
    1198             : 
    1199      902631 :         IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
    1200             :         {
    1201      238490 :             test();
    1202      238490 :             IF( ( frameno == 0 ) && ( st->last_core == ACELP_CORE ) )
    1203             :             {
    1204        7931 :                 TNSAnalysis_ivas_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], 1, hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL );
    1205             :             }
    1206             :             ELSE
    1207             :             {
    1208      230559 :                 TNSAnalysis_ivas_fx( st->hTcxCfg, L_frameTCX, st->hTcxCfg->tcx_coded_lines, transform_type[frameno], 0, hTcxEnc->spectrum_fx[frameno], st->hTranDet, -32768, &hTcxEnc->tnsData[frameno], &hTcxEnc->fUseTns[frameno], NULL );
    1209             :             }
    1210             : 
    1211      238490 :             IF( st->hTcxCfg->fIsTNSAllowed )
    1212             :             {
    1213      161621 :                 EncodeTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, &hTcxEnc->tnsData[frameno],
    1214      161621 :                                   param_core + frameno * NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, pTnsSize + frameno, pTnsBits + frameno );
    1215             :             }
    1216             : 
    1217      238490 :             IF( EQ_16( transform_type[frameno], TCX_5 ) )
    1218             :             {
    1219             :                 /* group sub-windows: interleave bins according to their frequencies */
    1220      524837 :                 FOR( i = 0; i < tcx5SizeFB; i++ )
    1221             :                 {
    1222      522640 :                     interleaveBuf[2 * i] = hTcxEnc->spectrum_fx[frameno][i]; /* hTcxEnc->spectrum_e */
    1223      522640 :                     move32();
    1224      522640 :                     interleaveBuf[2 * i + 1] = hTcxEnc->spectrum_fx[frameno][tcx5SizeFB + i]; /* hTcxEnc->spectrum_e */
    1225      522640 :                     move32();
    1226             :                 }
    1227        2197 :                 MVR2R_WORD32( interleaveBuf, hTcxEnc->spectrum_fx[frameno], tcx10SizeFB );
    1228             :             }
    1229             : 
    1230             :             /*--------------------------------------------------------------*
    1231             :              * LPC analysis
    1232             :              *---------------------------------------------------------------*/
    1233             : 
    1234      238490 :             IF( st->tcxonly )
    1235             :             {
    1236      108948 :                 HBAutocorrelation_fx( st->hTcxCfg, lpc_left_overlap_mode, lpc_right_overlap_mode, &st->speech_enc_pe[frameno * tcx10Size],
    1237      108948 :                                       shr( L_frame, sub( nSubframes, 1 ) ), r, M );
    1238             : 
    1239     1961064 :                 FOR( i = 0; i <= M; i++ )
    1240             :                 {
    1241     1852116 :                     r_l[frameno][i] = L_Extract_lc( r[i], &r_h[frameno][i] );
    1242     1852116 :                     move16();
    1243     1852116 :                     move16();
    1244             :                 }
    1245             : 
    1246      108948 :                 adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core );
    1247             : 
    1248      108948 :                 E_LPC_lev_dur( r_h[frameno], r_l[frameno], A, NULL, M, NULL );
    1249             : 
    1250      108948 :                 E_LPC_a_lsp_conversion( A, lsp[nSubframes - 1 - frameno], st->lspold_enc_fx, M );
    1251             :             }
    1252             : 
    1253      238490 :             IF( st->igf )
    1254             :             {
    1255      226807 :                 Word16 q_spectrum = sub( Q31, hTcxEnc->spectrum_e[frameno] );
    1256      226807 :                 ProcessIGF_ivas_fx( st, N_MAX + L_MDCT_OVLP_MAX, hTcxEnc->spectrum_fx[frameno], &q_spectrum, hTcxEnc->spectrum_fx[frameno], q_spectrum, powerSpec, powerSpec_e, transform_type[frameno] == TCX_20, frameno, 0, vad_hover_flag );
    1257             :             }
    1258             :         }
    1259             :     }
    1260             : 
    1261             : 
    1262      885784 :     IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
    1263             :     {
    1264             :         /* Copy memory */
    1265      236431 :         MVR2R_WORD16( lsp_new, st->lspold_enc_fx, M );
    1266             :     }
    1267             : 
    1268      885784 :     return;
    1269             : }

Generated by: LCOV version 1.14