LCOV - code coverage report
Current view: top level - lib_enc - qlpc_stoch_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 207 259 79.9 %
Date: 2025-05-03 01:55:50 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : 
       6             : #include <stdint.h>
       7             : #include <assert.h>
       8             : #include "options.h"
       9             : #include "cnst.h"
      10             : #include "rom_enc.h"
      11             : #include "rom_com_fx.h"
      12             : #include "rom_com.h"
      13             : //#include "prot_fx.h"
      14             : #include "prot_fx.h"     /* Function prototypes                    */
      15             : #include "prot_fx_enc.h" /* Function prototypes                    */
      16             : #include "basop_util.h"
      17             : #include "rom_basop_util.h"
      18             : 
      19             : /*-------------------------------------------------------------------*
      20             :  * local constants
      21             :  *--------------------------------------------------------------------*/
      22             : 
      23             : #define MIN_LOG_FX     0
      24             : #define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */
      25             : 
      26             : /*-------------------------------------------------------------------*
      27             :  * lpc_quantization_fx()
      28             :  *
      29             :  *
      30             :  *--------------------------------------------------------------------*/
      31        1266 : void lpc_quantization_fx(
      32             :     Encoder_State *st,
      33             :     const Word16 lsp[],        /* Q15 */
      34             :     const Word16 lspmid[],     /* Q15 */
      35             :     Word16 lsp_q[],            /* Q15 */
      36             :     Word16 lsf_q[],            /* 14Q1*1.28 */
      37             :     Word16 lspmid_q[],         /* Q15 */
      38             :     Word16 lspq_ind[],         /* Q15 */
      39             :     Word16 clip_var[],         /* [2.56x,Q14,Q8,Q0,Q14,Q14] */
      40             :     const Word16 coder_type,   /* Q0 */
      41             :     const Word16 acelp_midLpc, /* Q0 */
      42             :     Word16 param_lpc[],        /* Q0 */
      43             :     Word16 nbits_lpc[],        /* Q0 */
      44             :     Word16 *bits_param_lpc,    /* Q0 */
      45             :     Word16 *no_param_lpc,      /* Q0 */
      46             :     const Word16 Q_ener )
      47             : {
      48             :     Word16 nb_indices;
      49             :     Word16 lsfmid_q[M]; /* 14Q1*1.28 */
      50             :     Word16 lsfmid_idx;
      51             :     Word16 i, force_sf;
      52             :     Word16 lsf[M], lsfmid[M];
      53             :     Word16 fec_lsf[M], stab;
      54             : 
      55        1266 :     nb_indices = 0;
      56        1266 :     move16();
      57             : 
      58             :     /****** High-rate LPC quantizer *******/
      59             : 
      60        1266 :     IF( st->lpcQuantization == 0 )
      61             :     {
      62           0 :         if ( st->sr_core != 12800 )
      63             :         {
      64             :             // PMT("from the comment in E_LPC_isp_isf_conversion, it seems built for 12.8kHz, current sampling rate is NOT 12800, is it ok?")
      65             :             /*_DIFF_FLOAT_FIX_ E_LPC_lsp_lsf_conversion, does it work for 16kHz as well ?*/
      66             :         }
      67           0 :         E_LPC_lsp_lsf_conversion( lsp, lsf, M );
      68             : 
      69             :         /* check resonance for pitch clipping algorithm */
      70           0 :         gp_clip_test_lsf_fx( st->element_mode, lsf, clip_var, M );
      71             : 
      72           0 :         IF( ( EQ_16( st->core, TCX_10_CORE ) ) )
      73             :         {
      74           0 :             E_LPC_lsp_lsf_conversion( lspmid, lsfmid, M );
      75             :         }
      76             : 
      77             :         /* LPC quantizer */
      78           0 :         qlpc_avq_fx( lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, st->core, st->sr_core );
      79             : 
      80           0 :         E_LPC_lsf_lsp_conversion( lsf_q, lsp_q, M );
      81             : 
      82           0 :         IF( EQ_16( st->core, TCX_10_CORE ) )
      83             :         {
      84           0 :             E_LPC_lsf_lsp_conversion( lsfmid_q, lspmid_q, M );
      85             :         }
      86             : 
      87             :         /* assert(nb_indices<=NPRM_LPC_NEW); */
      88             :     }
      89             : 
      90             :     /****** Low-rate LPC quantizer *******/
      91             : 
      92        1266 :     ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
      93             :     {
      94        1266 :         assert( st->sr_core <= 32000 );
      95             : 
      96        1266 :         lsp2lsf_fx( lsp, lsf, M, extract_l( st->sr_core ) );
      97             : 
      98        1266 :         gp_clip_test_lsf_fx( st->element_mode, lsf, clip_var, M );
      99             : 
     100        1266 :         force_sf = 0;
     101        1266 :         move16();
     102             :         /*Force safety net when possible in case of transitions*/
     103        1266 :         test();
     104        1266 :         test();
     105        1266 :         IF( st->tc_cnt >= 1 || LE_32( st->last_core_brate, SID_2k40 ) || ( EQ_16( st->next_force_safety_net, 1 ) ) )
     106             :         {
     107          96 :             force_sf = 1;
     108          96 :             move16();
     109          96 :             st->next_force_safety_net = 0;
     110          96 :             move16();
     111             :         }
     112             : 
     113        1266 :         test();
     114        1266 :         IF( EQ_16( st->next_force_safety_net, 1 ) && EQ_16( st->Opt_RF_ON, 1 ) )
     115             :         {
     116           0 :             force_sf = 1;
     117           0 :             move16();
     118           0 :             st->next_force_safety_net = 0;
     119           0 :             move16();
     120             :         }
     121             : 
     122        1266 :         test();
     123        1266 :         IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, UNVOICED ) )
     124             :         {
     125          31 :             lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener,
     126             :                             force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC );
     127             : 
     128          31 :             nb_indices = *no_param_lpc; // Q0
     129          31 :             move16();
     130             :         }
     131             :         ELSE
     132             :         {
     133        1235 :             lsf_end_enc_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener,
     134             :                             force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type );
     135             : 
     136        1235 :             nb_indices = *no_param_lpc; // Q0
     137        1235 :             move16();
     138             :         }
     139             : 
     140             : 
     141        1266 :         FEC_lsf_estim_enc_fx( st, fec_lsf );
     142             : 
     143             :         /* FEC - calculate LSF stability */
     144        1266 :         stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame ); /*Q15*/
     145             : 
     146             : 
     147        1266 :         test();
     148        1266 :         test();
     149        1266 :         test();
     150        1266 :         IF( LT_16( stab, add( STAB_FAC_LIMIT_FX, 6553 /* =0.2 in Q15*/ ) ) &&
     151             :             ( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) && EQ_16( st->Opt_RF_ON, 1 ) )
     152             :         {
     153           0 :             st->next_force_safety_net = 1;
     154           0 :             move16();
     155             :         }
     156             : 
     157        1266 :         lsf2lsp_fx( lsf_q, lsp_q, M, st->sr_core );
     158             : 
     159        1266 :         *nbits_lpc = ENDLSF_NBITS;
     160        1266 :         move16();
     161             :     }
     162             :     ELSE
     163             :     {
     164           0 :         assert( 0 );
     165             :     }
     166             : 
     167        1266 :     IF( lspq_ind != NULL )
     168             :     {
     169        1266 :         E_LPC_lsf_lsp_conversion( lsf_q, lspq_ind, M );
     170             :     }
     171             : 
     172        1266 :     st->seed_acelp = 0;
     173        1266 :     move16();
     174        7006 :     FOR( i = nb_indices - 1; i >= 0; i-- )
     175             :     {
     176        5740 :         st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); // Q0
     177        5740 :         move16();
     178             :     }
     179             : 
     180             :     /* Mid-frame LPC quantization */
     181             : 
     182        1266 :     test();
     183        1266 :     IF( st->lpcQuantization && acelp_midLpc )
     184             :     {
     185             : 
     186         746 :         IF( st->rate_switching_reset == 0 )
     187             :         {
     188         734 :             lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) );
     189             : 
     190         734 :             midlsf_enc_fx( st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, (Word8) st->narrowBand, st->sr_core, coder_type );
     191         734 :             param_lpc[nb_indices++] = lsfmid_idx; // Q0
     192         734 :             move16();
     193         734 :             midlsf_dec( st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type, NULL, 0, 1 );
     194             : 
     195         734 :             reorder_lsf_fx( lsfmid_q, LSF_GAP_MID_FX, M, st->sr_core );
     196         734 :             lsf2lsp_fx( lsfmid_q, lspmid_q, M, st->sr_core );
     197             :         }
     198             :         ELSE
     199             :         {
     200          12 :             param_lpc[nb_indices++] = 0;
     201          12 :             move16();
     202             :         }
     203             :     }
     204             : 
     205             : 
     206        1266 :     return;
     207             : }
     208             : 
     209      218284 : void lpc_quantization_ivas_fx(
     210             :     Encoder_State *st,
     211             :     const Word16 lsp[],        /* Q15 */
     212             :     const Word16 lspmid[],     /* Q15 */
     213             :     Word16 lsp_q[],            /* Q15 */
     214             :     Word16 lsf_q[],            /* 14Q1*1.28 */
     215             :     Word16 lspmid_q[],         /* Q15 */
     216             :     const Word16 coder_type,   /* Q0 */
     217             :     const Word16 acelp_midLpc, /* Q0 */
     218             :     Word16 param_lpc[],        /* Q0 */
     219             :     Word16 nbits_lpc[],        /* Q0 */
     220             :     Word16 *bits_param_lpc,    /* Q0 */
     221             :     Word16 *no_param_lpc,      /* Q0 */
     222             :     const Word16 Q_ener )
     223             : {
     224             :     Word16 nb_indices;
     225             :     Word16 lsfmid_q[M]; /* 14Q1*1.28 */
     226             :     Word16 lsfmid_idx;
     227             :     Word16 i, force_sf;
     228             :     Word16 lsf[M], lsfmid[M];
     229             :     Word16 fec_lsf[M], stab;
     230             : 
     231      218284 :     nb_indices = 0;
     232      218284 :     move16();
     233             : 
     234             :     /****** High-rate LPC quantizer *******/
     235             : 
     236      218284 :     IF( st->lpcQuantization == 0 )
     237             :     {
     238      106874 :         E_LPC_lsp_lsf_conversion( lsp, lsf, M );
     239             : 
     240      106874 :         IF( ( EQ_16( st->core, TCX_10_CORE ) ) )
     241             :         {
     242        2059 :             E_LPC_lsp_lsf_conversion( lspmid, lsfmid, M );
     243             :         }
     244             : 
     245             :         /* LPC quantizer */
     246      106874 :         qlpc_avq_fx( lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, st->core, st->sr_core );
     247             : 
     248      106874 :         E_LPC_lsf_lsp_conversion( lsf_q, lsp_q, M );
     249             : 
     250      106874 :         IF( EQ_16( st->core, TCX_10_CORE ) )
     251             :         {
     252        2059 :             E_LPC_lsf_lsp_conversion( lsfmid_q, lspmid_q, M );
     253             :         }
     254             : 
     255      106874 :         assert( nb_indices <= NPRM_LPC_NEW );
     256             :     }
     257             : 
     258             :     /****** Low-rate LPC quantizer *******/
     259             : 
     260      111410 :     ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
     261             :     {
     262             : 
     263      111410 :         lsp2lsf_fx( lsp, lsf, M, extract_l( st->sr_core ) );
     264             : 
     265      111410 :         force_sf = 0;
     266      111410 :         move16();
     267             :         /*Force safety net when possible in case of transitions*/
     268      111410 :         test();
     269      111410 :         test();
     270      111410 :         IF( GE_32( st->tc_cnt, 1 ) || LE_32( st->last_core_brate, SID_2k40 ) || ( EQ_16( st->next_force_safety_net, 1 ) ) )
     271             :         {
     272       12420 :             force_sf = 1;
     273       12420 :             move16();
     274       12420 :             st->next_force_safety_net = 0;
     275       12420 :             move16();
     276             :         }
     277             : 
     278      111410 :         test();
     279      111410 :         IF( EQ_16( st->next_force_safety_net, 1 ) && EQ_16( st->Opt_RF_ON, 1 ) )
     280             :         {
     281           0 :             force_sf = 1;
     282           0 :             st->next_force_safety_net = 0;
     283           0 :             move16();
     284           0 :             move16();
     285             :         }
     286             : 
     287      111410 :         test();
     288      111410 :         IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( coder_type, UNVOICED ) )
     289             :         {
     290           0 :             lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, GENERIC, Q_ener,
     291             :                                  force_sf, param_lpc, no_param_lpc, bits_param_lpc, GENERIC, NULL );
     292             : 
     293           0 :             nb_indices = *no_param_lpc; // Q0
     294           0 :             move16();
     295             :         }
     296             :         ELSE
     297             :         {
     298      111410 :             lsf_end_enc_ivas_fx( st, lsf, lsf_q, ENDLSF_NBITS, coder_type, Q_ener,
     299             :                                  force_sf, param_lpc, no_param_lpc, bits_param_lpc, coder_type, NULL );
     300             : 
     301      111410 :             nb_indices = *no_param_lpc; // Q0
     302      111410 :             move16();
     303             :         }
     304             : 
     305             : 
     306      111410 :         FEC_lsf_estim_enc_fx( st, fec_lsf );
     307             : 
     308             :         /* FEC - calculate LSF stability */
     309      111410 :         stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame ); /*Q15*/
     310             : 
     311             : 
     312      111410 :         test();
     313      111410 :         test();
     314      111410 :         test();
     315      111410 :         IF( LT_16( stab, add( STAB_FAC_LIMIT_FX, 6553 /* =0.2 in Q15*/ ) ) &&
     316             :             ( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) && EQ_16( st->Opt_RF_ON, 1 ) )
     317             :         {
     318           0 :             st->next_force_safety_net = 1;
     319           0 :             move16();
     320             :         }
     321             : 
     322      111410 :         lsf2lsp_fx( lsf_q, lsp_q, M, st->sr_core );
     323             : 
     324      111410 :         *nbits_lpc = ENDLSF_NBITS;
     325      111410 :         move16();
     326             :     }
     327             :     ELSE
     328             :     {
     329           0 :         assert( 0 );
     330             :     }
     331             : 
     332      218284 :     st->seed_acelp = 0;
     333      218284 :     move16();
     334     2130991 :     FOR( i = nb_indices - 1; i >= 0; i-- )
     335             :     {
     336     1912707 :         st->seed_acelp = extract_l( L_mac0( L_mac0( 13849, shr( st->seed_acelp, 1 ), 31821 ), param_lpc[i], 31821 ) ); // Q0
     337     1912707 :         move16();
     338             :     }
     339             : 
     340             :     /* Mid-frame LPC quantization */
     341             : 
     342      218284 :     test();
     343      218284 :     IF( st->lpcQuantization && acelp_midLpc )
     344             :     {
     345             : 
     346           0 :         IF( st->rate_switching_reset == 0 )
     347             :         {
     348           0 :             lsp2lsf_fx( lspmid, lsfmid, M, extract_l( st->sr_core ) );
     349             : 
     350           0 :             midlsf_enc_fx( st->lsf_old_fx, lsf_q, lsfmid, &lsfmid_idx, M, st->Bin_E_old_fx, Q_ener, (Word8) st->narrowBand, st->sr_core, coder_type );
     351           0 :             param_lpc[nb_indices] = lsfmid_idx; // Q0
     352           0 :             move16();
     353           0 :             nb_indices = add( nb_indices, 1 );
     354           0 :             midlsf_dec( st->lsf_old_fx, lsf_q, lsfmid_idx, lsfmid_q, coder_type, NULL, 0, 1 );
     355             : 
     356           0 :             reorder_lsf_fx( lsfmid_q, LSF_GAP_MID_FX, M, st->sr_core );
     357           0 :             lsf2lsp_fx( lsfmid_q, lspmid_q, M, st->sr_core );
     358             :         }
     359             :         ELSE
     360             :         {
     361           0 :             param_lpc[nb_indices] = 0;
     362           0 :             move16();
     363           0 :             nb_indices = add( nb_indices, 1 ); // Q0
     364             :         }
     365             :     }
     366             : 
     367             : 
     368      218284 :     return;
     369             : }
     370             : 
     371             : 
     372             : /*-------------------------------------------------------------------*
     373             :  * Unified_weighting()
     374             :  *
     375             :  * LSF weighting
     376             :  *-------------------------------------------------------------------*/
     377             : 
     378      445909 : void Unified_weighting_fx(
     379             :     const Word32 Bin_Ener_128_fx[], /* i  : FFT Bin energy 128 bins in two sets         Q_ener */
     380             :     Word16 Q_ener,
     381             :     const Word16 lsf_fx[],   /* i  : LSF vector                                                                         x2.56 */
     382             :     Word16 w_fx[],           /* o  : LP weighting filter (numerator)                            Q8 */
     383             :     const Word16 narrowBand, /* i  : flag for Narrowband                                                        Q0*/
     384             :     const Word16 unvoiced,   /* i  : flag for Unvoiced frame                                            Q0*/
     385             :     const Word32 sr_core,    /* i  : sampling rate of core-coder                                        Q0*/
     386             :     const Word16 order       /* i  : LP order                                                                           Q0*/
     387             : )
     388             : {
     389             :     Word16 i;
     390             :     const Word16( *ptr_lsf_fit_model )[M];
     391             :     Word16 last_bin;
     392             :     /*float compen;*/
     393             : 
     394             :     Word16 exp, frac;
     395             :     Word16 w_fft_fx[M] /*, w_fx[M]*/;
     396             :     Word16 norm_lsf_fx[M]; /* Q0 */
     397             :     Word16 tmp_fx, min_fx, tmp1_fx, tmp2_fx, s1, s2;
     398             :     Word32 L_tmp;
     399             :     Word16 nf_fx;
     400             :     Word32 Bin_Ener_160_fx[160];
     401             :     const Word32 *Freq_w_Table_fx, *Bin_Ener_fx;
     402             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     403      445909 :     Flag Overflow = 0;
     404      445909 :     move32();
     405             : #endif
     406             : 
     407             :     /*Config. weighting*/
     408      445909 :     IF( narrowBand )
     409             :     {
     410           0 :         ptr_lsf_fit_model = lsf_unified_fit_model_nb; // Q0
     411           0 :         nf_fx = 16384;                                /* 6400 in x2.56 */
     412           0 :         move16();
     413             : 
     414           0 :         last_bin = 127;
     415           0 :         move16();
     416           0 :         Bin_Ener_fx = Bin_Ener_128_fx; /* Q_ener */
     417             :     }
     418      445909 :     ELSE IF( EQ_32( sr_core, INT_FS_12k8 ) )
     419             :     {
     420      221956 :         ptr_lsf_fit_model = lsf_unified_fit_model_wb;
     421      221956 :         nf_fx = 16384; /* 6400 in x2.56 */
     422      221956 :         move16();
     423             : 
     424      221956 :         last_bin = 127;
     425      221956 :         move16();
     426      221956 :         Bin_Ener_fx = Bin_Ener_128_fx; /* Q_ener */
     427             :     }
     428             :     ELSE
     429             :     {
     430      223953 :         ptr_lsf_fit_model = lsf_unified_fit_model_wbhb;
     431      223953 :         nf_fx = 20480; /* 8000 in x2.56 */
     432      223953 :         move16();
     433             : 
     434             :         /* Fill the missing part (128~159) of the bin energy */
     435      223953 :         last_bin = 159;
     436      223953 :         move16();
     437             : 
     438      223953 :         Copy32( Bin_Ener_128_fx, Bin_Ener_160_fx, L_FFT / 2 ); /* Q_ener */
     439             : 
     440             :         /* Find average bin energy (32 Energy) */
     441      223953 :         L_tmp = L_deposit_l( 0 );
     442     7390449 :         FOR( i = 95; i < 127; i++ )
     443             :         {
     444     7166496 :             L_tmp = L_add_o( L_tmp, Bin_Ener_160_fx[i], &Overflow ); /* Q_ener */
     445             :         }
     446             : 
     447      223953 :         L_tmp = L_shr( L_tmp, 5 );
     448     7614402 :         FOR( i = 127; i < 160; i++ )
     449             :         {
     450     7390449 :             Bin_Ener_160_fx[i] = L_tmp; /* Q_ener */
     451     7390449 :             move32();
     452             :         }
     453             : 
     454      223953 :         Bin_Ener_fx = Bin_Ener_160_fx; /* Q_ener */
     455             :     }
     456             : 
     457             :     /* 1) FFT weights*/
     458      445909 :     Freq_w_Table_fx = Freq_Weight_Com_fx; /* Q31 */
     459      445909 :     if ( unvoiced )
     460             :     {
     461        4925 :         Freq_w_Table_fx = Freq_Weight_UV_fx; /* Q31 */
     462             :     }
     463             : 
     464             :     /* Use Envelope */
     465      445909 :     min_fx = MAX_16;
     466      445909 :     move16();
     467     7580453 :     FOR( i = 0; i < M; i++ )
     468             :     {
     469     7134544 :         norm_lsf_fx[i] = mult_r( lsf_fx[i], 256 );
     470     7134544 :         move16();
     471             : 
     472     7134544 :         IF( norm_lsf_fx[i] == 0 )
     473             :         {
     474          29 :             L_tmp = L_add( Bin_Ener_fx[1], 0 );
     475             :         }
     476     7134515 :         ELSE IF( norm_lsf_fx[i] == last_bin )
     477             :         {
     478          24 :             L_tmp = L_add( Bin_Ener_fx[last_bin - 1], 0 );
     479             :         }
     480             :         ELSE
     481             :         {
     482     7134491 :             L_tmp = L_max( Bin_Ener_fx[norm_lsf_fx[i]], Bin_Ener_fx[norm_lsf_fx[i] - 1] ); /* Q_ener */
     483     7134491 :             L_tmp = L_max( Bin_Ener_fx[norm_lsf_fx[i] + 1], L_tmp );                       /* Q_ener */
     484             :         }
     485             : 
     486     7134544 :         IF( LE_32( L_tmp, MIN_LOG_FX ) )
     487             :         {
     488       29129 :             w_fft_fx[i] = MIN_LOG_VAL_FX;
     489       29129 :             move16(); /* Q8 */
     490             :         }
     491             :         ELSE
     492             :         {
     493     7105415 :             exp = norm_l( L_tmp );
     494     7105415 :             move16();
     495     7105415 :             IF( L_tmp == 0 )
     496             :             {
     497           0 :                 frac = 0;
     498           0 :                 move16();
     499             :             }
     500             :             ELSE
     501             :             {
     502     7105415 :                 frac = Log2_norm_lc( L_shl( L_tmp, exp ) );
     503             :             }
     504     7105415 :             exp = sub( sub( 30, exp ), Q_ener );
     505     7105415 :             L_tmp = Mpy_32_16( exp, frac, 24660 ); /* Q14 */ /* 10*log10(2) in Q13*/
     506     7105415 :             w_fft_fx[i] = round_fx( L_shl( L_tmp, 10 ) );    /* Q8 */
     507             :         }
     508             : 
     509     7134544 :         if ( LT_16( w_fft_fx[i], min_fx ) )
     510             :         {
     511     2488356 :             min_fx = w_fft_fx[i]; // Q8
     512     2488356 :             move16();
     513             :         }
     514             :     }
     515             : 
     516     7580453 :     FOR( i = 0; i < M; i++ )
     517             :     {
     518     7134544 :         IF( EQ_16( w_fft_fx[i], min_fx ) )
     519             :         {
     520      530805 :             w_fft_fx[i] = 2048;
     521      530805 :             move16(); /* 2.0 in Q10 */
     522             :         }
     523             :         ELSE
     524             :         {
     525     6603739 :             L_tmp = L_shl_o( L_deposit_l( sub_o( w_fft_fx[i], min_fx, &Overflow ) ), 13, &Overflow ); /* Q21 */
     526     6603739 :             exp = norm_l( L_tmp );
     527     6603739 :             frac = round_fx( L_shl( L_tmp, exp ) );
     528     6603739 :             exp = sub( add( exp, 21 ), 30 );
     529     6603739 :             tmp_fx = div_s( 16384, frac );
     530     6603739 :             L_tmp = Isqrt_lc( L_deposit_h( tmp_fx ), &exp );         /* Q(31-exp) */
     531     6603739 :             w_fft_fx[i] = round_fx( L_shl( L_tmp, sub( exp, 5 ) ) ); /* Q10 */
     532     6603739 :             w_fft_fx[i] = add( w_fft_fx[i], 2048 );
     533     6603739 :             move16(); /* Q10; 2.0 in Q10 */
     534             :         }
     535     7134544 :         w_fft_fx[i] = round_fx( Mult_32_16( Freq_w_Table_fx[norm_lsf_fx[i]], w_fft_fx[i] ) ); /* Q10 */
     536             :     }
     537             : 
     538             :     /* 2) IHM weights*/
     539     7580453 :     FOR( i = 0; i < order; i++ )
     540             :     {
     541             :         /* 2) IHM weights*/
     542     7134544 :         tmp1_fx = lsf_fx[i]; /* x2.56 */
     543     7134544 :         move16();
     544     7134544 :         if ( i > 0 )
     545             :         {
     546     6688635 :             tmp1_fx = sub( tmp1_fx, lsf_fx[i - 1] ); /* x2.56 */
     547             :         }
     548             : 
     549     7134544 :         tmp2_fx = nf_fx;
     550     7134544 :         move16();
     551     7134544 :         if ( NE_16( i, sub( order, 1 ) ) )
     552             :         {
     553     6688635 :             tmp2_fx = lsf_fx[i + 1]; /* x2.56 */
     554     6688635 :             move16();
     555             :         }
     556     7134544 :         tmp2_fx = sub( tmp2_fx, lsf_fx[i] ); /* x2.56 */
     557             : 
     558     7134544 :         s1 = 15;
     559     7134544 :         move16();
     560     7134544 :         s2 = 15;
     561     7134544 :         move16();
     562     7134544 :         if ( tmp1_fx == 0 )
     563             :         {
     564           0 :             tmp1_fx = 8;
     565           0 :             move16();
     566             :         }
     567     7134544 :         tmp1_fx = Inv16( tmp1_fx, &s1 );
     568     7134544 :         if ( tmp2_fx == 0 )
     569             :         {
     570           0 :             tmp2_fx = 8;
     571           0 :             move16();
     572             :         }
     573     7134544 :         tmp2_fx = Inv16( tmp2_fx, &s2 );
     574     7134544 :         s1 = BASOP_Util_Add_MantExp( tmp1_fx, s1, tmp2_fx, s2, &tmp1_fx ); /* x * 2.56 / pow(2.0, 15 + |s1|)   */
     575     7134544 :         tmp_fx = mult_r( nf_fx, 10430 /* 0.31 in Q15*/ );
     576     7134544 :         s2 = norm_s( tmp_fx );
     577     7134544 :         tmp_fx = shl( tmp_fx, s2 );
     578     7134544 :         s1 = sub( s1, s2 );
     579             : 
     580     7134544 :         tmp1_fx = mult_r( tmp1_fx, tmp_fx ); /* |s1| */
     581     7134544 :         s1 = abs_s( s1 );
     582             : 
     583             :         /* 3) Fitting model combining the two weights*/
     584     7134544 :         L_tmp = L_add( ptr_lsf_fit_model[0][i], 0 );                                                 /* Q10 */
     585     7134544 :         L_tmp = L_add( L_tmp, L_shl( L_mult0( ptr_lsf_fit_model[1][i], tmp1_fx ), sub( -5, s1 ) ) ); /* Q10 */
     586     7134544 :         L_tmp = L_add( L_tmp, L_shl( L_mult0( mult_r( tmp1_fx, tmp1_fx ), ptr_lsf_fit_model[2][i] ), sub( 7, shl( s1, 1 ) ) ) );
     587     7134544 :         L_tmp = L_add( L_tmp, L_shl( L_mult0( w_fft_fx[i], ptr_lsf_fit_model[3][i] ), -12 ) );
     588     7134544 :         move16(); /* Q10 */
     589             : 
     590     7134544 :         IF( LT_32( L_shl( L_tmp, 5 ), InvIntTable[i + 1] ) )
     591             :         {
     592           4 :             w_fx[i] = shr( InvIntTable[i + 1], 7 ); // Q8
     593           4 :             move16();
     594             :         }
     595             :         ELSE
     596             :         {
     597     7134540 :             IF( norm_l( L_tmp ) < 14 )
     598             :             {
     599           0 :                 w_fx[i] = MAX_16;
     600           0 :                 move16();
     601             :             }
     602             :             ELSE
     603             :             {
     604     7134540 :                 w_fx[i] = extract_l( L_shr( L_tmp, 2 ) ); // Q8
     605     7134540 :                 move16();
     606             :             }
     607             :         }
     608             :     }
     609             : 
     610      445909 :     return;
     611             : }

Generated by: LCOV version 1.14