LCOV - code coverage report
Current view: top level - lib_enc - eval_pit_contr_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 574a190e3c6896c6c4ed10d7f23649709a0c4347 Lines: 341 403 84.6 %
Date: 2025-06-27 02:59:36 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : #include <stdint.h>
       5             : #include "options.h"     /* Compilation switches                   */
       6             : #include "cnst.h"        /* Common constants                       */
       7             : #include "rom_com_fx.h"  /* Static table prototypes                */
       8             : #include "rom_com.h"     /* Static table prototypes                */
       9             : #include "prot_fx.h"     /* Function prototypes                    */
      10             : #include "prot_fx_enc.h" /* Function prototypes                    */
      11             : 
      12             : /*-------------------------------------------------------------------*
      13             :  * Local constantes
      14             :  *-------------------------------------------------------------------*/
      15             : #define NB_VOIC_FX     13
      16             : #define DIV_NB_VOIC_FX 2521
      17             : 
      18             : #define ALPA_FX   31130
      19             : #define ALPAM1_FX ( 32768 - ALPA_FX )
      20             : 
      21             : #define BETA_FX   819
      22             : #define AFREQ_THR 2
      23             : 
      24             : #define HANGOVER_DELAY 2
      25             : 
      26             : /*======================================================================*/
      27             : /* FUNCTION : Pit_exc_contribution_len_fx()                                                             */
      28             : /*----------------------------------------------------------------------*/
      29             : /* PURPOSE : Determine up to which band the pit contribution is significant*/
      30             : /*----------------------------------------------------------------------*/
      31             : /*  INPUT ARGUMENTS :                                                                                               */
      32             : /* _ (Struct)   st_fx             : encoder static memory                                       */
      33             : /* _ (Word16[]) dct_res           : DCT of residual                 Qnew                    */
      34             : /* _ (Word16[]) dct_pitex         : DCT of pitch contribution Qnew                  */
      35             : /* _ (Word16[]) pitch_buf         : Pitch per subframe              Q6          */
      36             : /* _ (Word16[]) nb_subfr          : Number of subframe considered           */
      37             : /* _ (Word16) hangover            : hangover for the time contribution switching*/
      38             : /* _ (Word16) Qnew                    :                                                                                 */
      39             : /*-----------------------------------------------------------------------*/
      40             : /* OUTPUT ARGUMENTS :                                                                                                    */
      41             : /* _ (Word16[]) dct_res           : DCT of residual                 Qnew                    */
      42             : /* _ (Word16[]) dct_pitex         : DCT of pitch contribution Qnew                  */
      43             : /*-----------------------------------------------------------------------*/
      44             : 
      45             : 
      46             : /*-----------------------------------------------------------------------*/
      47             : /* RETURN ARGUMENTS :                                                                                                    */
      48             : /* _ None                                                                                                                                */
      49             : /*=======================================================================*/
      50             : 
      51           5 : Word16 Pit_exc_contribution_len_fx(                        /* o  : bin where pitch contribution is significant */
      52             :                                     Encoder_State *st_fx,  /* i/o: state structure                 */
      53             :                                     const Word16 *dct_res, /* i  : DCT of residual                 Qnew*/
      54             :                                     Word16 *dct_pitex,     /* i/o: DCT of pitch contribution       Qnew*/
      55             :                                     Word16 *pitch_buf,     /* i/o: Pitch per subframe              Q6*/
      56             :                                     const Word16 nb_subfr, /* i  : Number of subframe considered   Q0*/
      57             :                                     Word16 *hangover,      /* i  : hangover for the time contribution switching         Q0*/
      58             :                                     Word16 Qnew )
      59             : {
      60             : 
      61             :     Word16 corr_dct_pit[MBANDS_LOC];
      62             :     Word32 corr_tmp, L_tmp;
      63             :     Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res;
      64             :     Word16 freq, i, j;
      65             :     Word16 last_pit_band, pit_contr_idx, last_pit_bin;
      66             :     Word32 ener_res;
      67             :     Word32 ener_pit;
      68             :     Word16 low_pit, F1st_harm, F8th_harm;
      69             :     Word16 corr_dct_pit_tmp[MBANDS_LOC];
      70           5 :     Word16 time_flg = 0;
      71             :     Word16 Len, max_len;
      72             :     Word16 tmp_dec;
      73           5 :     Word16 Mbands_loc = MBANDS_LOC - 2;
      74             :     Word16 exp1, tmp, exp2;
      75             :     Word32 L_tmp1, ener_init;
      76             :     Word16 exp_norm;
      77             :     Word16 norm;
      78             :     Word16 val_thrs;
      79           5 :     SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
      80           5 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
      81           5 :     GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
      82           5 :     move16();
      83           5 :     move16();
      84             : 
      85           5 :     if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
      86             :     {
      87           0 :         Mbands_loc = MBANDS_LOC;
      88           0 :         move16();
      89             :     }
      90             : 
      91           5 :     minimum_fx( pitch_buf, nb_subfr, &low_pit );
      92           5 :     exp1 = norm_s( low_pit );
      93           5 :     tmp = shl( low_pit, exp1 );
      94           5 :     tmp_dec = 12800;
      95           5 :     move16();
      96           5 :     if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
      97             :     {
      98           0 :         tmp_dec = 16000;
      99           0 :         move16();
     100             :     }
     101             :     /*F1st_harm = (12800.0f|160000.f)/low_pit;*/
     102           5 :     tmp = div_s( tmp_dec, tmp );              /*15-6-exp1(->9-exp1)*/
     103           5 :     F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/
     104             : 
     105             :     /*F8th_harm = 8.0f*F1st_harm;*/
     106           5 :     F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/
     107             : 
     108           5 :     freq = 0;
     109           5 :     move16();
     110           5 :     ener_init = L_shl( 3, 2 * Qnew - 5 ); /*(0.1->3 in Q5)  2*Qnew*/
     111          70 :     FOR( i = 0; i < Mbands_loc; i++ )     /* up to maximum allowed voiced critical band */
     112             :     {
     113          65 :         corr_tmp = L_deposit_l( 0 );
     114          65 :         ener_res = L_add( ener_init, 0 );
     115          65 :         ener_pit = L_add( ener_init, 0 );
     116             : 
     117        1025 :         FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */
     118             :         {
     119         960 :             tmp_ex = mult_r( dct_pitex[j + freq], 8192 /* 0.25 in Q15 */ );
     120         960 :             tmp_res = mult_r( dct_res[j + freq], 8192 /* 0.25 in Q15 */ );
     121         960 :             corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex );  /*2*Qnew*/
     122         960 :             ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/
     123         960 :             ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex );   /*2*Qnew*/
     124             :         }
     125             : 
     126          65 :         L_tmp1 = Mult_32_32( ener_res, ener_pit );
     127          65 :         exp2 = norm_l( L_tmp1 );
     128          65 :         L_tmp1 = L_shl( L_tmp1, exp2 );
     129          65 :         exp_norm = sub( 30, exp2 );
     130          65 :         L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm );
     131          65 :         norm = extract_h( L_tmp1 ); /*15-exp_norm*/
     132          65 :         L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm );
     133          65 :         corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/
     134             : 
     135          65 :         freq = add( freq, mfreq_bindiv_loc[i] );
     136             :     }
     137             : 
     138           5 :     val_thrs = 8192;
     139           5 :     move16(); /* 0.5 in Q14*/
     140             :     /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/
     141           5 :     tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/
     142           5 :     tmp = s_max( tmp, val_thrs );
     143             : 
     144           5 :     corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 );
     145           5 :     move16();
     146             : 
     147          60 :     FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */
     148             :     {
     149          55 :         L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] );       /* Q30 */
     150          55 :         L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q30 */
     151             : 
     152          55 :         tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q30 */
     153          55 :         tmp = s_max( tmp, val_thrs );
     154             : 
     155          55 :         corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 );
     156          55 :         move16();
     157             :     }
     158           5 :     tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/
     159           5 :     tmp = s_max( tmp, val_thrs );
     160           5 :     corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 );
     161           5 :     move16();
     162             : 
     163           5 :     Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc );
     164             : 
     165           5 :     L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/
     166          65 :     FOR( i = 1; i < NB_VOIC_FX; i++ )                   /* up to maximum allowed voiced critical band */
     167             :     {
     168          60 :         L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] );
     169             :     }
     170           5 :     av_corr = round_fx( L_tmp1 ); /*Qnew*/
     171             : 
     172             :     /* Find the cut-off freq similarly to HSX */
     173           5 :     last_pit_band = 0;
     174           5 :     move16();
     175           5 :     av_corr = round_fx( L_shl( L_mult0( av_corr, 6400 ), 16 - 12 ) ); /*Q14*Q0-12=Q2*/
     176             : 
     177           5 :     if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     178             :     {
     179             :         /*av_corr *= 1.25f;*/
     180           0 :         av_corr = add( av_corr, shr( av_corr, 2 ) ); /* Q2 */
     181             :     }
     182           5 :     test();
     183           5 :     if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) )
     184             :     {
     185           0 :         av_corr = shl_sat( av_corr, 1 ); /*Q2 Correlation really poor at low rate, time domain still valide*/
     186             :     }
     187           5 :     min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/
     188             : 
     189          65 :     FOR( i = 1; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
     190             :     {
     191          60 :         ftmp = abs_s( sub( mfreq_loc_Q2fx[i], av_corr ) ); /*Q2*/
     192             : 
     193          60 :         IF( LT_16( ftmp, min_corr ) )
     194             :         {
     195           1 :             last_pit_band = i;
     196           1 :             move16();
     197           1 :             min_corr = ftmp; /* Q2 */
     198           1 :             move16();
     199             :         }
     200             :     }
     201             : 
     202           5 :     IF( GT_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) )
     203             :     {
     204             :         DO
     205             :         {
     206          38 :             last_pit_band = add( last_pit_band, 1 );
     207             :         }
     208          38 :         WHILE( GE_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) );
     209             :     }
     210           5 :     if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) )
     211             :     {
     212           0 :         last_pit_band = s_max( last_pit_band, 7 );
     213             :     }
     214           5 :     test();
     215           5 :     test();
     216           5 :     test();
     217           5 :     IF( GT_16( last_pit_band, 7 + BAND1k2 ) && ( LT_32( st_fx->core_brate, CFREQ_BITRATE ) || EQ_16( st_fx->bwidth, NB ) ) ) /*Added for 9.1*/
     218             :     {
     219           0 :         last_pit_band = 7 + BAND1k2;
     220           0 :         move16();
     221             :     }
     222           5 :     ELSE IF( GT_16( last_pit_band, 10 + BAND1k2 ) && GE_32( st_fx->core_brate, CFREQ_BITRATE ) )
     223             :     {
     224           0 :         last_pit_band = add( 10, BAND1k2 );
     225             :     }
     226             : 
     227           5 :     time_flg = 0;
     228           5 :     move16();
     229           5 :     test();
     230           5 :     test();
     231           5 :     test();
     232           5 :     test();
     233           5 :     test();
     234           5 :     test();
     235           5 :     test();
     236           5 :     test();
     237           5 :     test();
     238           5 :     test();
     239           5 :     IF( ( hGSCEnc->mem_last_pit_band > 0 && GT_16( st_fx->old_corr_fx, 16384 ) && GT_16( hSpMusClas->mold_corr_fx, 16384 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ ) || ( GT_16( last_pit_band, 6 ) ) || ( GE_16( last_pit_band, 4 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ && GT_16( st_fx->old_corr_fx, 22938 ) ) || ( GT_16( last_pit_band, BAND1k2 ) && GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_16( hGSCEnc->lt_gpitch_fx, 13107 ) /*GPIT_THR*/ ) )
     240             :     {
     241           5 :         tmp_dec = 1;
     242           5 :         move16();
     243             :     }
     244             :     ELSE
     245             :     {
     246           0 :         tmp_dec = 0;
     247           0 :         move16();
     248             :     }
     249             : 
     250             :     /* Different past and current decision */
     251           5 :     test();
     252           5 :     test();
     253           5 :     test();
     254           5 :     IF( ( hGSCEnc->mem_last_pit_band == 0 && EQ_16( tmp_dec, 1 ) ) || ( hGSCEnc->mem_last_pit_band > 0 && tmp_dec == 0 ) )
     255             :     {
     256           0 :         IF( *hangover == 0 )
     257             :         {
     258           0 :             time_flg = tmp_dec;
     259           0 :             move16();
     260           0 :             *hangover = HANGOVER_DELAY;
     261           0 :             move16();
     262             :         }
     263             :         ELSE
     264             :         {
     265           0 :             time_flg = 0;
     266           0 :             move16();
     267           0 :             if ( hGSCEnc->mem_last_pit_band > 0 )
     268             :             {
     269           0 :                 time_flg = 1;
     270           0 :                 move16();
     271             :             }
     272             : 
     273           0 :             ( *hangover ) = sub( ( *hangover ), 1 );
     274           0 :             if ( *hangover < 0 )
     275             :             {
     276           0 :                 *hangover = 0;
     277           0 :                 move16();
     278             :             }
     279             :         }
     280             :     }
     281             :     ELSE
     282             :     {
     283           5 :         time_flg = tmp_dec;
     284           5 :         move16();
     285           5 :         *hangover = HANGOVER_DELAY;
     286           5 :         move16();
     287             :     }
     288             : 
     289             :     /* Decicison on final length of time contribution */
     290           5 :     pit_contr_idx = 0;
     291           5 :     move16();
     292           5 :     test();
     293           5 :     test();
     294           5 :     IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech )
     295             :     {
     296           5 :         test();
     297           5 :         test();
     298             :         /*if(st_fx->core_brate  <ACELP_9k60)*/
     299           5 :         IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 ) )
     300             :         {
     301           0 :             last_pit_band = add( 9, BAND1k2 );
     302           0 :             if ( EQ_16( st_fx->bwidth, NB ) )
     303             :             {
     304           0 :                 last_pit_band = add( 7, BAND1k2 );
     305             :             }
     306             :         }
     307           5 :         ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 ) )
     308             :         {
     309           0 :             last_pit_band = add( 5, BAND1k2 );
     310             :         }
     311           5 :         ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
     312             :         {
     313           0 :             last_pit_band = add( 3, BAND1k2 );
     314             :         }
     315           5 :         ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) )
     316             :         {
     317           1 :             last_pit_band = add( BAND1k2, 1 );
     318             :         }
     319           5 :         last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q0 */
     320           5 :         move16();
     321             : 
     322           5 :         st_fx->bpf_off = 0;
     323           5 :         move16();
     324             : 
     325           5 :         max_len = sub( st_fx->L_frame, last_pit_bin ); /* Q0 */
     326             : 
     327           5 :         if ( EQ_16( st_fx->bwidth, NB ) )
     328             :         {
     329           0 :             max_len = sub( 160, last_pit_bin );
     330             :         }
     331             : 
     332           5 :         Len = 80;
     333           5 :         move16();
     334           5 :         if ( LT_16( max_len, 80 ) )
     335             :         {
     336           1 :             Len = max_len;
     337           1 :             move16();
     338             :         }
     339           5 :         test();
     340           5 :         IF( ( EQ_32( st_fx->core_brate, ACELP_8k00 ) ) && ( NE_16( st_fx->bwidth, NB ) ) )
     341             :         {
     342           0 :             move16(); /*ptr init*/
     343           0 :             FOR( i = 0; i < max_len; i++ )
     344             :             {
     345           0 :                 dct_pitex[i + last_pit_bin] = 0;
     346           0 :                 move16();
     347             :             }
     348             :         }
     349             :         ELSE
     350             :         {
     351             : 
     352         390 :             FOR( i = 0; i < Len; i++ )
     353             :             {
     354         385 :                 dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */
     355             :             }
     356         249 :             FOR( ; i < max_len; i++ )
     357             :             {
     358         244 :                 dct_pitex[i + last_pit_bin] = 0;
     359         244 :                 move16();
     360             :             }
     361             :         }
     362           5 :         hGSCEnc->mem_last_pit_band = last_pit_band; /* Q0 */
     363           5 :         move16();
     364           5 :         pit_contr_idx = sub( last_pit_band, BAND1k2 );
     365             :     }
     366             :     ELSE
     367             :     {
     368           0 :         set16_fx( dct_pitex, 0, st_fx->L_frame );
     369           0 :         st_fx->bpf_off = 1;
     370           0 :         move16();
     371           0 :         last_pit_bin = 0;
     372           0 :         move16();
     373           0 :         last_pit_band = 0;
     374           0 :         move16();
     375           0 :         pit_contr_idx = 0;
     376           0 :         move16();
     377           0 :         hGSCEnc->mem_last_pit_band = 0;
     378           0 :         move16();
     379             : 
     380           0 :         set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k );
     381             : 
     382             :         /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */
     383           0 :         for ( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ )
     384             :         {
     385           0 :             delete_indice( hBstr, i );
     386             :         }
     387             : 
     388           0 :         delete_indice( hBstr, IND_ES_PRED );
     389             :     }
     390           5 :     IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) )
     391             :     {
     392           0 :         IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
     393             :         {
     394           0 :             if ( pit_contr_idx > 0 )
     395             :             {
     396           0 :                 pit_contr_idx = 1;
     397           0 :                 move16();
     398             :             }
     399             : 
     400           0 :             IF( EQ_16( st_fx->coder_type, INACTIVE ) )
     401             :             {
     402           0 :                 push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 );
     403             :             }
     404             :         }
     405             :         ELSE
     406             :         {
     407           0 :             push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 );
     408             :         }
     409             :     }
     410             :     ELSE
     411             :     {
     412           5 :         push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 );
     413             :     }
     414             : 
     415           5 :     return last_pit_bin;
     416             : }
     417             : 
     418             : 
     419       15095 : Word16 Pit_exc_contribution_len_ivas_fx(                        /* o  : bin where pitch contribution is significant */
     420             :                                          Encoder_State *st_fx,  /* i/o: state structure                 */
     421             :                                          const Word16 *dct_res, /* i  : DCT of residual                                                                 Q_new*/
     422             :                                          Word16 *dct_pitex,     /* i/o: DCT of pitch contribution                                               Q_new*/
     423             :                                          Word16 *pitch_buf,     /* i/o: Pitch per subframe                                                              Q6*/
     424             :                                          const Word16 nb_subfr, /* i  : Number of subframe considered                                   Q0*/
     425             :                                          Word16 *hangover,      /* i  : hangover for the time contribution switching    Q0*/
     426             :                                          Word16 Qnew )
     427             : {
     428             : 
     429             :     Word16 corr_dct_pit[MBANDS_LOC];
     430             :     Word32 corr_tmp, L_tmp;
     431             :     Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res;
     432             :     Word16 freq, i, j;
     433             :     Word16 last_pit_band, pit_contr_idx, last_pit_bin;
     434             :     Word32 ener_res;
     435             :     Word32 ener_pit;
     436             :     Word16 low_pit, F1st_harm, F8th_harm;
     437             :     Word16 corr_dct_pit_tmp[MBANDS_LOC];
     438       15095 :     Word16 time_flg = 0;
     439             :     Word16 Len, max_len;
     440             :     Word16 tmp_dec;
     441       15095 :     Word16 Mbands_loc = MBANDS_LOC - 2;
     442             :     Word16 exp1, tmp, exp2;
     443             :     Word32 L_tmp1, ener_init;
     444             :     Word16 exp_norm;
     445             :     Word16 norm;
     446             :     Word16 val_thrs;
     447       15095 :     SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
     448       15095 :     BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
     449       15095 :     GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
     450       15095 :     move16();
     451             : 
     452       15095 :     if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     453             :     {
     454        2659 :         Mbands_loc = MBANDS_LOC;
     455        2659 :         move16();
     456             :     }
     457             : 
     458       15095 :     minimum_fx( pitch_buf, nb_subfr, &low_pit );
     459       15095 :     exp1 = norm_s( low_pit );
     460       15095 :     tmp = shl( low_pit, exp1 );
     461       15095 :     tmp_dec = 12800;
     462       15095 :     move16();
     463       15095 :     if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     464             :     {
     465        2659 :         tmp_dec = 16000;
     466        2659 :         move16();
     467             :     }
     468             :     /*F1st_harm = (12800.0f|160000.f)/low_pit;*/
     469       15095 :     tmp = div_s( tmp_dec, tmp );              /*15-6-exp1(->9-exp1)*/
     470       15095 :     F1st_harm = shr_r( tmp, sub( 5, exp1 ) ); /*Q4*/
     471             : 
     472             :     /*F8th_harm = 8.0f*F1st_harm;*/
     473       15095 :     F8th_harm = extract_l( L_shr_r( L_mult0( F1st_harm, 8 ), 2 ) ); /*Q2*/
     474             : 
     475       15095 :     freq = 0;
     476       15095 :     move16();
     477       15095 :     ener_init = L_shl( 3, 2 * Qnew - 5 ); /*(0.1->3 in Q5)  2*Qnew*/
     478      216648 :     FOR( i = 0; i < Mbands_loc; i++ )     /* up to maximum allowed voiced critical band */
     479             :     {
     480      201553 :         corr_tmp = L_deposit_l( 0 );
     481      201553 :         ener_res = L_add( ener_init, 0 );
     482      201553 :         ener_pit = L_add( ener_init, 0 );
     483             : 
     484     3184881 :         FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */
     485             :         {
     486     2983328 :             tmp_ex = mult_r( dct_pitex[j + freq], 8192 );
     487     2983328 :             tmp_res = mult_r( dct_res[j + freq], 8192 );
     488     2983328 :             corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex );  /*2*Qnew*/
     489     2983328 :             ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/
     490     2983328 :             ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex );   /*2*Qnew*/
     491             :         }
     492             : 
     493      201553 :         L_tmp1 = Mult_32_32( ener_res, ener_pit );
     494      201553 :         exp2 = norm_l( L_tmp1 );
     495      201553 :         L_tmp1 = L_shl( L_tmp1, exp2 );
     496      201553 :         exp_norm = sub( 30, exp2 );
     497      201553 :         L_tmp1 = Isqrt_lc( L_tmp1, &exp_norm );
     498      201553 :         norm = extract_h( L_tmp1 ); /*15-exp_norm*/
     499      201553 :         L_tmp1 = L_shl( Mult_32_16( corr_tmp, norm ), exp_norm );
     500      201553 :         corr_dct_pit[i] = round_fx( L_shl( L_tmp1, 14 ) ); /*Q14*/
     501             : 
     502      201553 :         freq = add( freq, mfreq_bindiv_loc[i] );
     503             :     }
     504             : 
     505       15095 :     val_thrs = 8192;
     506       15095 :     move16(); /* 0.5 in Q14*/
     507             :     /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/
     508       15095 :     tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/
     509       15095 :     tmp = s_max( tmp, val_thrs );                                                  /*Qnew */
     510             : 
     511       15095 :     corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */
     512       15095 :     move16();
     513             : 
     514      186458 :     FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */
     515             :     {
     516      171363 :         L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] );       /* Q_new + 16 */
     517      171363 :         L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q_new + 16 */
     518             : 
     519      171363 :         tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q_new */
     520      171363 :         tmp = s_max( tmp, val_thrs );                   /* Q_new  */
     521             : 
     522      171363 :         corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */
     523      171363 :         move16();
     524             :     }
     525       15095 :     tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/
     526       15095 :     tmp = s_max( tmp, val_thrs );                                                      /* Q_new */
     527       15095 :     corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 );                              /* Q_new + 1 */
     528       15095 :     move16();
     529             : 
     530       15095 :     Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc ); /* Q_new + 1 */
     531             : 
     532       15095 :     L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/
     533      196235 :     FOR( i = 1; i < NB_VOIC_FX; i++ )                   /* up to maximum allowed voiced critical band */
     534             :     {
     535      181140 :         L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] ); /* Q_new + 16 */
     536             :     }
     537       15095 :     av_corr = round_fx( L_tmp1 ); /*Qnew*/
     538             : 
     539             :     /* Find the cut-off freq similarly to HSX */
     540       15095 :     last_pit_band = 0;
     541       15095 :     move16();
     542       15095 :     av_corr = round_fx( L_shl( L_mult0( av_corr, 6400 ), 16 - 12 ) ); /*Q14*Q0-12=Q2*/
     543             : 
     544       15095 :     if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     545             :     {
     546             :         /*av_corr *= 1.25f;*/
     547        2659 :         av_corr = add( av_corr, shr( av_corr, 2 ) );
     548             :     }
     549       15095 :     test();
     550       15095 :     if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) )
     551             :     {
     552       10446 :         av_corr = shl_sat( av_corr, 1 ); /*Q2 Correlation really poor at low rate, time domain still valide*/
     553             :     }
     554       15095 :     min_corr = abs_s( sub( mfreq_loc_Q2fx[0], av_corr ) ); /*Q2*/
     555             : 
     556      201553 :     FOR( i = 1; i < Mbands_loc; i++ ) /* up to maximum allowed voiced critical band */
     557             :     {
     558      186458 :         ftmp = abs_s( sub( mfreq_loc_Q2fx[i], av_corr ) ); /*Q2*/
     559             : 
     560      186458 :         IF( LT_16( ftmp, min_corr ) )
     561             :         {
     562       32233 :             last_pit_band = i;
     563       32233 :             move16();
     564       32233 :             min_corr = ftmp;
     565       32233 :             move16();
     566             :         }
     567             :     }
     568             : 
     569       15095 :     IF( GT_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) )
     570             :     {
     571             :         DO
     572             :         {
     573       60277 :             last_pit_band = add( last_pit_band, 1 );
     574             :         }
     575       60277 :         WHILE( GE_16( F8th_harm, mfreq_loc_Q2fx[last_pit_band] ) );
     576             :     }
     577       15095 :     if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) )
     578             :     {
     579        4890 :         last_pit_band = s_max( last_pit_band, 7 );
     580             :     }
     581       15095 :     test();
     582       15095 :     test();
     583       15095 :     test();
     584       15095 :     IF( GT_16( last_pit_band, 7 + BAND1k2 ) && ( LT_32( st_fx->core_brate, CFREQ_BITRATE ) || EQ_16( st_fx->bwidth, NB ) ) ) /*Added for 9.1*/
     585             :     {
     586        1331 :         last_pit_band = 7 + BAND1k2;
     587        1331 :         move16();
     588             :     }
     589       13764 :     ELSE IF( GT_16( last_pit_band, 10 + BAND1k2 ) && GE_32( st_fx->core_brate, CFREQ_BITRATE ) )
     590             :     {
     591         244 :         last_pit_band = add( 10, BAND1k2 );
     592             :     }
     593             : 
     594       15095 :     time_flg = 0;
     595       15095 :     move16();
     596       15095 :     test();
     597       15095 :     test();
     598       15095 :     test();
     599       15095 :     test();
     600       15095 :     test();
     601       15095 :     test();
     602       15095 :     test();
     603       15095 :     test();
     604       15095 :     test();
     605       15095 :     test();
     606       15095 :     IF( ( hGSCEnc->mem_last_pit_band > 0 && GT_16( st_fx->old_corr_fx, 16384 ) && GT_16( hSpMusClas->mold_corr_fx, 16384 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ ) || ( GT_16( last_pit_band, 6 ) ) || ( GE_16( last_pit_band, 4 ) && GE_16( hGSCEnc->lt_gpitch_fx, 19661 ) /*1.5f*GPIT_THR*/ && GT_16( st_fx->old_corr_fx, 22938 ) ) || ( GT_16( last_pit_band, BAND1k2 ) && GT_16( hSpMusClas->mold_corr_fx, 26214 ) && GE_16( hGSCEnc->lt_gpitch_fx, 13107 ) /*GPIT_THR*/ ) )
     607             :     {
     608       10168 :         tmp_dec = 1;
     609       10168 :         move16();
     610             :     }
     611             :     ELSE
     612             :     {
     613        4927 :         tmp_dec = 0;
     614        4927 :         move16();
     615             :     }
     616             : 
     617             :     /* Different past and current decision */
     618       15095 :     test();
     619       15095 :     test();
     620       15095 :     test();
     621       15095 :     IF( ( hGSCEnc->mem_last_pit_band == 0 && EQ_16( tmp_dec, 1 ) ) || ( hGSCEnc->mem_last_pit_band > 0 && tmp_dec == 0 ) )
     622             :     {
     623        4538 :         IF( *hangover == 0 )
     624             :         {
     625         850 :             time_flg = tmp_dec;
     626         850 :             move16();
     627         850 :             *hangover = HANGOVER_DELAY;
     628         850 :             move16();
     629             :         }
     630             :         ELSE
     631             :         {
     632        3688 :             time_flg = 0;
     633        3688 :             move16();
     634        3688 :             if ( hGSCEnc->mem_last_pit_band > 0 )
     635             :             {
     636        2895 :                 time_flg = 1;
     637        2895 :                 move16();
     638             :             }
     639             : 
     640        3688 :             ( *hangover ) = sub( ( *hangover ), 1 ); /* Q0 */
     641        3688 :             if ( *hangover < 0 )
     642             :             {
     643           0 :                 *hangover = 0;
     644           0 :                 move16();
     645             :             }
     646             :         }
     647             :     }
     648             :     ELSE
     649             :     {
     650       10557 :         time_flg = tmp_dec;
     651       10557 :         move16();
     652       10557 :         *hangover = HANGOVER_DELAY;
     653       10557 :         move16();
     654             :     }
     655             : 
     656             :     /* Decicison on final length of time contribution */
     657       15095 :     pit_contr_idx = 0;
     658       15095 :     move16();
     659       15095 :     test();
     660       15095 :     test();
     661       15095 :     IF( EQ_16( time_flg, 1 ) || NE_16( st_fx->coder_type, INACTIVE ) || st_fx->GSC_noisy_speech )
     662             :     {
     663       12821 :         test();
     664       12821 :         test();
     665             :         /*if(st_fx->core_brate  <ACELP_9k60)*/
     666       12821 :         IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 /* 64 in Q6 */ ) )
     667             :         {
     668        3366 :             last_pit_band = add( 9, BAND1k2 );
     669        3366 :             if ( EQ_16( st_fx->bwidth, NB ) )
     670             :             {
     671           0 :                 last_pit_band = add( 7, BAND1k2 );
     672             :             }
     673             :         }
     674        9455 :         ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 /* 128 in Q6 */ ) )
     675             :         {
     676        2354 :             last_pit_band = add( 5, BAND1k2 );
     677             :         }
     678        7101 :         ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
     679             :         {
     680        1824 :             last_pit_band = add( 3, BAND1k2 );
     681             :         }
     682        5277 :         ELSE IF( LT_16( last_pit_band, add( BAND1k2, 1 ) ) )
     683             :         {
     684         720 :             last_pit_band = add( BAND1k2, 1 );
     685             :         }
     686       12821 :         last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q15 */
     687       12821 :         move16();
     688             : 
     689       12821 :         st_fx->bpf_off = 0;
     690       12821 :         move16();
     691             : 
     692       12821 :         max_len = sub( st_fx->L_frame, last_pit_bin );
     693             : 
     694       12821 :         if ( EQ_16( st_fx->bwidth, NB ) )
     695             :         {
     696           0 :             max_len = sub( 160, last_pit_bin );
     697             :         }
     698             : 
     699       12821 :         Len = 80;
     700       12821 :         move16();
     701       12821 :         if ( LT_16( max_len, 80 ) )
     702             :         {
     703        3606 :             Len = max_len;
     704        3606 :             move16();
     705             :         }
     706       12821 :         test();
     707       12821 :         IF( ( EQ_32( st_fx->core_brate, ACELP_8k00 ) ) && ( NE_16( st_fx->bwidth, NB ) ) )
     708             :         {
     709          42 :             move16(); /*ptr init*/
     710        3956 :             FOR( i = 0; i < max_len; i++ )
     711             :             {
     712        3914 :                 dct_pitex[i + last_pit_bin] = 0;
     713        3914 :                 move16();
     714             :             }
     715             :         }
     716             :         ELSE
     717             :         {
     718             : 
     719      979032 :             FOR( i = 0; i < Len; i++ )
     720             :             {
     721      966253 :                 dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */
     722             :             }
     723      664217 :             FOR( ; i < max_len; i++ )
     724             :             {
     725      651438 :                 dct_pitex[i + last_pit_bin] = 0;
     726      651438 :                 move16();
     727             :             }
     728             :         }
     729       12821 :         hGSCEnc->mem_last_pit_band = last_pit_band;
     730       12821 :         move16();
     731       12821 :         pit_contr_idx = sub( last_pit_band, BAND1k2 );
     732             :     }
     733             :     ELSE
     734             :     {
     735        2274 :         set16_fx( dct_pitex, 0, st_fx->L_frame );
     736        2274 :         st_fx->bpf_off = 1;
     737        2274 :         move16();
     738        2274 :         last_pit_bin = 0;
     739        2274 :         move16();
     740        2274 :         last_pit_band = 0;
     741        2274 :         move16();
     742        2274 :         pit_contr_idx = 0;
     743        2274 :         move16();
     744        2274 :         hGSCEnc->mem_last_pit_band = 0;
     745        2274 :         move16();
     746             : 
     747        2274 :         set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR16k );
     748             :         /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */
     749      684474 :         FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ )
     750             :         {
     751      682200 :             delete_indice( hBstr, i );
     752             :         }
     753        2274 :         delete_indice( hBstr, IND_ES_PRED );
     754             :     }
     755       15095 :     IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) )
     756             :     {
     757        9723 :         IF( LT_32( st_fx->core_brate, ACELP_9k60 ) )
     758             :         {
     759        7664 :             if ( pit_contr_idx > 0 )
     760             :             {
     761        7544 :                 pit_contr_idx = 1;
     762        7544 :                 move16();
     763             :             }
     764             : 
     765        7664 :             IF( EQ_16( st_fx->coder_type, INACTIVE ) )
     766             :             {
     767         303 :                 push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 1 );
     768             :             }
     769             :         }
     770             :         ELSE
     771             :         {
     772        2059 :             push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 3 );
     773             :         }
     774             :     }
     775             :     ELSE
     776             :     {
     777        5372 :         push_indice( hBstr, IND_PIT_CONTR_IDX, pit_contr_idx, 4 );
     778             :     }
     779             : 
     780       15095 :     return last_pit_bin;
     781             : }

Generated by: LCOV version 1.14