LCOV - code coverage report
Current view: top level - lib_dec - dec_ace.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 126 167 75.4 %
Date: 2025-05-23 08:37:30 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <stdint.h>
      38             : #include "options.h"
      39             : #include "prot.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include <math.h>
      44             : #include "rom_com.h"
      45             : #include "wmc_auto.h"
      46             : 
      47             : /*-------------------------------------------------------------------*
      48             :  * decoder_acelp()
      49             :  *
      50             :  * Decode ACELP frame MODE2
      51             :  *-------------------------------------------------------------------*/
      52             : 
      53        1812 : void decoder_acelp(
      54             :     Decoder_State *st,              /* i/o: coder memory state          */
      55             :     int16_t prm[],                  /* i  : parameters                  */
      56             :     const float A[],                /* i  : coefficients NxAz[M+1]      */
      57             :     ACELP_config acelp_cfg,         /* i  : ACELP config                */
      58             :     float synth[],                  /* i/o: synthesis                   */
      59             :     int16_t *pT,                    /* o  : pitch for all subframe      */
      60             :     float *pgainT,                  /* o  : pitch gain for all subfr    */
      61             :     const float stab_fac,           /* i  : stability of isf            */
      62             :     float *pitch_buffer,            /* i/o: pitch values for each subfr.*/
      63             :     float *voice_factors,           /* o  : voicing factors             */
      64             :     const int16_t LSF_Q_prediction, /* i  : LSF prediction mode        */
      65             :     float *bwe_exc                  /* o  : excitation for SWB TBE      */
      66             : )
      67             : {
      68             :     int16_t i, i_subfr, L_frame;
      69             :     int16_t T0, T0_frac, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res;
      70             :     float tmp, gain_pit, gain_code, Es_pred;
      71             :     float code[L_SUBFR];
      72             :     float mem_syn[M], *syn, syn_buf[M + L_FRAME16k + L_FRAME16k / 2];
      73             :     float *exc, exc_buf[L_EXC_MEM_DEC + L_FRAME16k + 1];
      74             :     float exc2[L_FRAME16k];
      75             :     const float *p_A;
      76             :     float *pt_pitch, pitch_buf[NB_SUBFR16k];
      77             :     float gain_inov;
      78             :     float mem_back[M];
      79             :     float h1[L_FRAME16k / 4 + 1];
      80             :     float mem[M];
      81             :     const float *pA;
      82             :     float gain_code2;
      83             :     float code2[L_SUBFR];
      84             :     int16_t lp_flag;
      85        1812 :     float error = 0.0f;
      86        1812 :     float gain_preQ = 0;      /* Gain of prequantizer excitation   */
      87             :     float code_preQ[L_SUBFR]; /* Prequantizer excitation           */
      88             :     PulseConfig config;
      89             :     float weights[5];
      90             : 
      91             :     float prev_gain_pit;
      92             :     float tmp_noise; /* Long term temporary noise energy */
      93             : 
      94             :     float gain_code_tmp;
      95             :     float gain_pit_tmp;
      96             :     float gain_code_pre;
      97             : 
      98        1812 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
      99             : 
     100        1812 :     gain_inov = 0; /* to avoid compilation warnings */
     101        1812 :     T0 = 0;        /* to avoid compilation warnings */
     102        1812 :     T0_frac = 0;   /* to avoid compilation warnings */
     103        1812 :     T0_res = 0;    /* to avoid compilation warnings */
     104             : 
     105             :     /*------------------------------------------------------------------------*
     106             :      * Initializations                                                        *
     107             :      *------------------------------------------------------------------------*/
     108             : 
     109        1812 :     gain_code_pre = 0;
     110        1812 :     set_f( code_preQ, 0.f, L_SUBFR );
     111             : 
     112        1812 :     gain_pit = 0;
     113        1812 :     gain_code = 0;
     114        1812 :     gain_code2 = 0.f;
     115             : 
     116        1812 :     prev_gain_pit = 0;
     117        1812 :     tmp_noise = 0;
     118             : 
     119        1812 :     if ( st->nb_subfr == NB_SUBFR )
     120             :     {
     121           0 :         weights[0] = 0.1f;
     122           0 :         weights[1] = 0.2f;
     123           0 :         weights[2] = 0.3f;
     124           0 :         weights[3] = 0.4f;
     125             :     }
     126             :     else /*nb_subfr == NB_SUBFR16k */
     127             :     {
     128        1812 :         weights[0] = (float) 1 / 15;
     129        1812 :         weights[1] = (float) 2 / 15;
     130        1812 :         weights[2] = (float) 3 / 15;
     131        1812 :         weights[3] = (float) 4 / 15;
     132        1812 :         weights[4] = (float) 5 / 15;
     133             :     }
     134             : 
     135        1812 :     st->lp_gainp = 0;
     136        1812 :     st->lp_gainc = 0;
     137             : 
     138             : 
     139             :     /* Framing parameters */
     140        1812 :     L_frame = st->L_frame;
     141             : 
     142             :     /*------------------------------------------------------------------------*
     143             :      * Previous frame is TCX                                                  *
     144             :      *------------------------------------------------------------------------*/
     145             :     /* Reset phase dispersion */
     146             : 
     147        1812 :     if ( st->last_core_bfi > ACELP_CORE )
     148             :     {
     149          90 :         set_zero( st->dispMem, 8 );
     150             :     }
     151             : 
     152             :     /* Update of synthesis filter memories in case of 12k8 core */
     153        1812 :     if ( st->prev_bfi && st->last_con_tcx && st->L_frame < L_FRAME16k )
     154             :     {
     155           0 :         synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC );
     156             :     }
     157             : 
     158        1812 :     if ( st->last_con_tcx && st->old_enr_LP )
     159             :     {
     160             :         float enr_LP, ratio;
     161             : 
     162             :         /* rescale excitation buffer if LPC energies differs too much */
     163           0 :         enr_LP = enr_1_Az( A, L_SUBFR );
     164             : 
     165           0 :         ratio = st->old_enr_LP / enr_LP;
     166           0 :         if ( ratio < 0.8 )
     167             :         {
     168           0 :             v_multc( st->old_exc, ratio, st->old_exc, L_EXC_MEM_DEC );
     169             :         }
     170             :     }
     171             : 
     172             :     /*------------------------------------------------------------------------*
     173             :      * Initialize buffers                                                     *
     174             :      *------------------------------------------------------------------------*/
     175             : 
     176        1812 :     mvr2r( st->mem_syn2, mem_back, M );
     177             : 
     178             :     /* set ACELP synthesis memory */
     179        1812 :     mvr2r( st->mem_syn2, mem_syn, M );
     180             : 
     181             :     /* set excitation memory*/
     182        1812 :     exc = exc_buf + L_EXC_MEM_DEC;
     183        1812 :     mvr2r( st->old_exc, exc_buf, L_EXC_MEM_DEC );
     184        1812 :     *( exc + L_frame ) = 0.f;
     185             : 
     186             :     /* Init syn buffer */
     187        1812 :     syn = syn_buf + M;
     188        1812 :     mvr2r( st->mem_syn2, syn_buf, M );
     189             : 
     190             :     /*------------------------------------------------------------------------*
     191             :      * Fast recovery flag
     192             :      *------------------------------------------------------------------------*/
     193             : 
     194        1812 :     if ( st->prev_bfi && st->coder_type == VOICED )
     195             :     {
     196             :         /*Force BPF to be applied fully*/
     197           0 :         st->bpf_gain_param = 3;
     198             :     }
     199             : 
     200             :     /*------------------------------------------------------------------------*
     201             :      * - decode mean_ener_code for gain decoder (d_gain2.c)                   *
     202             :      *------------------------------------------------------------------------*/
     203             : 
     204        1812 :     if ( acelp_cfg.nrg_mode > 0 )
     205             :     {
     206        1812 :         Es_pred_dec( &Es_pred, prm[0], acelp_cfg.nrg_bits, acelp_cfg.nrg_mode > 1 );
     207        1812 :         prm++;
     208             :     }
     209             :     else
     210             :     {
     211           0 :         Es_pred = 0.f;
     212             :     }
     213             : 
     214             :     /*------------------------------------------------------------------------*
     215             :      *          Loop for every subframe in the analysis frame                 *
     216             :      *------------------------------------------------------------------------*
     217             :      *  To find the pitch and innovation parameters. The subframe size is     *
     218             :      *  L_SUBFR and the loop is repeated L_frame/L_SUBFR times.               *
     219             :      *     - compute impulse response of weighted synthesis filter (h1[])     *
     220             :      *     - compute the target signal for pitch search                       *
     221             :      *     - find the closed-loop pitch parameters                            *
     222             :      *     - encode the pitch delay                                           *
     223             :      *     - update the impulse response h1[] by including fixed-gain pitch   *
     224             :      *     - find target vector for codebook search                           *
     225             :      *     - correlation between target vector and impulse response           *
     226             :      *     - codebook search                                                  *
     227             :      *     - encode codebook address                                          *
     228             :      *     - VQ of pitch and codebook gains                                   *
     229             :      *     - find synthesis speech                                            *
     230             :      *     - update states of weighting filter                                *
     231             :      *------------------------------------------------------------------------*/
     232             : 
     233        1812 :     p_A = A;
     234        1812 :     pt_pitch = pitch_buf;
     235             : 
     236       10872 :     for ( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR )
     237             :     {
     238        9060 :         if ( st->use_partial_copy && st->rf_frame_type == RF_NELP )
     239             :         {
     240           0 :             if ( i_subfr == 0 )
     241             :             {
     242           0 :                 decod_nelp( st, &tmp_noise, pt_pitch, exc, exc2, voice_factors, bwe_exc, 0 /*st->bfi*/, pgainT );
     243           0 :                 set_f( pitch_buffer, L_SUBFR, NB_SUBFR );
     244             :             }
     245             :         }
     246             :         else
     247             :         {
     248             :             /*-------------------------------------------------------*
     249             :              * - Decode adaptive codebook.                           *
     250             :              *-------------------------------------------------------*/
     251             : 
     252        9060 :             if ( st->use_partial_copy && st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] == 0 )
     253             :             {
     254           0 :                 gain_pit = prev_gain_pit;
     255             :             }
     256             : 
     257        9060 :             if ( acelp_cfg.ltp_bits != 0 )
     258             :             {
     259             :                 /* pitch lag decoding */
     260        9060 :                 *pt_pitch = Mode2_pit_decode( acelp_cfg.ltp_mode, i_subfr, L_SUBFR, &prm, &T0, &T0_frac, &T0_res, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max );
     261             : 
     262             :                 /* find pitch excitation */
     263        9060 :                 if ( st->pit_res_max == 6 && !( st->use_partial_copy ) )
     264             :                 {
     265        9060 :                     if ( T0_res == ( st->pit_res_max >> 1 ) )
     266             :                     {
     267        8736 :                         pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac << 1, L_SUBFR + 1, inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 );
     268             :                     }
     269             :                     else
     270             :                     {
     271         324 :                         pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 );
     272             :                     }
     273             :                 }
     274             :                 else
     275             :                 {
     276           0 :                     if ( T0_res == ( st->pit_res_max >> 1 ) )
     277             :                     {
     278           0 :                         pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac << 1, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     279             :                     }
     280             :                     else
     281             :                     {
     282           0 :                         pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     283             :                     }
     284             :                 }
     285             : 
     286             :                 /* LP filtering of the adaptive excitation*/
     287        9060 :                 lp_flag = acelp_cfg.ltf_mode;
     288             : 
     289        9060 :                 if ( acelp_cfg.ltf_mode == NORMAL_OPERATION )
     290             :                 {
     291        4020 :                     lp_flag = *prm;
     292        4020 :                     prm++;
     293             :                 }
     294             : 
     295        9060 :                 lp_filt_exc_dec( st, MODE2, i_subfr, L_SUBFR, L_frame, lp_flag, exc );
     296             :             }
     297             :             else
     298             :             {
     299             :                 /* No adaptive codebook (UC) */
     300           0 :                 set_zero( exc + i_subfr, L_SUBFR );
     301             : 
     302           0 :                 T0 = L_SUBFR;
     303           0 :                 T0_frac = 0;
     304           0 :                 T0_res = 1;
     305           0 :                 pitch_buf[i_subfr / L_SUBFR] = (float) L_SUBFR;
     306             :             }
     307             : 
     308        9060 :             if ( st->igf )
     309             :             {
     310        9060 :                 tbe_celp_exc( st->element_mode, st->idchan, bwe_exc, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, 0 );
     311             :             }
     312             : 
     313        9060 :             pitch_buffer[i_subfr / L_SUBFR] = (float) T0 + (float) T0_frac / (float) T0_res;
     314             : 
     315             :             /*-------------------------------------------------------*
     316             :              * - Decode innovative codebook.                         *
     317             :              *-------------------------------------------------------*/
     318             : 
     319        9060 :             if ( st->use_partial_copy && ( st->rf_frame_type == RF_ALLPRED || ( st->rf_frame_type == RF_GENPRED && ( i_subfr == L_SUBFR || i_subfr == 3 * L_SUBFR ) ) ) )
     320             :             {
     321           0 :                 set_f( code, 0.0f, L_SUBFR );
     322             :             }
     323             :             else
     324             :             {
     325        9060 :                 config = PulseConfTable[acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]];
     326        9060 :                 D_ACELP_indexing( code, config, NB_TRACK_FCB_4T, prm, &st->BER_detect );
     327        9060 :                 ( prm ) += 8;
     328             : 
     329             :                 /*-------------------------------------------------------*
     330             :                  * - Add the fixed-gain pitch contribution to code[].    *
     331             :                  *-------------------------------------------------------*/
     332             : 
     333        9060 :                 cb_shape( acelp_cfg.pre_emphasis, acelp_cfg.pitch_sharpening, acelp_cfg.phase_scrambling, acelp_cfg.formant_enh, acelp_cfg.formant_tilt, acelp_cfg.formant_enh_num, acelp_cfg.formant_enh_den, p_A, code, st->tilt_code, pitch_buf[i_subfr / L_SUBFR], L_SUBFR );
     334             :             }
     335             : 
     336             :             /*-------------------------------------------------------*
     337             :              * - Generate Gaussian excitation                        *
     338             :              *-------------------------------------------------------*/
     339             : 
     340        9060 :             if ( acelp_cfg.gains_mode[i_subfr / L_SUBFR] == 7 && !st->use_partial_copy )
     341             :             {
     342           0 :                 gaus_L2_dec( code2, st->tilt_code, p_A, acelp_cfg.formant_enh_num, &( st->seed_acelp ) );
     343             :             }
     344             :             else
     345             :             {
     346        9060 :                 gain_code2 = 0.f;
     347        9060 :                 set_zero( code2, L_SUBFR );
     348             :             }
     349             : 
     350             :             /*-------------------------------------------------*
     351             :              * - Decode codebooks gains.                       *
     352             :              *-------------------------------------------------*/
     353             : 
     354        9060 :             if ( st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] != 0 )
     355             :             {
     356        9060 :                 decode_acelp_gains( code, acelp_cfg.gains_mode[i_subfr / L_SUBFR], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit ), &( st->past_gcode ), &gain_inov, L_SUBFR, code2, &gain_code2 );
     357             :             }
     358             : 
     359        9060 :             if ( st->use_partial_copy && st->rf_frame_type == RF_ALLPRED )
     360             :             {
     361           0 :                 st->past_gcode = 0.0f;
     362             :             }
     363             : 
     364        9060 :             if ( st->use_partial_copy && st->rf_frame_type == RF_NOPRED )
     365             :             {
     366           0 :                 st->past_gpit = 0.004089f;
     367             :             }
     368             : 
     369             :             /*----------------------------------------------------------*
     370             :              * Update parameters for the next subframe.                 *
     371             :              * - tilt of code: 0.0 (unvoiced) to 0.5 (voiced)           *
     372             :              *----------------------------------------------------------*/
     373             : 
     374        9060 :             st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &( st->voice_fac ), L_SUBFR, acelp_cfg.voice_tilt );
     375             : 
     376        9060 :             pgainT[i_subfr / L_SUBFR] = gain_pit;
     377             : 
     378             :             /*-------------------------------------------------------*
     379             :              * - Find the total excitation.                          *
     380             :              *-------------------------------------------------------*/
     381             : 
     382        9060 :             gain_code_tmp = gain_code;
     383        9060 :             gain_pit_tmp = gain_pit;
     384        9060 :             if ( st->core == ACELP_CORE && st->last_core == ACELP_CORE && ( st->use_partial_copy || st->prev_use_partial_copy ) )
     385             :             {
     386           0 :                 if ( i_subfr > 0 && gain_pit > 1.23f && st->prev_tilt_code_dec > 0.2f && st->next_coder_type == VOICED && ( st->use_partial_copy || st->prev_use_partial_copy ) )
     387             :                 {
     388           0 :                     gain_pit *= ( 0.8f - i_subfr / 640.0f );
     389             :                 }
     390             : 
     391           0 :                 else if ( !st->prev_use_partial_copy && st->last_coder_type == UNVOICED && st->next_coder_type != UNVOICED && gain_code < gain_code_pre )
     392             :                 {
     393           0 :                     gain_code = 0.0f;
     394             :                 }
     395             :             }
     396             : 
     397        9060 :             gain_code_pre = gain_code;
     398        9060 :             st->tilt_code_dec[i_subfr / L_SUBFR] = st->tilt_code;
     399             : 
     400      588900 :             for ( i = 0; i < L_SUBFR; i++ )
     401             :             {
     402      579840 :                 exc2[i + i_subfr] = gain_pit * exc[i + i_subfr];
     403      579840 :                 exc2[i + i_subfr] += gain_code2 * code2[i];
     404      579840 :                 exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];
     405             :             }
     406             : 
     407             :             /*-----------------------------------------------------------------*
     408             :              * Prepare TBE excitation
     409             :              *-----------------------------------------------------------------*/
     410             : 
     411        9060 :             gain_code = gain_code_tmp;
     412        9060 :             gain_pit = gain_pit_tmp;
     413             : 
     414        9060 :             if ( st->igf != 0 )
     415             :             {
     416        9060 :                 prep_tbe_exc( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, gain_preQ, code_preQ, T0, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 );
     417             :             }
     418             : 
     419             :             /*---------------------------------------------------------*
     420             :              * Enhance the excitation                                  *
     421             :              *---------------------------------------------------------*/
     422             : 
     423        9060 :             enhancer( MODE2, -1, acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 0, st->coder_type, L_frame, st->voice_fac, stab_fac, st->past_gcode, gain_inov, &( st->gc_threshold ), code, &exc2[i_subfr], gain_pit, st->dispMem );
     424             : 
     425             :         } /* !RF_NELP frame partial copy */
     426             : 
     427             :         /*----------------------------------------------------------*
     428             :          * - compute the synthesis speech                           *
     429             :          *----------------------------------------------------------*/
     430             : 
     431        9060 :         syn_filt( p_A, M, &exc2[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1 );
     432             : 
     433             :         /*-----------------------------------------------------------------*
     434             :          * update lp_filtered gains for the case of frame erasure
     435             :          *-----------------------------------------------------------------*/
     436             : 
     437        9060 :         st->lp_gainp += weights[i_subfr / L_SUBFR] * st->past_gpit;
     438        9060 :         st->lp_gainc += weights[i_subfr / L_SUBFR] * st->past_gcode;
     439             : 
     440             :         /*----------------------------------------------------------*
     441             :          * - update pitch lag for guided ACELP                      *
     442             :          *----------------------------------------------------------*/
     443             : 
     444        9060 :         if ( st->enableGplc && ( i_subfr / L_SUBFR ) == ( L_frame / L_SUBFR ) - 1 )
     445             :         {
     446        1812 :             st->T0_4th = T0;
     447             :         }
     448             : 
     449             :         /*----------------------------------------------------------*
     450             :          * - Update LPC coeffs                                      *
     451             :          *----------------------------------------------------------*/
     452             : 
     453        9060 :         p_A += ( M + 1 );
     454        9060 :         pt_pitch++;
     455             :         /* copy current gain for next subframe use, in case there is no explicit encoding */
     456        9060 :         prev_gain_pit = gain_pit;
     457             : 
     458             :     } /* end of subframe loop */
     459             : 
     460        1812 :     if ( st->BER_detect )
     461             :     {
     462           0 :         for ( i = 0; i < L_frame; i++ )
     463             :         {
     464           0 :             exc[i] = 0.0f;
     465             :         }
     466           0 :         int_lsp( L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_12k8, 0 );
     467             : 
     468           0 :         p_A = st->Aq_cng;
     469           0 :         if ( st->last_good < UNVOICED_TRANSITION )
     470             :         {
     471           0 :             mvr2r( st->mem_syn2, mem_syn, M );
     472             :         }
     473             :         else
     474             :         {
     475           0 :             set_zero( mem_syn, M );
     476             :         }
     477             : 
     478           0 :         for ( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR )
     479             :         {
     480           0 :             syn_filt( p_A, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1 );
     481           0 :             p_A += ( M + 1 );
     482             :         }
     483             :     }
     484             : 
     485        1812 :     tmp = 0;
     486        1812 :     pA = A + ( st->nb_subfr - 1 ) * ( M + 1 );
     487        1812 :     set_zero( h1, L_SUBFR + 1 );
     488        1812 :     set_zero( mem, M );
     489        1812 :     h1[0] = 1.0f;
     490        1812 :     syn_filt( pA, M, h1, h1, L_SUBFR, mem, 0 );   /* impulse response of LPC     */
     491        1812 :     deemph( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph  */
     492             :     /* impulse response level = gain introduced by synthesis+deemphasis */
     493        1812 :     st->last_gain_syn_deemph = (float) sqrt( dotp( h1, h1, L_SUBFR ) );
     494             : 
     495             :     /*-----------------------------------------------------------*
     496             :      * PLC: [ACELP: Fade-out]
     497             :      * PLC: update the background level
     498             :      *-----------------------------------------------------------*/
     499             : 
     500             :     /* Do the classification */
     501        1812 :     FEC_clas_estim( syn, pitch_buf, st->L_frame, st->core_ext_mode, st->codec_mode, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, CLASSIFIER_ACELP, 0, st->preemph_fac, st->tcxonly, st->last_core_brate, -1 );
     502             : 
     503             :     /* Update Pitch Lag memory */
     504        1812 :     mvr2r( &st->old_pitch_buf[L_frame / L_SUBFR], st->old_pitch_buf, L_frame / L_SUBFR );
     505        1812 :     mvr2r( pitch_buf, &st->old_pitch_buf[L_frame / L_SUBFR], L_frame / L_SUBFR );
     506             : 
     507        1812 :     FEC_scale_syn( st->L_frame, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, 0, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, A, &st->old_enr_LP, mem_back, mem_syn, st->last_con_tcx && ( st->L_frameTCX_past != st->L_frame ) && ( st->last_core != ACELP_CORE ), ( st->clas_dec == ONSET || ( st->last_good >= VOICED_TRANSITION && st->last_good < INACTIVE_CLAS ) ) );
     508             : 
     509             :     /* update ACELP synthesis memory */
     510        1812 :     mvr2r( mem_syn, st->mem_syn2, M );
     511        1812 :     mvr2r( syn + L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
     512             : 
     513        1812 :     tmp = st->syn[M];
     514        1812 :     deemph( syn, st->preemph_fac, L_frame, &tmp );
     515        1812 :     mvr2r( syn + L_frame - ( L_frame / 2 ), st->hTcxDec->old_syn_Overl, L_frame / 2 );
     516        1812 :     mvr2r( syn + L_frame - M - 1, st->syn, M + 1 );
     517        1812 :     mvr2r( syn, synth, L_frame );
     518             : 
     519        1812 :     if ( st->hBWE_TD != NULL )
     520             :     {
     521        1812 :         mvr2r( syn, st->hBWE_TD->old_core_synth, L_frame );
     522             :     }
     523             : 
     524             :     /* update old_exc */
     525        1812 :     mvr2r( exc_buf + L_frame, st->old_exc, L_EXC_MEM_DEC );
     526             : 
     527             :     /* Output pitch parameters for bass post-filter */
     528       10872 :     for ( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR )
     529             :     {
     530        9060 :         *pT++ = (int16_t) ( pitch_buf[i_subfr / L_SUBFR] + 0.5f );
     531             :     }
     532             : 
     533             :     /* Update TCX-LTP */
     534        1812 :     hTcxDec->tcxltp_last_gain_unmodified = 0.f;
     535             : 
     536             :     /*Update MODE1*/
     537        1812 :     mvr2r( p_A - ( M + 1 ), st->old_Aq_12_8, M + 1 );
     538        1812 :     st->old_Es_pred = Es_pred;
     539             : 
     540        1812 :     hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch;
     541        1812 :     hTcxDec->tcxltp_second_last_pitch = st->old_fpitch;
     542        1812 :     st->old_fpitch = pitch_buf[( L_frame / L_SUBFR ) - 1];
     543             : 
     544        1812 :     return;
     545             : }

Generated by: LCOV version 1.14