LCOV - code coverage report
Current view: top level - lib_enc - enc_gen_voic_rf_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ cede165d26d1b794bfc5f5f6f9ec19d4d64a9a3b Lines: 71 235 30.2 %
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 <stdint.h>
       6             : #include "options.h"
       7             : #include "cnst.h"
       8             : #include "stl.h"
       9             : #include "rom_basop_util.h"
      10             : #include "rom_com.h"     /* Common constants                       */
      11             : #include "prot_fx.h"     /* Function prototypes                    */
      12             : #include "prot_fx_enc.h" /* Function prototypes                    */
      13             : #include "basop_util.h"  /* Function prototypes                    */
      14             : 
      15             : 
      16      173318 : void reset_rf_indices_fx(
      17             :     Encoder_State *st /* i: state structure - contains partial RF indices */
      18             : )
      19             : {
      20      173318 :     RF_ENC_HANDLE hRF = st->hRF;
      21             :     Word16 i, j;
      22      173318 :     if ( hRF != NULL )
      23             :     {
      24        2479 :         hRF->rf_frame_type = 0; /* since this function is called every frame this will happen even for a SID frame, hence treating it as GSC frame, i.e no RF encoding */
      25        2479 :         hRF->rf_mem_w0 = 0;
      26        2479 :         move16();
      27        2479 :         st->rf_target_bits_write = 0;
      28        2479 :         move16();
      29        2479 :         set16_fx( hRF->rf_clip_var, 0, 6 );
      30        2479 :         hRF->rf_tilt_code = 0;
      31        2479 :         move16();
      32        2479 :         set16_fx( hRF->rf_mem_syn2, 0, M );
      33        2479 :         hRF->rf_dm_fx.prev_state = 0;
      34        2479 :         move16();
      35        2479 :         hRF->rf_dm_fx.prev_gain_code = 0;
      36        2479 :         move32();
      37             : 
      38       17353 :         FOR( i = 0; i < 6; i++ )
      39             :         {
      40       14874 :             hRF->rf_dm_fx.prev_gain_pit[i] = 0;
      41       14874 :             move16();
      42             :         }
      43             : 
      44        2479 :         hRF->rf_gc_threshold = 0;
      45        2479 :         move32();
      46        2479 :         set16_fx( hRF->rf_tilt_buf, 0, NB_SUBFR16k );
      47             : 
      48        2479 :         hRF->rf_target_bits = 0;
      49        2479 :         move16();
      50        2479 :         hRF->rf_tcxltp_pitch_int_past = st->L_frame; /* Q0 */
      51        2479 :         move16();
      52        2479 :         hRF->rf_last_tns_active = 0;
      53        2479 :         move16();
      54        2479 :         hRF->rf_second_last_tns_active = 0;
      55        2479 :         move16();
      56        2479 :         hRF->rf_second_last_core = 0;
      57        2479 :         move16();
      58             : 
      59       24790 :         FOR( i = 0; i < MAX_RF_FEC_OFFSET; i++ )
      60             :         {
      61       22311 :             hRF->rf_indx_frametype[i] = RF_NO_DATA;
      62       22311 :             move16(); /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */
      63       22311 :             hRF->rf_targetbits_buff[i] = 6;
      64       22311 :             move16();
      65       22311 :             hRF->rf_indx_lsf[i][0] = 0;
      66       22311 :             move16();
      67       22311 :             hRF->rf_indx_lsf[i][1] = 0;
      68       22311 :             move16();
      69       22311 :             hRF->rf_indx_lsf[i][2] = 0;
      70       22311 :             move16();
      71       22311 :             hRF->rf_indx_EsPred[i] = 0;
      72       22311 :             move16();
      73       22311 :             hRF->rf_indx_nelp_fid[i] = 0;
      74       22311 :             move16();
      75       22311 :             hRF->rf_indx_nelp_iG1[i] = 0;
      76       22311 :             move16();
      77       22311 :             hRF->rf_indx_nelp_iG2[i][0] = 0;
      78       22311 :             move16();
      79       22311 :             hRF->rf_indx_nelp_iG2[i][1] = 0;
      80       22311 :             move16();
      81             : 
      82      133866 :             FOR( j = 0; j < NB_SUBFR16k; j++ )
      83             :             {
      84      111555 :                 hRF->rf_indx_ltfMode[i][j] = 0;
      85      111555 :                 move16();
      86      111555 :                 hRF->rf_indx_pitch[i][j] = 0;
      87      111555 :                 move16();
      88      111555 :                 hRF->rf_indx_fcb[i][j] = 0;
      89      111555 :                 move16();
      90      111555 :                 hRF->rf_indx_gain[i][j] = 0;
      91      111555 :                 move16();
      92             :             }
      93             : 
      94       22311 :             hRF->rf_clas[i] = UNVOICED_CLAS;
      95       22311 :             move16();
      96       22311 :             hRF->rf_gain_tcx[i] = 0;
      97       22311 :             move16();
      98       22311 :             hRF->rf_tcxltp_param[i] = 0;
      99       22311 :             move16();
     100             : 
     101       22311 :             hRF->rf_indx_tbeGainFr[i] = 0;
     102       22311 :             move16();
     103             :         }
     104             :     }
     105             : 
     106      173318 :     return;
     107             : }
     108             : 
     109             : 
     110             : /*-------------------------------------------------------------------*
     111             :  * coder_acelp_rf_fx()
     112             :  *
     113             :  * Encode excitation signal (partial redundancy)
     114             :  *-------------------------------------------------------------------*/
     115           0 : void coder_acelp_rf_fx(
     116             :     ACELP_config *acelp_cfg, /*input/output: configuration of the ACELP coding*/
     117             :     const Word16 coder_type, /* input: coding type                                              Q0*/
     118             :     const Word16 A[],        /* input: coefficients 4xAz[M+1]                   Q12*/
     119             :     const Word16 Aq[],       /* input: coefficients 4xAz_q[M+1]                 Q12*/
     120             :     Word16 speech[],         /* input: speech[-M..lg]                                   Q_new-1*/
     121             :     const Word16 voicing[],  /* input: open-loop LTP gain                               Q15*/
     122             :     const Word16 T_op[],     /* input: open-loop LTP lag                                Q0*/
     123             :     Word16 stab_fac,         /* Q15 */
     124             :     Encoder_State *st,
     125             :     Word16 target_bits,         /* i/o : coder memory state                             Q0*/
     126             :     const Word16 rf_frame_type, /* i  : rf_frame_type                                   Q0*/
     127             :     Word16 *exc_rf,             /* i/o: pointer to RF excitation    Q_new*/
     128             :     Word16 *syn_rf,             /* i/o: pointer to RF synthesis     Q_new-1*/
     129             :     Word16 Q_new,
     130             :     Word16 shift )
     131             : {
     132             :     Word16 i, j, i_subfr, j_subfr;
     133             :     Word16 T0, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res;
     134             :     Word16 T0_frac;
     135             :     Word16 tmp2;
     136             :     Word16 gain_pit, voice_fac;
     137             :     Word32 gain_code, Ltmp, Ltmp2;
     138             :     ACELP_CbkCorr g_corr;
     139             :     const Word16 *p_A, *p_Aq;
     140             :     Word16 h1[L_SUBFR]; /* weighted impulse response of LP */
     141             :     Word16 code[L_SUBFR];
     142             :     Word16 xn_exp;
     143             :     Word16 Q_xn;
     144             :     Word16 Q_new_p5;
     145             :     Word16 cn[L_SUBFR];
     146             :     Word16 xn[L_SUBFR];
     147             :     Word16 y1[L_SUBFR]; /* Filtered adaptive excitation       */
     148             :     Word16 y2[L_SUBFR]; /* Filtered adaptive excitation       */
     149             :     Word16 res_save;
     150             :     Word16 exc_nelp[L_FRAME];
     151             :     Word16 exc2[L_SUBFR];
     152             :     Word16 syn2[L_DIV_MAX];
     153             :     Word16 gain_inov;
     154             :     Word32 past_gcode;
     155             :     Word16 L_frame;
     156             :     Word16 clip_gain;
     157             :     Word32 gain_code2;
     158             :     Word16 code2[L_SUBFR];
     159             :     Word16 y22[L_SUBFR]; /* Filtered adaptive excitation */
     160             :     Word32 gain_code_vect[2];
     161             :     Word16 *prm_rf;
     162             :     Word16 Es_pred_rf;
     163             :     Word16 nSubfr;
     164             :     Word16 prev_gain_pit;
     165             :     Word16 rf_coder_type;
     166             :     Word16 lp_select;
     167           0 :     RF_ENC_HANDLE hRF = st->hRF;
     168             : 
     169             :     /* to avoid compilation warnings */
     170           0 :     past_gcode = 0;
     171           0 :     gain_inov = 0;
     172           0 :     T0 = 0;
     173           0 :     T0_frac = 0;
     174           0 :     T0_res = 0;
     175           0 :     gain_pit = 0;
     176           0 :     gain_code = 0;
     177           0 :     voice_fac = 0;
     178           0 :     prev_gain_pit = 0;
     179           0 :     Es_pred_rf = 0;
     180           0 :     move32();
     181           0 :     move32();
     182           0 :     move16();
     183           0 :     move16();
     184           0 :     move16();
     185           0 :     move16();
     186           0 :     move16();
     187           0 :     move16();
     188           0 :     move16();
     189             : 
     190           0 :     set16_fx( code, 0, L_SUBFR );
     191             : 
     192             :     /*-----------------------------------------------------------------------*
     193             :      * Configure ACELP partial copy                                           *
     194             :      *------------------------------------------------------------------------*/
     195           0 :     tmp2 = BITS_ALLOC_config_acelp( target_bits, rf_frame_type, &( hRF->acelp_cfg_rf ), 0, st->nb_subfr ); /* Q0 */
     196             : 
     197             :     /* Init Framing parameters */
     198           0 :     L_frame = st->L_frame; /* Q0 */
     199           0 :     move16();
     200             :     /*------------------------------------------------------------------------*
     201             :      * Initialize buffers                                                     *
     202             :      *------------------------------------------------------------------------*/
     203             : 
     204             :     /* Rescale ACELP memories, which were not scaled yet*/
     205           0 :     xn_exp = sub( sub( 15 + 1, Q_new ), shift );
     206           0 :     Q_xn = add( sub( Q_new, 1 ), shift );
     207           0 :     Q_new_p5 = add( Q_new, 5 );
     208             : 
     209             :     /* Reset phase dispersion */
     210           0 :     IF( GT_16( st->last_core, ACELP_CORE ) )
     211             :     {
     212           0 :         hRF->rf_dm_fx.prev_gain_code = 0;
     213           0 :         set16_fx( hRF->rf_dm_fx.prev_gain_pit, 0, 6 );
     214           0 :         hRF->rf_dm_fx.prev_state = 0;
     215             :     }
     216             : 
     217             :     /* calculate residual */
     218           0 :     calc_residu_fx( st, speech, exc_rf, Aq );
     219             : 
     220             :     /*------------------------------------------------------------------------*
     221             :      * Find and quantize mean_ener_code for gain quantizer                    *
     222             :      *------------------------------------------------------------------------*/
     223             : 
     224           0 :     Es_pred_rf = 0;
     225           0 :     move16();
     226             : 
     227           0 :     test();
     228           0 :     IF( acelp_cfg->nrg_mode > 0 && NE_16( rf_frame_type, RF_NELP ) )
     229             :     {
     230           0 :         Es_pred_enc_fx( &Es_pred_rf, &hRF->rf_indx_EsPred[0], L_frame, exc_rf, voicing,
     231           0 :                         acelp_cfg->nrg_bits, extract_l( GT_16( acelp_cfg->nrg_mode, 1 ) ), Q_new );
     232             :     }
     233             : 
     234             :     /*------------------------------------------------------------------------*
     235             :      *          Loop for every subframe in the analysis frame                 *
     236             :      *------------------------------------------------------------------------*
     237             :      *  To find the pitch and innovation parameters. The subframe size is     *
     238             :      *  L_SUBFR and the loop is repeated L_FRAME_PLUS/L_SUBFR   *
     239             :      *  times.                                                                *
     240             :      *     - compute impulse response of weighted synthesis filter (h1[])     *
     241             :      *     - compute the target signal for pitch search                       *
     242             :      *     - find the closed-loop pitch parameters                            *
     243             :      *     - encode the pitch delay                                           *
     244             :      *     - update the impulse response h1[] by including fixed-gain pitch   *
     245             :      *     - find target vector for codebook search                           *
     246             :      *     - correlation between target vector and impulse response           *
     247             :      *     - codebook search                                                  *
     248             :      *     - encode codebook address                                          *
     249             :      *     - VQ of pitch and codebook gains                                   *
     250             :      *     - find synthesis speech                                            *
     251             :      *     - update states of weighting filter                                *
     252             :      *------------------------------------------------------------------------*/
     253           0 :     p_A = A;
     254           0 :     p_Aq = Aq;
     255             : 
     256           0 :     res_save = exc_rf[0];
     257           0 :     nSubfr = 0;
     258           0 :     j_subfr = 0;
     259             : 
     260           0 :     FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR )
     261             :     {
     262             : 
     263           0 :         IF( NE_16( rf_frame_type, RF_NELP ) )
     264             :         {
     265             :             /* Restore exc[i_subfr] and save next exc[L_SUBFR+i_subfr] */
     266           0 :             move16();
     267           0 :             move16();
     268           0 :             exc_rf[i_subfr] = res_save;
     269           0 :             res_save = exc_rf[L_SUBFR + i_subfr];
     270             : 
     271             :             /*--------------------------------------------------------------------------*
     272             :              * Find target for pitch search (xn[]), target for innovation search (cn[]) *
     273             :              * and impulse response of the weighted synthesis filter (h1[]).            *
     274             :              *--------------------------------------------------------------------------*/
     275           0 :             find_targets_fx( speech, &syn_rf[i_subfr - M], i_subfr, &( hRF->rf_mem_w0 ), p_Aq,
     276           0 :                              exc_rf, L_SUBFR, p_A, st->preemph_fac, xn, cn, h1 );
     277             : 
     278             :             /*---------------------------------------------------------------*
     279             :              * Compute impulse response, h1[], of weighted synthesis filter  *
     280             :              *---------------------------------------------------------------*/
     281           0 :             Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* Q13+1-shift */
     282             : 
     283             :             /* scaling of xn[] to limit dynamic at 12 bits */
     284           0 :             Scale_sig( xn, L_SUBFR, shift ); /* Q_new + shift */
     285             :         }
     286             : 
     287             : 
     288             :         /*-----------------------------------------------------------------*
     289             :          * Gain clipping test to avoid unstable synthesis on frame erasure
     290             :          * or in case of floating point encoder & fixed p. decoder
     291             :          *-----------------------------------------------------------------*/
     292             :         /* full frame nelp partial copy encoding */
     293           0 :         IF( EQ_16( rf_frame_type, RF_NELP ) )
     294             :         {
     295           0 :             IF( i_subfr == 0 )
     296             :             {
     297           0 :                 nelp_encoder_fx( st, exc_rf, exc_nelp, &Q_new, 0 );
     298             :             }
     299           0 :             Copy( &exc_nelp[i_subfr], exc2, L_SUBFR );   /* Q_new */
     300           0 :             Copy( &exc_nelp[i_subfr], exc_rf, L_SUBFR ); /* Q_new */
     301             :         }
     302             :         ELSE
     303             :         {
     304           0 :             clip_gain = Mode2_gp_clip_fx( voicing, i_subfr, coder_type, xn, hRF->rf_clip_var, L_SUBFR, Q_xn ); // Q0
     305             : 
     306             :             /*-----------------------------------------------------------------*
     307             :              * - find unity gain pitch excitation (adaptive codebook entry)    *
     308             :              *   with fractional interpolation.                                *
     309             :              * - find filtered pitch exc. y1[]=exc[] convolved with h1[])      *
     310             :              * - compute pitch gain1                                           *
     311             :              *-----------------------------------------------------------------*/
     312           0 :             if ( acelp_cfg->gains_mode[i_subfr / L_SUBFR] == 0 )
     313             :             {
     314           0 :                 gain_pit = prev_gain_pit;
     315           0 :                 move16();
     316             :             }
     317             : 
     318           0 :             IF( acelp_cfg->ltp_bits != 0 )
     319             :             {
     320           0 :                 prm_rf = &hRF->rf_indx_pitch[0][nSubfr]; /* Q0 */
     321             : 
     322             :                 /* Adaptive Codebook (GC and VC) */
     323           0 :                 Mode2_pit_encode_fx( acelp_cfg->ltp_mode, i_subfr, &prm_rf, &exc_rf[i_subfr],
     324             :                                      T_op, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, &T0,
     325           0 :                                      &T0_frac, &T0_res, h1, xn, st->pit_min, st->pit_fr1, st->pit_fr1b,
     326           0 :                                      st->pit_fr2, st->pit_max, st->pit_res_max );
     327             : 
     328             :                 /* find ACB excitation */
     329           0 :                 rf_coder_type = 100;
     330           0 :                 move16();
     331           0 :                 if ( acelp_cfg->gains_mode[i_subfr / L_SUBFR] > 0 )
     332             :                 {
     333           0 :                     rf_coder_type = acelp_cfg->gains_mode[i_subfr / L_SUBFR]; /* Q0 */
     334           0 :                     move16();
     335             :                 }
     336             : 
     337           0 :                 E_ACELP_adaptive_codebook( exc_rf, T0, T0_frac, T0_res, st->pit_res_max, acelp_cfg->ltf_mode,
     338             :                                            i_subfr, L_SUBFR, L_frame, h1, clip_gain, xn, y1, &g_corr, &prm_rf,
     339           0 :                                            &gain_pit, xn_exp, st->rf_mode, rf_coder_type, &lp_select );
     340             : 
     341             : 
     342           0 :                 if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) )
     343             :                 {
     344           0 :                     hRF->rf_indx_ltfMode[0][nSubfr] = lp_select; /* Q0 */
     345           0 :                     move16();
     346             :                 }
     347             :             }
     348           0 :             ELSE IF( acelp_cfg->ltp_bits == 0 )
     349             :             {
     350             :                 /* No adaptive codebook (UC) */
     351           0 :                 gain_pit = 0;
     352           0 :                 g_corr.xy1 = 0;
     353           0 :                 g_corr.xy1_e = 0;
     354           0 :                 g_corr.y1y1 = 0x4000; /* set to 0x4000 instead of 0 to avoid assert failue in gain_enc : assert(coeff0 >= 0x4000) */
     355           0 :                 g_corr.y1y1_e = 0;
     356           0 :                 set16_fx( y1, 0, L_SUBFR );
     357           0 :                 set16_fx( exc_rf + i_subfr, 0, L_SUBFR );
     358           0 :                 T0 = L_SUBFR;
     359           0 :                 T0_frac = 0;
     360           0 :                 T0_res = 1;
     361           0 :                 move16();
     362           0 :                 move16();
     363           0 :                 move16();
     364           0 :                 move16();
     365           0 :                 move16();
     366           0 :                 move16();
     367           0 :                 move16();
     368           0 :                 move16();
     369             :             }
     370             : 
     371             : 
     372             :             /*----------------------------------------------------------------------*
     373             :              *                 Encode the algebraic innovation                      *
     374             :              *----------------------------------------------------------------------*/
     375           0 :             IF( acelp_cfg->fixed_cdk_index[i_subfr / L_SUBFR] >= 0 )
     376             :             {
     377           0 :                 prm_rf = &hRF->rf_indx_fcb[0][nSubfr];
     378             : 
     379           0 :                 E_ACELP_innovative_codebook_fx( exc_rf, T0, T0_frac, T0_res, gain_pit, hRF->rf_tilt_code,
     380           0 :                                                 acelp_cfg, i_subfr, p_Aq, h1, xn, cn, y1, y2, (Word8) st->acelp_autocorr,
     381           0 :                                                 &prm_rf, code, shift, st->L_frame, st->last_L_frame, st->total_brate );
     382             :             }
     383             :             ELSE
     384             :             {
     385           0 :                 set16_fx( code, 0, L_SUBFR );
     386           0 :                 set16_fx( y2, 0, L_SUBFR );
     387             :             }
     388             : 
     389           0 :             IF( LT_16( i_subfr, sub( L_frame, L_SUBFR ) ) )
     390             :             {
     391           0 :                 E_ACELP_xy2_corr( xn, y1, y2, &g_corr, L_SUBFR, Q_xn );
     392             : 
     393           0 :                 g_corr.y2y2_e = sub( g_corr.y2y2_e, 18 );             /* -18 (y2*y2: Q9*Q9) */
     394           0 :                 g_corr.xy2_e = sub( g_corr.xy2_e, add( Q_xn, 9 ) );   /* -(Q_xn+9) (xn: Q_xn y2: Q9) */
     395           0 :                 g_corr.y1y2_e = sub( g_corr.y1y2_e, add( Q_xn, 9 ) ); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */
     396           0 :                 g_corr.xx_e = sub( g_corr.xx_e, add( Q_xn, Q_xn ) );  /* -(Q_xn+Q_xn) (xn: Q_xn) */
     397             : 
     398             :                 /*----------------------------------------------------------------------*
     399             :                  *                 Add Gaussian excitation                              *
     400             :                  *----------------------------------------------------------------------*/
     401           0 :                 gain_code2 = L_deposit_l( 0 );
     402           0 :                 set16_fx( code2, 0, L_SUBFR );
     403           0 :                 set16_fx( y22, 0, L_SUBFR );
     404             : 
     405             :                 /*----------------------------------------------------------*
     406             :                  *  - Compute the fixed codebook gain                       *
     407             :                  *  - quantize fixed codebook gain                          *
     408             :                  *----------------------------------------------------------*/
     409           0 :                 IF( acelp_cfg->gains_mode[i_subfr / L_SUBFR] != 0 )
     410             :                 {
     411           0 :                     prm_rf = &hRF->rf_indx_gain[0][nSubfr]; /* Q0 */
     412             : 
     413           0 :                     encode_acelp_gains_fx( code, acelp_cfg->gains_mode[j_subfr], Es_pred_rf,
     414             :                                            clip_gain, &g_corr, &gain_pit, &gain_code, &prm_rf, &past_gcode,
     415           0 :                                            &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr );
     416             :                 }
     417             : 
     418             : 
     419           0 :                 gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, hRF->rf_clip_var );
     420             : 
     421           0 :                 gain_code_vect[0] = gain_code;
     422           0 :                 move32();
     423           0 :                 gain_code_vect[1] = gain_code;
     424           0 :                 move32();
     425             : 
     426             :                 /*----------------------------------------------------------*
     427             :                  * - voice factor (for pitch enhancement)                   *
     428             :                  *----------------------------------------------------------*/
     429             : 
     430           0 :                 E_UTIL_voice_factor( exc_rf, i_subfr, code, gain_pit, gain_code,
     431           0 :                                      &voice_fac, &( hRF->rf_tilt_code ), L_SUBFR, acelp_cfg->voice_tilt, Q_new, shift );
     432             : 
     433             :                 /*-----------------------------------------------------------------*
     434             :                  * Update memory of the weighting filter
     435             :                  *-----------------------------------------------------------------*/
     436             : 
     437             :                 /* st_fx->_rf_mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */
     438           0 :                 Ltmp = Mpy_32_16_1( gain_code, y2[L_SUBFR - 1] );    /* Q10 */
     439           0 :                 Ltmp = L_shl_sat( Ltmp, add( 5, Q_xn ) );            /* Q15 + Q_xn */
     440           0 :                 Ltmp = L_mac_sat( Ltmp, y1[L_SUBFR - 1], gain_pit ); /* Q15 + Q_xn */
     441             :                 /* Add Gaussian contribution*/
     442           0 :                 Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] );                               /* Q10 */
     443           0 :                 Ltmp2 = L_shl_sat( Ltmp2, add( 5, Q_xn ) );                                        /* Q15 + Q_xn */
     444           0 :                 Ltmp = L_add_sat( Ltmp, Ltmp2 );                                                   /* Q15 + Q_xn */
     445           0 :                 hRF->rf_mem_w0 = sub_sat( xn[L_SUBFR - 1], round_fx_sat( L_shl_sat( Ltmp, 1 ) ) ); /* Q_xn */
     446           0 :                 move16();
     447           0 :                 hRF->rf_mem_w0 = shr_sat( hRF->rf_mem_w0, shift ); /*Qnew-1*/
     448             : 
     449             :                 /*-------------------------------------------------------*
     450             :                  * - Find the total excitation.                          *
     451             :                  *-------------------------------------------------------*/
     452             : 
     453           0 :                 tmp2 = shr( L_SUBFR, 1 );
     454           0 :                 FOR( j = 0; j < 2; j++ )
     455             :                 {
     456           0 :                     FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ )
     457             :                     {
     458             :                         /* code in Q9, gain_pit in Q14; exc Q_new */
     459           0 :                         Ltmp = Mpy_32_16_1( gain_code2, code2[i] );              /* Q10 */
     460           0 :                         Ltmp = L_shl_sat( Ltmp, Q_new_p5 );                      /* Q15 + Q_new */
     461           0 :                         Ltmp = L_mac_sat( Ltmp, gain_pit, exc_rf[i + i_subfr] ); /* Q15 + Q_new */
     462           0 :                         exc2[i] = round_fx_sat( L_shl_sat( Ltmp, 1 ) );          /* Q_new */
     463           0 :                         move16();
     464           0 :                         Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code[i] ); /* Q10 */
     465           0 :                         Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 );              /* Q15 + Q_new */
     466           0 :                         Ltmp = L_add_sat( Ltmp, Ltmp2 );                   /* Q15 + Q_new */
     467           0 :                         Ltmp = L_shl_sat( Ltmp, 1 );                       /* saturation can occur here Q16 + Q_new*/
     468           0 :                         exc_rf[i + i_subfr] = round_fx_sat( Ltmp );        /* Q_new */
     469           0 :                         move16();
     470             :                     }
     471           0 :                     tmp2 = L_SUBFR;
     472           0 :                     move16();
     473             :                 }
     474             : 
     475             :                 /*---------------------------------------------------------*
     476             :                  * Enhance the excitation                                  *
     477             :                  *---------------------------------------------------------*/
     478             : 
     479           0 :                 E_UTIL_enhancer( voice_fac, stab_fac, past_gcode, gain_inov,
     480             :                                  &hRF->rf_gc_threshold, code, exc2, gain_pit, &hRF->rf_dm_fx.prev_gain_code,
     481           0 :                                  hRF->rf_dm_fx.prev_gain_pit, &hRF->rf_dm_fx.prev_state, coder_type,
     482           0 :                                  acelp_cfg->fixed_cdk_index[j_subfr], L_SUBFR, L_frame, Q_new );
     483             :             }
     484             :         }
     485             : 
     486           0 :         test();
     487           0 :         IF( LT_16( i_subfr, sub( L_frame, L_SUBFR ) ) || NE_16( rf_frame_type, RF_NELP ) )
     488             :         {
     489             : 
     490             :             /*----------------------------------------------------------*
     491             :              * - compute the synthesis speech                           *
     492             :              *----------------------------------------------------------*/
     493             : 
     494           0 :             E_UTIL_synthesis( 1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, hRF->rf_mem_syn2, 1, M );
     495             : 
     496           0 :             E_UTIL_synthesis( 1, p_Aq, &exc_rf[i_subfr], &syn_rf[i_subfr], L_SUBFR, &syn_rf[i_subfr - M], 0, M );
     497             : 
     498             :             /*----------------------------------------------------------*
     499             :              * Update                                                   *
     500             :              *----------------------------------------------------------*/
     501           0 :             p_A += ( M + 1 );
     502           0 :             p_Aq += ( M + 1 );
     503           0 :             nSubfr++;
     504             : 
     505           0 :             st->gain_code[j_subfr] = gain_code; /* Q16 */
     506           0 :             j_subfr = add( j_subfr, 1 );
     507             : 
     508             :             /* copy current gain for next subframe use, in case there is no explicit encoding */
     509           0 :             prev_gain_pit = gain_pit;
     510           0 :             move16();
     511             :         }
     512             : 
     513             : 
     514             :     } /* end of subframe loop */
     515             : 
     516             : 
     517           0 :     return;
     518             : }

Generated by: LCOV version 1.14