LCOV - code coverage report
Current view: top level - lib_com - cb_shape_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 24 40 60.0 %
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             : #include <stdint.h>
       5             : #include "options.h" /* Compilation switches                   */
       6             : #include "cnst.h"    /* Common constants                       */
       7             : #include "prot_fx.h" /* Function prototypes                    */
       8             : #include "rom_com.h" /* */
       9             : 
      10             : /*
      11             :  * E_GAIN_f_pitch_sharpening
      12             :  *
      13             :  * Parameters:
      14             :  *    x            I/O: impulse response (or algebraic code)
      15             :  *    pit_lag        I: pitch lag
      16             :  *
      17             :  * Function:
      18             :  *    Performs Pitch sharpening routine for one subframe.
      19             :  *    pitch sharpening factor is 0.85
      20             :  *
      21             :  * Returns:
      22             :  *    void
      23             :  */
      24     1791203 : static void E_GAIN_f_pitch_sharpening( Word16 *x, Word16 pit_lag, Word16 L_subfr )
      25             : {
      26             :     Word16 i, tmp;
      27             : 
      28    12389305 :     FOR( i = pit_lag; i < L_subfr; i++ )
      29             :     {
      30             :         /*x[i] += x[i - pit_lag] * F_PIT_SHARP;*/
      31    10598102 :         tmp = mult_r( x[i - pit_lag], 27853 /*F_PIT_SHARP Q15*/ );
      32    10598102 :         x[i] = add( x[i], tmp );
      33    10598102 :         move16();
      34             :     }
      35     1791203 :     return;
      36             : }
      37             : 
      38             : /*-------------------------------------------------------------------*
      39             :  * cb_shape()
      40             :  *
      41             :  * pre-emphasis, pitch sharpening and formant sharpening of the algebraic codebook
      42             :  *-------------------------------------------------------------------*/
      43             : 
      44     1805139 : void cb_shape_fx(
      45             :     const Word16 preemphFlag,     /* i  : flag for pre-emphasis                           */
      46             :     const Word16 pitchFlag,       /* i  : flag for pitch sharpening                       */
      47             :     const Word16 scramblingFlag,  /* i  : flag for phase scrambling                       */
      48             :     const Word16 sharpFlag,       /* i  : flag for formant sharpening                     */
      49             :     const Word16 formantTiltFlag, /* i  : flag for formant tilt                           */
      50             :     const Word16 g1,              /* i  : formant sharpening numerator weighting     Q15     */
      51             :     const Word16 g2,              /* i  : formant sharpening denominator weighting   Q15     */
      52             :     const Word16 *p_Aq,           /* i  : LP filter coefficients                     Q12     */
      53             :     Word16 *code,                 /* i/o: signal to shape                            Q9      */
      54             :     const Word16 tilt_code,       /* i  : tilt of code                               Q15     */
      55             :     const Word16 pt_pitch,        /* i  : pointer to current subframe fractional pitch Q6   */
      56             :     const Word16 shift,
      57             :     const Word16 L_subfr /* i  : subframe lenght */
      58             : )
      59             : {
      60             :     Word16 tmp, buff[2 * L_SUBFR + M], A_num[M + 1], A_den[M + 1];
      61             :     Word16 i;
      62             :     Word32 L_tmp;
      63             :     Word16 tilt, mu;
      64             : 
      65     1805139 :     tmp = 0;
      66             : 
      67     1805139 :     move16();
      68             : 
      69             :     /* Pre-emphasis */
      70     1805139 :     IF( preemphFlag )
      71             :     {
      72     1805139 :         preemph_copy_fx( code, code, tilt_code, L_subfr, &tmp );
      73             :     }
      74             : 
      75             :     /* pitch sharpening */
      76     1805139 :     IF( pitchFlag )
      77             :     {
      78     1791203 :         E_GAIN_f_pitch_sharpening( code, pt_pitch, L_subfr );
      79             :     }
      80             : 
      81             :     /* phase scrambling filter */
      82     1805139 :     IF( scramblingFlag )
      83             :     {
      84           0 :         buff[0] = code[0];
      85           0 :         move16();
      86           0 :         FOR( i = 1; i < L_subfr; i++ )
      87             :         {
      88           0 :             buff[i] = code[i];
      89           0 :             move16();
      90             :             /*code[i] = 0.7f*buff[i] + buff[i-1] - 0.7f*code[i-1];      */
      91           0 :             L_tmp = L_mult( 22938 /*.7f in Q15*/, buff[i] );           // Q15+Q9+1
      92           0 :             tmp = mac_r( L_tmp, -22938 /*-.7f in Q15*/, code[i - 1] ); // Q9
      93           0 :             code[i] = add( tmp, buff[i - 1] );
      94           0 :             move16();
      95             :         }
      96             :     }
      97             : 
      98     1805139 :     test();
      99     1805139 :     IF( sharpFlag || formantTiltFlag )
     100             :     {
     101     1498728 :         weight_a_fx( p_Aq, A_num, g1, M );
     102     1498728 :         weight_a_fx( p_Aq, A_den, g2, M );
     103     1498728 :         set16_fx( buff, 0, add( M, L_subfr ) );
     104     1498728 :         IF( formantTiltFlag )
     105             :         {
     106           0 :             Copy( A_num, buff + M, M + 1 );
     107             : 
     108           0 :             E_UTIL_synthesis( 1, A_den, buff + M, buff + M, L_subfr, buff, 0, M );
     109             : 
     110             :             /*Compute tilt of formant enhancement*/
     111           0 :             tilt = extract_l( L_shr( get_gain( buff + M + 1, buff + M, sub( L_subfr, 1 ) ), 1 ) );
     112             : 
     113             :             /*Combine tilt of code and fe*/
     114           0 :             tmp = 0;
     115           0 :             move16();
     116             :             /*mu = 0.5f*tilt_code-0.25f*tilt;*/
     117           0 :             mu = sub( shr( tilt_code, 1 ), shr( tilt, 2 ) );
     118           0 :             preemph_copy_fx( code, code, mu, L_subfr, &tmp );
     119             :         }
     120             :         ELSE
     121             :         {
     122     1498728 :             Copy( code, buff, L_subfr );
     123             : 
     124     1498728 :             Residu3_lc_fx( A_num, M, buff, code, L_subfr, shift );
     125             :             {
     126     1498728 :                 syn_filt_s_lc_fx( shift, A_den, code, code, L_subfr );
     127             :             }
     128             :         }
     129             :     }
     130             : 
     131     1805139 :     return;
     132             : }

Generated by: LCOV version 1.14