LCOV - code coverage report
Current view: top level - lib_com - gs_inact_switching_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 70 70 100.0 %
Date: 2025-05-19 02:27:35 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include "options.h" /* Compilation switches                   */
       6             : #include "cnst.h"    /* Common constants                       */
       7             : #include "rom_com.h" /* Static table prototypes                */
       8             : #include "prot_fx.h" /* Function prototypes                    */
       9             : #include "stl.h"
      10             : 
      11             : /*-------------------------------------------------------------------*
      12             :  * Local constants
      13             :  *-------------------------------------------------------------------*/
      14             : 
      15             : #define ALPHA0_FX 13107                 /*Q15*/
      16             : #define BETA0_FX  ( 32768 - ALPHA0_FX ) /*Q15*/
      17             : 
      18             : /*========================================================================*/
      19             : /* FUNCTION : Inac_swtch_ematch_fx()                                                                      */
      20             : /*------------------------------------------------------------------------*/
      21             : /* PURPOSE : Apply energy matching when swithcing to INACTIVE frame coded */
      22             : /*                       by the GSC technology                                                                            */
      23             : /*------------------------------------------------------------------------*/
      24             : /* INPUT ARGUMENTS :                                                                                                      */
      25             : /* _ (Word16) coder_type  : Coding mode                                                                   */
      26             : /* _ (Word16) L_frame     : Frame lenght                                                          */
      27             : /* _ (Word32) core_brate  : core bitrate                                                          */
      28             : /*------------------------------------------------------------------------*/
      29             : /* INPUT/OUTPUT ARGUMENTS :                                                                                               */
      30             : /* _ (Word16[]) exc2             : CELP/GSC excitation buffer     Q_exc   */
      31             : /* _ (Word16[]) lt_ener_per_band : Long term energy per band      Q12     */
      32             : /* _ (Word16*) Q_exc             : input and output format of exc2        */
      33             : /*------------------------------------------------------------------------*/
      34             : /* OUTPUT ARGUMENTS :                                                                                                     */
      35             : /*------------------------------------------------------------------------*/
      36             : /*------------------------------------------------------------------------*/
      37             : /* RETURN ARGUMENTS :                                                                                                     */
      38             : /* _ None                                                                                                                                 */
      39             : /*========================================================================*/
      40             : 
      41      143065 : void Inac_switch_ematch_fx(
      42             :     Word16 exc2[],                         /* i/o: CELP/GSC excitation buffer       Q_exc*/
      43             :     Word16 dct_exc_tmp[],                  /* i  : GSC excitation in DCT domain          */
      44             :     Word16 lt_ener_per_band[],             /* i/o: Long term energy per band        Q12  */
      45             :     const Word16 coder_type,               /* i  : Coding mode                           */
      46             :     const Word16 inactive_coder_type_flag, /* i  : AVQ (0) or GSC (1) IC flag            */
      47             :     const Word16 L_frame,                  /* i  : Frame lenght                          */
      48             :     const Word16 Q_exc,                    /* i  : input and output format of exc2       */
      49             :     const Word16 bfi,                      /* i  : frame lost indicator                  */
      50             :     const Word16 last_core,                /* i  : Last core used                        */
      51             :     const Word16 last_codec_mode,          /* i  : Last codec mode                       */
      52             :     const Word16 tdm_low_rate_mode,        /* i  : secondary channel low rate mode flag  */
      53             :     const Word16 element_mode              /* i  : element mode                          */
      54             : )
      55             : {
      56             :     Word16 Ener_per_bd[MBANDS_GN16k];
      57             :     Word16 ftmp;
      58             :     Word16 *pt_exc;
      59             :     Word16 j, i;
      60             : 
      61             :     Word16 exp, frac;
      62             :     Word32 L_tmp;
      63             : 
      64             :     /*--------------------------------------------------------------------------
      65             :      * average energy per band
      66             :      *--------------------------------------------------------------------------*/
      67             : 
      68      143065 :     test();
      69      143065 :     test();
      70      143065 :     test();
      71      143065 :     test();
      72      143065 :     test();
      73      143065 :     test();
      74      143065 :     test();
      75      143065 :     test();
      76      143065 :     test();
      77      143065 :     test();
      78      143065 :     IF( ( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) ) ) && bfi == 0 )
      79             :     {
      80        9800 :         Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
      81             : 
      82             :         /* reset long-term energy per band */
      83      166600 :         FOR( i = 0; i < MBANDS_GN; i++ )
      84             :         {
      85      156800 :             lt_ener_per_band[i] = Ener_per_bd[i]; /*Q12*/
      86      156800 :             move16();
      87             :         }
      88             :     }
      89      133265 :     ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || ( last_core != ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) || ( ( element_mode > EVS_MONO ) && EQ_16( coder_type, UNVOICED ) ) )
      90             :     {
      91             :         /* Find spectrum and energy per band for GC and VC frames */
      92      120957 :         edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode );
      93             : 
      94      120957 :         Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
      95             : 
      96             :         /* reset long-term energy per band */
      97     2056269 :         FOR( i = 0; i < MBANDS_GN; i++ )
      98             :         {
      99     1935312 :             lt_ener_per_band[i] = Ener_per_bd[i]; /*Q12*/
     100     1935312 :             move16();
     101             :         }
     102             :     }
     103       12308 :     ELSE IF( ( coder_type == INACTIVE ) && inactive_coder_type_flag )
     104             :     {
     105             :         /* Find spectrum and energy per band for inactive frames */
     106       10482 :         edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode );
     107       10482 :         Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
     108             : 
     109             :         /* More agressive smoothing in the first 50 frames */
     110       10482 :         pt_exc = dct_exc_tmp;
     111       10482 :         move16();
     112      178194 :         FOR( i = 0; i < MBANDS_GN; i++ )
     113             :         {
     114             :             /* Compute smoothing gain to apply with gain limitation */
     115      167712 :             L_tmp = L_mult( ALPHA0_FX, lt_ener_per_band[i] ); /*Q(15+12+1)=Q(28) */
     116      167712 :             L_tmp = L_mac( L_tmp, BETA0_FX, Ener_per_bd[i] ); /*Q28 */
     117      167712 :             lt_ener_per_band[i] = round_fx( L_tmp );          /*Q12 */
     118      167712 :             move16();
     119             : 
     120      167712 :             ftmp = sub( lt_ener_per_band[i], Ener_per_bd[i] ); /*Q12 */
     121             : 
     122             :             /* ftmp = (float)pow(10, ftmp);= pow(2,3.321928*ftmp);*/
     123             : 
     124      167712 :             L_tmp = L_mult( 27213, ftmp );        /*Q(13+12+1)=Q26 ; 27213=3.321928 in Q13 */
     125      167712 :             L_tmp = L_shr( L_tmp, 10 );           /* From Q26 to Q16 */
     126      167712 :             frac = L_Extract_lc( L_tmp, &exp );   /* Extract exponent of ftmp */
     127      167712 :             ftmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
     128             :             /* output of Pow2() will be: */
     129             :             /* 16384 < Pow2() <= 32767 */
     130             : 
     131      167712 :             exp = sub( exp, 14 );
     132      167712 :             IF( LT_16( i, 2 ) )
     133             :             {
     134       20964 :                 IF( EQ_16( element_mode, EVS_MONO ) )
     135             :                 {
     136         108 :                     FOR( j = 0; j < 8; j++ )
     137             :                     {
     138          96 :                         L_tmp = L_mult( *pt_exc, ftmp );
     139          96 :                         L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc) -> Q(15+Q_exc)*/
     140          96 :                         *pt_exc = round_fx_sat( L_tmp );            /*Q_exc - 1*/
     141          96 :                         move16();
     142          96 :                         pt_exc++;
     143             :                     }
     144             :                 }
     145             :                 ELSE
     146             :                 {
     147      188568 :                     FOR( j = 0; j < 8; j++ )
     148             :                     {
     149      167616 :                         L_tmp = L_mult0( *pt_exc, ftmp );
     150      167616 :                         L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc) -> Q(15+Q_exc)*/
     151      167616 :                         *pt_exc = round_fx_sat( L_tmp );            /*Q_exc - 1*/
     152      167616 :                         move16();
     153      167616 :                         pt_exc++;
     154             :                     }
     155             :                 }
     156             :             }
     157             :             ELSE
     158             :             {
     159      146748 :                 IF( EQ_16( element_mode, EVS_MONO ) )
     160             :                 {
     161        1428 :                     FOR( j = 0; j < 16; j++ )
     162             :                     {
     163        1344 :                         L_tmp = L_mult( *pt_exc, ftmp );
     164        1344 :                         L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc) -> Q(15+Q_exc)*/
     165        1344 :                         *pt_exc = round_fx_sat( L_tmp );            /*Q_exc - 1*/
     166        1344 :                         move16();
     167        1344 :                         pt_exc++;
     168             :                     }
     169             :                 }
     170             :                 ELSE
     171             :                 {
     172     2493288 :                     FOR( j = 0; j < 16; j++ )
     173             :                     {
     174     2346624 :                         L_tmp = L_mult0( *pt_exc, ftmp );
     175     2346624 :                         L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc) -> Q(15+Q_exc)*/
     176     2346624 :                         *pt_exc = round_fx_sat( L_tmp );            /*Q_exc - 1*/
     177     2346624 :                         move16();
     178     2346624 :                         pt_exc++;
     179             :                     }
     180             :                 }
     181             :             }
     182             :         }
     183             : 
     184             :         /* Going back to time */
     185       10482 :         IF( GT_16( element_mode, EVS_MONO ) )
     186             :         {
     187       10476 :             Scale_sig( dct_exc_tmp, 240, 1 ); // Q_exc
     188       10476 :             Scale_sig( exc2, 240, 1 );        // Q_exc
     189             :         }
     190       10482 :         edct_16fx( dct_exc_tmp, exc2, L_frame, 5, element_mode );
     191             :     }
     192             : 
     193      143065 :     return;
     194             : }

Generated by: LCOV version 1.14