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

Generated by: LCOV version 1.14