LCOV - code coverage report
Current view: top level - lib_dec - LD_music_post_filter_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 7e820311176f5319416dc4e8571404206d62343b Lines: 425 448 94.9 %
Date: 2025-07-16 03:24:37 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include "options.h" /* Compilation switches                   */
       7             : #include "cnst.h"    /* Common constants                       */
       8             : #include "rom_com.h" /* Static table prototypes                */
       9             : #include "prot_fx.h" /* Function prototypes                    */
      10             : 
      11             : 
      12             : /*-------------------------------------------------------------------*
      13             :  * Local constants
      14             :  *-------------------------------------------------------------------*/
      15             : 
      16             : #define INV_MAX_SNR_FX  745   /* Q15 {1/(45-1)} Max. SNR considered for noise subtraction in voiced segments  */
      17             : #define MAX_SNR_SNR1_FX 16756 /* Q14 45* (1/(max_snr1-1)) */
      18             : 
      19             : #define BIN_1KHZ ( Word16 )( 1000 / BIN_16kdct_fx )
      20             : #define BIN_2KHZ ( Word16 )( 2000 / BIN_16kdct_fx )
      21             : #define BIN_4KHZ ( Word16 )( 4000 / BIN_16kdct_fx )
      22             : 
      23             : #define MAX_GN_R_Q14_FX 3277
      24             : #define ALPH_Q15_FX     32767
      25             : #define BET_Q15_FX      30310
      26             : #define MAXX_Q12_FX     ( 20480 )
      27             : 
      28             : #define MAXX_FX 5
      29             : 
      30             : /*-------------------------------------------------------------------*
      31             :  * Local function prototypes
      32             :  *-------------------------------------------------------------------*/
      33             : static void analy_sp_dct_fx( const Word16 *dct_buf, Word32 *fr_bands, Word32 *lf_E, Word16 *etot, const Word16 Qdct );
      34             : static void find_enr_dct_fx( const Word16 data[], Word32 band[], Word32 *ptE, Word32 *Etot, const Word16 min_band, const Word16 max_band, const Word16 Q_dct, const Word16 bin_freq );
      35             : static Word16 norm_lfe( const Word32 Lfe, const Word16 m_max, const Word16 e_max );
      36             : static void spectrum_mod_dct_fx( const Word16 Qdct, Word16 data[], const Word32 lf_E[], Word32 lf_EO[], const Word32 noiseE[], const Word16 minGain, Word16 lp_gbin[], const Word16 music_flag, Word16 min_band, const Word16 MAX_GN, const Word16 MAX_band );
      37             : 
      38             : /*------------------------------------------------------------------------*
      39             :  * LD_music_post_filter()
      40             :  *
      41             :  * Music post-filter
      42             :  *------------------------------------------------------------------------*/
      43        9313 : void LD_music_post_filter_fx(
      44             :     MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */
      45             :     const Word16 dtc_in[],          /* i   : input synthesis                       Qdct   */
      46             :     Word16 dtc_out[],               /* o   : output synthesis                      Qdct   */
      47             :     const Word32 core_brate,        /* i   : core bitrate                             Q0  */
      48             :     Word16 *Old_ener_Q,             /* i/o : Old energy scaling factor             */
      49             :     const Word16 coder_type,        /* i   : Coder type : -1 in case of IO            Q0  */
      50             :     const Word16 Last_coder_type,   /* i   : input scaling                            Q0  */
      51             :     const Word16 Qdct               /* i   : input scaling                            Q0  */
      52             : )
      53             : {
      54             :     Word32 fr_bands[MBANDS_GN_LD]; /*2*Qdct+10*/
      55             :     Word32 lf_E[VOIC_BINS_HR];     /*2*Qdct+10*/
      56             :     Word32 Ltmp, Ltmp_max;
      57             :     Word16 LG_etot; /*Q8*/
      58             :     Word16 i, j, k;
      59        9313 :     Word16 min_band = 0;
      60             :     Word16 local_min_gain;
      61        9313 :     Word16 music_flag2 = 0;
      62             :     Word32 max_val;
      63             :     Word16 max_ovf_2k, max_ovf_4k, max_ovf_6k;
      64             :     Word16 min_g_2k, min_g_4k, min_g_6k;
      65             :     Word32 m_ave;
      66             :     Word16 tmp_lfE[DCT_L_POST]; /*Q12*/
      67        9313 :     Word16 MAX_GN = MAX_GN_R_Q14_FX;
      68        9313 :     Word16 MAX_band = MBANDS_GN_LD;
      69             :     Word16 mant, exp1, s_ave, tmp16, old_tmp16;
      70             :     Word16 diff_sc;
      71             :     Word16 old_tmp16_1;
      72             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      73        9313 :     Flag Overflow = 0;
      74             : #endif
      75        9313 :     move16();
      76        9313 :     move16();
      77        9313 :     move16();
      78        9313 :     move16();
      79        9313 :     move32();
      80             : 
      81             : 
      82        9313 :     local_min_gain = hMusicPF->LDm_enh_min_ns_gain_fx; /*Q15*/
      83        9313 :     move16();
      84             : 
      85             :     /*------------------------------------------------------------------------*
      86             :      * Frequency analysis
      87             :      *------------------------------------------------------------------------*/
      88             : 
      89        9313 :     analy_sp_dct_fx( dtc_in, fr_bands, lf_E, &LG_etot, Qdct );
      90        9313 :     diff_sc = shl( sub( Qdct, *Old_ener_Q ), 1 );
      91        9313 :     *Old_ener_Q = Qdct;
      92        9313 :     move16();
      93             : 
      94        9313 :     Scale_sig32( hMusicPF->LDm_enh_lf_EO_fx, VOIC_BINS_HR, diff_sc ); /*Q23*/
      95             : 
      96             :     /*------------------------------------------------------------------------*
      97             :      * Find signal classification
      98             :      *------------------------------------------------------------------------*/
      99        9313 :     music_flag2 = stab_est_fx( LG_etot, hMusicPF->LDm_lt_diff_etot_fx, &hMusicPF->LDm_mem_etot_fx, &hMusicPF->LDm_nb_thr_3, &hMusicPF->LDm_nb_thr_1, hMusicPF->LDm_thres_fx, &hMusicPF->LDm_last_music_flag, 1 );
     100             : 
     101        9313 :     test();
     102        9313 :     if ( LT_32( core_brate, ACELP_6k60 ) || NE_16( Last_coder_type, AUDIO ) )
     103             :     {
     104             :         /* do not perform music improvement on SID frames */
     105         696 :         music_flag2 = 0;
     106         696 :         move16();
     107             :     }
     108             : 
     109        9313 :     hMusicPF->last_nonfull_music = add( hMusicPF->last_nonfull_music, 1 );
     110        9313 :     move16();
     111        9313 :     if ( LT_16( music_flag2, 4 ) )
     112             :     {
     113        6137 :         hMusicPF->last_nonfull_music = 0;
     114        6137 :         move16();
     115             :     }
     116             : 
     117             : 
     118        9313 :     hMusicPF->last_nonfull_music = s_min( 51 /*Q0*/, hMusicPF->last_nonfull_music ); /*Q0*/
     119        9313 :     move16();
     120             : 
     121             :     /*------------------------------------------------------------------------*
     122             :      * Remapping of bands
     123             :      * Section to "remap" the minimal band and the minimum gain for our needs
     124             :      *------------------------------------------------------------------------*/
     125             : 
     126        9313 :     IF( GT_16( music_flag2, 3 ) )
     127             :     {
     128        3176 :         min_band = 2;
     129        3176 :         move16();
     130        3176 :         local_min_gain = 8231; /*Q15->0.25119f;*/
     131        3176 :         move16();
     132             :     }
     133        6137 :     ELSE IF( EQ_16( music_flag2, 3 ) )
     134             :     {
     135         373 :         min_band = 3;
     136         373 :         move16();
     137         373 :         local_min_gain = 8231; /*Q15->0.25119f; */
     138         373 :         move16();
     139             :     }
     140        5764 :     ELSE IF( EQ_16( music_flag2, 2 ) )
     141             :     {
     142         413 :         min_band = 4;
     143         413 :         move16();
     144         413 :         local_min_gain = 11626; /*Q15->0.35481f; */
     145         413 :         move16();
     146             :     }
     147        5351 :     ELSE IF( EQ_16( music_flag2, 1 ) )
     148             :     {
     149         923 :         min_band = 4;
     150         923 :         move16();
     151         923 :         local_min_gain = 16423; /*Q15->0.50119f;*/
     152         923 :         move16();
     153             :     }
     154             : 
     155        9313 :     min_band = add( min_band, 4 );
     156             : 
     157        9313 :     MAX_GN = 1638; /*Q14*/
     158        9313 :     move16();
     159        9313 :     if ( GT_32( core_brate, ACELP_9k60 ) )
     160             :     {
     161             :         /* overshoot not allowed, since GSC already matches the energy */
     162        2396 :         MAX_GN = 0;
     163        2396 :         move16();
     164             :     }
     165             : 
     166        9313 :     if ( EQ_16( coder_type, AUDIO ) )
     167             :     {
     168             :         /* with GSC we know for sure that we are in music */
     169        9313 :         min_band = s_min( min_band, 3 ); /*Q0*/
     170             :     }
     171             : 
     172             :     /*------------------------------------------------------------------------*
     173             :      * Approximation of the inter-harmonic noise level
     174             :      * - sort the bin energy
     175             :      * - compupte the average energy per band excluding the maximum energy bin
     176             :      *------------------------------------------------------------------------*/
     177             : 
     178        9313 :     j = 0;
     179        9313 :     move16();
     180        9313 :     Ltmp_max = L_deposit_l( 0 );
     181      195573 :     FOR( i = 0; i < MBANDS_GN_LD; i++ )
     182             :     {
     183      186260 :         Ltmp = L_deposit_l( 0 );
     184      186260 :         max_val = L_deposit_l( 0 );
     185             : 
     186     6146580 :         FOR( k = j; k < mfreq_bindiv_LD[i] + j; k++ )
     187             :         {
     188             :             /*m_ave += lf_E[k];*/
     189     5960320 :             Ltmp = L_add_o( lf_E[k], Ltmp, &Overflow ); /*2*Qdct+10*/
     190     5960320 :             max_val = L_max( max_val, lf_E[k] );
     191             :         }
     192      186260 :         Ltmp_max = L_max( Ltmp_max, max_val ); /*2*Qdct+10*/
     193             :         /*m_ave -= max_val;*/
     194      186260 :         Ltmp = L_sub( Ltmp, max_val );
     195             :         /*m_ave /=(mfreq_bindiv_LD[i]-1);*/
     196      186260 :         m_ave = Mult_32_16( Ltmp, inv_mfreq_bindiv_LD_M1_fx[i] ); /*2*Qdct+10*/
     197             : 
     198             :         /*bckr[i] = m_ave*sc_qnoise[i];*/
     199      186260 :         hMusicPF->LDm_bckr_noise_fx[i] = Mult_32_16( m_ave, sc_qnoise_fx[i] ); /*2*Qdct+10*/
     200      186260 :         move32();
     201             : 
     202      186260 :         j = add( j, mfreq_bindiv_LD[i] );
     203             :     }
     204             : 
     205             :     /* This is computed inside the loop i = maximum(lf_E, DCT_L_POST, &m_ave);*/
     206             :     /*------------------------------------------------------------------------*
     207             :      * - Normalisation of the energy vector between [0.72, 5], with the form of pow(x,4)
     208             :      * - Simple LP filtering along the frequency domain
     209             :      * - LT averaging with the past and in function of the stability factor
     210             :      *------------------------------------------------------------------------*/
     211             :     /*m_ave = ALPH/lf_E[i];*/
     212        9313 :     exp1 = norm_l( Ltmp_max );
     213        9313 :     mant = extract_h( L_shl( Ltmp_max, exp1 ) ); /*2*Qdct+exp1-6*/
     214             :     /*exp1 = sub(16,exp1);*/
     215             : 
     216        9313 :     s_ave = div_s( 16384 /*1.0f in Q14*/, mant );
     217        9313 :     exp1 = sub( 14 /*+15*/ + 16, exp1 );          /*s_ave in Q15 + exp1*/
     218        9313 :     old_tmp16 = norm_lfe( lf_E[0], s_ave, exp1 ); /*Q12*/
     219        9313 :     old_tmp16 = s_min( old_tmp16, MAXX_Q12_FX );  /*Q12*/
     220        9313 :     tmp16 = norm_lfe( lf_E[1], s_ave, exp1 );     /*Q12*/
     221        9313 :     tmp16 = s_min( tmp16, MAXX_Q12_FX );          /*Q12*/
     222        9313 :     old_tmp16_1 = tmp16;                          /*Q12*/
     223        9313 :     move16();
     224        9313 :     tmp_lfE[0] = round_fx( L_mac( L_mult( 16384 /*0.5f in Q15*/, old_tmp16 ), 16384 /*0.5f in Q15*/, tmp16 ) ); /*Q12*/
     225        9313 :     move16();
     226             : 
     227     5951007 :     FOR( i = 1; i < DCT_L_POST - 1; i++ )
     228             :     {
     229             :         /*tmp_lfE[i] = 0.333f*old_ftmp + 0.333f*ftmp;  */
     230     5941694 :         Ltmp = L_mac( L_mult( 10813 /*Q15*/, old_tmp16 ), 10813 /*Q15*/, old_tmp16_1 ); /*Q28*/
     231             : 
     232     5941694 :         old_tmp16 = old_tmp16_1; /*Q12*/
     233     5941694 :         move16();
     234     5941694 :         tmp16 = norm_lfe( lf_E[i + 1], s_ave, exp1 ); /*Q12*/
     235             :         /*ftmp = min(ftmp, MAXX);
     236             :         tmp_lfE[i] += 0.333f*ftmp;  */
     237     5941694 :         old_tmp16_1 = s_min( tmp16, MAXX_Q12_FX );        /*Q12*/
     238     5941694 :         Ltmp = L_mac( Ltmp, 10813 /*Q15*/, old_tmp16_1 ); /*Q28*/
     239     5941694 :         tmp_lfE[i] = round_fx( Ltmp );                    /*Q12*/
     240     5941694 :         move16();
     241             :     }
     242             : 
     243        9313 :     tmp16 = norm_lfe( lf_E[i], s_ave, exp1 );
     244             :     /*ftmp = min(ftmp, MAXX);
     245             :     tmp_lfE[i] = 0.5f*old_ftmp + 0.5f*ftmp;*/
     246        9313 :     tmp16 = s_min( tmp16, MAXX_Q12_FX );
     247        9313 :     tmp_lfE[i] = round_fx( L_mac( L_mult( 16384 /*0.5F in Q15*/, old_tmp16 ), 16384 /*0.5F in Q15*/, tmp16 ) ); /*Q12*/
     248        9313 :     move16();
     249             : 
     250     3734513 :     FOR( i = 0; i < BIN_4KHZ; i++ )
     251             :     {
     252             :         /*filt_lfE[i] = tmp_lfE[i]*.05f + .95f*filt_lfE[i] ;*/
     253     3725200 :         hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_mult( tmp_lfE[i], 1638 /*Q15*/ ), 31130 /*Q15*/, hMusicPF->filt_lfE_fx[i] ) ); /*Q12*/
     254     3725200 :         move16();
     255             :     }
     256             : 
     257     2244433 :     FOR( ; i < DCT_L_POST; i++ )
     258             :     {
     259             :         /*filt_lfE[i] = tmp_lfE[i]*(.15f) + .85f*filt_lfE[i] ;*/
     260     2235120 :         hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_mult( tmp_lfE[i], 4915 /*Q15*/ ), 27853 /*Q15*/, hMusicPF->filt_lfE_fx[i] ) ); /*Q12*/
     261     2235120 :         move16();
     262             :     }
     263             :     /*------------------------------------------------------------------------*
     264             :      * - Reduce inter-harmonic noise with SNR based method
     265             :      * - Second stage of spectral shaping modification based
     266             :      *   on the pow(x,4) energy spectrum
     267             :      *------------------------------------------------------------------------*/
     268             : 
     269        9313 :     if ( EQ_16( coder_type, AUDIO ) )
     270             :     {
     271        9313 :         MAX_band = 16;
     272        9313 :         move16();
     273             :     }
     274             : 
     275        9313 :     Copy( dtc_in, dtc_out, DCT_L_POST ); /*Qdct*/
     276             : 
     277        9313 :     spectrum_mod_dct_fx( Qdct, dtc_out, lf_E, hMusicPF->LDm_enh_lf_EO_fx, hMusicPF->LDm_bckr_noise_fx, local_min_gain, hMusicPF->LDm_enh_lp_gbin_fx, music_flag2, min_band, MAX_GN, MAX_band );
     278             : 
     279        9313 :     i = 0;
     280        9313 :     move16();
     281        9313 :     IF( GE_16( music_flag2, 1 ) )
     282             :     {
     283      493385 :         FOR( i = 0; i < BIN_1KHZ; i++ )
     284             :         {
     285      488500 :             tmp16 = s_min( 4096 /*1.0f in Q12*/, hMusicPF->filt_lfE_fx[i] );  /*Q12*/
     286      488500 :             dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); /*Q15*/
     287      488500 :             move16();
     288             :         }
     289             :     }
     290             :     {
     291        9313 :         IF( GT_16( hMusicPF->last_nonfull_music, 40 ) )
     292             :         {
     293        1789 :             max_ovf_2k = 5120; /*1.25 Q12*/
     294        1789 :             move16();
     295        1789 :             max_ovf_4k = 6144; /*1.5 Q12*/
     296        1789 :             move16();
     297        1789 :             max_ovf_6k = 6144; /*1.5 Q12*/
     298        1789 :             move16();
     299             : 
     300        1789 :             min_g_2k = 0;
     301        1789 :             move16();
     302        1789 :             min_g_4k = 0;
     303        1789 :             move16();
     304        1789 :             min_g_6k = 0;
     305        1789 :             move16();
     306             : 
     307        1789 :             IF( EQ_16( coder_type, AUDIO ) )
     308             :             {
     309        1789 :                 max_ovf_2k = 4096; /*1.0 Q12*/
     310        1789 :                 move16();
     311        1789 :                 max_ovf_4k = 4506; /*1.1 Q12*/
     312        1789 :                 move16();
     313        1789 :                 max_ovf_6k = 5120; /*1.25 Q12*/
     314        1789 :                 move16();
     315             : 
     316        1789 :                 min_g_2k = 3072; /*0.75 Q12*/
     317        1789 :                 move16();
     318        1789 :                 min_g_4k = 2048; /*0.5 Q12*/
     319        1789 :                 move16();
     320        1789 :                 min_g_6k = 2048; /*0.5 Q12*/
     321        1789 :                 move16();
     322             : 
     323        1789 :                 IF( GT_32( core_brate, ACELP_9k60 ) )
     324             :                 {
     325         135 :                     max_ovf_4k = 4096; /*1.0 Q12*/
     326         135 :                     move16();
     327         135 :                     max_ovf_6k = 4710; /*1.15 Q12*/
     328         135 :                     move16();
     329             : 
     330         135 :                     min_g_2k = 3789; /*0.925 Q12*/
     331         135 :                     move16();
     332         135 :                     min_g_4k = 3379; /*0.825 Q12*/
     333         135 :                     move16();
     334         135 :                     min_g_6k = 3072; /*0.75  Q12*/
     335         135 :                     move16();
     336             :                 }
     337             :             }
     338           0 :             ELSE IF( GE_32( core_brate, ACELP_12k65 ) )
     339             :             {
     340           0 :                 max_ovf_2k = 4096; /*1.0 Q12*/
     341           0 :                 move16();
     342           0 :                 max_ovf_4k = 5120; /*1.25 Q12*/
     343           0 :                 move16();
     344             : 
     345           0 :                 IF( GT_32( core_brate, ACELP_15k85 ) )
     346             :                 {
     347           0 :                     max_ovf_4k = 4096; /*1.0 Q12*/
     348           0 :                     move16();
     349           0 :                     max_ovf_6k = 5120; /*1.25 Q12*/
     350           0 :                     move16();
     351             : 
     352           0 :                     min_g_2k = 3072; /*0.75 Q12*/
     353           0 :                     move16();
     354           0 :                     min_g_4k = 2048; /*0.5 Q12*/
     355           0 :                     move16();
     356           0 :                     min_g_6k = 2048; /*0.5 Q12*/
     357           0 :                     move16();
     358             :                 }
     359             :             }
     360             : 
     361      180689 :             FOR( ; i < BIN_2KHZ; i++ )
     362             :             {
     363      178900 :                 tmp16 = s_min( max_ovf_2k, hMusicPF->filt_lfE_fx[i] );                    /*Q12*/
     364      178900 :                 tmp16 = s_max( min_g_2k, tmp16 );                                         /*Q12*/
     365             :                                                                                           /*DCT_buf[i] *= ftmp;*/
     366      178900 :                 dtc_out[i] = round_fx_sat( L_shl_sat( L_mult( dtc_out[i], tmp16 ), 3 ) ); /*Q15*/
     367      178900 :                 move16();
     368             :             }
     369             : 
     370      359589 :             FOR( ; i < BIN_4KHZ; i++ )
     371             :             {
     372      357800 :                 tmp16 = s_min( max_ovf_4k, hMusicPF->filt_lfE_fx[i] );                        /*Q12*/
     373      357800 :                 tmp16 = s_max( min_g_4k, tmp16 );                                             /*Q12*/
     374             :                                                                                               /*DCT_buf[i] *= ftmp;*/
     375      357800 :                 dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); /*Q15*/
     376      357800 :                 move16();
     377             :             }
     378             : 
     379        1789 :             test();
     380        1789 :             IF( NE_16( coder_type, AUDIO ) || GT_32( core_brate, ACELP_8k85 ) )
     381             :             {
     382             :                 /* Do not modify HF when coded with GSC at LR, because the spectrum is just noise */
     383       32535 :                 FOR( ; i < DCT_L_POST; i++ )
     384             :                 {
     385       32400 :                     tmp16 = s_min( max_ovf_6k, hMusicPF->filt_lfE_fx[i] );                        /*Q12*/
     386       32400 :                     tmp16 = s_max( min_g_6k, tmp16 );                                             /*Q12*/
     387             :                                                                                                   /*DCT_buf[i] *= ftmp;*/
     388       32400 :                     dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); /*Q15*/
     389       32400 :                     move16();
     390             :                 }
     391             :             }
     392             :         }
     393        7524 :         ELSE IF( GT_16( hMusicPF->last_nonfull_music, 25 ) )
     394             :         {
     395             :             /* When unsure on content type only slight clean-up allowed, no overshoot allowed */
     396      123889 :             FOR( ; i < DCT_L_POST; i++ )
     397             :             {
     398      123660 :                 tmp16 = s_min( 4096 /*1.0f in Q12*/, hMusicPF->filt_lfE_fx[i] );              /*Q12*/
     399             :                                                                                               /*DCT_buf[i] *= ftmp;*/
     400      123660 :                 dtc_out[i] = round_fx_sat( L_shl_sat( L_mult_sat( dtc_out[i], tmp16 ), 3 ) ); /*Q15*/
     401      123660 :                 move16();
     402             :             }
     403             :         }
     404             :     }
     405        9313 : }
     406             : 
     407             : /*---------------------------------------------------------------------------*
     408             :  * spectrum_mod_dct()
     409             :  *
     410             :  * spectrum enhancement according to the output of signal_type_clas()
     411             :  *---------------------------------------------------------------------------*/
     412             : 
     413        9313 : static void spectrum_mod_dct_fx(
     414             :     const Word16 Qdct,       /* i  : scaling factor                               Q0       */
     415             :     Word16 data[],           /* i/o: dct spectrum                                    Qdct      */
     416             :     const Word32 lf_E[],     /* i:   per bin E for first 46 bins (without DC)    2*Qdct+10 */
     417             :     Word32 lf_EO[],          /* i/o: old per bin E for previous half frame      2*Qdct+10 */
     418             :     const Word32 noiseE[],   /* i:   per band background noise energy estimate  2*Qdct+10 */
     419             :     const Word16 minGain,    /* i:   minimum suppression gain                   Q15 */
     420             :     Word16 lp_gbin[],        /* i/o: Smoothed suppression gain, per FFT bin     Q14*/
     421             :     const Word16 music_flag, /* i:   music ? 1:0                                    */
     422             :     Word16 min_band,         /* i  : minimum band                                   */
     423             :     const Word16 MAX_GN,     /* i  : Maximum gain overshoot                         */
     424             :     const Word16 MAX_band    /* i  : minimum band                                   */
     425             : )
     426             : {
     427             :     Word32 maxNoise;
     428             :     Word32 binE[VOIC_BINS_HR], Lgain;
     429        9313 :     Word16 gain = 0, minE;
     430             :     Word16 freq, slope, m_invno[MBANDS_GN_LD], e_invno[MBANDS_GN_LD];
     431             :     Word16 *pt_gbin, alpha, tmpN;
     432             :     Word16 i;
     433             :     Word32 Ltmp;
     434             :     Word16 scaling;
     435             :     Word16 tmp_snr;
     436             :     Word16 *pt;
     437             :     Word16 wtmp;
     438             :     Word16 e_tmp;
     439             :     Word16 m_binE, e_binE;
     440             :     Word16 e_gain;
     441             :     Word16 sqrt_gain;
     442             :     Word32 Lshift;
     443             :     Word32 dot5_scaled;
     444             :     const Word32 *Lpt2;
     445             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     446        9313 :     Flag Overflow = 0;
     447             : #endif
     448             : 
     449        9313 :     move16();
     450        9313 :     move32();
     451             : 
     452        9313 :     gain = 0;
     453        9313 :     move16();
     454             : 
     455             :     /*-----------------------------------------------------------------*
     456             :      * Compute the inverse of noise
     457             :      *-----------------------------------------------------------------*/
     458             : 
     459        9313 :     scaling = add( shl( Qdct, 1 ), 10 );
     460        9313 :     IF( LE_16( scaling, 31 ) )
     461             :     {
     462             :         /* Calculate .5 in Qscaling only if scaling <= 31 */
     463        9313 :         dot5_scaled = L_shl( 1, sub( scaling, 1 ) );
     464             :     }
     465             :     ELSE
     466             :     {
     467             :         /* This is only for avaoiding build warning */
     468           0 :         dot5_scaled = MAX_32;
     469           0 :         move32();
     470             :     }
     471             : 
     472      195573 :     FOR( i = 0; i <= MBANDS_GN_LD - 1; i++ )
     473             :     {
     474             :         /*inv_noise[i] = 1.0f / noiseE[i];*/
     475      186260 :         IF( noiseE[i] != 0 )
     476             :         {
     477      186260 :             e_invno[i] = norm_l( noiseE[i] );
     478      186260 :             move16();
     479      186260 :             m_invno[i] = extract_h( L_shl( noiseE[i], e_invno[i] ) ); /* 2*Qdct + e_invno[i] - 6 */
     480      186260 :             move16();
     481      186260 :             e_invno[i] = sub( 14, e_invno[i] );
     482      186260 :             move16();
     483      186260 :             m_invno[i] = div_s( 16384 /*1.0f in Q14*/, m_invno[i] ); /*Q15*/
     484      186260 :             move16();
     485             :         }
     486             :         ELSE
     487             :         {
     488             :             /* noiseE[i] == 0 only if Q_new <0*/
     489           0 :             e_invno[i] = add( -16, Qdct );
     490           0 :             move16();
     491           0 :             m_invno[i] = MAX_16;
     492           0 :             move16();
     493             :         }
     494             :     }
     495             :     /*----------------------------------------------------------------------*
     496             :      * Perform noise reduction for 1 frames
     497             :      *----------------------------------------------------------------------*/
     498     5969633 :     FOR( i = 0; i < VOIC_BINS_HR; i++ )
     499             :     {
     500             :         /*binE[i] = (float)(0.3 * lf_EO[i] + 0.7 * lf_E[i]);*/
     501     5960320 :         Ltmp = Mult_32_16( lf_EO[i], 9830 /*0.3f in Q15*/ );          /*2*Qdct+10*/
     502     5960320 :         binE[i] = Madd_32_16( Ltmp, lf_E[i], 22938 /*0.7f in Q15*/ ); /*2*Qdct+10*/
     503     5960320 :         move32();
     504             :     }
     505        9313 :     Copy32( lf_E, lf_EO, VOIC_BINS_HR ); /* update 2*Qdct+10*/
     506             :     /*----------------------------------------------------------------------*
     507             :      * Find the maximum noise in a critical band
     508             :      *----------------------------------------------------------------------*/
     509             : 
     510        9313 :     maxNoise = L_max( noiseE[0], noiseE[1] ); /*2*Qdct+10*/
     511      176947 :     FOR( i = 2; i <= MBANDS_GN_LD - 1; i++ )
     512             :     {
     513      167634 :         maxNoise = L_max( maxNoise, noiseE[i] ); /*2*Qdct+10*/
     514             :     }
     515             : 
     516             :     /* pointer initialization */
     517        9313 :     pt = &data[0];
     518             : 
     519             :     /*-----------------------------------------------------------------*
     520             :      * Initialization for active speech frames or VAD hangover frames,
     521             :      * (exclude Clean speech)
     522             :      *-----------------------------------------------------------------*/
     523             : 
     524        9313 :     IF( music_flag != 0 ) /* prevent subtraction on clean speech */
     525             :     {
     526        4885 :         IF( LE_32( maxNoise, L_shl_o( 10, scaling, &Overflow ) ) )
     527             :         {
     528        4076 :             minE = 18432 / 2; /*Q14*/
     529        4076 :             move16();
     530             :         }
     531             :         ELSE
     532             :         {
     533         809 :             minE = shr( mult_r( minGain, minGain ), 1 ); /*Q14*/
     534             :         }
     535             : 
     536        4885 :         Lpt2 = binE; /*2*Qdct+10*/
     537        4885 :         freq = 0;
     538        4885 :         move16();
     539             : 
     540        4885 :         pt_gbin = lp_gbin; /*Q14*/
     541       19540 :         FOR( i = 0; i < min_band; i++ )
     542             :         {
     543             : 
     544      166090 :             FOR( ; freq <= mfreq_loc_LD_fx[i]; freq += BIN_16kdct_fx )
     545             :             {
     546      151435 :                 Lpt2++;
     547             :                 /* Lgain is already saturate if it's > 1*/
     548      151435 :                 pt++;
     549      151435 :                 *pt_gbin = 16384; /*Q14*/
     550      151435 :                 move16();
     551      151435 :                 pt_gbin++;
     552             :             }
     553             :         }
     554             :         /*-----------------------------------------------------------------*
     555             :          * Per Frequency BIN processing
     556             :          * For highly voiced and highly pitched speech, use per bin
     557             :          * subtraction in low frequencies (maximum up to 3700 Hz,
     558             :          * first 17 critical bands)
     559             :          *-----------------------------------------------------------------*/
     560             : 
     561       68390 :         FOR( ; i < MAX_band; i++ )
     562             :         {
     563             : 
     564             :             /*tmp = INV_MAX_SNR_tab[i];
     565             :             slope =  tmp - tmp * minE;
     566             :             shift =  MAX_SNR_SNR1_tab[i] * minE - tmp;*/
     567             : 
     568             :             /*tmp = 1.0f/ (MAX_SNR1 - 1.0f);*/
     569       63505 :             tmp_snr = INV_MAX_SNR_tab_FX[i]; /*Q15*/
     570       63505 :             move16();
     571             :             /*slope = -tmp * minE + tmp;*/
     572       63505 :             Ltmp = L_mult( tmp_snr, 16384 /*1.0f in Q14*/ ); /*Q30*/
     573       63505 :             slope = msu_r( Ltmp, tmp_snr, minE );            /*Q14*/
     574             : 
     575             :             /*shift = MAX_SNR1 * tmp * minE - tmp;*/
     576       63505 :             Ltmp = L_mult( MAX_SNR_SNR1_tab_FX[i], minE ); /*Q14*Q14*/
     577       63505 :             Lshift = L_msu( Ltmp, tmp_snr, 8192 );         /*Q15*Q13+Q29*/
     578       63505 :             Lshift = L_shl( Lshift, 1 );                   /*Q29 -> Q30*/
     579             : 
     580             :             /*tmpN = slope * inv_noise[i];*/
     581       63505 :             tmpN = mult( slope, m_invno[i] ); /*Q14*/
     582       63505 :             e_tmp = e_invno[i];
     583       63505 :             move16();
     584             : 
     585             :             /*while (freq <= mfreq_loc_LD[i])*/
     586     1455730 :             FOR( ; freq <= mfreq_loc_LD_fx[i]; freq += BIN_16kdct_fx )
     587             :             {
     588             :                 /*gain = 1.0f;*/
     589     1392225 :                 Lgain = L_deposit_h( 16384 /*1.0f in Q14*/ ); /*Q30*/
     590             :                 /*if (noiseE[i] >= 0.5f)*/
     591     1392225 :                 test();
     592     1392225 :                 IF( LT_16( scaling, 32 ) && GT_32( noiseE[i], dot5_scaled ) ) /* Do not alter if noise E very low */
     593             :                 {
     594             :                     /*gain = tmpN * *pt2 + shift;*/ /* limits: [x,y] = {[1, minE], [MAX_SNR1, 1]}, */
     595      638087 :                     e_binE = norm_l( *Lpt2 );
     596      638087 :                     m_binE = extract_h( L_shl( *Lpt2, e_binE ) ); /*2*Qdct+e_binE-6*/
     597             : 
     598      638087 :                     e_binE = sub( e_binE, 0 ); /* lf_e divided by 4 in anal_sp*/
     599             : 
     600      638087 :                     Ltmp = L_mult( tmpN, m_binE ); /*2*Qdct+e_binE+9*/
     601      638087 :                     e_binE = sub( add( e_tmp, e_binE ), 15 );
     602      638087 :                     Ltmp = L_shr_o( Ltmp, e_binE, &Overflow );  /*2*Qdct+9*/
     603      638087 :                     Lgain = L_add_o( Ltmp, Lshift, &Overflow ); /*Saturation can occure here result in Q30*/
     604             :                 }
     605             : 
     606     1392225 :                 Lpt2++;
     607     1392225 :                 gain = round_fx_o( Lgain, &Overflow ); /*gain in Q30-16 = Q14*/
     608             :                 /*if (gain < minE)gain = minE;*/
     609     1392225 :                 gain = s_max( gain, minE ); /*Q14*/
     610             :                 /*if (gain > 1.0f+MAX_GN)gain = 1.0f+MAX_GN;*/
     611     1392225 :                 gain = s_min( gain, add( 16384 /*1.0f in Q14*/, MAX_GN ) ); /*Q14*/
     612             : 
     613             :                 /* prepare gain to find sqrt */
     614     1392225 :                 e_gain = norm_s( gain );
     615     1392225 :                 Ltmp = L_shl( gain, add( 16, e_gain ) ); /* Q30+e_gain */
     616     1392225 :                 e_gain = negate( sub( e_gain, 1 ) );
     617             : 
     618     1392225 :                 Ltmp = Isqrt_lc( Ltmp, &e_gain );
     619     1392225 :                 wtmp = extract_h( Ltmp );
     620     1392225 :                 sqrt_gain = div_s( 16384 /*Q14*/, wtmp ); /*Q15*/
     621             : 
     622             : 
     623             :                 /* the gain smoothing control: stronger lp filtering for lower gains */
     624             :                 /*alpha = 1.0f - (float)sqrt(gain);*/
     625             :                 /* keep gain in Q14*/
     626     1392225 :                 sqrt_gain = shr( sqrt_gain, e_gain );              /*Q14*/
     627             :                 /*alpha = 1.0f - gain;*/                           /* the gain smoothing control: stronger LP filtering for lower gains */
     628     1392225 :                 alpha = shl( sub( 16384 /*Q14*/, sqrt_gain ), 1 ); /*Q15*/
     629             : 
     630             :                 /**pt_gbin = gain + alpha * *pt_gbin;*/
     631     1392225 :                 Ltmp = L_mult( gain, 32767 /*Q15*/ );                          /*Q30*/
     632     1392225 :                 *pt_gbin = round_fx( L_mac( Ltmp, alpha, *pt_gbin ) );         /*Q14*/
     633             :                                                                                /**pt++ *= *pt_gbin;*/
     634     1392225 :                 *pt = round_fx_sat( L_shl_sat( L_mult( *pt, *pt_gbin ), 1 ) ); /*Qdct*/
     635     1392225 :                 move16();
     636     1392225 :                 move16();
     637     1392225 :                 pt++;
     638     1392225 :                 pt_gbin++;
     639             :             }
     640             :         }
     641             :     }
     642             :     ELSE
     643             :     {
     644        4428 :         freq = BIN_16kdct_fx;
     645        4428 :         move16();
     646        4428 :         pt_gbin = lp_gbin; /*Q14*/
     647        4428 :         move16();
     648       92988 :         FOR( i = 0; i < MBANDS_GN_LD; i++ )
     649             :         {
     650     2918052 :             FOR( ; freq <= mfreq_loc_LD_fx[i]; freq += BIN_16kdct_fx )
     651             :             {
     652             :                 /**pt_gbin = 0.9f* *pt_gbin + 0.1f;*/
     653     2829492 :                 *pt_gbin = round_fx( L_mac( L_mult( 29491 /*0.9f in Q15*/, *pt_gbin ), 32767 /*Q15*/, 1638 /*0.1f in Q14*/ ) ); /*Q14*/
     654     2829492 :                 move16();
     655     2829492 :                 pt_gbin++;
     656             :             }
     657             :         }
     658             :     }
     659             : 
     660        9313 :     return;
     661             : }
     662             : 
     663             : 
     664             : /*----------------------------------------------------------------------------------*
     665             :  * analy_sp_dct()
     666             :  *
     667             :  * Spectral analysis of the current synthesized frame
     668             :  *----------------------------------------------------------------------------------*/
     669             : 
     670        9313 : static void analy_sp_dct_fx(
     671             :     const Word16 *dct_buf, /* i  input dct spectrum                             */
     672             :     Word32 *fr_bands,      /* o:  energy in critical frequency bands 2*Qdct+10   */
     673             :     Word32 *lf_E,          /* o:  per bin E for first...             2*Qdct+10 */
     674             :     Word16 *etot,          /* o:  total input energy                Q8 */
     675             :     const Word16 Qdct      /* i:  Scaling of dct                       */
     676             : )
     677             : {
     678        9313 :     Word32 Letot = 0;
     679        9313 :     move32();
     680             :     Word16 exp_etot, frac_etot;
     681             : 
     682        9313 :     Letot = L_deposit_l( 0 );
     683             :     /*-----------------------------------------------------------------*
     684             :      * find energy per critical frequency band and total energy in dB
     685             :      *-----------------------------------------------------------------*/
     686        9313 :     find_enr_dct_fx( dct_buf, fr_bands, lf_E, &Letot, 0, MBANDS_GN_LD, Qdct, BIN_16kdct_fx );
     687             : 
     688             :     /* find average log total energy over both half-frames */
     689             :     /**etot = 10.0f * (float)log10(*etot) - 3.0103f;*/
     690        9313 :     exp_etot = norm_l( Letot );
     691        9313 :     frac_etot = Log2_norm_lc( L_shl( Letot, exp_etot ) ); /*Q15*/
     692        9313 :     exp_etot = sub( 30, exp_etot );
     693        9313 :     exp_etot = sub( exp_etot, add( shl( Qdct, 1 ), 10 + 1 ) ); /* +(1) */
     694        9313 :     Letot = Mpy_32_16( exp_etot, frac_etot, LG10 );            /*Q14*/
     695             :     /* Q8 Averaged the total energy over both half-frames in log10 */
     696        9313 :     *etot = extract_l( L_shr( Letot, 14 - 8 ) ); /*Q8*/
     697        9313 :     move16();
     698             : 
     699        9313 :     return;
     700             : }
     701             : 
     702             : /*------------------------------------------------------------------------*
     703             :  * find_enr_dct)
     704             :  *
     705             :  * find input signal energy for each critical band and first 74 LF bins
     706             :  * The energy is normalized by the number of frequency bins in a channel
     707             :  *------------------------------------------------------------------------*/
     708             : 
     709        9313 : static void find_enr_dct_fx(
     710             :     const Word16 data[],   /* i  : dct result, for the format           Qdct*/
     711             :     Word32 band[],         /* o  : per band energy                     2*Qdct+10*/
     712             :     Word32 *ptE,           /* o  : per bin energy  for low frequencies 2*Qdct+10*/
     713             :     Word32 *Etot,          /* o  : total energy                        2*Qdct+10*/
     714             :     const Word16 min_band, /* i  : minimum critical band                Q0  */
     715             :     const Word16 max_band, /* i  : maximum critical band                Q0  */
     716             :     const Word16 Q_dct,    /* i  : scaling factor                       Q0  */
     717             :     const Word16 bin_freq  /* i  : Number of frequency bins             Q0  */
     718             : )
     719             : {
     720             :     Word16 i;
     721             :     Word16 freq;
     722             :     const Word16 *ptR;
     723             :     Word32 LE_min, Ltmp, Ltmp1;
     724             : 
     725             : 
     726        9313 :     LE_min = L_max( L_shl( E_MIN_Q15, sub( add( shl( Q_dct, 1 ), 10 ), 22 ) ), 1 ); /* 2*Q_dct + 10*/
     727             : 
     728        9313 :     ptR = &data[0]; /* pointer to first real coefficient Qdct*/
     729        9313 :     freq = 0;
     730        9313 :     move16();
     731      195573 :     FOR( i = 0; i < max_band; i++ )
     732             :     {
     733      186260 :         band[i] = 0;
     734      186260 :         move16();
     735      186260 :         Ltmp1 = L_deposit_l( 0 );
     736     6146580 :         FOR( ; freq <= mfreq_loc_LD_fx[i]; freq += bin_freq )
     737             :         {
     738             :             /* energy  */
     739             :             /**ptE = *ptR * *ptR;           */
     740     5960320 :             Ltmp = L_mult_sat( *ptR, *ptR ); /*2*Qdct+1*/
     741             :             /* normalization */
     742             :             /**ptE *= 1.0f / (DCT_L_POST);*/
     743     5960320 :             Ltmp = Mult_32_16( Ltmp, 26214 ); /*26214 = 1.0/640 ->Q15+9 --> 2*Q_dct + 10*/
     744     5960320 :             Ltmp = L_max( Ltmp, LE_min );     /*2*Q_dct + 10*/
     745     5960320 :             *ptE = Ltmp;                      /*2*Q_dct + 10*/
     746     5960320 :             move32();
     747             : 
     748             :             /*band[i] += *ptE++;*/
     749     5960320 :             Ltmp1 = L_add_sat( Ltmp, Ltmp1 ); /*2*Q_dct + 10*/
     750             : 
     751     5960320 :             ptE++;
     752     5960320 :             ptR++;
     753             :         }
     754             : 
     755             :         /* normalization per frequency bin */
     756             :         /*band[i] /= cnt;*/
     757      186260 :         band[i] = L_max( Mult_32_16( Ltmp1, inv_mfreq_bindiv_LD_fx[i] ), LE_min );
     758      186260 :         move32(); /* 2*Q_dct + 10*/
     759             :     }
     760             : 
     761             :     /*-----------------------------------------------------------------*
     762             :      * Find the total energy over the input bandwidth
     763             :      *-----------------------------------------------------------------*/
     764             : 
     765        9313 :     Ltmp = 0;
     766        9313 :     move16();
     767      167634 :     FOR( i = min_band; i <= NB_LIMIT_BAND; i++ )
     768             :     {
     769             :         /* total channel energy */
     770      158321 :         Ltmp = L_add_sat( band[i], Ltmp ); /* 2*Q_dct + 10*/
     771             :     }
     772             : 
     773        9313 :     *Etot = Ltmp; /* 2*Q_dct + 10*/
     774        9313 :     move32();
     775             : 
     776        9313 :     return;
     777             : }
     778             : 
     779             : /*------------------------------------------------------------------------*
     780             :  * Prep_music_postP()
     781             :  *
     782             :  * Performs the steps needed to do the music post processing
     783             :  *------------------------------------------------------------------------*/
     784             : 
     785        9313 : void Prep_music_postP_fx(
     786             :     Word16 exc_buffer_in[],    /* i/o: excitation buffer   Q_exc*/
     787             :     Word16 dct_buffer_out[],   /* o  : DCT output buffer   (qdct)*/
     788             :     Word16 filt_lfE[],         /* i/o: long term spectrum energy Q12*/
     789             :     const Word16 last_core,    /* i  : last core  */
     790             :     const Word16 element_mode, /* i  : element mode  */
     791             :     const Word16 *pitch_buf,   /* i  : current frame pitch information Q6*/
     792             :     Word16 *LDm_enh_lp_gbin,   /* o  : smoothed suppression gain, per dct bin Q14*/
     793             :     const Word16 Q_exc,        /* i  : excitation scaling         */
     794             :     Word16 *qdct               /* o  : Scaling factor of dct coefficient */
     795             : )
     796             : {
     797             :     Word16 i;
     798             :     Word16 *pt1;
     799             :     const Word16 *pt2;
     800             :     Word16 s_pit, fr_pit;
     801             : 
     802             :     Word16 exc16[DCT_L_POST];
     803             :     Word16 *pt1_out;
     804             : 
     805        9313 :     s_pit = shr( pitch_buf[3], 6 );                          /*Q0*/
     806        9313 :     fr_pit = shr( sub( pitch_buf[3], shl( s_pit, 6 ) ), 4 ); /* Find fractional part Q2*/
     807             : 
     808             :     /*------------------------------------------------------------*
     809             :      * Resetting some memories in case of switching
     810             :      *------------------------------------------------------------*/
     811        9313 :     test();
     812        9313 :     test();
     813        9313 :     test();
     814        9313 :     test();
     815        9313 :     test();
     816        9313 :     IF( ( EQ_16( element_mode, EVS_MONO ) && EQ_16( last_core, HQ_CORE ) ) || ( NE_16( element_mode, EVS_MONO ) && ( EQ_16( last_core, HQ_CORE ) || EQ_16( last_core, TCX_20_CORE ) || EQ_16( last_core, TCX_10_CORE ) ) ) )
     817             :     {
     818         626 :         set16_fx( filt_lfE, 4096 /*Q12*/, DCT_L_POST );
     819         626 :         set16_fx( LDm_enh_lp_gbin, 16384 /*Q14*/, VOIC_BINS_HR );
     820         626 :         pt1 = exc_buffer_in + OFFSET2 - 1;    /*Q_exc*/
     821         626 :         pt2 = pt1 + shr_r( pitch_buf[0], 6 ); /*Q_exc*/
     822      120818 :         FOR( i = 0; i < OFFSET2; i++ )
     823             :         {
     824      120192 :             *pt1 = *pt2;
     825      120192 :             move16();
     826      120192 :             pt1--;
     827      120192 :             pt2--;
     828             :         }
     829             :     }
     830             : 
     831             :     /*------------------------------------------------------------*
     832             :      * Extrapolation of the last future part and windowing
     833             :      *------------------------------------------------------------*/
     834        9313 :     pt1 = exc_buffer_in + DCT_L_POST - OFFSET2; /*Q_exc*/
     835        9313 :     IF( element_mode != EVS_MONO )
     836             :     {
     837        9313 :         pred_lt4_ivas_fx( pt1, pt1, s_pit, fr_pit, OFFSET2, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     838             :     }
     839             :     ELSE
     840             :     {
     841           0 :         pred_lt4( pt1, pt1, s_pit, fr_pit, OFFSET2, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     842             :     }
     843             :     /*------------------------------------------------------------*
     844             :      *  windowing right side
     845             :      *------------------------------------------------------------*/
     846        9313 :     pt2 = post_dct_wind_fx; /*Q15*/
     847        9313 :     pt1_out = exc16 + DCT_L_POST - OFFSET2;
     848     1797409 :     FOR( i = 0; i < OFFSET2; i++ )
     849             :     {
     850     1788096 :         *pt1_out = mult_r( *pt1, *pt2 ); /*Q_exc*/
     851     1788096 :         move16();
     852     1788096 :         pt1++;
     853     1788096 :         pt2++;
     854     1788096 :         pt1_out++;
     855             :     }
     856             :     /*------------------------------------------------------------*
     857             :      *  windowing left side
     858             :      *------------------------------------------------------------*/
     859        9313 :     pt1 = exc_buffer_in; /*Q_exc*/
     860        9313 :     pt1_out = exc16;
     861        9313 :     pt2--;
     862     1797409 :     FOR( i = 0; i < OFFSET2; i++ )
     863             :     {
     864     1788096 :         *pt1_out = mult_r( *pt1, *pt2 ); /*Q_exc*/
     865     1788096 :         move16();
     866     1788096 :         pt1++;
     867     1788096 :         pt1_out++;
     868     1788096 :         pt2--;
     869             :     }
     870             :     /*------------------------------------------------------------*
     871             :      *  Copy remaining data (Flat part)
     872             :      *------------------------------------------------------------*/
     873             : 
     874     2393441 :     FOR( ; i < L_FRAME + OFFSET2; i++ )
     875             :     {
     876     2384128 :         *pt1_out = *pt1; /*Q_exc*/
     877     2384128 :         move16();
     878     2384128 :         pt1++;
     879     2384128 :         pt1_out++;
     880             :     }
     881             :     /*------------------------------------------------------------*
     882             :      *  EDCT and back to 16 bits
     883             :      *------------------------------------------------------------*/
     884             : 
     885        9313 :     edct_16fx( exc16, dct_buffer_out, DCT_L_POST, 6, EVS_MONO );
     886        9313 :     *qdct = Q_exc;
     887        9313 :     move16();
     888             : 
     889        9313 :     return;
     890             : }
     891             : /*------------------------------------------------------------------------*
     892             :  * norm_lfe()
     893             :  *
     894             :  * Energy bins normalisation
     895             :  *------------------------------------------------------------------------*/
     896     5969633 : static Word16 norm_lfe(
     897             :     const Word32 Lfe,    /* i: energy bin to normalize 2*Qdct+10     */
     898             :     const Word16 m_norm, /* i: Normalisation factor Q e_norm         */
     899             :     const Word16 e_norm  /* i: Exponent of the normalisation factor  */
     900             : )
     901             : {
     902             :     Word32 Ltmp;
     903             :     Word16 exp2, tmp16, exp3;
     904             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     905     5969633 :     Flag Overflow = 0;
     906             : #endif
     907             : 
     908     5969633 :     move32();
     909             : 
     910     5969633 :     Ltmp = Mult_32_16( Lfe, m_norm );
     911     5969633 :     Ltmp = L_add( Ltmp, L_shl( BET_Q15_FX, sub( e_norm, 15 ) ) ); /* Ltmp -> e_norm*/
     912     5969633 :     exp2 = norm_l( Ltmp );
     913     5969633 :     tmp16 = extract_h( L_shl( Ltmp, exp2 ) ); /* exp2 -= 16 */
     914     5969633 :     exp2 = add( e_norm, exp2 );
     915             : 
     916     5969633 :     tmp16 = mult_r( tmp16, tmp16 ); /* tmp16 in Q exp2 */
     917     5969633 :     tmp16 = mult_r( tmp16, tmp16 );
     918     5969633 :     tmp16 = mult_r( tmp16, tmp16 );
     919             : 
     920     5969633 :     exp3 = sub( 12 + 16, exp2 ); /* tmp16 in Q exp2 */
     921     5969633 :     if ( NE_16( exp2, 31 ) )
     922             :     {
     923     1051468 :         exp3 = sub( exp2, 12 + 16 - 3 ); /* if exp2 < 31, means that tmp >= 1.0 */
     924             :         /* Need to shl by 3 to take into account the 3 multiplications */
     925             :     }
     926     5969633 :     tmp16 = shl_o( tmp16, exp3, &Overflow ); /* Result in Q12 */
     927             : 
     928     5969633 :     return tmp16;
     929             : }
     930             : 
     931             : /*------------------------------------------------------------------------*
     932             :  * Post_music_postP()
     933             :  *
     934             :  * Going back from frequency to time domain from the enhanced spectrum.
     935             :  * Retreive the aligned excitation and redo the synthesis
     936             :  *------------------------------------------------------------------------*/
     937             : 
     938        9313 : void Post_music_postP_fx(
     939             :     Word16 dct_buffer_in[],          /* i/o: excitation buffer */
     940             :     Word16 *exc2,                    /* i/o: Current excitation to be overwriten Q_exc*/
     941             :     const Word16 *mem_tmp,           /* i  : previous frame synthesis memory     Q_syn*/
     942             :     Word16 *st_mem_syn2,             /* i/o: current frame synthesis memory      Q_syn*/
     943             :     const Word16 *Aq,                /* i  : LPC filter coefficients             Q12*/
     944             :     Word16 *syn,                     /* i/o: 12k8 synthesis                      Q_syn*/
     945             :     Word16 *Q_exc,                   /* i  : excitation scaling                  */
     946             :     Word16 *prev_Q_syn,              /* i  : previsous frame synthesis scaling   */
     947             :     Word16 *Q_syn,                   /* i  : Current frame synthesis scaling     */
     948             :     Word16 *mem_syn_clas_estim_fx,   /* i  : old 12k8 synthesis used for frame classification Q_syn*/
     949             :     const Word16 IsIO,               /* i: Flag to indicate IO mode */
     950             :     Word16 *mem_deemph,              /* i/o: speech deemph filter memory                 Q_syn*/
     951             :     Word16 *st_pst_old_syn_fx,       /* i/o:  psfiler                                     Q_syn*/
     952             :     Word16 *st_pst_mem_deemp_err_fx, /* i/o:  psfiler                                     Q_syn*/
     953             :     Word16 *mem_agc,                 /*Q_syn*/
     954             :     PFSTAT *pf_stat,                 /* i/o:  All memories related to NB post filter      */
     955             :     const Word16 *tmp_buffer         /* tmp_buffer in Q-1 */
     956             :     ,
     957             :     Word16 *mem_tmp2 /* Temporary memory used with scale_syn Q_syn*/
     958             : )
     959             : {
     960             :     Word16 exc16[DCT_L_POST];
     961             : 
     962             :     /*------------------------------------------------------------------------*
     963             :      * Go back to time domain
     964             :      *------------------------------------------------------------------------*/
     965             : 
     966        9313 :     edct_16fx( dct_buffer_in, exc16, DCT_L_POST, 6, EVS_MONO );
     967             : 
     968        9313 :     Copy( exc16 + OFFSET2, exc2, L_FRAME );
     969             : 
     970        9313 :     Copy( mem_tmp, st_mem_syn2, M ); /*Q_syn*/
     971             : 
     972             :     /*------------------------------------------------------------------------*
     973             :      * Perform the synthesis filtering using the enhanced excitation
     974             :      *------------------------------------------------------------------------*/
     975        9313 :     IF( IsIO == 0 ) /* Rescaling already done in IO mode */
     976             :     {
     977        9313 :         Rescale_mem( *Q_exc, prev_Q_syn, Q_syn, st_mem_syn2, mem_syn_clas_estim_fx, 4,
     978             :                      mem_deemph, st_pst_old_syn_fx, st_pst_mem_deemp_err_fx, mem_agc,
     979             :                      pf_stat, 1, 0, tmp_buffer );
     980        9313 :         Copy( st_mem_syn2, mem_tmp2, M ); /*Q_syn*/
     981             :     }
     982             : 
     983        9313 :     syn_12k8_fx( L_FRAME, Aq, exc2, syn, st_mem_syn2, 1, *Q_exc, *Q_syn );
     984             : 
     985        9313 :     return;
     986             : }
     987             : 
     988             : 
     989             : /*-------------------------------------------------------------------*
     990             :  * music_postfilt_init()
     991             :  *
     992             :  * Initialize LD music postfilter state structure
     993             :  *-------------------------------------------------------------------*/
     994        3256 : void music_postfilt_init(
     995             :     MUSIC_POSTFILT_HANDLE hMusicPF /* i/o: LD music postfilter handle */
     996             : )
     997             : {
     998             :     Word16 i, e_db, f_db;
     999             :     Word32 L_tmp;
    1000             : 
    1001        3256 :     set16_fx( hMusicPF->dct_post_old_exc_fx, 0, DCT_L_POST - OFFSET2 );
    1002             :     /*st->LDm_enh_min_ns_gain = (float)pow(10.0f, -12/20.0f);*/
    1003        3256 :     L_tmp = L_mult( ( ( -12 * 256 ) ), 5443 ); /* *0.166096 in Q15 -> Q24 */
    1004        3256 :     L_tmp = L_shr( L_tmp, 8 );                 /* From Q24 to Q16 */
    1005        3256 :     f_db = L_Extract_lc( L_tmp, &e_db );       /* Extract exponent */
    1006        3256 :     f_db = extract_l( Pow2( 14, f_db ) );      /* Put 14 as exponent so that */
    1007        3256 :     e_db = add( e_db, 15 - 14 );
    1008        3256 :     f_db = add( f_db, shr( 1, add( e_db, 1 ) ) );
    1009        3256 :     hMusicPF->LDm_enh_min_ns_gain_fx = shl( f_db, e_db );
    1010        3256 :     move16();
    1011             : 
    1012        3256 :     hMusicPF->LDm_last_music_flag = 0;
    1013        3256 :     move16();
    1014        3256 :     set16_fx( hMusicPF->LDm_lt_diff_etot_fx, 0, MAX_LT );
    1015             : 
    1016        3256 :     hMusicPF->LDm_thres_fx[0] = TH_0_MIN_FX;
    1017        3256 :     move16();
    1018        3256 :     hMusicPF->LDm_thres_fx[1] = TH_1_MIN_FX;
    1019        3256 :     move16();
    1020        3256 :     hMusicPF->LDm_thres_fx[2] = TH_2_MIN_FX;
    1021        3256 :     move16();
    1022        3256 :     hMusicPF->LDm_thres_fx[3] = TH_3_MIN_FX;
    1023        3256 :     move16();
    1024             : 
    1025        3256 :     hMusicPF->LDm_nb_thr_1 = 0;
    1026        3256 :     move16();
    1027        3256 :     hMusicPF->LDm_nb_thr_3 = 0;
    1028        3256 :     move16();
    1029        3256 :     hMusicPF->LDm_mem_etot_fx = 0;
    1030        3256 :     move16();
    1031             : 
    1032     2087096 :     FOR( i = 0; i < VOIC_BINS_HR; i++ )
    1033             :     {
    1034     2083840 :         hMusicPF->LDm_enh_lp_gbin_fx[i] = 16384; /*1.0f Q14*/
    1035     2083840 :         move16();
    1036     2083840 :         hMusicPF->LDm_enh_lf_EO_fx[i] = 328; /*0.01f Q15*/
    1037     2083840 :         move16();
    1038             :     }
    1039             : 
    1040       68376 :     FOR( i = 0; i < MBANDS_GN_LD; i++ )
    1041             :     {
    1042       65120 :         hMusicPF->LDm_bckr_noise_fx[i] = E_MIN_Q15;
    1043       65120 :         move16();
    1044             :     }
    1045        3256 :     set16_fx( hMusicPF->filt_lfE_fx, 4096 /*1.0f in Q12*/, DCT_L_POST );
    1046        3256 :     hMusicPF->last_nonfull_music = 0;
    1047        3256 :     move16();
    1048        3256 :     hMusicPF->Old_ener_Q = 0;
    1049        3256 :     move16();
    1050             : 
    1051        3256 :     return;
    1052             : }

Generated by: LCOV version 1.14