LCOV - code coverage report
Current view: top level - lib_dec - ivas_post_proc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ bf9ba511f19a231c475b8e110fdaeacf18aa32c4 Lines: 335 336 99.7 %
Date: 2025-07-11 02:46:47 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <assert.h>
      34             : #include <stdint.h>
      35             : #include "options.h"
      36             : #include "cnst.h"
      37             : #include "rom_com.h"
      38             : #include "prot_fx.h"
      39             : #include "ivas_prot_fx.h"
      40             : #include "ivas_cnst.h"
      41             : #include "wmc_auto.h"
      42             : 
      43             : /*-------------------------------------------------------------------------
      44             :  * ivas_post_proc()
      45             :  *
      46             :  * IVAS post-processing
      47             :  * - in SCE, post-processing of output channel
      48             :  * - in CPE_DFT, post-processing on output channels
      49             :  * - in CPE_TD, post-processing on decoded channels before upmixing
      50             :  *-------------------------------------------------------------------------*/
      51             : 
      52     1028889 : void ivas_post_proc_fx(
      53             :     SCE_DEC_HANDLE hSCE,                /* i/o: SCE decoder structure              */
      54             :     CPE_DEC_HANDLE hCPE,                /* i/o: CPE decoder structure              */
      55             :     const Word16 n,                     /* i  : channel number                     Q0*/
      56             :     Word32 synth[],                     /* i/o: output synthesis signal            Q11*/
      57             :     Word32 *output[CPE_CHANNELS],       /* i/o: output synthesis signal            output_q*/
      58             :     const Word16 output_frame,          /* i  : output frame length                Q0*/
      59             :     const Word16 sba_dirac_stereo_flag, /* i  : signal stereo output for SBA DirAC Q0*/
      60             :     Word16 output_q )
      61             : {
      62             :     Word16 k;
      63             :     Word16 delay_comp;
      64             :     Word32 output_Fs;
      65             :     Decoder_State **sts;
      66             :     TCX_LTP_DEC_HANDLE hTcxLtpDec;
      67             : 
      68     1028889 :     IF( hSCE != NULL )
      69             :     {
      70      311046 :         sts = hSCE->hCoreCoder;
      71             :     }
      72             :     ELSE
      73             :     {
      74      717843 :         sts = hCPE->hCoreCoder;
      75             :     }
      76             : 
      77     1028889 :     output_Fs = sts[0]->output_Fs;
      78     1028889 :     move32();
      79             : 
      80     1028889 :     test();
      81     1028889 :     test();
      82     1028889 :     test();
      83     1028889 :     test();
      84     1028889 :     test();
      85     1028889 :     IF( ( NE_16( sts[n]->element_mode, IVAS_CPE_DFT ) && !( sba_dirac_stereo_flag && NE_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) ) || ( EQ_16( sts[n]->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) )
      86             :     {
      87      983033 :         IF( sts[n]->hTcxLtpDec != NULL )
      88             :         {
      89      979282 :             hTcxLtpDec = sts[n]->hTcxLtpDec;
      90             : 
      91      979282 :             test();
      92      979282 :             IF( NE_16( sts[n]->core, TCX_20_CORE ) && NE_16( sts[n]->core, TCX_10_CORE ) )
      93             :             {
      94             :                 /* TCX-LTP Postfilter: used in Mode 1 to update memories and to avoid discontinuities when the past frame was TCX */
      95      143483 :                 tcx_ltp_post_fx32( sts[n], hTcxLtpDec, ACELP_CORE, output_frame, 0, synth, NULL, output_q );
      96             :             }
      97             :             ELSE
      98             :             {
      99             :                 /* set delay */
     100      835799 :                 delay_comp = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); /*Q0*/
     101      835799 :                 move16();
     102             : 
     103      835799 :                 test();
     104      835799 :                 test();
     105      835799 :                 test();
     106      835799 :                 test();
     107      835799 :                 IF( EQ_16( EQ_16( sts[n]->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ), 0 ) && NE_16( sts[n]->element_mode, IVAS_CPE_MDCT ) )
     108             :                 {
     109      197826 :                     Copy32( sts[n]->delay_buf_out32_fx, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/
     110             :                 }
     111      637973 :                 ELSE IF( sba_dirac_stereo_flag && EQ_16( sts[n]->element_mode, IVAS_CPE_MDCT ) )
     112             :                 {
     113       22423 :                     Word16 numZeros = (Word16) ( NS2SA_FX2( output_Fs, N_ZERO_MDCT_NS ) ); /*Q0*/
     114       22423 :                     move16();
     115             : #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT
     116       22423 :                     assert( sts[n]->hHQ_core->Q_old_out_fx32 == Q11 );
     117             : #endif
     118       22423 :                     Copy32( sts[n]->hHQ_core->old_out_fx32 + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/
     119             :                 }
     120             : 
     121      835799 :                 tcx_ltp_post_fx32( sts[n], hTcxLtpDec, sts[n]->core, output_frame, add( NS2SA_FX2( output_Fs, ACELP_LOOK_NS ), delay_comp ), synth, sts[n]->hTcxDec->FBTCXdelayBuf_32, output_q );
     122             :             }
     123             :         }
     124             :     }
     125             :     ELSE /* IVAS_CPE_DFT */
     126             :     {
     127             :         Word16 pit_res_max_past_tmp;
     128             : 
     129       45856 :         pit_res_max_past_tmp = sts[0]->pit_res_max_past; /*Q0*/
     130       45856 :         move16();
     131      132223 :         FOR( k = 0; k < hCPE->nchan_out; k++ )
     132             :         {
     133       86367 :             IF( k == 0 )
     134             :             {
     135       45856 :                 hTcxLtpDec = sts[0]->hTcxLtpDec;
     136             :             }
     137             :             ELSE
     138             :             {
     139       40511 :                 hTcxLtpDec = hCPE->hStereoDft->hTcxLtpDec;
     140             :                 /* copy LTP side-info of downmix channel also to right channel struct */
     141       40511 :                 hTcxLtpDec->tcxltp = sts[0]->hTcxLtpDec->tcxltp; /*Q0*/
     142       40511 :                 move16();
     143       40511 :                 hTcxLtpDec->tcxltp_gain = sts[0]->hTcxLtpDec->tcxltp_gain; /*Q15*/
     144       40511 :                 move16();
     145       40511 :                 hTcxLtpDec->tcxltp_pitch_int = sts[0]->hTcxLtpDec->tcxltp_pitch_int; /*Q0*/
     146       40511 :                 move16();
     147       40511 :                 hTcxLtpDec->tcxltp_pitch_fr = sts[0]->hTcxLtpDec->tcxltp_pitch_fr; /*Q0*/
     148       40511 :                 move16();
     149             :                 /* revert update of pit_res_max_past to have correct value also in right channel */
     150       40511 :                 sts[0]->pit_res_max_past = pit_res_max_past_tmp; /*Q0*/
     151       40511 :                 move16();
     152             :             }
     153             : 
     154             :             /*TCX-LTP*/
     155       86367 :             IF( NE_16( sts[0]->core, TCX_20_CORE ) && NE_16( sts[0]->core, TCX_10_CORE ) )
     156             :             {
     157             :                 /* update memories and to avoid discontinuities when the past frame was TCX */
     158       60695 :                 tcx_ltp_post_fx32( sts[0], hTcxLtpDec, ACELP_CORE, output_frame, 0, output[k], NULL, output_q );
     159             :             }
     160             :             ELSE
     161             :             {
     162             :                 /*Use channel 0 side info.*/
     163       25672 :                 tcx_ltp_post_fx32( sts[0], hTcxLtpDec, TCX_20_CORE, output_frame, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), output[k], hCPE->output_mem_fx[k], output_q );
     164             :             }
     165             :         }
     166             :     }
     167             : 
     168     1028889 :     return;
     169             : }
     170             : 
     171             : 
     172             : /*-------------------------------------------------------------------------
     173             :  * stereo_dft_dec_core_switching_fx()
     174             :  *
     175             :  * core switching in DFT stereo
     176             :  *-------------------------------------------------------------------------*/
     177             : 
     178       63558 : void stereo_dft_dec_core_switching_fx(
     179             :     CPE_DEC_HANDLE hCPE,                             /* i/o: CPE decoder structure               */
     180             :     Word32 output_fx[],                              /* i/o: synthesis @internal Fs              q*/
     181             :     Word32 synth_fx[],                               /* i/o: synthesis @output Fs                q*/
     182             :     Word32 hb_synth_fx[],                            /* i/o: hb synthesis                        q*/
     183             :     Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o  : DFT buffers                         q_DFT*/
     184             :     const Word16 output_frame,                       /* i  : output frame length                 Q0*/
     185             :     const Word16 use_cldfb_for_dft,                  /* i  : flag to use of CLDFB FOR DFT Stereo Q0*/
     186             :     const Word16 sba_dirac_stereo_dtx_flag,          /* i  : DTX indicator FOR SBA DirAC stereo  Q0*/
     187             :     Word16 *q,
     188             :     Word16 *q_DFT )
     189             : {
     190             :     Word32 output_Fs;
     191             :     Decoder_State *st;
     192             :     Word16 i, tmps;
     193             :     Word16 delay_dft_dec, delay_dft_dec_lb, delay_tdbwe, delay_comp;
     194             :     Word16 L_frameTCX;
     195             :     Word16 predelay, ap_fade_len;
     196             :     Word32 ap_fade_len_inv, ap_fade_len_fx;
     197             :     Word16 qap_fade_len;
     198             :     Word32 pAp_input_fx[L_FRAME16k];
     199             :     Word32 tcx_core_buf_fx[L_FRAME16k];
     200             :     Word64 calc_inv;
     201             :     Word32 synth_tmp_fx[L_FRAME48k];
     202             : 
     203             : 
     204       63558 :     st = hCPE->hCoreCoder[0];  /* in DFT stereo, only M channel is decoded by the CoreCoder */
     205       63558 :     output_Fs = st->output_Fs; /*Q0*/
     206       63558 :     move32();
     207       63558 :     L_frameTCX = st->hTcxDec->L_frameTCX; /*Q0*/
     208       63558 :     move16();
     209             : 
     210             :     /*TBE*/
     211       63558 :     delay_tdbwe = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/
     212       63558 :     move16();
     213       63558 :     delay_dft_dec = NS2SA_FX2( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); /*Q0*/
     214       63558 :     move16();
     215       63558 :     delay_dft_dec_lb = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT_DELAY_DEC_BWE_NS ); /*Q0*/
     216       63558 :     move16();
     217             : 
     218             :     /* TCX/ACELP/HQ-CORE->TCX */
     219       63558 :     tmps = NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ); /*cross-fading size @ FB*/ /*Q0*/
     220       63558 :     move16();
     221       63558 :     delay_comp = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), DELAY_BWE_TOTAL_NS ); /*cross-fading size @ LB*/ /*Q0*/
     222       63558 :     move16();
     223             : 
     224       63558 :     calc_inv = W_shl( 1, 31 );
     225             : 
     226             :     // Memory Tables //////////////////////////////////////////////////////////////////////////////
     227       63558 :     Word32 mem_len_inv_tbl[] = { 85899345, 42949672, 28633115, 21474836, 17179869, 14316557 };                                                          /*Q31*/
     228       63558 :     Word32 delay_comp_inv_tbl[] = { 2147483647, 306783378, 153391689, 97612893, 74051160, 58040098, 48806446, 42107522, 36398027, 32537631, 29020049 }; /*Q31*/
     229             :     ///////////////////////////////////////////////////////////////////////////////////////////////
     230             : 
     231       63558 :     test();
     232       63558 :     test();
     233       63558 :     IF( NE_16( st->last_L_frame, st->L_frame ) && LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) )
     234             :     {
     235         293 :         L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), NS2SA_FX2( L_mult0( st->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) );
     236         293 :         L_lerp_fx_q11( hCPE->input_mem_BPF_fx[0], hCPE->input_mem_BPF_fx[0], NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), NS2SA_FX2( L_mult0( st->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) );
     237             :     }
     238             : 
     239       63558 :     test();
     240       63558 :     test();
     241       63558 :     IF( ( st->prev_bfi != 0 ) && EQ_16( ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) )
     242             :     {
     243             :         /* last_core needed FOR correctly decoding ACELP->TCX/HQ switching frames in ivas_core_dec().
     244             :            In the following steps the decoder needs to consider IF the core was changed due to a lost frame to apply the correct transition */
     245         877 :         st->last_core = st->last_core_bfi;
     246         877 :         move16();
     247             :     }
     248             : 
     249             : 
     250       63558 :     test();
     251       63558 :     test();
     252       63558 :     test();
     253       63558 :     test();
     254       63558 :     test();
     255       63558 :     IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) )
     256             :     {
     257       17532 :         test();
     258       17532 :         test();
     259       17532 :         test();
     260       17532 :         test();
     261       17532 :         test();
     262       17532 :         test();
     263       17532 :         IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( sba_dirac_stereo_dtx_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */
     264             :         {
     265             :             /* In case of a TCX to ACELP switch next frame */
     266       16293 :             Copy32( &output_fx[st->L_frame - NS2SA( ( st->L_frame * FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/
     267             : 
     268             :             /* BPF */
     269       16293 :             test();
     270       16293 :             test();
     271       16293 :             IF( st->p_bpf_noise_buf_32 && NE_16( st->core, HQ_CORE ) )
     272             :             {
     273       15192 :                 Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/
     274       15192 :                 stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 2, 0, q, q_DFT );
     275             :             }
     276             :             /* st->p_bpf_noise_buf not updated FOR HQ core -> skip analysis and set input memory to zero */
     277        1101 :             ELSE IF( st->p_bpf_noise_buf_32 && EQ_16( st->core, HQ_CORE ) )
     278             :             {
     279        1101 :                 set32_fx( hCPE->input_mem_BPF_fx[0], 0, STEREO_DFT32MS_OVL_16k );
     280             :             }
     281             : 
     282             :             /* TCX */
     283       16293 :             stereo_dft_dec_analyze_fx( hCPE, synth_fx, DFT_fx, 0, L_frameTCX, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, q, q_DFT );
     284             :         }
     285        1239 :         ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */
     286             :         {
     287        1239 :             test();
     288        1239 :             IF( LE_32( st->last_core_brate, SID_2k40 ) && LE_16( st->element_mode, IVAS_SCE ) )
     289           2 :             {
     290           2 :                 Word16 mem_len = NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /*Q0*/
     291           2 :                 move16();
     292           2 :                 Word32 mem_len_inv = mem_len_inv_tbl[( mem_len / 25 ) - 1];
     293           2 :                 move32();
     294           2 :                 Word16 qmem_len = norm_l( mem_len );
     295           2 :                 Word32 mem_len_fx = L_shl( mem_len, qmem_len );
     296         302 :                 FOR( i = 0; i < mem_len; i++ )
     297             :                 {
     298         300 :                     hCPE->input_mem_fx[0][i] = Mpy_32_32( hCPE->input_mem_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); /*Q11 + qmem_len - 31*/
     299         300 :                     move32();
     300         300 :                     hCPE->input_mem_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); /*Q11*/
     301         300 :                     move32();
     302             :                 }
     303             : 
     304             :                 /* Update FB input buff with hb synth FOR last delay_tdbwe sampled */
     305         224 :                 FOR( i = 0; i < delay_tdbwe; i++ )
     306             :                 {
     307         444 :                     hCPE->input_mem_fx[0][( ( NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] =
     308         222 :                         L_add( hCPE->input_mem_fx[0][NS2SA( ( ( L_frameTCX * FRAMES_PER_SEC ) - STEREO_DFT32MS_OVL_NS ) + delay_tdbwe, i )], hb_synth_fx[i] ); /*Q11*/
     309         222 :                     move32();
     310             :                 }
     311             :             }
     312             :             ELSE
     313             :             {
     314             :                 /* Update FB input buff with hb synth FOR last delay_tdbwe sampled */
     315       99176 :                 FOR( i = 0; i < delay_tdbwe; i++ )
     316             :                 {
     317       97939 :                     hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe ) + i )] = hb_synth_fx[i]; /*Q11*/
     318       97939 :                     move32();
     319             :                 }
     320             :             }
     321             : 
     322             :             /* cross-fading between (delayed) TBE and FB-TCX over 2.3125ms */
     323        1239 :             Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/
     324        1239 :             Word16 qtmps = norm_l( tmps );
     325        1239 :             Word32 tmps_fx = L_shl( tmps, qtmps );
     326        1239 :             Word32 tmps_inv = (Word32) ( calc_inv / tmps );
     327       99400 :             FOR( i = 0; i < tmps; i++ )
     328             :             {
     329       98161 :                 synth_tmp_fx[i] = L_add( Mpy_32_32( hb_synth_fx[( i + delay_tdbwe )], L_sub( tmps_fx, L_shl( i, qtmps ) ) ), Mpy_32_32( synth_fx[i], L_shl( i, qtmps ) ) ); /*q + qtmps - 31*/
     330       98161 :                 move32();
     331       98161 :                 synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], tmps_inv ), sub( 31, qtmps ) ); /*q*/
     332       98161 :                 move32();
     333             :             }
     334             : 
     335             :             /* FB-TCX */
     336        1239 :             stereo_dft_dec_analyze_fx( hCPE, synth_tmp_fx, DFT_fx, 0, L_frameTCX, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, q, q_DFT );
     337             : 
     338        1239 :             IF( st->tcxonly == 0 )
     339             :             {
     340        1239 :                 IF( EQ_16( hCPE->hStereoDft->hConfig->res_pred_mode, STEREO_DFT_RESPRED_ESF ) )
     341             :                 {
     342         774 :                     Copy32( output_fx, tcx_core_buf_fx, L_FRAME16k ); /*q*/
     343             :                 }
     344             :                 /* fading-out LB-TCX/ACELP */
     345        1239 :                 Word16 qdelay_comp = norm_l( delay_comp );
     346        1239 :                 Word32 delay_comp_inv = delay_comp_inv_tbl[( delay_comp / 7 )]; /*Q31*/
     347        1239 :                 move32();
     348        1239 :                 Word32 delay_comp_fx = L_shl( delay_comp, qdelay_comp );
     349       43882 :                 FOR( i = 0; i < delay_comp; i++ )
     350             :                 {
     351       42643 :                     output_fx[i] = Mpy_32_32( output_fx[i], L_sub( delay_comp_fx, L_shl( i, qdelay_comp ) ) ); /*q + qdelay_comp - 31*/
     352       42643 :                     move32();
     353       42643 :                     output_fx[i] = L_shl( Mpy_32_32( output_fx[i], delay_comp_inv ), sub( Q31, qdelay_comp ) ); /*q*/
     354       42643 :                     move32();
     355             :                 }
     356             : 
     357             :                 /* In case of TCX frames, output LB TCX is zeroed out until the end but in case of an TCX->ACELP switch, this memory is needed, hence it is backed up */
     358             :                 /* Unlike the case when DFT32MS is disabled, there is only 1 DFT analysis window, hence in the TCX frame we don't want to do a DFT analysis FOR LB TCX
     359             :                 but in a potential ACELP frame, we want the memories of the LB TCX FOR the last OLA samples so that HB analysis can be skipped */
     360        1239 :                 Copy32( &output_fx[st->L_frame - NS2SA_FX2( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*q*/
     361             : 
     362             :                 /*zero the rest FOR avoiding adding contribution except the last samples which are not considered in DFT analysis (potentially used in next ACELP frame)*/
     363        1239 :                 IF( GT_32( st->last_core_brate, SID_2k40 ) )
     364             :                 {
     365      312376 :                     FOR( ; i < st->L_frame; i++ )
     366             :                     {
     367      311198 :                         output_fx[i] = 0;
     368      311198 :                         move32();
     369             :                     }
     370             : 
     371        1178 :                     stereo_dft_dec_analyze_fx( hCPE, output_fx, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB_ADD, 1, 0, q, q_DFT );
     372             : 
     373             :                     /* BPF */
     374        1178 :                     IF( st->p_bpf_noise_buf_32 )
     375             :                     {
     376        1178 :                         set32_fx( hCPE->input_mem_BPF_fx[0], 0, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) );
     377             :                     }
     378             :                 }
     379             :             }
     380             :         }
     381             :     }
     382             :     ELSE /* ACELP core */
     383             :     {
     384       46026 :         test();
     385       46026 :         test();
     386       46026 :         test();
     387       46026 :         IF( LE_32( st->core_brate, SID_2k40 ) && !sba_dirac_stereo_dtx_flag )
     388             :         {
     389       10351 :             set32_fx( hCPE->input_mem_fx[0], 0, NS2SA_FX2( L_mult0( st->hTcxDec->L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) );
     390       10351 :             set32_fx( hCPE->input_mem_LB_fx[0], 0, NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) );
     391             : 
     392             :             /* CNG generated in ivas_cpe_dec() */
     393             :         }
     394       35675 :         ELSE IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */
     395             :         {
     396        1529 :             IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( sba_dirac_stereo_dtx_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) )
     397             :             {
     398             :                 /* In case of a TCX to ACELP switch, retrieve the LB-TCX memories FOR the first STEREO_DFT32MS_OVL_NS NS of OLA */
     399        1088 :                 L_lerp_fx_q11( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), NS2SA_FX2( L_mult0( st->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) );
     400             :             }
     401             : 
     402        1529 :             IF( sba_dirac_stereo_dtx_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) )
     403           3 :             {
     404             :                 Word16 nZeros;
     405           3 :                 nZeros = (Word16) ( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ); /*Q0*/
     406           3 :                 move16();
     407           3 :                 delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*Q0*/
     408           3 :                 move16();
     409             : 
     410           3 :                 Copy32( &st->hHQ_core->old_out_fx32[nZeros - ( delay_comp + NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) )], hCPE->input_mem_fx[0], NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*Q11*/
     411           3 :                 Copy32( synth_fx, synth_tmp_fx, output_frame );                                                                                                                                                                                     /*q*/
     412             : 
     413             :                 Word16 mem_len;
     414           3 :                 mem_len = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /*Q0*/
     415           3 :                 move16();
     416             : 
     417           3 :                 Word16 qmem_len = norm_l( mem_len );
     418           3 :                 Word32 mem_len_fx = L_shl( mem_len, qmem_len );
     419           3 :                 Word32 mem_len_inv = (Word32) ( calc_inv / tmps );
     420           3 :                 move32();
     421         153 :                 FOR( i = 0; i < mem_len; i++ )
     422             :                 {
     423         150 :                     hCPE->input_mem_LB_fx[0][i] = Mpy_32_32( hCPE->input_mem_LB_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); /*Q11 + qmem_len - 31*/
     424         150 :                     move32();
     425         150 :                     hCPE->input_mem_LB_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); /*Q11*/
     426         150 :                     move32();
     427             :                 }
     428           3 :                 set32_fx( output_fx, 0, st->L_frame );
     429             : 
     430           3 :                 stereo_dft_dec_analyze_fx( hCPE, output_fx, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, q, q_DFT );
     431             : 
     432             :                 /* BPF */
     433           3 :                 IF( st->p_bpf_noise_buf_32 )
     434             :                 {
     435           3 :                     Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/
     436           3 :                     stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0, q, q_DFT );
     437             :                 }
     438             :             }
     439             :             ELSE
     440             :             {
     441             :                 /* ACELP */
     442       42560 :                 FOR( i = 0; i < ( NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ); i++ )
     443             :                 {
     444       41034 :                     hCPE->input_mem_LB_fx[0][i] = 0;
     445       41034 :                     move32();
     446             :                 }
     447             :                 /* ACELP fading-in*/
     448        1526 :                 Word16 qdelay_dft_dec_lb = norm_l( delay_dft_dec_lb );
     449        1526 :                 Word32 delay_dft_dec_lb_inv = (Word32) ( calc_inv / delay_dft_dec_lb );
     450       28882 :                 FOR( i = 0; i < delay_dft_dec_lb; i++ )
     451             :                 {
     452       54712 :                     hCPE->input_mem_LB_fx[0][( ( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] =
     453       27356 :                         Mpy_32_32( hCPE->input_mem_LB_fx[0][( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i], L_shl( i, qdelay_dft_dec_lb ) ); /*Q11 + qdelay_dft_dec_lb -31*/
     454       27356 :                     move32();
     455       54712 :                     hCPE->input_mem_LB_fx[0][( ( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )] =
     456       27356 :                         L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][( ( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ) + i )], delay_dft_dec_lb_inv ), sub( Q31, qdelay_dft_dec_lb ) ); /*Q11*/
     457       27356 :                     move32();
     458             :                 }
     459        1526 :                 stereo_dft_dec_analyze_fx( hCPE, output_fx, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, q, q_DFT );
     460             : 
     461             :                 /* BPF */
     462        1526 :                 IF( st->p_bpf_noise_buf_32 )
     463             :                 {
     464        1085 :                     Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/
     465        1085 :                     stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0, q, q_DFT );
     466             :                 }
     467             : 
     468             :                 /* Fading-in TD-BWE, Fading-out FB-TCX*/
     469        1526 :                 Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/
     470        1526 :                 IF( NE_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) )
     471             :                 {
     472        1061 :                     Word16 qdelay_dft_dec = norm_l( delay_dft_dec );
     473        1061 :                     Word32 delay_dft_dec_inv = (Word32) ( calc_inv / delay_dft_dec );
     474        1061 :                     Word32 delay_dft_dec_fx = L_shl( delay_dft_dec, qdelay_dft_dec );
     475       47241 :                     FOR( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade-in and TCX fade-out */
     476             :                     {
     477      138540 :                         hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )] = L_add(
     478       46180 :                             Mpy_32_32( hb_synth_fx[( ( delay_tdbwe - delay_dft_dec ) + i )], L_shl( i, qdelay_dft_dec ) ),
     479       46180 :                             Mpy_32_32( hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ) ); /*Q11 + qdelay_dft_dec - 31*/
     480       46180 :                         move32();
     481       46180 :                         hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )] = L_shl(
     482       46180 :                             Mpy_32_32( hCPE->input_mem_fx[0][( ( NS2SA_FX2( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec ) + i )], delay_dft_dec_inv ),
     483       46180 :                             sub( Q31, qdelay_dft_dec ) ); /*Q11*/
     484       46180 :                         move32();
     485             :                     }
     486       47241 :                     FOR( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade out. ICBWE fade in performed in time domain here */
     487             :                     {
     488       46180 :                         synth_tmp_fx[i] = Mpy_32_32( hb_synth_fx[( ( delay_tdbwe - delay_dft_dec ) + i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ); /*q + qdelay_dft_dec - 31*/
     489       46180 :                         move32();
     490       46180 :                         synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], delay_dft_dec_inv ), sub( Q31, qdelay_dft_dec ) ); /*q*/
     491       46180 :                         move32();
     492             :                     }
     493             : 
     494      693761 :                     FOR( ; i < output_frame; i++ )
     495             :                     {
     496      692700 :                         synth_tmp_fx[i] = 0;
     497      692700 :                         move32();
     498             :                     }
     499             :                 }
     500             :             }
     501             : 
     502             : 
     503        1529 :             IF( sba_dirac_stereo_dtx_flag )
     504             :             {
     505           3 :                 stereo_dft_dec_analyze_fx( hCPE, synth_tmp_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 0, 0, q, q_DFT );
     506             :             }
     507        1526 :             ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) )
     508             :             {
     509         465 :                 stereo_dft_dec_analyze_fx( hCPE, synth_tmp_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_HB_ADD, 1, 0, q, q_DFT );
     510             :             }
     511             :             ELSE
     512             :             {
     513        1061 :                 stereo_dft_dec_analyze_fx( hCPE, synth_tmp_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 1, 0, q, q_DFT );
     514             :             }
     515             :         }
     516             :         ELSE /* ACELP -> ACELP */
     517             :         {
     518       34146 :             test();
     519       34146 :             test();
     520       34146 :             test();
     521       34146 :             test();
     522       34146 :             IF( sba_dirac_stereo_dtx_flag && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) )
     523             :             {
     524          88 :                 set32_fx( output_fx, 0, st->L_frame );
     525             :             }
     526             :             /* this needs an indication FOR sba2stereo in general */
     527       34058 :             ELSE IF( EQ_16( hCPE->element_mode, IVAS_SCE ) && LE_32( st->last_core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) )
     528             :             {
     529           0 :                 L_lerp_fx_q11( hCPE->input_mem_fx[0], hCPE->input_mem_LB_fx[0], NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) );
     530             :             }
     531             : 
     532             :             /* ACELP synthesis @ internal sampling rate */
     533             : 
     534       34146 :             stereo_dft_dec_analyze_fx( hCPE, output_fx, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, q, q_DFT );
     535             : 
     536             :             /* BPF */
     537       34146 :             IF( st->p_bpf_noise_buf_32 )
     538             :             {
     539       31917 :                 Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); /*q*/
     540       31917 :                 stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0, q, q_DFT );
     541             :             }
     542             : 
     543             :             /* BWE */
     544       34146 :             test();
     545       34146 :             test();
     546       34146 :             test();
     547       34146 :             test();
     548       34146 :             IF( sba_dirac_stereo_dtx_flag && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) )
     549             :             {
     550          88 :                 stereo_dft_dec_analyze_fx( hCPE, synth_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 0, 0, q, q_DFT );
     551             :             }
     552       34058 :             ELSE IF( NE_16( st->extl, -1 ) || ( ( st->bws_cnt > 0 ) && EQ_16( st->core, ACELP_CORE ) ) )
     553             :             {
     554       29457 :                 stereo_dft_dec_analyze_fx( hCPE, hb_synth_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 2, negate( delay_tdbwe ), q, q_DFT );
     555             :             }
     556             :         }
     557             :     }
     558             : 
     559             :     /*----------------------------------------------------------------*
     560             :      * enhanced stereo filling: allpass filter
     561             :      *----------------------------------------------------------------*/
     562             : 
     563       63558 :     IF( EQ_16( hCPE->hStereoDft->hConfig->res_pred_mode, STEREO_DFT_RESPRED_ESF ) )
     564             :     {
     565       32164 :         IF( EQ_32( st->sr_core, INT_FS_12k8 ) )
     566             :         {
     567       19754 :             ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_12k8;
     568       19754 :             move16();
     569       19754 :             ap_fade_len_inv = 67108864; /*1/32 in Q31*/
     570       19754 :             move32();
     571             :         }
     572             :         ELSE
     573             :         {
     574       12410 :             ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_16k;
     575       12410 :             move16();
     576       12410 :             ap_fade_len_inv = 53687091; /*1/40 in Q31*/
     577       12410 :             move32();
     578             :         }
     579             : 
     580       32164 :         qap_fade_len = norm_l( ap_fade_len );
     581       32164 :         ap_fade_len_fx = L_shl( ap_fade_len, qap_fade_len );
     582             : 
     583       32164 :         test();
     584       32164 :         test();
     585       32164 :         test();
     586       32164 :         test();
     587       32164 :         test();
     588       32164 :         IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) )
     589       11208 :         {
     590       11208 :             Word16 numZeros = (Word16) ( NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ) ); /*Q0*/
     591             :             Word32 tmp_fade_fx[max( STEREO_DFT_ALLPASS_FADELEN_12k8, STEREO_DFT_ALLPASS_FADELEN_16k )];
     592             : 
     593       11208 :             Copy32( st->hHQ_core->old_out_LB_fx32 + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); /*st->hHQ_core->q_old_outLB_fx*/
     594             : #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT
     595       11208 :             hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->Q_old_out_fx32;
     596             : #else
     597             :             hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->q_old_outLB_fx;
     598             : #endif
     599       11208 :             move16();
     600             : 
     601       11208 :             test();
     602       11208 :             test();
     603       11208 :             test();
     604       11208 :             test();
     605       11208 :             test();
     606       11208 :             IF( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) && !st->tcxonly )
     607             :             {
     608         774 :                 Copy32( tcx_core_buf_fx, pAp_input_fx, st->L_frame ); /*q*/
     609             :             }
     610             :             ELSE
     611             :             {
     612       10434 :                 Copy32( output_fx, pAp_input_fx, st->L_frame ); /*q*/
     613             :             }
     614             : 
     615       11208 :             IF( EQ_16( st->last_core, ACELP_CORE ) && EQ_16( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) && !st->tcxonly ) /* ACELP -> TCX/HQ-Core */
     616             :             {
     617         774 :                 Copy32( tcx_core_buf_fx, tmp_fade_fx, ap_fade_len ); /*q*/
     618       28702 :                 FOR( i = 0; i < ap_fade_len; i++ )
     619             :                 {
     620       27928 :                     pAp_input_fx[i] = L_add(
     621             :                         Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ),
     622             :                         Mpy_32_32( tmp_fade_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); /*q + qap_fade_len - 31*/
     623       27928 :                     move32();
     624       27928 :                     pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/
     625       27928 :                     move32();
     626             :                 }
     627             :             }
     628             :         }
     629             :         ELSE
     630             :         {
     631       20956 :             Copy32( output_fx, pAp_input_fx, st->L_frame ); /*q*/
     632       20956 :             IF( NE_16( st->last_core, ACELP_CORE ) )        /* TCX/HQ-Core -> ACELP */
     633             :             {
     634        1011 :                 Word16 shift = sub( hCPE->hStereoDft->q_ap_fade_mem_fx, q_DFT[0] );
     635       36027 :                 FOR( i = 0; i < ap_fade_len; i++ )
     636             :                 {
     637       70032 :                     pAp_input_fx[i] = L_add(
     638             :                         Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ),
     639       35016 :                         Mpy_32_32( L_shr( hCPE->hStereoDft->ap_fade_mem_fx[i], shift ), L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); /*q + qap_fade_len - 31*/
     640       35016 :                     move32();
     641       35016 :                     pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/
     642       35016 :                     move32();
     643             :                 }
     644             :             }
     645             :         }
     646       32164 :         predelay = NS2SA_FX2( st->sr_core, DELAY_BWE_TOTAL_NS ); /*Q0*/
     647       32164 :         move16();
     648             : 
     649             :         /* apply predelay to have same overall filter delay FOR all cases */
     650             : 
     651       32164 :         delay_signal_q_adj_fx( pAp_input_fx, st->L_frame, hCPE->hStereoDft->ap_delay_mem_fx, predelay, *q, hCPE->hStereoDft->q_ap_delay_mem_fx );
     652             : 
     653             :         /* input zeroes FOR transient frames */
     654       32164 :         IF( hCPE->hStereoDft->attackPresent )
     655             :         {
     656         941 :             IF( hCPE->hStereoDft->ap_wasTransient )
     657             :             {
     658          73 :                 set32_fx( pAp_input_fx, 0, ap_fade_len );
     659             :             }
     660             :             ELSE
     661             :             {
     662       31076 :                 FOR( i = 0; i < ap_fade_len; i++ )
     663             :                 {
     664       30208 :                     pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ); /*q + qap_fade_len - 31*/
     665       30208 :                     move32();
     666       30208 :                     pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/
     667       30208 :                     move32();
     668             :                 }
     669             :             }
     670         941 :             set32_fx( pAp_input_fx + ap_fade_len, 0, st->L_frame - ap_fade_len );
     671         941 :             hCPE->hStereoDft->ap_wasTransient = 1;
     672         941 :             move16();
     673             :         }
     674       31223 :         ELSE IF( hCPE->hStereoDft->ap_wasTransient )
     675             :         {
     676       30994 :             FOR( i = 0; i < ap_fade_len; i++ )
     677             :             {
     678       30128 :                 pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ); /*q + qap_fade_len - 31*/
     679       30128 :                 move32();
     680       30128 :                 pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); /*q*/
     681       30128 :                 move32();
     682             :             }
     683         866 :             hCPE->hStereoDft->ap_wasTransient = 0;
     684         866 :             move16();
     685             :         }
     686             : 
     687             :         /* apply 5-stage allpass, each stage consisting of a nested allpass pair */
     688       32164 :         filter_with_allpass_fx( pAp_input_fx, pAp_input_fx, st->L_frame, &hCPE->hStereoDft->ap1, *q );
     689       32164 :         filter_with_allpass_fx( pAp_input_fx, pAp_input_fx, st->L_frame, &hCPE->hStereoDft->ap2, *q );
     690       32164 :         filter_with_allpass_fx( pAp_input_fx, pAp_input_fx, st->L_frame, &hCPE->hStereoDft->ap3, *q );
     691             : 
     692             :         /* apply DFT to allpass-filtered signal */
     693       32164 :         stereo_dft_dec_analyze_fx( hCPE, pAp_input_fx, DFT_fx, 1, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, q, q_DFT );
     694       32164 :         hCPE->hStereoDft->q_ap_delay_mem_fx = *q;
     695       32164 :         move16();
     696             :     }
     697             : 
     698       63558 :     IF( EQ_16( st->core, ACELP_CORE ) )
     699             :     {
     700       46053 :         IF( !use_cldfb_for_dft ) /* Skip this FOR DFT Stereo mono output at non-residual bitrates */
     701             :         {
     702       31319 :             L_lerp_fx_q11( output_fx, synth_fx, output_frame, hCPE->hCoreCoder[0]->L_frame ); /* Dirty resampling, but should be good enough FOR ECU analysis */
     703             :         }
     704       46053 :         test();
     705       46053 :         test();
     706       46053 :         test();
     707       46053 :         test();
     708       46053 :         test();
     709       46053 :         IF( !use_cldfb_for_dft || ( ( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && EQ_16( st->cng_type, LP_CNG ) && EQ_16( st->extl, SWB_CNG ) && EQ_16( hCPE->nchan_out, 1 ) ) )
     710             :         {
     711       32118 :             v_add_fx( synth_fx, hb_synth_fx, synth_fx, output_frame ); /* Use one channel TD-BWE FOR ECU analysis buffer */ /*q*/
     712             :         }
     713             :     }
     714             : 
     715             : 
     716       63558 :     return;
     717             : }

Generated by: LCOV version 1.14