LCOV - code coverage report
Current view: top level - lib_dec - dec_pit_exc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 188 221 85.1 %
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 "rom_com.h" /* Static table prototypes                */
       8             : #include "prot_fx.h" /* Function prototypes                    */
       9             : 
      10             : /*==========================================================================*/
      11             : /* FUNCTION : void  dec_pit_exc_fx()                                                                    */
      12             : /*--------------------------------------------------------------------------*/
      13             : /* PURPOSE  :  Decode pitch only contribution                               */
      14             : /*--------------------------------------------------------------------------*/
      15             : /*    INPUT ARGUMENTS :                                                                                                 */
      16             : /* _ (Word16*) Aq_fx               : LP filter coefficient              Q12                         */
      17             : /* _ (Word16) coder_type    : coding type                               Q0                          */
      18             : /* _ (Word16) nb_subfr_fx      :Number of subframe considered               */
      19             : /* _ (Word16) Es_pred_fx       :predicted scaled innov. energy              */
      20             : /*--------------------------------------------------------------------------*/
      21             : /* OUTPUT ARGUMENTS :                                                                                                       */
      22             : /* _ (Word16*) pitch_buf_fx     : floating pitch values for each subframe Q6    */
      23             : /* _ (Word16*)  code_fx     : innovation Q12                                    */
      24             : /*--------------------------------------------------------------------------*/
      25             : /* INPUT/OUTPUT ARGUMENTS :                                                                                         */
      26             : /*  Decoder_State_fx *st_fx     : decoder state structure                   */
      27             : /* _ (Word16*) exc_fx                   : adapt. excitation exc                             */
      28             : /*--------------------------------------------------------------------------*/
      29             : /* RETURN ARGUMENTS :                                                                                                       */
      30             : /* _ None                                                                                                                                   */
      31             : /*==========================================================================*/
      32             : 
      33             : #ifndef REMOVE_EVS_DUPLICATES
      34             : void dec_pit_exc_fx(
      35             :     Decoder_State *st_fx,    /* i/o: decoder static memory                     */
      36             :     const Word16 *Aq_fx,     /* i  : LP filter coefficient                     */
      37             :     const Word16 coder_type, /* i  : coding type                               */
      38             :     const Word16 Es_pred_fx, /* i  : predicted scaled innov. energy            */
      39             :     Word16 *pitch_buf_fx,    /* o  : floating pitch values for each subframe   */
      40             :     Word16 *code_fx,         /* o  : innovation                                */
      41             :     Word16 *exc_fx,          /* i/o: adapt. excitation exc                     */
      42             :     Word16 *bwe_exc_fx,      /* o  : excitation for SWB TBE                    */
      43             :     const Word16 nb_subfr_fx /* i  : Number of subframe considered             */
      44             :     ,
      45             :     Word16 *gain_buf /*Q14*/
      46             : )
      47             : {
      48             :     Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables    */
      49             :     Word16 gain_pit_fx;                             /* pitch gain               Q14                            */
      50             :     Word32 gain_code_fx;                            /* gain/normalized gain of the algebraic excitation Q16      */
      51             :     Word32 norm_gain_code_fx;                       /* normalized gain of the algebraic excitation        Q16   */
      52             :     Word16 gain_inov_fx;                            /* Innovation gain  Q12                                      */
      53             :     Word16 voice_fac_fx;                            /* voicing factor  Q15                                      */
      54             :     Word16 L_subfr_fx, pit_idx_fx;
      55             :     const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12                      */
      56             :     Word16 *pt_pitch_fx;   /* pointer to floating pitch     Q6                        */
      57             :     Word16 i_subfr_fx, i;  /* tmp variables                                         */
      58             :     Word32 Local_BR_fx, Pitch_BR_fx;
      59             :     Word16 pitch_limit_flag, Pitch_CT_fx;
      60             :     Word16 exc2_bidon[L_SUBFR];
      61             :     Word16 *pt_gain; /* Pointer to floating gain values for each subframe     */
      62             : 
      63             :     Word16 gain_code16, gain_pitx2;
      64             :     Word32 L_tmp;
      65             :     Word16 nbits;
      66             :     GSC_DEC_HANDLE hGSCDec;
      67             :     gain_pit_fx = 0;
      68             :     move16();
      69             :     hGSCDec = st_fx->hGSCDec;
      70             : 
      71             :     MUSIC_POSTFILT_HANDLE hMusicPF;
      72             :     hMusicPF = st_fx->hMusicPF;
      73             : 
      74             :     Word16 use_fcb;
      75             :     Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes                    */
      76             :     Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes                   */
      77             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      78             :     Flag Overflow = 0;
      79             :     move16();
      80             : #endif
      81             : 
      82             :     use_fcb = 0;
      83             :     move16();
      84             :     test();
      85             :     test();
      86             :     IF( ( st_fx->GSC_IVAS_mode > 0 ) && ( EQ_16( st_fx->GSC_noisy_speech, 1 ) || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) )
      87             :     {
      88             :         Local_BR_fx = ACELP_8k00;
      89             :         Pitch_CT_fx = GENERIC;
      90             :         Pitch_BR_fx = ACELP_8k00;
      91             :         move32();
      92             :         move32();
      93             :         move16();
      94             :         IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
      95             :         {
      96             :             Local_BR_fx = ACELP_14k80;
      97             :             move32();
      98             :             if ( st_fx->GSC_IVAS_mode > 0 )
      99             :             {
     100             :                 Local_BR_fx = ACELP_9k60;
     101             :                 move32();
     102             :             }
     103             :             Pitch_BR_fx = st_fx->core_brate;
     104             :             move32();
     105             :         }
     106             :     }
     107             :     ELSE IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) )
     108             :     {
     109             :         Local_BR_fx = ACELP_7k20;
     110             :         move32();
     111             :         Pitch_CT_fx = GENERIC;
     112             :         move16();
     113             :         Pitch_BR_fx = ACELP_7k20;
     114             :         move32();
     115             :         if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     116             :         {
     117             :             Pitch_BR_fx = st_fx->core_brate;
     118             :             move32();
     119             :         }
     120             :     }
     121             :     ELSE
     122             :     {
     123             :         Local_BR_fx = ACELP_7k20;
     124             :         move32();
     125             :         Pitch_CT_fx = AUDIO;
     126             :         move16();
     127             :         Pitch_BR_fx = st_fx->core_brate;
     128             :         move32();
     129             :         IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     130             :         {
     131             :             Pitch_BR_fx = ACELP_13k20;
     132             :             move32();
     133             :             Pitch_CT_fx = GENERIC;
     134             :             move16();
     135             :         }
     136             :     }
     137             :     L_subfr_fx = mult_r( st_fx->L_frame, div_s( 1, nb_subfr_fx ) ); /* TV2Opt : this could be less complex with 2 ifs*/
     138             : 
     139             : 
     140             :     gain_code_fx = 0;
     141             :     move16();
     142             :     pitch_limit_flag = 1;
     143             :     move16(); /* always extended pitch Q range */
     144             :     test();
     145             :     test();
     146             :     test();
     147             :     test();
     148             :     test();
     149             :     test();
     150             :     test();
     151             :     test();
     152             :     test();
     153             :     IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) )
     154             :     {
     155             :         use_fcb = 1;
     156             :         move16();
     157             :     }
     158             :     ELSE IF( ( st_fx->GSC_IVAS_mode > 0 ) && EQ_16( L_subfr_fx, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) )
     159             :     {
     160             :         use_fcb = 2;
     161             :         st_fx->acelp_cfg.fcb_mode = 1;
     162             :         move16();
     163             :         move16();
     164             :         set16_fx( st_fx->acelp_cfg.gains_mode, 6, 4 );
     165             :         set16_fx( st_fx->acelp_cfg.pitch_bits, 9, 4 );
     166             :         set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, 5 );
     167             :     }
     168             :     /*------------------------------------------------------------------*
     169             :      * ACELP subframe loop
     170             :      *------------------------------------------------------------------*/
     171             :     p_Aq_fx = Aq_fx;            /* pointer to interpolated LPC parameters */
     172             :     pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
     173             :     pt_gain = gain_buf;         /* pointer to the gain buffer  */
     174             :     FOR( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx )
     175             :     {
     176             :         /*----------------------------------------------------------------------*
     177             :          *  Decode pitch lag
     178             :          *----------------------------------------------------------------------*/
     179             :         *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx );
     180             :         move16();
     181             : 
     182             :         /*--------------------------------------------------------------*
     183             :          * Find the adaptive codebook vector.
     184             :          *--------------------------------------------------------------*/
     185             : 
     186             :         pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     187             : 
     188             :         /*--------------------------------------------------------------*
     189             :          * Innovation decoding
     190             :          *--------------------------------------------------------------*/
     191             : 
     192             :         IF( EQ_16( use_fcb, 1 ) )
     193             :         {
     194             :             inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx );
     195             :             /*--------------------------------------------------------------*
     196             :              * Gain decoding
     197             :              * Estimate spectrum tilt and voicing
     198             :              *--------------------------------------------------------------*/
     199             : 
     200             :             gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
     201             : 
     202             :             st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 );
     203             :             move16();
     204             :         }
     205             :         ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */
     206             :         {
     207             :             inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx );
     208             :             /*--------------------------------------------------------------*
     209             :              * Gain decoding
     210             :              * Estimate spectrum tilt and voicing
     211             :              *--------------------------------------------------------------*/
     212             : 
     213             :             gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx );
     214             : 
     215             :             st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 );
     216             :             move16();
     217             :         }
     218             :         ELSE
     219             :         {
     220             :             nbits = 5;
     221             :             move16();
     222             :             if ( LT_32( st_fx->core_brate, MIN_RATE_FCB ) )
     223             :             {
     224             :                 nbits = 4;
     225             :                 move16();
     226             :             }
     227             : 
     228             :             set16_fx( code_fx, 0, L_SUBFR );
     229             :             gain_code_fx = L_deposit_l( 0 );
     230             :             st_fx->tilt_code_fx = 0;
     231             :             move16();
     232             :             pit_idx_fx = (Word16) get_next_indice( st_fx, nbits );
     233             :             move16();
     234             : 
     235             :             gain_pit_fx = add( 9590, dic_gp_fx[pit_idx_fx] );
     236             :             move16(); /*Q14  0.5853 in Q14 9590*/
     237             : 
     238             :             if ( st_fx->BER_detect ) /* Bitstream is corrupted, use the past pitch gain */
     239             :             {
     240             :                 gain_pit_fx = st_fx->lp_gainp_fx;
     241             :                 move16();
     242             :             }
     243             :             gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/
     244             :         }
     245             : 
     246             :         /*----------------------------------------------------------------------*
     247             :          * Find the total excitation
     248             :          *----------------------------------------------------------------------*/
     249             : 
     250             :         Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx,
     251             :                      L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type );
     252             : 
     253             :         gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
     254             : 
     255             :         IF( use_fcb != 0 )
     256             :         {
     257             :             Acelp_dec_total_exc( exc_fx, exc2_bidon - i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_subfr_fx );
     258             :         }
     259             :         ELSE
     260             :         {
     261             :             IF( norm_s( s_or( gain_pit_fx, 1 ) ) == 0 )
     262             :             {
     263             :                 FOR( i = 0; i < L_subfr_fx; i++ )
     264             :                 {
     265             :                     L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/
     266             :                     exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp );                        /*Q_exc*/
     267             :                     move16();
     268             :                 }
     269             :             }
     270             :             ELSE
     271             :             {
     272             :                 gain_pitx2 = shl( gain_pit_fx, 1 ); /*Q15*/
     273             : 
     274             :                 FOR( i = 0; i < L_subfr_fx; i++ )
     275             :                 {
     276             :                     L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/
     277             :                     exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp );       /*Q_exc*/
     278             :                     move16();
     279             :                 }
     280             :             }
     281             :         }
     282             : 
     283             :         IF( EQ_16( L_subfr_fx, L_FRAME16k ) )
     284             :         {
     285             :             /* update gains for FEC - equivalent to lp_gain_updt() */
     286             :             st_fx->lp_gainp_fx = gain_pit_fx;
     287             :             move16();
     288             :             st_fx->lp_gainc_fx = 0;
     289             :             move32();
     290             : 
     291             :             pt_pitch_fx++;
     292             :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     293             :             pt_pitch_fx++;
     294             :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     295             :             pt_pitch_fx++;
     296             :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     297             :             pt_pitch_fx++;
     298             :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     299             :             pt_pitch_fx++;
     300             :             move16();
     301             :             move16();
     302             :             move16();
     303             :             move16();
     304             :             p_Aq_fx += 5 * ( M + 1 );
     305             :         }
     306             :         ELSE IF( EQ_16( L_subfr_fx, L_FRAME16k / 2 ) )
     307             :         {
     308             :             IF( i_subfr_fx == 0 )
     309             :             {
     310             :                 pt_pitch_fx++;
     311             :                 *pt_pitch_fx = *( pt_pitch_fx - 1 );
     312             :                 pt_pitch_fx++;
     313             :                 p_Aq_fx += 2 * ( M + 1 );
     314             :                 move16();
     315             : 
     316             :                 /* update gains for FEC - equivalent to lp_gain_updt() */
     317             :                 st_fx->lp_gainp_fx = extract_h( L_mult( 6554, gain_pit_fx ) ); /*Q14 (3/15 in Q15 9830)*/
     318             :                 st_fx->lp_gainc_fx = 0;
     319             :                 move16();
     320             :                 move16();
     321             :             }
     322             :             ELSE
     323             :             {
     324             :                 pt_pitch_fx++;
     325             :                 *pt_pitch_fx = *( pt_pitch_fx - 1 );
     326             :                 pt_pitch_fx++;
     327             :                 *pt_pitch_fx = *( pt_pitch_fx - 1 );
     328             :                 pt_pitch_fx++;
     329             :                 p_Aq_fx += 3 * ( M + 1 );
     330             :                 move16();
     331             :                 move16();
     332             : 
     333             :                 /* update gains for FEC - equivalent to lp_gain_updt() */
     334             :                 st_fx->lp_gainp_fx = extract_h( L_mult( 26214, gain_pit_fx ) ); /*Q14 (12/15 in Q15 9830)*/
     335             :                 st_fx->lp_gainc_fx = 0;
     336             :                 move16();
     337             :                 move16();
     338             :             }
     339             :         }
     340             :         ELSE IF( EQ_16( L_subfr_fx, 128 ) ) /*2*L_SUBFR*/
     341             :         {
     342             :             p_Aq_fx += 2 * ( M + 1 );
     343             :             pt_pitch_fx++;
     344             :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     345             :             move16();
     346             :             pt_pitch_fx++;
     347             :             *pt_gain = gain_pit_fx;
     348             :             move16();
     349             :             pt_gain++;
     350             :             *pt_gain = *( pt_gain - 1 );
     351             :             move16();
     352             :             pt_gain++;
     353             :             IF( i_subfr_fx == 0 )
     354             :             {
     355             :                 /* update gains for FEC - equivalent to lp_gain_updt() */
     356             :                 st_fx->lp_gainp_fx = extract_h( L_mult( 9830, gain_pit_fx ) ); /*Q14 (3/10 in Q15 9830)*/
     357             :                 st_fx->lp_gainc_fx = 0;
     358             :                 move16();
     359             :                 move16();
     360             :             }
     361             :             ELSE
     362             :             {
     363             :                 /* update gains for FEC - equivalent to lp_gain_updt() */
     364             :                 st_fx->lp_gainp_fx = extract_h( L_mult( 22938, gain_pit_fx ) ); /*Q14 (7/10 in Q15 22938)*/
     365             :                 st_fx->lp_gainc_fx = 0;
     366             :                 move16();
     367             :                 move16();
     368             :             }
     369             :         }
     370             :         ELSE IF( EQ_16( L_subfr_fx, 256 ) ) /*4*L_SUBFR*/
     371             :         {
     372             :             pt_pitch_fx++;
     373             :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     374             :             move16();
     375             :             pt_pitch_fx++;
     376             :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     377             :             move16();
     378             :             pt_pitch_fx++;
     379             :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     380             :             move16();
     381             :             pt_pitch_fx++;
     382             :             *pt_gain = gain_pit_fx;
     383             :             move16();
     384             :             pt_gain++;
     385             :             *pt_gain = *( pt_gain - 1 );
     386             :             move16();
     387             :             pt_gain++;
     388             :             *pt_gain = *( pt_gain - 1 );
     389             :             move16();
     390             :             pt_gain++;
     391             :             *pt_gain = *( pt_gain - 1 );
     392             :             move16();
     393             :             pt_gain++;
     394             :             p_Aq_fx += 4 * ( M + 1 );
     395             : 
     396             :             /* update gains for FEC - equivalent to lp_gain_updt() */
     397             :             st_fx->lp_gainp_fx = gain_pit_fx;
     398             :             move16();
     399             :             st_fx->lp_gainc_fx = 0;
     400             :             move16();
     401             :         }
     402             :         ELSE
     403             :         {
     404             :             p_Aq_fx += ( M + 1 );
     405             :             move16();
     406             :             pt_pitch_fx++;
     407             :             move16();
     408             :             *pt_gain = gain_pit_fx;
     409             :             move16();
     410             :             pt_gain++;
     411             : 
     412             :             lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame );
     413             :         }
     414             :     }
     415             : 
     416             :     return;
     417             : }
     418             : 
     419             : /*==========================================================================*/
     420             : /* FUNCTION : void  dec_pit_exc_ivas_fx()                                                                       */
     421             : /*--------------------------------------------------------------------------*/
     422             : /* PURPOSE  :  Decode pitch only contribution                               */
     423             : /*--------------------------------------------------------------------------*/
     424             : /*    INPUT ARGUMENTS :                                                                                                 */
     425             : /* _ (Word16*) Aq_fx               : LP filter coefficient              Q12                         */
     426             : /* _ (Word16) coder_type    : coding type                               Q0                          */
     427             : /* _ (Word16) nb_subfr_fx      :Number of subframe considered               */
     428             : /* _ (Word16) Es_pred_fx       :predicted scaled innov. energy              */
     429             : /*--------------------------------------------------------------------------*/
     430             : /* OUTPUT ARGUMENTS :                                                                                                       */
     431             : /* _ (Word16*) pitch_buf_fx     : Word16 pitch values for each subframe Q6    */
     432             : /* _ (Word16*)  code_fx     : innovation                                    */
     433             : /*--------------------------------------------------------------------------*/
     434             : /* INPUT/OUTPUT ARGUMENTS :                                                                                         */
     435             : /*  Decoder_State_fx *st_fx     : decoder state structure                   */
     436             : /* _ (Word16*) exc_fx                   : adapt. excitation exc                             */
     437             : /*--------------------------------------------------------------------------*/
     438             : /* RETURN ARGUMENTS :                                                                                                       */
     439             : /* _ None                                                                                                                                   */
     440             : /*==========================================================================*/
     441             : #endif
     442       11717 : void dec_pit_exc_ivas_fx(
     443             :     Decoder_State *st_fx,              /* i/o: decoder static memory                     */
     444             :     const Word16 *Aq_fx,               /* i  : LP filter coefficient                     */
     445             :     const Word16 coder_type,           /* i  : coding type                               */
     446             :     const Word16 Es_pred_fx,           /* i  : predicted scaled innov. energy            */
     447             :     Word16 *pitch_buf_fx,              /* o  : Word16 pitch values for each subframe   */
     448             :     Word16 *code_fx,                   /* o  : innovation                                */
     449             :     Word16 *exc_fx,                    /* i/o: adapt. excitation exc                     */
     450             :     Word16 *bwe_exc_fx,                /* o  : excitation for SWB TBE                    */
     451             :     const Word16 nb_subfr_fx,          /* i  : Number of subframe considered             */
     452             :     Word16 *gain_buf,                  /*Q14*/
     453             :     const Word16 tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag          */
     454             :     const Word16 tdm_Pri_pitch_buf[]   /* i  : primary channel pitch buffer              */
     455             : )
     456             : {
     457             :     Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables    */
     458             :     Word16 gain_pit_fx;                             /* pitch gain               Q14                            */
     459             :     Word32 gain_code_fx;                            /* gain/normalized gain of the algebraic excitation Q16      */
     460             :     Word32 norm_gain_code_fx;                       /* normalized gain of the algebraic excitation        Q16   */
     461             :     Word16 gain_inov_fx;                            /* Innovation gain  Q12                                      */
     462             :     Word16 voice_fac_fx;                            /* voicing factor  Q15                                      */
     463             :     Word16 L_subfr_fx, pit_idx_fx;
     464             :     const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12                      */
     465             :     Word16 *pt_pitch_fx;   /* pointer to Word16 pitch     Q6                        */
     466             :     Word16 i_subfr_fx, i;  /* tmp variables                                         */
     467             :     Word32 Local_BR_fx, Pitch_BR_fx;
     468             :     Word16 pitch_limit_flag, Pitch_CT_fx;
     469             :     Word16 *pt_gain; /* Pointer to Word16 gain values for each subframe     */
     470             : 
     471             :     Word16 gain_code16, gain_pitx2;
     472             :     Word32 L_tmp;
     473             :     Word16 nbits;
     474             :     GSC_DEC_HANDLE hGSCDec;
     475       11717 :     gain_pit_fx = 0;
     476       11717 :     move16();
     477       11717 :     hGSCDec = st_fx->hGSCDec;
     478             : 
     479             :     MUSIC_POSTFILT_HANDLE hMusicPF;
     480       11717 :     hMusicPF = st_fx->hMusicPF;
     481             : 
     482             :     Word16 use_fcb;
     483             :     Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes                    */
     484             :     Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes                   */
     485             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     486       11717 :     Flag Overflow = 0;
     487       11717 :     move32();
     488             : #endif
     489             : 
     490       11717 :     use_fcb = 0;
     491       11717 :     move16();
     492       11717 :     test();
     493       11717 :     test();
     494       11717 :     IF( ( st_fx->GSC_IVAS_mode > 0 ) && ( EQ_16( st_fx->GSC_noisy_speech, 1 ) || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) )
     495             :     {
     496          99 :         Local_BR_fx = ACELP_8k00;
     497          99 :         Pitch_CT_fx = GENERIC;
     498          99 :         Pitch_BR_fx = ACELP_8k00;
     499          99 :         move32();
     500          99 :         move32();
     501          99 :         move16();
     502          99 :         IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     503             :         {
     504           0 :             Local_BR_fx = ACELP_14k80;
     505           0 :             move32();
     506           0 :             if ( st_fx->GSC_IVAS_mode > 0 )
     507             :             {
     508           0 :                 Local_BR_fx = ACELP_9k60;
     509           0 :                 move32();
     510             :             }
     511           0 :             Pitch_BR_fx = st_fx->core_brate;
     512           0 :             move32();
     513             :         }
     514             :     }
     515       11618 :     ELSE IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) )
     516             :     {
     517         695 :         Local_BR_fx = ACELP_7k20;
     518         695 :         move32();
     519         695 :         Pitch_CT_fx = GENERIC;
     520         695 :         move16();
     521         695 :         Pitch_BR_fx = ACELP_7k20;
     522         695 :         move32();
     523         695 :         if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     524             :         {
     525           0 :             Pitch_BR_fx = st_fx->core_brate;
     526           0 :             move32();
     527             :         }
     528             :     }
     529             :     ELSE
     530             :     {
     531       10923 :         Local_BR_fx = ACELP_7k20;
     532       10923 :         move32();
     533       10923 :         Pitch_CT_fx = AUDIO;
     534       10923 :         move16();
     535       10923 :         Pitch_BR_fx = st_fx->core_brate;
     536       10923 :         move32();
     537       10923 :         IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
     538             :         {
     539        1024 :             Pitch_BR_fx = ACELP_13k20;
     540        1024 :             move32();
     541        1024 :             Pitch_CT_fx = GENERIC;
     542        1024 :             move16();
     543             :         }
     544             :     }
     545       11717 :     L_subfr_fx = mult_r( st_fx->L_frame, div_s( 1, nb_subfr_fx ) ); /* TV2Opt : this could be less complex with 2 ifs*/
     546             : 
     547             : 
     548       11717 :     gain_code_fx = 0;
     549       11717 :     move16();
     550       11717 :     pitch_limit_flag = 1;
     551       11717 :     move16(); /* always extended pitch Q range */
     552       11717 :     test();
     553       11717 :     test();
     554       11717 :     test();
     555       11717 :     test();
     556       11717 :     test();
     557       11717 :     test();
     558       11717 :     IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) )
     559             :     {
     560         695 :         use_fcb = 1;
     561         695 :         move16();
     562             :     }
     563       11022 :     ELSE IF( ( st_fx->GSC_IVAS_mode > 0 ) && EQ_16( L_subfr_fx, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) )
     564             :     {
     565        1822 :         use_fcb = 2;
     566        1822 :         st_fx->acelp_cfg.fcb_mode = 1;
     567        1822 :         move16();
     568        1822 :         move16();
     569        1822 :         set16_fx( st_fx->acelp_cfg.gains_mode, 6, 4 );
     570        1822 :         set16_fx( st_fx->acelp_cfg.pitch_bits, 9, 4 );
     571        1822 :         set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, 5 );
     572             :     }
     573             : 
     574             :     /*------------------------------------------------------------------*
     575             :      * ACELP subframe loop
     576             :      *------------------------------------------------------------------*/
     577             : 
     578       11717 :     p_Aq_fx = Aq_fx;            /* pointer to interpolated LPC parameters */
     579       11717 :     pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
     580       11717 :     pt_gain = gain_buf;         /* pointer to the gain buffer  */
     581       35026 :     FOR( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx )
     582             :     {
     583             :         /*----------------------------------------------------------------------*
     584             :          *  Decode pitch lag
     585             :          *----------------------------------------------------------------------*/
     586             : 
     587       23309 :         *pt_pitch_fx = pit_decode_ivas_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
     588       23309 :         move16();
     589             : 
     590             :         /*--------------------------------------------------------------*
     591             :          * Find the adaptive codebook vector.
     592             :          *--------------------------------------------------------------*/
     593             : 
     594       23309 :         pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     595             : 
     596             :         /*--------------------------------------------------------------*
     597             :          * Innovation decoding
     598             :          *--------------------------------------------------------------*/
     599             : 
     600       23309 :         IF( EQ_16( use_fcb, 1 ) )
     601             :         {
     602        2780 :             inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx );
     603             : 
     604             :             /*--------------------------------------------------------------*
     605             :              * Gain decoding
     606             :              * Estimate spectrum tilt and voicing
     607             :              *--------------------------------------------------------------*/
     608             : 
     609        2780 :             gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
     610             : 
     611        2780 :             st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 );
     612        2780 :             move16();
     613             :         }
     614       20529 :         ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */
     615             :         {
     616             :             /*inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx);*/
     617        3644 :             inov_decode_fx( st_fx, st_fx->core_brate, 0, st_fx->L_frame, 0, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx );
     618             : 
     619             :             /*--------------------------------------------------------------*
     620             :              * Gain decoding
     621             :              * Estimate spectrum tilt and voicing
     622             :              *--------------------------------------------------------------*/
     623             : 
     624        3644 :             gain_dec_lbr_ivas_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx );
     625             : 
     626        3644 :             st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 );
     627        3644 :             move16();
     628             :         }
     629             :         ELSE
     630             :         {
     631       16885 :             nbits = 5;
     632       16885 :             move16();
     633       16885 :             if ( LT_32( st_fx->core_brate, MIN_RATE_FCB ) )
     634             :             {
     635       16570 :                 nbits = 4;
     636       16570 :                 move16();
     637             :             }
     638             : 
     639       16885 :             set16_fx( code_fx, 0, L_SUBFR );
     640       16885 :             gain_code_fx = L_deposit_l( 0 );
     641       16885 :             st_fx->tilt_code_fx = 0;
     642       16885 :             move16();
     643       16885 :             pit_idx_fx = (Word16) get_next_indice_fx( st_fx, nbits );
     644       16885 :             move16();
     645             : 
     646       16885 :             gain_pit_fx = add( 9590, dic_gp_fx[pit_idx_fx] ); /*Q14  0.5853 in Q14 9590*/
     647             : 
     648       16885 :             if ( st_fx->BER_detect ) /* Bitstream is corrupted, use the past pitch gain */
     649             :             {
     650           0 :                 gain_pit_fx = st_fx->lp_gainp_fx;
     651           0 :                 move16();
     652             :             }
     653       16885 :             gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 /*0.5.Q15*/ ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/
     654             :         }
     655             : 
     656             :         /*----------------------------------------------------------------------*
     657             :          * Find the total excitation
     658             :          *----------------------------------------------------------------------*/
     659       23309 :         Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx,
     660       23309 :                      L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type );
     661             : 
     662       23309 :         gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
     663             : 
     664       23309 :         IF( NE_16( use_fcb, 0 ) )
     665             :         {
     666      650776 :             FOR( i = 0; i < L_subfr_fx; i++ )
     667             :             {
     668      644352 :                 L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 );         /*Q16+Q_exc*/
     669      644352 :                 L_tmp = L_add_sat( L_tmp, L_shl_sat( L_mult( gain_code16, code_fx[i] ), 6 ) ); /*Q16+Q_exc*/
     670      644352 :                 exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp );                                /*Q_exc*/
     671      644352 :                 move16();
     672      644352 :                 move16();
     673             :             }
     674             :         }
     675             :         ELSE
     676             :         {
     677       16885 :             IF( norm_s( s_or( gain_pit_fx, 1 ) ) == 0 )
     678             :             {
     679      257225 :                 FOR( i = 0; i < L_subfr_fx; i++ )
     680             :                 {
     681      254336 :                     L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/
     682      254336 :                     exc_fx[i + i_subfr_fx] = round_fx( L_tmp );                        /*Q_exc*/
     683      254336 :                     move16();
     684             :                 }
     685             :             }
     686             :             ELSE
     687             :             {
     688       13996 :                 gain_pitx2 = shl( gain_pit_fx, 1 ); /*Q15*/
     689             : 
     690     2180396 :                 FOR( i = 0; i < L_subfr_fx; i++ )
     691             :                 {
     692     2166400 :                     L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/
     693     2166400 :                     exc_fx[i + i_subfr_fx] = round_fx( L_tmp );           /*Q_exc*/
     694     2166400 :                     move16();
     695             :                 }
     696             :             }
     697             :         }
     698             : 
     699       23309 :         IF( EQ_16( L_subfr_fx, L_FRAME16k ) )
     700             :         {
     701             :             /* update gains for FEC - equivalent to lp_gain_updt() */
     702        1024 :             st_fx->lp_gainp_fx = gain_pit_fx;
     703        1024 :             move16();
     704        1024 :             st_fx->lp_gainc_fx = 0;
     705        1024 :             move32();
     706             : 
     707        1024 :             pt_pitch_fx++;
     708        1024 :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     709        1024 :             pt_pitch_fx++;
     710        1024 :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     711        1024 :             pt_pitch_fx++;
     712        1024 :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     713        1024 :             pt_pitch_fx++;
     714        1024 :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     715        1024 :             pt_pitch_fx++;
     716        1024 :             move16();
     717        1024 :             move16();
     718        1024 :             move16();
     719        1024 :             move16();
     720        1024 :             p_Aq_fx += 5 * ( M + 1 );
     721             :         }
     722       22285 :         ELSE IF( EQ_16( L_subfr_fx, L_FRAME16k / 2 ) )
     723             :         {
     724           0 :             IF( i_subfr_fx == 0 )
     725             :             {
     726           0 :                 pt_pitch_fx++;
     727           0 :                 *pt_pitch_fx = *( pt_pitch_fx - 1 );
     728           0 :                 pt_pitch_fx++;
     729           0 :                 p_Aq_fx += 2 * ( M + 1 );
     730           0 :                 move16();
     731             : 
     732             :                 /* update gains for FEC - equivalent to lp_gain_updt() */
     733           0 :                 st_fx->lp_gainp_fx = extract_h( L_mult( 6554, gain_pit_fx ) ); /*Q14 (3/15 in Q15 9830)*/
     734           0 :                 st_fx->lp_gainc_fx = 0;
     735           0 :                 move16();
     736           0 :                 move16();
     737             :             }
     738             :             ELSE
     739             :             {
     740           0 :                 pt_pitch_fx++;
     741           0 :                 *pt_pitch_fx = *( pt_pitch_fx - 1 );
     742           0 :                 pt_pitch_fx++;
     743           0 :                 *pt_pitch_fx = *( pt_pitch_fx - 1 );
     744           0 :                 pt_pitch_fx++;
     745           0 :                 p_Aq_fx += 3 * ( M + 1 );
     746           0 :                 move16();
     747           0 :                 move16();
     748             : 
     749             :                 /* update gains for FEC - equivalent to lp_gain_updt() */
     750           0 :                 st_fx->lp_gainp_fx = extract_h( L_mult( 26214, gain_pit_fx ) ); /*Q14 (12/15 in Q15 9830)*/
     751           0 :                 st_fx->lp_gainc_fx = 0;
     752           0 :                 move16();
     753           0 :                 move16();
     754             :             }
     755             :         }
     756       22285 :         ELSE IF( EQ_16( L_subfr_fx, 128 ) ) /*2*L_SUBFR*/
     757             :         {
     758        5178 :             p_Aq_fx += 2 * ( M + 1 );
     759        5178 :             move16();
     760        5178 :             pt_pitch_fx++;
     761        5178 :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     762        5178 :             move16();
     763        5178 :             pt_pitch_fx++;
     764        5178 :             *pt_gain = gain_pit_fx;
     765        5178 :             move16();
     766        5178 :             pt_gain++;
     767        5178 :             *pt_gain = *( pt_gain - 1 );
     768        5178 :             move16();
     769        5178 :             pt_gain++;
     770        5178 :             IF( i_subfr_fx == 0 )
     771             :             {
     772             :                 /* update gains for FEC - equivalent to lp_gain_updt() */
     773        2589 :                 st_fx->lp_gainp_fx = extract_h( L_mult( 9830, gain_pit_fx ) ); /*Q14 (3/10 in Q15 9830)*/
     774        2589 :                 st_fx->lp_gainc_fx = 0;
     775        2589 :                 move16();
     776        2589 :                 move16();
     777             :             }
     778             :             ELSE
     779             :             {
     780             :                 /* update gains for FEC - equivalent to lp_gain_updt() */
     781        2589 :                 st_fx->lp_gainp_fx = extract_h( L_mult( 22938, gain_pit_fx ) ); /*Q14 (7/10 in Q15 22938)*/
     782        2589 :                 st_fx->lp_gainc_fx = 0;
     783        2589 :                 move16();
     784        2589 :                 move16();
     785             :             }
     786             :         }
     787       17107 :         ELSE IF( EQ_16( L_subfr_fx, 256 ) ) /*4*L_SUBFR*/
     788             :         {
     789        5103 :             pt_pitch_fx++;
     790        5103 :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     791        5103 :             move16();
     792        5103 :             pt_pitch_fx++;
     793        5103 :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     794        5103 :             move16();
     795        5103 :             pt_pitch_fx++;
     796        5103 :             *pt_pitch_fx = *( pt_pitch_fx - 1 );
     797        5103 :             move16();
     798        5103 :             pt_pitch_fx++;
     799        5103 :             *pt_gain = gain_pit_fx;
     800        5103 :             move16();
     801        5103 :             pt_gain++;
     802        5103 :             *pt_gain = *( pt_gain - 1 );
     803        5103 :             move16();
     804        5103 :             pt_gain++;
     805        5103 :             *pt_gain = *( pt_gain - 1 );
     806        5103 :             move16();
     807        5103 :             pt_gain++;
     808        5103 :             *pt_gain = *( pt_gain - 1 );
     809        5103 :             move16();
     810        5103 :             pt_gain++;
     811        5103 :             p_Aq_fx += 4 * ( M + 1 );
     812             : 
     813             :             /* update gains for FEC - equivalent to lp_gain_updt() */
     814        5103 :             st_fx->lp_gainp_fx = gain_pit_fx; // Q14
     815        5103 :             move16();
     816        5103 :             st_fx->lp_gainc_fx = 0;
     817        5103 :             move16();
     818             :         }
     819             :         ELSE
     820             :         {
     821       12004 :             p_Aq_fx += ( M + 1 );
     822       12004 :             pt_pitch_fx++;
     823       12004 :             *pt_gain = gain_pit_fx;
     824       12004 :             move16();
     825       12004 :             pt_gain++;
     826             : 
     827       12004 :             lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame );
     828             :         }
     829             :     }
     830             : 
     831       11717 :     return;
     832             : }

Generated by: LCOV version 1.14