LCOV - code coverage report
Current view: top level - lib_enc - swb_pre_proc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 43b7b28dcb1471ff5d355252c4b8f37ee7ecc268 Lines: 613 712 86.1 %
Date: 2025-11-02 02:02:47 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdlib.h>
       6             : #include "options.h"
       7             : #include "cnst.h"
       8             : #include "rom_com.h"
       9             : #include "stl.h"
      10             : #include "prot_fx.h"      /* Function prototypes                    */
      11             : #include "ivas_prot_fx.h" /* Function prototypes                    */
      12             : #include "prot_fx_enc.h"  /* Function prototypes                    */
      13             : #include "basop_util.h"
      14             : #include "ivas_rom_enc.h"
      15             : #include <assert.h>
      16             : 
      17             : 
      18             : /*========================================================================*/
      19             : /* FUNCTION :  wb_pre_proc_fx()                                                                                   */
      20             : /*------------------------------------------------------------------------*/
      21             : /* PURPOSE :  Resampling of input signal when input signal sample rate    */
      22             : /*              is above 16kHz                                                        */
      23             : /*------------------------------------------------------------------------*/
      24             : /* INPUT ARGUMENTS :                                                                                                      */
      25             : /* Encoder_State *st_fx   : Encoder State Structure                               */
      26             : /* _ (Word16*) input         : original input signal                      */
      27             : /*------------------------------------------------------------------------*/
      28             : /* INPUT/OUTPUT ARGUMENTS :                                                                                               */
      29             : /* _None                                                                      */
      30             : /*------------------------------------------------------------------------*/
      31             : /* OUTPUT ARGUMENTS :                                                                                                     */
      32             : /* _ (Word16*) new_wb_speech : original input signal at 16kHz    Q-1      */
      33             : /*------------------------------------------------------------------------*/
      34             : 
      35             : /* st_fx->old_wtda_wb_fx                                                  */
      36             : /*------------------------------------------------------------------------*/
      37             : /* RETURN ARGUMENTS :                                                                                                     */
      38             : /* _ None                                                                                                                                 */
      39             : /*========================================================================*/
      40             : 
      41           0 : void wb_pre_proc_fx(
      42             :     Encoder_State *st_fx,            /* i/o: encoder state structure                   */
      43             :     const Word16 *new_inp_resamp16k, /* i  : original input signal in Q-1              */
      44             :     Word16 *hb_speech                /* o  : HB target signal (6-8kHz) at 16kHz in Q-1 */
      45             : )
      46             : {
      47             :     Word16 Sample_Delay_WB_BWE;
      48             :     Word16 ramp_flag;
      49             :     Word16 old_input[NS2SA( 16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k];
      50             :     Word16 *highband_new_speech;
      51             :     Word16 highband_old_speech[( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16];
      52             :     Word16 temp_buf[320];
      53             :     Word16 Q_wb_sp, i, max_wb;
      54           0 :     Word16 fSwitchFromIO = 0;
      55           0 :     move16();
      56           0 :     Word32 temp1 = 0;
      57           0 :     move32();
      58           0 :     Word32 temp2 = 0;
      59           0 :     move32();
      60           0 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
      61           0 :     TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD;
      62           0 :     FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD;
      63             : 
      64           0 :     test();
      65           0 :     test();
      66           0 :     test();
      67           0 :     test();
      68           0 :     test();
      69           0 :     test();
      70           0 :     IF( ( EQ_32( st_fx->last_total_brate, ACELP_6k60 ) ) ||
      71             :         ( EQ_32( st_fx->last_total_brate, ACELP_8k85 ) ) ||
      72             :         ( EQ_32( st_fx->last_total_brate, ACELP_12k65 ) ) ||
      73             :         ( EQ_32( st_fx->last_total_brate, ACELP_14k25 ) ) ||
      74             :         ( EQ_32( st_fx->last_total_brate, ACELP_15k85 ) ) ||
      75             :         ( GE_32( st_fx->last_total_brate, ACELP_18k25 ) && LE_32( st_fx->last_total_brate, ACELP_23k85 ) ) )
      76             :     {
      77           0 :         fSwitchFromIO = 1;
      78           0 :         move16();
      79             :     }
      80             : 
      81           0 :     set16_fx( old_input, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k );
      82             : 
      83           0 :     max_wb = 1;
      84           0 :     move16();
      85           0 :     FOR( i = 0; i < L_FRAME16k; i++ )
      86             :     {
      87           0 :         max_wb = s_max( max_wb, abs_s( new_inp_resamp16k[i] ) );
      88             :     }
      89           0 :     Q_wb_sp = norm_s( max_wb );
      90             : 
      91           0 :     Copy_Scale_sig( new_inp_resamp16k, temp_buf, L_FRAME16k, -3 );
      92           0 :     temp1 = L_mac0( temp1, temp_buf[0], temp_buf[0] );
      93           0 :     FOR( i = 1; i < L_FRAME16k; i++ )
      94             :     {
      95           0 :         temp1 = L_mac0( temp1, temp_buf[i], temp_buf[i] );
      96           0 :         temp2 = L_mac0( temp2, temp_buf[i - 1], temp_buf[i] );
      97             :     }
      98             : 
      99           0 :     IF( temp2 < Mult_32_16( temp1, 31129 /*0.95f*/ ) )
     100             :     {
     101           0 :         Q_wb_sp = sub( Q_wb_sp, 3 ); /* leave 3 bit headroom */
     102             :     }
     103           0 :     Copy_Scale_sig( new_inp_resamp16k, temp_buf, L_FRAME16k, Q_wb_sp );
     104           0 :     Scale_sig( hBWE_TD->decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), Q_wb_sp );
     105           0 :     Scale_sig( hBWE_TD->decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), Q_wb_sp );
     106             :     /* temp_buf, and the memory states are in Q_wb_sp */
     107             : 
     108           0 :     test();
     109           0 :     test();
     110           0 :     IF( EQ_16( st_fx->extl, WB_BWE ) || EQ_16( st_fx->extl, WB_TBE ) || st_fx->igf != 0 )
     111             :     {
     112           0 :         ramp_flag = 0;
     113           0 :         move16();
     114             : 
     115           0 :         test();
     116           0 :         test();
     117           0 :         test();
     118           0 :         test();
     119           0 :         if ( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) && st_fx->igf == 0 ) ||
     120           0 :              ( st_fx->igf != 0 && fSwitchFromIO != 0 ) )
     121             :         {
     122           0 :             ramp_flag = 1;
     123           0 :             move16();
     124             :         }
     125             : 
     126           0 :         IF( !hSC_VBR->ppp_mode )
     127             :         {
     128             :             /* temp_buf is in Q_wb_sp
     129             :                hb_speech and the two decimator memories are in Q_wb_sp */
     130           0 :             flip_spectrum_and_decimby4_fx( temp_buf, hb_speech, L_FRAME16k, hBWE_TD->decim_state1_fx, hBWE_TD->decim_state2_fx, ramp_flag );
     131             : 
     132             :             /* rescale the hb_speech and memories back to Q-1 to keep the downstream BWE coding unaffected */
     133           0 :             Scale_sig( hb_speech, L_FRAME16k / 4, -Q_wb_sp );
     134           0 :             Scale_sig( hBWE_TD->decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), -Q_wb_sp );
     135           0 :             Scale_sig( hBWE_TD->decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), -Q_wb_sp );
     136             : 
     137           0 :             IF( NE_16( st_fx->extl, WB_TBE ) )
     138             :             {
     139             :                 /* Update the previous wideband speech buffer in case of a WB_BWE frame */
     140           0 :                 Sample_Delay_WB_BWE = ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16;
     141             : 
     142           0 :                 highband_new_speech = highband_old_speech + Sample_Delay_WB_BWE;
     143           0 :                 Copy( hb_speech, highband_new_speech, L_FRAME16k / 4 );
     144           0 :                 Copy( highband_old_speech + L_FRAME16k / 4, hBWE_TD->old_speech_wb_fx, Sample_Delay_WB_BWE );
     145             :             }
     146             :         }
     147             :     }
     148             :     ELSE
     149             :     {
     150           0 :         set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     151           0 :         set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     152           0 :         set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 );
     153             :     }
     154             : 
     155             :     /* st->old_input_wb and st->old_wtda_wb must be updated each frame, or there are often some clicks during WB TBE <-> WB BWE switching */
     156           0 :     test();
     157           0 :     test();
     158           0 :     test();
     159           0 :     IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && LE_32( st_fx->total_brate, ACELP_8k00 ) ) ) && !hSC_VBR->ppp_mode )
     160             :     {
     161           0 :         Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS );
     162             : 
     163           0 :         Copy( new_inp_resamp16k, &old_input[Sample_Delay_WB_BWE], L_FRAME16k );
     164           0 :         Copy( hBWE_FD->old_input_wb_fx, old_input, Sample_Delay_WB_BWE );
     165           0 :         Copy( new_inp_resamp16k + L_FRAME16k - Sample_Delay_WB_BWE, hBWE_FD->old_input_wb_fx, Sample_Delay_WB_BWE );
     166           0 :         Copy( old_input, hBWE_FD->L_old_wtda_swb_fx, L_FRAME16k );
     167             :     }
     168           0 :     return;
     169             : }
     170             : 
     171             : 
     172             : /*========================================================================*/
     173             : /* FUNCTION :  wb_pre_proc_ivas_fx()                                                                      */
     174             : /*------------------------------------------------------------------------*/
     175             : /* PURPOSE :  Resampling of input signal when input signal sample rate    */
     176             : /*              is above 16kHz                                                        */
     177             : /*------------------------------------------------------------------------*/
     178             : /* INPUT ARGUMENTS :                                                                                                      */
     179             : /* Encoder_State *st_fx   : Encoder State Structure                               */
     180             : /* _ (Word16*) input         : original input signal                      */
     181             : /*------------------------------------------------------------------------*/
     182             : /* INPUT/OUTPUT ARGUMENTS :                                                                                               */
     183             : /* _None                                                                      */
     184             : /*------------------------------------------------------------------------*/
     185             : /* OUTPUT ARGUMENTS :                                                                                                     */
     186             : /* _ (Word16*) new_wb_speech : original input signal at 16kHz    Q-1      */
     187             : /*------------------------------------------------------------------------*/
     188             : 
     189             : /* st_fx->old_wtda_wb_fx                                                  */
     190             : /*------------------------------------------------------------------------*/
     191             : /* RETURN ARGUMENTS :                                                                                                     */
     192             : /* _ None                                                                                                                                 */
     193             : /*========================================================================*/
     194             : 
     195       43714 : void wb_pre_proc_ivas_fx(
     196             :     Encoder_State *st_fx,            /* i/o: encoder state structure                   */
     197             :     const Word16 last_element_mode,  /* i  : last element mode                          */
     198             :     const Word16 *new_inp_resamp16k, /* i  : original input signal in Q-1              */
     199             :     Word16 *hb_speech                /* o  : HB target signal (6-8kHz) at 16kHz in Q-1 */
     200             : )
     201             : {
     202             :     Word16 Sample_Delay_WB_BWE;
     203             :     Word16 ramp_flag;
     204             :     Word16 decim_state1_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )], decim_state2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )];
     205             :     Word16 old_input[NS2SA( 16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + STEREO_DFT_OVL_16k + L_FRAME16k];
     206             :     Word16 *highband_new_speech;
     207             :     Word16 highband_old_speech[( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16];
     208             :     Word16 temp_buf[320];
     209             :     Word16 Q_wb_sp, i, max_wb;
     210       43714 :     Word16 fSwitchFromIO = 0;
     211             :     Word16 ppp_mode;
     212       43714 :     Word64 temp1 = 0;
     213       43714 :     Word64 temp2 = 0;
     214             :     Word32 tmp1, tmp2;
     215             :     Word16 norm;
     216       43714 :     move16();
     217       43714 :     move64();
     218       43714 :     move64();
     219             : 
     220             : 
     221       43714 :     TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD;
     222       43714 :     FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD;
     223             : 
     224       43714 :     IF( st_fx->Opt_SC_VBR )
     225             :     {
     226           0 :         ppp_mode = st_fx->hSC_VBR->ppp_mode;
     227           0 :         move16();
     228             :     }
     229             :     ELSE
     230             :     {
     231       43714 :         ppp_mode = 0;
     232       43714 :         move16();
     233             :     }
     234             : 
     235       43714 :     test();
     236       43714 :     test();
     237       43714 :     test();
     238       43714 :     test();
     239       43714 :     test();
     240       43714 :     test();
     241       43714 :     test();
     242       43714 :     test();
     243       87423 :     if ( ( EQ_32( st_fx->last_total_brate, ACELP_6k60 ) ) ||
     244       87417 :          ( EQ_32( st_fx->last_total_brate, ACELP_8k85 ) ) ||
     245       87371 :          ( EQ_32( st_fx->last_total_brate, ACELP_12k65 ) ) ||
     246       87226 :          ( EQ_32( st_fx->last_total_brate, ACELP_14k25 ) ) ||
     247       86922 :          ( EQ_32( st_fx->last_total_brate, ACELP_15k85 ) ) ||
     248       86706 :          ( EQ_32( st_fx->last_total_brate, ACELP_18k25 ) ) ||
     249       86692 :          ( EQ_32( st_fx->last_total_brate, ACELP_19k85 ) ) ||
     250       86598 :          ( EQ_32( st_fx->last_total_brate, ACELP_23k05 ) ) ||
     251       43253 :          ( EQ_32( st_fx->last_total_brate, ACELP_23k85 ) ) )
     252             :     {
     253         543 :         fSwitchFromIO = 1;
     254         543 :         move16();
     255             :     }
     256             : 
     257       43714 :     set16_fx( old_input, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + STEREO_DFT_OVL_16k + L_FRAME16k );
     258             : 
     259       43714 :     max_wb = 1;
     260       43714 :     move16();
     261    14032194 :     FOR( i = 0; i < L_FRAME16k; i++ )
     262             :     {
     263    13988480 :         max_wb = s_max( max_wb, abs_s( new_inp_resamp16k[i] ) );
     264             :     }
     265       43714 :     Q_wb_sp = norm_s( max_wb );
     266             : 
     267       43714 :     Copy_Scale_sig( new_inp_resamp16k, temp_buf, L_FRAME16k, -3 );
     268       43714 :     temp1 = W_mac_32_32( temp1, temp_buf[0], temp_buf[0] );
     269    13988480 :     FOR( i = 1; i < L_FRAME16k; i++ )
     270             :     {
     271    13944766 :         temp1 = W_mac_32_32( temp1, temp_buf[i], temp_buf[i] );
     272    13944766 :         temp2 = W_mac_32_32( temp2, temp_buf[i - 1], temp_buf[i] );
     273             :     }
     274       43714 :     norm = s_min( W_norm( temp1 ), W_norm( temp2 ) );
     275       43714 :     tmp1 = W_extract_h( W_shl( temp1, norm ) );
     276       43714 :     tmp2 = W_extract_h( W_shl( temp2, norm ) );
     277             : 
     278       43714 :     IF( LT_32( tmp2, Mpy_32_16_1( tmp1, 31129 /*0.95f*/ ) ) )
     279             :     {
     280       12203 :         Q_wb_sp = sub( Q_wb_sp, 3 ); /* leave 3 bit headroom */
     281             :     }
     282       43714 :     Copy_Scale_sig( new_inp_resamp16k, temp_buf, L_FRAME16k, Q_wb_sp );
     283       43714 :     Scale_sig( hBWE_TD->decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), Q_wb_sp );
     284       43714 :     Scale_sig( hBWE_TD->decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), Q_wb_sp );
     285             :     /* temp_buf, and the memory states are in Q_wb_sp */
     286             : 
     287       43714 :     test();
     288       43714 :     test();
     289       43714 :     IF( EQ_16( st_fx->extl, WB_BWE ) || EQ_16( st_fx->extl, WB_TBE ) || st_fx->igf )
     290             :     {
     291       21377 :         ramp_flag = 0;
     292       21377 :         move16();
     293             : 
     294       21377 :         test();
     295       21377 :         test();
     296       21377 :         test();
     297       21377 :         test();
     298       21377 :         IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) && !st_fx->igf ) ||
     299             :             ( st_fx->igf && fSwitchFromIO ) )
     300             :         {
     301         585 :             ramp_flag = 1;
     302         585 :             move16();
     303             :         }
     304             : 
     305       21377 :         IF( !ppp_mode )
     306             :         {
     307             :             /* temp_buf is in Q_wb_sp
     308             :                hb_speech and the two decimator memories are in Q_wb_sp */
     309       21377 :             IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) )
     310             :             {
     311        5027 :                 Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS );
     312             : 
     313        5027 :                 IF( EQ_16( last_element_mode, IVAS_CPE_TD ) )
     314             :                 {
     315           1 :                     set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     316           1 :                     set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     317           1 :                     ramp_flag = 1;
     318           1 :                     move16();
     319             :                 }
     320             : 
     321             :                 /*Get past signal*/
     322        5027 :                 Copy_Scale_sig( hBWE_FD->L_old_wtda_swb_fx + L_FRAME16k - STEREO_DFT_OVL_16k, old_input, STEREO_DFT_OVL_16k, Q_wb_sp );
     323        5027 :                 Copy_Scale_sig( hBWE_FD->old_input_wb_fx, old_input + STEREO_DFT_OVL_16k, Sample_Delay_WB_BWE, Q_wb_sp );
     324             : 
     325             :                 /*Get new signal*/
     326        5027 :                 Copy( temp_buf, &old_input[Sample_Delay_WB_BWE + STEREO_DFT_OVL_16k], L_FRAME16k );
     327             : 
     328             :                 /*compute hb_speech on delayed input*/
     329        5027 :                 flip_spectrum_and_decimby4_fx( old_input + Sample_Delay_WB_BWE, hb_speech, L_FRAME16k, hBWE_TD->decim_state1_fx, hBWE_TD->decim_state2_fx, ramp_flag );
     330             : 
     331             :                 /*Update memory*/
     332        5027 :                 Copy_Scale_sig( hb_speech, hBWE_TD->old_speech_wb_fx + ( L_SUBFR * 5 / 16 ), STEREO_DFT_OVL_16k / 4, -Q_wb_sp );
     333        5027 :                 Copy( hb_speech + STEREO_DFT_OVL_16k / 4, hb_speech, ( L_FRAME16k - STEREO_DFT_OVL_16k ) / 4 );
     334             : 
     335             :                 /*rest without memory update*/
     336        5027 :                 Copy( hBWE_TD->decim_state1_fx, decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     337        5027 :                 Copy( hBWE_TD->decim_state2_fx, decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     338             : 
     339        5027 :                 flip_spectrum_and_decimby4_fx( old_input + Sample_Delay_WB_BWE + L_FRAME16k, hb_speech + ( L_FRAME16k - STEREO_DFT_OVL_16k ) / 4, STEREO_DFT_OVL_16k, decim_state1_fx, decim_state2_fx, 0 );
     340             :             }
     341       16350 :             ELSE IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) )
     342             :             {
     343        1232 :                 Word16 l_recalc_16k = L_MEM_RECALC_16K + L_FILT16k + 1; /* Note: "+1" is used because L_FILT16k is not divisible by 4 */
     344        1232 :                 move16();
     345        1232 :                 Word16 l_recalc_4k = ( L_MEM_RECALC_16K + L_FILT16k + 1 ) / 4;
     346        1232 :                 move16();
     347        1232 :                 Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS );
     348             : 
     349        1232 :                 IF( EQ_16( last_element_mode, IVAS_CPE_DFT ) )
     350             :                 {
     351          17 :                     set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     352          17 :                     set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     353          17 :                     ramp_flag = 1;
     354          17 :                     move16();
     355             :                 }
     356             : 
     357             :                 /*Get past signal*/
     358        1232 :                 Copy_Scale_sig( hBWE_FD->L_old_wtda_swb_fx + L_FRAME16k - l_recalc_16k, old_input, l_recalc_16k, Q_wb_sp );
     359        1232 :                 Copy_Scale_sig( hBWE_FD->old_input_wb_fx, old_input + l_recalc_16k, Sample_Delay_WB_BWE, Q_wb_sp );
     360             : 
     361             :                 /* Saturation added to prevent the crash. Needs further review */
     362        1232 :                 old_input[Sample_Delay_WB_BWE] = shl_sat( hBWE_FD->mem_old_wtda_swb_fx, Q_wb_sp );
     363             : 
     364             :                 /*Get new signal*/
     365        1232 :                 Copy( temp_buf, old_input + Sample_Delay_WB_BWE + l_recalc_16k, L_FRAME16k );
     366             : 
     367             :                 /*compute hb_speech on delayed input*/
     368        1232 :                 flip_spectrum_and_decimby4_fx( old_input + Sample_Delay_WB_BWE, hb_speech, L_FRAME16k, hBWE_TD->decim_state1_fx, hBWE_TD->decim_state2_fx, ramp_flag );
     369             : 
     370             :                 /*Update memory*/
     371        1232 :                 Copy_Scale_sig( hb_speech, hBWE_TD->old_speech_wb_fx + ( ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ) - l_recalc_4k, l_recalc_4k, -Q_wb_sp );
     372        1232 :                 Copy( hb_speech + l_recalc_4k, hb_speech, ( L_FRAME16k / 4 ) - l_recalc_4k );
     373             : 
     374             :                 /*rest without memory update*/
     375        1232 :                 Copy( hBWE_TD->decim_state1_fx, decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     376        1232 :                 Copy( hBWE_TD->decim_state2_fx, decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     377             : 
     378        1232 :                 flip_spectrum_and_decimby4_fx( old_input + Sample_Delay_WB_BWE + L_FRAME16k, hb_speech + ( L_FRAME16k / 4 ) - l_recalc_4k, l_recalc_16k, decim_state1_fx, decim_state2_fx, 0 );
     379             :             }
     380       15118 :             ELSE IF( EQ_16( st_fx->element_mode, IVAS_SCE ) )
     381             :             {
     382       15118 :                 IF( EQ_32( st_fx->input_Fs, 16000 ) )
     383             :                 {
     384           0 :                     flip_spectrum_and_decimby4_fx( temp_buf, hb_speech, L_FRAME16k, hBWE_TD->decim_state1_fx, hBWE_TD->decim_state2_fx, ramp_flag );
     385             :                 }
     386             :                 ELSE
     387             :                 {
     388       15118 :                     Word16 l_recalc_16k = L_FILT16k + 1; /* Note: "+1" is used because L_FILT16k is not divisible by 4 */
     389       15118 :                     Word16 l_recalc_4k = ( L_FILT16k + 1 ) / 4;
     390             : 
     391       15118 :                     Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS );
     392             : 
     393             :                     /*Get past signal*/
     394       15118 :                     Copy_Scale_sig( hBWE_FD->L_old_wtda_swb_fx + L_FRAME16k - l_recalc_16k, old_input, l_recalc_16k, Q_wb_sp );
     395       15118 :                     Copy_Scale_sig( hBWE_FD->old_input_wb_fx, old_input + l_recalc_16k, Sample_Delay_WB_BWE, Q_wb_sp );
     396             : 
     397             :                     /*Get new signal*/
     398       15118 :                     Copy( temp_buf, old_input + Sample_Delay_WB_BWE + l_recalc_16k, L_FRAME16k );
     399             : 
     400             :                     /*compute hb_speech on delayed input*/
     401       15118 :                     flip_spectrum_and_decimby4_fx( old_input + Sample_Delay_WB_BWE, hb_speech, L_FRAME16k, hBWE_TD->decim_state1_fx, hBWE_TD->decim_state2_fx, ramp_flag );
     402             : 
     403             :                     /* update hBWE_TD->old_speech_wb memory */
     404       15118 :                     Copy_Scale_sig( hb_speech, hBWE_TD->old_speech_wb_fx + ( ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ) - l_recalc_4k, l_recalc_4k, -Q_wb_sp );
     405       15118 :                     Copy( hb_speech + l_recalc_4k, hb_speech, ( L_FRAME16k / 4 ) - l_recalc_4k );
     406             : 
     407             :                     /*rest without memory update*/
     408       15118 :                     Copy( hBWE_TD->decim_state1_fx, decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     409       15118 :                     Copy( hBWE_TD->decim_state2_fx, decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     410             : 
     411       15118 :                     flip_spectrum_and_decimby4_fx( old_input + Sample_Delay_WB_BWE + L_FRAME16k, hb_speech + ( L_FRAME16k / 4 ) - l_recalc_4k, l_recalc_16k, decim_state1_fx, decim_state2_fx, 0 );
     412             :                 }
     413             :             }
     414             :             ELSE
     415             :             {
     416           0 :                 flip_spectrum_and_decimby4_fx( temp_buf, hb_speech, L_FRAME16k, hBWE_TD->decim_state1_fx, hBWE_TD->decim_state2_fx, ramp_flag );
     417             :             }
     418             : 
     419             :             /* rescale the hb_speech and memories back to Q-1 to keep the downstream BWE coding unaffected */
     420       21377 :             Scale_sig( hb_speech, L_FRAME16k / 4, -Q_wb_sp );
     421       21377 :             Scale_sig( hBWE_TD->decim_state1_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), -Q_wb_sp );
     422       21377 :             Scale_sig( hBWE_TD->decim_state2_fx, ( 2 * ALLPASSSECTIONS_STEEP + 1 ), -Q_wb_sp );
     423             : 
     424       21377 :             IF( NE_16( st_fx->extl, WB_TBE ) )
     425             :             {
     426             :                 /* Update the previous wideband speech buffer in case of a WB_BWE frame */
     427       13719 :                 Sample_Delay_WB_BWE = ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16;
     428             : 
     429       13719 :                 highband_new_speech = highband_old_speech + Sample_Delay_WB_BWE;
     430       13719 :                 Copy( hb_speech, highband_new_speech, L_FRAME16k / 4 );
     431       13719 :                 Copy( highband_old_speech + L_FRAME16k / 4, hBWE_TD->old_speech_wb_fx, Sample_Delay_WB_BWE );
     432             :             }
     433             :         }
     434             :     }
     435             :     ELSE
     436             :     {
     437       22337 :         set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     438       22337 :         set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     439       22337 :         set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 );
     440             :     }
     441             : 
     442       43714 :     if ( hBWE_FD != NULL )
     443             :     {
     444       43714 :         hBWE_FD->mem_old_wtda_swb_fx = new_inp_resamp16k[L_FRAME16k - L_MEM_RECALC_16K - L_FILT16k - 1];
     445       43714 :         move16();
     446             :     }
     447             : 
     448             :     /* st->old_input_wb and st->old_wtda_wb must be updated each frame, or there are often some clicks during WB TBE <-> WB BWE switching */
     449       43714 :     test();
     450       43714 :     test();
     451       43714 :     test();
     452       43714 :     IF( ( NE_16( st_fx->extl, WB_BWE ) || ( EQ_16( st_fx->extl, WB_BWE ) && EQ_32( st_fx->total_brate, 0 ) ) ) && !ppp_mode )
     453             :     {
     454       31284 :         Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS );
     455             : 
     456       31284 :         Copy( new_inp_resamp16k, &old_input[Sample_Delay_WB_BWE], L_FRAME16k );
     457       31284 :         Copy( hBWE_FD->old_input_wb_fx, old_input, Sample_Delay_WB_BWE );
     458       31284 :         Copy( new_inp_resamp16k + L_FRAME16k - Sample_Delay_WB_BWE, hBWE_FD->old_input_wb_fx, Sample_Delay_WB_BWE );
     459       31284 :         test();
     460       31284 :         IF( NE_16( st_fx->extl, SWB_BWE ) && NE_16( st_fx->extl, FB_BWE ) )
     461             :         {
     462       31284 :             Copy( old_input, hBWE_FD->L_old_wtda_swb_fx, L_FRAME16k );
     463       31284 :             st_fx->Q_old_wtda = -1;
     464       31284 :             move16();
     465             :         }
     466             :     }
     467       43714 :     return;
     468             : }
     469             : 
     470             : 
     471             : /*========================================================================*/
     472             : /* FUNCTION :  swb_pre_proc_fx()                                                                                  */
     473             : /*------------------------------------------------------------------------*/
     474             : /* PURPOSE :   Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz)                      */
     475             : /*       SHB target signal for SWB TBE or SWB BWE coding                  */
     476             : /*       Common SWB TBE and SWB BWE pre-processing                                                */
     477             : /*------------------------------------------------------------------------*/
     478             : /* INPUT ARGUMENTS :                                                                                                      */
     479             : /* Encoder_State *st_fx   : Encoder State Structure                     Q0        */
     480             : /* _ (Word16*) input_fx         : original input signal             Q0    */
     481             : /*------------------------------------------------------------------------*/
     482             : /* INPUT/OUTPUT ARGUMENTS :                                                                                               */
     483             : /* _None                                                                      */
     484             : /*------------------------------------------------------------------------*/
     485             : /* OUTPUT ARGUMENTS :                                                                                                     */
     486             : /* _ (Word16*) new_swb_speech_fx : original input signal at 16kHz    Q0   */
     487             : /* _ (Word16*) shb_speech_fx     : original input signal at 16kHz    Q0   */
     488             : /*------------------------------------------------------------------------*/
     489             : 
     490             : /* st_fx->old_input_fx                                                                                                         */
     491             : /* st_fx->old_wtda_shb_fx                                                 */
     492             : /*------------------------------------------------------------------------*/
     493             : /* RETURN ARGUMENTS :                                                                                                     */
     494             : /* _ None                                                                                                                                 */
     495             : /*========================================================================*/
     496             : 
     497        3100 : void swb_pre_proc_fx(
     498             :     Encoder_State *st_fx,      /* i/o: encoder state structure                */
     499             :     const Word16 *input_fx,    /* i  : original input signal                  */
     500             :     Word16 *new_swb_speech_fx, /* o  : original input signal at 32kHz         */
     501             :     Word16 *shb_speech_fx,     /* o  : SHB target signal (6-14kHz) at 16kHz   */
     502             :     Word16 *Q_shb_spch,
     503             :     Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real CLDFB buffer for target synthesis */
     504             :     Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag CLDFB buffer for target synthesis */
     505             :     const CLDFB_SCALE_FACTOR *cldfbScale                        /* i : scale data of real and imag CLDFB buffers */
     506             : )
     507             : {
     508             :     Word16 Sample_Delay_SWB_BWE, delay;
     509             :     Word16 inner_frame;
     510             :     UWord16 inner_Fs;
     511             :     Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k];
     512             :     Word16 spchTmp_fx[L_FRAME32k];
     513             :     Word16 i;
     514             :     Word16 startB, endB;
     515             :     Word16 j;
     516             :     Word32 *realBufferFlipped[CLDFB_NO_COL_MAX];
     517             :     Word32 *imagBufferFlipped[CLDFB_NO_COL_MAX];
     518             :     Word32 realBufferTmp[CLDFB_NO_COL_MAX][20];
     519             :     Word32 imagBufferTmp[CLDFB_NO_COL_MAX][20];
     520             :     Word32 cldfbWorkBuffer[256];
     521             :     Word16 ts, nB, uB;
     522             :     /* Highband energy computation using CLDFB */
     523             :     Word32 CldfbHB_ener;
     524             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     525        3100 :     Flag Overflow = 0;
     526        3100 :     move16();
     527             : #endif
     528             :     Word16 realQ_neg1, imagQ_neg1, exp, Cldfbtemp1;
     529        3100 :     TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD;
     530        3100 :     FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD;
     531             : 
     532       52700 :     FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ )
     533             :     {
     534       49600 :         set32_fx( realBufferTmp[j], 0, 20 );
     535       49600 :         set32_fx( imagBufferTmp[j], 0, 20 );
     536       49600 :         realBufferFlipped[j] = realBufferTmp[j];
     537       49600 :         imagBufferFlipped[j] = imagBufferTmp[j];
     538             :     }
     539             : 
     540        3100 :     set16_fx( old_input_fx, 0, NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k );
     541             : 
     542        3100 :     IF( EQ_32( st_fx->input_Fs, 32000 ) )
     543             :     {
     544        1050 :         Copy( input_fx, new_swb_speech_fx, L_FRAME32k ); /*Q0 */
     545        1050 :         test();
     546        1050 :         test();
     547        1050 :         IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) )
     548             :         {
     549        1042 :             Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS );
     550        1042 :             Copy( hBWE_FD->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k );
     551        1042 :             set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE );
     552        1042 :             Copy( hBWE_FD->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE );
     553             : 
     554        1042 :             IF( sub( st_fx->extl, WB_BWE ) != 0 )
     555             :             {
     556        1042 :                 Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, L_FRAME32k );
     557             :             }
     558             :         }
     559             : 
     560        1050 :         test();
     561        1050 :         IF( NE_16( st_fx->extl, SWB_BWE ) && NE_16( st_fx->extl, FB_BWE ) )
     562             :         {
     563        1042 :             Copy( input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k );
     564             :         }
     565             :     }
     566             :     ELSE /* 48 kHz */
     567             :     {
     568             :         /* 48kHz sampled processing needs review of FD2 memory handling/Q-factors */
     569        2050 :         IF( EQ_16( st_fx->codec_mode, MODE1 ) )
     570             :         {
     571        1066 :             test();
     572        1066 :             test();
     573        1066 :             IF( NE_16( st_fx->extl, SWB_BWE ) && NE_16( st_fx->extl, FB_BWE ) && EQ_16( st_fx->core, ACELP_CORE ) )
     574             :             {
     575             :                 /* move the resampling out of the TDBWE path as new_swb_speech is not needed for TDBWE. */
     576         674 :                 Copy( input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k );
     577             :             }
     578             :             ELSE
     579             :             {
     580         392 :                 test();
     581         392 :                 IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) )
     582             :                 {
     583             :                     /* resample 48 kHz to 32kHz */
     584             : #ifdef NONBE_1244_FIX_SWB_BWE_MEMORY
     585         392 :                     IF( ( st_fx->last_bwidth == FB && st_fx->element_mode == EVS_MONO ) || ( EQ_16( st_fx->bwidth, FB ) && st_fx->element_mode > EVS_MONO ) ) // note: once EVS i CR fixed, the condition will simplify to "if ( st->bwidth == FB )" only
     586             : #else
     587             :                     IF( EQ_16( st_fx->last_bwidth, FB ) )
     588             : #endif
     589             :                     {
     590           0 :                         inner_frame = L_FRAME48k;
     591           0 :                         inner_Fs = 48000;
     592           0 :                         Copy( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech_fx, L_FRAME48k );
     593             :                     }
     594             :                     ELSE
     595             :                     {
     596         392 :                         inner_frame = L_FRAME32k;
     597         392 :                         inner_Fs = 32000;
     598         392 :                         decimate_2_over_3_allpass_fx( hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2,
     599         392 :                                                       decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
     600             :                     }
     601         392 :                     move16();
     602         392 :                     move16();
     603             : 
     604         392 :                     Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS );
     605         392 :                     Copy( new_swb_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], inner_frame );
     606         392 :                     set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE );
     607         392 :                     Copy( new_swb_speech_fx + inner_frame - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE );
     608         392 :                     Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, inner_frame );
     609         392 :                     st_fx->Q_old_wtda = 0;
     610         392 :                     move16();
     611             :                 }
     612             :                 /* resample 48 kHz to 32kHz */
     613         392 :                 IF( EQ_16( st_fx->bwidth, FB ) )
     614             :                 {
     615           0 :                     Copy( input_fx, new_swb_speech_fx, L_FRAME48k );
     616             :                 }
     617             :                 ELSE
     618             :                 {
     619         392 :                     decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2,
     620         392 :                                                   decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
     621             :                 }
     622             :             }
     623             :         }
     624             :         ELSE
     625             :         {
     626             :             /* resample 48 kHz to 32kHz */
     627         984 :             IF( EQ_16( st_fx->bwidth, FB ) )
     628             :             {
     629           0 :                 Copy( input_fx, new_swb_speech_fx, L_FRAME48k );
     630             :             }
     631             :             ELSE
     632             :             {
     633         984 :                 decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2,
     634         984 :                                               decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
     635             :             }
     636             :         }
     637             :     }
     638             : 
     639        3100 :     test();
     640        3100 :     test();
     641        3100 :     test();
     642        3100 :     test();
     643        3100 :     test();
     644        3100 :     IF( ( st_fx->core == ACELP_CORE && NE_16( st_fx->extl, SWB_BWE_HIGHRATE ) && NE_16( st_fx->extl, FB_BWE_HIGHRATE ) ) || ( ( EQ_32( st_fx->total_brate, 9600 ) || st_fx->rf_mode != 0 ) && EQ_16( st_fx->bwidth, SWB ) ) )
     645             :     {
     646        1361 :         IF( EQ_16( st_fx->L_frame, L_FRAME ) )
     647             :         {
     648         749 :             startB = 34;
     649         749 :             move16();
     650         749 :             endB = 14;
     651         749 :             move16();
     652       12733 :             FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
     653             :             {
     654       11984 :                 uB = 0;
     655       11984 :                 move16();
     656      251664 :                 FOR( nB = startB; nB > endB; nB-- )
     657             :                 {
     658      239680 :                     realBufferFlipped[ts][uB] = realBuffer[ts][nB];
     659      239680 :                     move32();
     660      239680 :                     if ( s_and( ts, 1 ) != 0 )
     661             :                     {
     662      119840 :                         realBufferFlipped[ts][uB] = L_negate( realBufferFlipped[ts][uB] );
     663      119840 :                         move32();
     664             :                     }
     665      239680 :                     imagBufferFlipped[ts][uB] = imagBuffer[ts][nB];
     666      239680 :                     move32();
     667      239680 :                     if ( s_and( ts, 1 ) == 0 )
     668             :                     {
     669      119840 :                         imagBufferFlipped[ts][uB] = L_negate( imagBufferFlipped[ts][uB] );
     670      119840 :                         move32();
     671             :                     }
     672      239680 :                     uB = add( uB, 1 ); /* uB ++ */
     673             :                 }
     674             :             }
     675             :         }
     676             :         ELSE
     677             :         {
     678         612 :             startB = 39;
     679         612 :             move16();
     680         612 :             endB = 19;
     681         612 :             move16();
     682       10404 :             FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
     683             :             {
     684        9792 :                 uB = 0;
     685        9792 :                 move16();
     686      205632 :                 FOR( nB = startB; nB > endB; nB-- )
     687             :                 {
     688      195840 :                     realBufferFlipped[ts][uB] = L_negate( realBuffer[ts][nB] );
     689      195840 :                     move32();
     690      195840 :                     imagBufferFlipped[ts][uB] = imagBuffer[ts][nB];
     691      195840 :                     move32();
     692      195840 :                     uB = add( uB, 1 ); /* uB ++ */
     693             :                 }
     694             :             }
     695             :         }
     696             : 
     697             :         /* Highband energy computation for gain shape control in case of bandwidth switching fix*/
     698             :         {
     699        1361 :             CldfbHB_ener = 0;
     700        1361 :             move32();
     701       14971 :             FOR( nB = 0; nB < 10; nB++ )
     702             :             {
     703      231370 :                 FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
     704             :                 {
     705      217760 :                     realQ_neg1 = extract_l( L_shr( realBufferFlipped[ts][nB], 31 - ( 15 + cldfbScale->hb_scale ) + 1 ) );
     706      217760 :                     imagQ_neg1 = extract_l( L_shr( imagBufferFlipped[ts][nB], 31 - ( 15 + cldfbScale->hb_scale ) + 1 ) ); /* Q(-1), headroom needed */
     707             : 
     708      217760 :                     CldfbHB_ener = L_mac0_o( CldfbHB_ener, realQ_neg1, realQ_neg1, &Overflow );
     709      217760 :                     CldfbHB_ener = L_mac0_o( CldfbHB_ener, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */
     710             :                 }
     711             :             }
     712             : 
     713        1361 :             exp = norm_l( CldfbHB_ener );
     714        1361 :             CldfbHB_ener = L_shl( CldfbHB_ener, exp ); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */
     715        1361 :             Cldfbtemp1 = ( Log2_norm_lc( CldfbHB_ener ) );
     716        1361 :             Cldfbtemp1 = add( shr( Cldfbtemp1, 6 ), shl( sub( 30, sub( exp, 2 ) ), 9 ) );      /* Log2_norm_lc(CldfbHB_ener) = 2^15*(log2(CldfbHB_ener/2^30)) = 2^15*(log2(CldfbHB_fl*(2^-2)*2^exp/2^30)) = 2^15*(log2(CldfbHB_fl) + exp-2-30) => 2^(-6)*l2nc + 2^9(20-(exp-2)) = 2^9*log2(CldfbHB_fl), Q9 */
     717        1361 :             CldfbHB_ener = L_mult( sub( Cldfbtemp1, 1741 /*3.401 Q9*/ ), 3495 );               /* 3495 = Q19 log10(2)*0.1/log10(32768), Q = 19+9+1 = 29 */
     718        1361 :             hBWE_TD->cldfbHBLT = mac_r( CldfbHB_ener, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */
     719             :         }
     720        1361 :         cldfbSynthesis_fx( st_fx->cldfbSynTd, realBufferFlipped, imagBufferFlipped, cldfbScale, shb_speech_fx, 0, CLDFB_NO_COL_MAX, cldfbWorkBuffer );
     721        1361 :         *Q_shb_spch = 0; /*shb_speech_fx : Q0*/
     722        1361 :         move16();
     723             : 
     724        1361 :         test();
     725        1361 :         test();
     726        1361 :         IF( NE_16( st_fx->extl, WB_TBE ) && NE_16( st_fx->extl, SWB_TBE ) && NE_16( st_fx->extl, FB_TBE ) )
     727             :         {
     728             :             /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */
     729           8 :             delay = L_LOOK_16k + L_SUBFR16k;
     730           8 :             Copy( shb_speech_fx + L_FRAME16k - delay, hBWE_TD->old_speech_shb_fx, delay );
     731             :         }
     732             :     }
     733             :     ELSE
     734             :     {
     735        1739 :         test();
     736        1739 :         IF( EQ_16( st_fx->bwidth, FB ) || EQ_16( st_fx->core, ACELP_CORE ) )
     737             :         {
     738         674 :             set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k );
     739         674 :             set16_fx( shb_speech_fx, 0, L_FRAME16k ); /* shb_speech for FB/SWB BWE_HIGHRATE is not used at 64kbps */
     740             :         }
     741             :         ELSE
     742             :         {
     743             :             /* flip the spectrm */
     744        1065 :             Copy( new_swb_speech_fx, spchTmp_fx, L_FRAME32k );
     745             : 
     746      341865 :             FOR( i = 0; i < L_FRAME32k; i = i + 2 )
     747             :             {
     748      340800 :                 spchTmp_fx[i] = negate( spchTmp_fx[i] );
     749      340800 :                 move16();
     750             :             }
     751             : 
     752        1065 :             Decimate_allpass_steep_fx( spchTmp_fx, hBWE_TD->state_ana_filt_shb_fx, L_FRAME32k, shb_speech_fx );
     753        1065 :             Copy( shb_speech_fx + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k );
     754             :         }
     755             : 
     756             :         /* Reset CLDFB synthesis buffer */
     757        1739 :         set16_fx( st_fx->cldfbSynTd->FilterStates, 0, st_fx->cldfbSynTd->p_filter_length + st_fx->cldfbSynTd->no_channels * st_fx->cldfbSynTd->no_col );
     758             :     }
     759        3100 :     IF( EQ_16( st_fx->last_extl, -1 ) )
     760             :     {
     761         429 :         delay = NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS );
     762       19164 :         FOR( i = 0; i < delay; i++ )
     763             :         {
     764       18735 :             shb_speech_fx[i] = mult_r( mult_r( i, 983 /*0.03f Q15*/ ), shb_speech_fx[2 * delay - 1 - i] );
     765       18735 :             move16();
     766             :         }
     767             :     }
     768             : 
     769        3100 :     return;
     770             : }
     771             : 
     772             : /*-------------------------------------------------------------------*
     773             :  * swb_pre_proc()
     774             :  *
     775             :  * - Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB target signal
     776             :  *   for SWB TBE or SWB BWE coding
     777             :  * - Common SWB TBE and SWB BWE pre-processing
     778             :  *-------------------------------------------------------------------*/
     779             : 
     780             : /*full implementation pending*/
     781      396042 : void swb_pre_proc_ivas_fx(
     782             :     Encoder_State *st,         /* i/o: encoder state structure                  */
     783             :     Word16 *new_swb_speech,    /* o  : original input signal at 32kHz - st->q_inp      */
     784             :     Word32 *new_swb_speech_fx, /* o  : original input signal at 32kHz - Q - q_reImBuffer */
     785             :     Word16 *shb_speech,        /* o  : SHB target signal (6-14kHz) at 16kHz- Q(Q_shb_spch) */
     786             :     Word16 *Q_shb_spch,
     787             :     Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i  : real buffer Q - q_reImbuffer             */
     788             :     Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i  : imag buffer Q - q_reImbuffer             */
     789             :     Word16 q_reImBuffer,                                        /* i : scale data of real and imag CLDFB buffers */
     790             :     CPE_ENC_HANDLE hCPE                                         /* i/o: CPE encoder structure                    */
     791             : )
     792             : {
     793             :     Word16 Sample_Delay_SWB_BWE, inner_frame, delay;
     794             :     TD_BWE_ENC_HANDLE hBWE_TD;
     795             :     FD_BWE_ENC_HANDLE hBWE_FD;
     796             :     Word32 inner_Fs, input_Fs;
     797             :     Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k];    // fixed counterpart
     798             :     Word32 old_input_fx_32[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; // fixed counterpart
     799             :     Word16 spchTmp[L_FRAME32k], spchTmp2[L_FRAME32k];
     800             :     Word16 i, j, L_resamp;
     801             :     Word16 startB, endB;
     802             :     Word32 *realBufferFlipped[CLDFB_NO_COL_MAX];
     803             :     Word32 *imagBufferFlipped[CLDFB_NO_COL_MAX];
     804             :     Word32 realBufferTmp[CLDFB_NO_COL_MAX][20];
     805             :     Word32 imagBufferTmp[CLDFB_NO_COL_MAX][20];
     806             :     Word32 shb_speech_fx_32[L_FRAME16k];
     807             :     Word16 ts, nB, uB;
     808             :     Word32 v, t, regression;
     809             :     Word16 t_16;
     810             :     const Word32 *thr, *regV;
     811             :     Word32 lbEner;
     812      396042 :     Word16 exp_lbEner = 0;
     813             :     Word16 Sample_Delay_SWB_BWE32k, lMemRecalc32k, dft_ovl32k;
     814      396042 :     Word32 one_by_50_Q31 = 42949673;
     815             : 
     816      396042 :     lMemRecalc32k = NS2SA( 32000, L_MEM_RECALC_NS );
     817      396042 :     move16(); // exp_lbEner
     818      396042 :     move16(); // lMemRecalc32k
     819      396042 :     move32(); // one_by_50_Q31
     820             : 
     821             :     /* initialization */
     822      396042 :     hBWE_TD = st->hBWE_TD;
     823      396042 :     hBWE_FD = st->hBWE_FD;
     824      396042 :     input_Fs = st->input_Fs;
     825             : 
     826     6732714 :     FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ )
     827             :     {
     828     6336672 :         set32_fx( realBufferTmp[j], 0, 20 );
     829     6336672 :         set32_fx( imagBufferTmp[j], 0, 20 );
     830     6336672 :         realBufferFlipped[j] = realBufferTmp[j];
     831     6336672 :         imagBufferFlipped[j] = imagBufferTmp[j];
     832             :     }
     833             : 
     834      396042 :     set16_fx( old_input_fx, 0, NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k );
     835             : 
     836      396042 :     IF( EQ_32( st->input_Fs, 32000 ) )
     837             :     {
     838       57471 :         IF( st->element_mode > EVS_MONO )
     839             :         {
     840       57471 :             Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_12k8_NS );
     841       57471 :             IF( EQ_16( st->L_frame, L_FRAME16k ) )
     842             :             {
     843       32465 :                 Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_16k_NS );
     844             :             }
     845             : 
     846       57471 :             Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE );
     847       57471 :             Copy( st->input_fx - L_FRAME32k, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k );
     848             : 
     849       57471 :             test();
     850       57471 :             test();
     851       57471 :             scale_sig( hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( st->q_inp, st->Q_old_wtda ) ); // st->Q_old_wtda -> st->q_inp
     852       57471 :             st->Q_old_wtda = st->q_inp;
     853       57471 :             move16();
     854       57471 :             IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && GE_16( st->bwidth, SWB ) )
     855             :             {
     856        3975 :                 Copy( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ) );
     857             :             }
     858       53496 :             ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) )
     859             :             {
     860       26882 :                 Copy( st->input_fx - hCPE->hStereoDft->dft_ovl, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( hCPE->hStereoDft->dft_ovl, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoDft->dft_ovl, Sample_Delay_SWB_BWE ) );
     861             :             }
     862             :         }
     863             : 
     864       57471 :         Copy( st->input_fx, new_swb_speech, L_FRAME32k );
     865             : 
     866       57471 :         test();
     867       57471 :         test();
     868       57471 :         IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) && NE_16( st->extl, SWB_BWE_HIGHRATE ) )
     869             :         {
     870       56667 :             Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS );
     871       56667 :             test();
     872       56667 :             IF( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) )
     873             :             {
     874       32337 :                 Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS );
     875             :             }
     876       56667 :             IF( st->element_mode > EVS_MONO )
     877             :             {
     878       56667 :                 Sample_Delay_SWB_BWE = sub( Sample_Delay_SWB_BWE, NS2SA( 32000, DELAY_FIR_RESAMPL_NS ) );
     879             :             }
     880             : 
     881       56667 :             Copy( hBWE_FD->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k );
     882             : 
     883       56667 :             set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE );
     884       56667 :             Copy( hBWE_FD->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE );
     885       56667 :             IF( NE_16( st->extl, WB_BWE ) )
     886             :             {
     887       56631 :                 Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, L_FRAME32k );
     888       56631 :                 st->Q_old_wtda = st->q_inp;
     889       56631 :                 move16();
     890             :             }
     891             :         }
     892             : 
     893       57471 :         test();
     894       57471 :         IF( NE_16( st->extl, SWB_BWE ) && NE_16( st->extl, FB_BWE ) )
     895             :         {
     896       56659 :             Copy( st->input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME32k );
     897             :         }
     898             :     }
     899             :     ELSE /* 48 kHz */
     900             :     {
     901             : 
     902      338571 :         Sample_Delay_SWB_BWE32k = NS2SA( 32000, DELAY_FD_BWE_ENC_12k8_NS );
     903      338571 :         move16();
     904      338571 :         Sample_Delay_SWB_BWE = NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS );
     905      338571 :         move16();
     906      338571 :         IF( EQ_16( st->L_frame, L_FRAME16k ) )
     907             :         {
     908      119109 :             Sample_Delay_SWB_BWE32k = NS2SA( 32000, DELAY_FD_BWE_ENC_16k_NS );
     909      119109 :             move16();
     910      119109 :             Sample_Delay_SWB_BWE = NS2SA( 48000, DELAY_FD_BWE_ENC_16k_NS );
     911      119109 :             move16();
     912             :         }
     913             : 
     914      338571 :         dft_ovl32k = 0;
     915      338571 :         move16();
     916      338571 :         IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
     917             :         {
     918       20888 :             dft_ovl32k = (Word16) ( STEREO_DFT_OVL_MAX * 32000 / 48000 );
     919       20888 :             move16();
     920             :         }
     921             : 
     922      338571 :         IF( EQ_16( st->codec_mode, MODE1 ) )
     923             :         {
     924      338571 :             IF( st->element_mode > EVS_MONO )
     925             :             {
     926             : 
     927      338571 :                 IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
     928             :                 {
     929             :                 }
     930      336541 :                 ELSE IF( EQ_16( st->bwidth, FB ) )
     931             :                 {
     932      210256 :                     Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE );
     933             :                 }
     934             : 
     935      338571 :                 Copy( st->input_fx - L_FRAME48k, hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k );
     936             : 
     937      338571 :                 test();
     938      338571 :                 test();
     939      338571 :                 scale_sig( hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( st->q_inp, st->Q_old_wtda ) ); // st->Q_old_wtda -> st->q_inp
     940      338571 :                 st->Q_old_wtda = st->q_inp;
     941      338571 :                 move16();
     942             : 
     943      338571 :                 IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && GE_16( st->bwidth, SWB ) )
     944             :                 {
     945        1912 :                     IF( EQ_16( st->bwidth, SWB ) )
     946             :                     {
     947             :                         /* buffers hBWE_FD->old_input[] and hBWE_FD->old_wtda_swb[] need to be at 32 kHz (inner) sampling rate */
     948             : 
     949         439 :                         decimate_2_over_3_allpass_fx( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hCPE->hStereoTCA->lMemRecalc, spchTmp, hBWE_TD->dec_2_over_3_mem_fx,
     950         439 :                                                       allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
     951             : 
     952         439 :                         Copy( spchTmp, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - sub( lMemRecalc32k, Sample_Delay_SWB_BWE32k ), sub( lMemRecalc32k, Sample_Delay_SWB_BWE32k ) );
     953         439 :                         Copy( spchTmp + lMemRecalc32k - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k );
     954             :                     }
     955             :                     ELSE /* FB_BWE */
     956             :                     {
     957        1473 :                         Copy( st->input_fx - hCPE->hStereoTCA->lMemRecalc, hBWE_FD->L_old_wtda_swb_fx + L_FRAME48k - sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ), sub( hCPE->hStereoTCA->lMemRecalc, Sample_Delay_SWB_BWE ) );
     958        1473 :                         Copy( st->input_fx - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE );
     959             :                     }
     960             :                 }
     961      336659 :                 ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) )
     962             :                 {
     963       19874 :                     IF( EQ_16( st->bwidth, SWB ) )
     964             :                     {
     965       10046 :                         lerp( st->input_fx - hCPE->hStereoDft->dft_ovl, spchTmp, dft_ovl32k - Sample_Delay_SWB_BWE32k, hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE );
     966             : 
     967       10046 :                         Copy( spchTmp, hBWE_FD->L_old_wtda_swb_fx + L_FRAME32k - ( dft_ovl32k - Sample_Delay_SWB_BWE32k ), dft_ovl32k - Sample_Delay_SWB_BWE32k );
     968             :                     }
     969             :                     ELSE
     970             :                     {
     971        9828 :                         Copy( st->input_fx - hCPE->hStereoDft->dft_ovl, hBWE_FD->L_old_wtda_swb_fx + L_FRAME48k - ( hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE ), hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE );
     972             :                     }
     973             :                 }
     974             :             }
     975             : 
     976      338571 :             test();
     977      338571 :             test();
     978      338571 :             test();
     979      338571 :             test();
     980      338571 :             IF( ( NE_16( st->extl, SWB_BWE ) && NE_16( st->extl, FB_BWE ) && ( st->core == ACELP_CORE ) ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && ( st->core != ACELP_CORE ) ) /*resampling not needed for MDCT cores*/ )
     981             :             {
     982             :                 /* move the resampling out of the TDBWE path as new_swb_speech is not needed for TDBWE. */
     983      114926 :                 Copy( st->input_fx, hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k );
     984             :             }
     985             :             ELSE
     986             :             {
     987      223645 :                 test();
     988      223645 :                 IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) )
     989             :                 {
     990             :                     /* resample 48 kHz to 32kHz */
     991             : #ifdef NONBE_1244_FIX_SWB_BWE_MEMORY
     992      213722 :                     IF( ( st->last_bwidth == FB && st->element_mode == EVS_MONO ) || ( EQ_16( st->bwidth, FB ) && st->element_mode > EVS_MONO ) ) // note: once EVS i CR fixed, the condition will simplify to "if ( st->bwidth == FB )" only
     993             : #else
     994             :                     IF( EQ_16( st->last_bwidth, FB ) )
     995             : #endif
     996             :                     {
     997      157946 :                         inner_frame = L_FRAME48k;
     998      157946 :                         move16();
     999      157946 :                         inner_Fs = 48000;
    1000      157946 :                         move32();
    1001      157946 :                         Copy( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech, L_FRAME48k );
    1002             :                     }
    1003             :                     ELSE
    1004             :                     {
    1005       55776 :                         inner_frame = L_FRAME32k;
    1006       55776 :                         move16();
    1007       55776 :                         inner_Fs = 32000;
    1008       55776 :                         move32();
    1009             : 
    1010       55776 :                         IF( NE_16( st->element_mode, IVAS_CPE_DFT ) )
    1011             :                         {
    1012       55561 :                             decimate_2_over_3_allpass_fx( hBWE_FD->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
    1013             :                         }
    1014             :                         ELSE
    1015             :                         {
    1016         215 :                             lerp( hBWE_FD->old_fdbwe_speech_fx, new_swb_speech, inner_frame, L_FRAME48k );
    1017             :                         }
    1018             : 
    1019       55776 :                         test();
    1020       55776 :                         IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->idchan == 0 )
    1021             :                         {
    1022       60415 :                             FOR( i = 0; i < STEREO_DFT_OVL_32k; i++ )
    1023             :                             {
    1024       60200 :                                 hCPE->hStereoDft->output_mem_dmx_32k_fx[i] = L_shr( Mpy_32_16_1( hCPE->hStereoDft->win_32k_fx[STEREO_DFT_OVL_32k - 1 - i], new_swb_speech[( ( inner_frame + i ) - STEREO_DFT_OVL_32k )] ), 1 ); // Q15
    1025       60200 :                                 move32();
    1026             :                             }
    1027             :                         }
    1028             :                     }
    1029             : 
    1030      213722 :                     Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS );
    1031      213722 :                     move16();
    1032      213722 :                     test();
    1033      213722 :                     IF( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) )
    1034             :                     {
    1035       60952 :                         Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS );
    1036       60952 :                         move16();
    1037             :                     }
    1038      213722 :                     IF( st->element_mode > EVS_MONO )
    1039             :                     {
    1040      213722 :                         Sample_Delay_SWB_BWE = sub( Sample_Delay_SWB_BWE, NS2SA_FX2( inner_Fs, DELAY_FIR_RESAMPL_NS ) );
    1041             :                     }
    1042             : 
    1043      213722 :                     Copy( new_swb_speech, &old_input_fx[Sample_Delay_SWB_BWE], inner_frame );
    1044      213722 :                     set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE );
    1045      213722 :                     Copy( new_swb_speech + inner_frame - Sample_Delay_SWB_BWE, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE );
    1046      213722 :                     Copy( old_input_fx, hBWE_FD->L_old_wtda_swb_fx, inner_frame );
    1047      213722 :                     st->Q_old_wtda = st->q_inp;
    1048      213722 :                     move16();
    1049             :                 }
    1050             : 
    1051             :                 /* resample 48 kHz to 32kHz */
    1052      223645 :                 IF( EQ_16( st->bwidth, FB ) )
    1053             :                 {
    1054      162542 :                     Copy( st->input_fx, new_swb_speech, L_FRAME48k );
    1055             :                 }
    1056             :                 ELSE
    1057             :                 {
    1058       61103 :                     IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
    1059             :                     {
    1060             :                         Word16 dec_2_over_3_mem_tmp[L_FILT_2OVER3], dec_2_over_3_mem_lp_tmp[L_FILT_2OVER3_LP];
    1061             : 
    1062          16 :                         decimate_2_over_3_allpass_fx( st->input_fx, L_FRAME48k - hCPE->hStereoTCA->lMemRecalc, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
    1063             : 
    1064          16 :                         Copy( hBWE_TD->dec_2_over_3_mem_fx, dec_2_over_3_mem_tmp, L_FILT_2OVER3 );
    1065          16 :                         Copy( hBWE_TD->dec_2_over_3_mem_lp_fx, dec_2_over_3_mem_lp_tmp, L_FILT_2OVER3_LP );
    1066             : 
    1067          16 :                         decimate_2_over_3_allpass_fx( st->input_fx + L_FRAME48k - hCPE->hStereoTCA->lMemRecalc, hCPE->hStereoTCA->lMemRecalc, new_swb_speech + L_FRAME32k - lMemRecalc32k, dec_2_over_3_mem_tmp, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, dec_2_over_3_mem_lp_tmp );
    1068             :                     }
    1069       61087 :                     ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) )
    1070             :                     {
    1071       59583 :                         decimate_2_over_3_allpass_fx( st->input_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
    1072             :                     }
    1073             :                     ELSE /* IVAS_CPE_DFT */
    1074             :                     {
    1075             :                         Word16 out_start_ind, out_end_ind;
    1076        1504 :                         stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL );
    1077        1504 :                         Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, L_FRAME48k + STEREO_DFT_OVL_MAX, add( st->q_inp, add( q_reImBuffer, 1 ) ) ); // st->q_inp
    1078             : 
    1079        1504 :                         Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); // st->q_inp
    1080             :                     }
    1081             :                 }
    1082             :             }
    1083             :         }
    1084             :         ELSE
    1085             :         {
    1086             :             /* resample 48 kHz to 32kHz */
    1087           0 :             IF( EQ_16( st->bwidth, FB ) )
    1088             :             {
    1089           0 :                 Copy( st->input_fx, new_swb_speech, L_FRAME48k );
    1090             :             }
    1091             :             ELSE
    1092             :             {
    1093           0 :                 decimate_2_over_3_allpass_fx( st->input_fx, L_FRAME48k, new_swb_speech, hBWE_TD->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, decimate_3_ov_2_lowpass_num_fx, decimate_3_ov_2_lowpass_den_fx, hBWE_TD->dec_2_over_3_mem_lp_fx );
    1094             :             }
    1095             :         }
    1096             :     }
    1097             : 
    1098      396042 :     test();
    1099      396042 :     test();
    1100      396042 :     test();
    1101      396042 :     test();
    1102      396042 :     test();
    1103      396042 :     test();
    1104      396042 :     IF( ( ( st->core == ACELP_CORE ) && NE_16( st->extl, SWB_BWE_HIGHRATE ) && NE_16( st->extl, FB_BWE_HIGHRATE ) ) ||
    1105             :         ( ( EQ_32( st->total_brate, ACELP_9k60 ) || st->rf_mode ) && EQ_16( st->bwidth, SWB ) && ( st->element_mode == EVS_MONO ) ) )
    1106      157409 :     {
    1107      157409 :         Word64 CldfbHB64_fx = 0;
    1108      157409 :         move64();
    1109      157409 :         Word32 CldfbHB_fx = 0;   // fixed counterpart
    1110      157409 :         Word16 CldfbHB_fx_e = 0; // fixed counterpart
    1111             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
    1112      157409 :         Flag Overflow = 0;
    1113      157409 :         move16();
    1114             : #endif
    1115      157409 :         Word16 realQ_neg1, imagQ_neg1, exp = 0, Cldfbtemp1;
    1116      157409 :         move32();
    1117      157409 :         move16();
    1118      157409 :         move16();
    1119             : 
    1120      157409 :         IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
    1121             :         {
    1122             :             Word16 out_start_ind, out_end_ind;
    1123             :             Word16 exp_icbweRefEner_fx;
    1124       35774 :             Copy_Scale_sig_16_32_DEPREC( (const Word16 *) &old_input_fx[0], &old_input_fx_32[0], NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k, Q15 ); // Q15
    1125       35774 :             CldfbHB_fx = stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, old_input_fx_32 + STEREO_DFT_OVL_16k, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 16000, st->L_frame, &CldfbHB_fx_e );
    1126       35774 :             Copy_Scale_sig_32_16( (const Word32 *) &old_input_fx_32[0], &old_input_fx[0], NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k, -Q15 ); // Q0
    1127             : 
    1128             :             /* delay corresponding to CLDFB delay */
    1129       35774 :             Copy( old_input_fx + STEREO_DFT_OVL_16k - 20, shb_speech, L_FRAME16k );
    1130       35774 :             Copy( old_input_fx, hBWE_TD->old_speech_shb_fx + L_LOOK_16k + L_SUBFR16k - ( STEREO_DFT_OVL_16k - 20 ), STEREO_DFT_OVL_16k - 20 );
    1131       35774 :             Copy( old_input_fx, hCPE->hStereoICBWE->mem_shb_speech_ref_fx, STEREO_DFT_OVL_16k - 20 ); // Q0
    1132       35774 :             hCPE->hStereoICBWE->mem_shb_speech_ref_e = 15;
    1133       35774 :             move16();
    1134             : 
    1135       35774 :             IF( LE_32( CldfbHB_fx, 0 ) )
    1136             :             {
    1137        1090 :                 CldfbHB_fx = EPSILON_FX;
    1138        1090 :                 move32();
    1139             :             }
    1140       35774 :             CldfbHB_fx = L_shl( CldfbHB_fx, exp );   /* CldfbHB_ener = CldfbHB_fl*2^(exp) */
    1141       35774 :             Cldfbtemp1 = Log2_norm_lc( CldfbHB_fx ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */
    1142       35774 :             Cldfbtemp1 = sub( shr( Cldfbtemp1, 6 ), shl( add( sub( Q31 - Q30, CldfbHB_fx_e ), exp ), 9 ) );
    1143       35774 :             CldfbHB_fx = L_mult( Cldfbtemp1, 9864 ); /* Q9 + Q15 + Q1 = Q25 */
    1144       35774 :             CldfbHB_fx = Mpy_32_16_1( L_sub( CldfbHB_fx, 1 << Q25 ), 11611 /* 0.1 * 0.221462 in Q19 */ );
    1145             :             /* Resulting Q = Q25 + Q19 - Q15 = Q29 */
    1146       35774 :             hBWE_TD->cldfbHBLT = mac_r( CldfbHB_fx, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */
    1147       35774 :             move16();
    1148             : 
    1149       35774 :             exp_lbEner = hCPE->hStereoDft->lbEner_fx_e;
    1150       35774 :             move32();
    1151       35774 :             lbEner = Mpy_32_16_1( Sqrt32( hCPE->hStereoDft->lbEner_fx, &exp_lbEner ), 1638 /* 0.05 in Q15 */ );
    1152       35774 :             exp_icbweRefEner_fx = hCPE->hStereoDft->icbweRefEner_fx_e;
    1153       35774 :             move16();
    1154       35774 :             hCPE->hStereoICBWE->icbweRefEner_fx = Mpy_32_16_1( Sqrt32( hCPE->hStereoDft->icbweRefEner_fx, &exp_icbweRefEner_fx ), 1638 /* 0.05 in Q15 */ );
    1155       35774 :             move32();
    1156       35774 :             hCPE->hStereoICBWE->icbweRefEner_fx_e = exp_icbweRefEner_fx;
    1157       35774 :             move16();
    1158             :             // lbEner = 0.05f * (float) sqrt( hCPE->hStereoDft->lbEner );
    1159       35774 :             thr = icbwe_thr_DFT_fx;
    1160       35774 :             regV = icbwe_regressionValuesDFT_fx;
    1161             :         }
    1162             :         ELSE
    1163             :         {
    1164      121635 :             IF( EQ_16( st->L_frame, L_FRAME ) )
    1165             :             {
    1166       67392 :                 startB = 34;
    1167       67392 :                 move16();
    1168       67392 :                 endB = 14;
    1169       67392 :                 move16();
    1170     1145664 :                 FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
    1171             :                 {
    1172     1078272 :                     uB = 0;
    1173     1078272 :                     move16();
    1174    22643712 :                     FOR( nB = startB; nB > endB; nB-- )
    1175             :                     {
    1176    21565440 :                         realBufferFlipped[ts][uB] = realBuffer[ts][nB];
    1177    21565440 :                         move32();
    1178    21565440 :                         if ( s_and( ts, 1 ) != 0 )
    1179             :                         {
    1180    10782720 :                             realBufferFlipped[ts][uB] = L_negate( realBufferFlipped[ts][uB] );
    1181    10782720 :                             move32();
    1182             :                         }
    1183    21565440 :                         imagBufferFlipped[ts][uB] = imagBuffer[ts][nB];
    1184    21565440 :                         move32();
    1185    21565440 :                         if ( s_and( ts, 1 ) == 0 )
    1186             :                         {
    1187    10782720 :                             imagBufferFlipped[ts][uB] = L_negate( imagBufferFlipped[ts][uB] );
    1188    10782720 :                             move32();
    1189             :                         }
    1190    21565440 :                         uB = add( uB, 1 ); /* uB ++ */
    1191             :                     }
    1192             :                 }
    1193             :             }
    1194             :             ELSE
    1195             :             {
    1196       54243 :                 startB = 39;
    1197       54243 :                 move16();
    1198       54243 :                 endB = 19;
    1199       54243 :                 move16();
    1200      922131 :                 FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
    1201             :                 {
    1202      867888 :                     uB = 0;
    1203      867888 :                     move16();
    1204    18225648 :                     FOR( nB = startB; nB > endB; nB-- )
    1205             :                     {
    1206    17357760 :                         realBufferFlipped[ts][uB] = L_negate( realBuffer[ts][nB] );
    1207    17357760 :                         move32();
    1208    17357760 :                         imagBufferFlipped[ts][uB] = imagBuffer[ts][nB];
    1209    17357760 :                         move32();
    1210    17357760 :                         uB = add( uB, 1 ); /* uB ++ */
    1211             :                     }
    1212             :                 }
    1213             :             }
    1214             : 
    1215     1337985 :             FOR( nB = 0; nB < 10; nB++ )
    1216             :             {
    1217    20677950 :                 FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
    1218             :                 {
    1219    19461600 :                     CldfbHB64_fx = W_mac_32_32( CldfbHB64_fx, realBufferFlipped[ts][nB], realBufferFlipped[ts][nB] );
    1220    19461600 :                     CldfbHB64_fx = W_mac_32_32( CldfbHB64_fx, imagBufferFlipped[ts][nB], imagBufferFlipped[ts][nB] );
    1221             :                 }
    1222             :             }
    1223             : 
    1224      121635 :             Word16 scf = W_norm( CldfbHB64_fx );
    1225      121635 :             CldfbHB64_fx = W_shl( CldfbHB64_fx, scf );
    1226      121635 :             CldfbHB_fx = W_extract_h( CldfbHB64_fx );
    1227      121635 :             CldfbHB_fx_e = sub( Q31, add( shl( q_reImBuffer, 1 ), sub( scf, Q31 ) ) );
    1228      121635 :             Cldfbtemp1 = Log2_norm_lc( CldfbHB_fx ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */
    1229      121635 :             Cldfbtemp1 = sub( shr( Cldfbtemp1, 6 ), shl( add( sub( Q31 - Q30, CldfbHB_fx_e ), exp ), 9 ) );
    1230      121635 :             CldfbHB_fx = L_mult( Cldfbtemp1, 9864 ); /* Q9 + Q15 + Q1 = Q25 */
    1231      121635 :             CldfbHB_fx = Mpy_32_16_1( L_sub( CldfbHB_fx, 1 << Q25 ), 11611 /* 0.1 * 0.221462 in Q19 */ );
    1232             :             /* Resulting Q = Q25 + Q19 - Q15 = Q29 */
    1233      121635 :             hBWE_TD->cldfbHBLT = mac_r( CldfbHB_fx, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */
    1234      121635 :             move32();
    1235             : 
    1236      121635 :             IF( CldfbHB_fx == 0 )
    1237             :             {
    1238           0 :                 CldfbHB_fx = EPSILLON_FX;
    1239           0 :                 move32();
    1240             :             }
    1241             : 
    1242      121635 :             test();
    1243      121635 :             IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoICBWE != NULL )
    1244             :             {
    1245          75 :                 Word32 icbweRefEner_fx = EPSILON_FX;
    1246          75 :                 Word16 exp_icbweRefEner_fx = 0;
    1247             : 
    1248          75 :                 move32();
    1249          75 :                 move16();
    1250        1575 :                 FOR( nB = 20; nB < 40; nB++ )
    1251             :                 {
    1252       25500 :                     FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
    1253             :                     {
    1254       24000 :                         realQ_neg1 = extract_l( L_shr( realBuffer[ts][nB], 16 ) );
    1255       24000 :                         imagQ_neg1 = extract_l( L_shr( imagBuffer[ts][nB], 16 ) ); /* Q(-1), headroom needed */
    1256       24000 :                         icbweRefEner_fx = L_mac0_o( icbweRefEner_fx, realQ_neg1, realQ_neg1, &Overflow );
    1257       24000 :                         icbweRefEner_fx = L_mac0_o( icbweRefEner_fx, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */
    1258             :                     }
    1259             :                 }
    1260          75 :                 exp_icbweRefEner_fx = sub( Q31, shl( sub( q_reImBuffer, Q16 ), 1 ) );
    1261          75 :                 hCPE->hStereoICBWE->icbweRefEner_fx = Mpy_32_16_1( Sqrt32( icbweRefEner_fx, &exp_icbweRefEner_fx ), 1638 /* 0.05 in Q15 */ );
    1262          75 :                 move32();
    1263          75 :                 hCPE->hStereoICBWE->icbweRefEner_fx_e = exp_icbweRefEner_fx;
    1264          75 :                 move16();
    1265             :             }
    1266             : 
    1267      121635 :             lbEner = EPSILON_FX;
    1268      121635 :             move32();
    1269     2554335 :             FOR( nB = 0; nB < 20; nB++ )
    1270             :             {
    1271    41355900 :                 FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
    1272             :                 {
    1273    38923200 :                     realQ_neg1 = extract_l( L_shr( realBuffer[ts][nB], 16 ) );
    1274    38923200 :                     imagQ_neg1 = extract_l( L_shr( imagBuffer[ts][nB], 16 ) ); /* Q(-1), headroom needed */
    1275             : 
    1276    38923200 :                     lbEner = L_mac0_o( lbEner, realQ_neg1, realQ_neg1, &Overflow );
    1277    38923200 :                     lbEner = L_mac0_o( lbEner, imagQ_neg1, imagQ_neg1, &Overflow ); /* Q(-2) */
    1278             :                 }
    1279             :             }
    1280      121635 :             exp_lbEner = sub( Q31, shl( sub( q_reImBuffer, Q16 ), 1 ) );
    1281      121635 :             lbEner = Mpy_32_16_1( Sqrt32( lbEner, &exp_lbEner ), 1638 /* 0.05 in Q15 */ );
    1282      121635 :             thr = icbwe_thr_TDM_fx;
    1283      121635 :             regV = icbwe_regressionValuesTDM_fx;
    1284             : 
    1285      121635 :             cldfbSynthesis_ivas_fx( realBufferFlipped, imagBufferFlipped, shb_speech_fx_32, -1, 0, 0, st->cldfbSynTd );
    1286      121635 :             Copy_Scale_sig_32_16( shb_speech_fx_32, shb_speech, L_FRAME16k, negate( sub( q_reImBuffer, 1 ) ) );
    1287      121635 :             *Q_shb_spch = 0;
    1288      121635 :             move16();
    1289             :         }
    1290             : 
    1291      157409 :         IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && hCPE->hStereoICBWE != NULL )
    1292             :         {
    1293             :             Word16 exp_t;
    1294       35849 :             hCPE->hStereoICBWE->MSFlag = 0; /* Init the multi-source flag */
    1295       35849 :             move16();
    1296       35849 :             v = Mpy_32_16_1( L_add( L_deposit_l( st->voicing_fx[0] ), L_add( L_deposit_l( st->voicing_fx[1] ), L_deposit_l( st->voicing_fx[2] ) ) ), 10923 /* 0.33333 in Q15 */ );
    1297             : 
    1298             :             // t = log10f( ( hCPE->hStereoICBWE->icbweRefEner + 1e-6f ) / ( lbEner + 1e-6f ) );
    1299       35849 :             t = L_deposit_h( BASOP_Util_Divide3232_Scale( L_add( hCPE->hStereoICBWE->icbweRefEner_fx, EPSILON_FX ), L_add( lbEner, EPSILON_FX ), &exp_t ) );
    1300       35849 :             exp_t = add( exp_t, sub( hCPE->hStereoICBWE->icbweRefEner_fx_e, exp_lbEner ) );
    1301       35849 :             exp = norm_l( t );
    1302       35849 :             t = L_shl( t, exp );
    1303       35849 :             t_16 = Log2_norm_lc( t ); /* Log2_norm_lc(t) = 2^15*(log2(t/2^30)) */
    1304       35849 :             t_16 = sub( shr( t_16, 6 ), shl( add( sub( Q31 - Q30, exp_t ), exp ), 9 ) );
    1305       35849 :             t = L_mult( t_16, 9864 ); /* Q9 + Q15 + Q1 = Q25 */
    1306             :             /* Three Level Decision Tree to calculate a regression value first */
    1307       35849 :             IF( LT_32( t, thr[0] ) ) /* level 1 */
    1308             :             {
    1309       26431 :                 IF( LT_32( t, thr[1] ) ) /* level 2 */
    1310             :                 {
    1311       23074 :                     IF( LT_32( v, thr[3] ) )
    1312             :                     {
    1313           0 :                         regression = regV[0]; /* level 3 */
    1314           0 :                         move32();
    1315             :                     }
    1316             :                     ELSE
    1317             :                     {
    1318       23074 :                         regression = regV[1];
    1319       23074 :                         move32();
    1320             :                     }
    1321             :                 }
    1322             :                 ELSE
    1323             :                 {
    1324        3357 :                     IF( LT_32( v, thr[4] ) )
    1325             :                     {
    1326        3357 :                         regression = regV[2]; /* level 3 */
    1327        3357 :                         move32();
    1328             :                     }
    1329             :                     ELSE
    1330             :                     {
    1331           0 :                         regression = regV[3];
    1332           0 :                         move32();
    1333             :                     }
    1334             :                 }
    1335             :             }
    1336             :             ELSE
    1337             :             {
    1338        9418 :                 IF( LT_32( t, thr[2] ) ) /* level 2 */
    1339             :                 {
    1340        2426 :                     IF( LT_32( v, thr[5] ) )
    1341             :                     {
    1342        2426 :                         regression = regV[4]; /* level 3 */
    1343        2426 :                         move32();
    1344             :                     }
    1345             :                     ELSE
    1346             :                     {
    1347           0 :                         regression = regV[5];
    1348           0 :                         move32();
    1349             :                     }
    1350             :                 }
    1351             :                 ELSE
    1352             :                 {
    1353        6992 :                     IF( LT_32( v, thr[6] ) )
    1354             :                     {
    1355        6992 :                         regression = regV[6]; /* level 3 */
    1356        6992 :                         move32();
    1357             :                     }
    1358             :                     ELSE
    1359             :                     {
    1360           0 :                         regression = regV[7];
    1361           0 :                         move32();
    1362             :                     }
    1363             :                 }
    1364             :             }
    1365             : 
    1366       35849 :             test();
    1367       35849 :             test();
    1368             :             /* Convert the regression to a hard decision (classification) */
    1369       35849 :             IF( GT_32( regression, 1696512081 /* 0.79f in Q31*/ ) && !( LT_16( st->bwidth, SWB ) || hCPE->hCoreCoder[0]->vad_flag == 0 ) )
    1370             :             {
    1371        5988 :                 hCPE->hStereoICBWE->MSFlag = 1;
    1372        5988 :                 move16();
    1373             :             }
    1374             :         }
    1375             : 
    1376      157409 :         test();
    1377      157409 :         test();
    1378      157409 :         IF( NE_16( st->extl, WB_TBE ) && NE_16( st->extl, SWB_TBE ) && NE_16( st->extl, FB_TBE ) )
    1379             :         {
    1380             :             /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */
    1381       37644 :             delay = L_LOOK_16k + L_SUBFR16k;
    1382       37644 :             move16();
    1383       37644 :             Copy( shb_speech + sub( L_FRAME16k, delay ), hBWE_TD->old_speech_shb_fx, delay );
    1384             :         }
    1385             :     }
    1386             :     ELSE
    1387             :     {
    1388      238633 :         test();
    1389      238633 :         test();
    1390      238633 :         IF( ( EQ_16( st->bwidth, FB ) || st->core == ACELP_CORE ) && ( st->element_mode == EVS_MONO ) )
    1391             :         {
    1392           0 :             InitSWBencBufferStates_fx( st->hBWE_TD, shb_speech );
    1393             :         }
    1394             :         ELSE
    1395             :         {
    1396      238633 :             IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
    1397             :             {
    1398       12342 :                 IF( EQ_16( st->L_frame, L_FRAME ) )
    1399             :                 {
    1400        3615 :                     L_resamp = 560; /* 6.4 kHz core -> 6 - 14 kHz SHB target. 20 ms is 560 samples in 28 kHz sample rate */
    1401        3615 :                     move16();
    1402             :                 }
    1403             :                 ELSE
    1404             :                 {
    1405        8727 :                     L_resamp = 620; /* 8 kHz core -> 7.5 - 15.5 kHz SHB target. 20 ms is 620 samples in 31 kHz sample rate */
    1406        8727 :                     move16();
    1407             :                 }
    1408             : 
    1409             :                 /* Dirty downsampling to match Nyquist to upper frequency limit of target */
    1410       12342 :                 lerp( st->input_fx, new_swb_speech, L_resamp, extract_l( Mpy_32_32( input_Fs, one_by_50_Q31 ) ) );
    1411             : 
    1412             :                 /* flip the spectrum */
    1413       12342 :                 Copy( new_swb_speech, spchTmp, L_resamp );
    1414     3729912 :                 FOR( i = 0; i < L_resamp; i = i + 2 )
    1415             :                 {
    1416     3717570 :                     spchTmp[i] = negate( spchTmp[i] );
    1417     3717570 :                     move16();
    1418             :                 }
    1419             : 
    1420             :                 /* Dirty upsampling to match Nyquist/2 to lower frequency limit of target (reversed spectrum)*/
    1421       12342 :                 lerp( spchTmp, spchTmp2, L_FRAME32k, L_resamp );
    1422       12342 :                 Copy( spchTmp2, spchTmp, L_FRAME32k );
    1423             :             }
    1424             :             ELSE
    1425             :             {
    1426             :                 /* flip the spectrum */
    1427      226291 :                 Copy( new_swb_speech, spchTmp, L_FRAME32k );
    1428             : 
    1429    72639411 :                 FOR( i = 0; i < L_FRAME32k; i = i + 2 )
    1430             :                 {
    1431    72413120 :                     spchTmp[i] = negate( spchTmp[i] );
    1432    72413120 :                     move16();
    1433             :                 }
    1434             :             }
    1435             : 
    1436      238633 :             Decimate_allpass_steep_fx( spchTmp, hBWE_TD->state_ana_filt_shb_fx, L_FRAME32k, shb_speech );
    1437             : 
    1438      238633 :             Copy( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k );
    1439             : 
    1440             :             /*Compute the past overlap for potential next iDFTs SHB*/
    1441      238633 :             IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
    1442             :             {
    1443     1740222 :                 FOR( i = 0; i < STEREO_DFT_OVL_16k; i++ )
    1444             :                 {
    1445     1727880 :                     hCPE->hStereoDft->output_mem_dmx_16k_shb_fx[i] = L_mult0( shb_speech[20 + i], mult_r( hCPE->hStereoDft->win_ana_16k_fx[STEREO_DFT_OVL_16k - 1 - i], hCPE->hStereoDft->win_ana_16k_fx[STEREO_DFT_OVL_16k - 1 - i] ) ); // Q15
    1446     1727880 :                     move32();
    1447             :                 }
    1448             :             }
    1449             :         }
    1450             : 
    1451      238633 :         IF( NE_16( st->element_mode, IVAS_CPE_DFT ) )
    1452             :         {
    1453             :             /* Reset CLDFB synthesis buffer */
    1454      226291 :             set32_fx( st->cldfbSynTd->cldfb_state_fx, 0, st->cldfbSynTd->p_filter_length );
    1455             :         }
    1456             :         ELSE
    1457             :         {
    1458       12342 :             hCPE->hStereoDft->flip_sign = negate( hCPE->hStereoDft->flip_sign ); /* Make sure sign is updated even if DFT SHB target is not generated */
    1459       12342 :             move16();
    1460             :         }
    1461             :     }
    1462             : 
    1463             :     /* Memory reset to compensate for 0.9375 ms offset when transitioning from IO to SWB */
    1464             :     /* When switching from n >1 to n = 1, we keep the enc/dec delay as 8.75/3.25 and below code not needed;
    1465             :        only when n = 1 start, it will be 9.6875/2.3125 in that case this reset is needed for IO->BWE.*/
    1466      396042 :     test();
    1467      396042 :     IF( EQ_16( st->last_extl, -1 ) && ( st->element_mode == EVS_MONO ) )
    1468             :     {
    1469           0 :         delay = NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS );
    1470           0 :         move16();
    1471           0 :         FOR( i = 0; i < delay; i++ )
    1472             :         {
    1473           0 :             shb_speech[i] = mult_r( mult_r( i, 983 /*0.03f Q15*/ ), shb_speech[2 * delay - 1 - i] );
    1474           0 :             move16();
    1475             :         }
    1476             :     }
    1477             : 
    1478      396042 :     return;
    1479             : }

Generated by: LCOV version 1.14