LCOV - code coverage report
Current view: top level - lib_dec - ivas_post_proc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 174 175 99.4 %
Date: 2025-05-23 08:37:30 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     3388248 : 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     3388248 :     if ( hSCE != NULL )
      74             :     {
      75     1033566 :         sts = hSCE->hCoreCoder;
      76             :     }
      77             :     else
      78             :     {
      79     2354682 :         sts = hCPE->hCoreCoder;
      80             :     }
      81             : 
      82     3388248 :     output_Fs = sts[0]->output_Fs;
      83             : 
      84     3388248 :     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     3249105 :         if ( sts[n]->hTcxLtpDec != NULL )
      87             :         {
      88     3237765 :             hTcxLtpDec = sts[n]->hTcxLtpDec;
      89             : 
      90     3237765 :             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      476814 :                 tcx_ltp_post( sts[n], hTcxLtpDec, ACELP_CORE, output_frame, 0, synth, NULL );
      94             :             }
      95             :             else
      96             :             {
      97             :                 /* set delay */
      98     2760951 :                 delay_comp = NS2SA( output_Fs, DELAY_CLDFB_NS );
      99             : 
     100     2760951 :                 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      649566 :                     mvr2r( sts[n]->prev_synth_buffer, sts[n]->hTcxDec->FBTCXdelayBuf, 0 );
     103      649566 :                     mvr2r( sts[n]->delay_buf_out, sts[n]->hTcxDec->FBTCXdelayBuf + 0, delay_comp );
     104             :                 }
     105     2111385 :                 else if ( sba_dirac_stereo_flag && sts[n]->element_mode == IVAS_CPE_MDCT )
     106             :                 {
     107       67173 :                     int16_t numZeros = (int16_t) ( NS2SA( output_Fs, N_ZERO_MDCT_NS ) );
     108       67173 :                     mvr2r( sts[n]->hHQ_core->old_out + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf, delay_comp );
     109             :                 }
     110             : 
     111     2760951 :                 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      139143 :         pit_res_max_past_tmp = sts[0]->pit_res_max_past;
     121      401403 :         for ( k = 0; k < hCPE->nchan_out; k++ )
     122             :         {
     123      262260 :             if ( k == 0 )
     124             :             {
     125      139143 :                 hTcxLtpDec = sts[0]->hTcxLtpDec;
     126             :             }
     127             :             else
     128             :             {
     129      123117 :                 hTcxLtpDec = hCPE->hStereoDft->hTcxLtpDec;
     130             :                 /* copy LTP side-info of downmix channel also to right channel struct */
     131      123117 :                 hTcxLtpDec->tcxltp = sts[0]->hTcxLtpDec->tcxltp;
     132      123117 :                 hTcxLtpDec->tcxltp_gain = sts[0]->hTcxLtpDec->tcxltp_gain;
     133      123117 :                 hTcxLtpDec->tcxltp_pitch_int = sts[0]->hTcxLtpDec->tcxltp_pitch_int;
     134      123117 :                 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      123117 :                 sts[0]->pit_res_max_past = pit_res_max_past_tmp;
     137             :             }
     138             : 
     139             :             /*TCX-LTP*/
     140      262260 :             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      183720 :                 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       78540 :                 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     3388248 :     return;
     155             : }
     156             : 
     157             : 
     158             : /*-------------------------------------------------------------------------
     159             :  * stereo_dft_dec_core_switching()
     160             :  *
     161             :  * core switching in DFT stereo
     162             :  *-------------------------------------------------------------------------*/
     163             : 
     164      192594 : 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      192594 :     st = hCPE->hCoreCoder[0]; /* in DFT stereo, only M channel is decoded by the CoreCoder */
     188      192594 :     output_Fs = st->output_Fs;
     189      192594 :     L_frameTCX = st->hTcxDec->L_frameTCX;
     190             : 
     191             :     /*TBE*/
     192      192594 :     delay_tdbwe = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS );
     193      192594 :     delay_dft_dec = NS2SA( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS );
     194      192594 :     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      192594 :     tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS );                          /*cross-fading size @ FB*/
     198      192594 :     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      192594 :     if ( st->last_L_frame != st->L_frame && st->last_L_frame <= L_FRAME16k && st->L_frame <= L_FRAME16k )
     205             :     {
     206        1023 :         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        1023 :         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      192594 :     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        4332 :         st->last_core = st->last_core_bfi;
     215             :     }
     216             : 
     217      192594 :     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       53697 :         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       49920 :             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       49920 :             if ( st->p_bpf_noise_buf && st->core != HQ_CORE )
     229             :             {
     230       46602 :                 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        3318 :             else if ( st->p_bpf_noise_buf && st->core == HQ_CORE )
     234             :             {
     235        3318 :                 set_zero( hCPE->input_mem_BPF[0], STEREO_DFT32MS_OVL_16k );
     236             :             }
     237             : 
     238             :             /* TCX */
     239       49920 :             stereo_dft_dec_analyze( hCPE, synth, DFT, 0, L_frameTCX, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0 );
     240             :         }
     241        3777 :         else if ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) /* ACELP -> TCX/HQ */
     242             :         {
     243        3777 :             if ( st->last_core_brate <= SID_2k40 && st->element_mode == IVAS_SCE )
     244           6 :             {
     245           6 :                 int16_t mem_len = NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS );
     246         906 :                 for ( i = 0; i < mem_len; i++ )
     247             :                 {
     248         900 :                     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         672 :                 for ( i = 0; i < delay_tdbwe; i++ )
     253             :                 {
     254         666 :                     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      304026 :                 for ( i = 0; i < delay_tdbwe; i++ )
     261             :                 {
     262      300255 :                     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        3777 :             mvr2r( synth, synth_tmp, output_frame );
     268      304698 :             for ( i = 0; i < tmps; i++ )
     269             :             {
     270      300921 :                 synth_tmp[i] = ( hb_synth[i + delay_tdbwe] * ( tmps - i ) + synth[i] * i ) / tmps;
     271             :             }
     272             : 
     273             :             /* FB-TCX */
     274        3777 :             stereo_dft_dec_analyze( hCPE, synth_tmp, DFT, 0, L_frameTCX, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0 );
     275             : 
     276        3777 :             if ( !st->tcxonly )
     277             :             {
     278        3777 :                 if ( hCPE->hStereoDft->hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF )
     279             :                 {
     280        2412 :                     mvr2r( output, tcx_core_buf, L_FRAME16k );
     281             :                 }
     282             :                 /* fading-out LB-TCX/ACELP */
     283      133470 :                 for ( i = 0; i < delay_comp; i++ )
     284             :                 {
     285      129693 :                     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        3777 :                 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        3777 :                 if ( st->last_core_brate > SID_2k40 )
     295             :                 {
     296      953016 :                     for ( ; i < st->L_frame; i++ )
     297             :                     {
     298      949416 :                         output[i] = 0.0f;
     299             :                     }
     300             : 
     301        3600 :                     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        3600 :                     if ( st->p_bpf_noise_buf )
     305             :                     {
     306        3600 :                         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      138897 :         if ( st->core_brate <= SID_2k40 && !( sba_dirac_stereo_dtx_flag ) )
     315             :         {
     316       30804 :             set_zero( hCPE->input_mem[0], NS2SA( st->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
     317       30804 :             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      108093 :         else if ( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE || st->last_core == HQ_CORE ) /* TCX/HQ -> ACELP */
     322             :         {
     323        4785 :             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        3435 :                 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        4785 :             if ( sba_dirac_stereo_dtx_flag && st->core_brate == SID_2k40 && st->cng_type == FD_CNG )
     330           9 :             {
     331             :                 int16_t nZeros;
     332           9 :                 nZeros = (int16_t) ( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) );
     333           9 :                 delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
     334             : 
     335           9 :                 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           9 :                 mvr2r( synth, synth_tmp, output_frame );
     337             : 
     338             :                 int16_t mem_len;
     339           9 :                 mem_len = NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS );
     340             :                 float fac;
     341           9 :                 fac = 1.0f / mem_len;
     342         459 :                 for ( i = 0; i < mem_len; i++ )
     343             :                 {
     344         450 :                     hCPE->input_mem_LB[0][i] *= ( 1 - i * fac );
     345             :                 }
     346           9 :                 set_zero( output, st->L_frame );
     347             : 
     348           9 :                 stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 );
     349             : 
     350             :                 /* BPF */
     351           9 :                 if ( st->p_bpf_noise_buf )
     352             :                 {
     353           9 :                     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      132756 :                 for ( i = 0; i < ( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ); i++ )
     360             :                 {
     361      127980 :                     hCPE->input_mem_LB[0][i] = 0.f;
     362             :                 }
     363             :                 /* ACELP fading-in*/
     364       90096 :                 for ( i = 0; i < delay_dft_dec_lb; i++ )
     365             :                 {
     366       85320 :                     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        4776 :                 stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 );
     370             : 
     371             :                 /* BPF */
     372        4776 :                 if ( st->p_bpf_noise_buf )
     373             :                 {
     374        3426 :                     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        4776 :                 mvr2r( synth, synth_tmp, output_frame );
     379        4776 :                 if ( hCPE->last_element_mode != IVAS_CPE_MDCT )
     380             :                 {
     381      150774 :                     for ( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade-in and TCX fade-out */
     382             :                     {
     383      147420 :                         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      150774 :                     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      147420 :                         synth_tmp[i] = ( hb_synth[delay_tdbwe - delay_dft_dec + i] * ( delay_dft_dec - i ) ) / delay_dft_dec;
     388             :                     }
     389             : 
     390     2214654 :                     for ( ; i < output_frame; i++ )
     391             :                     {
     392     2211300 :                         synth_tmp[i] = 0;
     393             :                     }
     394             :                 }
     395             :             }
     396             : 
     397        4785 :             if ( sba_dirac_stereo_dtx_flag )
     398             :             {
     399           9 :                 stereo_dft_dec_analyze( hCPE, synth_tmp, DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 0, 0 );
     400             :             }
     401        4776 :             else if ( hCPE->last_element_mode == IVAS_CPE_MDCT )
     402             :             {
     403        1422 :                 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        3354 :                 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      103308 :             if ( sba_dirac_stereo_dtx_flag && st->core_brate <= SID_2k40 && st->cng_type == FD_CNG )
     413             :             {
     414         264 :                 set_zero( output, st->L_frame );
     415             :             }
     416             :             /* this needs an indication for sba2stereo in general */
     417      103044 :             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      103308 :             stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 );
     424             : 
     425             :             /* BPF */
     426      103308 :             if ( st->p_bpf_noise_buf )
     427             :             {
     428       97215 :                 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      103308 :             if ( sba_dirac_stereo_dtx_flag && st->core_brate <= SID_2k40 && st->cng_type == FD_CNG )
     433             :             {
     434         264 :                 stereo_dft_dec_analyze( hCPE, synth, DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 0, 0 );
     435             :             }
     436      103044 :             else if ( st->extl != -1 || ( st->bws_cnt > 0 && st->core == ACELP_CORE ) )
     437             :             {
     438       89277 :                 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      192594 :     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       98130 :         if ( st->sr_core == INT_FS_12k8 )
     465             :         {
     466       60285 :             ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_12k8;
     467             :         }
     468             :         else
     469             :         {
     470       37845 :             ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_16k;
     471             :         }
     472             : 
     473             : #if !defined( DEBUG_MODE_INFO ) || !defined( DEBUG_STEREO_DFT_NOCORE )
     474       98130 :         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       34410 :         {
     476       34410 :             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       34410 :             mvr2r( st->hHQ_core->old_outLB + numZeros, hCPE->hStereoDft->ap_fade_mem, ap_fade_len );
     480             : 
     481       34410 :             if ( st->last_core == ACELP_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) && !st->tcxonly )
     482             :             {
     483        2412 :                 mvr2r( tcx_core_buf, pAp_input, st->L_frame );
     484             :             }
     485             :             else
     486             :             {
     487       31998 :                 mvr2r( output, pAp_input, st->L_frame );
     488             :             }
     489             : 
     490       34410 :             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        2412 :                 mvr2r( tcx_core_buf, tmp_fade, ap_fade_len );
     493       89340 :                 for ( i = 0; i < ap_fade_len; i++ )
     494             :                 {
     495       86928 :                     pAp_input[i] = ( pAp_input[i] * i + tmp_fade[i] * ( ap_fade_len - i ) ) / ap_fade_len;
     496             :                 }
     497             :             }
     498             :         }
     499             :         else
     500             :         {
     501       63720 :             mvr2r( output, pAp_input, st->L_frame );
     502       63720 :             if ( st->last_core != ACELP_CORE ) /* TCX/HQ-Core -> ACELP */
     503             :             {
     504      114828 :                 for ( i = 0; i < ap_fade_len; i++ )
     505             :                 {
     506      111600 :                     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       98130 :         predelay = NS2SA( st->sr_core, DELAY_BWE_TOTAL_NS );
     512             : 
     513             :         /* apply predelay to have same overall filter delay for all cases */
     514       98130 :         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       98130 :         if ( hCPE->hStereoDft->attackPresent )
     532             :         {
     533        2955 :             float inv_tmps = 1.f / ap_fade_len;
     534        2955 :             if ( hCPE->hStereoDft->ap_wasTransient )
     535             :             {
     536         288 :                 set_zero( pAp_input, ap_fade_len );
     537             :             }
     538             :             else
     539             :             {
     540       95619 :                 for ( i = 0; i < ap_fade_len; i++ )
     541             :                 {
     542       92952 :                     pAp_input[i] *= ( ap_fade_len - i ) * inv_tmps;
     543             :                 }
     544             :             }
     545        2955 :             set_zero( pAp_input + ap_fade_len, st->L_frame - ap_fade_len );
     546        2955 :             hCPE->hStereoDft->ap_wasTransient = 1;
     547             :         }
     548       95175 :         else if ( hCPE->hStereoDft->ap_wasTransient )
     549             :         {
     550        2658 :             float inv_tmps = 1.f / ap_fade_len;
     551       95250 :             for ( i = 0; i < ap_fade_len; i++ )
     552             :             {
     553       92592 :                 pAp_input[i] *= i * inv_tmps;
     554             :             }
     555        2658 :             hCPE->hStereoDft->ap_wasTransient = 0;
     556             :         }
     557             : 
     558             :         /* apply 5-stage allpass, each stage consisting of a nested allpass pair */
     559       98130 :         filter_with_allpass( pAp_input, pAp_input, st->L_frame, &hCPE->hStereoDft->ap1 );
     560       98130 :         filter_with_allpass( pAp_input, pAp_input, st->L_frame, &hCPE->hStereoDft->ap2 );
     561       98130 :         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       98130 :         stereo_dft_dec_analyze( hCPE, pAp_input, DFT, 1, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0 );
     577             :     }
     578             : 
     579      192594 :     if ( st->core == ACELP_CORE )
     580             :     {
     581      139113 :         if ( !use_cldfb_for_dft ) /* Skip this for DFT Stereo mono output at non-residual bitrates */
     582             :         {
     583       94785 :             lerp( output, synth, output_frame, hCPE->hCoreCoder[0]->L_frame ); /* Dirty resampling, but should be good enough for ECU analysis */
     584             :         }
     585      139113 :         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       97200 :             v_add( synth, hb_synth, synth, output_frame ); /* Use one channel TD-BWE for ECU analysis buffer */
     588             :         }
     589             :     }
     590             : 
     591      192594 :     return;
     592             : }

Generated by: LCOV version 1.14