LCOV - code coverage report
Current view: top level - lib_com - ivas_fb_mixer.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 477 500 95.4 %
Date: 2025-05-29 08:28:55 Functions: 18 18 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 <stdint.h>
      34             : #include "options.h"
      35             : #ifdef DEBUGGING
      36             : #include "debug.h"
      37             : #endif
      38             : #include <math.h>
      39             : #include "prot.h"
      40             : #include "ivas_prot.h"
      41             : #include "ivas_rom_com.h"
      42             : #include <assert.h>
      43             : #include "wmc_auto.h"
      44             : 
      45             : 
      46             : /*------------------------------------------------------------------------------------------*
      47             :  * Static functions declarations
      48             :  *------------------------------------------------------------------------------------------*/
      49             : 
      50             : static void ivas_get_active_bins( const int16_t **pActive_bins, const int16_t **pActive_bins_abs, const int16_t **pStart_offset, const int16_t **pStart_offset_ab, const int32_t sampling_rate );
      51             : static void ivas_get_ld_fb_resp( float **ppIdeal_FRs_re, float **ppIdeal_FRs_im, float **ppNew_FRs_re, float **ppNew_FRs_im, const int16_t *pActive_bins, const int16_t *pStart_offset, const int16_t num_bands, const int16_t delay, const int32_t sampling_rate );
      52             : static ivas_error ivas_filterbank_setup( IVAS_FB_MIXER_HANDLE hFbMixer, const int32_t sampling_rate );
      53             : static ivas_error ivas_fb_mixer_get_window( const int16_t fade_len, const int32_t sampling_rate, const float **pWindow );
      54             : 
      55             : 
      56             : /*-----------------------------------------------------------------------------------------*
      57             :  * Function ivas_get_num_bands_from_bw_idx()
      58             :  *
      59             :  * Get number of bands from BW index
      60             :  *-----------------------------------------------------------------------------------------*/
      61             : 
      62             : /*! r: number of spectral bands */
      63     6210032 : int16_t ivas_get_num_bands_from_bw_idx(
      64             :     const int16_t bwidth /* i  : audio bandwidth    */
      65             : )
      66             : {
      67             :     int16_t num_active_bands;
      68             : 
      69     6210032 :     assert( bwidth > 0 ); /*NB BW is not supported*/
      70     6210032 :     num_active_bands = ivas_num_active_bands[bwidth - 1];
      71             : 
      72     6210032 :     return num_active_bands;
      73             : }
      74             : 
      75             : 
      76             : /*-----------------------------------------------------------------------------------------*
      77             :  * Function ivas_get_num_bands()
      78             :  *
      79             :  * Get number of bands depending on the sampling rates
      80             :  *-----------------------------------------------------------------------------------------*/
      81             : 
      82       92944 : static int16_t ivas_get_num_bands(
      83             :     const int32_t sampling_rate )
      84             : {
      85       92944 :     int16_t bwidth = ivas_get_bw_idx_from_sample_rate( sampling_rate );
      86       92944 :     int16_t num_active_bands = ivas_get_num_bands_from_bw_idx( bwidth );
      87             : 
      88       92944 :     return num_active_bands;
      89             : }
      90             : 
      91             : 
      92             : /*---------------------------------------------------------------------*
      93             :  * Function ivas_fb_set_cfg()
      94             :  *
      95             :  * Set default configs for FB mixer
      96             :  *---------------------------------------------------------------------*/
      97             : 
      98      103206 : ivas_error ivas_fb_set_cfg(
      99             :     IVAS_FB_CFG **pFb_cfg_out,     /* o  : FB config. handle                */
     100             :     const int16_t ivas_format,     /* i  : IVAS format                      */
     101             :     const int16_t num_in_chans,    /* i  : number of FB input channels      */
     102             :     const int16_t num_out_chans,   /* i  : number of FB output channels     */
     103             :     const int16_t active_w_mixing, /* i  : active_w_mixing flag             */
     104             :     const int32_t sampling_rate,   /* i  : sampling rate                    */
     105             :     const int16_t nchan_fb_in      /* i  : number of dirAC analysis channels*/
     106             : )
     107             : {
     108             :     IVAS_FB_CFG *pFb_cfg;
     109             : 
     110      103206 :     if ( ( pFb_cfg = (IVAS_FB_CFG *) malloc( sizeof( IVAS_FB_CFG ) ) ) == NULL )
     111             :     {
     112           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer config" );
     113             :     }
     114             : 
     115      103206 :     pFb_cfg->num_in_chans = num_in_chans;
     116      103206 :     pFb_cfg->num_out_chans = num_out_chans;
     117      103206 :     pFb_cfg->nchan_fb_in = nchan_fb_in;
     118             : 
     119      103206 :     pFb_cfg->pcm_offset = 0; /* note: in SPAR decoder, this parameter is overwritten later */
     120      103206 :     pFb_cfg->active_w_mixing = active_w_mixing;
     121      103206 :     pFb_cfg->windowed_fr_offset = 0;
     122             : 
     123      103206 :     if ( ivas_format == ISM_FORMAT )
     124             :     {
     125        2249 :         pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_4_NS );
     126        2249 :         pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_4_NS );
     127        2249 :         pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS_PARAM_ISM ) + NS2SA( sampling_rate, DIRAC_SLOT_ENC_NS );
     128             :     }
     129      100957 :     else if ( ivas_format == SBA_FORMAT )
     130             :     {
     131       84301 :         pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS );
     132             : 
     133       84301 :         pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_4_NS );
     134       84301 :         pFb_cfg->prior_input_length = NS2SA( sampling_rate, FRAME_SIZE_NS );
     135       84301 :         pFb_cfg->windowed_fr_offset = (int16_t) ( (float) ( sampling_rate / FRAMES_PER_SEC ) * 3.0f / 4.0f ) - NS2SA( sampling_rate, DELAY_DIRAC_SPAR_ENC_CMP_NS );
     136             :     }
     137       16656 :     else if ( ivas_format == MASA_FORMAT )
     138             :     {
     139       12143 :         pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS );
     140       12143 :         pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_1_NS );
     141       12143 :         pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS ) + NS2SA( sampling_rate, DIRAC_SLOT_ENC_NS );
     142             :     }
     143        4513 :     else if ( ivas_format == MC_FORMAT )
     144             :     {
     145        4513 :         pFb_cfg->fb_latency = NS2SA( sampling_rate, DELAY_FB_1_NS );
     146        4513 :         pFb_cfg->fade_len = NS2SA( sampling_rate, DELAY_FB_1_NS );
     147        4513 :         pFb_cfg->prior_input_length = NS2SA( sampling_rate, DELAY_DIRAC_ENC_CMP_NS ) + NS2SA( sampling_rate, PARAM_MC_SLOT_ENC_NS );
     148             :     }
     149             : 
     150      103206 :     *pFb_cfg_out = pFb_cfg;
     151             : 
     152      103206 :     return IVAS_ERR_OK;
     153             : }
     154             : 
     155             : 
     156             : /*-------------------------------------------------------------------------
     157             :  * ivas_FB_mixer_open()
     158             :  *
     159             :  * Allocate and initialize FB mixer handle
     160             :  *------------------------------------------------------------------------*/
     161             : 
     162      103206 : ivas_error ivas_FB_mixer_open(
     163             :     IVAS_FB_MIXER_HANDLE *hFbMixer_out, /* i/o: FB mixer handle           */
     164             :     const int32_t sampling_rate,        /* i  : sampling rate             */
     165             :     IVAS_FB_CFG *fb_cfg,                /* i  : FB config. handle         */
     166             :     const int16_t spar_reconfig_flag    /* i  : SPAR reconfiguration flag */
     167             : )
     168             : {
     169             :     IVAS_FB_MIXER_HANDLE hFbMixer;
     170             :     int16_t i, j, frame_len, num_bands;
     171             :     int16_t num_chs_alloc;
     172             :     ivas_error error;
     173             : 
     174      103206 :     error = IVAS_ERR_OK;
     175             : 
     176      103206 :     frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC );
     177             : 
     178      103206 :     hFbMixer = *hFbMixer_out;
     179             : 
     180      103206 :     if ( !spar_reconfig_flag )
     181             :     {
     182       64708 :         if ( ( hFbMixer = (IVAS_FB_MIXER_HANDLE) malloc( sizeof( IVAS_FB_MIXER_DATA ) ) ) == NULL )
     183             :         {
     184           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
     185             :         }
     186             : 
     187       64708 :         if ( fb_cfg->num_out_chans > 0 )
     188             :         {
     189       46472 :             if ( ( hFbMixer->pFb = (ivas_filterbank_t *) malloc( sizeof( ivas_filterbank_t ) ) ) == NULL )
     190             :             {
     191           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
     192             :             }
     193             :         }
     194             :         else
     195             :         {
     196       18236 :             hFbMixer->pFb = NULL;
     197             :         }
     198             :     }
     199             : 
     200      103206 :     if ( fb_cfg->active_w_mixing == -1 )
     201             :     {
     202       68514 :         num_chs_alloc = 0;
     203             :     }
     204       34692 :     else if ( fb_cfg->active_w_mixing )
     205             :     {
     206        4678 :         num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in );
     207             :     }
     208             :     else
     209             :     {
     210       30014 :         num_chs_alloc = 1; /* only W channel processed for predicting YZX */
     211             :     }
     212             : 
     213      151932 :     for ( i = 0; i < num_chs_alloc; i++ )
     214             :     {
     215       48726 :         if ( fb_cfg->num_out_chans == 0 )
     216             :         {
     217       18236 :             hFbMixer->ppFilterbank_inFR_re[i] = NULL;
     218       18236 :             hFbMixer->ppFilterbank_inFR_im[i] = NULL;
     219             :         }
     220             :         else
     221             :         {
     222       30490 :             j = fb_cfg->remix_order[i];
     223             : 
     224       30490 :             if ( ( hFbMixer->ppFilterbank_inFR_re[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL )
     225             :             {
     226           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
     227             :             }
     228             : 
     229       30490 :             if ( ( hFbMixer->ppFilterbank_inFR_im[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL )
     230             :             {
     231           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
     232             :             }
     233             :         }
     234             :     }
     235             : 
     236      103206 :     if ( fb_cfg->active_w_mixing == -1 )
     237             :     {
     238       68514 :         num_chs_alloc = 0;
     239             :     }
     240             :     else
     241             :     {
     242       34692 :         num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in );
     243             :     }
     244             : 
     245      291133 :     for ( i = 0; i < num_chs_alloc; i++ )
     246             :     {
     247      187927 :         if ( ( hFbMixer->ppFilterbank_prior_input[i] = (float *) malloc( sizeof( float ) * fb_cfg->prior_input_length ) ) == NULL )
     248             :         {
     249           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
     250             :         }
     251      187927 :         set_f( hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length );
     252             :     }
     253             : 
     254      103206 :     if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) )
     255             :     {
     256             :         float *pTemp_mem;
     257       16456 :         if ( ( pTemp_mem = (float *) malloc( sizeof( float ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL )
     258             :         {
     259           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" );
     260             :         }
     261       57246 :         for ( i = 0; i < fb_cfg->num_out_chans; i++ )
     262             :         {
     263      263402 :             for ( j = 0; j < fb_cfg->num_in_chans; j++ )
     264             :             {
     265      222612 :                 hFbMixer->prior_mixer[i][j] = pTemp_mem;
     266      222612 :                 pTemp_mem += IVAS_MAX_NUM_BANDS;
     267      222612 :                 set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS );
     268             :             }
     269             :         }
     270             :     }
     271             : 
     272      103206 :     if ( !spar_reconfig_flag )
     273             :     {
     274       64708 :         if ( fb_cfg->num_out_chans > 0 )
     275             :         {
     276             :             const int16_t *pActive_bins_per_band, *pActive_bins_per_band_abs, *pStart_offset, *pStart_offset_abs;
     277             : 
     278       46472 :             num_bands = ivas_get_num_bands( sampling_rate );
     279             : 
     280       46472 :             ivas_get_active_bins( &pActive_bins_per_band, &pActive_bins_per_band_abs, &pStart_offset, &pStart_offset_abs, sampling_rate );
     281             : 
     282       46472 :             if ( fb_cfg->active_w_mixing != -1 )
     283             :             {
     284       32862 :                 for ( i = 0; i < num_bands; i++ )
     285             :                 {
     286       30250 :                     if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL )
     287             :                     {
     288           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
     289             :                     }
     290             :                 }
     291             :             }
     292             : 
     293       46472 :             if ( sampling_rate != 48000 )
     294             :             {
     295             :                 int16_t num_diff_bands, start_diff_band_non48k;
     296             : 
     297       31058 :                 num_diff_bands = MAX_NUM_BANDS_DIFF_NON48K;
     298       31058 :                 start_diff_band_non48k = num_bands - num_diff_bands;
     299             : 
     300       31058 :                 hFbMixer->num_diff_bands = num_diff_bands;
     301             : 
     302      124232 :                 for ( j = start_diff_band_non48k; j < num_bands; j++ )
     303             :                 {
     304       93174 :                     if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL )
     305             :                     {
     306           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
     307             :                     }
     308             : 
     309       93174 :                     if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL )
     310             :                     {
     311           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" );
     312             :                     }
     313             :                 }
     314             :             }
     315             :         }
     316             :         else
     317             :         {
     318             :             /* ignore all the deeper filter bank stuff for now */
     319       18236 :             hFbMixer->num_diff_bands = 0;
     320             :         }
     321             :     }
     322             : 
     323      103206 :     hFbMixer->fb_cfg = fb_cfg;
     324      103206 :     set_s( hFbMixer->first_frame, 1, hFbMixer->fb_cfg->num_out_chans );
     325      103206 :     set_s( hFbMixer->first_frame + hFbMixer->fb_cfg->num_out_chans, 0, IVAS_SPAR_MAX_CH - hFbMixer->fb_cfg->num_out_chans );
     326             : 
     327      103206 :     if ( !spar_reconfig_flag )
     328             :     {
     329       64708 :         if ( ( error = ivas_filterbank_setup( hFbMixer, sampling_rate ) ) != IVAS_ERR_OK )
     330             :         {
     331           0 :             return error;
     332             :         }
     333             :     }
     334             : 
     335      103206 :     *hFbMixer_out = hFbMixer;
     336             : 
     337      103206 :     return error;
     338             : }
     339             : 
     340             : 
     341             : /*-------------------------------------------------------------------------
     342             :  * ivas_FB_mixer_close()
     343             :  *
     344             :  * Deallocate FB mixer handle
     345             :  *------------------------------------------------------------------------*/
     346             : 
     347      103206 : void ivas_FB_mixer_close(
     348             :     IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle              */
     349             :     const int32_t sampling_rate,       /* i  : sampling rate in Hz          */
     350             :     const int16_t spar_reconfig_flag   /* i  : SPAR reconfiguration flag    */
     351             : )
     352             : {
     353             :     IVAS_FB_MIXER_HANDLE hFbMixer;
     354             :     IVAS_FB_CFG *fb_cfg;
     355             :     int16_t i, j, num_bands;
     356             :     int16_t num_chs_alloc;
     357             : 
     358      103206 :     hFbMixer = *hFbMixer_in;
     359      103206 :     fb_cfg = hFbMixer->fb_cfg;
     360             : 
     361      103206 :     if ( fb_cfg->active_w_mixing == -1 )
     362             :     {
     363       68514 :         num_chs_alloc = 0;
     364             :     }
     365       34692 :     else if ( fb_cfg->active_w_mixing )
     366             :     {
     367        4678 :         num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in );
     368             :     }
     369             :     else
     370             :     {
     371       30014 :         num_chs_alloc = 1; /* only W channel processed for predicting YZX */
     372             :     }
     373             : 
     374      103206 :     if ( hFbMixer != NULL )
     375             :     {
     376      151932 :         for ( i = 0; i < num_chs_alloc; i++ )
     377             :         {
     378       48726 :             if ( fb_cfg->num_out_chans > 0 )
     379             :             {
     380       30490 :                 j = fb_cfg->remix_order[i];
     381             : 
     382       30490 :                 free( hFbMixer->ppFilterbank_inFR_re[j] );
     383       30490 :                 hFbMixer->ppFilterbank_inFR_re[j] = NULL;
     384             : 
     385       30490 :                 free( hFbMixer->ppFilterbank_inFR_im[j] );
     386       30490 :                 hFbMixer->ppFilterbank_inFR_im[j] = NULL;
     387             :             }
     388             :         }
     389             : 
     390      103206 :         if ( fb_cfg->active_w_mixing == -1 )
     391             :         {
     392       68514 :             num_chs_alloc = 0;
     393             :         }
     394             :         else
     395             :         {
     396       34692 :             num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in );
     397             :         }
     398             : 
     399      291133 :         for ( i = 0; i < num_chs_alloc; i++ )
     400             :         {
     401      187927 :             free( hFbMixer->ppFilterbank_prior_input[i] );
     402      187927 :             hFbMixer->ppFilterbank_prior_input[i] = NULL;
     403             :         }
     404             : 
     405      103206 :         if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) )
     406             :         {
     407       16456 :             free( hFbMixer->prior_mixer[0][0] );
     408       16456 :             hFbMixer->prior_mixer[0][0] = NULL;
     409             :         }
     410             : 
     411      103206 :         if ( !spar_reconfig_flag )
     412             :         {
     413       64708 :             if ( fb_cfg->num_out_chans > 0 )
     414             :             {
     415       46472 :                 num_bands = hFbMixer->pFb->filterbank_num_bands;
     416             : 
     417       46472 :                 if ( fb_cfg->active_w_mixing != -1 )
     418             :                 {
     419       32862 :                     for ( i = 0; i < num_bands; i++ )
     420             :                     {
     421       30250 :                         free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] );
     422       30250 :                         hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = NULL;
     423             :                     }
     424             :                 }
     425             : 
     426       46472 :                 if ( sampling_rate != 48000 )
     427             :                 {
     428             :                     int16_t start_diff_band_non48k;
     429       31058 :                     start_diff_band_non48k = num_bands - hFbMixer->num_diff_bands;
     430             : 
     431      124232 :                     for ( j = start_diff_band_non48k; j < num_bands; j++ )
     432             :                     {
     433       93174 :                         free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] );
     434       93174 :                         hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = NULL;
     435             : 
     436       93174 :                         free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] );
     437       93174 :                         hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = NULL;
     438             :                     }
     439             :                 }
     440             :             }
     441       64708 :             if ( hFbMixer->pFb != NULL )
     442             :             {
     443       46472 :                 free( hFbMixer->pFb );
     444       46472 :                 hFbMixer->pFb = NULL;
     445             :             }
     446             :         }
     447             : 
     448      103206 :         if ( hFbMixer->fb_cfg != NULL )
     449             :         {
     450      103206 :             free( hFbMixer->fb_cfg );
     451      103206 :             hFbMixer->fb_cfg = NULL;
     452             :         }
     453             : 
     454      103206 :         if ( !spar_reconfig_flag )
     455             :         {
     456       64708 :             free( hFbMixer );
     457       64708 :             hFbMixer = NULL;
     458             :         }
     459             :     }
     460             : 
     461      103206 :     return;
     462             : }
     463             : 
     464             : 
     465             : /*-----------------------------------------------------------------------------------------*
     466             :  * Function ivas_fb_mixer_pcm_ingest()
     467             :  *
     468             :  * PCM ingest block
     469             :  *-----------------------------------------------------------------------------------------*/
     470             : 
     471     2510926 : void ivas_fb_mixer_pcm_ingest(
     472             :     IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle             */
     473             :     float *pcm_in[],               /* i  : input audio channels        */
     474             :     float **ppOut_pcm,             /* o  : output audio channels       */
     475             :     const int16_t frame_len,       /* i  : frame length                */
     476             :     const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] )
     477             : {
     478             :     int16_t i;
     479             :     int16_t num_chs_ingest;
     480     2510926 :     IVAS_FB_CFG *fb_cfg = hFbMixer->fb_cfg;
     481             : 
     482     2510926 :     if ( fb_cfg->active_w_mixing )
     483             :     {
     484      840271 :         num_chs_ingest = fb_cfg->num_in_chans;
     485             :     }
     486             :     else
     487             :     {
     488     1670655 :         num_chs_ingest = 1; /* forward Filterbank MDFT only on W */
     489             :     }
     490             : 
     491    13521749 :     for ( i = 0; i < fb_cfg->num_in_chans; i++ )
     492             :     {
     493    11010823 :         mvr2r( &hFbMixer->ppFilterbank_prior_input[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len );
     494    11010823 :         mvr2r( pcm_in[HOA_md_ind[i]], &ppOut_pcm[i][frame_len], frame_len );
     495             :     }
     496             : 
     497     7542665 :     for ( i = 0; i < num_chs_ingest; i++ )
     498             :     {
     499     5031739 :         ivas_mdft( ppOut_pcm[fb_cfg->remix_order[i]], hFbMixer->ppFilterbank_inFR_re[fb_cfg->remix_order[i]], hFbMixer->ppFilterbank_inFR_im[fb_cfg->remix_order[i]], frame_len << 1, frame_len );
     500             :     }
     501             : 
     502     2510926 :     return;
     503             : }
     504             : 
     505             : 
     506             : /*-----------------------------------------------------------------------------------------*
     507             :  * Function ivas_fb_mixer_update_prior_input()
     508             :  *
     509             :  *
     510             :  *-----------------------------------------------------------------------------------------*/
     511             : 
     512    13142540 : void ivas_fb_mixer_update_prior_input(
     513             :     IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle              */
     514             :     float *pcm_in[],               /* i  : input audio channels         */
     515             :     const int16_t length,          /* i  : length of time slot          */
     516             :     const int16_t nchan_fb_in      /* i  : number of analysis channels  */
     517             : )
     518             : {
     519             :     int16_t i;
     520             : 
     521    74727408 :     for ( i = 0; i < nchan_fb_in; i++ )
     522             :     {
     523    61584868 :         mvr2r( &hFbMixer->ppFilterbank_prior_input[i][length], hFbMixer->ppFilterbank_prior_input[i], hFbMixer->fb_cfg->prior_input_length - length );
     524    61584868 :         mvr2r( pcm_in[i], &hFbMixer->ppFilterbank_prior_input[i][hFbMixer->fb_cfg->prior_input_length - length], length );
     525             :     }
     526             : 
     527    13142540 :     return;
     528             : }
     529             : 
     530             : 
     531             : /*-----------------------------------------------------------------------------------------*
     532             :  * Function ivas_fb_mixer_get_windowed_fr()
     533             :  *
     534             :  *
     535             :  *-----------------------------------------------------------------------------------------*/
     536             : 
     537    13121640 : void ivas_fb_mixer_get_windowed_fr(
     538             :     IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle                    */
     539             :     float *pcm_in[],               /* i  : input audio channels               */
     540             :     float *frame_f_real[],         /* o  : real freq domain values            */
     541             :     float *frame_f_imag[],         /* o  : imag freq domain values            */
     542             :     const int16_t length,          /* i  : number of new samples in time slot */
     543             :     const int16_t mdft_len,        /* i  : MDFT frame length                  */
     544             :     const int16_t nchan_fb_in      /* i  : number of analysis channels        */
     545             : )
     546             : {
     547             :     int16_t ch_idx, j, offset, rev_offset;
     548             :     int16_t n_old_samples;
     549             :     int16_t n_new_samples;
     550             :     float fr_in_block[L_FRAME48k * 2];
     551             :     const float *win_ptr;
     552             : 
     553    13121640 :     n_old_samples = min( ( hFbMixer->fb_cfg->prior_input_length - hFbMixer->fb_cfg->windowed_fr_offset ), ( 2 * mdft_len ) );
     554    13121640 :     n_new_samples = max( 0, 2 * length - n_old_samples );
     555    13121640 :     offset = (int16_t) ( 2 * mdft_len - length - hFbMixer->ana_window_offset );
     556    13121640 :     rev_offset = (int16_t) ( 2 * mdft_len - hFbMixer->ana_window_offset );
     557    13121640 :     set_zero( fr_in_block, offset );
     558             : 
     559    74549976 :     for ( ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ )
     560             :     {
     561    61428336 :         mvr2r( &hFbMixer->ppFilterbank_prior_input[ch_idx][offset + hFbMixer->fb_cfg->windowed_fr_offset], &fr_in_block[offset], n_old_samples - offset );
     562    61428336 :         mvr2r( pcm_in[ch_idx], &fr_in_block[n_old_samples], n_new_samples );
     563    61428336 :         win_ptr = hFbMixer->pAna_window;
     564             : 
     565  2862669104 :         for ( j = offset; j < 2 * mdft_len - length; j++ )
     566             :         {
     567  2801240768 :             fr_in_block[j] *= ( *( win_ptr++ ) );
     568             :         }
     569             : 
     570  2862669104 :         for ( j = rev_offset; j < 2 * mdft_len; j++ )
     571             :         {
     572  2801240768 :             fr_in_block[j] *= ( *( --win_ptr ) );
     573             :         }
     574             : 
     575    61428336 :         ivas_mdft( fr_in_block, frame_f_real[ch_idx], frame_f_imag[ch_idx], mdft_len << 1, mdft_len );
     576             :     }
     577             : 
     578    13121640 :     return;
     579             : }
     580             : 
     581             : 
     582             : /*-----------------------------------------------------------------------------------------*
     583             :  * Function ivas_fb_mixer_cross_fading()
     584             :  *
     585             :  * FB Mixer cross fading
     586             :  *-----------------------------------------------------------------------------------------*/
     587             : 
     588     4117366 : void ivas_fb_mixer_cross_fading(
     589             :     IVAS_FB_MIXER_HANDLE hFbMixer,
     590             :     float **ppOut_pcm,
     591             :     float *pMdft_out_old,
     592             :     float *pMdft_out_new,
     593             :     const int16_t ch,
     594             :     const int16_t frame_len,
     595             :     const int16_t cf_offset )
     596             : {
     597             :     int16_t k, fade_start_offset, fade_end_offset;
     598             : 
     599     4117366 :     if ( hFbMixer->first_frame[ch] == 0 )
     600             :     {
     601     4090361 :         fade_start_offset = hFbMixer->cross_fade_start_offset;
     602     4090361 :         fade_end_offset = hFbMixer->cross_fade_end_offset;
     603             : 
     604     4090361 :         for ( k = 0; k < fade_start_offset; k++ )
     605             :         {
     606           0 :             ppOut_pcm[ch][k] = pMdft_out_old[k + cf_offset];
     607             :         }
     608             : 
     609   621208057 :         for ( k = fade_start_offset; k < fade_end_offset; k++ )
     610             :         {
     611   617117696 :             ppOut_pcm[ch][k] = pMdft_out_new[k + cf_offset] * hFbMixer->pFilterbank_cross_fade[k - fade_start_offset] + pMdft_out_old[k + cf_offset] * ( 1.0f - hFbMixer->pFilterbank_cross_fade[k - fade_start_offset] );
     612             :         }
     613             : 
     614  2472561145 :         for ( k = fade_end_offset; k < frame_len; k++ )
     615             :         {
     616  2468470784 :             ppOut_pcm[ch][k] = pMdft_out_new[k + cf_offset];
     617             :         }
     618             :     }
     619             :     else
     620             :     {
     621       27005 :         hFbMixer->first_frame[ch] = 0;
     622             : 
     623    22891325 :         for ( k = 0; k < frame_len; k++ )
     624             :         {
     625    22864320 :             ppOut_pcm[ch][k] = pMdft_out_new[k + cf_offset];
     626             :         }
     627             :     }
     628             : 
     629     4117366 :     return;
     630             : }
     631             : 
     632             : 
     633             : /*-----------------------------------------------------------------------------------------*
     634             :  * Function ivas_fb_mixer_process()
     635             :  *
     636             :  * Filter bank process
     637             :  *-----------------------------------------------------------------------------------------*/
     638             : 
     639     2510926 : void ivas_fb_mixer_process(
     640             :     IVAS_FB_MIXER_HANDLE hFbMixer,                                                   /* i/o: FB mixer handle                             */
     641             :     float ***mixer_mat,                                                              /* i  : mixer matrix                                */
     642             :     float **ppOut_pcm,                                                               /* o  : output audio channels                       */
     643             :     const int16_t frame_len,                                                         /* i  : frame length in samples                     */
     644             :     int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */
     645             : )
     646             : {
     647     2510926 :     ivas_filterbank_t *pFb = hFbMixer->pFb;
     648     2510926 :     int16_t num_bands = pFb->filterbank_num_bands;
     649             :     int16_t i, j, k, ch, hist;
     650             :     const float *pFilterbank_bin_to_band_re;
     651             :     const float *pFilterbank_bin_to_band_im;
     652             :     float *pMdft_out[2], *pOut_fr_re, *pOut_fr_im;
     653             :     float Out_fr_re[L_FRAME48k], Out_fr_im[L_FRAME48k];
     654             :     float Mdft_out_0[L_FRAME48k * 2], Mdft_out_1[L_FRAME48k * 2];
     655             : 
     656     2510926 :     pOut_fr_re = Out_fr_re;
     657     2510926 :     pOut_fr_im = Out_fr_im;
     658     2510926 :     pMdft_out[0] = Mdft_out_0;
     659     2510926 :     pMdft_out[1] = Mdft_out_1;
     660             : 
     661     6628292 :     for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ )
     662             :     {
     663             :         /* Run a loop of 2 to calculate current frame's filterbank output and prev frame's output */
     664    12352098 :         for ( hist = 0; hist < 2; hist++ )
     665             :         {
     666     8234732 :             set_zero( pOut_fr_re, frame_len );
     667     8234732 :             set_zero( pOut_fr_im, frame_len );
     668             : 
     669    46976374 :             for ( j = 0; j < hFbMixer->fb_cfg->num_in_chans; j++ )
     670             :             {
     671    38741642 :                 if ( in_out_mixer_map[ch][j] != 0 )
     672             :                 {
     673             :                     float filterbank_mixer_bins_re[L_FRAME48k];
     674             :                     float filterbank_mixer_bins_im[L_FRAME48k];
     675    13276358 :                     float *pFb_inFR_re = hFbMixer->ppFilterbank_inFR_re[j];
     676    13276358 :                     float *pFb_inFR_im = hFbMixer->ppFilterbank_inFR_im[j];
     677             : 
     678    13276358 :                     set_zero( filterbank_mixer_bins_re, frame_len );
     679    13276358 :                     set_zero( filterbank_mixer_bins_im, frame_len );
     680             : 
     681   168547546 :                     for ( i = 0; i < num_bands; i++ )
     682             :                     {
     683   155271188 :                         int16_t start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i];
     684   155271188 :                         int16_t num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i];
     685             : 
     686   155271188 :                         float mixer_const = hFbMixer->prior_mixer[ch][j][i];
     687             : 
     688   155271188 :                         pFilterbank_bin_to_band_re = pFb->fb_consts.ppFilterbank_FRs[0][i];
     689   155271188 :                         pFilterbank_bin_to_band_im = pFb->fb_consts.ppFilterbank_FRs[1][i];
     690             : 
     691 47006480950 :                         for ( k = start_offset; k < num_bins + start_offset; k++ )
     692             :                         {
     693 46851209762 :                             filterbank_mixer_bins_re[k] += *pFilterbank_bin_to_band_re++ * mixer_const;
     694 46851209762 :                             filterbank_mixer_bins_im[k] += *pFilterbank_bin_to_band_im++ * mixer_const;
     695             :                         }
     696   155271188 :                         hFbMixer->prior_mixer[ch][j][i] = mixer_mat[ch][j][i];
     697             :                     }
     698             : 
     699  9756672838 :                     for ( k = 0; k < frame_len; k++ )
     700             :                     {
     701             :                         float temp_out_re, temp_out_im;
     702             : 
     703  9743396480 :                         IVAS_CMULT_FLOAT( filterbank_mixer_bins_re[k], filterbank_mixer_bins_im[k], pFb_inFR_re[k],
     704             :                                           pFb_inFR_im[k], temp_out_re, temp_out_im );
     705             : 
     706  9743396480 :                         pOut_fr_re[k] += temp_out_re;
     707  9743396480 :                         pOut_fr_im[k] += temp_out_im;
     708             :                     }
     709             :                 }
     710             :             }
     711             : 
     712     8234732 :             ivas_imdft( pOut_fr_re, pOut_fr_im, pMdft_out[hist], frame_len );
     713             :         }
     714             : 
     715     4117366 :         ivas_fb_mixer_cross_fading( hFbMixer, ppOut_pcm, pMdft_out[0], pMdft_out[1], ch, frame_len, frame_len );
     716             :     }
     717             : 
     718     2510926 :     return;
     719             : }
     720             : 
     721             : 
     722             : /*-----------------------------------------------------------------------------------------*
     723             :  * Function ivas_fb_mixer_get_in_out_mapping()
     724             :  *
     725             :  *
     726             :  *-----------------------------------------------------------------------------------------*/
     727             : 
     728     2510926 : void ivas_fb_mixer_get_in_out_mapping(
     729             :     const IVAS_FB_CFG *fb_cfg,                                                       /* i  : FB config. handle  */
     730             :     int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping     */
     731             : )
     732             : {
     733             :     int16_t i, j;
     734             : 
     735     2510926 :     set_s( (int16_t *) in_out_mixer_map, 0, IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH );
     736             : 
     737     2510926 :     if ( fb_cfg->active_w_mixing )
     738             :     {
     739     1680542 :         for ( i = 0; i < fb_cfg->num_out_chans; i++ )
     740             :         {
     741     4201355 :             for ( j = 0; j < fb_cfg->num_in_chans; j++ )
     742             :             {
     743     3361084 :                 in_out_mixer_map[i][j] = 1;
     744             :             }
     745             :         }
     746             :     }
     747             :     else
     748             :     {
     749     1670655 :         in_out_mixer_map[0][0] = 1; /* W depends on only W input*/
     750     4947750 :         for ( i = 1; i < fb_cfg->num_out_chans; i++ )
     751             :         {
     752     3277095 :             in_out_mixer_map[i][0] = 1;
     753             :         }
     754             :     }
     755             : 
     756     2510926 :     return;
     757             : }
     758             : 
     759             : 
     760             : /*-----------------------------------------------------------------------------------------*
     761             :  * Function ivas_calculate_abs_fr()
     762             :  *
     763             :  * Function to calculate number of active bands
     764             :  *-----------------------------------------------------------------------------------------*/
     765             : 
     766       46472 : static int16_t ivas_calculate_abs_fr(
     767             :     ivas_filterbank_t *pFb,
     768             :     const int32_t sampling_rate,
     769             :     const int16_t alloc_fb_resp )
     770             : {
     771             :     int16_t frame_len;
     772             :     float ppFilterbank_FRs_s[L_FRAME48k];
     773       46472 :     int16_t bands = pFb->filterbank_num_bands;
     774       46472 :     int16_t i, j, num_active_bands = 0;
     775       46472 :     int16_t idx_short_stride_bin_to_band = 0;
     776             : 
     777      573554 :     for ( i = 0; i < bands; i++ )
     778             :     {
     779      527082 :         const float *long_mdft_ptr_re = pFb->fb_consts.ppFilterbank_FRs[0][i];
     780      527082 :         const float *long_mdft_ptr_im = pFb->fb_consts.ppFilterbank_FRs[1][i];
     781      527082 :         int16_t start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i];
     782      527082 :         int16_t num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i];
     783      527082 :         int16_t short_mdft_start_bin = -1;
     784             :         float short_stride_pow_spec[MDFT_FB_BANDS_240];
     785      527082 :         float short_stride_nrg = 0.0f;
     786      527082 :         float cldfb_nrg = 0.0f;
     787      527082 :         int16_t short_stride = pFb->fb_bin_to_band.short_stride;
     788      527082 :         const int16_t num_bins_per_short_stride_bin = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / short_stride );
     789      527082 :         const int16_t num_bins_per_cldfb_band = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands );
     790      527082 :         float short_stride_max_per_spar_band = 1e-9f;
     791             : 
     792             :         /*loop over all stored Filter Bank Response MDFT coefficients*/
     793      527082 :         set_f( short_stride_pow_spec, 0, MDFT_FB_BANDS_240 );
     794   151678377 :         for ( j = start_offset; j < num_bins + start_offset; j++ )
     795             :         {
     796             :             float sq_abs;
     797             : 
     798             :             /*calculate bin energy */
     799   151151295 :             IVAS_CALCULATE_SQ_ABS( *long_mdft_ptr_re, *long_mdft_ptr_im, sq_abs );
     800   151151295 :             long_mdft_ptr_re++;
     801   151151295 :             long_mdft_ptr_im++;
     802             : 
     803             :             /* accumulate bin energies within a short stride bin */
     804   151151295 :             short_stride_nrg += sq_abs;
     805   151151295 :             if ( !( ( j + 1 ) % num_bins_per_short_stride_bin ) )
     806             :             {                                                                                             /* new short stride bin */
     807    37706348 :                 short_stride_pow_spec[j / num_bins_per_short_stride_bin] = short_stride_nrg;              /* energy rather than magnitude works better for covariance weighting*/
     808    37706348 :                 short_stride_max_per_spar_band = max( short_stride_nrg, short_stride_max_per_spar_band ); /*compute highest magnitude per band*/
     809    37706348 :                 short_stride_nrg = 0.0f;
     810             :             }
     811             : 
     812             :             /* accumulate bin energies within a CLDFB band */
     813   151151295 :             cldfb_nrg += sq_abs;
     814   151151295 :             if ( !( ( j + 1 ) % num_bins_per_cldfb_band ) )
     815             :             {
     816     9352964 :                 pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j / num_bins_per_cldfb_band][i] = sqrtf( cldfb_nrg );
     817     9352964 :                 cldfb_nrg = 0.0f;
     818             :             }
     819             :         }
     820             : 
     821             :         /*loop over the short MDFT bins*/
     822    87424842 :         for ( j = 0; j < short_stride; j++ )
     823             :         {
     824             :             /* normalize and sparsify the energies */
     825    86897760 :             short_stride_pow_spec[j] /= short_stride_max_per_spar_band;
     826    86897760 :             short_stride_pow_spec[j] = max( short_stride_pow_spec[j] - 0.3f, 0.0f ) / 0.7f;
     827    86897760 :             if ( short_stride_pow_spec[j] > 0.0f )
     828             :             {
     829     8098086 :                 assert( idx_short_stride_bin_to_band < 2 * MDFT_FB_BANDS_240 ); /* array size of p_short_stride_bin_to_band */
     830     8098086 :                 if ( short_mdft_start_bin == -1 )
     831             :                 {
     832      527082 :                     short_mdft_start_bin = j;
     833      527082 :                     pFb->fb_bin_to_band.p_short_stride_start_bin_per_band[i] = j;
     834      527082 :                     pFb->fb_bin_to_band.pp_short_stride_bin_to_band[i] = &pFb->fb_bin_to_band.p_short_stride_bin_to_band[idx_short_stride_bin_to_band];
     835             :                 }
     836     8098086 :                 pFb->fb_bin_to_band.p_short_stride_bin_to_band[idx_short_stride_bin_to_band++] = short_stride_pow_spec[j];
     837     8098086 :                 pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[i]++;
     838             :             }
     839             :         }
     840             :     }
     841             : 
     842             :     /*loop over CLDFB bands*/
     843     1907812 :     for ( j = 0; j < pFb->fb_bin_to_band.num_cldfb_bands; j++ )
     844             :     {
     845     1861340 :         float sum_over_spar_bands = 0.0f;
     846     1861340 :         float max_spar_band_contribution = 0.0f;
     847     1861340 :         int16_t spar_start = 0;
     848     1861340 :         int16_t any_non_zero = 0;
     849             : 
     850    23585780 :         for ( i = 0; i < bands; i++ )
     851             :         {
     852    21724440 :             sum_over_spar_bands += pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i];
     853    21724440 :             if ( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i] > max_spar_band_contribution )
     854             :             {
     855     5768031 :                 max_spar_band_contribution = pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i];
     856     5768031 :                 pFb->fb_bin_to_band.p_cldfb_map_to_spar_band[j] = i;
     857             :             }
     858             :         }
     859     1861340 :         sum_over_spar_bands = max( sum_over_spar_bands, EPSILON );
     860    23585780 :         for ( i = 0; i < bands; i++ )
     861             :         {
     862    21724440 :             if ( pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i] == 0.0f && !any_non_zero )
     863             :             {
     864    10970727 :                 spar_start++;
     865             :             }
     866             :             else
     867             :             {
     868    10753713 :                 any_non_zero = 1;
     869             :             }
     870    21724440 :             pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[j][i] /= sum_over_spar_bands;
     871             :         }
     872     1861340 :         pFb->fb_bin_to_band.p_spar_start_bands[j] = spar_start;
     873             :     }
     874             : 
     875       46472 :     frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC );
     876             : 
     877       46472 :     set_f( ppFilterbank_FRs_s, 0, frame_len );
     878             : 
     879             :     /*Commented logic is for calculating number of active bands, can be removed if not needed */
     880      573554 :     for ( i = 0; i < bands; i++ )
     881             :     {
     882      527082 :         const float *pFilterbank_bin_to_band_re = pFb->fb_consts.ppFilterbank_FRs[0][i];
     883      527082 :         const float *pFilterbank_bin_to_band_im = pFb->fb_consts.ppFilterbank_FRs[1][i];
     884             : 
     885      527082 :         int16_t start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i];
     886      527082 :         int16_t num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i];
     887      527082 :         int16_t idx = 0;
     888      527082 :         int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[i];
     889      527082 :         int16_t abs_start_offset = pFb->fb_bin_to_band.pFb_start_bin_per_band[i];
     890             : 
     891   151678377 :         for ( j = start_offset; j < num_bins + start_offset; j++ )
     892             :         {
     893   151151295 :             float temp = 0;
     894             : 
     895   151151295 :             IVAS_CALCULATE_ABS( *pFilterbank_bin_to_band_re, *pFilterbank_bin_to_band_im, temp );
     896             : 
     897   151151295 :             pFilterbank_bin_to_band_re++;
     898   151151295 :             pFilterbank_bin_to_band_im++;
     899             : 
     900   151151295 :             temp -= 0.3f;
     901             : 
     902   151151295 :             if ( temp < 0.0f )
     903             :             {
     904   110090750 :                 temp = 0;
     905             :             }
     906             : 
     907   151151295 :             if ( j < ( abs_active_bins + abs_start_offset ) && j >= abs_start_offset && alloc_fb_resp != -1 )
     908             :             {
     909     2612729 :                 pFb->fb_bin_to_band.pFb_bin_to_band[i][idx++] = temp;
     910             :             }
     911             : 
     912   151151295 :             ppFilterbank_FRs_s[j] += temp;
     913             :         }
     914             :     }
     915             : 
     916    29827912 :     for ( i = 0; i < frame_len; i++ )
     917             :     {
     918    29781440 :         if ( ppFilterbank_FRs_s[i] < 0.1f )
     919             :         {
     920           0 :             ppFilterbank_FRs_s[i] = 0.1f;
     921             :         }
     922             :     }
     923             : 
     924       46472 :     if ( alloc_fb_resp != -1 )
     925             :     {
     926       32862 :         for ( j = 0; j < bands; j++ )
     927             :         {
     928       30250 :             int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j];
     929       30250 :             int16_t abs_start_offset = pFb->fb_bin_to_band.pFb_start_bin_per_band[j];
     930             : 
     931     2642979 :             for ( i = 0; i < abs_active_bins; i++ )
     932             :             {
     933     2612729 :                 pFb->fb_bin_to_band.pFb_bin_to_band[j][i] /= ppFilterbank_FRs_s[i + abs_start_offset];
     934             :                 /*if(pFb->fb_bin_to_band.pFb_bin_to_band[j][i] > 0.5f)
     935             :                 {
     936             :                     num_active_bands = j + 1;
     937             :                     break;
     938             :                 }*/
     939             :             }
     940             :         }
     941             :     }
     942             : 
     943       46472 :     return num_active_bands;
     944             : }
     945             : 
     946             : 
     947             : /*-----------------------------------------------------------------------------------------*
     948             :  * Function ivas_get_active_bins()
     949             :  *
     950             :  *
     951             :  *-----------------------------------------------------------------------------------------*/
     952             : 
     953       92944 : static void ivas_get_active_bins(
     954             :     const int16_t **pActive_bins,
     955             :     const int16_t **pActive_bins_abs,
     956             :     const int16_t **pStart_offset,
     957             :     const int16_t **pStart_offset_abs,
     958             :     const int32_t sampling_rate )
     959             : {
     960             :     int16_t sr_idx;
     961             : 
     962       92944 :     if ( sampling_rate == 32000 )
     963             :     {
     964       31534 :         sr_idx = 1;
     965             :     }
     966       61410 :     else if ( sampling_rate == 16000 )
     967             :     {
     968       30582 :         sr_idx = 2;
     969             :     }
     970             :     else
     971             :     {
     972       30828 :         sr_idx = 0;
     973             :     }
     974             : 
     975       92944 :     *pActive_bins_abs = ivas_fb_abs_bins_per_band_12band_1ms[sr_idx];
     976       92944 :     *pActive_bins = ivas_fb_bins_per_band_12band_1ms[sr_idx];
     977       92944 :     *pStart_offset_abs = ivas_fb_abs_bins_start_offset_12band_1ms[sr_idx];
     978       92944 :     *pStart_offset = ivas_fb_bins_start_offset_12band_1ms[sr_idx];
     979             : 
     980       92944 :     return;
     981             : }
     982             : 
     983             : 
     984             : /*-----------------------------------------------------------------------------------------*
     985             :  * Function ivas_filterbank_setup()
     986             :  *
     987             :  * Filterbank setup, initialization
     988             :  *-----------------------------------------------------------------------------------------*/
     989             : 
     990       64708 : static ivas_error ivas_filterbank_setup(
     991             :     IVAS_FB_MIXER_HANDLE hFbMixer,
     992             :     const int32_t sampling_rate )
     993             : {
     994             :     int16_t i, j;
     995             :     const float *pAll_fb_fr[2];
     996       64708 :     const int16_t *pAll_bins_start_offset = NULL;
     997       64708 :     const int16_t *pAll_bins_per_band = NULL;
     998       64708 :     const int16_t *pAll_bins_start_offset_abs = NULL;
     999       64708 :     const int16_t *pAll_bins_per_band_abs = NULL;
    1000       64708 :     const int16_t *pAll_bins_per_band_48k = NULL;
    1001             :     ivas_error error;
    1002       64708 :     IVAS_FB_CFG *pCfg = hFbMixer->fb_cfg;
    1003             : 
    1004       64708 :     error = IVAS_ERR_OK;
    1005             : 
    1006       64708 :     if ( pCfg->num_out_chans > 0 )
    1007             :     {
    1008       46472 :         hFbMixer->pFb->filterbank_num_bands = ivas_get_num_bands( sampling_rate );
    1009             : 
    1010       46472 :         ivas_get_active_bins( &pAll_bins_per_band, &pAll_bins_per_band_abs, &pAll_bins_start_offset, &pAll_bins_start_offset_abs, sampling_rate );
    1011             : 
    1012       46472 :         if ( pCfg->fb_latency == NS2SA( sampling_rate, DELAY_FB_1_NS ) )
    1013             :         {
    1014       46472 :             pAll_fb_fr[0] = ivas_fb_fr_12band_1ms_re;
    1015       46472 :             pAll_fb_fr[1] = ivas_fb_fr_12band_1ms_im;
    1016       46472 :             pAll_bins_per_band_48k = ivas_fb_bins_per_band_12band_1ms[0];
    1017             :         }
    1018             :         else
    1019             :         {
    1020           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong FB in ivas_filterbank_setup()!" );
    1021             :         }
    1022             :     }
    1023             : 
    1024       64708 :     hFbMixer->cross_fade_end_offset = pCfg->fade_len + pCfg->pcm_offset;
    1025       64708 :     hFbMixer->cross_fade_start_offset = hFbMixer->cross_fade_end_offset - pCfg->fade_len;
    1026       64708 :     hFbMixer->ana_window_offset = pCfg->fb_latency + pCfg->pcm_offset;
    1027             : 
    1028       64708 :     if ( ( error = ivas_fb_mixer_get_window( pCfg->fb_latency, sampling_rate, &( hFbMixer->pAna_window ) ) ) != IVAS_ERR_OK )
    1029             :     {
    1030           0 :         return error;
    1031             :     }
    1032             : 
    1033       64708 :     if ( ( error = ivas_fb_mixer_get_window( pCfg->fade_len, sampling_rate, &( hFbMixer->pFilterbank_cross_fade ) ) ) != IVAS_ERR_OK )
    1034             :     {
    1035           0 :         return error;
    1036             :     }
    1037             : 
    1038       64708 :     if ( pCfg->num_out_chans > 0 )
    1039             :     {
    1040       46472 :         ivas_filterbank_t *pFb = hFbMixer->pFb;
    1041       46472 :         int16_t offset = 0;
    1042             : 
    1043       46472 :         pFb->fb_consts.pFilterbank_bins_per_band = pAll_bins_per_band;
    1044       46472 :         pFb->fb_consts.pFilterbank_bins_start_offset = pAll_bins_start_offset;
    1045       46472 :         pFb->fb_bin_to_band.pFb_active_bins_per_band = pAll_bins_per_band_abs;
    1046       46472 :         pFb->fb_bin_to_band.pFb_start_bin_per_band = pAll_bins_start_offset_abs;
    1047             : 
    1048             :         /* Initialization for short stride Parameter calculation and SPAR CLDFB reconstruction */
    1049       46472 :         pFb->fb_bin_to_band.num_cldfb_bands = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f );
    1050             :         /*pFb->fb_bin_to_band.cldfb_stride = ( int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );*/ /* equals num_cldfb_bands*/
    1051       46472 :         pFb->fb_bin_to_band.short_stride = (int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / 4 );
    1052       46472 :         set_f( pFb->fb_bin_to_band.p_short_stride_bin_to_band, 0.0f, 2 * MDFT_FB_BANDS_240 );
    1053       46472 :         set_s( pFb->fb_bin_to_band.p_cldfb_map_to_spar_band, 0, CLDFB_NO_CHANNELS_MAX );
    1054       46472 :         set_s( pFb->fb_bin_to_band.p_spar_start_bands, 0, CLDFB_NO_CHANNELS_MAX );
    1055             : 
    1056      975912 :         for ( j = 0; j < IVAS_MAX_NUM_FB_BANDS; j++ )
    1057             :         {
    1058      929440 :             pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j] = 0;  /* aka num_active_bins per SPAR band */
    1059      929440 :             pFb->fb_bin_to_band.p_short_stride_start_bin_per_band[j] = 0; /* first considered bin index per SPAR band */
    1060      929440 :             pFb->fb_bin_to_band.pp_short_stride_bin_to_band[j] = NULL;
    1061    56695840 :             for ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ )
    1062             :             {
    1063    55766400 :                 pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[i][j] = 0.0f;
    1064             :             }
    1065             :         }
    1066       46472 :         if ( sampling_rate == 48000 )
    1067             :         {
    1068      200382 :             for ( j = 0; j < pFb->filterbank_num_bands; j++ )
    1069             :             {
    1070      184968 :                 pFb->fb_consts.ppFilterbank_FRs[0][j] = &pAll_fb_fr[0][offset];
    1071      184968 :                 pFb->fb_consts.ppFilterbank_FRs[1][j] = &pAll_fb_fr[1][offset];
    1072      184968 :                 offset += pFb->fb_consts.pFilterbank_bins_per_band[j];
    1073             :             }
    1074             : 
    1075       15414 :             ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing );
    1076             :         }
    1077             :         else
    1078             :         {
    1079             :             float *ppFilterbank_FRs_re_temp[MAX_NUM_BANDS_DIFF_NON48K];
    1080             :             float *ppFilterbank_FRs_im_temp[MAX_NUM_BANDS_DIFF_NON48K];
    1081             :             int16_t active_bins_temp[MAX_NUM_BANDS_DIFF_NON48K];
    1082             :             int16_t start_offset_temp[MAX_NUM_BANDS_DIFF_NON48K];
    1083             :             int16_t num_diff_bands, start_diff_band_non48k;
    1084             : 
    1085       31058 :             num_diff_bands = MAX_NUM_BANDS_DIFF_NON48K;
    1086       31058 :             start_diff_band_non48k = pFb->filterbank_num_bands - num_diff_bands;
    1087             : 
    1088       31058 :             pFb->fb_consts.pFilterbank_bins_per_band = pAll_bins_per_band;
    1089       31058 :             pFb->fb_consts.pFilterbank_bins_start_offset = pAll_bins_start_offset;
    1090             : 
    1091      373172 :             for ( j = 0; j < pFb->filterbank_num_bands; j++ )
    1092             :             {
    1093      342114 :                 int16_t num_active_bins = pFb->fb_consts.pFilterbank_bins_per_band[j];
    1094             : 
    1095      342114 :                 if ( j < start_diff_band_non48k )
    1096             :                 {
    1097      248940 :                     pFb->fb_consts.ppFilterbank_FRs[0][j] = &pAll_fb_fr[0][offset];
    1098      248940 :                     pFb->fb_consts.ppFilterbank_FRs[1][j] = &pAll_fb_fr[1][offset];
    1099             :                 }
    1100             :                 else
    1101             :                 {
    1102       93174 :                     mvr2r( &pAll_fb_fr[0][offset], pFb->fb_consts.ppFilterbank_FRs_non48k[0][j], num_active_bins );
    1103       93174 :                     mvr2r( &pAll_fb_fr[1][offset], pFb->fb_consts.ppFilterbank_FRs_non48k[1][j], num_active_bins );
    1104             :                 }
    1105             : 
    1106      342114 :                 offset += pAll_bins_per_band_48k[j];
    1107             :             }
    1108             : 
    1109      124232 :             for ( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ )
    1110             :             {
    1111       93174 :                 ppFilterbank_FRs_re_temp[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k[0][j];
    1112       93174 :                 ppFilterbank_FRs_im_temp[j - start_diff_band_non48k] = pFb->fb_consts.ppFilterbank_FRs_non48k[1][j];
    1113       93174 :                 active_bins_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_per_band[j];
    1114       93174 :                 start_offset_temp[j - start_diff_band_non48k] = pFb->fb_consts.pFilterbank_bins_start_offset[j];
    1115             :             }
    1116             : 
    1117       31058 :             ivas_get_ld_fb_resp( ppFilterbank_FRs_re_temp, ppFilterbank_FRs_im_temp, ppFilterbank_FRs_re_temp, ppFilterbank_FRs_im_temp,
    1118       31058 :                                  active_bins_temp, start_offset_temp, num_diff_bands, pCfg->fb_latency, sampling_rate );
    1119             : 
    1120      124232 :             for ( j = start_diff_band_non48k; j < pFb->filterbank_num_bands; j++ )
    1121             :             {
    1122       93174 :                 pFb->fb_consts.ppFilterbank_FRs[0][j] = (const float *) pFb->fb_consts.ppFilterbank_FRs_non48k[0][j];
    1123       93174 :                 pFb->fb_consts.ppFilterbank_FRs[1][j] = (const float *) pFb->fb_consts.ppFilterbank_FRs_non48k[1][j];
    1124             :             }
    1125             : 
    1126       31058 :             ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing );
    1127             :         }
    1128             :     }
    1129             : 
    1130       64708 :     return error;
    1131             : }
    1132             : 
    1133             : 
    1134             : /*-----------------------------------------------------------------------------------------*
    1135             :  * Function ivas_fb_mixer_get_window()
    1136             :  *
    1137             :  *
    1138             :  *-----------------------------------------------------------------------------------------*/
    1139             : 
    1140      129416 : static ivas_error ivas_fb_mixer_get_window(
    1141             :     const int16_t fade_len,      /* i  : window fading length in samples    */
    1142             :     const int32_t sampling_rate, /* i  : sampling rate                      */
    1143             :     const float **pWindow        /* o  : pointer to the window coefficents  */
    1144             : )
    1145             : {
    1146             :     ivas_error error;
    1147             : 
    1148      129416 :     error = IVAS_ERR_OK;
    1149             : 
    1150      129416 :     if ( fade_len == NS2SA( sampling_rate, DELAY_FB_4_NS ) )
    1151             :     {
    1152       50301 :         switch ( sampling_rate )
    1153             :         {
    1154       19149 :             case 48000:
    1155       19149 :                 *pWindow = ivas_fb_cf_4ms_48k;
    1156       19149 :                 break;
    1157       15814 :             case 32000:
    1158       15814 :                 *pWindow = ivas_fb_cf_4ms_32k;
    1159       15814 :                 break;
    1160       15338 :             case 16000:
    1161       15338 :                 *pWindow = ivas_fb_cf_4ms_16k;
    1162       15338 :                 break;
    1163           0 :             default:
    1164           0 :                 return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported Sampling frequency!" );
    1165             :         }
    1166             :     }
    1167       79115 :     else if ( fade_len == NS2SA( sampling_rate, DELAY_FB_1_NS ) )
    1168             :     {
    1169       79115 :         switch ( sampling_rate )
    1170             :         {
    1171       45281 :             case 48000:
    1172       45281 :                 *pWindow = ivas_fb_cf_1ms_48k;
    1173       45281 :                 break;
    1174       18376 :             case 32000:
    1175       18376 :                 *pWindow = ivas_fb_cf_1ms_32k;
    1176       18376 :                 break;
    1177       15458 :             case 16000:
    1178       15458 :                 *pWindow = ivas_fb_cf_1ms_16k;
    1179       15458 :                 break;
    1180           0 :             default:
    1181           0 :                 return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Unsupported Sampling frequency!" );
    1182             :         }
    1183             :     }
    1184             :     else
    1185             :     {
    1186           0 :         IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Incorrect FB window fade len (%f ms)\n", ( fade_len / 1000000.f ) );
    1187             :     }
    1188             : 
    1189      129416 :     return error;
    1190             : }
    1191             : 
    1192             : 
    1193       31058 : static const float *ivas_get_cheby_ramp(
    1194             :     const int16_t delay )
    1195             : {
    1196       31058 :     const float *pCheby = NULL;
    1197             : 
    1198       31058 :     switch ( delay )
    1199             :     {
    1200       15767 :         case IVAS_FB_1MS_32K_SAMP:
    1201       15767 :             pCheby = ivas_fb_resp_cheby_ramp_32del;
    1202       15767 :             break;
    1203       15291 :         case IVAS_FB_1MS_16K_SAMP:
    1204       15291 :             pCheby = ivas_fb_resp_cheby_ramp_16del;
    1205       15291 :             break;
    1206           0 :         default:
    1207           0 :             assert( !"Unsupported cheby ramp length!" );
    1208             :     }
    1209             : 
    1210       31058 :     return pCheby;
    1211             : }
    1212             : 
    1213             : 
    1214             : /*get first half of the hanning window*/
    1215       31058 : static void ivas_get_hanning_win(
    1216             :     const int16_t len,
    1217             :     float *pH_win )
    1218             : {
    1219             :     int16_t i;
    1220             : 
    1221    15015058 :     for ( i = 0; i < len; i++ )
    1222             :     {
    1223    14984000 :         pH_win[i] = 0.5f * ( 1.0f - cosf( ( PI2 * ( i + 1 ) ) / ( ( 2 * len ) + 1 ) ) );
    1224             :     }
    1225             : 
    1226       31058 :     return;
    1227             : }
    1228             : 
    1229             : 
    1230       31058 : static void ivas_get_ld_fb_resp(
    1231             :     float **ppIdeal_FRs_re,
    1232             :     float **ppIdeal_FRs_im,
    1233             :     float **ppNew_FRs_re,
    1234             :     float **ppNew_FRs_im,
    1235             :     const int16_t *pActive_bins,
    1236             :     const int16_t *pStart_offset,
    1237             :     const int16_t num_bands,
    1238             :     const int16_t delay,
    1239             :     const int32_t sampling_rate )
    1240             : {
    1241             :     int16_t b, s, frame_len;
    1242             :     const float *pCheby;
    1243             : 
    1244             :     /*common scratch buffers for computing impulse/frequency responses,
    1245             :     pre-ring, post-ring and circular shifted outputs to optimize stack*/
    1246             :     float scratch1[L_FRAME32k * 2];
    1247             :     float scratch2[L_FRAME32k * 2];
    1248             :     float han_win[L_FRAME32k];
    1249             : 
    1250       31058 :     frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC );
    1251       31058 :     pCheby = ivas_get_cheby_ramp( delay );
    1252       31058 :     b = 0;
    1253       31058 :     s = 0;
    1254             : 
    1255       31058 :     assert( sampling_rate == 32000 || sampling_rate == 16000 );
    1256             : 
    1257       31058 :     ivas_get_hanning_win( frame_len, han_win );
    1258      124232 :     for ( b = 0; b < num_bands; b++ )
    1259             :     {
    1260       93174 :         set_f( scratch2, 0, frame_len << 1 );
    1261       93174 :         mvr2r( ppIdeal_FRs_re[b], &scratch2[pStart_offset[b]], pActive_bins[b] );
    1262       93174 :         mvr2r( ppIdeal_FRs_im[b], &scratch2[frame_len + pStart_offset[b]], pActive_bins[b] );
    1263       93174 :         ivas_imdft( scratch2, &scratch2[frame_len], scratch1, frame_len );
    1264             : 
    1265             :         /*apply circular shift and hanning window*/
    1266             : 
    1267    45045174 :         for ( s = delay; s < frame_len + delay; s++ )
    1268             :         {
    1269    44952000 :             scratch2[s - delay] = scratch1[s] * ( 1 - han_win[s - delay] );
    1270             :         }
    1271             : 
    1272    42797574 :         for ( ; s < 2 * frame_len; s++ )
    1273             :         {
    1274    42704400 :             scratch2[s - delay] = scratch1[s] * han_win[s - ( frame_len + delay )];
    1275             :         }
    1276             : 
    1277     2340774 :         for ( s = 0; s < delay; s++ )
    1278             :         {
    1279     2247600 :             scratch2[2 * frame_len - delay + s] = -1 * scratch1[s] * han_win[frame_len - delay + s];
    1280             :         }
    1281             : 
    1282             :         /*apply heavy/cheby ramp window and compute pre ring*/
    1283             : 
    1284     2433948 :         for ( s = 0; s < delay + 1; s++ )
    1285             :         {
    1286     2340774 :             scratch1[s] = scratch2[s] * pCheby[delay - s];
    1287             :         }
    1288             : 
    1289    42704400 :         for ( ; s < frame_len; s++ )
    1290             :         {
    1291    42611226 :             scratch1[s] = 0;
    1292             :         }
    1293             : 
    1294    42797574 :         for ( ; s < 2 * frame_len - delay; s++ )
    1295             :         {
    1296    42704400 :             scratch1[s] = scratch2[s];
    1297             :         }
    1298             : 
    1299     2340774 :         for ( ; s < 2 * frame_len; s++ )
    1300             :         {
    1301     2247600 :             scratch1[s] = scratch2[s] * ( 1 - pCheby[s - ( 2 * frame_len - delay )] );
    1302             :         }
    1303             : 
    1304             :         /*IR - pre ring + post ring*/
    1305    89904000 :         for ( s = 1; s < 2 * frame_len; s++ )
    1306             :         {
    1307    89810826 :             scratch2[s] = scratch2[s] /*pre ring*/ - scratch1[s] /*post ring*/ - scratch1[( 2 * frame_len ) - s];
    1308             :         }
    1309             : 
    1310    87749574 :         for ( s = 0; s < 2 * frame_len - delay; s++ )
    1311             :         {
    1312    87656400 :             scratch1[s + delay] = scratch2[s];
    1313             :         }
    1314             : 
    1315     2340774 :         for ( ; s < 2 * frame_len; s++ )
    1316             :         {
    1317     2247600 :             scratch1[s - ( 2 * frame_len - delay )] = -1 * ( scratch2[s] );
    1318             :         }
    1319             : 
    1320             :         /* apply final window*/
    1321     2340774 :         for ( s = 0; s < delay; s++ )
    1322             :         {
    1323     2247600 :             scratch1[s] = scratch1[s] * sinf( ( EVS_PI * ( s + 1 ) ) / ( 2 * delay ) );
    1324             :         }
    1325             : 
    1326    40643148 :         for ( s = 2 * delay; s < frame_len + 1; s++ )
    1327             :         {
    1328    40549974 :             scratch1[s] = scratch1[s] * sinf( ( EVS_PI * ( frame_len - s ) ) / ( 2 * ( frame_len + 1 - ( 2 * delay ) ) ) );
    1329             :         }
    1330             : 
    1331    44952000 :         for ( ; s < 2 * frame_len; s++ )
    1332             :         {
    1333    44858826 :             scratch1[s] = 0;
    1334             :         }
    1335             : 
    1336             :         /*compute frequency response*/
    1337       93174 :         ivas_mdft( scratch1, scratch2, &scratch2[frame_len], frame_len << 1, frame_len );
    1338             : 
    1339       93174 :         mvr2r( &scratch2[pStart_offset[b]], ppNew_FRs_re[b], pActive_bins[b] );
    1340       93174 :         mvr2r( &scratch2[frame_len + pStart_offset[b]], ppNew_FRs_im[b], pActive_bins[b] );
    1341             :     }
    1342             : 
    1343       31058 :     return;
    1344             : }

Generated by: LCOV version 1.14