LCOV - code coverage report
Current view: top level - lib_enc - enc_uv_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ cede165d26d1b794bfc5f5f6f9ec19d4d64a9a3b Lines: 90 185 48.6 %
Date: 2025-11-01 03:16:20 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <assert.h>
       6             : #include <stdint.h>
       7             : #include "options.h" /* Compilation switches                   */
       8             : #include "cnst.h"    /* Common constants                       */
       9             : #include "prot_fx.h" /* Function prototypes                    */
      10             : #include "rom_com.h"
      11             : #include "prot_fx_enc.h" /* Function prototypes                    */
      12             : 
      13             : 
      14             : /*-------------------------------------------------------------------*
      15             :  * encod_unvoiced()
      16             :  *
      17             :  * Encode unvoiced (UC) frames
      18             :  *-------------------------------------------------------------------*/
      19             : 
      20           0 : void encod_unvoiced_fx(
      21             :     Encoder_State *st_fx,           /* i/o: state structure                         */
      22             :     const Word16 *speech_fx,        /* i  : Input speech                                                        Q_new*/
      23             :     const Word16 Aw_fx[],           /* i  : weighted A(z) unquantized for subframes Q12*/
      24             :     const Word16 *Aq_fx,            /* i  : 12k8 Lp coefficient                     Q12*/
      25             :     const Word16 Es_pred,           /* i  : predicted scaled innov. energy          Q8*/
      26             :     const Word16 uc_two_stage_flag, /* i  : flag indicating two-stage UC            Q0*/
      27             :     const Word16 *res_fx,           /* i  : residual signal                         Q_new*/
      28             :     Word16 *syn_fx,                 /* o  : core synthesis                          Q_new -1 */
      29             :     Word16 *tmp_noise_fx,           /* o  : long-term noise energy                  Q0*/
      30             :     Word16 *exc_fx,                 /* i/o: current non-enhanced excitation         Q_new*/
      31             :     Word16 *pitch_buf_fx,           /* o  : floating pitch values for each subframe Q6*/
      32             :     Word16 *voice_factors_fx,       /* o  : voicing factors                         Q15*/
      33             :     Word16 *bwe_exc_fx,             /* i/o: excitation for SWB TBE                                      Q_exc*/
      34             :     const Word16 Q_new,
      35             :     const Word16 shift )
      36             : {
      37             :     Word16 xn_fx[L_SUBFR];   /* Target vector for pitch search     */
      38             :     Word16 h1_fx[L_SUBFR];   /* Impulse response vector            */
      39             :     Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation          */
      40             :     Word16 y2_fx[L_SUBFR];   /* Filtered algebraic excitation      */
      41             :     Word16 *pt_pitch_fx;     /* pointer to floating pitch buffer   */
      42             :     Word16 gain_pit_fx;      /* Pitch gain                         */
      43             :     Word16 voice_fac_fx;     /* Voicing factor                     */
      44             :     Word32 L_gain_code_fx;   /* gain of code                       */
      45             :     Word16 gain_inov_fx;     /* inovative gain                     */
      46             :     Word16 cn_fx[L_SUBFR];   /* Target vector in residual domain               */
      47             :     Word16 y1[L_SUBFR];      /* Filtered adaptive excitation                   */
      48             :     Word16 code2[L_SUBFR];   /* Gaussian excitation                            */
      49             :     Word16 y22[L_SUBFR];     /* Filtered Gaussian excitation                   */
      50           0 :     Word16 prm_t[2 * NPRM_DIV], *prm = prm_t;
      51             :     const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */
      52             :     Word32 norm_gain_code_fx;
      53             :     ACELP_config *acelp_cfg;
      54             :     ACELP_CbkCorr g_corr;
      55             :     Word32 gain_code2;
      56             :     Word32 gain_code_vect[2], Ltmp, Ltmp2;
      57             :     Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i;
      58             :     Word16 index, i_subfr_idx;
      59           0 :     acelp_cfg = &( st_fx->acelp_cfg );
      60           0 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
      61           0 :     LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
      62             : 
      63             :     /*------------------------------------------------------------------*
      64             :      * Initializations
      65             :      *------------------------------------------------------------------*/
      66           0 :     gain_pit_fx = 0;
      67           0 :     move16();
      68             : 
      69           0 :     test();
      70           0 :     test();
      71           0 :     test();
      72           0 :     IF( st_fx->Opt_SC_VBR && st_fx->vad_flag == 0 && ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) || EQ_16( hSC_VBR->last_nelp_mode, 1 ) ) )
      73             :     {
      74             :         /* SC_VBR - reset the encoder, to avoid memory not updated issue for the
      75             :            case when UNVOICED mode is used to code inactive speech */
      76           0 :         CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 1 );
      77             :     }
      78             : 
      79           0 :     p_Aw_fx = Aw_fx;
      80           0 :     p_Aq_fx = Aq_fx;
      81           0 :     pt_pitch_fx = pitch_buf_fx;
      82           0 :     move16();
      83           0 :     Q_xn = add( sub( Q_new, 1 ), shift );
      84           0 :     Q_new_p5 = add( Q_new, 5 );
      85             : 
      86           0 :     FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR )
      87             :     {
      88             :         /*----------------------------------------------------------------*
      89             :          * Bandwidth expansion of A(z) filter coefficients
      90             :          * Find the excitation search target "xn" and innovation target in residual domain "cn"
      91             :          * Compute impulse response, h1[], of weighted synthesis filter
      92             :          *----------------------------------------------------------------*/
      93             : 
      94           0 :         i_subfr_idx = shr( i_subfr, 6 );
      95           0 :         Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
      96             : 
      97           0 :         find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx,
      98           0 :                          res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx );
      99             : 
     100             :         /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/
     101           0 :         Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
     102             : 
     103             :         /* scaling of xn[] to limit dynamic at 12 bits */
     104           0 :         Scale_sig( xn_fx, L_SUBFR, shift );
     105             : 
     106             :         /*----------------------------------------------------------------*
     107             :          * Unvoiced subframe processing
     108             :          *----------------------------------------------------------------*/
     109             : 
     110           0 :         IF( !uc_two_stage_flag )
     111             :         {
     112           0 :             *pt_pitch_fx = gaus_encode_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx,
     113             :                                            &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx,
     114             :                                            &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); /* Q0 */
     115             :         }
     116             :         ELSE
     117             :         {
     118             :             /*----------------------------------------------------------------*
     119             :              * Unvoiced subframe processing in two stages
     120             :              *----------------------------------------------------------------*/
     121             : 
     122             :             /* No adaptive codebook (UC) */
     123           0 :             set16_fx( y1, 0, L_SUBFR );
     124           0 :             set16_fx( exc_fx + i_subfr, 0, L_SUBFR );
     125             : 
     126             :             /*-----------------------------------------------------------------*
     127             :              * Gain clipping test to avoid unstable synthesis on frame erasure
     128             :              * or in case of floating point encoder & fixed p. decoder
     129             :              *-----------------------------------------------------------------*/
     130             : 
     131           0 :             Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn );
     132           0 :             *pt_pitch_fx = L_SUBFR;
     133           0 :             move16();
     134             : 
     135             :             /*----------------------------------------------------------------------*
     136             :              *                 Encode the algebraic innovation                      *
     137             :              *----------------------------------------------------------------------*/
     138             : 
     139           0 :             E_ACELP_innovative_codebook_fx( exc_fx, *pt_pitch_fx, 0, 1, gain_pit_fx, hLPDmem->tilt_code, acelp_cfg, i_subfr, p_Aq_fx, h1_fx, xn_fx, cn_fx, y1, y2_fx, (Word8) st_fx->acelp_autocorr, &prm, code_fx, shift, st_fx->L_frame, st_fx->last_L_frame, st_fx->total_brate );
     140             : 
     141           0 :             E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn );
     142             : 
     143           0 :             g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 );             /* -18 (y2*y2: Q9*Q9) */
     144           0 :             g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) );   /* -(Q_xn+9) (xn: Q_xn y2: Q9) */
     145           0 :             g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */
     146           0 :             g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) );  /* -(Q_xn+Q_xn) (xn: Q_xn) */
     147             : 
     148           0 :             assert( gain_pit_fx == 0 );
     149           0 :             gauss_L2_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift );
     150             : 
     151             :             /*----------------------------------------------------------*
     152             :              *  - Compute the fixed codebook gain                       *
     153             :              *  - quantize fixed codebook gain                          *
     154             :              *----------------------------------------------------------*/
     155             : 
     156           0 :             index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2,
     157           0 :                                     st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); /* Q0 */
     158             : 
     159             : #ifdef DEBUGGING
     160             :             assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" );
     161             : #endif
     162           0 :             push_indice( st_fx->hBstr, IND_GAIN, index, st_fx->acelp_cfg.gains_mode[i_subfr_idx] );
     163             : 
     164           0 :             gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx );
     165             : 
     166           0 :             gain_code_vect[0] = L_gain_code_fx;
     167           0 :             move32();
     168           0 :             gain_code_vect[1] = L_gain_code_fx;
     169           0 :             move32();
     170             : 
     171             :             /*----------------------------------------------------------*
     172             :              * - voice factor (for pitch enhancement)                   *
     173             :              *----------------------------------------------------------*/
     174             : 
     175           0 :             E_UTIL_voice_factor( exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift );
     176             : 
     177           0 :             IF( st_fx->Opt_RF_ON )
     178             :             {
     179           0 :                 st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code;
     180             :             }
     181             : 
     182             :             /*-----------------------------------------------------------------*
     183             :              * Update memory of the weighting filter
     184             :              *-----------------------------------------------------------------*/
     185             : 
     186             :             /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */
     187           0 :             Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); /* Q10 */
     188           0 :             Ltmp = L_shl( Ltmp, add( 5, Q_xn ) );                     /* Q15 + Q_xn */
     189           0 :             Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx );       /* Q15 + Q_xn */
     190             :             /* Add Gaussian contribution*/
     191           0 :             Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] );                       /* Q10 */
     192           0 :             Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) );                                    /* Q15 + Q_xn */
     193           0 :             Ltmp = L_add( Ltmp, Ltmp2 );                                               /* Q15 + Q_xn */
     194           0 :             hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); /* Q_xn */
     195           0 :             move16();
     196             :             BASOP_SATURATE_WARNING_OFF_EVS;
     197           0 :             hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/
     198             :             BASOP_SATURATE_WARNING_ON_EVS;
     199             : 
     200             :             /*-------------------------------------------------------*
     201             :              * - Find the total excitation.                          *
     202             :              *-------------------------------------------------------*/
     203             : 
     204           0 :             tmp2 = shr( L_SUBFR, 1 );
     205           0 :             FOR( j = 0; j < 2; j++ )
     206             :             {
     207           0 :                 FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ )
     208             :                 {
     209             :                     /* code in Q9, gain_pit in Q14; exc Q_new */
     210           0 :                     Ltmp = Mpy_32_16_1( gain_code2, code2[i] );             /* Q10 */
     211           0 :                     Ltmp = L_shl( Ltmp, Q_new_p5 );                         /* Q15 + Q_new */
     212           0 :                     Ltmp = L_mac( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); /* Q_new + Q15 */
     213           0 :                     Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] );   /* Q10 */
     214           0 :                     Ltmp2 = L_shl( Ltmp2, Q_new_p5 );                       /* Q15 + Q_new */
     215           0 :                     Ltmp = L_add( Ltmp, Ltmp2 );                            /* Q15 + Q_new */
     216           0 :                     Ltmp = L_shl_sat( Ltmp, 1 );                            /* saturation can occur here        Q16 + Q_new */
     217           0 :                     exc_fx[i + i_subfr] = round_fx_sat( Ltmp );             /* Q_new */
     218             :                 }
     219           0 :                 tmp2 = L_SUBFR;
     220           0 :                 move16();
     221             :             }
     222             :         }
     223             : 
     224           0 :         *tmp_noise_fx = extract_h( norm_gain_code_fx ); /* Q0 */
     225           0 :         voice_factors_fx[i_subfr / L_SUBFR] = 0;
     226           0 :         move16();
     227             : 
     228           0 :         interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR );
     229             : 
     230             :         /*-----------------------------------------------------------------*
     231             :          * Synthesize speech to update mem_syn[].
     232             :          * Update A(z) filters
     233             :          *-----------------------------------------------------------------*/
     234             : 
     235           0 :         Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 );
     236             : 
     237           0 :         p_Aw_fx += ( M + 1 );
     238           0 :         p_Aq_fx += ( M + 1 );
     239           0 :         pt_pitch_fx++;
     240             :     }
     241             : 
     242             :     /* SC-VBR */
     243           0 :     hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */
     244           0 :     move16();
     245           0 :     hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
     246           0 :     move16();
     247             : 
     248           0 :     return;
     249             : }
     250             : 
     251             : 
     252        2015 : void encod_unvoiced_ivas_fx(
     253             :     Encoder_State *st_fx,           /* i/o: state structure                         */
     254             :     const Word16 *speech_fx,        /* i  : Input speech                                                        Q_new*/
     255             :     const Word16 Aw_fx[],           /* i  : weighted A(z) unquantized for subframes Q12*/
     256             :     const Word16 *Aq_fx,            /* i  : 12k8 Lp coefficient                                         Q12*/
     257             :     const Word16 Es_pred,           /* i  : predicted scaled innov. energy          Q8*/
     258             :     const Word16 uc_two_stage_flag, /* i  : flag indicating two-stage UC            Q0*/
     259             :     const Word16 *res_fx,           /* i  : residual signal                         Q_new*/
     260             :     Word16 *syn_fx,                 /* o  : core synthesis                          Q_new*/
     261             :     Word16 *tmp_noise_fx,           /* o  : long-term noise energy                  Q0*/
     262             :     Word16 *exc_fx,                 /* i/o: current non-enhanced excitation         Q_new*/
     263             :     Word16 *pitch_buf_fx,           /* o  : floating pitch values for each subframe Q6*/
     264             :     Word16 *voice_factors_fx,       /* o  : voicing factors                         Q15*/
     265             :     Word16 *bwe_exc_fx,             /* i/o: excitation for SWB TBE                                      Q_exc*/
     266             :     const Word16 Q_new,
     267             :     const Word16 shift )
     268             : {
     269             :     Word16 xn_fx[L_SUBFR];   /* Target vector for pitch search     */
     270             :     Word16 h1_fx[L_SUBFR];   /* Impulse response vector            */
     271             :     Word16 h2_fx[L_SUBFR];   /* Impulse response vector            */
     272             :     Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation          */
     273             :     Word16 y2_fx[L_SUBFR];   /* Filtered algebraic excitation      */
     274             :     Word16 *pt_pitch_fx;     /* pointer to floating pitch buffer   */
     275             :     Word16 gain_pit_fx;      /* Pitch gain                         */
     276             :     Word16 voice_fac_fx;     /* Voicing factor                     */
     277             :     Word32 L_gain_code_fx;   /* gain of code                       */
     278             :     Word16 gain_inov_fx;     /* inovative gain                     */
     279             :     Word16 cn_fx[L_SUBFR];   /* Target vector in residual domain               */
     280             :     Word16 y1[L_SUBFR];      /* Filtered adaptive excitation                   */
     281             :     Word16 code2[L_SUBFR];   /* Gaussian excitation                            */
     282             :     Word16 y22[L_SUBFR];     /* Filtered Gaussian excitation                   */
     283             :     // Word16 prm_t[2 * NPRM_DIV], *prm = prm_t;
     284             :     const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */
     285             :     Word32 norm_gain_code_fx;
     286             :     ACELP_config *acelp_cfg;
     287             :     ACELP_CbkCorr g_corr;
     288             :     Word32 gain_code2;
     289             :     Word32 gain_code_vect[2], Ltmp, Ltmp2;
     290             :     Word16 i_subfr, Q_xn, Q_new_p5, tmp2, j, i;
     291             :     Word16 index, i_subfr_idx;
     292             :     Word16 unbits_PI;
     293             :     Word16 q_h1;
     294        2015 :     acelp_cfg = &( st_fx->acelp_cfg );
     295        2015 :     SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
     296        2015 :     LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
     297             : 
     298             :     /*------------------------------------------------------------------*
     299             :      * Initializations
     300             :      *------------------------------------------------------------------*/
     301             : 
     302        2015 :     gain_pit_fx = 0;
     303        2015 :     move16();
     304             : 
     305        2015 :     test();
     306        2015 :     test();
     307        2015 :     test();
     308        2015 :     IF( st_fx->Opt_SC_VBR && st_fx->vad_flag == 0 && ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) || EQ_16( hSC_VBR->last_nelp_mode, 1 ) ) )
     309             :     {
     310             :         /* SC_VBR - reset the encoder, to avoid memory not updated issue for the
     311             :            case when UNVOICED mode is used to code inactive speech */
     312           0 :         CNG_reset_enc_fx( st_fx, hLPDmem, pitch_buf_fx, voice_factors_fx, 1 );
     313             :     }
     314             : 
     315        2015 :     p_Aw_fx = Aw_fx;
     316        2015 :     p_Aq_fx = Aq_fx;
     317        2015 :     pt_pitch_fx = pitch_buf_fx;
     318        2015 :     Q_xn = add( sub( Q_new, 1 ), shift );
     319        2015 :     Q_new_p5 = add( Q_new, 5 );
     320             : 
     321       10075 :     FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR )
     322             :     {
     323             :         /*----------------------------------------------------------------*
     324             :          * Bandwidth expansion of A(z) filter coefficients
     325             :          * Find the excitation search target "xn" and innovation target in residual domain "cn"
     326             :          * Compute impulse response, h1[], of weighted synthesis filter
     327             :          *----------------------------------------------------------------*/
     328             : 
     329        8060 :         i_subfr_idx = shr( i_subfr, 6 );
     330        8060 :         Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
     331             : 
     332        8060 :         find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx,
     333        8060 :                               res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx );
     334             : 
     335        8060 :         q_h1 = sub( 14, norm_s( h1_fx[0] ) );
     336        8060 :         Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, sub( 11, q_h1 ) );
     337        8060 :         Scale_sig( h1_fx, L_SUBFR, sub( 14, q_h1 ) );
     338             : 
     339             :         /* scaling of xn[] to limit dynamic at 12 bits */
     340        8060 :         Scale_sig( xn_fx, L_SUBFR, shift ); // Q_new - 1 + shift
     341             : 
     342             :         /*----------------------------------------------------------------*
     343             :          * Unvoiced subframe processing
     344             :          *----------------------------------------------------------------*/
     345             : 
     346        8060 :         IF( !uc_two_stage_flag )
     347             :         {
     348           0 :             *pt_pitch_fx = gaus_encode_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx,
     349             :                                            &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx,
     350             :                                            &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); /* Q0 */
     351           0 :             move16();
     352             :         }
     353             :         ELSE
     354             :         {
     355             :             /*----------------------------------------------------------------*
     356             :              * Unvoiced subframe processing in two stages
     357             :              *----------------------------------------------------------------*/
     358             : 
     359             :             // PMT("The code below needs validation, never been tested")
     360             :             /* No adaptive codebook (UC) */
     361        8060 :             set16_fx( y1, 0, L_SUBFR );
     362        8060 :             set16_fx( exc_fx + i_subfr, 0, L_SUBFR );
     363             : 
     364             :             /*-----------------------------------------------------------------*
     365             :              * Gain clipping test to avoid unstable synthesis on frame erasure
     366             :              * or in case of floating point encoder & fixed p. decoder
     367             :              *-----------------------------------------------------------------*/
     368             : 
     369        8060 :             Mode2_gp_clip_fx( st_fx->voicing_fx, i_subfr, st_fx->coder_type, xn_fx, st_fx->clip_var_fx, L_SUBFR, Q_xn );
     370        8060 :             *pt_pitch_fx = L_SUBFR << 6;
     371        8060 :             move16();
     372             : 
     373             :             /*----------------------------------------------------------------------*
     374             :              *                 Encode the algebraic innovation                      *
     375             :              *----------------------------------------------------------------------*/
     376             : 
     377        8060 :             inov_encode_ivas_fx( st_fx, st_fx->core_brate, 0, L_FRAME, st_fx->last_L_frame,
     378        8060 :                                  UNVOICED, st_fx->bwidth, 1, i_subfr, -1, p_Aq_fx,
     379        8060 :                                  gain_pit_fx, cn_fx, exc_fx, h2_fx, hLPDmem->tilt_code, *pt_pitch_fx, xn_fx, code_fx, y2_fx, &unbits_PI, L_SUBFR, shift, Q_new );
     380             : 
     381        8060 :             E_ACELP_xy2_corr( xn_fx, y1, y2_fx, &g_corr, L_SUBFR, Q_xn );
     382             : 
     383        8060 :             g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 );             /* -18 (y2*y2: Q9*Q9) */
     384        8060 :             g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) );   /* -(Q_xn+9) (xn: Q_xn y2: Q9) */
     385        8060 :             g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */
     386        8060 :             g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) );  /* -(Q_xn+Q_xn) (xn: Q_xn) */
     387        8060 :             move16();
     388        8060 :             move16();
     389        8060 :             move16();
     390        8060 :             move16();
     391             : 
     392        8060 :             assert( gain_pit_fx == 0 );
     393        8060 :             gauss_L2_ivas_fx( h1_fx, code2, y2_fx, y22, &gain_code2, &g_corr, gain_pit_fx, hLPDmem->tilt_code, p_Aq_fx, acelp_cfg->formant_enh_num, &( st_fx->seed_acelp ), shift );
     394             : 
     395             :             /*----------------------------------------------------------*
     396             :              *  - Compute the fixed codebook gain                       *
     397             :              *  - quantize fixed codebook gain                          *
     398             :              *----------------------------------------------------------*/
     399             : 
     400        8060 :             index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2,
     401        8060 :                                     st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); /* Q0 */
     402             : 
     403             : #ifdef DEBUGGING
     404             :             assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" );
     405             : #endif
     406        8060 :             push_indice( st_fx->hBstr, IND_GAIN, index, st_fx->acelp_cfg.gains_mode[i_subfr_idx] );
     407             : 
     408        8060 :             gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx );
     409             : 
     410        8060 :             gain_code_vect[0] = L_gain_code_fx;
     411        8060 :             move32();
     412        8060 :             gain_code_vect[1] = L_gain_code_fx;
     413        8060 :             move32();
     414             : 
     415             :             /*----------------------------------------------------------*
     416             :              * - voice factor (for pitch enhancement)                   *
     417             :              *----------------------------------------------------------*/
     418             : 
     419        8060 :             E_UTIL_voice_factor( exc_fx, i_subfr, code_fx, gain_pit_fx, L_gain_code_fx, &voice_fac_fx, &( hLPDmem->tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift );
     420             : 
     421        8060 :             if ( st_fx->Opt_RF_ON )
     422             :             {
     423           0 :                 st_fx->hRF->rf_tilt_buf[i_subfr_idx] = hLPDmem->tilt_code;
     424           0 :                 move16();
     425             :             }
     426             :             /*-----------------------------------------------------------------*
     427             :              * Update memory of the weighting filter
     428             :              *-----------------------------------------------------------------*/
     429             : 
     430             :             /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */
     431        8060 :             Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); /* Q10 */
     432        8060 :             Ltmp = L_shl( Ltmp, add( 5, Q_xn ) );                     // Qxn+15
     433        8060 :             Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx );       /* Qxn + Q15 */
     434             :             /* Add Gaussian contribution*/
     435        8060 :             Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] );                       /* Q10 */
     436        8060 :             Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) );                                    // Q_xn+15
     437        8060 :             Ltmp = L_add( Ltmp, Ltmp2 );                                               /* Qxn + Q15 */
     438        8060 :             hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); // Q_xn
     439        8060 :             move16();
     440             :             BASOP_SATURATE_WARNING_OFF_EVS;
     441        8060 :             hLPDmem->mem_w0 = shr_sat( hLPDmem->mem_w0, shift ); /*Qnew-1*/
     442        8060 :             move16();
     443             :             BASOP_SATURATE_WARNING_ON_EVS;
     444             : 
     445             :             /*-------------------------------------------------------*
     446             :              * - Find the total excitation.                          *
     447             :              *-------------------------------------------------------*/
     448             : 
     449        8060 :             tmp2 = shr( L_SUBFR, 1 );
     450       24180 :             FOR( j = 0; j < 2; j++ )
     451             :             {
     452      531960 :                 FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ )
     453             :                 {
     454             :                     /* code in Q9, gain_pit in Q14; exc Q_new */
     455      515840 :                     Ltmp = Mpy_32_16_1( gain_code2, code2[i] );                 /* Q10 */
     456      515840 :                     Ltmp = L_shl_sat( Ltmp, Q_new_p5 );                         /* Q15 + Q_new */
     457      515840 :                     Ltmp = L_mac_sat( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); /* Q15 + Q_new */
     458      515840 :                     Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] );       /* Q10 */
     459      515840 :                     Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 );                       /* Q15 + Q_new */
     460      515840 :                     Ltmp = L_add_sat( Ltmp, Ltmp2 );                            /* Q15 + Q_new */
     461      515840 :                     Ltmp = L_shl_sat( Ltmp, 1 );                                /* saturation can occur here    Q16 + Q_new */
     462      515840 :                     exc_fx[i + i_subfr] = round_fx_sat( Ltmp );                 /* Q_new */
     463      515840 :                     move16();
     464             :                 }
     465       16120 :                 tmp2 = L_SUBFR;
     466       16120 :                 move16();
     467             :             }
     468             :         }
     469             : 
     470        8060 :         *tmp_noise_fx = extract_h( norm_gain_code_fx );
     471        8060 :         move16();
     472        8060 :         voice_factors_fx[i_subfr / L_SUBFR] = 0;
     473        8060 :         move16();
     474             : 
     475        8060 :         if ( st_fx->hBWE_TD != NULL )
     476             :         {
     477        8060 :             interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR );
     478             :         }
     479             : 
     480             :         /*-----------------------------------------------------------------*
     481             :          * Synthesize speech to update mem_syn[].
     482             :          * Update A(z) filters
     483             :          *-----------------------------------------------------------------*/
     484             : 
     485        8060 :         Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 );
     486             : 
     487        8060 :         p_Aw_fx += ( M + 1 );
     488        8060 :         p_Aq_fx += ( M + 1 );
     489        8060 :         pt_pitch_fx++;
     490             :     }
     491             : 
     492             :     /* SC-VBR */
     493        2015 :     IF( hSC_VBR )
     494             :     {
     495           0 :         hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */
     496           0 :         move16();
     497           0 :         hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
     498           0 :         move16();
     499             :     }
     500             : 
     501        2015 :     return;
     502             : }

Generated by: LCOV version 1.14