LCOV - code coverage report
Current view: top level - lib_dec - evs_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 229 332 69.0 %
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             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include <math.h>
      43             : #include "cnst.h"
      44             : #include "rom_com.h"
      45             : #include "prot.h"
      46             : #include "wmc_auto.h"
      47             : #ifdef DEBUG_PLOT
      48             : #include "deb_out.h"
      49             : #endif
      50             : 
      51             : /*--------------------------------------------------------------------------*
      52             :  * evs_dec()
      53             :  *
      54             :  * Principal decoder routine
      55             :  *--------------------------------------------------------------------------*/
      56             : 
      57        9300 : ivas_error evs_dec(
      58             :     Decoder_State *st,              /* i/o: Decoder state structure         */
      59             :     float mem_hp20_out[L_HP20_MEM], /* i/o: HP filter memory for synthesis  */
      60             :     float *output,                  /* o  : output synthesis signal         */
      61             :     FRAME_MODE frameMode            /* i  : Decoder frame mode              */
      62             : )
      63             : {
      64             :     int16_t i, output_frame;
      65             :     int16_t sharpFlag;
      66             :     float synth[L_FRAME48k];
      67             :     float hb_synth[L_FRAME48k];
      68             :     float tmp_buffer[L_FRAME48k];
      69             :     int16_t tmps, incr;
      70             :     float bwe_exc_extended[L_FRAME32k + NL_BUFF_OFFSET];
      71             :     float voice_factors[NB_SUBFR16k];
      72             :     float fb_exc[L_FRAME16k];
      73             :     int16_t core_switching_flag;
      74             :     float old_syn_12k8_16k[L_FRAME16k];
      75             :     float tmp, tmpF;
      76             :     float pitch_buf[NB_SUBFR16k];
      77             :     int16_t unbits;
      78             :     int16_t hq_core_type;
      79             :     int16_t sid_bw;
      80             :     int16_t delay_comp, delta, delay_tdbwe;
      81             :     int16_t concealWholeFrame; /* status after decoding */
      82             :     int16_t concealWholeFrameTmp;
      83             :     float pcmbufFB[L_FRAME_MAX];
      84        9300 :     TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
      85             :     ivas_error error;
      86             : 
      87        9300 :     error = IVAS_ERR_OK;
      88             : 
      89        9300 :     push_wmops( "evs_dec" );
      90             :     /*------------------------------------------------------------------*
      91             :      * Initialization
      92             :      *-----------------------------------------------------------------*/
      93             : 
      94        9300 :     st->idchan = 0;
      95        9300 :     st->flag_ACELP16k = set_ACELP_flag( EVS_MONO, -1, st->total_brate, 0, 0, -1, -1 );
      96             : 
      97        9300 :     tmps = 0;
      98        9300 :     delay_tdbwe = 0;
      99        9300 :     sid_bw = -1;
     100        9300 :     concealWholeFrameTmp = -1;
     101        9300 :     if ( !st->bfi )
     102             :     {
     103        9300 :         st->extl = -1;
     104             :     }
     105             : 
     106        9300 :     output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC );
     107             : 
     108        9300 :     core_switching_flag = 0;
     109        9300 :     sharpFlag = 0;
     110        9300 :     unbits = 0;
     111             : 
     112        9300 :     st->use_partial_copy = 0;
     113        9300 :     st->rf_flag = 0;
     114             : 
     115        9300 :     if ( st->bfi == 1 )
     116             :     {
     117           0 :         hq_core_type = st->hHQ_core->last_hq_core_type;
     118           0 :         st->coder_type = st->last_coder_type;
     119             :     }
     120             :     else
     121             :     {
     122        9300 :         hq_core_type = -1;
     123        9300 :         st->coder_type = INACTIVE;
     124             :     }
     125             : 
     126             :     /* PLC: [TCX: Fade-out-recovery]
     127             :      * PLC: overlapping part needs to be attenuated for first good frame */
     128        9300 :     if ( !st->bfi && st->prev_bfi && ( st->last_codec_mode == MODE2 ) && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) )
     129             :     {
     130           0 :         v_multc( st->hHQ_core->old_out, st->hPlcInfo->recovery_gain, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX );
     131           0 :         v_multc( st->hHQ_core->old_outLB, st->hPlcInfo->recovery_gain, st->hHQ_core->old_outLB, st->L_frame );
     132             : 
     133           0 :         if ( !st->hTcxCfg->last_aldo )
     134             :         {
     135           0 :             v_multc( st->hTcxDec->syn_OverlFB, st->hPlcInfo->recovery_gain, st->hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB );
     136           0 :             v_multc( st->hTcxDec->syn_Overl, st->hPlcInfo->recovery_gain, st->hTcxDec->syn_Overl, st->hTcxCfg->tcx_mdct_window_length );
     137             :         }
     138             :     }
     139             : 
     140        9300 :     set_f( voice_factors, 0.f, NB_SUBFR16k );
     141             : 
     142        9300 :     set_f( hb_synth, 0.0f, L_FRAME48k );
     143             : 
     144        9300 :     st->rate_switching_reset = 0;
     145             : 
     146        9300 :     if ( !st->bfi )
     147             :     {
     148        9300 :         st->flagGuidedAcelp = 0;
     149             :     }
     150             : 
     151             :     /*----------------------------------------------------------------*
     152             :      * Updates in case of AMR-WB IO mode -> EVS primary mode switching
     153             :      *----------------------------------------------------------------*/
     154             : 
     155        9300 :     if ( st->last_core == AMR_WB_CORE )
     156             :     {
     157           0 :         updt_IO_switch_dec( output_frame, st );
     158             :     }
     159             : 
     160        9300 :     if ( frameMode != FRAMEMODE_MISSING ) /* frame mode normal or future frame */
     161             :     {
     162        9300 :         getPartialCopyInfo( st, &sharpFlag );
     163        9300 :         frameMode = st->bfi;
     164             :     }
     165             : 
     166        9300 :     if ( st->rf_frame_type == RF_NO_DATA && st->use_partial_copy )
     167             :     {
     168             :         /* the partial copy is a RF FRAME_NO_DATA frame and should follow the concealment path*/
     169           0 :         st->bfi = 1;
     170           0 :         st->codec_mode = st->last_codec_mode;
     171           0 :         frameMode = FRAMEMODE_MISSING;
     172           0 :         st->use_partial_copy = 0;
     173             :     }
     174             : 
     175             :     /* if previous frame was concealed via ACELP, drop TCX partial copy info and continue ACELP concealment */
     176        9300 :     if ( st->use_partial_copy && st->core == TCX_20_CORE && st->prev_bfi && st->last_core == ACELP_CORE )
     177             :     {
     178           0 :         st->bfi = 1;
     179           0 :         st->codec_mode = st->last_codec_mode;
     180           0 :         frameMode = FRAMEMODE_MISSING;
     181           0 :         st->use_partial_copy = 0;
     182           0 :         st->core = ACELP_CORE;
     183             :     }
     184             : 
     185             :     /* if previous frame was HQ Core/TCX10/TCX20 (high bitrate), drop partial copy info and continue HQ Core/TCX10/TCX20 concealment */
     186        9300 :     if ( st->use_partial_copy && ( st->last_core == HQ_CORE || st->last_core == TCX_10_CORE || ( st->last_core == TCX_20_CORE && getTcxonly( EVS_MONO, st->last_total_brate, 0, 0 ) ) ) )
     187             :     {
     188           0 :         st->bfi = 1;
     189           0 :         st->codec_mode = st->last_codec_mode;
     190           0 :         frameMode = FRAMEMODE_MISSING;
     191           0 :         st->use_partial_copy = 0;
     192           0 :         st->core = st->last_core;
     193             :     }
     194             : 
     195             :     /*------------------------------------------------------------------*
     196             :      * Decoding
     197             :      *-----------------------------------------------------------------*/
     198             : 
     199        9300 :     if ( st->codec_mode == MODE1 )
     200             :     {
     201             :         /*------------------------------------------------------------------*
     202             :          * Decision matrix (selection of technologies)
     203             :          *-----------------------------------------------------------------*/
     204             : 
     205             :         /* decision matrix (selection of technologies) */
     206        5550 :         if ( st->bfi != 1 )
     207             :         {
     208        5550 :             decision_matrix_dec( st, &sharpFlag, &hq_core_type, &core_switching_flag );
     209             : 
     210        5550 :             if ( st->bfi != 1 )
     211             :             {
     212        5550 :                 st->sr_core = st->L_frame * FRAMES_PER_SEC;
     213        5550 :                 st->fscale_old = st->fscale;
     214        5550 :                 st->fscale = sr2fscale( st->sr_core );
     215             :             }
     216             :             else
     217             :             {
     218           0 :                 frameMode = FRAMEMODE_MISSING;
     219             :             }
     220             :         }
     221             :     }
     222             : 
     223        9300 :     if ( st->codec_mode == MODE1 )
     224             :     {
     225             :         /*------------------------------------------------------------------*
     226             :          * Initialization
     227             :          *-----------------------------------------------------------------*/
     228             : 
     229        5550 :         if ( st->bfi == 1 )
     230             :         {
     231           0 :             st->nbLostCmpt++;
     232             :         }
     233             :         else
     234             :         {
     235        5550 :             st->nbLostCmpt = 0;
     236             :         }
     237        5550 :         st->enablePlcWaveadjust = 0;
     238             : 
     239             :         /*---------------------------------------------------------------------*
     240             :          * Detect bandwidth switching
     241             :          *---------------------------------------------------------------------*/
     242             : 
     243        5550 :         bandwidth_switching_detect( st );
     244             : 
     245             :         /*---------------------------------------------------------------------*
     246             :          * Preprocessing (preparing) for ACELP/HQ core switching
     247             :          *---------------------------------------------------------------------*/
     248             : 
     249        5550 :         if ( ( error = core_switching_pre_dec( st, output_frame, -1, -1, EVS_MONO, -1 ) ) != IVAS_ERR_OK )
     250             :         {
     251           0 :             return error;
     252             :         }
     253             : 
     254             :         /*---------------------------------------------------------------------*
     255             :          * ACELP core decoding
     256             :          * HQ core decoding
     257             :          *---------------------------------------------------------------------*/
     258             : 
     259        5550 :         if ( st->core == ACELP_CORE )
     260             :         {
     261             :             /* ACELP core decoder */
     262        4230 :             if ( ( error = acelp_core_dec( st, NULL, synth, NULL, bwe_exc_extended, voice_factors, old_syn_12k8_16k, sharpFlag, pitch_buf, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK )
     263             :             {
     264           0 :                 return error;
     265             :             }
     266             :         }
     267             :         else
     268             :         {
     269             :             /* HQ core decoder */
     270        1320 :             hq_core_dec( st, synth, output_frame, hq_core_type, core_switching_flag, NULL );
     271             :         }
     272             : 
     273             :         /*---------------------------------------------------------------------*
     274             :          * Postprocessing for ACELP/MDCT core switching
     275             :          *---------------------------------------------------------------------*/
     276             : 
     277        5550 :         if ( ( error = core_switching_post_dec( st, synth, NULL, NULL, 0, output_frame, core_switching_flag, 0, -1, EVS_MONO ) ) != IVAS_ERR_OK )
     278             :         {
     279           0 :             return error;
     280             :         }
     281             : 
     282             :         /*---------------------------------------------------------------------*
     283             :          * Pre-processing for bandwidth switching
     284             :          *---------------------------------------------------------------------*/
     285        5550 :         push_wmops( "BWE_decoding" );
     286             : 
     287        5550 :         bw_switching_pre_proc( st, old_syn_12k8_16k, -1, 1 );
     288             : 
     289             :         /*---------------------------------------------------------------------*
     290             :          * WB TBE decoding
     291             :          * WB BWE decoding
     292             :          *---------------------------------------------------------------------*/
     293             : 
     294        5550 :         if ( st->extl == WB_TBE )
     295             :         {
     296             :             /* WB TBE decoder */
     297           0 :             wb_tbe_dec( st, bwe_exc_extended, voice_factors, hb_synth );
     298             :         }
     299             : 
     300        5550 :         if ( st->extl == WB_BWE && st->bws_cnt == 0 )
     301             :         {
     302             :             /* WB BWE decoder */
     303           0 :             wb_bwe_dec( st, NULL, synth, hb_synth, 0, output_frame, voice_factors, pitch_buf );
     304             :         }
     305             : 
     306             :         /*---------------------------------------------------------------------*
     307             :          * SWB(FB) TBE decoding
     308             :          * SWB(FB) BWE decoding
     309             :          *---------------------------------------------------------------------*/
     310             : 
     311        5550 :         if ( st->extl == SWB_TBE || st->extl == FB_TBE || ( st->coder_type != AUDIO && st->coder_type != INACTIVE && st->core_brate >= SID_2k40 && st->core == ACELP_CORE && st->output_Fs >= 32000 && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) )
     312             :         {
     313             :             /* SWB TBE decoder */
     314        2205 :             swb_tbe_dec( st, NULL, bwe_exc_extended, voice_factors, old_syn_12k8_16k, fb_exc, hb_synth, pitch_buf );
     315             : 
     316             :             /* FB TBE decoder */
     317        2205 :             if ( output_frame == L_FRAME48k && st->extl == FB_TBE )
     318             :             {
     319           0 :                 fb_tbe_dec( st, fb_exc, hb_synth, NULL, L_FRAME48k );
     320             :             }
     321             :         }
     322        3345 :         else if ( st->extl == SWB_BWE || st->extl == FB_BWE || ( st->output_Fs >= 32000 && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) )
     323             :         {
     324             :             /* SWB BWE decoder */
     325          18 :             swb_bwe_dec( st, NULL, synth, hb_synth, 0, output_frame );
     326             :         }
     327        3327 :         else if ( st->extl == SWB_BWE_HIGHRATE || st->extl == FB_BWE_HIGHRATE )
     328             :         {
     329        2007 :             swb_bwe_dec_hr( st, old_syn_12k8_16k, hb_synth, output_frame, unbits, pitch_buf );
     330             :         }
     331             : 
     332             :         /*---------------------------------------------------------------------*
     333             :          * FEC - recovery after lost HQ core (smoothing of the BWE component)
     334             :          *---------------------------------------------------------------------*/
     335             : 
     336        5550 :         if ( st->prev_bfi && st->last_core == HQ_CORE && st->extl != -1 )
     337             :         {
     338           0 :             tmp = FRAC_BWE_SMOOTH / output_frame;
     339             : 
     340           0 :             for ( i = 0; i < output_frame / FRAC_BWE_SMOOTH; i++ )
     341             :             {
     342           0 :                 hb_synth[i] *= ( i * tmp );
     343             :             }
     344             :         }
     345             : 
     346             :         /*---------------------------------------------------------------------*
     347             :          * SWB CNG
     348             :          *---------------------------------------------------------------------*/
     349             : 
     350        5550 :         if ( output_frame >= L_FRAME32k )
     351             :         {
     352             :             /* SHB CNG decoder */
     353        5550 :             swb_CNG_dec( st, synth, hb_synth, sid_bw );
     354             :         }
     355             : 
     356        5550 :         pop_wmops();
     357             : 
     358             :         /*----------------------------------------------------------------*
     359             :          * Delay ACELP core synthesis to be synchronized with the components of bandwidth extension layers
     360             :          *----------------------------------------------------------------*/
     361             : 
     362        5550 :         if ( output_frame >= L_FRAME16k )
     363             :         {
     364        5550 :             tmps = NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS );
     365        5550 :             delay_signal( synth, output_frame, st->prev_synth_buffer, tmps );
     366             :         }
     367             : 
     368        5550 :         if ( st->core == ACELP_CORE && !st->bfi && st->prev_bfi && st->last_total_brate >= HQ_48k && st->last_codec_mode == MODE2 && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hPlcInfo->concealment_method == TCX_NONTONAL && st->hPlcInfo->nbLostCmpt < 4 )
     369             :         {
     370           0 :             tmps = 0;
     371           0 :             if ( output_frame >= L_FRAME16k )
     372             :             {
     373           0 :                 tmps = NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS );
     374             :             }
     375             : 
     376           0 :             waveform_adj2( st->hPlcInfo, st->hTonalMDCTConc->secondLastPcmOut, synth + tmps, tmps, st->hPlcInfo->nbLostCmpt + 1, st->bfi );
     377           0 :             st->hPlcInfo->Pitch = 0;
     378             :         }
     379             : 
     380             :         /*----------------------------------------------------------------*
     381             :          * Addition of BWE components to the ACELP core synthesis
     382             :          *----------------------------------------------------------------*/
     383             : 
     384        5550 :         if ( st->extl != -1 || ( st->bws_cnt > 0 && st->core == ACELP_CORE ) )
     385             :         {
     386             :             /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */
     387        4230 :             if ( st->L_frame == L_FRAME )
     388             :             {
     389             :                 /* TBE on top of ACELP@12.8kHz */
     390        2223 :                 tmps = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS );
     391             :             }
     392             :             else
     393             :             {
     394        2007 :                 if ( st->extl == SWB_BWE_HIGHRATE || st->extl == FB_BWE_HIGHRATE )
     395             :                 {
     396             :                     /* HR SWB BWE on top of ACELP@16kHz */
     397        2007 :                     tmps = NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS );
     398             :                 }
     399             :                 else
     400             :                 {
     401             :                     /* TBE on top of ACELP@16kHz */
     402           0 :                     tmps = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS );
     403             :                 }
     404             :             }
     405             : 
     406             :             /* Smooth transitions when switching between different technologies */
     407        4230 :             if ( ( st->extl != st->last_extl || ( st->extl == st->last_extl && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( st->extl == SWB_CNG && st->last_extl == SWB_TBE ) )
     408             :             {
     409             :                 /* switching between BWE and TBE technologies */
     410         108 :                 incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) );
     411        3921 :                 for ( i = 0; i < tmps; i++ )
     412             :                 {
     413        3813 :                     hb_synth[i] *= sin_table256[i * incr];
     414             :                 }
     415             : 
     416         108 :                 set_f( st->hb_prev_synth_buffer, 0.0f, tmps );
     417             :             }
     418        4122 :             else if ( tmps < st->old_bwe_delay )
     419             :             {
     420             :                 /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */
     421           0 :                 incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) );
     422           0 :                 for ( i = 0; i < tmps; i++ )
     423             :                 {
     424           0 :                     tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr] +
     425           0 :                                     st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];
     426             :                 }
     427             : 
     428           0 :                 mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps );
     429             :             }
     430        4122 :             else if ( tmps > st->old_bwe_delay )
     431             :             {
     432             :                 /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */
     433           6 :                 incr = (int16_t) ( L_FRAME / ( st->old_bwe_delay + 0.5f ) );
     434           6 :                 for ( i = 0; i < st->old_bwe_delay; i++ )
     435             :                 {
     436           0 :                     tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr];
     437             :                 }
     438             : 
     439         345 :                 for ( ; i < tmps; i++ )
     440             :                 {
     441         339 :                     tmp_buffer[i] = 0.0f;
     442             :                 }
     443             : 
     444           6 :                 for ( i = 0; i < st->old_bwe_delay; i++ )
     445             :                 {
     446           0 :                     tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];
     447             :                 }
     448             : 
     449           6 :                 mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps );
     450             :             }
     451             : 
     452             :             /* Delay hb_synth */
     453        4230 :             delay_signal( hb_synth, output_frame, st->hb_prev_synth_buffer, tmps );
     454             : 
     455        4230 :             st->old_bwe_delay = tmps;
     456        4230 :             if ( ( st->ppp_mode_dec || ( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) && st->L_frame == st->last_L_frame && ( st->bws_cnt > 1 || st->last_extl != -1 ) )
     457             :             {
     458           0 :                 mvr2r( st->hBWE_TD->old_hb_synth, hb_synth, output_frame );
     459             :             }
     460             :             else
     461             :             {
     462        4230 :                 mvr2r( hb_synth, st->hBWE_TD->old_hb_synth, output_frame );
     463             :             }
     464             : 
     465             :             /* Add the delayed hb_synth component to the delayed ACELP synthesis */
     466        4230 :             v_add( synth, hb_synth, synth, output_frame );
     467             : 
     468             :             /* SWB CNG/DTX - calculate SHB energy */
     469        4230 :             if ( output_frame >= L_FRAME32k && st->extl > SWB_CNG && st->hTdCngDec != NULL )
     470             :             {
     471        4230 :                 st->hTdCngDec->last_shb_ener = 0.001f;
     472     3353670 :                 for ( i = 0; i < output_frame; i++ )
     473             :                 {
     474     3349440 :                     st->hTdCngDec->last_shb_ener += hb_synth[i] * hb_synth[i];
     475             :                 }
     476        4230 :                 st->hTdCngDec->last_shb_ener /= (float) output_frame;
     477        4230 :                 st->hTdCngDec->last_shb_ener = 10 * (float) log10( st->hTdCngDec->last_shb_ener );
     478             :             }
     479             :         }
     480             : 
     481             :         /* TCX-LTP Postfilter: used in Mode 1 to update memories and to avoid discontinuities when the past frame was TCX */
     482        5550 :         tcx_ltp_post( st, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth, NULL );
     483             : 
     484             :         /* final output of synthesis signal */
     485        5550 :         mvr2r( synth, output, output_frame );
     486             :     }
     487             :     else /* Mode 2 */
     488             :     {
     489             : 
     490             :         /* -------------------------------------------------------------- *
     491             :          * Mode 2 concealment
     492             :          * -------------------------------------------------------------- */
     493             : 
     494        3750 :         concealWholeFrame = 0;
     495             : 
     496        3750 :         if ( frameMode == FRAMEMODE_NORMAL )
     497             :         {
     498        3750 :             st->m_decodeMode = DEC_NO_FRAM_LOSS;
     499             :         }
     500             : 
     501        3750 :         if ( frameMode == FRAMEMODE_MISSING )
     502             :         {
     503           0 :             if ( st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 )
     504             :             {
     505           0 :                 st->m_decodeMode = DEC_NO_FRAM_LOSS;
     506             :             }
     507             :             else
     508             :             {
     509           0 :                 st->m_decodeMode = DEC_CONCEALMENT_EXT;
     510             :             }
     511             :         }
     512             : 
     513        3750 :         if ( st->m_decodeMode == DEC_CONCEALMENT_EXT )
     514             :         {
     515           0 :             concealWholeFrame = 1;
     516             :         }
     517             : 
     518             :         /* -------------------------------------------------------------- *
     519             :          * Decode core
     520             :          * -------------------------------------------------------------- */
     521             : 
     522        3750 :         dec_acelp_tcx_frame( st, &concealWholeFrame, output, st->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended, voice_factors, pitch_buf, NULL );
     523             : 
     524        3750 :         concealWholeFrameTmp = concealWholeFrame;
     525        3750 :         if ( st->bfi )
     526             :         {
     527           0 :             frameMode = FRAMEMODE_MISSING;
     528             :         }
     529             : 
     530        3750 :         if ( st->igf )
     531             :         {
     532             :             /* TBE for Mode 2 interface */
     533        3750 :             if ( ( st->bfi == 0 || st->last_core == ACELP_CORE ) && st->core == ACELP_CORE )
     534             :             {
     535        1812 :                 switch ( st->bwidth )
     536             :                 {
     537           0 :                     case WB:
     538           0 :                         st->extl = WB_TBE;
     539           0 :                         st->extl_brate = WB_TBE_0k35;
     540           0 :                         break;
     541        1812 :                     case SWB:
     542        1812 :                         st->extl = SWB_TBE;
     543        1812 :                         st->extl_brate = SWB_TBE_1k6;
     544             : 
     545        1812 :                         if ( st->total_brate < ACELP_13k20 )
     546             :                         {
     547           0 :                             st->extl_brate = SWB_TBE_0k95;
     548             :                         }
     549        1812 :                         else if ( st->total_brate >= ACELP_24k40 )
     550             :                         {
     551        1812 :                             st->extl_brate = SWB_TBE_2k8;
     552             :                         }
     553             : 
     554        1812 :                         break;
     555             : 
     556           0 :                     case FB:
     557           0 :                         st->extl = FB_TBE;
     558           0 :                         st->extl_brate = FB_TBE_1k8;
     559             : 
     560           0 :                         if ( st->total_brate >= ACELP_24k40 )
     561             :                         {
     562           0 :                             st->extl_brate = FB_TBE_3k0;
     563             :                         }
     564             : 
     565           0 :                         break;
     566             :                 }
     567        1812 :             }
     568             :             else
     569             :             {
     570        1938 :                 st->extl = IGF_BWE;
     571        1938 :                 st->extl_brate = 0;
     572             :             }
     573             : 
     574        3750 :             if ( st->output_Fs == 8000 || ( st->output_Fs == 16000 && st->L_frame == L_FRAME16k ) )
     575             :             {
     576           0 :                 st->extl = -1;
     577             :             }
     578             : 
     579        3750 :             st->core_brate = st->total_brate - st->extl_brate;
     580             : 
     581        3750 :             st->bws_cnt = 0;
     582        3750 :             st->bws_cnt1 = 0;
     583        3750 :             st->tilt_wb = 0;
     584             : 
     585        3750 :             if ( st->m_frame_type == ACTIVE_FRAME )
     586             :             {
     587        3750 :                 if ( ( st->bfi == 0 || st->last_core == ACELP_CORE ) && st->core == ACELP_CORE )
     588             :                 {
     589        1812 :                     if ( st->extl == WB_TBE )
     590             :                     {
     591           0 :                         wb_tbe_dec( st, bwe_exc_extended, voice_factors, hb_synth );
     592             :                     }
     593        1812 :                     else if ( st->extl == SWB_TBE || st->extl == FB_TBE )
     594             :                     {
     595             :                         /* SWB TBE decoder */
     596        1812 :                         swb_tbe_dec( st, NULL, bwe_exc_extended, voice_factors, st->hBWE_TD->old_core_synth, fb_exc, hb_synth, pitch_buf );
     597             : 
     598        1812 :                         if ( st->extl == FB_TBE && output_frame == L_FRAME48k )
     599             :                         {
     600           0 :                             fb_tbe_dec( st, fb_exc, hb_synth, NULL, L_FRAME48k );
     601             :                         }
     602             :                     }
     603        1812 :                     mvr2r( hb_synth, st->hBWE_TD->old_hb_synth, output_frame );
     604             :                 }
     605             :                 else
     606             :                 {
     607        1938 :                     if ( st->last_core == ACELP_CORE )
     608             :                     {
     609         114 :                         if ( ( st->bwidth == SWB || st->bwidth == FB ) &&
     610         114 :                              ( ( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) && st->last_codec_mode == MODE2 ) )
     611             :                         {
     612          66 :                             GenTransition( st->hBWE_TD, hb_synth, st->output_Fs, EVS_MONO, st->L_frame, st->rf_flag, st->total_brate );
     613             :                         }
     614          48 :                         else if ( st->bwidth == WB && st->last_extl == WB_TBE )
     615             :                         {
     616           0 :                             GenTransition_WB( st->hBWE_TD, hb_synth, st->output_Fs );
     617             :                         }
     618             : 
     619         114 :                         TBEreset_dec( st );
     620             :                     }
     621        1824 :                     else if ( st->last_codec_mode == MODE1 )
     622             :                     {
     623          39 :                         swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) );
     624             : 
     625          39 :                         if ( st->extl == FB_TBE )
     626             :                         {
     627           0 :                             set_f( st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER );
     628           0 :                             st->hBWE_TD->fb_tbe_demph = 0;
     629           0 :                             fb_tbe_reset_synth( st->hBWE_TD->fbbwe_hpf_mem, &st->hBWE_TD->prev_fbbwe_ratio );
     630             :                         }
     631          39 :                         swb_tbe_reset_synth( st->hBWE_TD->genSHBsynth_Hilbert_Mem, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local );
     632             :                     }
     633             :                 }
     634             :             }
     635             :         }
     636             : 
     637             : 
     638        3750 :         if ( st->m_frame_type != ACTIVE_FRAME )
     639             :         {
     640           0 :             st->extl = -1;
     641           0 :             st->extl_brate = 0;
     642             :         }
     643             : 
     644             :         /* -------------------------------------------------------------- *
     645             :          * Postprocessing
     646             :          * -------------------------------------------------------------- */
     647             :         {
     648             :             float *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX];
     649             :             float realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
     650             : 
     651       63750 :             for ( i = 0; i < CLDFB_NO_COL_MAX; i++ )
     652             :             {
     653       60000 :                 set_f( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
     654       60000 :                 set_f( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
     655       60000 :                 realBuffer[i] = realBufferTmp[i];
     656       60000 :                 imagBuffer[i] = imagBufferTmp[i];
     657             :             }
     658             : 
     659        3750 :             st->cldfbSyn->nab = min( st->cldfbAna->no_channels, st->cldfbSyn->no_channels );
     660        3750 :             st->cldfbAna->nab = 0;
     661             : 
     662        3750 :             if ( st->hFdCngDec != NULL && ( st->sr_core == 8000 || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) && st->total_brate <= ACELP_32k )
     663             :             {
     664             :                 /* -------------------------------------------------------------- *
     665             :                  * In CLDFB domain:
     666             :                  *   - perform noise estimation during active frames
     667             :                  *   - do CNG during inactive frames
     668             :                  * -------------------------------------------------------------- */
     669             : 
     670        3750 :                 noisy_speech_detection( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, output );
     671             : 
     672        3750 :                 st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech;
     673             : 
     674        3750 :                 st->lp_noise = st->hFdCngDec->lp_noise;
     675             : 
     676        3750 :                 ApplyFdCng( output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0 );
     677             : 
     678             :                 /* Generate additional comfort noise to mask potential coding artefacts */
     679        3750 :                 if ( st->m_frame_type == ACTIVE_FRAME && st->flag_cna )
     680             :                 {
     681         825 :                     generate_masking_noise( output, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, NULL, -1 );
     682             :                 }
     683             :             }
     684             : 
     685        3750 :             if ( st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ( ( st->last_core == ACELP_CORE && st->last_coder_type != AUDIO ) || st->last_core == TCX_20_CORE || st->last_core == AMR_WB_CORE ) )
     686             :             {
     687           0 :                 v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, tmp_buffer, st->L_frame / 2 );
     688           0 :                 v_add( tmp_buffer, output, output, st->L_frame / 2 );
     689             :             }
     690             : 
     691        3750 :             if ( st->m_frame_type == ACTIVE_FRAME )
     692             :             {
     693        3750 :                 cldfbAnalysis( output, realBuffer, imagBuffer, -1, st->cldfbAna );
     694             :             }
     695             :             else
     696             :             {
     697             :                 float timeDomainBuffer[L_FRAME16k];
     698             :                 float A[M + 1];
     699             : 
     700           0 :                 mvr2r( st->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st->L_frame );
     701           0 :                 mvr2r( st->hFdCngDec->hFdCngCom->A_cng, A, M + 1 );
     702             : 
     703           0 :                 update_decoder_LPD_cng( st, timeDomainBuffer, A, st->p_bpf_noise_buf );
     704             : 
     705             :                 /* Generate additional comfort noise to mask potential coding artefacts */
     706           0 :                 if ( st->flag_cna )
     707             :                 {
     708           0 :                     generate_masking_noise( timeDomainBuffer, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, NULL, -1 );
     709             :                 }
     710           0 :                 else if ( st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ( ( st->last_core == ACELP_CORE && st->last_coder_type != AUDIO ) || st->last_core == TCX_20_CORE || st->last_core == AMR_WB_CORE ) )
     711             :                 {
     712           0 :                     v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, tmp_buffer, st->L_frame / 2 );
     713           0 :                     v_add( tmp_buffer, timeDomainBuffer, timeDomainBuffer, st->L_frame / 2 );
     714             :                 }
     715             : 
     716             :                 /* check if the CLDFB works on the right sample rate */
     717           0 :                 if ( ( st->cldfbAna->no_channels * st->cldfbAna->no_col ) != st->L_frame )
     718             :                 {
     719           0 :                     resampleCldfb( st->cldfbAna, ( st->L_frame * FRAMES_PER_SEC ) );
     720           0 :                     resampleCldfb( st->cldfbBPF, ( st->L_frame * FRAMES_PER_SEC ) );
     721             :                 }
     722             : 
     723           0 :                 st->cldfbSyn->bandsToZero = 0;
     724           0 :                 if ( st->bwidth == NB && st->cldfbSyn->no_channels > 10 )
     725             :                 {
     726           0 :                     st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - 10;
     727             :                 }
     728           0 :                 else if ( st->hFdCngDec->hFdCngCom->regularStopBand < st->cldfbSyn->no_channels )
     729             :                 {
     730           0 :                     st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->hFdCngDec->hFdCngCom->regularStopBand;
     731             :                 }
     732           0 :                 cldfbAnalysis( timeDomainBuffer, realBuffer, imagBuffer, -1, st->cldfbAna );
     733             :             }
     734             : 
     735        3750 :             if ( st->flag_cna == 0 )
     736             :             {
     737        2925 :                 set_f( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.f, st->hFdCngDec->hFdCngCom->fftlen );
     738             :             }
     739             : 
     740        3750 :             if ( st->p_bpf_noise_buf )
     741             :             {
     742        3750 :                 addBassPostFilter( st->p_bpf_noise_buf, -1, realBuffer, imagBuffer, st->cldfbBPF );
     743             :             }
     744             : 
     745        3750 :             if ( st->output_Fs > 8000 && st->hTECDec != NULL )
     746             :             {
     747        3750 :                 calcGainTemp_TBE( realBuffer, imagBuffer, st->hTECDec->loBuffer, 0, st->cldfbAna->no_col, st->cldfbAna->no_channels, st->hTECDec->pGainTemp, st->tec_flag );
     748             :             }
     749             : 
     750             :             /* set high band buffers to zero. Covering the current frame and the overlap area. */
     751        3750 :             if ( st->m_frame_type == ACTIVE_FRAME )
     752             :             {
     753       63750 :                 for ( i = 0; i < CLDFB_NO_COL_MAX; i++ )
     754             :                 {
     755       60000 :                     set_f( &realBuffer[i][st->cldfbSyn->nab], 0.f, st->cldfbSyn->no_channels - st->cldfbSyn->nab );
     756       60000 :                     set_f( &imagBuffer[i][st->cldfbSyn->nab], 0.f, st->cldfbSyn->no_channels - st->cldfbSyn->nab );
     757             :                 }
     758             :             }
     759             : 
     760        3750 :             cldfbSynthesis( realBuffer, imagBuffer, output, -1, st->cldfbSyn );
     761             : 
     762             :             /* set multiplication factor according to the sampling rate */
     763        3750 :             delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
     764        3750 :             delay_tdbwe = NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS );
     765             : 
     766             :             /* MODE1 MDCT to ACELP 2 transition */
     767        3750 :             if ( st->last_codec_mode == MODE1 && st->last_core_bfi > ACELP_CORE )
     768             :             {
     769          63 :                 mvr2r( st->delay_buf_out, output, delay_comp ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */
     770             : 
     771          63 :                 if ( st->core == ACELP_CORE )
     772             :                 {
     773          24 :                     tmpF = 1.0f / (float) NS2SA( st->output_Fs, 3000000 );
     774          24 :                     if ( st->prev_bfi && st->hHQ_core->HqVoicing )
     775             :                     {
     776           0 :                         mvr2r( st->hHQ_core->fer_samples, st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, 3000000 ) );
     777             :                     }
     778        3480 :                     for ( i = 0; i < NS2SA( st->output_Fs, 3000000 ); i++ )
     779             :                     {
     780        3456 :                         output[i + delay_comp] = ( 1 - tmpF * (float) i ) * st->hHQ_core->old_out[i + NS2SA( st->output_Fs, N_ZERO_MDCT_NS )] + tmpF * (float) i * output[i + delay_comp];
     781             :                     }
     782             :                 }
     783             :                 else
     784             :                 {
     785          39 :                     if ( st->output_Fs == 8000 )
     786             :                     {
     787           0 :                         mvr2r( st->delay_buf_out, st->hTcxDec->FBTCXdelayBuf, delay_comp );
     788             :                     }
     789             :                     else
     790             :                     {
     791          39 :                         mvr2r( st->prev_synth_buffer, st->hTcxDec->FBTCXdelayBuf, delay_tdbwe );
     792          39 :                         mvr2r( st->delay_buf_out, st->hTcxDec->FBTCXdelayBuf + delay_tdbwe, delay_comp );
     793             :                     }
     794             :                 }
     795             :             }
     796             : 
     797             :             /* set delay compensation between HQ synthesis and ACELP synthesis */
     798        3750 :             if ( st->core == ACELP_CORE && !st->con_tcx )
     799             :             {
     800        1812 :                 set_f( st->delay_buf_out, 0, delay_comp );
     801        1812 :                 mvr2r( output, st->previoussynth, output_frame );
     802             :             }
     803             :             else
     804             :             {
     805        1938 :                 mvr2r( st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB - delay_comp, st->delay_buf_out, delay_comp );
     806             : 
     807        1938 :                 if ( st->output_Fs == 8000 )
     808             :                 {
     809           0 :                     mvr2r( st->hTcxDec->FBTCXdelayBuf, st->previoussynth, delay_comp );
     810             :                 }
     811             :                 else
     812             :                 {
     813        1938 :                     mvr2r( st->hTcxDec->FBTCXdelayBuf + delay_tdbwe, st->previoussynth, delay_comp );
     814             :                 }
     815             : 
     816        1938 :                 mvr2r( pcmbufFB, st->previoussynth + delay_comp, output_frame - delay_comp );
     817             :             }
     818             : 
     819             :             /* Delay compensation for TBE */
     820        3750 :             if ( output_frame >= L_FRAME16k )
     821             :             {
     822        3750 :                 delay_signal( output, output_frame, st->prev_synth_buffer, delay_tdbwe );
     823             :             }
     824             : 
     825        3750 :             if ( st->igf && st->m_frame_type == ACTIVE_FRAME )
     826             :             {
     827        3750 :                 if ( !st->bfi && st->core == ACELP_CORE && ( st->tec_flag || st->tfa_flag ) && st->output_Fs > 8000 && st->hTECDec != NULL )
     828             :                 {
     829         204 :                     procTecTfa_TBE( hb_synth, st->hTECDec->pGainTemp, st->tfa_flag, st->last_core, (int16_t) ( output_frame / N_TEC_TFA_SUBFR ), st->tec_flag == 2 ? 1 : 0 );
     830             :                 }
     831             : 
     832        3750 :                 if ( ( ( ( !st->bfi || st->last_core == ACELP_CORE ) && st->core == ACELP_CORE ) ||
     833        1938 :                        ( st->last_core == ACELP_CORE && st->bwidth != NB && st->last_codec_mode == MODE2 ) ) &&
     834        1878 :                      ( st->output_Fs > 8000 ) )
     835             :                 {
     836             :                     /* Add the delayed hb_synth component to the delayed core synthesis */
     837        1878 :                     v_add( output, hb_synth, output, output_frame );
     838             :                 }
     839             :             }
     840             :         }
     841             : 
     842             :         /* set delay */
     843        3750 :         if ( st->output_Fs == 8000 )
     844             :         {
     845           0 :             tmps = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
     846             :         }
     847             :         else
     848             :         {
     849        3750 :             tmps = NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS );
     850             :         }
     851        3750 :         delta = NS2SA( st->output_Fs, TCXLTP_DELAY_NS );
     852             : 
     853             :         /* TCX/ACELP/HQ-CORE->TCX */
     854        3750 :         if ( ( st->bfi && st->last_core > ACELP_CORE ) || st->core > ACELP_CORE )
     855             :         {
     856             :             /* TCX / HQ-CORE / TD-TCX-PLC -> TCX / TD-TCX-PLC */
     857        1938 :             if ( st->last_core_bfi > ACELP_CORE || ( st->bfi && st->last_core > ACELP_CORE ) || ( st->prev_bfi && st->last_con_tcx ) )
     858             :             {
     859        1821 :                 mvr2r( st->hTcxDec->FBTCXdelayBuf, output, tmps );
     860        1821 :                 mvr2r( pcmbufFB, output + tmps, st->hTcxDec->L_frameTCX - tmps );
     861             :             }
     862             :             /* ACELP -> TCX */
     863             :             else
     864             :             {
     865             :                 /*cross-fading between LB-TCX and FB-TCX over 2.3125ms*/
     866       11328 :                 for ( i = 0; i < tmps; i++ )
     867             :                 {
     868       11211 :                     output[i + tmps] = ( output[i + tmps] * ( tmps - i ) + pcmbufFB[i] * i ) / tmps;
     869             :                 }
     870         117 :                 mvr2r( pcmbufFB + tmps, output + 2 * tmps, st->hTcxDec->L_frameTCX - 2 * tmps );
     871             :             }
     872             : 
     873        1938 :             mvr2r( pcmbufFB + st->hTcxDec->L_frameTCX - tmps, st->hTcxDec->FBTCXdelayBuf, tmps );
     874             : 
     875        1938 :             if ( st->bfi && st->last_core > ACELP_CORE )
     876             :             {
     877           0 :                 if ( st->output_Fs == 8000 )
     878             :                 {
     879           0 :                     mvr2r( st->hTcxDec->FBTCXdelayBuf, st->delay_buf_out, NS2SA( st->output_Fs, DELAY_CLDFB_NS ) );
     880             :                 }
     881             :                 else
     882             :                 {
     883           0 :                     mvr2r( st->hTcxDec->FBTCXdelayBuf, st->prev_synth_buffer, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
     884           0 :                     mvr2r( st->hTcxDec->FBTCXdelayBuf + NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), st->delay_buf_out, NS2SA( st->output_Fs, DELAY_CLDFB_NS ) );
     885             :                 }
     886             :             }
     887             :         }
     888             :         /* TCX/TD TCX PLC->ACELP */
     889        1812 :         else if ( st->last_codec_mode == MODE2 && st->last_core > ACELP_CORE )
     890             :         {
     891          66 :             mvr2r( st->hTcxDec->FBTCXdelayBuf, output, delta );
     892        6600 :             for ( i = delta; i < tmps; i++ )
     893             :             {
     894        6534 :                 output[i] = ( output[i] * ( i - delta ) + st->hTcxDec->FBTCXdelayBuf[i] * ( tmps - i ) ) / ( tmps - delta );
     895             :             }
     896             :         }
     897             : 
     898        3750 :         tcx_ltp_post( st, hTcxLtpDec, st->core, output_frame, NS2SA( st->output_Fs, ACELP_LOOK_NS ) + tmps, output, st->hTcxDec->FBTCXdelayBuf );
     899             : 
     900             :     } /* end of Mode 2 */
     901             : 
     902             :     /*----------------------------------------------------------------*
     903             :      * Save synthesis for HQ FEC
     904             :      *----------------------------------------------------------------*/
     905             : 
     906        9300 :     save_synthesis_hq_fec( st, output, output_frame, NULL );
     907             : 
     908             :     /*----------------------------------------------------------------*
     909             :      * HP filtering
     910             :      *----------------------------------------------------------------*/
     911             : 
     912        9300 :     hp20( output, output_frame, mem_hp20_out, st->output_Fs );
     913             : 
     914             :     /*--------------------------------------------------------*
     915             :      * Updates
     916             :      *--------------------------------------------------------*/
     917             : 
     918        9300 :     if ( st->last_is_cng == 0 && st->codec_mode == MODE2 )
     919             :     {
     920        3750 :         st->bfi = 0;
     921        3750 :         if ( st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 )
     922             :         {
     923           0 :             if ( frameMode == FRAMEMODE_MISSING )
     924             :             {
     925           0 :                 st->bfi = 1;
     926             :             }
     927             :         }
     928        3750 :         else if ( st->m_decodeMode == DEC_CONCEALMENT_EXT )
     929             :         {
     930           0 :             st->bfi = 1;
     931             :         }
     932             : 
     933        3750 :         updt_dec_common( st, -1, concealWholeFrameTmp, output );
     934             :     }
     935             :     else
     936             :     {
     937        5550 :         if ( st->codec_mode == MODE2 )
     938             :         {
     939           0 :             st->bfi = 0;
     940             :         }
     941             : 
     942        5550 :         updt_dec_common( st, hq_core_type, concealWholeFrameTmp, output );
     943             :     }
     944             : 
     945             : 
     946             : #ifdef DEBUG_MODE_INFO
     947             :     for ( i = 0; i < ( st->L_frame / L_SUBFR ); i++ )
     948             :     {
     949             :         dbgwrite( &pitch_buf[i], sizeof( float ), 1, output_frame / ( st->L_frame / L_SUBFR ), "res/pitch_buf.dec" );
     950             :     }
     951             :     dbgwrite( &st->clas_dec, sizeof( int16_t ), 1, output_frame, "res/clas.dec" );
     952             :     dbgwrite( &st->codec_mode, sizeof( int16_t ), 1, output_frame, "res/codec.dec" );
     953             :     dbgwrite( &st->core, sizeof( int16_t ), 1, output_frame, "res/core.dec" );
     954             :     dbgwrite( &st->extl, sizeof( int16_t ), 1, output_frame, "res/extl.dec" );
     955             :     dbgwrite( &st->bwidth, sizeof( int16_t ), 1, output_frame, "res/bwidth.dec" );
     956             :     dbgwrite( &st->cng_type, sizeof( int16_t ), 1, output_frame, "res/cng_type.dec" );
     957             :     tmp = st->extl_brate / 1000.0f;
     958             :     dbgwrite( &tmp, sizeof( float ), 1, output_frame, "res/extl_brate.dec" );
     959             :     tmp = st->core_brate / 1000.0f;
     960             :     dbgwrite( &tmp, sizeof( float ), 1, output_frame, "res/core_brate.dec" );
     961             :     tmp = st->total_brate / 1000.0f;
     962             :     dbgwrite( &tmp, sizeof( float ), 1, output_frame, "res/total_brate.dec" );
     963             :     dbgwrite( &st->coder_type, sizeof( int16_t ), 1, output_frame, "res/coder_type.dec" );
     964             :     dbgwrite( &st->L_frame, sizeof( int16_t ), 1, output_frame, "res/L_frame.dec" );
     965             :     dbgwrite( &st->bfi, sizeof( int16_t ), 1, output_frame, "res/bfi" );
     966             :     dbgwrite( &st->BER_detect, sizeof( int16_t ), 1, output_frame, "res/BER_detect" );
     967             : 
     968             :     if ( st->core != ACELP_CORE )
     969             :     {
     970             :         set_f( hb_synth, 0, output_frame );
     971             :         dbgwrite( hb_synth, 4, st->L_frame, 1, "res/exc.dec" );
     972             :     }
     973             : #endif
     974             : 
     975        9300 :     pop_wmops();
     976        9300 :     return error;
     977             : }

Generated by: LCOV version 1.14