LCOV - code coverage report
Current view: top level - lib_enc - stat_noise_uv_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ e95243e9e67ddeb69dddf129509de1b3d95b402e Lines: 35 54 64.8 %
Date: 2025-09-14 03:13:15 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include "options.h"
       7             : #include "cnst.h"
       8             : //#include "prot_fx.h"     /* Function prototypes                    */
       9             : #include "rom_com_fx.h"  /* Static table prototypes                */
      10             : #include "rom_com.h"     /* Static table prototypes                */
      11             : #include "prot_fx.h"     /* Function prototypes                    */
      12             : #include "prot_fx_enc.h" /* Function prototypes                    */
      13             : 
      14             : 
      15             : /*======================================================================*/
      16             : /* FUNCTION : stat_noise_uv_enc_fx                                      */
      17             : /*----------------------------------------------------------------------*/
      18             : /* PURPOSE :   Modifies excitation signal in UC mode                    */
      19             : /*         when the noise is stationary                                 */
      20             : /*----------------------------------------------------------------------*/
      21             : /*  INPUT ARGUMENTS :                                                   */
      22             : /* _ (Encoder_State) st_fx :  Encoder state Structure                */
      23             : /* _ (Word16*) epsP           : LP prediction errors                    */
      24             : /* _ (Word16*) isp_new        : immittance spectral pairs at 4th sfr Q15 */
      25             : /* _ (Word16*) isp_mid        : immittance spectral pairs at 2nd sfr Q15 */
      26             : /* _ (Word16*) Aq             :  A(z) quantized for the 4 subframes  Q12 */
      27             : /* _ (Word16 ) uc_two_stage_flag  flag undicating two-stage UC           */
      28             : /*-----------------------------------------------------------------------*/
      29             : /* INPUT/OUTPUT ARGUMENTS :                                              */
      30             : /* _ (Word16*) exc2             :  excitation buffer        Q_exc        */
      31             : /*-----------------------------------------------------------------------*/
      32             : /* OUTPUT ARGUMENTS :                                                    */
      33             : /*-----------------------------------------------------------------------*/
      34             : 
      35             : /* _ None                                                                */
      36             : /*-----------------------------------------------------------------------*/
      37             : /* RETURN ARGUMENTS :                                                    */
      38             : /* _ None                                                                */
      39             : /*=======================================================================*/
      40        1423 : void stat_noise_uv_enc_fx(
      41             :     Encoder_State *st_fx,           /* i/o: state structure                      */
      42             :     const Word32 *LepsP,            /* i  : LP prediction errors                 */
      43             :     const Word16 *isp_new,          /* i  : immittance spectral pairs at 4th sfr */
      44             :     const Word16 *isp_mid,          /* i  : immittance spectral pairs at 2nd sfr */
      45             :     Word16 *Aq,                     /* i  : A(z) quantized for the 4 subframes   */
      46             :     Word16 *exc2,                   /* i/o: excitation buffer                    */
      47             :     const Word16 uc_two_stage_flag, /* o  : flag undicating two-stage UC         */
      48             :     Word16 Q_new )
      49             : {
      50        1423 :     Word16 noisiness = 0;
      51        1423 :     move16();
      52             :     Word16 num, den, expn, expd;
      53             : #ifndef ISSUE_1867_replace_overflow_libenc
      54             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      55             :     Flag Overflow = 0;
      56             :     move16();
      57             : #endif
      58             : #endif
      59        1423 :     test();
      60        1423 :     test();
      61        1423 :     test();
      62        1423 :     IF( ( EQ_16( st_fx->coder_type, UNVOICED ) && uc_two_stage_flag == 0 ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) )
      63             :     {
      64             : 
      65             :         /*-----------------------------------------------------------------*
      66             :          * Calculate and write the noisiness parameter
      67             :          *-----------------------------------------------------------------*/
      68             :         /* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */
      69           0 :         expn = sub( norm_l( LepsP[0] ), 1 );
      70             : #ifdef ISSUE_1867_replace_overflow_libenc
      71           0 :         num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/
      72             : #else
      73             :         num = extract_h( L_shl_o( LepsP[0], expn, &Overflow ) ); /*expn-16*/
      74             : #endif
      75           0 :         expd = norm_l( LepsP[1] );
      76             : #ifdef ISSUE_1867_replace_overflow_libenc
      77           0 :         den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/
      78             : #else
      79             :         den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/
      80             : #endif
      81           0 :         num = div_s( num, den );                           /*expn-expd+15*/
      82           0 :         num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/
      83           0 :         num = sub( num, 1024 );                            /*num - 1*/
      84             : 
      85           0 :         test();
      86           0 :         IF( NE_16( st_fx->bwidth, NB ) )
      87             :         {
      88             :             /* WB case */
      89             :             /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*2 * 32);*/
      90           0 :             noisiness = shr( num, 4 ); /*Q10  x64 -> Q0 */
      91             :         }
      92           0 :         ELSE IF( EQ_16( st_fx->coder_type, INACTIVE ) && EQ_16( st_fx->bwidth, NB ) )
      93             :         {
      94             :             /* NB GSC case */
      95             :             /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*.25f * 32);*/
      96           0 :             noisiness = shr( num, 4 + 3 ); /*Q10  x8 -> Q0 */
      97             :         }
      98             :         ELSE
      99             :         {
     100             :             /* NB case */
     101           0 :             noisiness = shr( num, 4 + 2 ); /*Q16  x16 -> Q0 */
     102             :         }
     103             : 
     104           0 :         noisiness = s_max( noisiness, 0 );
     105           0 :         noisiness = s_min( noisiness, 31 );
     106             : 
     107           0 :         push_indice( st_fx->hBstr, IND_NOISINESS, noisiness, 5 );
     108             :     }
     109             : 
     110             :     /*-----------------------------------------------------------------*
     111             :      * Modify the stationary noise excitation signal
     112             :      *-----------------------------------------------------------------*/
     113             : 
     114        1423 :     stat_noise_uv_mod_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count,
     115        1423 :                           st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx,
     116        1423 :                           st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge );
     117             : 
     118             : 
     119        1423 :     return;
     120             : }
     121             : 
     122             : 
     123      145380 : void stat_noise_uv_enc_ivas_fx(
     124             :     Encoder_State *st_fx,           /* i/o: state structure                                                      */
     125             :     const Word32 *LepsP,            /* i  : LP prediction errors                 Q=Qx*/
     126             :     const Word16 *isp_new,          /* i  : immittance spectral pairs at 4th sfr Q=15*/
     127             :     const Word16 *isp_mid,          /* i  : immittance spectral pairs at 2nd sfr Q=15*/
     128             :     Word16 *Aq,                     /* i  : A(z) quantized for the 4 subframes  Q=12 */
     129             :     Word16 *exc2,                   /* i/o: excitation buffer         Q=Q_stat_noise */
     130             :     const Word16 uc_two_stage_flag, /* o  : flag undicating two-stage UC                 */
     131             :     Word16 *Q_new )
     132             : {
     133      145380 :     Word16 noisiness = 0;
     134      145380 :     move16();
     135             :     Word16 num, den, expn, expd;
     136             : #ifndef ISSUE_1867_replace_overflow_libenc
     137             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     138             :     Flag Overflow = 0;
     139             :     move32();
     140             : #endif
     141             : #endif
     142      145380 :     test();
     143      145380 :     test();
     144      145380 :     test();
     145      145380 :     IF( ( EQ_16( st_fx->coder_type, UNVOICED ) && uc_two_stage_flag == 0 ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) )
     146             :     {
     147             : 
     148             :         /*-----------------------------------------------------------------*
     149             :          * Calculate and write the noisiness parameter
     150             :          *-----------------------------------------------------------------*/
     151             :         /* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */
     152         339 :         expn = sub( norm_l( LepsP[0] ), 1 );
     153             : #ifdef ISSUE_1867_replace_overflow_libenc
     154         339 :         num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/
     155             : #else
     156             :         num = extract_h( L_shl_o( LepsP[0], expn, &Overflow ) ); /*expn-16*/
     157             : #endif
     158         339 :         expd = norm_l( LepsP[1] );
     159             : #ifdef ISSUE_1867_replace_overflow_libenc
     160         339 :         den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/
     161             : #else
     162             :         den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/
     163             : #endif
     164         339 :         num = div_s( num, den );                           /*expn-expd+15*/
     165         339 :         num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/
     166         339 :         num = sub( num, 1024 );                            /*num - 1*/
     167             : 
     168         339 :         test();
     169         339 :         IF( NE_16( st_fx->bwidth, NB ) )
     170             :         {
     171             :             /* WB case */
     172             :             /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*2 * 32);*/
     173         339 :             noisiness = shr( num, 4 ); /*Q10  x64 -> Q0 */
     174             :         }
     175           0 :         ELSE IF( EQ_16( st_fx->coder_type, INACTIVE ) && EQ_16( st_fx->bwidth, NB ) )
     176             :         {
     177             :             /* NB GSC case */
     178             :             /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*.25f * 32);*/
     179           0 :             noisiness = shr( num, 4 + 3 ); /*Q10  x8 -> Q0 */
     180             :         }
     181             :         ELSE
     182             :         {
     183             :             /* NB case */
     184           0 :             noisiness = shr( num, 4 + 2 ); /*Q16  x16 -> Q0 */
     185             :         }
     186             : 
     187         339 :         noisiness = s_max( noisiness, 0 );
     188         339 :         noisiness = s_min( noisiness, 31 );
     189             : 
     190         339 :         push_indice( st_fx->hBstr, IND_NOISINESS, noisiness, 5 );
     191             :     }
     192             : 
     193             :     /*-----------------------------------------------------------------*
     194             :      * Modify the stationary noise excitation signal
     195             :      *-----------------------------------------------------------------*/
     196             : 
     197      145380 :     stat_noise_uv_mod_ivas_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count,
     198      145380 :                                st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx,
     199      145380 :                                st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge );
     200             : 
     201             : 
     202      145380 :     return;
     203             : }

Generated by: LCOV version 1.14