LCOV - code coverage report
Current view: top level - lib_dec - dec_gen_voic_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 116 209 55.5 %
Date: 2025-05-17 01:59:02 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdlib.h>
       6             : #include "options.h" /* Compilation switches                   */
       7             : #include "cnst.h"    /* Common constants                       */
       8             : #include "rom_com.h" /* Static table prototypes                */
       9             : #include "prot_fx.h" /* Function prototypes                    */
      10             : #include "stl.h"
      11             : #include "basop_util.h"
      12             : 
      13             : /*======================================================================*/
      14             : /* FUNCTION : decod_gen_voic_fx()                                       */
      15             : /*----------------------------------------------------------------------*/
      16             : /* PURPOSE : Decode generic (GC), voiced (VC) and AMR-WB IO frames      */
      17             : /*                                                                      */
      18             : /*----------------------------------------------------------------------*/
      19             : /* GLOBAL INPUT ARGUMENTS :                                             */
      20             : /* _ (Struct)    st_fx            : decoder static memory               */
      21             : /* _ (Word16) L_frame             : length of the frame                 */
      22             : /* _ (Word16[]) Aq_fx            : LP filter coefficient        Q12     */
      23             : /* _ (Word16) Es_pred_fx        : predicted scaled innov. energy Q8     */
      24             : /* _ (Word16[]) pitch_buf_fx    : floating pitch values for each subframe Q6*/
      25             : /* _ (Word16[])    voice_factors_fx: frame error rate           Q15     */
      26             : /*----------------------------------------------------------------------*/
      27             : /* OUTPUT ARGUMENTS :                                                   */
      28             : /* _ (Word16[]) exc_fx            : adapt. excitation exc (Q_exc)       */
      29             : /* _ (Word16[]) exc2_fx           : adapt. excitation/total exc (Q_exc) */
      30             : /*----------------------------------------------------------------------*/
      31             : /*----------------------------------------------------------------------*/
      32             : /* RETURN ARGUMENTS :                                                   */
      33             : /* _ None                                                               */
      34             : /*======================================================================*/
      35             : 
      36      105524 : ivas_error decod_gen_voic_fx(
      37             :     Decoder_State *st_fx,              /* i/o: decoder static memory                            */
      38             :     const Word16 L_frame,              /* i  : length of the frame                              */
      39             :     const Word16 sharpFlag_fx,         /* i  : formant sharpening flag                          */
      40             :     const Word16 *Aq_fx,               /* i  : LP filter coefficient                    Q12     */
      41             :     const Word16 Es_pred_fx,           /* i  : predicted scaled innov. energy           Q8      */
      42             :     const Word16 do_WI_fx,             /* i  : do interpolation after a FER                     */
      43             :     Word16 *pitch_buf_fx,              /* o  : Word16 pitch values for each subframe    Q6      */
      44             :     Word16 *voice_factors_fx,          /* o  : voicing factors                          Q15     */
      45             :     Word16 *exc_fx,                    /* i/o: adapt. excitation exc                    Q_exc   */
      46             :     Word16 *exc2_fx,                   /* i/o: adapt. excitation/total exc              Q_exc   */
      47             :     Word16 *bwe_exc_fx,                /* o  : excitation for SWB TBE                   Q_exc   */
      48             :     Word16 *unbits,                    /* number of unused bits                                 */
      49             :     Word16 *gain_buf,                  /* o  : Word16 pitch gain for each subframe              Q14     */
      50             :     const Word16 tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag                 */
      51             :     const Word16 tdm_Pri_pitch_buf[]   /* i  : primary channel pitch buffer     Q6              */
      52             : )
      53             : {
      54             :     Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables                              */
      55             :     Word16 gain_pit_fx;                             /* pitch gain               Q14                         */
      56             :     Word32 gain_code_fx;                            /* gain/normalized gain of the algebraic excitation Q16 */
      57             :     Word32 norm_gain_code_fx;                       /* normalized gain of the algebraic excitation    Q16   */
      58             :     Word16 gain_inov_fx;                            /* Innovation gain  Q12                                 */
      59             :     Word32 gc_mem[NB_SUBFR - 1];                    /* gain_code from previous subframes                    */
      60             :     Word16 gp_mem[NB_SUBFR - 1];                    /* gain_pitch from previous subframes                   */
      61             :     Word16 voice_fac_fx;                            /* voicing factor  Q15                                  */
      62             :     Word16 code_fx[L_SUBFR];                        /* algebraic codevector      Q12                        */
      63             : 
      64             :     const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12                  */
      65             :     Word16 *pt_pitch_fx;   /* pointer to Word16 pitch     Q6                       */
      66             :     Word16 i_subfr_fx, i;  /* tmp variables                                        */
      67             :     Word16 error_fx;
      68             :     Word16 gain_preQ_fx;          /* Gain of prequantizer excitation                      */
      69             :     Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation                              */
      70             :     Word32 norm_gain_preQ_fx;
      71             :     Word16 pitch_limit_flag_fx;
      72             : 
      73             :     Word16 tmp1_fx, gain_code16;
      74             :     Word32 L_tmp_GC;
      75             :     Word32 L_tmp;
      76             : 
      77             :     Word16 harm_flag_acelp;
      78             : 
      79             :     Word16 shft_prev, ph_offset_fx;
      80             :     Word32 prev_res_nrg;
      81             :     Word32 prev_spch_nrg;
      82             :     Word32 curr_res_nrg;
      83             :     Word32 curr_spch_nrg;
      84             :     Word16 rint_bfi_pitch, rint_pitch;
      85             :     Word16 fraca, fracb, expa, expb, scale, exp1;
      86             :     Word16 *p_exc;
      87             :     Word16 mem_tmp_fx[M];
      88             :     Word16 syn_tmp_fx[L_FRAME16k];
      89             :     Word16 shft_curr;
      90             :     Word16 *p_syn;
      91             :     Word16 sp_enratio, Qsp_enratio;
      92             :     Word16 enratio, Qenratio;
      93             :     DTFS_STRUCTURE *PREVP, *CURRP;
      94             :     Word16 S_fx[PIT_MAX * 4 + 1], C_fx[PIT_MAX * 4 + 1];
      95             :     Word16 dummy2[2];
      96             :     Word16 out_fx[L_FRAME16k];
      97             : 
      98             :     Word16 pf_temp1[MAXLAG_WI]; /*may not need more than MAXLAG_WI/2+1 */
      99             :     Word16 pf_temp2[MAXLAG_WI];
     100             :     Word16 pf_temp[MAXLAG_WI];
     101             :     Word16 pf_n2[MAXLAG_WI];
     102             :     MUSIC_POSTFILT_HANDLE hMusicPF;
     103      105524 :     gain_pit_fx = 0;
     104      105524 :     gain_code_fx = 0;
     105      105524 :     norm_gain_code_fx = 0;
     106      105524 :     gain_inov_fx = 0;
     107      105524 :     error_fx = 0;
     108      105524 :     gain_preQ_fx = 0;
     109             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
     110      105524 :     Flag Overflow = 0;
     111      105524 :     move32();
     112             : #endif
     113      105524 :     move16();
     114      105524 :     move32();
     115      105524 :     move32();
     116      105524 :     move16();
     117      105524 :     move16();
     118      105524 :     move16();
     119             : 
     120      105524 :     hMusicPF = st_fx->hMusicPF;
     121             : 
     122             :     GSC_DEC_HANDLE hGSCDec;
     123      105524 :     hGSCDec = st_fx->hGSCDec;
     124             :     ivas_error error;
     125             : 
     126      105524 :     error = IVAS_ERR_OK;
     127      105524 :     move32();
     128             : 
     129      105524 :     T0_fx = PIT_MIN;
     130      105524 :     move16();
     131      105524 :     T0_frac_fx = 0;
     132      105524 :     move16();
     133             : 
     134             :     /* read harmonicity flag */
     135      105524 :     harm_flag_acelp = 0;
     136      105524 :     move16();
     137      105524 :     test();
     138      105524 :     test();
     139      105524 :     IF( ( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) ) && EQ_16( st_fx->coder_type, GENERIC ) )
     140             :     {
     141        6629 :         harm_flag_acelp = (Word16) get_next_indice_fx( st_fx, 1 );
     142             :     }
     143             : 
     144             :     /*------------------------------------------------------------------*
     145             :      * ACELP subframe loop
     146             :      *------------------------------------------------------------------*/
     147             : 
     148      105524 :     p_Aq_fx = Aq_fx;            /* pointer to interpolated LPC parameters */
     149      105524 :     pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
     150      105524 :     norm_gain_preQ_fx = 0;
     151      105524 :     move32();
     152      105524 :     gain_preQ_fx = 0;
     153      105524 :     move16();
     154      105524 :     set16_fx( code_preQ_fx, 0, L_SUBFR );
     155             : 
     156      585708 :     FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
     157             :     {
     158             :         /*----------------------------------------------------------------------*
     159             :          * Decode pitch lag
     160             :          *----------------------------------------------------------------------*/
     161             : 
     162      480184 :         *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx,
     163             :                                       &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
     164      480184 :         move16(); /*Q6*/
     165             : 
     166             :         /*--------------------------------------------------------------*
     167             :          * Find the adaptive codebook vector
     168             :          *--------------------------------------------------------------*/
     169             : 
     170      480184 :         pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     171             : 
     172             :         // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx);
     173      480184 :         tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag );
     174             : 
     175             :         /*--------------------------------------------------------------*
     176             :          * LP filtering of the adaptive excitation
     177             :          *--------------------------------------------------------------*/
     178      480184 :         lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx );
     179             :         /*-----------------------------------------------------------------*
     180             :          * Transform-domain contribution decoding (active frames)
     181             :          *-----------------------------------------------------------------*/
     182             : 
     183      480184 :         test();
     184      480184 :         IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) )
     185             :         {
     186       45840 :             gain_code_fx = 0;
     187       45840 :             move16();
     188       45840 :             transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits );
     189             :         }
     190             : 
     191             :         /*--------------------------------------------------------------*
     192             :          * Innovation decoding
     193             :          *--------------------------------------------------------------*/
     194             : 
     195      480184 :         inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR );
     196             : 
     197             :         /*--------------------------------------------------------------*
     198             :          * Gain decoding
     199             :          * Estimate spectrum tilt and voicing
     200             :          *--------------------------------------------------------------*/
     201             : 
     202      480184 :         IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
     203             :         {
     204       12804 :             gain_dec_lbr_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR );
     205             :         }
     206      467380 :         ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) )
     207             :         {
     208       37820 :             gain_dec_SQ_fx( st_fx, i_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
     209             :         }
     210             :         ELSE
     211             :         {
     212      429560 :             gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx );
     213             :         }
     214      480184 :         st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); // Q15
     215      480184 :         move16();
     216             : 
     217             :         /*-----------------------------------------------------------------*
     218             :          * Transform domain contribution decoding
     219             :          *-----------------------------------------------------------------*/
     220      480184 :         test();
     221      480184 :         IF( !st_fx->inactive_coder_type_flag && st_fx->coder_type == INACTIVE )
     222             :         {
     223        9025 :             transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits );
     224             :         }
     225             : 
     226             :         /* update LP filtered gains for the case of frame erasures */
     227      480184 :         IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
     228             :         {
     229        5802 :             lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame );
     230             :         }
     231             :         ELSE
     232             :         {
     233      474382 :             lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame );
     234             :         }
     235             : 
     236             :         /*----------------------------------------------------------------------*
     237             :          * Find the total excitation
     238             :          *----------------------------------------------------------------------*/
     239             : 
     240      480184 :         IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */
     241             :         {
     242      189744 :             IF( ( bwe_exc_fx != NULL ) )
     243             :             {
     244      189304 :                 Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx,
     245      189304 :                              L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type );
     246             :             }
     247             :             ELSE
     248             :             {
     249         440 :                 Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx,
     250         440 :                              L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type );
     251             :             }
     252             :         }
     253             :         ELSE /* Rescaling for 16k core */
     254             :         {
     255             : 
     256      290440 :             L_tmp_GC = L_max( gain_code_fx, L_shl( gain_preQ_fx, 16 ) ); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/
     257      290440 :             IF( bwe_exc_fx != NULL )
     258             :             {
     259      290440 :                 Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx,
     260      290440 :                              L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type );
     261             :             }
     262             :             ELSE
     263             :             {
     264           0 :                 Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx,
     265           0 :                              L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type );
     266             :             }
     267             :         }
     268             : 
     269      480184 :         gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/
     270             : 
     271             :         /*-----------------------------------------------------------------*
     272             :          * Add the ACELP pre-quantizer contribution
     273             :          *-----------------------------------------------------------------*/
     274             : 
     275      480184 :         IF( gain_preQ_fx != 0 )
     276             :         {
     277       54858 :             IF( st_fx->element_mode == EVS_MONO )
     278             :             {
     279        3110 :                 tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc );
     280             :             }
     281             :             ELSE
     282             :             {
     283       51748 :                 tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc );
     284             :             }
     285     3565770 :             FOR( i = 0; i < L_SUBFR; i++ )
     286             :             {
     287             :                 Word32 Ltmp1;
     288             :                 /* Contribution from AVQ layer */
     289     3510912 :                 Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/
     290     3510912 :                 Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx );             /* Q16 + Q_exc */
     291             : 
     292             :                 /* Compute exc2 */
     293     3510912 :                 L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 );
     294     3510912 :                 exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
     295     3510912 :                 move16();
     296             :                 /* gain_pit in Q14 */
     297     3510912 :                 L_tmp = L_mult( gain_code16, code_fx[i] );                       // Q_exc+Q9+1
     298     3510912 :                 L_tmp = L_shl_sat( L_tmp, 5 );                                   // Q_exc+Q9+1+5
     299     3510912 :                 L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+16
     300     3510912 :                 L_tmp = L_shl_sat( L_tmp, 1 );                                   /* saturation can occur here */
     301             : 
     302     3510912 :                 exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc
     303     3510912 :                 move16();
     304             :             }
     305             :         }
     306             :         ELSE
     307             :         {
     308      425326 :             Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR );
     309             :         }
     310             : 
     311             :         /*-----------------------------------------------------------------*
     312             :          * Prepare TBE excitation
     313             :          *-----------------------------------------------------------------*/
     314             : 
     315             :         Word16 idx;
     316      480184 :         idx = 0;
     317      480184 :         move16();
     318      480184 :         IF( i_subfr_fx != 0 )
     319             :         {
     320      374660 :             idx = idiv1616( i_subfr_fx, L_SUBFR );
     321             :         }
     322             : 
     323      480184 :         prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
     324      480184 :                          &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
     325      480184 :                          st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate,
     326      480184 :                          st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag );
     327             : 
     328             : 
     329             :         /*----------------------------------------------------------------*
     330             :          * Excitation enhancements (update of total excitation signal)
     331             :          *----------------------------------------------------------------*/
     332             : 
     333      480184 :         test();
     334      480184 :         IF( GT_32( st_fx->core_brate, ACELP_32k ) || EQ_16( st_fx->coder_type, INACTIVE ) )
     335             :         {
     336       40955 :             Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR );
     337             :         }
     338             :         ELSE
     339             :         {
     340      439229 :             IF( EQ_16( st_fx->element_mode, EVS_MONO ) )
     341             :             {
     342        2692 :                 enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx,
     343        2692 :                              norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc );
     344             :             }
     345             :             ELSE
     346             :             {
     347      436537 :                 enhancer_ivas_fx2( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx,
     348      436537 :                                    norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc );
     349             :             }
     350             :         }
     351             : 
     352      480184 :         p_Aq_fx += ( M + 1 );
     353      480184 :         move16();
     354      480184 :         pt_pitch_fx++;
     355      480184 :         gain_buf[idx] = gain_pit_fx; // Q14
     356      480184 :         move16();
     357             :     }
     358             : 
     359             :     /* FEC fast recovery */
     360             : 
     361      105524 :     IF( do_WI_fx )
     362             :     {
     363             :         /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/
     364           0 :         L_tmp = L_shl( L_deposit_l( st_fx->bfi_pitch_fx ), 10 ); /*Q16*/
     365           0 :         rint_bfi_pitch = rint_new_fx( L_tmp );                   /*Q0*/
     366           0 :         shft_prev = sub( L_EXC_MEM, rint_bfi_pitch );            /*Q0*/
     367             : 
     368           0 :         p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev;
     369           0 :         p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev;
     370             : 
     371           0 :         prev_res_nrg = 1;
     372           0 :         move32();
     373           0 :         prev_spch_nrg = 1;
     374           0 :         move32();
     375           0 :         FOR( i = 0; i < rint_bfi_pitch; i++ )
     376             :         {
     377           0 :             prev_res_nrg = L_mac0_sat( prev_res_nrg, *p_exc, *p_exc );   /* 2*st_fx->prev_Q_exc_fr */
     378           0 :             prev_spch_nrg = L_mac0_sat( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */
     379           0 :             p_exc++;
     380           0 :             p_syn++;
     381             :         }
     382             : 
     383           0 :         Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M );
     384             : 
     385           0 :         syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_tmp_fx, mem_tmp_fx, 1, st_fx->Q_exc, st_fx->Q_syn );
     386             : 
     387           0 :         L_tmp = L_shl( L_deposit_l( pitch_buf_fx[NB_SUBFR16k - 1] ), 10 ); /*Q16*/
     388           0 :         rint_pitch = rint_new_fx( L_tmp );                                 /*Q0*/
     389           0 :         shft_curr = sub( st_fx->L_frame, rint_pitch );                     /*Q0*/
     390             : 
     391           0 :         p_exc = exc2_fx + shft_curr;
     392           0 :         p_syn = syn_tmp_fx + shft_curr;
     393             : 
     394           0 :         curr_res_nrg = 1;
     395           0 :         move32();
     396           0 :         curr_spch_nrg = 1;
     397           0 :         move32();
     398           0 :         FOR( i = 0; i < rint_pitch; i++ )
     399             :         {
     400           0 :             curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc );   /* 2*st_fx->Q_exc */
     401           0 :             curr_spch_nrg = L_mac0( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */
     402           0 :             p_exc++;
     403           0 :             p_syn++;
     404             :         }
     405             : 
     406             :         /* enratio = (curr_res_nrg / prev_res_nrg); */
     407           0 :         IF( prev_res_nrg > 0 )
     408             :         {
     409           0 :             expa = norm_l( prev_res_nrg );
     410           0 :             fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr +expa -16*/
     411           0 :             expa = sub( 30, add( expa, shl( st_fx->prev_Q_exc_fr, 1 ) ) );
     412             : 
     413           0 :             expb = norm_l( curr_res_nrg );
     414           0 :             fracb = round_fx( L_shl( curr_res_nrg, expb ) ); /* 2*st_fx->prev_Q_exc_fr +expb -16*/
     415           0 :             expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) );
     416             : 
     417           0 :             scale = shr( sub( fraca, fracb ), 15 );
     418           0 :             fracb = shl( fracb, scale ); // Q(15-expb)+scale
     419           0 :             expb = sub( expb, scale );
     420             : 
     421           0 :             enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)
     422           0 :             exp1 = sub( expb, expa );
     423           0 :             Qenratio = sub( 15, exp1 );
     424             :         }
     425             :         ELSE
     426             :         {
     427           0 :             enratio = 0;
     428           0 :             move16();
     429           0 :             Qenratio = 0;
     430           0 :             move16();
     431             :         }
     432             : 
     433             :         /* sp_enratio = curr_spch_nrg/prev_spch_nrg */
     434           0 :         IF( prev_spch_nrg > 0 )
     435             :         {
     436           0 :             expa = norm_l( prev_spch_nrg );
     437           0 :             fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr -16 +expa */
     438           0 :             expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) );
     439             : 
     440           0 :             expb = norm_l( curr_spch_nrg );
     441           0 :             fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb -16*/
     442           0 :             expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) );
     443             : 
     444           0 :             scale = shr( sub( fraca, fracb ), 15 );
     445           0 :             fracb = shl( fracb, scale ); // Q(15-expb)+scale
     446           0 :             expb = sub( expb, scale );
     447             : 
     448           0 :             sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa))
     449           0 :             exp1 = sub( expb, expa );
     450           0 :             Qsp_enratio = sub( 15, exp1 );
     451             :         }
     452             :         ELSE
     453             :         {
     454           0 :             sp_enratio = 0;
     455           0 :             move16();
     456           0 :             Qsp_enratio = 0;
     457           0 :             move16();
     458             :         }
     459             : 
     460           0 :         test();
     461           0 :         test();
     462           0 :         test();
     463           0 :         test();
     464           0 :         IF( GT_16( shl_ro( enratio, sub( 15, Qenratio ), &Overflow ), 8192 ) &&       /*compare with 0.25 in Q15*/
     465             :             LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) &&      /*compare with 15.0 in Q10*/
     466             :             GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/
     467             :             LT_16( st_fx->bfi_pitch_fx, 9600 ) &&                                     /*Q6*/
     468             :             LT_16( pitch_buf_fx[( NB_SUBFR16k - 1 )], 9600 ) )                        /*Q6*/
     469             :         {
     470           0 :             IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) )
     471             :             {
     472           0 :                 return error;
     473             :             }
     474             : 
     475           0 :             IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) )
     476             :             {
     477           0 :                 return error;
     478             :             }
     479             : 
     480           0 :             GetSinCosTab_fx( rint_bfi_pitch, S_fx, C_fx );
     481           0 :             DTFS_to_fs_fx( st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx );
     482           0 :             PREVP->Q = add( PREVP->Q, st_fx->prev_Q_exc_fr );
     483           0 :             move16();
     484             : 
     485           0 :             GetSinCosTab_fx( rint_pitch, S_fx, C_fx );
     486           0 :             DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx );
     487           0 :             CURRP->Q = add( CURRP->Q, st_fx->Q_exc );
     488           0 :             move16();
     489             : 
     490           0 :             ph_offset_fx = 0;
     491           0 :             move16();
     492           0 :             IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) )
     493             :             {
     494           0 :                 return error;
     495             :             }
     496             : 
     497             : 
     498           0 :             Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc
     499           0 :             Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc );  // Q_exc
     500             : 
     501             :             /* update bwe_exc for SWB-TBE */
     502           0 :             FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR )
     503             :             {
     504           0 :                 interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + ( i_subfr_fx * 2 ), L_SUBFR );
     505             :             }
     506             : 
     507           0 :             free( PREVP );
     508           0 :             free( CURRP );
     509             :         }
     510             :     }
     511             : 
     512             :     /* SC-VBR */
     513      105524 :     st_fx->prev_gain_pit_dec_fx = gain_pit_fx;
     514      105524 :     move16(); /*Q14*/
     515      105524 :     st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx;
     516      105524 :     move16(); /*Q15*/
     517             : 
     518      105524 :     return error;
     519             : }

Generated by: LCOV version 1.14