LCOV - code coverage report
Current view: top level - lib_dec - dec_tran_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 106 106 100.0 %
Date: 2025-05-03 01:55:50 Functions: 1 1 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             : 
       9             : #define Q3_4   ( 4 << Q3 )
      10             : #define Q3_17  ( 17 << Q3 )
      11             : #define Q16_8  ( 8 << Q16 )
      12             : #define Q16_30 ( 30 << Q16 )
      13             : 
      14             : /*======================================================================*/
      15             : /* FUNCTION : decod_tran_fx()                                                                               */
      16             : /*----------------------------------------------------------------------*/
      17             : /* PURPOSE : Decode transition (TC) frames                                      */
      18             : /*                                                                                                                                              */
      19             : /*----------------------------------------------------------------------*/
      20             : /* GLOBAL INPUT ARGUMENTS :                                                                                             */
      21             : /* _ (Struct)   st_fx                   : decoder static memory                                 */
      22             : /* _ (Word16) L_frame_fx                : length of the frame           Q0                      */
      23             : /* _ (Word16[]) Aq_fx                   : LP filter coefficient         Q12                     */
      24             : /* _ (Word16) coder_type                : coding type                           Q12                     */
      25             : /* _ (Word16) Es_pred_fx                : predicted scaled innov. energy Q8             */
      26             : /* _ (Word16[]) pitch_buf_fx    : floating pitch values for each subframe Q6*/
      27             : /* _ (Word16[]) voice_factors_fx: frame error rate                              Q15             */
      28             : /*-----------------------------------------------------------------------*/
      29             : /* OUTPUT ARGUMENTS :                                                                                                    */
      30             : /* _ (Word16[]) exc_fx                  : adapt. excitation exc (Q_exc)                  */
      31             : /* _ (Word16[]) exc2_fx                 : adapt. excitation/total exc (Q_exc)    */
      32             : /*-----------------------------------------------------------------------*/
      33             : 
      34             : 
      35             : /*-----------------------------------------------------------------------*/
      36             : /* RETURN ARGUMENTS :                                                                                                    */
      37             : /* _ None                                                                                                                                */
      38             : /*=======================================================================*/
      39             : 
      40       12668 : void decod_tran_fx(
      41             :     Decoder_State *st_fx,     /* i/o: decoder static memory                  */
      42             :     const Word16 L_frame_fx,  /* i  : length of the frame                    */
      43             :     const Word16 tc_subfr_fx, /* i  : TC subframe index                      */
      44             :     const Word16 *Aq_fx,      /* i  : LP filter coefficient                  */
      45             :     const Word16 Es_pred_fx,  /* i  : predicted scaled innov. energy         */
      46             :     Word16 *pitch_buf_fx,     /* o  : floating pitch values for each subframe*/
      47             :     Word16 *voice_factors_fx, /* o  : voicing factors                        */
      48             :     Word16 *exc_fx,           /* i/o: adapt. excitation exc                  */
      49             :     Word16 *exc2_fx,          /* i/o: adapt. excitation/total exc            */
      50             :     Word16 *bwe_exc_fx,       /* i/o: excitation for SWB TBE                 */
      51             :     Word16 *unbits,           /* i/o: number of unused bits                  */
      52             :     const Word16 sharpFlag,   /* i  : formant sharpening flag                */
      53             :     Word16 *gain_buf          /* o  : floating pitch gain for each subframe  */
      54             : )
      55             : {
      56             :     Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables                     */
      57             :     Word32 gain_code_fx;                /* Quantized algebraic codeebook gain          */
      58             :     Word32 norm_gain_code_fx;           /* normalized algebraic codeebook gain         */
      59             :     Word16 gain_pit_fx;                 /* Quantized pitch gain                        */
      60             :     Word16 voice_fac_fx;                /* Voicing factor                              */
      61             :     Word16 gain_inov_fx;                /* inovation gain                              */
      62             :     Word16 code_fx[L_SUBFR];            /* algebraic codevector                        */
      63             :     const Word16 *p_Aq_fx;              /* pointer to lp filter coefficient            */
      64             :     Word16 *pt_pitch_fx;                /* pointer to floating pitch                   */
      65             :     Word16 i_subfr, i;                  /* tmp variables                               */
      66             :     Word16 position;                    /* TC related flag                             */
      67             :     Word16 gain_preQ_fx;                /* Gain of prequantizer excitation             */
      68             :     Word16 code_preQ_fx[L_SUBFR];       /* Prequantizer excitation                     */
      69             :     Word16 Jopt_flag;                   /* flag indicating zero adaptive contribtuion  */
      70             :     Word32 norm_gain_preQ_fx;
      71             :     Word16 gain_code16;
      72             :     Word32 L_tmp;
      73             :     Word16 tmp16, tmp1_fx, tmp_fx;
      74             :     GSC_DEC_HANDLE hGSCDec;
      75       12668 :     hGSCDec = st_fx->hGSCDec;
      76             :     MUSIC_POSTFILT_HANDLE hMusicPF;
      77       12668 :     hMusicPF = st_fx->hMusicPF;
      78             : 
      79             : 
      80       12668 :     gain_code_fx = 0; /* Quantized algebraic codeebook gain          */
      81       12668 :     move32();
      82       12668 :     norm_gain_code_fx = 0; /* normalized algebraic codeebook gain Q16        */
      83       12668 :     move32();
      84       12668 :     gain_pit_fx = 0; /* Quantized pitch gain Q14                        */
      85       12668 :     move16();
      86       12668 :     gain_inov_fx = 0; /* inovation gain                              */
      87       12668 :     move16();
      88       12668 :     gain_preQ_fx = 0; /* Gain of prequantizer excitation Q2            */
      89       12668 :     move16();
      90             : 
      91       12668 :     set16_fx( code_preQ_fx, 0, L_SUBFR ); // Q10
      92             :     /*----------------------------------------------------------------*
      93             :      * ACELP subframe loop
      94             :      *----------------------------------------------------------------*/
      95             : 
      96       12668 :     p_Aq_fx = Aq_fx;            // Q12
      97       12668 :     pt_pitch_fx = pitch_buf_fx; // Q6
      98       12668 :     Jopt_flag = 0;
      99       12668 :     move16();
     100       12668 :     norm_gain_preQ_fx = 0;
     101       12668 :     move16();
     102             : 
     103       69529 :     FOR( i_subfr = 0; i_subfr < L_frame_fx; i_subfr += L_SUBFR )
     104             :     {
     105             :         /*------------------------------------------------------------*
     106             :          * TC : subframe determination &
     107             :          * adaptive/glottal part of excitation construction
     108             :          *------------------------------------------------------------*/
     109             : 
     110       56861 :         test();
     111       56861 :         IF( i_subfr == 0 && GT_16( st_fx->Q_exc, 2 ) )
     112             :         {
     113        7711 :             tmp16 = sub( 2, st_fx->Q_exc );
     114        7711 :             Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, tmp16 );               // Q2
     115        7711 :             Scale_sig( bwe_exc_fx - PIT16k_MAX * 2, PIT16k_MAX * 2, tmp16 ); // Q2
     116        7711 :             Scale_sig( hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16 );        // Q2
     117        7711 :             st_fx->Q_exc = add( st_fx->Q_exc, tmp16 );
     118        7711 :             move16();
     119             :         }
     120             : 
     121       56861 :         transition_dec_fx( st_fx, 0, L_frame_fx, i_subfr, tc_subfr_fx, &Jopt_flag, exc_fx,
     122             :                            &T0, &T0_frac, &T0_min, &T0_max, &pt_pitch_fx, &position, bwe_exc_fx, &st_fx->Q_exc );
     123             :         /*-----------------------------------------------------------------*
     124             :          * Transform domain contribution decoding - active frames
     125             :          *-----------------------------------------------------------------*/
     126       56861 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     127             :         {
     128        5650 :             gain_code_fx = 0;
     129        5650 :             move16();
     130        5650 :             transf_cdbk_dec_fx( st_fx, 0, i_subfr, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits );
     131             :         }
     132             : 
     133             :         /*-----------------------------------------------------------------*
     134             :          * ACELP codebook search + pitch sharpening
     135             :          *-----------------------------------------------------------------*/
     136             : 
     137       56861 :         inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame_fx, sharpFlag, i_subfr, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR );
     138             : 
     139             :         /*-----------------------------------------------------------------*
     140             :          * De-quantize the gains
     141             :          * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced)
     142             :          *-----------------------------------------------------------------*/
     143             : 
     144       56861 :         IF( Jopt_flag == 0 )
     145             :         {
     146             :             /* 2/3-bit decoding */
     147       17592 :             IF( st_fx->element_mode == EVS_MONO )
     148             :             {
     149          94 :                 gain_dec_tc_fx( st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
     150             :             }
     151             :             ELSE
     152             :             {
     153       17498 :                 gain_dec_tc_ivas_fx( st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
     154             :             }
     155             :         }
     156             :         ELSE
     157             :         {
     158             :             /* 5-bit decoding */
     159       39269 :             IF( GT_32( st_fx->core_brate, ACELP_32k ) )
     160             :             {
     161        2758 :                 gain_dec_SQ_fx( st_fx, i_subfr, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
     162             :             }
     163             :             ELSE
     164             :             {
     165       36511 :                 gain_dec_mless_fx( st_fx, L_frame_fx, st_fx->coder_type, i_subfr, tc_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
     166             :             }
     167             :         }
     168             : 
     169             :         /* update LP filtered gains for the case of frame erasures */
     170       56861 :         IF( st_fx->element_mode == EVS_MONO )
     171             :         {
     172         535 :             lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx );
     173             : 
     174         535 :             st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc );
     175         535 :             move16();
     176             :         }
     177             :         ELSE
     178             :         {
     179       56326 :             lp_gain_updt_ivas_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx );
     180             : 
     181       56326 :             st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 );
     182       56326 :             move16();
     183             :         }
     184             : 
     185             :         /*----------------------------------------------------------------------*
     186             :          * Find the total excitation
     187             :          *----------------------------------------------------------------------*/
     188       56861 :         test();
     189       56861 :         test();
     190       56861 :         test();
     191       56861 :         IF( st_fx->element_mode > EVS_MONO && ( GE_16( add( i_subfr, L_SUBFR ), tc_subfr_fx ) && LT_16( i_subfr, tc_subfr_fx ) && GT_16( st_fx->Q_subfr[0], 4 ) ) )
     192             :         {
     193        4631 :             test();
     194        4631 :             test();
     195        4631 :             test();
     196        4631 :             IF( GE_16( st_fx->Q_subfr[0], 7 ) && LE_32( st_fx->lp_gainc_fx, Q3_4 ) && LE_32( norm_gain_code_fx, Q16_8 ) )
     197             :             {
     198        1374 :                 st_fx->Q_subfr[0] = s_min( st_fx->Q_subfr[0], 4 );
     199        1374 :                 move16();
     200             :             }
     201        3257 :             ELSE IF( LE_32( st_fx->lp_gainc_fx, Q3_17 ) && LE_32( L_sub( gain_code_fx, norm_gain_code_fx ), Q16_30 ) )
     202             :             {
     203        1980 :                 st_fx->Q_subfr[0] = s_min( 4, sub( st_fx->Q_subfr[0], 2 ) );
     204        1980 :                 move16();
     205             :             }
     206             :         }
     207       56861 :         IF( EQ_16( L_frame_fx, L_FRAME ) ) /* Rescaling for 12.8k core */
     208             :         {
     209       25916 :             Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[( ( i_subfr * 2 * HIBND_ACB_L_FAC ) >> 1 )], hGSCDec->last_exc_dct_in_fx,
     210       25916 :                          L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type );
     211             :         }
     212             :         ELSE /* Rescaling for 16k core */
     213             :         {
     214       30945 :             Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], hGSCDec->last_exc_dct_in_fx,
     215       30945 :                          L_SUBFR, L_SUBFR * 2, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type );
     216             :         }
     217             : 
     218       56861 :         gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
     219       56861 :         Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx, L_SUBFR );
     220             : 
     221             :         /*-----------------------------------------------------------------*
     222             :          * Add the ACELP pre-quantizer contribution
     223             :          *-----------------------------------------------------------------*/
     224       56861 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) )
     225             :         {
     226        5650 :             IF( ( st_fx->element_mode == EVS_MONO ) )
     227             :             {
     228         235 :                 tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc );
     229             :             }
     230             :             ELSE
     231             :             {
     232        5415 :                 tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc );
     233             :             }
     234      367250 :             FOR( i = 0; i < L_SUBFR; i++ )
     235             :             {
     236      361600 :                 L_tmp = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q10 -> Q13*/
     237      361600 :                 L_tmp = L_shl_sat( L_tmp, tmp1_fx );             /* Q16 + Q_exc      */
     238      361600 :                 tmp_fx = round_fx_sat( L_tmp );
     239      361600 :                 exc2_fx[i + i_subfr] = add_sat( exc2_fx[i + i_subfr], tmp_fx );
     240      361600 :                 move16();
     241      361600 :                 exc_fx[i + i_subfr] = add_sat( exc_fx[i + i_subfr], tmp_fx );
     242      361600 :                 move16();
     243             :             }
     244             :         }
     245             : 
     246             :         /*-----------------------------------------------------------------*
     247             :          * Prepare TBE excitation
     248             :          *-----------------------------------------------------------------*/
     249             :         Word16 tmp_idx_2;
     250       56861 :         tmp_idx_2 = 0;
     251       56861 :         move16();
     252       56861 :         if ( i_subfr != 0 )
     253             :         {
     254       44193 :             tmp_idx_2 = idiv1616( i_subfr, L_SUBFR );
     255             :         }
     256             : 
     257             : #ifdef REMOVE_EVS_DUPLICATES
     258       56861 :         prep_tbe_exc_ivas_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
     259       56861 :                               &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
     260       56861 :                               st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate,
     261       56861 :                               st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
     262             : #else
     263             :         prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
     264             :                          &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
     265             :                          st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate );
     266             : #endif
     267             : 
     268             :         /*----------------------------------------------------------------*
     269             :          * Excitation enhancements (update of total excitation signal)
     270             :          *----------------------------------------------------------------*/
     271             : 
     272       56861 :         IF( GT_32( st_fx->core_brate, ACELP_32k ) )
     273             :         {
     274        3990 :             Copy( exc_fx + i_subfr, exc2_fx + i_subfr, L_SUBFR );
     275             :         }
     276             :         ELSE
     277             :         {
     278       52871 :             enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr, L_frame_fx, voice_fac_fx, st_fx->stab_fac_fx,
     279       52871 :                          norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc );
     280             :         }
     281             : 
     282             :         Word16 tmp_idx;
     283       56861 :         tmp_idx = 0;
     284       56861 :         move16();
     285       56861 :         if ( i_subfr != 0 )
     286             :         {
     287       44193 :             tmp_idx = idiv1616( i_subfr, L_SUBFR );
     288             :         }
     289       56861 :         p_Aq_fx += ( M + 1 );
     290       56861 :         pt_pitch_fx++;
     291       56861 :         st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; // Q15
     292       56861 :         move16();
     293       56861 :         gain_buf[tmp_idx] = gain_pit_fx; // Q14
     294       56861 :         move16();
     295             :     }
     296             : 
     297             :     /* SC-VBR */
     298       12668 :     st_fx->prev_gain_pit_dec_fx = gain_pit_fx;
     299       12668 :     move16(); /*Q14*/
     300             : 
     301       12668 :     return;
     302             : }

Generated by: LCOV version 1.14