LCOV - code coverage report
Current view: top level - lib_dec - syn_outp_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 37 41 90.2 %
Date: 2025-05-03 01:55:50 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        1852 : 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        1852 :     tmp = Q_syn2;
      29        1852 :     move16();
      30             : 
      31             :     /*-----------------------------------------------------------------*
      32             :      * Output synthesis signal with compensation for saturation
      33             :      *-----------------------------------------------------------------*/
      34             : 
      35        1852 :     test();
      36        1852 :     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        1852 :         Copy_Scale_sig( synth, synth_out, output_frame, negate( tmp ) );
      50             :     }
      51             : 
      52        1852 :     return;
      53             : }
      54             : /*-------------------------------------------------------------------*
      55             :  * Local function
      56             :  * unscale_AGC
      57             :  *
      58             :  * Output synthesis signal with compensation for saturation
      59             :  *-------------------------------------------------------------------*/
      60      162611 : 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             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      71      162611 :     Flag Overflow = 0;
      72      162611 :     move32();
      73             : #endif
      74             : 
      75             :     /*----------------------------------------------------------------*
      76             :      * calculate AGC factor to avoid saturation
      77             :      *----------------------------------------------------------------*/
      78             : 
      79      162611 :     max_val = abs_s( x[0] );
      80    46824192 :     FOR( i = 1; i < n; i++ )
      81             :     {
      82    46661581 :         max_val = s_max( max_val, abs_s( x[i] ) );
      83             :     }
      84             :     BASOP_SATURATE_WARNING_OFF_EVS
      85      162611 :     tmp = shl_o( 30000, Qx, &Overflow ); /* saturation can occur here */
      86             :     BASOP_SATURATE_WARNING_ON_EVS
      87      162611 :     frame_fac = 0;
      88      162611 :     move16();
      89      162611 :     IF( GT_16( max_val, tmp ) )
      90             :     {
      91         304 :         frame_fac = sub( 16384 /*0.5f in Q15*/, div_s( shr( tmp, 1 ), max_val ) ); /* frame fac in Q15 */
      92             :     }
      93             : 
      94             :     /*----------------------------------------------------------------*
      95             :      * AGC
      96             :      *----------------------------------------------------------------*/
      97             :     /* update AGC factor (slowly) */
      98      162611 :     fac = mac_r( L_mult( 32440 /*0.99f in Q15*/, mem[0] ) /*Q14*/, 328 /*0.01f in Q15*/, frame_fac /*Q15*/ );
      99             : 
     100      162611 :     L_tmp = L_mult( x[0], 16384 /*1.0f in Q14*/ ); // Q13
     101      162611 :     L_tmp = L_msu0( L_tmp, fac, x[0] );
     102      162611 :     L_tmp = L_msu( L_tmp, fac, mem[1] );
     103      162611 :     L_tmp = L_shr( L_tmp, -1 ); /* saturation can occur here */
     104             : 
     105      162611 :     y[0] = round_fx( L_tmp );
     106      162611 :     move16();
     107             : 
     108    46824192 :     FOR( i = 1; i < n; i++ )
     109             :     {
     110             :         /* update AGC factor (slowly) */
     111    46661581 :         fac = mac_r( L_mult( 32440, fac ), 328, frame_fac );
     112             : 
     113    46661581 :         L_tmp = L_deposit_h( x[i] );
     114    46661581 :         L_tmp = L_msu( L_tmp, fac, x[i] );
     115    46661581 :         L_tmp = L_msu( L_tmp, fac, x[i - 1] );
     116    46661581 :         y[i] = round_fx( L_tmp );
     117    46661581 :         move16();
     118             :     }
     119             : 
     120      162611 :     mem[0] = fac;
     121      162611 :     move16();
     122      162611 :     mem[1] = shr( x[i - 1], 1 );
     123      162611 :     move16();
     124      162611 : }

Generated by: LCOV version 1.14