LCOV - code coverage report
Current view: top level - lib_dec - syn_outp_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 35 39 89.7 %
Date: 2025-08-23 01:22:27 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" /* Compilation switches                   */
       7             : #include "cnst.h"    /* Common constants                       */
       8             : #include "prot_fx.h" /* Debug prototypes                       */
       9             : 
      10             : /*-------------------------------------------------------------------*
      11             :  * syn_output_fx()
      12             :  *
      13             :  * Output synthesis signal with compensation for saturation
      14             :  *-------------------------------------------------------------------*/
      15             : 
      16        1850 : void syn_output_fx(
      17             :     const Word16 codec_mode,   /* i  : MODE1 or MODE2                      Q0           */
      18             :     Word16 *synth,             /* i/o: fixed point synthesis signal        Q_syn2       */
      19             :     const Word16 output_frame, /* i  : output frame length                 Q0           */
      20             :     Word16 *synth_out,         /* o  : integer 16 bits synthesis signal    Q_syn2       */
      21             :     const Word16 Q_syn2        /* i  : Synthesis scaling factor                         */
      22             : )
      23             : {
      24             :     Word16 i, tmp;
      25             :     Word32 L_tmp;
      26             : 
      27             :     /*tmp = sub(Q_syn2, 1); */
      28        1850 :     tmp = Q_syn2;
      29        1850 :     move16();
      30             : 
      31             :     /*-----------------------------------------------------------------*
      32             :      * Output synthesis signal with compensation for saturation
      33             :      *-----------------------------------------------------------------*/
      34             : 
      35        1850 :     test();
      36        1850 :     IF( EQ_16( codec_mode, MODE2 ) || EQ_16( output_frame, L_FRAME8k ) )
      37             :     {
      38             :         /* integer conversion */
      39             :         /*mvr2s( synth, synth_out, output_frame );   */
      40           0 :         FOR( i = 0; i < output_frame; i++ )
      41             :         {
      42           0 :             L_tmp = L_deposit_h( synth[i] );
      43           0 :             synth_out[i] = round_fx_sat( L_shr_sat( L_tmp, tmp ) );
      44           0 :             move16();
      45             :         }
      46             :     }
      47             :     ELSE
      48             :     {
      49        1850 :         Copy_Scale_sig( synth, synth_out, output_frame, negate( tmp ) );
      50             :     }
      51             : 
      52        1850 :     return;
      53             : }
      54             : /*-------------------------------------------------------------------*
      55             :  * Local function
      56             :  * unscale_AGC
      57             :  *
      58             :  * Output synthesis signal with compensation for saturation
      59             :  *-------------------------------------------------------------------*/
      60      165048 : void unscale_AGC(
      61             :     const Word16 x[], /* i:   16kHz synthesis                 Qx */
      62             :     const Word16 Qx,  /* i:   scale factor of x                  */
      63             :     Word16 y[],       /* o:   output vector                   Q0 */
      64             :     Word16 mem[],     /* i/o: mem[2] should be init to [0,0]  Q0 */
      65             :     const Word16 n    /* i:   vector size                        */
      66             : )
      67             : {
      68             :     Word16 i, fac, tmp, frame_fac, max_val;
      69             :     Word32 L_tmp;
      70             : #ifndef ISSUE_1866_replace_overflow_libdec
      71             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      72             :     Flag Overflow = 0;
      73             :     move32();
      74             : #endif
      75             : #endif
      76             : 
      77             :     /*----------------------------------------------------------------*
      78             :      * calculate AGC factor to avoid saturation
      79             :      *----------------------------------------------------------------*/
      80             : 
      81      165048 :     max_val = abs_s( x[0] );
      82    47573696 :     FOR( i = 1; i < n; i++ )
      83             :     {
      84    47408648 :         max_val = s_max( max_val, abs_s( x[i] ) );
      85             :     }
      86             :     BASOP_SATURATE_WARNING_OFF_EVS
      87             : #ifdef ISSUE_1866_replace_overflow_libdec
      88      165048 :     tmp = shl_sat( 30000, Qx ); /* saturation can occur here */
      89             : #else
      90             :     tmp = shl_o( 30000, Qx, &Overflow ); /* saturation can occur here */
      91             : #endif
      92             :     BASOP_SATURATE_WARNING_ON_EVS
      93      165048 :     frame_fac = 0;
      94      165048 :     move16();
      95      165048 :     IF( GT_16( max_val, tmp ) )
      96             :     {
      97         305 :         frame_fac = sub( 16384 /*0.5f in Q15*/, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */
      98             :     }
      99             : 
     100             :     /*----------------------------------------------------------------*
     101             :      * AGC
     102             :      *----------------------------------------------------------------*/
     103             :     /* update AGC factor (slowly) */
     104      165048 :     fac = mac_r( L_mult( 32440 /*0.99f in Q15*/, mem[0] ) /*Q14*/, 328 /*0.01f in Q15*/, frame_fac /*Q15*/ );
     105             : 
     106      165048 :     L_tmp = L_mult( x[0], 16384 /*1.0f in Q14*/ ); // Q13
     107      165048 :     L_tmp = L_msu0( L_tmp, fac, x[0] );
     108      165048 :     L_tmp = L_msu( L_tmp, fac, mem[1] );
     109      165048 :     L_tmp = L_shr( L_tmp, -1 ); /* saturation can occur here */
     110             : 
     111      165048 :     y[0] = round_fx( L_tmp );
     112      165048 :     move16();
     113             : 
     114    47573696 :     FOR( i = 1; i < n; i++ )
     115             :     {
     116             :         /* update AGC factor (slowly) */
     117    47408648 :         fac = mac_r( L_mult( 32440, fac ), 328, frame_fac );
     118             : 
     119    47408648 :         L_tmp = L_deposit_h( x[i] );
     120    47408648 :         L_tmp = L_msu( L_tmp, fac, x[i] );
     121    47408648 :         L_tmp = L_msu( L_tmp, fac, x[i - 1] );
     122    47408648 :         y[i] = round_fx( L_tmp );
     123    47408648 :         move16();
     124             :     }
     125             : 
     126      165048 :     mem[0] = fac;
     127      165048 :     move16();
     128      165048 :     mem[1] = shr( x[i - 1], 1 );
     129      165048 :     move16();
     130      165048 : }

Generated by: LCOV version 1.14