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

Generated by: LCOV version 1.14