LCOV - code coverage report
Current view: top level - lib_com - gs_noisefill_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 545 696 78.3 %
Date: 2025-05-03 01:55:50 Functions: 9 9 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"
       6             : #include "rom_com.h"
       7             : #include "prot_fx.h"
       8             : 
       9             : /*-------------------------------------------------------------------*
      10             :  * gs_noisf()
      11             :  *
      12             :  * Noise fill-in function
      13             :  *-------------------------------------------------------------------*/
      14             : 
      15      479365 : static void gs_noisf_fx(
      16             :     const Word16 Start_BIN,  /* i  : First bin for noise fill     */
      17             :     const Word16 NB_Qbins,   /* i  : Number of bin per band       */
      18             :     const Word16 Noise_fac,  /* i  : Noise level              Q15 */
      19             :     const Word16 *y_norm,    /* i  : Quantized pulses         Q(qNoise_fac)  */
      20             :     Word16 *exc_diffQ,       /* o  : Quantized pulses with noise added Q(qNoise_fac) */
      21             :     Word16 *seed_tcx,        /* i  : Random generator seed    */
      22             :     const Word16 coder_type, /* i  : coder type               */
      23             :     Word16 qNoise_fac )
      24             : {
      25             :     Word32 ftmp;
      26             :     Word16 i, k;
      27             :     Word16 NB_zer;
      28      479365 :     Word32 const_1 = 1;
      29      479365 :     move32();
      30             :     Word16 tmp;
      31             : 
      32      479365 :     NB_zer = shr( NB_Qbins, 1 );
      33             : 
      34      479365 :     const_1 = L_shl( const_1, add( qNoise_fac, qNoise_fac ) ); /*2*Q(qNoise_fac)*/
      35      479365 :     if ( ( coder_type == INACTIVE ) )
      36             :     {
      37      144238 :         NB_zer = 2;
      38      144238 :         move16();
      39             :     }
      40             : 
      41             :     /*----------------------------------------------*
      42             :      * noise fill-in on unquantized subvector       *
      43             :      * injected only from 1066Hz to 6400Hz.         *
      44             :      *----------------------------------------------*/
      45             : 
      46     2386323 :     FOR( k = Start_BIN; k < NB_Qbins + Start_BIN; k += NB_zer )
      47             :     {
      48     1906958 :         ftmp = L_deposit_l( 0 );
      49     9742062 :         FOR( i = k; i < k + NB_zer; i++ )
      50             :         {
      51     7835104 :             exc_diffQ[i] = y_norm[i];
      52     7835104 :             move16();
      53     7835104 :             ftmp = L_mac0( ftmp, exc_diffQ[i], exc_diffQ[i] ); /*2*Q(qNoise_fac)*/
      54             :         }
      55             : 
      56     1906958 :         IF( LT_32( L_shl( ftmp, 1 ), const_1 ) )
      57             :         {
      58     7276850 :             FOR( i = k; i < k + NB_zer; i++ )
      59             :             {
      60             :                 /*exc_diffQ[i] += Noise_fac*((float)own_random(seed_tcx)/32768.0f);*/
      61     5850214 :                 tmp = mult( Noise_fac, Random( seed_tcx ) ); /*Q15 */
      62     5850214 :                 tmp = shr( tmp, sub( 15, qNoise_fac ) );     /*qNoise_fac */
      63     5850214 :                 exc_diffQ[i] = add( exc_diffQ[i], tmp );
      64     5850214 :                 move16(); /*Q */
      65             :             }
      66             :         }
      67             :         ELSE
      68             :         {
      69             :             /* This is added only to keep the seed in sync between different compilers */
      70     2465212 :             FOR( i = k; i < k + NB_zer; i++ )
      71             :             {
      72     1984890 :                 Random( seed_tcx );
      73             :             }
      74             :         }
      75             :     }
      76             : 
      77      479365 :     return;
      78             : }
      79             : 
      80             : /*-------------------------------------------------------------------*
      81             :  * EstimateNoiseLevel_inner()
      82             :  *
      83             :  * Estimate noise level from the power spectrum
      84             :  *-------------------------------------------------------------------*/
      85             : 
      86       23832 : static void EstimateNoiseLevel_inner_fx(
      87             :     Word16 *noisepb,       /* o  : Noise per band Q15 */
      88             :     const long bitrate,    /* i  : Bitrate of the codec */
      89             :     const Word16 i_band,   /* i  : First band to compute the noise  */
      90             :     const Word16 Mbands_gn /* i  : number of bands                  */
      91             : )
      92             : {
      93             :     Word16 i;
      94             :     Word16 noise_offset;
      95             : 
      96       23832 :     noise_offset = 8192;
      97       23832 :     move16();
      98             :     /*0.25f * 32768 */
      99       23832 :     IF( GT_32( bitrate, ACELP_24k40 ) )
     100             :     {
     101         393 :         noise_offset = 6554;
     102         393 :         move16(); /*.2f * 32768 */
     103             :     }
     104       23439 :     ELSE IF( GE_32( bitrate, ACELP_22k60 ) )
     105             :     {
     106        1307 :         noise_offset = 9830;
     107        1307 :         move16(); /*.3f * 32768 */
     108             :     }
     109       22132 :     ELSE IF( GE_32( bitrate, ACELP_9k60 ) )
     110             :     {
     111        9561 :         noise_offset = 11469;
     112        9561 :         move16(); /*0.35f * 32768 */
     113             :     }
     114             :     ELSE
     115             :     {
     116       12571 :         noise_offset = 13107;
     117       12571 :         move16(); /*.4f * 32768 */
     118             :     }
     119             : 
     120       23832 :     set16_fx( noisepb + i_band, noise_offset, sub( Mbands_gn, i_band ) ); /*Q15*/
     121             : 
     122      142992 :     FOR( i = i_band; i < 5; i++ )
     123             :     {
     124      119160 :         noisepb[i] = s_min( noisepb[i], 6554 /*0.2(Q15)*/ );
     125      119160 :         move16();
     126             :     }
     127             : 
     128       23832 :     return;
     129             : }
     130             : /*==========================================================================*/
     131             : /* FUNCTION : void  EstimateNoiseLevel_fx()                                                     */
     132             : /*--------------------------------------------------------------------------*/
     133             : /* PURPOSE  :                                                               */
     134             : /*--------------------------------------------------------------------------*/
     135             : /*    INPUT ARGUMENTS :                                                                                                 */
     136             : /* _ (Word32) bitrate              : Bitrate of the codec       Q0                  */
     137             : /* _ (Word16) Diff_len                     : number of bin before cut-off frequency */
     138             : /* _ (Word16) Mbands_gn            : number of bands            Q0              */
     139             : /* _ (Word16) coder_type           : coder type             Q0              */
     140             : /* _ (Word16) noise_lev                    : pulses dynamic         Q0                  */
     141             : /* _ (Word16) pit_band_idx         : bin position of the cut-off frequency  */
     142             : /* _ (Word16*) freq_nsbin_per_band : bin per bands tables       Q0                              */
     143             : /*--------------------------------------------------------------------------*/
     144             : /* OUTPUT ARGUMENTS :                                                                                                       */
     145             : /* _ (Word16*) noisepb             :  Noise per band        Q15             */
     146             : /*--------------------------------------------------------------------------*/
     147             : /* INPUT/OUTPUT ARGUMENTS :                                                                                         */
     148             : /*  None                                                                    */
     149             : /*--------------------------------------------------------------------------*/
     150             : /* RETURN ARGUMENTS :                                                                                                       */
     151             : /* _ None                                                                                                                                   */
     152             : /*==========================================================================*/
     153       23832 : static void EstimateNoiseLevel_fx(
     154             :     Word16 *noisepb,           /* o  : Noise per band                          */
     155             :     const Word32 bitrate,      /* i  : Bitrate of the codec                    */
     156             :     const Word16 Diff_len,     /* i  : number of bin before cut-off frequency  */
     157             :     const Word16 Mbands_gn,    /* i  : number of bands                         */
     158             :     const Word16 coder_type,   /* i  : coder type                              */
     159             :     const Word16 noise_lev,    /* i  : pulses dynamic                          */
     160             :     const Word16 pit_band_idx, /* i  : bin position of the cut-off frequency   */
     161             :     Word16 last_bin,           /* i  : the last bin of bit allocation          */
     162             :     Word16 bwidth,
     163             :     const Word16 L_frame /* i  : frame length                            */
     164             : )
     165             : {
     166             :     Word16 i_band;
     167             : 
     168       23832 :     i_band = 0;
     169       23832 :     move16();
     170             : 
     171       23832 :     IF( LT_16( Diff_len, L_frame ) )
     172             :     {
     173       23832 :         EstimateNoiseLevel_inner_fx( noisepb, bitrate, i_band, MBANDS_GN );
     174       23832 :         IF( coder_type != INACTIVE )
     175             :         {
     176       15660 :             test();
     177       15660 :             test();
     178       15660 :             IF( ( EQ_32( bitrate, ACELP_8k00 ) && GT_16( last_bin, 8 ) ) && NE_16( bwidth, NB ) )
     179             :             {
     180          68 :                 FOR( ; Mbands_gn > i_band; i_band++ )
     181             :                 {
     182          64 :                     noisepb[i_band] = add( noisepb[i_band], noisepb[i_band] );
     183          64 :                     move16();
     184             :                 }
     185             :             }
     186             :             ELSE
     187             :             {
     188      149162 :                 FOR( ; pit_band_idx > i_band; i_band++ )
     189             :                 {
     190      133506 :                     noisepb[i_band] = mult_r( noisepb[i_band], 16384 );
     191      133506 :                     move16(); /* 1/2=0.5 in Q15 */
     192             :                 }
     193             :             }
     194             :         }
     195             :     }
     196       23832 :     test();
     197       23832 :     test();
     198       23832 :     IF( ( ( coder_type == INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) && EQ_16( L_frame, L_FRAME ) )
     199             :     {
     200       97210 :         FOR( i_band = 9; i_band < Mbands_gn; i_band++ )
     201             :         {
     202       85055 :             noisepb[i_band] = add( noisepb[i_band], mult_r( noisepb[i_band], 4915 ) );
     203       85055 :             move16(); /*noisepb[i_band]*1.15=noisepb[i_band] *(1 + 0.15) */
     204             :         }
     205             :     }
     206       11677 :     ELSE IF( EQ_16( L_frame, L_FRAME16k ) )
     207             :     {
     208        5175 :         IF( EQ_32( bitrate, ACELP_13k20 ) )
     209             :         {
     210           0 :             set16_fx( noisepb, 14746 /*0.45*/, Mbands_gn );
     211             :         }
     212             : 
     213        5175 :         IF( ( coder_type == INACTIVE ) )
     214             :         {
     215       98325 :             FOR( ; i_band < Mbands_gn; i_band++ )
     216             :             {
     217       93150 :                 noisepb[i_band] = 13107 /*.4f*/;
     218       93150 :                 move16();
     219             :             }
     220             :         }
     221           0 :         ELSE IF( LE_16( noise_lev, NOISE_LEVEL_SP1 ) && GT_32( bitrate, ACELP_16k40 ) )
     222             :         {
     223           0 :             FOR( ; i_band < sub( Mbands_gn, 4 ); i_band++ )
     224             :             {
     225           0 :                 noisepb[i_band] = mult_r( noisepb[i_band], 19661 ) /*.6f*/;
     226           0 :                 move16();
     227             :             }
     228             :         }
     229           0 :         ELSE IF( LE_16( noise_lev, NOISE_LEVEL_SP2 ) && GT_32( bitrate, ACELP_16k40 ) )
     230             :         {
     231           0 :             FOR( ; i_band < sub( Mbands_gn, 4 ); i_band++ )
     232             :             {
     233           0 :                 noisepb[i_band] = mult_r( noisepb[i_band], 26214 ) /*.8f*/;
     234           0 :                 move16();
     235             :             }
     236             :         }
     237             :     }
     238             : 
     239             : 
     240       23832 :     return;
     241             : }
     242             : 
     243             : /*============================================================================*/
     244             : /* FUNCTION : void  Appy_NoiseFill_fx()                                                           */
     245             : /*----------------------------------------------------------------------------*/
     246             : /* PURPOSE  :                                                                 */
     247             : /*----------------------------------------------------------------------------*/
     248             : /*    INPUT ARGUMENTS :                                                                                                   */
     249             : /* _ (Word16*) seed_tcx           : Seed for noise           Q0               */
     250             : /* _ (Word16*) noisepb                    : Noise per band           Q15              */
     251             : /* _ (Word16) Diff_len            : number of bin before cut-off frequency Q0 */
     252             : /* _ (Word16) Mbands_gn           : number of bands          Q0               */
     253             : /* _ (Word16) coder_type                  : pulses dynamic           Q0                   */
     254             : /* _ (Word16*) freq_nsbin_per_band: bin per bands tables     Q0               */
     255             : /* _ (Word16)  qexc_diffQ         : Q format of exc_diffQ                             */
     256             : /*----------------------------------------------------------------------------*/
     257             : /* OUTPUT ARGUMENTS :                                                                                                         */
     258             : /* _ (Word16*) exc_diffQ              :  Noise per band        qexc_diffQ         */
     259             : /*----------------------------------------------------------------------------*/
     260             : /* INPUT/OUTPUT ARGUMENTS :                                                                                           */
     261             : /*  None                                                                      */
     262             : /*----------------------------------------------------------------------------*/
     263             : /* RETURN ARGUMENTS :                                                                                                         */
     264             : /* _ None                                                                                                                                     */
     265             : /*============================================================================*/
     266       29322 : static void Apply_NoiseFill_fx(
     267             :     Word16 *exc_diffQ,                 /* i/o: Noise per band                        qexc_diffQ  */
     268             :     Word16 *seed_tcx,                  /* i  : Seed for noise                                     */
     269             :     const Word16 *noisepb,             /* i  : Noise per band                        Q15         */
     270             :     const Word16 Diff_len,             /* i  : number of bin before cut-off frequency  */
     271             :     const Word16 Mbands_gn,            /* i  : number of bands                         */
     272             :     const Word16 coder_type,           /* i  : coder type                              */
     273             :     const Word16 *freq_nsbin_per_band, /* i  : bin per bands tables                    */
     274             :     Word16 qexc_diffQ )
     275             : {
     276             :     Word16 StartBin, NB_Qbins, i_band;
     277       29322 :     StartBin = 0;
     278       29322 :     move16();
     279       29322 :     NB_Qbins = 0;
     280       29322 :     move16();
     281             : 
     282      508687 :     FOR( i_band = 0; i_band < Mbands_gn; i_band++ )
     283             :     {
     284      479365 :         StartBin = add( StartBin, NB_Qbins );
     285      479365 :         NB_Qbins = freq_nsbin_per_band[i_band];
     286      479365 :         move16();
     287             : 
     288      479365 :         IF( LT_16( Diff_len, L_FRAME ) )
     289             :         {
     290      479365 :             gs_noisf_fx( StartBin, NB_Qbins, noisepb[i_band], exc_diffQ, exc_diffQ, seed_tcx, coder_type, qexc_diffQ );
     291             :         }
     292             :     }
     293             : 
     294       29322 :     return;
     295             : }
     296             : /*==========================================================================*/
     297             : /* FUNCTION :void freq_dnw_scaling_fx   ()                                                              */
     298             : /*--------------------------------------------------------------------------*/
     299             : /* PURPOSE  :                                                               */
     300             : /*--------------------------------------------------------------------------*/
     301             : /*    INPUT ARGUMENTS :                                                                                                 */
     302             : /* _ (Word16) cor_strong_limit       : HF correlation             Q0                */
     303             : /* _ (Word16) coder_type                         : coder type                     Q0                */
     304             : /* _ (Word16) noise_lev                          : Noise level                    Q0                */
     305             : /* _ (Word32) core_brate             : Core bitrate           Q0            */
     306             : /* _ (Word16) Qx                     : Q format of fy_norm                                  */
     307             : /*--------------------------------------------------------------------------*/
     308             : /* OUTPUT ARGUMENTS :                                                                                                       */
     309             : /* _ None                                                                   */
     310             : /*--------------------------------------------------------------------------*/
     311             : /* INPUT/OUTPUT ARGUMENTS :                                                                                         */
     312             : /* _ (Word16[]) fy_norm        : Frequency quantized parameter  Qx              */
     313             : /*--------------------------------------------------------------------------*/
     314             : /* RETURN ARGUMENTS :                                                                                                       */
     315             : /* _None                                                                            */
     316             : /*==========================================================================*/
     317       28874 : void freq_dnw_scaling_fx(
     318             :     const Word16 cor_strong_limit, /* i  : HF correlation                */
     319             :     const Word16 coder_type,       /* i  : coder type                    */
     320             :     const Word16 noise_lev,        /* i  : Noise level                   */
     321             :     const Word32 core_brate,       /* i  : Core bitrate                  */
     322             :     Word16 fy_norm[],              /* i/o: Frequency quantized parameter Qx */
     323             :     Word16 Qx,                     /* Q format of fy_norm*/
     324             :     const Word16 L_frame           /* i  : frame length                  */
     325             : 
     326             : )
     327             : {
     328             :     Word16 sc_dyn;
     329             :     Word16 start_sc, i;
     330             : 
     331       28874 :     sc_dyn = 32767;
     332       28874 :     move16(); /*Q15 */
     333       28874 :     start_sc = L_frame;
     334       28874 :     move16();
     335       28874 :     test();
     336       28874 :     IF( LE_32( core_brate, ACELP_8k00 ) && ( coder_type == INACTIVE ) )
     337             :     {
     338          55 :         sc_dyn = mult_r( sc_dyn, 4915 ); /*Q15  (0.15 in Q15) */
     339          55 :         start_sc = 64;
     340          55 :         move16();
     341             :     }
     342       28819 :     ELSE IF( ( coder_type == INACTIVE ) )
     343             :     {
     344        8256 :         sc_dyn = mult_r( sc_dyn, 8192 ); /*Q15 (0.25 in Q15) */
     345        8256 :         start_sc = 80;
     346        8256 :         move16();
     347             :     }
     348             :     ELSE
     349             :     {
     350             :         /*sc_dyn = (float)(NOISE_LEVEL_SP3 - noise_lev)/10.0f + 0.4f;*/
     351       20563 :         sc_dyn = extract_l( L_mac( 13107, sub( NOISE_LEVEL_SP3, noise_lev ), 1638 ) ); /*Q0*Q14x2+Q15 =Q15*/
     352       20563 :         start_sc = add( 112, shl( sub( NOISE_LEVEL_SP3, noise_lev ), 4 ) );
     353       20563 :         if ( EQ_16( noise_lev, NOISE_LEVEL_SP0 ) )
     354             :         {
     355        4901 :             start_sc = L_FRAME;
     356        4901 :             move16();
     357             :         }
     358             :     }
     359             : 
     360       28874 :     test();
     361       28874 :     IF( EQ_16( L_frame, L_FRAME16k ) && LE_32( core_brate, ACELP_24k40 ) )
     362             :     {
     363             :         /*sc_dyn += 0.125f;*/
     364        4782 :         sc_dyn = add( sc_dyn, 4096 ); /* Saturates to 1.0 */
     365             :     }
     366             : 
     367     3881706 :     FOR( i = start_sc; i < L_frame; i++ )
     368             :     {
     369     3852832 :         fy_norm[i] = mult_r( fy_norm[i], sc_dyn );
     370     3852832 :         move16(); /*Qx */
     371             :     }
     372             : 
     373       28874 :     test();
     374       28874 :     test();
     375       28874 :     IF( ( LT_32( core_brate, ACELP_13k20 ) && cor_strong_limit == 0 ) || LT_32( core_brate, ACELP_9k60 ) )
     376             :     {
     377     2080650 :         FOR( i = 160; i < L_frame; i++ )
     378             :         {
     379     2059200 :             fy_norm[i] = s_min( fy_norm[i], shl( 1, Qx ) ); /*Qx*/
     380     2059200 :             move16();
     381     2059200 :             fy_norm[i] = s_max( fy_norm[i], shl( -1, Qx ) ); /*Qx*/
     382     2059200 :             move16();
     383             :         }
     384             :     }
     385        7424 :     ELSE IF( LT_32( core_brate, ACELP_22k60 ) )
     386             :     {
     387      777628 :         FOR( i = 160; i < L_frame; i++ )
     388             :         {
     389      771904 :             fy_norm[i] = s_min( fy_norm[i], shr_r( 1536 /*1.5 in Q10*/, sub( 10, Qx ) ) ); /*Qx*/
     390      771904 :             move16();
     391      771904 :             fy_norm[i] = s_max( fy_norm[i], shr_r( -1536 /*1.5 in Q10*/, sub( 10, Qx ) ) ); /*Qx*/
     392      771904 :             move16();
     393             :         }
     394             :     }
     395             : 
     396       28874 :     return;
     397             : }
     398             : 
     399          61 : static void Decreas_freqPeak_fx(
     400             :     const Word16 *lsf_new, /* i  : ISFs at the end of the frame                        Qx2.56  */
     401             :     Word16 *exc_diffQ,     /* i/o: frequency coefficients of per band                    */
     402             :     Word16 rat             /* i  : threshold of ratio between consecutive lsf_new_diff   */
     403             : )
     404             : {
     405             :     Word16 i, j, k;
     406          61 :     Word16 last_bin = 0;
     407          61 :     Word16 pos = 0;
     408          61 :     move16();
     409             :     Word16 *src, max_val, avrg;
     410             :     Word32 L_avrg, L_tmp;
     411             :     Word16 lsf_new_diff[M];
     412             :     Word16 tmp, tmp1, exp;
     413             :     Word16 tmp2;
     414             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     415          61 :     Flag Overflow = 0;
     416          61 :     move16();
     417             : #endif
     418          61 :     move16();            /*ptr init*/
     419          61 :     lsf_new_diff[0] = 0; /* prevent unitialized value */
     420          61 :     move16();
     421         915 :     FOR( j = 1; j < ( M - 1 ); j++ )
     422             :     {
     423         854 :         lsf_new_diff[j] = sub( lsf_new[j], lsf_new[j - 1] ); /*Qx2.56 */
     424         854 :         move16();
     425             :     }
     426             : 
     427          61 :     avrg = 0;
     428          61 :     move16();
     429          61 :     L_avrg = L_deposit_l( 0 );
     430          61 :     max_val = 1;
     431          61 :     move16();
     432        5917 :     FOR( i = 160; i < L_FRAME; i++ )
     433             :     {
     434        5856 :         IF( GT_16( abs_s( exc_diffQ[i] ), max_val ) )
     435             :         {
     436         331 :             max_val = abs_s( exc_diffQ[i] );
     437         331 :             pos = i;
     438         331 :             move16();
     439             :         }
     440        5856 :         L_avrg = L_add( L_avrg, abs_s( exc_diffQ[i] ) );
     441             :     }
     442             :     /* avrg /= 96; */
     443          61 :     L_avrg = Mult_32_16( L_avrg, 21845 );   /*Q_exc+21 -15 ->Q_exc + 6 */
     444          61 :     avrg = round_fx( L_shl( L_avrg, 10 ) ); /*Q_exc */
     445          61 :     last_bin = M - 1;
     446          61 :     move16(); /* When the search is false, should equate the end of the vector, not the beginning */
     447         680 :     FOR( i = 0; i < ( M - 1 ); i++ )
     448             :     {
     449         680 :         IF( GT_16( lsf_new[i], 10240 /*4000 in Qx2.56*/ ) )
     450             :         {
     451          61 :             last_bin = i;
     452          61 :             move16();
     453          61 :             BREAK;
     454             :         }
     455             :     }
     456             : 
     457         296 :     FOR( i = last_bin; i < 14; i++ )
     458             :     {
     459         235 :         tmp = mult_r( rat, lsf_new_diff[i - 1] ); /*Qx2.56 */
     460         235 :         IF( GT_16( tmp, lsf_new_diff[i] ) )
     461             :         {
     462          14 :             src = &exc_diffQ[( i - 1 ) << 4];
     463          14 :             move16();
     464          42 :             FOR( j = 0; j < 2; j++ )
     465             :             {
     466         476 :                 FOR( k = 0; k < 16; k++ )
     467             :                 {
     468         448 :                     tmp = mult_r( 16384, abs_s( *src ) );
     469         448 :                     IF( GT_16( tmp, avrg ) )
     470             :                     {
     471          36 :                         tmp = abs_s( *src );
     472          36 :                         exp = norm_s( max_val );
     473          36 :                         tmp1 = div_s( shl( 1, sub( 14, exp ) ), max_val );               /*Q(29 - exp - Q_exc) */
     474          36 :                         L_tmp = L_mult( tmp, tmp1 );                                     /*Q(30 - exp) */
     475          36 :                         tmp = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q14 */
     476          36 :                         tmp = sub( 32767, tmp );                                         /*Q14 */
     477          36 :                         L_tmp = L_mult( avrg, tmp );                                     /*Q_exc +15 */
     478             : 
     479          36 :                         tmp = round_fx( L_shl( L_tmp, 1 ) );
     480          36 :                         tmp1 = negate( tmp );
     481             : 
     482          36 :                         tmp2 = *src;
     483          36 :                         move16();
     484          36 :                         *( src ) = tmp1;
     485          36 :                         move16();
     486          36 :                         if ( tmp2 > 0 )
     487             :                         {
     488          16 :                             *( src ) = tmp;
     489          16 :                             move16();
     490             :                         }
     491             :                     }
     492         448 :                     src++;
     493             :                 }
     494             :             }
     495             :         }
     496             :     }
     497             : 
     498          61 :     tmp = mult_r( 8192, max_val ); /*Q_exc */
     499          61 :     test();
     500          61 :     IF( EQ_16( abs_s( exc_diffQ[pos] ), max_val ) && GT_16( tmp, avrg ) )
     501             :     {
     502          88 :         FOR( i = pos - 1; i < pos + 2; i++ )
     503             :         {
     504          66 :             exc_diffQ[pos] = mult_r( 16384 /*0.5 in Q15*/, exc_diffQ[pos] );
     505          66 :             move16();
     506             :         }
     507             :     }
     508             : 
     509          61 :     return;
     510             : }
     511             : 
     512          29 : static void envelop_modify_fx(
     513             :     Word16 *exc_diffQ_fx,      /* i/o: frequency coefficients of per band      */
     514             :     Word16 *seed_tcx,          /* i  : Seed for noise                          */
     515             :     Word16 last_bin,           /* i  : last bin of bit allocation              */
     516             :     Word16 *Ener_per_bd_iQ_fx, /* i  : Quantized energy of targeted vector     */
     517             :     Word16 Q_exc,
     518             :     Word16 *Q_hb_exc )
     519             : {
     520             :     Word16 i, j, end_band;
     521             :     Word16 start_band;
     522             :     Word32 Ener_fx;
     523             :     Word16 Ener1_fx;
     524             :     Word16 tmp, tmp1;
     525             :     Word32 L_tmp;
     526             :     Word16 exp, exp1, frac;
     527             :     Word16 *src_fx;
     528             :     Word16 weight_fx;
     529             :     Word32 L_exc_diffQ_fx[L_FRAME16k], exc_diffQ_max;
     530             :     Word16 Q_tmp;
     531             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     532          29 :     Flag Overflow = 0;
     533          29 :     move16();
     534             : #endif
     535             : 
     536          29 :     start_band = i_mult( last_bin, 16 );
     537          29 :     end_band = L_FRAME;
     538          29 :     move16();
     539          29 :     Ener_fx = L_deposit_l( 0 );
     540        2813 :     FOR( i = start_band; i < end_band; i++ )
     541             :     {
     542        2784 :         L_tmp = L_mult0( exc_diffQ_fx[i], exc_diffQ_fx[i] ); /*2*Q_exc */
     543        2784 :         Ener_fx = L_add( Ener_fx, L_shr( L_tmp, 7 ) );       /*2*Q_exc-7 */
     544             :     }
     545             : 
     546          29 :     tmp = sub( end_band, start_band );
     547          29 :     tmp = div_s( 1, tmp );                /*Q15 */
     548          29 :     Ener_fx = Mult_32_16( Ener_fx, tmp ); /*Q(2*Q_exc-7+15)->Q(2*Q_exc-7) */
     549             : 
     550          29 :     exp1 = norm_l( Ener_fx );
     551          29 :     Ener_fx = L_shl( Ener_fx, exp1 );
     552          29 :     exp1 = sub( sub( 31, exp1 ), sub( shl( Q_exc, 1 ), 7 ) );
     553          29 :     Ener_fx = Isqrt_lc( Ener_fx, &exp1 ); /*Q(31-exp1) */
     554             : 
     555          29 :     weight_fx = 16384; /*Q15 */
     556          29 :     move16();
     557          29 :     src_fx = &exc_diffQ_fx[start_band]; /*Q_exc */
     558         145 :     FOR( i = last_bin; i < last_bin + 4; i++ )
     559             :     {
     560             :         /*Ener1 = (float)(0.4f*pow(10, Ener_per_bd_iQ[i+1])); */
     561         116 :         L_tmp = L_shr( L_mult0( Ener_per_bd_iQ_fx[i + 1], 27213 ), 9 ); /* 3.321928 in Q13 -> Q16 */
     562             : 
     563         116 :         frac = L_Extract_lc( L_tmp, &exp );  /* Extract exponent of L_tmp */
     564         116 :         tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
     565             :         /* output of Pow2() will be: */
     566             :         /* 16384 < Pow2() <= 32767 */
     567         116 :         exp = sub( exp, 14 );
     568         116 :         Ener1_fx = mult_ro( 13107, shl_o( tmp, exp, &Overflow ), &Overflow ); /*Q0 */
     569             : 
     570        1972 :         FOR( j = 0; j < 16; j++ )
     571             :         {
     572             :             /**src = Ener1*(weight*(*src)*Ener + (1.0f-weight)*own_random(seed_tcx)/32768.0f); */
     573        1856 :             L_tmp = Mult_32_16( Ener_fx, *src_fx );                          /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */
     574        1856 :             tmp = extract_l( L_shr( L_tmp, add( 4, sub( Q_exc, exp1 ) ) ) ); /*Q12 */
     575        1856 :             tmp = mult_r( weight_fx, tmp );                                  /*Q12 */
     576             : 
     577        1856 :             L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */
     578        1856 :             tmp1 = round_fx( L_shr( L_tmp, 2 ) );
     579             : 
     580        1856 :             L_exc_diffQ_fx[( ( 16 * i ) + j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12           */
     581        1856 :             move32();
     582        1856 :             src_fx++;
     583             :         }
     584             :     }
     585             : 
     586             :     /*Ener1 = (float)(0.4f*pow(10, Ener_per_bd_iQ[15])); */
     587          29 :     L_tmp = L_shr( L_mult0( Ener_per_bd_iQ_fx[15], 27213 ), 9 ); /* 3.321928 in Q13 -> Q16 */
     588             : 
     589          29 :     frac = L_Extract_lc( L_tmp, &exp );  /* Extract exponent of L_tmp */
     590          29 :     tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
     591             :     /* output of Pow2() will be: */
     592             :     /* 16384 < Pow2() <= 32767 */
     593          29 :     exp = sub( exp, 14 );
     594          29 :     Ener1_fx = mult_r( 13107, shl_o( tmp, exp, &Overflow ) ); /*Q0 */
     595             : 
     596          29 :     src_fx = &exc_diffQ_fx[224];
     597         957 :     FOR( j = 0; j < 32; j++ )
     598             :     {
     599             :         /**src = Ener1*(weight*(*src)*Ener + (1.0f-weight)*own_random(seed_tcx)/32768.0f); */
     600         928 :         L_tmp = Mult_32_16( Ener_fx, *src_fx );                          /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */
     601         928 :         tmp = extract_l( L_shr( L_tmp, add( 4, sub( Q_exc, exp1 ) ) ) ); /*Q12 */
     602         928 :         tmp = mult_r( weight_fx, tmp );                                  /*Q12 */
     603             : 
     604         928 :         L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */
     605         928 :         tmp1 = round_fx( L_shr( L_tmp, 2 ) );                           /*Q12 */
     606             : 
     607         928 :         L_exc_diffQ_fx[( ( 16 * i ) + j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12                     */
     608         928 :         move32();
     609         928 :         src_fx++;
     610             :     }
     611             : 
     612          29 :     exc_diffQ_max = 0;
     613          29 :     move16();
     614        2813 :     FOR( i = start_band; i < L_FRAME; i++ )
     615             :     {
     616        2784 :         if ( GT_32( L_abs( L_exc_diffQ_fx[i] ), exc_diffQ_max ) )
     617             :         {
     618         100 :             exc_diffQ_max = L_abs( L_exc_diffQ_fx[i] );
     619             :         }
     620             :     }
     621          29 :     exp = norm_l( exc_diffQ_max );
     622             : 
     623          29 :     IF( GT_16( exp, 16 ) )
     624             :     {
     625           0 :         *Q_hb_exc = 12;
     626           0 :         move16();
     627           0 :         FOR( i = start_band; i < L_FRAME; i++ )
     628             :         {
     629           0 :             exc_diffQ_fx[i] = extract_l( L_exc_diffQ_fx[i] );
     630           0 :             move16();
     631             :         }
     632             :     }
     633             :     ELSE
     634             :     {
     635          29 :         Q_tmp = sub( 16, exp );
     636          29 :         *Q_hb_exc = sub( 12, Q_tmp );
     637          29 :         move16();
     638        2813 :         FOR( i = start_band; i < L_FRAME; i++ )
     639             :         {
     640        2784 :             exc_diffQ_fx[i] = extract_l( L_shr( L_exc_diffQ_fx[i], Q_tmp ) );
     641        2784 :             move16();
     642             :         }
     643             :     }
     644             : 
     645          29 :     return;
     646             : }
     647             : 
     648           7 : void highband_exc_dct_in_fx(
     649             :     const Word32 core_brate,         /* i  : core bitrate                            */
     650             :     const Word16 *mfreq_bindiv,      /* i  : bin per bands tables                    */
     651             :     Word16 last_bin,                 /* i  : last bin of bit allocation              */
     652             :     Word16 Diff_len,                 /* i  : number of bin before cut-off frequency  */
     653             :     Word16 noise_lev,                /* i  : pulses dynamic                          */
     654             :     Word16 pit_band_idx,             /* i  : bin position of the cut-off frequency   */
     655             :     Word16 *exc_diffQ,               /* i  : frequency coefficients of per band      */
     656             :     Word16 *seed_tcx,                /* i  : Seed for noise                          */
     657             :     Word16 *Ener_per_bd_iQ,          /* i  : Quantized energy of targeted vector     */
     658             :     Word16 nb_subfr,                 /* i  : Number of subframe considered           */
     659             :     Word16 *exc_dct_in,              /* o  : dct of residual signal                  */
     660             :     Word16 last_coder_type,          /* i  : coding type of last frame               */
     661             :     Word16 *bitallocation_band,      /* i  : bit allocation flag of each band        */
     662             :     const Word16 *lsf_new,           /* i  : LSFs at the end of the frame            */
     663             :     Word16 *last_exc_dct_in,         /* i  : dct of residual signal of last frame    */
     664             :     Word16 *last_ener,               /* i  : frequency energy  of last frame         */
     665             :     Word16 *last_bitallocation_band, /* i  : bit allocation flag of each band  of last frame   */
     666             :     Word16 *bitallocation_exc,       /* i  : flag of decoded coefficients            */
     667             :     Word16 bfi,                      /* i  : bad frame indicator                     */
     668             :     const Word16 coder_type,         /* i  : coder type                              */
     669             :     Word16 bwidth,
     670             :     Word16 *exc_wo_nf, /* o  : temporal excitation (in f domain) without noisefill   */
     671             :     Word16 Qexc_diffQ,
     672             :     Word16 Q_exc,
     673             :     const Word16 GSC_noisy_speech,
     674             :     Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy                 */
     675             :     const Word16 L_frame,        /* i  : frame length                            */
     676             :     const Word16 element_mode,   /* i  : IVAS element mode                       */
     677             :     const Word16 GSC_IVAS_mode   /* i  : GSC IVAS mode                           */
     678             : )
     679             : {
     680             :     Word16 i, j, k;
     681           7 :     Word16 MAX_Bin = 0;
     682           7 :     Word16 last_bin_tmp, ener = 0;
     683           7 :     move16();
     684             :     Word16 noisepb[MBANDS_GN16k];
     685             :     Word16 Ener_per_bd_yQ[MBANDS_GN16k];
     686             :     Word16 *src, *dst;
     687             :     Word32 L_tmp;
     688           7 :     Word16 length_bin, bwe_flag = 0, tmp;
     689           7 :     move16();
     690             :     Word16 frac, exp, tmp1;
     691             :     Word16 tmp2;
     692             :     Word16 *end, Q_hb_exc;
     693             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     694           7 :     Flag Overflow = 0;
     695           7 :     move16();
     696             : #endif
     697             : 
     698          49 :     FOR( j = 10; j < MBANDS_GN; j++ )
     699             :     {
     700             :         /*  ener += (float)pow(10, Ener_per_bd_iQ[j]);
     701             :             ener += (float)pow(2, 3.321928*Ener_per_bd_iQ[j]); */
     702             : 
     703          42 :         L_tmp = L_mult( Ener_per_bd_iQ[j], 27213 ); /* 3.321928 in Q13 -> Q27 */
     704          42 :         L_tmp = L_shr( L_tmp, 10 );                 /* From Q27 to Q16 */
     705             : 
     706          42 :         frac = L_Extract_lc( L_tmp, &exp );  /* Extract exponent of L_tmp */
     707          42 :         tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
     708             :         /* output of Pow2() will be: */
     709             :         /* 16384 < Pow2() <= 32767 */
     710          42 :         exp = sub( exp, 14 );
     711          42 :         tmp1 = shl_o( tmp, exp, &Overflow );
     712          42 :         move16();
     713          42 :         ener = add_o( tmp1, ener, &Overflow ); /*Q0 */
     714             :     }
     715             : 
     716           7 :     test();
     717           7 :     IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
     718             :     {
     719           0 :         if ( NE_16( last_coder_type, AUDIO ) )
     720             :         {
     721           0 :             *last_ener = ener;
     722           0 :             move16();
     723             :         }
     724           0 :         test();
     725           0 :         test();
     726           0 :         IF( ( GT_16( last_bin, 8 ) || Diff_len != 0 ) && EQ_16( last_coder_type, AUDIO ) )
     727             :         {
     728           0 :             MAX_Bin = 10;
     729           0 :             move16();
     730           0 :             bwe_flag = 1;
     731           0 :             move16();
     732             :         }
     733             :         ELSE
     734             :         {
     735           0 :             MAX_Bin = 15;
     736           0 :             move16();
     737             :         }
     738             : 
     739           0 :         last_bin_tmp = last_bin;
     740           0 :         move16();
     741           0 :         last_bin = s_max( last_bin, MAX_Bin );
     742           0 :         last_bin = add( last_bin, 1 );
     743             :     }
     744             :     ELSE
     745             :     {
     746           7 :         IF( EQ_16( L_frame, L_FRAME16k ) )
     747             :         {
     748           0 :             last_bin = MBANDS_GN16k;
     749           0 :             move16();
     750             :         }
     751             :         ELSE
     752             :         {
     753           7 :             last_bin = MBANDS_GN;
     754           7 :             move16();
     755             :         }
     756           7 :         last_bin_tmp = last_bin;
     757           7 :         move16();
     758             :     }
     759             : 
     760           7 :     test();
     761           7 :     test();
     762           7 :     test();
     763           7 :     test();
     764           7 :     IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) )
     765             :     {
     766           0 :         set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */
     767             :     }
     768           7 :     ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) )
     769             :     {
     770           0 :         set16_fx( noisepb, 13107 /*0.4f*/, MBANDS_GN16k );
     771             :     }
     772             :     ELSE
     773             :     {
     774           7 :         EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame );
     775             :     }
     776             : 
     777           7 :     IF( exc_wo_nf != NULL )
     778             :     {
     779           7 :         Copy( exc_diffQ, exc_wo_nf, L_frame );
     780             :     }
     781             : 
     782           7 :     test();
     783           7 :     test();
     784           7 :     test();
     785           7 :     IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) )
     786             :     {
     787           0 :         set16_fx( noisepb, 3277, MBANDS_GN );
     788             :     }
     789           7 :     test();
     790           7 :     IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) )
     791             :     {
     792           0 :         FOR( i = 0; i < L_frame; i++ )
     793             :         {
     794           0 :             IF( exc_diffQ[i] == 0 )
     795             :             {
     796             :                 /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
     797           0 :                 tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
     798           0 :                 tmp = shr( tmp, sub( 15, Qexc_diffQ ) );                /*qNoise_fac */
     799           0 :                 exc_diffQ[i] = add( exc_diffQ[i], tmp );
     800           0 :                 move16(); /*Q */
     801             :             }
     802             :         }
     803             :     }
     804             :     ELSE
     805             :     {
     806           7 :         Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ );
     807             :     }
     808             :     /*--------------------------------------------------------------------------------------*
     809             :      * Quantize average gain
     810             :      * Subtract Q averaged gain
     811             :      * VQ of remaining gain per band
     812             :      *--------------------------------------------------------------------------------------*/
     813           7 :     test();
     814           7 :     IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
     815             :     {
     816           0 :         Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0 );
     817             :     }
     818             :     ELSE
     819             :     {
     820           7 :         Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 );
     821             : 
     822           7 :         IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) )
     823             :         {
     824         119 :             FOR( i = L_FRAME - 16; i < L_FRAME; i++ )
     825             :             {
     826             :                 /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */
     827         112 :                 tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) );  /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */
     828         112 :                 L_tmp = L_mult( exc_diffQ[i], tmp );                /*Q(Qexc_diffQ+10) */
     829         112 :                 exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */
     830         112 :                 move16();
     831             :             }
     832             :         }
     833             :     }
     834             :     /*--------------------------------------------------------------------------------------*
     835             :      * Check potential energy excitation overshoot
     836             :      *--------------------------------------------------------------------------------------*/
     837           7 :     IF( bfi )
     838             :     {
     839           0 :         test();
     840           0 :         IF( GSC_noisy_speech == 0 && GT_16( coder_type, UNVOICED ) ) /* Here coder_type == last_coder_type because of the bfi */
     841             :         {
     842           0 :             FOR( i = 0; i < last_bin; i++ )
     843             :             {
     844           0 :                 Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( sub( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) );
     845           0 :                 move16();
     846           0 :                 lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
     847           0 :                 move16();
     848             :             }
     849           0 :             FOR( ; i < MBANDS_GN; i++ )
     850             :             {
     851           0 :                 Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( lt_ener_per_band_fx[i], 154 ) );
     852           0 :                 move16();
     853           0 :                 lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
     854           0 :                 move16();
     855             :             }
     856             :         }
     857             :         ELSE
     858             :         {
     859           0 :             FOR( i = 0; i < last_bin; i++ )
     860             :             {
     861           0 :                 Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) );
     862           0 :                 move16();
     863           0 :                 lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
     864           0 :                 move16();
     865             :             }
     866           0 :             FOR( ; i < MBANDS_GN; i++ )
     867             :             {
     868           0 :                 Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], add( lt_ener_per_band_fx[i], 1229 ) );
     869           0 :                 move16();
     870           0 :                 lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
     871           0 :                 move16();
     872             :             }
     873             :         }
     874             :     }
     875             :     /*--------------------------------------------------------------------------------------*
     876             :      * Apply decoded gain onto the difference signal
     877             :      *--------------------------------------------------------------------------------------*/
     878             : 
     879           7 :     IF( GSC_noisy_speech )
     880             :     {
     881           0 :         FOR( i = 0; i < L_frame; i++ )
     882             :         {
     883           0 :             exc_diffQ[i] = mult_r( exc_diffQ[i], 29491 );
     884           0 :             move16();
     885             :         }
     886             :     }
     887             : 
     888           7 :     Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc );
     889             : 
     890           7 :     IF( exc_wo_nf != NULL )
     891             :     {
     892           7 :         Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, Q_exc );
     893           7 :         Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
     894             :     }
     895             :     /*--------------------------------------------------------------------------------------*
     896             :      * add the correction layer to the LF bins,
     897             :      * and add the quantized pulses or the noise for the higher part of the spectrum
     898             :      * (non valuable temporal content already zeroed)
     899             :      * DC is Zeroed
     900             :      *--------------------------------------------------------------------------------------*/
     901             : 
     902           7 :     Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame );
     903           7 :     test();
     904           7 :     IF( core_brate == ACELP_8k00 && bwidth != NB )
     905             :     {
     906           0 :         IF( EQ_16( bwe_flag, 1 ) )
     907             :         {
     908           0 :             last_bin = sub( last_bin, 1 );
     909           0 :             tmp = i_mult( MAX_Bin, 16 );
     910           0 :             tmp1 = i_mult( last_bin, 16 );
     911           0 :             src = &exc_diffQ[L_FRAME - 1];
     912           0 :             move16();
     913           0 :             dst = &exc_dct_in[( tmp - 1 )];
     914           0 :             move16();
     915           0 :             end = &exc_diffQ[( tmp1 - 1 )];
     916           0 :             move16();
     917             : 
     918           0 :             WHILE( src > end )
     919             :             {
     920           0 :                 *src-- = *dst--;
     921           0 :                 move16();
     922             :             }
     923           0 :             test();
     924           0 :             test();
     925           0 :             if ( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && EQ_32( core_brate, ACELP_8k00 ) )
     926             :             {
     927           0 :                 exc_diffQ[160] = 0;
     928           0 :                 move16();
     929             :             }
     930             : 
     931           0 :             Q_hb_exc = 0;
     932           0 :             move16();
     933           0 :             envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc );
     934           0 :             Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ), sub( Q_exc, Q_hb_exc ) ); /* from Q_hb_exc -> Q_exc as expected */
     935             :         }
     936             : 
     937           0 :         IF( LT_16( nb_subfr, 4 ) )
     938             :         {
     939           0 :             FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ )
     940             :             {
     941             :                 /*exc_dct_in[i] *= (0.067f*i-15.f); */
     942           0 :                 tmp = mult_r( 17564, shl( i, 6 ) );                                      /*0.067 in Q18 and i in Q6= Q9 */
     943           0 :                 tmp = sub( tmp, 7680 );                                                  /*15 in Q9 = Q9 */
     944           0 :                 L_tmp = L_mult( exc_dct_in[i], tmp );                                    /*Q(Q_exc+10) */
     945           0 :                 exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */
     946             :             }
     947             :         }
     948             : 
     949           0 :         tmp1 = mult_r( ener, 16384 );
     950           0 :         tmp1 = sub( *last_ener, tmp1 );
     951           0 :         tmp = mult_r( *last_ener, 16384 );
     952           0 :         tmp = sub( ener, tmp );
     953           0 :         test();
     954           0 :         IF( tmp > 0 && tmp1 > 0 )
     955             :         {
     956           0 :             length_bin = 6;
     957           0 :             move16();
     958           0 :             IF( last_coder_type != AUDIO )
     959             :             {
     960           0 :                 set16_fx( last_bitallocation_band, 0, 6 );
     961           0 :                 Copy( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 );
     962             :             }
     963             : 
     964           0 :             FOR( i = 4; i < ( 4 + length_bin ); i++ )
     965             :             {
     966           0 :                 test();
     967           0 :                 IF( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) )
     968             :                 {
     969           0 :                     k = shl( add( i, length_bin ), 4 );
     970           0 :                     src = &exc_dct_in[k]; /*(i+length_bin)*16*/
     971           0 :                     dst = &last_exc_dct_in[k];
     972           0 :                     FOR( j = 0; j < 16; j++ )
     973             :                     {
     974           0 :                         tmp = mult_r( 10923, abs_s( *src ) );
     975           0 :                         tmp1 = mult_r( 10923, abs_s( *dst ) );
     976             : 
     977           0 :                         IF( GT_16( tmp, abs_s( *dst ) ) )
     978             :                         {
     979           0 :                             tmp2 = *src;
     980           0 :                             *src = mult_r( 16384, sub_o( *src, abs_s( *dst ), &Overflow ) ); /*Q_exc */
     981           0 :                             move16();
     982           0 :                             tmp = mult_r( 16384, add_o( tmp2, abs_s( *dst ), &Overflow ) ); /*Q_exc */
     983           0 :                             if ( tmp2 > 0 )
     984             :                             {
     985           0 :                                 *src = tmp;
     986           0 :                                 move16();
     987             :                             }
     988             :                         }
     989           0 :                         ELSE IF( GT_16( tmp1, abs_s( *src ) ) )
     990             :                         {
     991           0 :                             tmp = mult_r( *src, 22938 );
     992           0 :                             tmp1 = mult_r( 9830, abs_s( *dst ) );
     993           0 :                             tmp2 = *src;
     994           0 :                             *src = sub( tmp, tmp1 ); /*Q_exc */
     995           0 :                             move16();
     996           0 :                             if ( tmp2 > 0 )
     997             :                             {
     998           0 :                                 *src = add( tmp, tmp1 ); /*Q_exc */
     999           0 :                                 move16();
    1000             :                             }
    1001             :                         }
    1002           0 :                         src++;
    1003           0 :                         dst++;
    1004             :                     }
    1005             :                 }
    1006             :             }
    1007             :         }
    1008           0 :         IF( EQ_16( bwe_flag, 1 ) )
    1009             :         {
    1010           0 :             Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 );
    1011             :         }
    1012             :         ELSE
    1013             :         {
    1014           0 :             Decreas_freqPeak_fx( lsf_new, exc_dct_in, 16384 );
    1015             :         }
    1016             :     }
    1017             : 
    1018           7 :     Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 );
    1019           7 :     Copy( &bitallocation_band[4], last_bitallocation_band, 6 );
    1020           7 :     *last_ener = ener;
    1021           7 :     move16();
    1022             : 
    1023           7 :     return;
    1024             : }
    1025             : 
    1026       43458 : void highband_exc_dct_in_ivas_fx(
    1027             :     const Word32 core_brate,         /* i  : core bitrate                            */
    1028             :     const Word16 *mfreq_bindiv,      /* i  : bin per bands tables                    */
    1029             :     Word16 last_bin,                 /* i  : last bin of bit allocation              */
    1030             :     Word16 Diff_len,                 /* i  : number of bin before cut-off frequency  */
    1031             :     Word16 noise_lev,                /* i  : pulses dynamic                          */
    1032             :     Word16 pit_band_idx,             /* i  : bin position of the cut-off frequency   */
    1033             :     Word16 *exc_diffQ,               /* i  : frequency coefficients of per band      */
    1034             :     Word16 *seed_tcx,                /* i  : Seed for noise                          */
    1035             :     Word16 *Ener_per_bd_iQ,          /* i  : Quantized energy of targeted vector     */
    1036             :     Word16 nb_subfr,                 /* i  : Number of subframe considered           */
    1037             :     Word16 *exc_dct_in,              /* o  : dct of residual signal                  */
    1038             :     Word16 last_coder_type,          /* i  : coding type of last frame               */
    1039             :     Word16 *bitallocation_band,      /* i  : bit allocation flag of each band        */
    1040             :     const Word16 *lsf_new,           /* i  : LSFs at the end of the frame            */
    1041             :     Word16 *last_exc_dct_in,         /* i  : dct of residual signal of last frame    */
    1042             :     Word16 *last_ener,               /* i  : frequency energy  of last frame         */
    1043             :     Word16 *last_bitallocation_band, /* i  : bit allocation flag of each band  of last frame   */
    1044             :     Word16 *bitallocation_exc,       /* i  : flag of decoded coefficients            */
    1045             :     Word16 bfi,                      /* i  : bad frame indicator                     */
    1046             :     const Word16 coder_type,         /* i  : coder type                              */
    1047             :     Word16 bwidth,
    1048             :     Word16 *exc_wo_nf, /* o  : temporal excitation (in f domain) without noisefill   */
    1049             :     Word16 Qexc_diffQ,
    1050             :     Word16 *Q_exc,
    1051             :     const Word16 GSC_noisy_speech,
    1052             :     Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy                 */
    1053             :     const Word16 L_frame,        /* i  : frame length                            */
    1054             :     const Word16 element_mode,   /* i  : IVAS element mode                       */
    1055             :     const Word16 GSC_IVAS_mode   /* i  : GSC IVAS mode                           */
    1056             : )
    1057             : {
    1058             :     Word16 i, j, k;
    1059       43458 :     Word16 MAX_Bin = 0;
    1060       43458 :     Word16 last_bin_tmp, ener = 0;
    1061       43458 :     move16();
    1062             :     Word16 noisepb[MBANDS_GN16k];
    1063             :     Word16 Ener_per_bd_yQ[MBANDS_GN16k];
    1064             :     Word16 *src, *dst;
    1065             :     Word32 L_tmp;
    1066       43458 :     Word16 length_bin, bwe_flag = 0, tmp;
    1067       43458 :     move16();
    1068             :     Word16 frac, exp, tmp1;
    1069             :     Word16 tmp2;
    1070             :     Word16 *end, Q_hb_exc;
    1071             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
    1072       43458 :     Flag Overflow = 0;
    1073       43458 :     move16();
    1074             : #endif
    1075             : 
    1076      304206 :     FOR( j = 10; j < MBANDS_GN; j++ )
    1077             :     {
    1078             :         /*  ener += (float)pow(10, Ener_per_bd_iQ[j]);
    1079             :             ener += (float)pow(2, 3.321928*Ener_per_bd_iQ[j]); */
    1080             : 
    1081      260748 :         L_tmp = L_mult( Ener_per_bd_iQ[j], 27213 ); /* 3.321928 in Q13 -> Q27 */
    1082      260748 :         L_tmp = L_shr( L_tmp, 10 );                 /* From Q27 to Q16 */
    1083             : 
    1084      260748 :         frac = L_Extract_lc( L_tmp, &exp );  /* Extract exponent of L_tmp */
    1085      260748 :         tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
    1086             :         /* output of Pow2() will be: */
    1087             :         /* 16384 < Pow2() <= 32767 */
    1088      260748 :         exp = sub( exp, 14 );
    1089      260748 :         tmp1 = shl_o( tmp, exp, &Overflow );
    1090      260748 :         move16();
    1091      260748 :         ener = add_o( tmp1, ener, &Overflow ); /*Q0 */
    1092             :     }
    1093             : 
    1094       43458 :     test();
    1095       43458 :     IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
    1096             :     {
    1097          61 :         IF( NE_16( last_coder_type, AUDIO ) )
    1098             :         {
    1099          32 :             *last_ener = ener;
    1100          32 :             move16();
    1101             :         }
    1102          61 :         test();
    1103          61 :         test();
    1104          61 :         IF( ( GT_16( last_bin, 8 ) || Diff_len != 0 ) && EQ_16( last_coder_type, AUDIO ) )
    1105             :         {
    1106          29 :             MAX_Bin = 10;
    1107          29 :             move16();
    1108          29 :             bwe_flag = 1;
    1109          29 :             move16();
    1110             :         }
    1111             :         ELSE
    1112             :         {
    1113          32 :             MAX_Bin = 15;
    1114          32 :             move16();
    1115             :         }
    1116             : 
    1117          61 :         last_bin_tmp = last_bin;
    1118          61 :         move16();
    1119          61 :         last_bin = s_max( last_bin, MAX_Bin );
    1120          61 :         last_bin = add( last_bin, 1 );
    1121             :     }
    1122             :     ELSE
    1123             :     {
    1124       43397 :         IF( EQ_16( L_frame, L_FRAME16k ) )
    1125             :         {
    1126        5179 :             last_bin = MBANDS_GN16k;
    1127        5179 :             move16();
    1128             :         }
    1129             :         ELSE
    1130             :         {
    1131       38218 :             last_bin = MBANDS_GN;
    1132       38218 :             move16();
    1133             :         }
    1134       43397 :         last_bin_tmp = last_bin;
    1135       43397 :         move16();
    1136             :     }
    1137             : 
    1138       43458 :     test();
    1139       43458 :     test();
    1140       43458 :     test();
    1141       43458 :     test();
    1142       43458 :     IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) )
    1143             :     {
    1144       14339 :         set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */
    1145             :     }
    1146       29119 :     ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) )
    1147             :     {
    1148        5294 :         set16_fx( noisepb, 13107 /*0.4f*/, MBANDS_GN16k );
    1149             :     }
    1150             :     ELSE
    1151             :     {
    1152       23825 :         EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame );
    1153             :     }
    1154             : 
    1155       43458 :     IF( exc_wo_nf != NULL )
    1156             :     {
    1157       43256 :         Copy( exc_diffQ, exc_wo_nf, L_frame );
    1158             :     }
    1159             : 
    1160       43458 :     test();
    1161       43458 :     test();
    1162             : 
    1163       43458 :     IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) )
    1164             :     {
    1165       15099 :         set16_fx( noisepb, 3277, MBANDS_GN );
    1166             :     }
    1167             : 
    1168       43458 :     test();
    1169       43458 :     IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) )
    1170             :     {
    1171     3634751 :         FOR( i = 0; i < L_frame; i++ )
    1172             :         {
    1173     3620608 :             IF( exc_diffQ[i] == 0 )
    1174             :             {
    1175             :                 /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
    1176     3603661 :                 tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
    1177     3603661 :                 tmp = shr( tmp, sub( 15, Qexc_diffQ ) );                /*qNoise_fac */
    1178     3603661 :                 exc_diffQ[i] = add( exc_diffQ[i], tmp );
    1179     3603661 :                 move16(); /*Q */
    1180             :             }
    1181             :         }
    1182             :     }
    1183             :     ELSE
    1184             :     {
    1185       29315 :         Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ );
    1186             :     }
    1187             :     /*--------------------------------------------------------------------------------------*
    1188             :      * Quantize average gain
    1189             :      * Subtract Q averaged gain
    1190             :      * VQ of remaining gain per band
    1191             :      *--------------------------------------------------------------------------------------*/
    1192       43458 :     test();
    1193       43458 :     IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
    1194             :     {
    1195          61 :         Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame );
    1196             :     }
    1197             :     ELSE
    1198             :     {
    1199       43397 :         Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame );
    1200             : 
    1201       43397 :         test();
    1202       43397 :         IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) )
    1203             :         {
    1204      536180 :             FOR( i = L_FRAME - 16; i < L_FRAME; i++ )
    1205             :             {
    1206             :                 /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */
    1207      504640 :                 tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) );  /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */
    1208      504640 :                 L_tmp = L_mult( exc_diffQ[i], tmp );                /*Q(Qexc_diffQ+10) */
    1209      504640 :                 exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */
    1210      504640 :                 move16();
    1211             :             }
    1212             :         }
    1213             :     }
    1214             :     /*--------------------------------------------------------------------------------------*
    1215             :      * Check potential energy excitation overshoot
    1216             :      *--------------------------------------------------------------------------------------*/
    1217       43458 :     IF( bfi )
    1218             :     {
    1219         202 :         test();
    1220         202 :         IF( GSC_noisy_speech == 0 && GT_16( coder_type, UNVOICED ) ) /* Here coder_type == last_coder_type because of the bfi */
    1221             :         {
    1222        1394 :             FOR( i = 0; i < last_bin; i++ )
    1223             :             {
    1224        1312 :                 Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub_sat( sub_sat( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) );
    1225        1312 :                 move16();
    1226        1312 :                 lt_ener_per_band_fx[i] = sub_sat( lt_ener_per_band_fx[i], 77 );
    1227        1312 :                 move16();
    1228             :             }
    1229          82 :             FOR( ; i < MBANDS_GN; i++ )
    1230             :             {
    1231           0 :                 Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( lt_ener_per_band_fx[i], 154 ) );
    1232           0 :                 move16();
    1233           0 :                 lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
    1234           0 :                 move16();
    1235             :             }
    1236             :         }
    1237             :         ELSE
    1238             :         {
    1239        2048 :             FOR( i = 0; i < last_bin; i++ )
    1240             :             {
    1241        1928 :                 Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub_sat( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) );
    1242        1928 :                 move16();
    1243        1928 :                 lt_ener_per_band_fx[i] = sub_sat( lt_ener_per_band_fx[i], 77 );
    1244        1928 :                 move16();
    1245             :             }
    1246         120 :             FOR( ; i < MBANDS_GN; i++ )
    1247             :             {
    1248           0 :                 Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], add( lt_ener_per_band_fx[i], 1229 ) );
    1249           0 :                 move16();
    1250           0 :                 lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
    1251           0 :                 move16();
    1252             :             }
    1253             :         }
    1254             :     }
    1255             : 
    1256             :     /*--------------------------------------------------------------------------------------*
    1257             :      * Apply decoded gain onto the difference signal
    1258             :      *--------------------------------------------------------------------------------------*/
    1259             : 
    1260       43458 :     IF( GSC_IVAS_mode >= 1 )
    1261             :     {
    1262        9060 :         Word16 scale_factLF = 29491; /* 0.9f */
    1263        9060 :         move16();
    1264        9060 :         Word16 scale_factHF = 29491; /* 0.9f */
    1265        9060 :         move16();
    1266             : 
    1267        9060 :         test();
    1268        9060 :         test();
    1269        9060 :         IF( EQ_16( GSC_IVAS_mode, 1 ) && GSC_noisy_speech == 0 )
    1270             :         {
    1271        3309 :             scale_factHF = 26214;
    1272        3309 :             move16();
    1273             :         }
    1274        5751 :         ELSE IF( EQ_16( GSC_IVAS_mode, 2 ) || EQ_16( GSC_noisy_speech, 1 ) )
    1275             :         {
    1276         668 :             scale_factHF = 23265; /* 0.71f */
    1277         668 :             move16();
    1278             :         }
    1279        5083 :         ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) )
    1280             :         {
    1281        5083 :             scale_factHF = 29491; /* 0.9f */
    1282        5083 :             move16();
    1283             :         }
    1284     1258052 :         FOR( i = 0; i < pit_band_idx * 16; i++ )
    1285             :         {
    1286     1248992 :             exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factLF );
    1287             :         }
    1288     1079428 :         FOR( ; i < L_frame; i++ )
    1289             :         {
    1290     1070368 :             exc_diffQ[i] = mult_r( exc_diffQ[i], scale_factHF );
    1291     1070368 :             move16();
    1292             :         }
    1293             :     }
    1294       34398 :     ELSE IF( GSC_noisy_speech )
    1295             :     {
    1296       15769 :         Word16 scale_fact = 29491; /* 0.9f */
    1297       15769 :         move16();
    1298             : 
    1299       15769 :         IF( EQ_16( element_mode, IVAS_CPE_TD ) )
    1300             :         {
    1301          46 :             IF( coder_type == INACTIVE )
    1302             :             {
    1303           0 :                 scale_fact = 32767; /* 1.0f */
    1304           0 :                 move16();
    1305             :             }
    1306             :             ELSE
    1307             :             {
    1308          46 :                 scale_fact = 31129; /* 0.95f */
    1309          46 :                 move16();
    1310             :             }
    1311             :         }
    1312       15723 :         ELSE IF( GT_16( element_mode, IVAS_SCE ) )
    1313             :         {
    1314         578 :             scale_fact = 23265; /* 0.71f */
    1315         578 :             move16();
    1316             :         }
    1317             : 
    1318     4052633 :         FOR( i = 0; i < L_frame; i++ )
    1319             :         {
    1320     4036864 :             exc_diffQ[i] = mult_r( exc_diffQ[i], scale_fact );
    1321     4036864 :             move16();
    1322             :         }
    1323             :     }
    1324             : 
    1325       43458 :     IF( GSC_noisy_speech && GT_16( element_mode, IVAS_SCE ) && LT_32( core_brate, ACELP_7k20 ) )
    1326             :     {
    1327        7788 :         FOR( i = 80; i < L_frame; i++ )
    1328             :         {
    1329             :             /* exc_diffQ[i] *= (+0.0024f * (float)i + 1.192f); */
    1330        7744 :             exc_diffQ[i] = mult_r( shl( exc_diffQ[i], 1 ) /*Q16*/, (Word16) L_shr( L_add( 629 * i, 312475 ) /*Q18*/, Q4 ) /*Q14*/ );
    1331        7744 :             move16();
    1332             :         }
    1333             :     }
    1334             : 
    1335             : 
    1336             : #ifdef REMOVE_EVS_DUPLICATES
    1337       43458 :     IF( EQ_16( element_mode, EVS_MONO ) )
    1338             :     {
    1339           6 :         Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc );
    1340             : 
    1341           6 :         IF( exc_wo_nf != NULL )
    1342             :         {
    1343           6 :             Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc );
    1344           6 :             Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
    1345             :         }
    1346             :     }
    1347             :     ELSE
    1348             :     {
    1349             : #endif
    1350       43452 :         Word16 Q_tmp = *Q_exc;
    1351       43452 :         move16();
    1352       43452 :         Word16 Q_old = *Q_exc;
    1353       43452 :         move16();
    1354       43452 :         Comp_and_apply_gain_ivas_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc );
    1355             : 
    1356       43452 :         IF( exc_wo_nf != NULL )
    1357             :         {
    1358       43250 :             Comp_and_apply_gain_ivas_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, &Q_tmp );
    1359       43250 :             IF( GT_16( Q_tmp, *Q_exc ) )
    1360             :             {
    1361           0 :                 Scale_sig( exc_wo_nf, L_frame, sub( *Q_exc, Q_tmp ) );
    1362             :             }
    1363       43250 :             ELSE IF( LT_16( Q_tmp, *Q_exc ) )
    1364             :             {
    1365           3 :                 Scale_sig( exc_diffQ, L_frame, sub( Q_tmp, *Q_exc ) );
    1366           3 :                 *Q_exc = Q_tmp;
    1367           3 :                 move16();
    1368             :             }
    1369       43250 :             Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) );
    1370       43250 :             Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
    1371             :         }
    1372             :         ELSE
    1373             :         {
    1374         202 :             Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) );
    1375             :         }
    1376             : #ifdef REMOVE_EVS_DUPLICATES
    1377             :     }
    1378             : #endif
    1379             : 
    1380             :     /*--------------------------------------------------------------------------------------*
    1381             :      * add the correction layer to the LF bins,
    1382             :      * and add the quantized pulses or the noise for the higher part of the spectrum
    1383             :      * (non valuable temporal content already zeroed)
    1384             :      * DC is Zeroed
    1385             :      *--------------------------------------------------------------------------------------*/
    1386             : 
    1387       43458 :     Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame );
    1388       43458 :     test();
    1389       43458 :     IF( EQ_32( core_brate, ACELP_8k00 ) && bwidth != NB )
    1390             :     {
    1391          61 :         IF( EQ_16( bwe_flag, 1 ) )
    1392             :         {
    1393          29 :             last_bin = sub( last_bin, 1 );
    1394          29 :             tmp = i_mult( MAX_Bin, 16 );
    1395          29 :             tmp1 = i_mult( last_bin, 16 );
    1396          29 :             src = &exc_diffQ[( L_FRAME - 1 )];
    1397          29 :             move16();
    1398          29 :             dst = &exc_dct_in[( tmp - 1 )];
    1399          29 :             move16();
    1400          29 :             end = &exc_diffQ[( tmp1 - 1 )];
    1401          29 :             move16();
    1402             : 
    1403        2813 :             WHILE( src > end )
    1404             :             {
    1405        2784 :                 *src-- = *dst--;
    1406        2784 :                 move16();
    1407             :             }
    1408          29 :             test();
    1409          29 :             test();
    1410          29 :             IF( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && EQ_32( core_brate, ACELP_8k00 ) )
    1411             :             {
    1412           4 :                 exc_diffQ[160] = 0;
    1413           4 :                 move16();
    1414             :             }
    1415             : 
    1416          29 :             Q_hb_exc = 0;
    1417          29 :             move16();
    1418          29 :             envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, *Q_exc, &Q_hb_exc );
    1419             : #ifdef REMOVE_EVS_DUPLICATES
    1420          29 :             test();
    1421          29 :             IF( GT_16( *Q_exc, Q_hb_exc ) && GT_16( element_mode, EVS_MONO ) )
    1422             : #else
    1423             :             IF( GT_16( *Q_exc, Q_hb_exc ) )
    1424             : #endif
    1425             :             {
    1426           0 :                 Scale_sig( exc_wo_nf, L_frame, sub( Q_hb_exc, *Q_exc ) );
    1427           0 :                 *Q_exc = Q_hb_exc;
    1428           0 :                 move16();
    1429             :             }
    1430             :             ELSE
    1431             :             {
    1432          29 :                 Scale_sig( &exc_diffQ[tmp1], sub( L_FRAME, tmp1 ), sub( *Q_exc, Q_hb_exc ) );
    1433             :             }
    1434          29 :             Copy( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ) ); /* from Q_hb_exc -> Q_exc as expected */
    1435             :         }
    1436             : 
    1437          61 :         IF( LT_16( nb_subfr, 4 ) )
    1438             :         {
    1439         272 :             FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ )
    1440             :             {
    1441             :                 /*exc_dct_in[i] *= (0.067f*i-15.f); */
    1442         256 :                 tmp = mult_r( 17564, shl( i, 6 ) );                                      /*0.067 in Q18 and i in Q6= Q9 */
    1443         256 :                 tmp = sub( tmp, 7680 );                                                  /*15 in Q9 = Q9 */
    1444         256 :                 L_tmp = L_mult( exc_dct_in[i], tmp );                                    /*Q(Q_exc+10) */
    1445         256 :                 exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */
    1446             :             }
    1447             :         }
    1448             : 
    1449          61 :         tmp1 = mult_r( ener, 16384 );
    1450          61 :         tmp1 = sub( *last_ener, tmp1 );
    1451          61 :         tmp = mult_r( *last_ener, 16384 );
    1452          61 :         tmp = sub( ener, tmp );
    1453          61 :         test();
    1454          61 :         IF( tmp > 0 && tmp1 > 0 )
    1455             :         {
    1456          60 :             length_bin = 6;
    1457          60 :             move16();
    1458          60 :             IF( last_coder_type != AUDIO )
    1459             :             {
    1460          32 :                 set16_fx( last_bitallocation_band, 0, 6 );
    1461          32 :                 Copy( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 );
    1462             :             }
    1463             : 
    1464         420 :             FOR( i = 4; i < ( 4 + length_bin ); i++ )
    1465             :             {
    1466         360 :                 test();
    1467         360 :                 IF( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) )
    1468             :                 {
    1469         295 :                     k = shl( add( i, length_bin ), 4 );
    1470         295 :                     src = &exc_dct_in[k]; /*(i+length_bin)*16*/
    1471         295 :                     dst = &last_exc_dct_in[k];
    1472        5015 :                     FOR( j = 0; j < 16; j++ )
    1473             :                     {
    1474        4720 :                         tmp = mult_r( 10923, abs_s( *src ) );
    1475        4720 :                         tmp1 = mult_r( 10923, abs_s( *dst ) );
    1476             : 
    1477        4720 :                         IF( GT_16( tmp, abs_s( *dst ) ) )
    1478             :                         {
    1479         400 :                             tmp2 = *src;
    1480         400 :                             *src = mult_r( 16384, sub_o( *src, abs_s( *dst ), &Overflow ) ); /*Q_exc */
    1481         400 :                             move16();
    1482         400 :                             tmp = mult_r( 16384, add_o( tmp2, abs_s( *dst ), &Overflow ) ); /*Q_exc */
    1483         400 :                             IF( tmp2 > 0 )
    1484             :                             {
    1485         222 :                                 *src = tmp;
    1486         222 :                                 move16();
    1487             :                             }
    1488             :                         }
    1489        4320 :                         ELSE IF( GT_16( tmp1, abs_s( *src ) ) )
    1490             :                         {
    1491         543 :                             tmp = mult_r( *src, 22938 );
    1492         543 :                             tmp1 = mult_r( 9830, abs_s( *dst ) );
    1493         543 :                             tmp2 = *src;
    1494         543 :                             *src = sub( tmp, tmp1 ); /*Q_exc */
    1495         543 :                             move16();
    1496         543 :                             IF( tmp2 > 0 )
    1497             :                             {
    1498         281 :                                 *src = add( tmp, tmp1 ); /*Q_exc */
    1499         281 :                                 move16();
    1500             :                             }
    1501             :                         }
    1502        4720 :                         src++;
    1503        4720 :                         dst++;
    1504             :                     }
    1505             :                 }
    1506             :             }
    1507             :         }
    1508          61 :         IF( EQ_16( bwe_flag, 1 ) )
    1509             :         {
    1510          29 :             Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 );
    1511             :         }
    1512             :         ELSE
    1513             :         {
    1514          32 :             Decreas_freqPeak_fx( lsf_new, exc_dct_in, 16384 );
    1515             :         }
    1516             :     }
    1517             : 
    1518       43458 :     Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 );
    1519       43458 :     Copy( &bitallocation_band[4], last_bitallocation_band, 6 );
    1520       43458 :     *last_ener = ener;
    1521       43458 :     move16();
    1522             : 
    1523       43458 :     return;
    1524             : }

Generated by: LCOV version 1.14