LCOV - code coverage report
Current view: top level - lib_dec - bass_psfilter.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 178 203 87.7 %
Date: 2025-05-23 08:37:30 Functions: 5 6 83.3 %

          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             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <stdint.h>
      38             : #include "options.h"
      39             : #include <math.h>
      40             : #include "prot.h"
      41             : #include "ivas_prot.h"
      42             : #include "cnst.h"
      43             : #include "stat_dec.h"
      44             : #include "rom_com.h"
      45             : #ifdef DEBUGGING
      46             : #include "debug.h"
      47             : #endif
      48             : #include <assert.h>
      49             : #include "wmc_auto.h"
      50             : 
      51             : /*---------------------------------------------------------------------*
      52             :  * Local constants
      53             :  *---------------------------------------------------------------------*/
      54             : 
      55             : #define NBPSF_L_EXTRA        120
      56             : #define BPF_STOP_STOPBAND_16 16
      57             : 
      58             : #define K_PC_DEC -0.0357f /* <45, 17>             */
      59             : #define C_PC_DEC 1.6071f
      60             : 
      61             : /*---------------------------------------------------------------------*
      62             :  * Local function prototypes
      63             :  *---------------------------------------------------------------------*/
      64             : 
      65             : static int16_t Pit_track( const float syn[], int16_t T );
      66             : 
      67             : /*---------------------------------------------------------------------*
      68             :  * bass_psfilter_init()
      69             :  *
      70             :  * Initialisation of postfiltering variables
      71             :  *---------------------------------------------------------------------*/
      72             : 
      73       14496 : void bass_psfilter_init(
      74             :     BPF_DEC_HANDLE hBPF /* o  : BPF data handle               */
      75             : )
      76             : {
      77             :     /* post-filter memories */
      78       14496 :     hBPF->pst_mem_deemp_err = 0.0f;
      79       14496 :     hBPF->pst_lp_ener = 0.0f;
      80       14496 :     set_f( hBPF->pst_old_syn, 0, NBPSF_PIT_MAX );
      81             : 
      82       14496 :     set_s( hBPF->Track_on_hist, 0, L_TRACK_HIST );
      83       14496 :     set_s( hBPF->vibrato_hist, 0, L_TRACK_HIST );
      84       14496 :     set_f( hBPF->mem_mean_pit, 80, L_TRACK_HIST );
      85       14496 :     hBPF->psf_att = 1.0f;
      86             : 
      87       14496 :     return;
      88             : }
      89             : 
      90             : /*---------------------------------------------------------------------*
      91             :  * bass_psfilter()
      92             :  *
      93             :  * Perform low-frequency postfiltering
      94             :  *---------------------------------------------------------------------*/
      95             : 
      96      552780 : void bass_psfilter(
      97             :     BPF_DEC_HANDLE hBPF,      /* o  : BPF data handle                    */
      98             :     const int16_t Opt_AMR_WB, /* i  : AMR-WB IO flag                     */
      99             :     const float synth_in[],   /* i  : input synthesis (at 16kHz)         */
     100             :     const int16_t L_frame,    /* i  : length of the last frame           */
     101             :     const float pitch_buf[],  /* i  : pitch for every subfr [0,1,2,3]    */
     102             :     const int16_t bpf_off,    /* i  : do not use BPF when set to 1       */
     103             :     float v_stab,             /* i  : stability factor                   */
     104             :     float *v_stab_smooth,     /* i/o: smoothed stability factor          */
     105             :     const int16_t coder_type, /* i  : coder_type                         */
     106             :     float bpf_noise_buf[]     /* o  : BPF error signal (at int_fs)       */
     107             : )
     108             : {
     109             :     int16_t i, i_subfr, T;
     110             :     float gain, alpha, corr, ener;
     111             :     float syn_buf[NBPSF_PIT_MAX + L_FRAME16k + NBPSF_PIT_MAX], *syn;
     112             :     float syn2_buf[L_FRAME16k], *syn2;
     113             :     float err[L_HALFR16k];
     114             :     int16_t T_sf[NB_SUBFR16k];
     115             :     int16_t nb_subfr, T_update;
     116             :     float delta_v_stab;
     117             :     int16_t dist_pit_diff, idx_pit_min, idx_pit_max, vibrato, Track_on;
     118             :     float loc_pit_max, loc_pit_min, diff_pit;
     119             :     float TrackOnR, vibratR, alp_tmp;
     120             :     int16_t subfr_len;
     121             :     int16_t nbpsf_pit_max;
     122             : 
     123      552780 :     subfr_len = ( L_frame == L_FRAME8k ) ? STEREO_DFT_L_SUBFR_8k : L_SUBFR;
     124      552780 :     nbpsf_pit_max = ( L_frame == L_FRAME8k ) ? STEREO_DFT_NBPSF_PIT_MAX_8k : NBPSF_PIT_MAX;
     125             : 
     126      552780 :     Track_on = 0;
     127      552780 :     T_update = 01;
     128      552780 :     vibrato = 0;
     129      552780 :     nb_subfr = L_frame / subfr_len;
     130             : 
     131             :     /*-------------------------------------------------------
     132             :      *  Initialize pointers to various synthesis buffers
     133             :      *
     134             :      *   |--------------------syn_buf--------------------------------|
     135             :      *   |-----old_syn-----|-------synth_in--------|----extrapol---- |
     136             :      *   |--NBPSF_PIT_MAX--| sf1 | sf2 | sf3 | sf4 |--NBPSF_PIT_MAX--|
     137             :      *                     |------syn2_buf---------|
     138             :      *                     |------L_frame----------|
     139             :      *                     |----bpf_noise_buf------|
     140             :      *
     141             :      *-------------------------------------------------------*/
     142             : 
     143      552780 :     mvr2r( hBPF->pst_old_syn, syn_buf, nbpsf_pit_max );
     144      552780 :     mvr2r( synth_in, syn_buf + nbpsf_pit_max, L_frame );
     145             : 
     146      552780 :     if ( !( pitch_buf == NULL || bpf_off ) )
     147             :     {
     148     4783050 :         for ( i = L_TRACK_HIST - 1; i > 0; i-- )
     149             :         {
     150     4304745 :             hBPF->mem_mean_pit[i] = hBPF->mem_mean_pit[i - 1];
     151             :         }
     152             : 
     153      478305 :         hBPF->mem_mean_pit[i] = mean( pitch_buf, nb_subfr );
     154             :     }
     155             : 
     156      552780 :     idx_pit_min = minimum( hBPF->mem_mean_pit, L_TRACK_HIST, &loc_pit_min );
     157      552780 :     idx_pit_max = maximum( hBPF->mem_mean_pit, L_TRACK_HIST, &loc_pit_max );
     158             : 
     159      552780 :     dist_pit_diff = (int16_t) abs( idx_pit_max - idx_pit_min );
     160      552780 :     diff_pit = loc_pit_max - loc_pit_min;
     161             : 
     162      552780 :     if ( L_frame == L_FRAME16k || L_frame == L_FRAME8k )
     163             :     {
     164      278007 :         diff_pit *= 0.8f;
     165             :     }
     166             : 
     167      552780 :     if ( coder_type != INACTIVE && diff_pit >= 2.0f && diff_pit < 10 && dist_pit_diff >= 3 )
     168             :     {
     169       24867 :         vibrato = 1;
     170             :     }
     171             : 
     172      552780 :     TrackOnR = (float) sum_s( hBPF->Track_on_hist, L_TRACK_HIST ) / L_TRACK_HIST;
     173      552780 :     vibratR = (float) sum_s( hBPF->vibrato_hist, L_TRACK_HIST );
     174      552780 :     alp_tmp = 1.0f - TrackOnR;
     175             : 
     176      552780 :     if ( vibrato )
     177             :     {
     178       24867 :         vibratR = vibratR * vibratR * -0.009f + 1.0f;
     179       24867 :         alp_tmp *= vibratR;
     180             :     }
     181             : 
     182      552780 :     alp_tmp = max( 0.1f, alp_tmp );
     183             : 
     184      552780 :     if ( alp_tmp > hBPF->psf_att )
     185             :     {
     186      499725 :         hBPF->psf_att = 0.05f * alp_tmp + 0.95f * hBPF->psf_att;
     187             :     }
     188             :     else
     189             :     {
     190       53055 :         hBPF->psf_att = 0.4f * alp_tmp + 0.6f * hBPF->psf_att;
     191             :     }
     192             : 
     193      552780 :     if ( pitch_buf == NULL || bpf_off )
     194             :     {
     195             :         /* do not use BPF for HQ core */
     196       74475 :         T_update = L_frame == L_FRAME8k ? 40 : 80;
     197       74475 :         set_s( T_sf, 0, 5 );
     198       74475 :         syn = &syn_buf[nbpsf_pit_max + L_frame];
     199    21401655 :         for ( i = 0; i < nbpsf_pit_max; i++ )
     200             :         {
     201    21327180 :             syn[i] = syn[i - T_update];
     202             :         }
     203             :     }
     204             :     else
     205             :     {
     206             :         /* extrapolation of synth_in */
     207     2630550 :         for ( i = 0; i < nb_subfr; i++ )
     208             :         {
     209             :             /* copy subframe pitch values [1,2,3,4] of the current frame */
     210     2152245 :             T_sf[i] = ( L_frame == L_FRAME8k ) ? (int16_t) ( pitch_buf[i] / 2 + 0.5f ) : (int16_t) ( pitch_buf[i] + 0.5f );
     211             : 
     212     2152245 :             if ( L_frame == L_FRAME16k || L_frame == L_FRAME8k )
     213             :             {
     214             :                 /* Safety check, should be very rare */
     215     1195125 :                 if ( T_sf[i] > nbpsf_pit_max )
     216             :                 {
     217           0 :                     T_sf[i] = nbpsf_pit_max;
     218             :                 }
     219             :             }
     220             :             else
     221             :             {
     222      957120 :                 if ( T_sf[i] > PIT_MAX )
     223             :                 {
     224         729 :                     T_sf[i] = PIT_MAX;
     225             :                 }
     226             :             }
     227             :         }
     228             : 
     229      478305 :         T = T_sf[nb_subfr - 1];
     230      478305 :         syn = &syn_buf[nbpsf_pit_max + L_frame];
     231   134754975 :         for ( i = 0; i < nbpsf_pit_max; i++ )
     232             :         {
     233   134276670 :             syn[i] = syn[i - T];
     234             :         }
     235             :     }
     236             : 
     237     3041757 :     for ( i_subfr = 0; i_subfr < L_frame; i_subfr += subfr_len )
     238             :     {
     239     2488977 :         T = T_sf[i_subfr / subfr_len];
     240             : 
     241             :         /* Pitch limitation already done in the previous loop */
     242     2488977 :         syn = &syn_buf[nbpsf_pit_max + i_subfr];
     243     2488977 :         syn2 = &syn2_buf[i_subfr];
     244             : 
     245     2488977 :         if ( T != 0 )
     246             :         {
     247     2152245 :             if ( T >= PIT_MIN && Opt_AMR_WB )
     248             :             {
     249           0 :                 T = Pit_track( syn, T );
     250             : 
     251           0 :                 if ( T != T_sf[i_subfr / L_SUBFR] )
     252             :                 {
     253           0 :                     Track_on = 1;
     254             :                 }
     255             :             }
     256             : 
     257             :             /* symetric pitch prediction : phase is opposite between harmonic */
     258   135005685 :             for ( i = 0; i < subfr_len; i++ )
     259             :             {
     260   132853440 :                 syn2[i] = 0.5f * ( syn[i - T] + syn[i + T] );
     261             :             }
     262             : 
     263             :             /* gain of prediction */
     264     2152245 :             corr = 0.0001f;
     265   135005685 :             for ( i = 0; i < subfr_len; i++ )
     266             :             {
     267   132853440 :                 corr += syn[i] * syn2[i];
     268             :             }
     269             : 
     270     2152245 :             ener = 0.0001f;
     271   135005685 :             for ( i = 0; i < subfr_len; i++ )
     272             :             {
     273   132853440 :                 ener += syn2[i] * syn2[i];
     274             :             }
     275     2152245 :             gain = corr / ener;
     276             : 
     277             :             /* error of prediction for noise estimator */
     278   135005685 :             for ( i = 0; i < subfr_len; i++ )
     279             :             {
     280   132853440 :                 err[i] = syn[i] - ( gain * syn2[i] );
     281             :             }
     282             : 
     283             :             /* alpha = post-filtering factor (0=OFF, 1=100%) */
     284     2152245 :             ener = (float) ( ener + pow( 10.0, 0.1 * hBPF->pst_lp_ener ) ); /* limit alpha (post-filtering) when noise is high */
     285     2152245 :             alpha = corr / ener;
     286     2152245 :             if ( alpha > 0.5f )
     287             :             {
     288      677109 :                 alpha = 0.5f;
     289             :             }
     290             : 
     291     2152245 :             alpha *= ( hBPF->psf_att );
     292     2152245 :             if ( alpha > 0.3f && Track_on )
     293             :             {
     294           0 :                 alpha = 0.3f;
     295             :             }
     296     2152245 :             else if ( alpha > 0.4f && vibrato )
     297             :             {
     298       13113 :                 alpha = 0.4f;
     299             :             }
     300             : 
     301     2152245 :             if ( alpha < 0.0f )
     302             :             {
     303      116700 :                 alpha = 0.0f;
     304             :             }
     305             : 
     306     2152245 :             *v_stab_smooth = 0.8f * v_stab + 0.2f * ( *v_stab_smooth );
     307     2152245 :             delta_v_stab = (float) fabs( *v_stab_smooth - v_stab );
     308     2152245 :             v_stab = (float) pow( v_stab, 0.5f );
     309     2152245 :             alpha = ( 1.0f + 0.15f * v_stab - 2.0f * delta_v_stab ) * alpha;
     310             : 
     311   135005685 :             for ( i = 0; i < subfr_len; i++ )
     312             :             {
     313   132853440 :                 syn2[i] = alpha * ( syn[i] - syn2[i] );
     314             :             }
     315             :         }
     316             : 
     317             :         else
     318             :         {
     319             :             /* symetric pitch prediction : phase is opposite between harmonic */
     320    21589020 :             for ( i = 0; i < subfr_len; i++ )
     321             :             {
     322    21252288 :                 syn2[i] = 0.5f * ( syn[i - T_update] + syn[i + T_update] );
     323             :             }
     324             : 
     325      336732 :             if ( coder_type == AUDIO ) /* GSC mode without temporal component */
     326             :             {
     327        2004 :                 Track_on = 1;
     328             :             }
     329             :             else
     330             :             {
     331      334728 :                 Track_on = 0;
     332             :             }
     333             : 
     334             :             /* gain of prediction */
     335      336732 :             corr = 0.0001f;
     336    21589020 :             for ( i = 0; i < subfr_len; i++ )
     337             :             {
     338    21252288 :                 corr += syn[i] * syn2[i];
     339             :             }
     340      336732 :             ener = 0.0001f;
     341    21589020 :             for ( i = 0; i < subfr_len; i++ )
     342             :             {
     343    21252288 :                 ener += syn2[i] * syn2[i];
     344             :             }
     345             : 
     346      336732 :             gain = corr / ener;
     347             : 
     348             :             /* error of prediction for noise estimator */
     349    21589020 :             for ( i = 0; i < subfr_len; i++ )
     350             :             {
     351    21252288 :                 err[i] = syn[i] - ( gain * syn2[i] );
     352             :             }
     353             : 
     354             :             /* alpha = post-filtering factor (0=OFF, 1=100%) */
     355      336732 :             alpha = 0.0f;
     356             : 
     357      336732 :             *v_stab_smooth = 0.8f * v_stab + 0.2f * ( *v_stab_smooth );
     358             : 
     359      336732 :             set_f( syn2, 0.0f, subfr_len );
     360             :         }
     361             : 
     362             :         /* low-frequency noise estimator (lp_ener is average in dB) */
     363     2488977 :         deemph( err, 0.9f, subfr_len, &( hBPF->pst_mem_deemp_err ) ); /* +20dB at 50Hz */
     364             : 
     365     2488977 :         ener = 0.0001f;
     366   156594705 :         for ( i = 0; i < subfr_len; i++ )
     367             :         {
     368   154105728 :             ener += err[i] * err[i];
     369             :         }
     370     2488977 :         ener = (float) ( 10.0 * log10( ener ) );
     371     2488977 :         hBPF->pst_lp_ener = (float) ( 0.99f * hBPF->pst_lp_ener + 0.01f * ener );
     372             : 
     373             :         /* just write out the error signal */
     374     2488977 :         mvr2r( syn2, bpf_noise_buf + i_subfr, subfr_len );
     375             :     }
     376             : 
     377             :     /*-------------------------------------------------------*
     378             :      * update memory for next frame
     379             :      *-------------------------------------------------------*/
     380             : 
     381     5527800 :     for ( i = L_TRACK_HIST - 1; i > 0; i-- )
     382             :     {
     383     4975020 :         hBPF->Track_on_hist[i] = hBPF->Track_on_hist[i - 1];
     384     4975020 :         hBPF->vibrato_hist[i] = hBPF->vibrato_hist[i - 1];
     385             :     }
     386             : 
     387      552780 :     hBPF->Track_on_hist[i] = Track_on;
     388      552780 :     hBPF->vibrato_hist[i] = vibrato;
     389             : 
     390      552780 :     mvr2r( syn_buf + L_frame, hBPF->pst_old_syn, nbpsf_pit_max );
     391             : 
     392      552780 :     return;
     393             : }
     394             : 
     395             : 
     396             : /*---------------------------------------------------------------------*
     397             :  * Pit_track()
     398             :  *
     399             :  * Perform pitch tracking and test pitch/2 to avoid continuous pitch doubling
     400             :  *---------------------------------------------------------------------*/
     401             : 
     402             : /*! r: Pitch */
     403           0 : static int16_t Pit_track(
     404             :     const float syn[], /* i  : synthesis [-NBPSF_PIT_MAX..L_HALFR16k]  */
     405             :     int16_t T          /* i  : pitch period (>= PIT_MIN)               */
     406             : )
     407             : {
     408             :     int16_t i, T2;
     409             :     float tmp, corr, ener, cn;
     410             :     const float *v1, *v2;
     411             : 
     412             :     /*----------------------------------------------------------------*
     413             :      * Test pitch/2 to avoid continuous pitch doubling
     414             :      * (short pitch is limited to PIT_MIN (34 = 376Hz) by the encoder
     415             :      *----------------------------------------------------------------*/
     416             : 
     417           0 :     T2 = T >> 1;
     418             : 
     419           0 :     v1 = &syn[-NBPSF_L_EXTRA];
     420           0 :     v2 = &syn[-T2 - NBPSF_L_EXTRA];
     421             : 
     422           0 :     ener = 0.01f;
     423           0 :     for ( i = 0; i < L_HALFR16k + NBPSF_L_EXTRA; i++ )
     424             :     {
     425           0 :         ener += v1[i] * v1[i];
     426             :     }
     427           0 :     corr = 0.01f;
     428           0 :     for ( i = 0; i < L_HALFR16k + NBPSF_L_EXTRA; i++ )
     429             :     {
     430           0 :         corr += v1[i] * v2[i];
     431             :     }
     432           0 :     tmp = 0.01f;
     433           0 :     for ( i = 0; i < L_HALFR16k + NBPSF_L_EXTRA; i++ )
     434             :     {
     435           0 :         tmp += v2[i] * v2[i];
     436             :     }
     437             : 
     438             :     /* cn = normalized correlation of pitch/2 */
     439           0 :     cn = corr / (float) sqrt( ener * tmp );
     440           0 :     if ( cn > 0.95f )
     441             :     {
     442           0 :         T = T2;
     443             :     }
     444             : 
     445           0 :     return ( T );
     446             : }
     447             : 
     448             : 
     449             : /*---------------------------------------------------------------------*
     450             :  * addBassPostFilter()
     451             :  *
     452             :  * Add BPF component in cldfb domain
     453             :  *---------------------------------------------------------------------*/
     454             : 
     455      554130 : void addBassPostFilter(
     456             :     const float *harm_timeIn,
     457             :     const int16_t samplesToProcess,
     458             :     float **rAnalysis,
     459             :     float **iAnalysis,
     460             :     HANDLE_CLDFB_FILTER_BANK cldfb )
     461             : {
     462             :     float *tmp_R[CLDFB_NO_COL_MAX];
     463             :     float *tmp_I[CLDFB_NO_COL_MAX];
     464             :     float cldfbBufferReal[CLDFB_NO_COL_MAX][20];
     465             :     float cldfbBufferImag[CLDFB_NO_COL_MAX][20];
     466             :     int16_t i, b;
     467             :     int16_t maxBand;
     468             :     const float *weights;
     469      554130 :     int16_t nCol = cldfb->no_col;
     470      554130 :     int16_t nColToProcess = nCol;
     471      554130 :     int16_t nChan = cldfb->no_channels;
     472             : 
     473      554130 :     if ( samplesToProcess > -1 )
     474             :     {
     475      171066 :         nColToProcess = ( ( samplesToProcess + cldfb->no_channels - 1 ) / cldfb->no_channels );
     476             :     }
     477             : 
     478      554130 :     assert( nCol == 16 );
     479             : 
     480      554130 :     weights = bpf_weights_16;
     481             : 
     482      554130 :     if ( nChan > BPF_STOP_STOPBAND_16 )
     483             :     {
     484      272286 :         maxBand = BPF_STOP_STOPBAND_16;
     485             :     }
     486             :     else
     487             :     {
     488      281844 :         maxBand = nChan;
     489             :     }
     490             : 
     491     7822446 :     for ( i = 0; i < nColToProcess; i++ )
     492             :     {
     493     7268316 :         tmp_R[i] = cldfbBufferReal[i];
     494     7268316 :         tmp_I[i] = cldfbBufferImag[i];
     495             :     }
     496             : 
     497             :     /* do the analysis of filtered signal */
     498      554130 :     cldfbAnalysis( harm_timeIn, tmp_R, tmp_I, samplesToProcess, cldfb );
     499             : 
     500             :     /* now do the subtraction */
     501     7822446 :     for ( i = 0; i < nColToProcess; i++ )
     502             :     {
     503             :         /* loop over low frequency bands */
     504   123561372 :         for ( b = 0; b < maxBand; b++ )
     505             :         {
     506   116293056 :             rAnalysis[i][b] -= weights[b] * tmp_R[i][b];
     507   116293056 :             iAnalysis[i][b] -= weights[b] * tmp_I[i][b];
     508             :         }
     509             :     }
     510             : 
     511      554130 :     return;
     512             : }
     513             : 
     514             : /*---------------------------------------------------------------------*
     515             :  * res_bpf_adapt()
     516             :  *
     517             :  * Analyze BPF output and decide if it should be applied on DFT stereo
     518             :  * residual signal
     519             :  *---------------------------------------------------------------------*/
     520             : 
     521             : /*! r: Decision to enable or disable BPF on DFT stereo residual */
     522       32430 : int16_t res_bpf_adapt(
     523             :     STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */
     524             :     const float *bpf_error_signal_8k,      /* i  : BPF modification signal   */
     525             :     float res_buf[STEREO_DFT_N_8k]         /* i  : residual buffer           */
     526             : )
     527             : {
     528             :     float error_nrg;
     529             :     float tmp;
     530             :     float res_hb_nrg;
     531             :     float bpf_error_ratio;
     532             :     int16_t res_bpf_flag;
     533             :     int16_t i;
     534             :     int16_t i_start;
     535             :     int16_t i_end;
     536             :     float bw_inv;
     537             : 
     538       32430 :     if ( hStereoDft->res_cod_band_max == 6 )
     539             :     {
     540           0 :         i_start = 39;
     541           0 :         i_end = 64;
     542           0 :         bw_inv = 0.04f; /* 1/(64 - 39) */
     543             :     }
     544             :     else
     545             :     {
     546       32430 :         i_start = 28;
     547       32430 :         i_end = 40;
     548       32430 :         bw_inv = 0.083f; /* 1/(40 - 28) */
     549             :     }
     550             : 
     551             :     /* Measure energy of high frequency band in MDCT domain */
     552       32430 :     res_hb_nrg = EPSILON;
     553      421590 :     for ( i = i_start; i < i_end; i++ )
     554             :     {
     555      389160 :         res_hb_nrg += res_buf[i] * res_buf[i];
     556             :     }
     557       32430 :     res_hb_nrg *= bw_inv;
     558       32430 :     res_hb_nrg = STEREO_DFT_BPF_ADAPT_ALPHA * res_hb_nrg + ( 1 - STEREO_DFT_BPF_ADAPT_ALPHA ) * hStereoDft->res_hb_nrg_mem;
     559       32430 :     hStereoDft->res_hb_nrg_mem = res_hb_nrg;
     560             : 
     561             :     /* Measure energy of discontinuities at subframe boundaries */
     562       32430 :     error_nrg = 0;
     563      194580 :     for ( i = 0; i < L_FRAME8k; i += STEREO_DFT_L_SUBFR_8k )
     564             :     {
     565      162150 :         tmp = bpf_error_signal_8k[i] - hStereoDft->bpf_error_signal_last;
     566      162150 :         error_nrg += tmp * tmp;
     567      162150 :         hStereoDft->bpf_error_signal_last = bpf_error_signal_8k[i + STEREO_DFT_L_SUBFR_8k - 1];
     568             :     }
     569       32430 :     error_nrg *= 0.2f;                                  /* Division by 5 for average value */
     570       32430 :     bpf_error_ratio = min( 2, error_nrg / res_hb_nrg ); /* Form decision variable and apply limit */
     571       32430 :     bpf_error_ratio = STEREO_DFT_BPF_ADAPT_BETA * bpf_error_ratio + ( 1 - STEREO_DFT_BPF_ADAPT_BETA ) * hStereoDft->bpf_error_ratio_mem;
     572       32430 :     hStereoDft->bpf_error_ratio_mem = bpf_error_ratio;
     573             : 
     574       32430 :     res_bpf_flag = bpf_error_ratio < 1;
     575             : 
     576       32430 :     return res_bpf_flag;
     577             : }
     578             : 
     579             : /*---------------------------------------------------------------------*
     580             :  * bpf_pitch_coherence()
     581             :  *
     582             :  * Analyse pitch coherence
     583             :  *---------------------------------------------------------------------*/
     584      530307 : void bpf_pitch_coherence(
     585             :     Decoder_State *st,      /* i/o: decoder state structure            */
     586             :     const float pitch_buf[] /* i  : pitch for every subfr [0,1,2,3]    */
     587             : )
     588             : {
     589             :     int16_t nb_subfr;
     590             :     float pc, pcn1, pcn2, pcn3;
     591             : 
     592      530307 :     nb_subfr = st->L_frame / L_SUBFR;
     593             : 
     594      530307 :     if ( st->clas_dec > UNVOICED_CLAS && st->element_mode != EVS_MONO )
     595             :     {
     596      318516 :         pc = (float) fabs( st->old_pitch_buf[nb_subfr + 3] + st->old_pitch_buf[nb_subfr + 2] - st->old_pitch_buf[nb_subfr] - st->old_pitch_buf[nb_subfr + 1] ) * 256.0f / (float) st->L_frame;
     597      318516 :         pcn1 = K_PC_DEC * pc + C_PC_DEC;
     598      318516 :         pcn1 = max( min( pcn1, 1.0f ), 0.0f );
     599             : 
     600      318516 :         pc = (float) fabs( pitch_buf[nb_subfr - 1] + pitch_buf[nb_subfr - 2] - pitch_buf[1] - pitch_buf[0] ) * 256.0f / (float) st->L_frame;
     601      318516 :         pcn2 = K_PC_DEC * pc + C_PC_DEC;
     602      318516 :         pcn2 = max( min( pcn2, 1.0f ), 0.0f );
     603             : 
     604      318516 :         pc = (float) fabs( st->old_pitch_buf[nb_subfr + 3] + st->old_pitch_buf[nb_subfr + 2] - pitch_buf[1] - pitch_buf[0] ) * 256.0f / (float) st->L_frame;
     605      318516 :         pcn3 = K_PC_DEC * pc + C_PC_DEC;
     606      318516 :         pcn3 = max( min( pcn3, 1.0f ), 0.0f );
     607             : 
     608      318516 :         if ( pcn1 + pcn2 + pcn3 < 2.5f )
     609             :         {
     610       88965 :             st->hBPF->psf_att = 0.4f;
     611       88965 :             set_s( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr );
     612             :         }
     613             :     }
     614             : 
     615      530307 :     return;
     616             : }

Generated by: LCOV version 1.14