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

Generated by: LCOV version 1.14