LCOV - code coverage report
Current view: top level - lib_dec - ivas_post_proc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- conformance test test_26252.py @ a21f94bc6bac334fe001a5bad2f7b32b79038097 Lines: 174 175 99.4 %
Date: 2025-11-01 05:07:43 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.h"
      39             : #include "ivas_prot.h"
      40             : #include "ivas_cnst.h"
      41             : #ifdef DEBUGGING
      42             : #include "debug.h"
      43             : #endif
      44             : #include "wmc_auto.h"
      45             : 
      46             : /*-------------------------------------------------------------------------
      47             :  * ivas_post_proc()
      48             :  *
      49             :  * IVAS post-processing
      50             :  * - in SCE, post-processing of output channel
      51             :  * - in CPE_DFT, post-processing on output channels
      52             :  * - in CPE_TD, post-processing on decoded channels before upmixing
      53             :  *-------------------------------------------------------------------------*/
      54             : 
      55     2077208 : void ivas_post_proc(
      56             :     SCE_DEC_HANDLE hSCE,                /* i/o: SCE decoder structure              */
      57             :     CPE_DEC_HANDLE hCPE,                /* i/o: CPE decoder structure              */
      58             :     const int16_t n,                    /* i  : channel number                     */
      59             :     float synth[],                      /* i/o: output synthesis signal            */
      60             :     float *output[CPE_CHANNELS],        /* i/o: output synthesis signal            */
      61             :     const int16_t output_frame,         /* i  : output frame length                */
      62             :     const int16_t sba_dirac_stereo_flag /* i  : signal stereo output for SBA DirAC */
      63             : )
      64             : {
      65             : #ifndef DEBUG_STEREO_DFT_NOCORE
      66             :     int16_t k;
      67             : #endif
      68             :     int16_t delay_comp;
      69             :     int32_t output_Fs;
      70             :     Decoder_State **sts;
      71             :     TCX_LTP_DEC_HANDLE hTcxLtpDec;
      72             : 
      73     2077208 :     if ( hSCE != NULL )
      74             :     {
      75      444962 :         sts = hSCE->hCoreCoder;
      76             :     }
      77             :     else
      78             :     {
      79     1632246 :         sts = hCPE->hCoreCoder;
      80             :     }
      81             : 
      82     2077208 :     output_Fs = sts[0]->output_Fs;
      83             : 
      84     2077208 :     if ( ( sts[n]->element_mode != IVAS_CPE_DFT && !( sba_dirac_stereo_flag && sts[n]->element_mode != IVAS_CPE_MDCT ) ) || ( sts[n]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) )
      85             :     {
      86     2025157 :         if ( sts[n]->hTcxLtpDec != NULL )
      87             :         {
      88     2021357 :             hTcxLtpDec = sts[n]->hTcxLtpDec;
      89             : 
      90     2021357 :             if ( sts[n]->core != TCX_20_CORE && sts[n]->core != TCX_10_CORE )
      91             :             {
      92             :                 /* TCX-LTP Postfilter: used in Mode 1 to update memories and to avoid discontinuities when the past frame was TCX */
      93      229506 :                 tcx_ltp_post( sts[n], hTcxLtpDec, ACELP_CORE, output_frame, 0, synth, NULL );
      94             :             }
      95             :             else
      96             :             {
      97             :                 /* set delay */
      98     1791851 :                 delay_comp = NS2SA( output_Fs, DELAY_CLDFB_NS );
      99             : 
     100     1791851 :                 if ( !( sts[n]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) && sts[n]->element_mode != IVAS_CPE_MDCT )
     101             :                 {
     102      277429 :                     mvr2r( sts[n]->prev_synth_buffer, sts[n]->hTcxDec->FBTCXdelayBuf, 0 );
     103      277429 :                     mvr2r( sts[n]->delay_buf_out, sts[n]->hTcxDec->FBTCXdelayBuf + 0, delay_comp );
     104             :                 }
     105     1514422 :                 else if ( sba_dirac_stereo_flag && sts[n]->element_mode == IVAS_CPE_MDCT )
     106             :                 {
     107       22391 :                     int16_t numZeros = (int16_t) ( NS2SA( output_Fs, N_ZERO_MDCT_NS ) );
     108       22391 :                     mvr2r( sts[n]->hHQ_core->old_out + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf, delay_comp );
     109             :                 }
     110             : 
     111     1791851 :                 tcx_ltp_post( sts[n], hTcxLtpDec, sts[n]->core, output_frame, NS2SA( output_Fs, ACELP_LOOK_NS ) + delay_comp, synth, sts[n]->hTcxDec->FBTCXdelayBuf );
     112             :             }
     113             :         }
     114             :     }
     115             :     else /* IVAS_CPE_DFT */
     116             :     {
     117             : #ifndef DEBUG_STEREO_DFT_NOCORE
     118             :         int16_t pit_res_max_past_tmp;
     119             : 
     120       52051 :         pit_res_max_past_tmp = sts[0]->pit_res_max_past;
     121      150811 :         for ( k = 0; k < hCPE->nchan_out; k++ )
     122             :         {
     123       98760 :             if ( k == 0 )
     124             :             {
     125       52051 :                 hTcxLtpDec = sts[0]->hTcxLtpDec;
     126             :             }
     127             :             else
     128             :             {
     129       46709 :                 hTcxLtpDec = hCPE->hStereoDft->hTcxLtpDec;
     130             :                 /* copy LTP side-info of downmix channel also to right channel struct */
     131       46709 :                 hTcxLtpDec->tcxltp = sts[0]->hTcxLtpDec->tcxltp;
     132       46709 :                 hTcxLtpDec->tcxltp_gain = sts[0]->hTcxLtpDec->tcxltp_gain;
     133       46709 :                 hTcxLtpDec->tcxltp_pitch_int = sts[0]->hTcxLtpDec->tcxltp_pitch_int;
     134       46709 :                 hTcxLtpDec->tcxltp_pitch_fr = sts[0]->hTcxLtpDec->tcxltp_pitch_fr;
     135             :                 /* revert update of pit_res_max_past to have correct value also in right channel */
     136       46709 :                 sts[0]->pit_res_max_past = pit_res_max_past_tmp;
     137             :             }
     138             : 
     139             :             /*TCX-LTP*/
     140       98760 :             if ( sts[0]->core != TCX_20_CORE && sts[0]->core != TCX_10_CORE )
     141             :             {
     142             :                 /* update memories and to avoid discontinuities when the past frame was TCX */
     143       63952 :                 tcx_ltp_post( sts[0], hTcxLtpDec, ACELP_CORE, output_frame, 0, output[k], NULL );
     144             :             }
     145             :             else
     146             :             {
     147             :                 /*Use channel 0 side info.*/
     148       34808 :                 tcx_ltp_post( sts[0], hTcxLtpDec, TCX_20_CORE, output_frame, NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ), output[k], hCPE->output_mem[k] );
     149             :             }
     150             :         }
     151             : #endif
     152             :     }
     153             : 
     154     2077208 :     return;
     155             : }
     156             : 
     157             : 
     158             : /*-------------------------------------------------------------------------
     159             :  * stereo_dft_dec_core_switching()
     160             :  *
     161             :  * core switching in DFT stereo
     162             :  *-------------------------------------------------------------------------*/
     163             : 
     164       90488 : void stereo_dft_dec_core_switching(
     165             :     CPE_DEC_HANDLE hCPE,                         /* i/o: CPE decoder structure               */
     166             :     float output[],                              /* i/o: synthesis @internal Fs              */
     167             :     float synth[],                               /* i/o: synthesis @output Fs                */
     168             :     float hb_synth[],                            /* i/o: hb synthesis                        */
     169             :     float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o  : DFT buffers                         */
     170             :     const int16_t output_frame,                  /* i  : output frame length                 */
     171             :     const int16_t use_cldfb_for_dft,             /* i  : flag to use of CLDFB for DFT Stereo */
     172             :     const int16_t sba_dirac_stereo_dtx_flag      /* i  : DTX indicator for SBA DirAC stereo  */
     173             : )
     174             : {
     175             :     int16_t i, tmps;
     176             :     int16_t delay_dft_dec, delay_dft_dec_lb, delay_tdbwe, delay_comp;
     177             :     int16_t L_frameTCX;
     178             :     int32_t output_Fs;
     179             :     Decoder_State *st;
     180             :     int16_t predelay, ap_fade_len;
     181             :     float pAp_input[L_FRAME16k];
     182             : #ifndef DEBUG_STEREO_DFT_NOCORE
     183             :     float tcx_core_buf[L_FRAME16k];
     184             :     float synth_tmp[L_FRAME48k];
     185             : #endif
     186             : 
     187       90488 :     st = hCPE->hCoreCoder[0]; /* in DFT stereo, only M channel is decoded by the CoreCoder */
     188       90488 :     output_Fs = st->output_Fs;
     189       90488 :     L_frameTCX = st->hTcxDec->L_frameTCX;
     190             : 
     191             :     /*TBE*/
     192       90488 :     delay_tdbwe = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS );
     193       90488 :     delay_dft_dec = NS2SA( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS );
     194       90488 :     delay_dft_dec_lb = NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT_DELAY_DEC_BWE_NS );
     195             : 
     196             :     /* TCX/ACELP/HQ-CORE->TCX */
     197       90488 :     tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS );                          /*cross-fading size @ FB*/
     198       90488 :     delay_comp = NS2SA( st->L_frame * FRAMES_PER_SEC, DELAY_BWE_TOTAL_NS ); /*cross-fading size @ LB*/
     199             : 
     200             : #if defined( DEBUG_MODE_DFT ) && defined( DEBUG_STEREO_DFT_NOCORE )
     201             :     stereo_dft_dec_analyze( hCPE, output, DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_NOCORE, 0, 0 );
     202             : #else
     203             :     /* resample DFT analysis memories in case of internal sampling rate change */
     204       90488 :     if ( st->last_L_frame != st->L_frame && st->last_L_frame <= L_FRAME16k && st->L_frame <= L_FRAME16k )
     205             :     {
     206         367 :         lerp( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     207         367 :         lerp( hCPE->input_mem_BPF[0], hCPE->input_mem_BPF[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     208             :     }
     209             : 
     210       90488 :     if ( st->prev_bfi && !( st->last_core_bfi == ACELP_CORE && st->last_con_tcx == 1 ) )
     211             :     {
     212             :         /* last_core needed for correctly decoding ACELP->TCX/HQ switching frames in ivas_core_dec().
     213             :            In the following steps the decoder needs to consider if the core was changed due to a lost frame to apply the correct transition */
     214        2260 :         st->last_core = st->last_core_bfi;
     215             :     }
     216             : 
     217       90488 :     if ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE || ( st->bfi == 1 && st->core == ACELP_CORE && st->con_tcx == 1 ) )
     218             :     {
     219             : #ifdef DEBUGGING
     220             :         assert( L_frameTCX == output_frame );
     221             : #endif
     222       22318 :         if ( ( ( st->last_core != ACELP_CORE || ( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) && st->last_core != AMR_WB_CORE ) || ( sba_dirac_stereo_dtx_flag && st->cng_type == FD_CNG ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */
     223             :         {
     224             :             /* In case of a TCX to ACELP switch next frame */
     225       20808 :             mvr2r( &output[st->L_frame - NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem, NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     226             : 
     227             :             /* BPF */
     228       20808 :             if ( st->p_bpf_noise_buf && st->core != HQ_CORE )
     229             :             {
     230       19700 :                 stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 2, 0 );
     231             :             }
     232             :             /* st->p_bpf_noise_buf not updated for HQ core -> skip analysis and set input memory to zero */
     233        1108 :             else if ( st->p_bpf_noise_buf && st->core == HQ_CORE )
     234             :             {
     235        1108 :                 set_zero( hCPE->input_mem_BPF[0], STEREO_DFT32MS_OVL_16k );
     236             :             }
     237             : 
     238             :             /* TCX */
     239       20808 :             stereo_dft_dec_analyze( hCPE, synth, DFT, 0, L_frameTCX, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0 );
     240             :         }
     241        1510 :         else if ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) /* ACELP -> TCX/HQ */
     242             :         {
     243        1510 :             if ( st->last_core_brate <= SID_2k40 && st->element_mode == IVAS_SCE )
     244           2 :             {
     245           2 :                 int16_t mem_len = NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS );
     246         302 :                 for ( i = 0; i < mem_len; i++ )
     247             :                 {
     248         300 :                     hCPE->input_mem[0][i] *= ( mem_len - i ) / mem_len;
     249             :                 }
     250             : 
     251             :                 /* Update FB input buff with hb synth for last delay_tdbwe sampled */
     252         224 :                 for ( i = 0; i < delay_tdbwe; i++ )
     253             :                 {
     254         222 :                     hCPE->input_mem[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i] += hb_synth[i];
     255             :                 }
     256             :             }
     257             :             else
     258             :             {
     259             :                 /* Update FB input buff with hb synth for last delay_tdbwe sampled */
     260      129454 :                 for ( i = 0; i < delay_tdbwe; i++ )
     261             :                 {
     262      127946 :                     hCPE->input_mem[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i] = hb_synth[i];
     263             :                 }
     264             :             }
     265             : 
     266             :             /* cross-fading between (delayed) TBE and FB-TCX over 2.3125ms */
     267        1510 :             mvr2r( synth, synth_tmp, output_frame );
     268      129678 :             for ( i = 0; i < tmps; i++ )
     269             :             {
     270      128168 :                 synth_tmp[i] = ( hb_synth[i + delay_tdbwe] * ( tmps - i ) + synth[i] * i ) / tmps;
     271             :             }
     272             : 
     273             :             /* FB-TCX */
     274        1510 :             stereo_dft_dec_analyze( hCPE, synth_tmp, DFT, 0, L_frameTCX, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0 );
     275             : 
     276        1510 :             if ( !st->tcxonly )
     277             :             {
     278        1510 :                 if ( hCPE->hStereoDft->hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF )
     279             :                 {
     280         984 :                     mvr2r( output, tcx_core_buf, L_FRAME16k );
     281             :                 }
     282             :                 /* fading-out LB-TCX/ACELP */
     283       53436 :                 for ( i = 0; i < delay_comp; i++ )
     284             :                 {
     285       51926 :                     output[i] = ( output[i] * ( delay_comp - i ) ) / delay_comp;
     286             :                 }
     287             : 
     288             :                 /* 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 */
     289             :                 /* 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
     290             :                 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 */
     291        1510 :                 mvr2r( &output[st->L_frame - NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem, NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     292             : 
     293             :                 /*zero the rest for avoiding adding contribution except the last samples which are not considered in DFT analysis (potentially used in next ACELP frame)*/
     294        1510 :                 if ( st->last_core_brate > SID_2k40 )
     295             :                 {
     296      384812 :                     for ( ; i < st->L_frame; i++ )
     297             :                     {
     298      383361 :                         output[i] = 0.0f;
     299             :                     }
     300             : 
     301        1451 :                     stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB_ADD, 1, 0 );
     302             : 
     303             :                     /* BPF */
     304        1451 :                     if ( st->p_bpf_noise_buf )
     305             :                     {
     306        1451 :                         set_zero( hCPE->input_mem_BPF[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     307             :                     }
     308             :                 }
     309             :             }
     310             :         }
     311             :     }
     312             :     else /* ACELP core */
     313             :     {
     314       68170 :         if ( st->core_brate <= SID_2k40 && !( sba_dirac_stereo_dtx_flag ) )
     315             :         {
     316       10268 :             set_zero( hCPE->input_mem[0], NS2SA( st->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     317       10268 :             set_zero( hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     318             : 
     319             :             /* CNG generated in ivas_cpe_dec() */
     320             :         }
     321       57902 :         else if ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE || st->last_core == HQ_CORE ) /* TCX/HQ -> ACELP */
     322             :         {
     323        1877 :             if ( ( st->last_L_frame <= L_FRAME16k && st->L_frame <= L_FRAME16k ) || ( sba_dirac_stereo_dtx_flag && st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) )
     324             :             {
     325             :                 /* In case of a TCX to ACELP switch, retrieve the LB-TCX memories for the first STEREO_DFT32MS_OVL_NS NS of OLA */
     326        1402 :                 lerp( hCPE->hStereoDft->buff_LBTCX_mem, hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     327             :             }
     328             : 
     329        1877 :             if ( sba_dirac_stereo_dtx_flag && st->core_brate == SID_2k40 && st->cng_type == FD_CNG )
     330           3 :             {
     331             :                 int16_t nZeros;
     332           3 :                 nZeros = (int16_t) ( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) );
     333           3 :                 delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
     334             : 
     335           3 :                 mvr2r( &st->hHQ_core->old_out[nZeros - delay_comp - NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )], hCPE->input_mem[0], NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     336           3 :                 mvr2r( synth, synth_tmp, output_frame );
     337             : 
     338             :                 int16_t mem_len;
     339           3 :                 mem_len = NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS );
     340             :                 float fac;
     341           3 :                 fac = 1.0f / mem_len;
     342         153 :                 for ( i = 0; i < mem_len; i++ )
     343             :                 {
     344         150 :                     hCPE->input_mem_LB[0][i] *= ( 1 - i * fac );
     345             :                 }
     346           3 :                 set_zero( output, st->L_frame );
     347             : 
     348           3 :                 stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 );
     349             : 
     350             :                 /* BPF */
     351           3 :                 if ( st->p_bpf_noise_buf )
     352             :                 {
     353           3 :                     stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 );
     354             :                 }
     355             :             }
     356             :             else
     357             :             {
     358             :                 /* ACELP */
     359       52394 :                 for ( i = 0; i < ( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ); i++ )
     360             :                 {
     361       50520 :                     hCPE->input_mem_LB[0][i] = 0.f;
     362             :                 }
     363             :                 /* ACELP fading-in*/
     364       35554 :                 for ( i = 0; i < delay_dft_dec_lb; i++ )
     365             :                 {
     366       33680 :                     hCPE->input_mem_LB[0][NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb + i] *= (float) ( i ) / (float) ( delay_dft_dec_lb );
     367             :                 }
     368             : 
     369        1874 :                 stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 );
     370             : 
     371             :                 /* BPF */
     372        1874 :                 if ( st->p_bpf_noise_buf )
     373             :                 {
     374        1399 :                     stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 );
     375             :                 }
     376             : 
     377             :                 /* Fading-in TD-BWE, Fading-out FB-TCX*/
     378        1874 :                 mvr2r( synth, synth_tmp, output_frame );
     379        1874 :                 if ( hCPE->last_element_mode != IVAS_CPE_MDCT )
     380             :                 {
     381       65935 :                     for ( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade-in and TCX fade-out */
     382             :                     {
     383       64560 :                         hCPE->input_mem[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec + i] = ( hb_synth[delay_tdbwe - delay_dft_dec + i] * ( i ) + hCPE->input_mem[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec + i] * ( delay_dft_dec - i ) ) / ( delay_dft_dec );
     384             :                     }
     385       65935 :                     for ( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade out. ICBWE fade in performed in time domain here */
     386             :                     {
     387       64560 :                         synth_tmp[i] = ( hb_synth[delay_tdbwe - delay_dft_dec + i] * ( delay_dft_dec - i ) ) / delay_dft_dec;
     388             :                     }
     389             : 
     390      969775 :                     for ( ; i < output_frame; i++ )
     391             :                     {
     392      968400 :                         synth_tmp[i] = 0;
     393             :                     }
     394             :                 }
     395             :             }
     396             : 
     397        1877 :             if ( sba_dirac_stereo_dtx_flag )
     398             :             {
     399           3 :                 stereo_dft_dec_analyze( hCPE, synth_tmp, DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 0, 0 );
     400             :             }
     401        1874 :             else if ( hCPE->last_element_mode == IVAS_CPE_MDCT )
     402             :             {
     403         499 :                 stereo_dft_dec_analyze( hCPE, synth_tmp, DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_HB_ADD, 1, 0 );
     404             :             }
     405             :             else
     406             :             {
     407        1375 :                 stereo_dft_dec_analyze( hCPE, synth_tmp, DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 1, 0 );
     408             :             }
     409             :         }
     410             :         else /* ACELP -> ACELP */
     411             :         {
     412       56025 :             if ( sba_dirac_stereo_dtx_flag && st->core_brate <= SID_2k40 && st->cng_type == FD_CNG )
     413             :             {
     414          88 :                 set_zero( output, st->L_frame );
     415             :             }
     416             :             /* this needs an indication for sba2stereo in general */
     417       55937 :             else if ( hCPE->element_mode == IVAS_SCE && st->last_core_brate <= SID_2k40 && st->cng_type == FD_CNG )
     418             :             {
     419           0 :                 lerp( hCPE->input_mem[0], hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     420             :             }
     421             : 
     422             :             /* ACELP synthesis @ internal sampling rate */
     423       56025 :             stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 );
     424             : 
     425             :             /* BPF */
     426       56025 :             if ( st->p_bpf_noise_buf )
     427             :             {
     428       53788 :                 stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 );
     429             :             }
     430             : 
     431             :             /* BWE */
     432       56025 :             if ( sba_dirac_stereo_dtx_flag && st->core_brate <= SID_2k40 && st->cng_type == FD_CNG )
     433             :             {
     434          88 :                 stereo_dft_dec_analyze( hCPE, synth, DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 0, 0 );
     435             :             }
     436       55937 :             else if ( st->extl != -1 || ( st->bws_cnt > 0 && st->core == ACELP_CORE ) )
     437             :             {
     438       51348 :                 stereo_dft_dec_analyze( hCPE, hb_synth, DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 2, -delay_tdbwe );
     439             :             }
     440             :         }
     441             :     }
     442             : #endif
     443             : 
     444             :     /*----------------------------------------------------------------*
     445             :      * enhanced stereo filling: allpass filter
     446             :      *----------------------------------------------------------------*/
     447             : 
     448       90488 :     if ( hCPE->hStereoDft->hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF )
     449             :     {
     450             : #if defined( DEBUG_MODE_INFO ) && defined( DEBUG_STEREO_DFT_NOCORE )
     451             :         {
     452             :             char file_name[100];
     453             :             int16_t tmp[320];
     454             :             {
     455             :                 sprintf( file_name, "./res/stereo_dft_enc_M_S_%d_c%d_b0.pcm", st->L_frame * FRAMES_PER_SEC, 0 );
     456             :             }
     457             :             dbgread( tmp, sizeof( int16_t ), st->L_frame, file_name );
     458             :             for ( i = 0; i < st->L_frame; i++ )
     459             :             {
     460             :                 pAp_input[i] = (float) ( tmp[i] );
     461             :             }
     462             :         }
     463             : #endif
     464       38310 :         if ( st->sr_core == INT_FS_12k8 )
     465             :         {
     466       20381 :             ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_12k8;
     467             :         }
     468             :         else
     469             :         {
     470       17929 :             ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_16k;
     471             :         }
     472             : 
     473             : #if !defined( DEBUG_MODE_INFO ) || !defined( DEBUG_STEREO_DFT_NOCORE )
     474       38310 :         if ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE || ( st->bfi == 1 && st->core == ACELP_CORE && st->con_tcx == 1 ) )
     475       15755 :         {
     476       15755 :             int16_t numZeros = (int16_t) ( NS2SA( st->sr_core, N_ZERO_MDCT_NS ) );
     477             :             float tmp_fade[max( STEREO_DFT_ALLPASS_FADELEN_12k8, STEREO_DFT_ALLPASS_FADELEN_16k )];
     478             : 
     479       15755 :             mvr2r( st->hHQ_core->old_outLB + numZeros, hCPE->hStereoDft->ap_fade_mem, ap_fade_len );
     480             : 
     481       15755 :             if ( st->last_core == ACELP_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) && !st->tcxonly )
     482             :             {
     483         984 :                 mvr2r( tcx_core_buf, pAp_input, st->L_frame );
     484             :             }
     485             :             else
     486             :             {
     487       14771 :                 mvr2r( output, pAp_input, st->L_frame );
     488             :             }
     489             : 
     490       15755 :             if ( st->last_core == ACELP_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) && !st->tcxonly ) /* ACELP -> TCX/HQ-Core */
     491             :             {
     492         984 :                 mvr2r( tcx_core_buf, tmp_fade, ap_fade_len );
     493       37112 :                 for ( i = 0; i < ap_fade_len; i++ )
     494             :                 {
     495       36128 :                     pAp_input[i] = ( pAp_input[i] * i + tmp_fade[i] * ( ap_fade_len - i ) ) / ap_fade_len;
     496             :                 }
     497             :             }
     498             :         }
     499             :         else
     500             :         {
     501       22555 :             mvr2r( output, pAp_input, st->L_frame );
     502       22555 :             if ( st->last_core != ACELP_CORE ) /* TCX/HQ-Core -> ACELP */
     503             :             {
     504       46457 :                 for ( i = 0; i < ap_fade_len; i++ )
     505             :                 {
     506       45176 :                     pAp_input[i] = ( pAp_input[i] * i + hCPE->hStereoDft->ap_fade_mem[i] * ( ap_fade_len - i ) ) / ap_fade_len;
     507             :                 }
     508             :             }
     509             :         }
     510             : #endif
     511       38310 :         predelay = NS2SA( st->sr_core, DELAY_BWE_TOTAL_NS );
     512             : 
     513             :         /* apply predelay to have same overall filter delay for all cases */
     514       38310 :         delay_signal( pAp_input, st->L_frame, hCPE->hStereoDft->ap_delay_mem, predelay );
     515             : 
     516             : #ifdef DEBUG_MODE_DFT
     517             :         {
     518             :             int16_t v;
     519             :             int16_t out_ap[L_FRAME16k];
     520             : 
     521             :             for ( v = 0; v < st->L_frame; v++ )
     522             :             {
     523             :                 out_ap[v] = (int16_t) pAp_input[v];
     524             :             }
     525             : 
     526             :             dbgwrite( out_ap, sizeof( int16_t ), st->L_frame, 1, "res/stereo_dft_allpass_input.pcm" );
     527             :         }
     528             : #endif /*DEBUG_MODE_DFT*/
     529             : 
     530             :         /* input zeroes for transient frames */
     531       38310 :         if ( hCPE->hStereoDft->attackPresent )
     532             :         {
     533        1145 :             float inv_tmps = 1.f / ap_fade_len;
     534        1145 :             if ( hCPE->hStereoDft->ap_wasTransient )
     535             :             {
     536          99 :                 set_zero( pAp_input, ap_fade_len );
     537             :             }
     538             :             else
     539             :             {
     540       38222 :                 for ( i = 0; i < ap_fade_len; i++ )
     541             :                 {
     542       37176 :                     pAp_input[i] *= ( ap_fade_len - i ) * inv_tmps;
     543             :                 }
     544             :             }
     545        1145 :             set_zero( pAp_input + ap_fade_len, st->L_frame - ap_fade_len );
     546        1145 :             hCPE->hStereoDft->ap_wasTransient = 1;
     547             :         }
     548       37165 :         else if ( hCPE->hStereoDft->ap_wasTransient )
     549             :         {
     550        1043 :             float inv_tmps = 1.f / ap_fade_len;
     551       38099 :             for ( i = 0; i < ap_fade_len; i++ )
     552             :             {
     553       37056 :                 pAp_input[i] *= i * inv_tmps;
     554             :             }
     555        1043 :             hCPE->hStereoDft->ap_wasTransient = 0;
     556             :         }
     557             : 
     558             :         /* apply 5-stage allpass, each stage consisting of a nested allpass pair */
     559       38310 :         filter_with_allpass( pAp_input, pAp_input, st->L_frame, &hCPE->hStereoDft->ap1 );
     560       38310 :         filter_with_allpass( pAp_input, pAp_input, st->L_frame, &hCPE->hStereoDft->ap2 );
     561       38310 :         filter_with_allpass( pAp_input, pAp_input, st->L_frame, &hCPE->hStereoDft->ap3 );
     562             : 
     563             : #ifdef DEBUG_MODE_DFT
     564             :         {
     565             :             int16_t v;
     566             :             int16_t out_ap[L_FRAME16k];
     567             :             for ( v = 0; v < st->L_frame; v++ )
     568             :             {
     569             :                 out_ap[v] = (int16_t) pAp_input[v];
     570             :             }
     571             : 
     572             :             dbgwrite( out_ap, sizeof( int16_t ), st->L_frame, 1, "res/stereo_dft_allpass.pcm" );
     573             :         }
     574             : #endif /*DEBUG_MODE_DFT*/
     575             :         /* apply DFT to allpass-filtered signal */
     576       38310 :         stereo_dft_dec_analyze( hCPE, pAp_input, DFT, 1, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0 );
     577             :     }
     578             : 
     579       90488 :     if ( st->core == ACELP_CORE )
     580             :     {
     581       68276 :         if ( !use_cldfb_for_dft ) /* Skip this for DFT Stereo mono output at non-residual bitrates */
     582             :         {
     583       32948 :             lerp( output, synth, output_frame, hCPE->hCoreCoder[0]->L_frame ); /* Dirty resampling, but should be good enough for ECU analysis */
     584             :         }
     585       68276 :         if ( !use_cldfb_for_dft || ( ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && st->cng_type == LP_CNG && st->extl == SWB_CNG && hCPE->nchan_out == 1 ) )
     586             :         {
     587       33753 :             v_add( synth, hb_synth, synth, output_frame ); /* Use one channel TD-BWE for ECU analysis buffer */
     588             :         }
     589             :     }
     590             : 
     591       90488 :     return;
     592             : }

Generated by: LCOV version 1.14