LCOV - code coverage report
Current view: top level - lib_dec - dec_LPD.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 145 288 50.3 %
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 <assert.h>
      38             : #include <stdint.h>
      39             : #include "options.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include <math.h>
      44             : #include "prot.h"
      45             : #include "rom_com.h"
      46             : #include "cnst.h"
      47             : #include "basop_proto_func.h"
      48             : #include "stat_com.h"
      49             : #include "wmc_auto.h"
      50             : 
      51             : 
      52             : /*-------------------------------------------------------------------*
      53             :  * decoder_LPD()
      54             :  *
      55             :  * Core decoder MODE2
      56             :  *--------------------------------------------------------------------*/
      57             : 
      58        3750 : void decoder_LPD(
      59             :     Decoder_State *st,     /* i/o: decoder memory state pointer        */
      60             :     float signal_out[],    /* o  : signal with LPD delay (7 subfrs)    */
      61             :     float signal_outFB[],  /* o  : synthesis @output_FS                */
      62             :     int16_t *total_nbbits, /* i/o:    number of bits / decoded bits    */
      63             :     float *bpf_noise_buf,  /* i/o: BPF noise buffer                    */
      64             :     int16_t bfi,           /* i  : BFI flag                            */
      65             :     int16_t *bitsRead,     /* o  : number of read bits                 */
      66             :     int16_t param[],       /* o  : buffer of parameters                */
      67             :     float *pitch_buf,      /* i/o: floating pitch values for each subfr*/
      68             :     float *voice_factors,  /* o  : voicing factors                     */
      69             :     float *ptr_bwe_exc     /* o  : excitation for SWB TBE              */
      70             : )
      71             : {
      72             :     int16_t *prm;
      73             :     int16_t param_lpc[NPRM_LPC_NEW];
      74             : #ifdef FIX_1320_STACK_CPE_DECODER
      75             :     float synth_buf[OLD_SYNTH_INTERNAL_DEC + L_FRAME_PLUS_INTERNAL + M];
      76             : #else
      77             :     float synth_buf[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M];
      78             : #endif
      79             :     float *synth;
      80             :     float synth_bufFB[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M];
      81             :     float *synthFB;
      82             :     float lsf[( NB_DIV + 1 ) * M], lsp[( NB_DIV + 1 ) * M], lspmid[M], lsfmid[M];
      83             :     float Aq[( NB_SUBFR16k + 1 ) * ( M + 1 )];
      84             :     int16_t pitch[NB_SUBFR16k];
      85             :     float pit_gain[NB_SUBFR16k];
      86             :     int16_t i, k;
      87             :     int16_t past_core_mode, offset;
      88             :     int16_t L_frame, nb_subfr, L_frameTCX;
      89             :     Word16 Aind[M + 1], lspind[M];
      90             :     float tmp_old[M + 1], tmp_new[M + 1], enr_old, enr_new;
      91             :     float lspnew_uw[NB_DIV * M], lsfnew_uw[NB_DIV * M];
      92             :     float lsf_q_1st_rf[M], lsf_q_rf[M], lsp_q_rf[M];
      93             :     float lsp_diff;
      94             :     int16_t LSF_Q_prediction; /* o  : LSF prediction mode                 */
      95             :     int16_t tcx_last_overlap_mode, tcx_current_overlap_mode;
      96        3750 :     TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
      97        3750 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
      98             : 
      99             :     /*--------------------------------------------------------------------------------*
     100             :      * Initializations
     101             :      *--------------------------------------------------------------------------------*/
     102             : 
     103        3750 :     prm = param;           /* to avoid compilation warnings */
     104        3750 :     LSF_Q_prediction = -1; /* to avoid compilation warnings */
     105        3750 :     enr_old = 0.0f;
     106        3750 :     enr_new = 0.0f;
     107             : 
     108        3750 :     if ( st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 )
     109             :     {
     110           0 :         bfi = st->bfi;
     111             :     }
     112             : 
     113        3750 :     past_core_mode = st->last_core_bfi;
     114             : 
     115             :     /*Adjust bit per frame*/
     116        3750 :     if ( !bfi )
     117             :     {
     118        3750 :         st->bits_frame_core = st->bits_frame - ( *bitsRead );
     119             :     }
     120             : 
     121             :     /* Framing parameters */
     122        3750 :     L_frame = st->L_frame;
     123        3750 :     L_frameTCX = st->hTcxDec->L_frameTCX;
     124        3750 :     nb_subfr = st->nb_subfr;
     125             : 
     126             :     /* Initialize pointers */
     127        3750 :     synth = synth_buf + st->hTcxDec->old_synth_len;
     128        3750 :     synthFB = synth_bufFB + st->hTcxDec->old_synth_lenFB;
     129        3750 :     mvr2r( st->hTcxDec->old_synth, synth_buf, st->hTcxDec->old_synth_len );
     130        3750 :     mvr2r( st->hTcxDec->old_synthFB, synth_bufFB, st->hTcxDec->old_synth_lenFB );
     131             : #ifdef FIX_1320_STACK_CPE_DECODER
     132        3750 :     set_zero( synth, L_FRAME_PLUS_INTERNAL + M );
     133             : #else
     134             :     set_zero( synth, L_FRAME_PLUS + M );
     135             : #endif
     136        3750 :     set_zero( synthFB, L_FRAME_PLUS + M );
     137             : 
     138             : 
     139             :     /*For post-processing (post-filtering+blind BWE)*/
     140        3750 :     if ( st->tcxonly == 0 )
     141             :     {
     142             :         /* for bass postfilter */
     143        3750 :         set_s( pitch, L_SUBFR, nb_subfr );
     144        3750 :         set_zero( pit_gain, nb_subfr );
     145             :     }
     146             : 
     147             :     /* PLC: [Common: Memory update]
     148             :      * PLC: Update the number of lost frames */
     149        3750 :     if ( bfi )
     150             :     {
     151           0 :         st->nbLostCmpt++;
     152             :     }
     153             : 
     154             :     /*--------------------------------------------------------------------------------*
     155             :      * BITSTREAM DECODING
     156             :      *--------------------------------------------------------------------------------*/
     157             : 
     158        3750 :     if ( !bfi )
     159             :     {
     160        3750 :         st->second_last_core = st->last_core;
     161        3750 :         tcx_last_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode;
     162        3750 :         tcx_current_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode;
     163             : 
     164        3750 :         dec_prm( st, param, param_lpc, total_nbbits, bitsRead );
     165             : 
     166        3750 :         if ( !st->rate_switching_init && ( st->last_codec_mode ) == MODE2 && st->BER_detect )
     167             :         {
     168           0 :             st->coder_type = st->last_coder_type;
     169           0 :             st->last_core = st->second_last_core;
     170           0 :             st->hTcxCfg->tcx_last_overlap_mode = tcx_last_overlap_mode;
     171           0 :             st->hTcxCfg->tcx_curr_overlap_mode = tcx_current_overlap_mode;
     172           0 :             st->bfi = 1;
     173           0 :             bfi = 1;
     174           0 :             st->flagGuidedAcelp = 0;
     175           0 :             st->nbLostCmpt++;
     176           0 :             st->core_brate = st->last_core_brate;
     177           0 :             st->core = GetPLCModeDecision( st );
     178             :         }
     179             :     }
     180             :     else
     181             :     {
     182           0 :         if ( st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 )
     183             :         {
     184           0 :             dec_prm( st, param, param_lpc, total_nbbits, bitsRead );
     185             :         }
     186             : 
     187           0 :         if ( st->nbLostCmpt > 1 )
     188             :         {
     189           0 :             st->flagGuidedAcelp = 0;
     190             :         }
     191             :         /* PLC: [Common: mode decision]
     192             :          * PLC: Decide which Concealment to use. Update pitch lags if needed */
     193           0 :         st->core = GetPLCModeDecision( st );
     194             :     }
     195             : 
     196             :     /* PLC: [Common: Memory update]
     197             :      * PLC: Update the number of lost frames */
     198        3750 :     if ( !bfi )
     199             :     {
     200        3750 :         if ( st->prev_bfi == 1 )
     201             :         {
     202           0 :             st->prev_nbLostCmpt = st->nbLostCmpt;
     203             :         }
     204             :         else
     205             :         {
     206        3750 :             st->prev_nbLostCmpt = 0;
     207             :         }
     208             : 
     209        3750 :         st->nbLostCmpt = 0;
     210             :     }
     211             : 
     212             :     /*--------------------------------------------------------------------------------*
     213             :      * LPC PARAMETERS
     214             :      *--------------------------------------------------------------------------------*/
     215             : 
     216        3750 :     if ( ( bfi == 0 ) || ( bfi == 1 && st->use_partial_copy && st->rf_frame_type == RF_TCXFD ) )
     217             :     {
     218        3750 :         if ( st->use_partial_copy && ( st->rf_frame_type < RF_TCXFD || st->rf_frame_type > RF_TCXTD2 ) )
     219             :         {
     220           0 :             if ( hTcxDec->envWeighted )
     221             :             {
     222           0 :                 mvr2r( st->lspold_uw, st->lsp_old, M );
     223           0 :                 mvr2r( st->lsfold_uw, st->lsf_old, M );
     224           0 :                 hTcxDec->envWeighted = 0;
     225             :             }
     226             : 
     227             :             /* first stage VQ, 8 bits; reuse TCX high rate codebook */
     228           0 :             set_f( lsf_q_1st_rf, 0.0f, M );
     229           0 :             vlpc_1st_dec( param_lpc[0], lsf_q_1st_rf, st->sr_core );
     230             : 
     231             :             /* second stage vq */
     232             :             /* quantized lsf from two stages */
     233           0 :             v_add( lsf_q_1st_rf, lsf_q_diff_cb_8b_rf + M * param_lpc[1], lsf_q_rf, M );
     234             : 
     235           0 :             v_sort( lsf_q_rf, 0, M - 1 );
     236           0 :             reorder_lsf( lsf_q_rf, LSF_GAP, M, st->sr_core );
     237             : 
     238             :             /* current n-th ACELP frame and its corresponding partial copy */
     239           0 :             lsf2lsp( lsf_q_rf, lsp_q_rf, M, st->sr_core );
     240             : 
     241             :             /* copy the old and current lsfs and lsps into the lsf[] and lsp[] buffer for interpolation */
     242           0 :             mvr2r( st->lsf_old, &lsf[0], M );
     243           0 :             mvr2r( st->lsp_old, &lsp[0], M );
     244           0 :             mvr2r( lsf_q_rf, &lsf[M], M );
     245           0 :             mvr2r( lsp_q_rf, &lsp[M], M );
     246           0 :             lsp_diff = 0.0f;
     247             : 
     248           0 :             for ( i = 0; i < M; i++ )
     249             :             {
     250           0 :                 lsp_diff += (float) fabs( lsp[i + M] - lsp[i] );
     251             :             }
     252             : 
     253           0 :             if ( st->core == ACELP_CORE && st->last_core == ACELP_CORE && lsp_diff < 1.6f && lsp_diff > 0.12f && st->next_coder_type == GENERIC && !st->prev_use_partial_copy && st->last_coder_type == UNVOICED && st->rf_frame_type >= RF_GENPRED )
     254             :             {
     255           0 :                 mvr2r( &lsp[0], &lsp[M], M );
     256             :             }
     257             : 
     258             :             /* update mem_MA and mem_AR memories */
     259           0 :             lsf_update_memory( st->narrowBand, &lsf[M], st->mem_MA, st->mem_MA );
     260           0 :             mvr2r( &lsf[M], st->mem_AR, M );
     261             : 
     262           0 :             for ( k = 0; k < st->numlpc; ++k )
     263             :             {
     264           0 :                 mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M );
     265           0 :                 mvr2r( &lsf[( k + 1 ) * M], &lsfnew_uw[k * M], M );
     266             :             }
     267             :         }
     268        3750 :         else if ( ( hTcxDec->enableTcxLpc && st->core != ACELP_CORE ) || ( bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD ) )
     269           0 :         {
     270             :             int16_t tcx_lpc_cdk;
     271             : 
     272           0 :             if ( bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD )
     273             :             {
     274           0 :                 tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC );
     275             :             }
     276             :             else
     277             :             {
     278           0 :                 tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type );
     279             :             }
     280             : 
     281           0 :             mvr2r( st->lsf_old, &lsf[0], M );
     282           0 :             mvr2r( st->lsp_old, &lsp[0], M );
     283             : 
     284           0 :             D_lsf_tcxlpc( param_lpc, &lsf[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA );
     285             : 
     286           0 :             lsf2lsp( &lsf[M], &lsp[M], M, st->sr_core );
     287             : 
     288           0 :             lsf_update_memory( st->narrowBand, &lsf[M], st->mem_MA, st->mem_MA );
     289           0 :             mvr2r( &lsf[M], st->mem_AR, M );
     290           0 :             hTcxDec->envWeighted = 1;
     291             : 
     292           0 :             E_LPC_lsp_unweight( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma );
     293             :         }
     294             :         else
     295             :         {
     296        3750 :             if ( hTcxDec->envWeighted )
     297             :             {
     298           0 :                 mvr2r( st->lspold_uw, st->lsp_old, M );
     299           0 :                 mvr2r( st->lsfold_uw, st->lsf_old, M );
     300           0 :                 hTcxDec->envWeighted = 0;
     301             :             }
     302             : 
     303             :             /* Unquantize LPC */
     304        3750 :             if ( st->core == TCX_20_CORE )
     305             :             {
     306        1938 :                 lpc_unquantize( st, lsf, lsp, param_lpc, lspmid, lsfmid, AUDIO, &LSF_Q_prediction );
     307             :             }
     308             :             else
     309             :             {
     310        1812 :                 lpc_unquantize( st, lsf, lsp, param_lpc, lspmid, lsfmid, st->coder_type, &LSF_Q_prediction );
     311             : 
     312        1812 :                 if ( st->prev_use_partial_copy && st->last_core == ACELP_CORE && st->core == ACELP_CORE && st->prev_rf_frame_type >= RF_GENPRED && st->coder_type == UNVOICED )
     313             :                 {
     314           0 :                     if ( st->lpcQuantization && st->acelp_cfg.midLpc )
     315             :                     {
     316           0 :                         mvr2r( lspmid, &lsp[0], M );
     317           0 :                         mvr2r( &lsp[M], lspmid, M );
     318             :                     }
     319             :                 }
     320             :             }
     321             : 
     322        7500 :             for ( k = 0; k < st->numlpc; ++k )
     323             :             {
     324        3750 :                 mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M );
     325        3750 :                 mvr2r( &lsf[( k + 1 ) * M], &lsfnew_uw[k * M], M );
     326             :             }
     327             :         }
     328             : 
     329             :         /* PLC: [LPD: LPC concealment] built the moving average for the LPC concealment */
     330        7500 :         for ( k = 0; k < st->numlpc; k++ )
     331             :         {
     332       63750 :             for ( i = 0; i < M; i++ )
     333             :             {
     334       60000 :                 st->lsf_adaptive_mean[i] = ( st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + lsfnew_uw[k * M + i] ) / 3;
     335       60000 :                 st->lsfoldbfi1[i] = st->lsfoldbfi0[i];
     336       60000 :                 st->lsfoldbfi0[i] = lsfnew_uw[k * M + i];
     337             :             }
     338             :         }
     339             :     }
     340             :     else
     341             :     {
     342             :         /* PLC: [LPD: LPC concealment] Conceal the LPC from the lost frame */
     343             :         const float *lsfBase; /* base for differential lsf coding */
     344             : 
     345           0 :         if ( st->tcxonly == 0 || st->core < TCX_10_CORE )
     346             :         {
     347           0 :             st->numlpc = 1;
     348             :         }
     349             :         else
     350             :         {
     351           0 :             st->numlpc = 2;
     352             :         }
     353             : 
     354           0 :         if ( st->nbLostCmpt == 1 )
     355             :         {
     356           0 :             mvr2r( st->lsf_old, st->old_lsf_q_cng, M );
     357           0 :             mvr2r( st->lsp_old, st->old_lsp_q_cng, M );
     358             :         }
     359             : 
     360             : 
     361           0 :         lsfBase = PlcGetlsfBase( st->lpcQuantization, st->narrowBand, st->sr_core );
     362             : 
     363           0 :         dlpc_bfi( st->L_frame, lsfnew_uw, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA, st->mem_AR, &( st->stab_fac ), st->lsf_adaptive_mean, st->numlpc, st->lsf_cng, st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase );
     364             : 
     365           0 :         hTcxDec->envWeighted = 0;
     366             : 
     367           0 :         mvr2r( st->lspold_uw, lsp, M );
     368           0 :         mvr2r( st->lsfold_uw, lsf, M );
     369             : 
     370           0 :         for ( k = 0; k < st->numlpc; k++ )
     371             :         {
     372           0 :             mvr2r( &lsfnew_uw[k * M], &lsf[( k + 1 ) * M], M );
     373             : 
     374           0 :             lsf2lsp( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core );
     375           0 :             lsf2lsp( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core );
     376             : 
     377           0 :             mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M );
     378             :         }
     379             :     }
     380             : 
     381             :     /*--------------------------------------------------------------*
     382             :      * Rate switching
     383             :      *---------------------------------------------------------------*/
     384             : 
     385        3750 :     if ( st->rate_switching_reset )
     386             :     {
     387          63 :         mvr2r( &( lsf[M] ), &( lsf[0] ), M );
     388          63 :         mvr2r( &( lsp[M] ), &( lsp[0] ), M );
     389          63 :         mvr2r( &( lsf[M] ), st->lsf_old, M );
     390          63 :         mvr2r( &( lsp[M] ), st->lsp_old, M );
     391          63 :         mvr2r( &( lsf[M] ), lsfmid, M );
     392          63 :         mvr2r( &( lsp[M] ), lspmid, M );
     393          63 :         lsp2a_stab( st->lsp_old, st->old_Aq_12_8, M );
     394             :     }
     395             : 
     396        3750 :     if ( st->enablePlcWaveadjust )
     397             :     {
     398           0 :         if ( st->core == ACELP_CORE )
     399             :         {
     400           0 :             st->tonality_flag = 0;
     401             :         }
     402             : 
     403           0 :         if ( bfi )
     404             :         {
     405           0 :             st->hPlcInfo->nbLostCmpt++;
     406             :         }
     407             :     }
     408             : 
     409             :     /*--------------------------------------------------------------------------------*
     410             :      * ACELP
     411             :      *--------------------------------------------------------------------------------*/
     412             : 
     413        3750 :     if ( st->prev_bfi != 0 && bfi == 0 && st->coder_type == VOICED && st->prev_nbLostCmpt > 4 )
     414             :     {
     415           0 :         st->dec_glr_idx = 1;
     416           0 :         st->reset_mem_AR = 1;
     417             :     }
     418             : 
     419        3750 :     if ( st->core == ACELP_CORE )
     420             :     {
     421        1812 :         if ( !st->tcxonly )
     422             :         {
     423             :             /* Set pointer to parameters */
     424        1812 :             prm = param;
     425             : 
     426             :             /* Stability Factor */
     427        1812 :             if ( !bfi )
     428             :             {
     429        1812 :                 st->stab_fac = lsf_stab( &lsf[M], &lsf[0], 0, st->L_frame );
     430             :             }
     431             : 
     432        1812 :             if ( !bfi && st->prev_bfi )
     433             :             {
     434             :                 /* check if LSP interpolation can be relaxed or if LPC power can be diffused*/
     435           0 :                 lsp2a_stab( &lsp[0], tmp_old, M );
     436           0 :                 enr_old = enr_1_Az( tmp_old, 2 * L_SUBFR );
     437             : 
     438           0 :                 lsp2a_stab( &lsp[M], tmp_new, M );
     439           0 :                 enr_new = enr_1_Az( tmp_new, 2 * L_SUBFR );
     440             :             }
     441             : 
     442        1812 :             if ( !bfi && ( st->dec_glr_idx == 1 || ( !( st->safety_net ) && enr_new >= 256.f && enr_new > 2 * enr_old ) ) && st->prev_bfi )
     443             :             {
     444           0 :                 RecLpcSpecPowDiffuseLc( &lsp[M], &lsp[0], &lsf[M], st, st->dec_glr_idx == 1 ? 1 : 0 );
     445           0 :                 int_lsp( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 );
     446           0 :                 mvr2r( &lsf[M], lsfnew_uw, M );
     447             :             }
     448             :             else
     449             :             {
     450             :                 /* LPC Interpolation for ACELP */
     451        1812 :                 if ( !bfi && st->acelp_cfg.midLpc )
     452             :                 {
     453        1008 :                     st->relax_prev_lsf_interp = 0;
     454             : 
     455        1008 :                     if ( st->prev_bfi )
     456             :                     {
     457             :                         /* check if LSP interpolation can be relaxed */
     458           0 :                         if ( enr_new < ( 0.25f * enr_old ) )
     459             :                         {
     460             :                             /* don't use safety_net as this is getting impacted with lsf_restruct */
     461           0 :                             if ( st->clas_dec == UNVOICED_CLAS || st->clas_dec == SIN_ONSET || st->clas_dec == INACTIVE_CLAS || st->coder_type == GENERIC || st->coder_type == TRANSITION )
     462             :                             {
     463           0 :                                 st->relax_prev_lsf_interp = 1;
     464             :                             }
     465             :                             else
     466             :                             {
     467           0 :                                 st->relax_prev_lsf_interp = -1;
     468             :                             }
     469             :                         }
     470             :                     }
     471             : 
     472        1008 :                     if ( st->stab_fac == 0 && st->old_bfi_cnt > 0 && st->clas_dec != VOICED_CLAS && st->clas_dec != ONSET && st->relax_prev_lsf_interp == 0 )
     473             :                     {
     474           0 :                         st->relax_prev_lsf_interp = 2;
     475             :                     }
     476        1008 :                     int_lsp4( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp );
     477             :                 }
     478             :                 else
     479             :                 {
     480         804 :                     int_lsp( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 );
     481         804 :                     int_lsp( L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_12k8, 0 );
     482             :                 }
     483             :             }
     484             :         }
     485             : 
     486        1812 :         if ( bfi && st->last_core != ACELP_CORE )
     487             :         {
     488             :             /* PLC: [TCX: TD PLC] */
     489           0 :             con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL );
     490           0 :             lerp( synthFB, synth, st->L_frame, st->hTcxDec->L_frameTCX );
     491           0 :             st->con_tcx = 1;
     492           0 :             set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr );
     493             :         }
     494             :         else
     495             :         {
     496             :             /* ACELP decoder */
     497        1812 :             if ( st->hBWE_TD != NULL )
     498             :             {
     499        1812 :                 if ( st->L_frame == L_FRAME )
     500             :                 {
     501           0 :                     mvr2r( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) );
     502             :                 }
     503             :                 else
     504             :                 {
     505        1812 :                     mvr2r( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq, ( M + 1 ) );
     506             :                 }
     507             :             }
     508             : 
     509        1812 :             if ( bfi )
     510             :             {
     511             :                 /* PLC: [ACELP: general]
     512             :                  * PLC: Use the ACELP like concealment */
     513           0 :                 con_acelp( Aq, st->core_ext_mode, &synth[0], pitch, pit_gain, st->stab_fac, st, pitch_buf, voice_factors, ptr_bwe_exc );
     514           0 :                 mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->nb_subfr + 2], st->nb_subfr );
     515           0 :                 set_zero( &st->mem_pitch_gain[2], st->nb_subfr );
     516             :             }
     517             :             else
     518             :             {
     519        1812 :                 decoder_acelp( st, prm, Aq, st->acelp_cfg, &synth[0], pitch, pit_gain, st->stab_fac, pitch_buf, voice_factors, LSF_Q_prediction, ptr_bwe_exc );
     520             : 
     521        1812 :                 if ( st->flagGuidedAcelp > 0 )
     522             :                 {
     523         915 :                     st->guidedT0 = max( min( st->T0_4th + st->guidedT0, NBPSF_PIT_MAX ), PIT_MIN_16k );
     524             :                 }
     525             : 
     526       10872 :                 for ( i = 0; i < st->nb_subfr; i++ )
     527             :                 {
     528        9060 :                     st->mem_pitch_gain[2 + ( 2 * st->nb_subfr - 1 ) - i] = st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i];
     529        9060 :                     st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i] = pit_gain[i];
     530             :                 }
     531             :             }
     532             :         }
     533             : 
     534             :         /* LPC for ACELP/BWE */
     535        1812 :         if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k )
     536             :         {
     537        1812 :             mvr2r( Aq, st->mem_Aq, nb_subfr * ( M + 1 ) );
     538             :         }
     539             : 
     540             :         /* PLC: [TCX: Tonal Concealment] */
     541             :         /* Signal that this frame is not TCX */
     542        1812 :         TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, 0, 0, 0, 0 );
     543             : 
     544        1812 :         if ( !bfi )
     545             :         {
     546        1812 :             st->second_last_tns_active = st->last_tns_active;
     547        1812 :             st->last_tns_active = 0;
     548        1812 :             hTcxDec->tcxltp_last_gain_unmodified = 0.0f;
     549             :         }
     550             :     }
     551             : 
     552             : 
     553             :     /*--------------------------------------------------------------------------------*
     554             :      * TCX20
     555             :      *--------------------------------------------------------------------------------*/
     556             : 
     557        3750 :     if ( st->core == TCX_20_CORE )
     558             :     {
     559             :         /* Set pointer to parameters */
     560        1938 :         prm = param;
     561             : 
     562             :         /* Stability Factor */
     563        1938 :         if ( !bfi )
     564             :         {
     565        1938 :             st->stab_fac = lsf_stab( &lsf[M], &lsf[0], 0, st->L_frame );
     566             :         }
     567             : 
     568        1938 :         if ( hTcxDec->enableTcxLpc )
     569             :         {
     570             :             /* Convert quantized lsp to A */
     571           0 :             lsp2a_stab( &lsp[M], Aq, M );
     572             :         }
     573             :         else
     574             :         {
     575        1938 :             if ( !st->tcxonly )
     576             :             {
     577        1938 :                 if ( !bfi && st->prev_bfi && !( st->safety_net ) && st->rate_switching_reset )
     578             :                 {
     579             :                     /* diffuse LPC power on rate switching*/
     580           0 :                     RecLpcSpecPowDiffuseLc( &lsp[M], &lsp[0], &lsf[M], st, 0 );
     581           0 :                     int_lsp( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 );
     582           0 :                     mvr2r( &lsf[M], lsfnew_uw, M );
     583             :                 }
     584             :                 else
     585             :                 {
     586             :                     /* LPC Interpolation for TCX */
     587        1938 :                     E_LPC_int_lpc_tcx( &lsp[0], &lsp[M], Aq );
     588             :                 }
     589             :             }
     590             :             else
     591             :             {
     592           0 :                 lsp2a_stab( &lsp[M], Aq, M );
     593             :             }
     594             :         }
     595             : 
     596        1938 :         if ( !bfi && hTcxDec->tcx_lpc_shaped_ari )
     597             :         {
     598           0 :             basop_E_LPC_f_lsp_a_conversion( lspind, Aind, M );
     599             :         }
     600             : 
     601             :         /* TCX decoder */
     602        1938 :         decoder_tcx( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, 0 );
     603             :     }
     604             : 
     605             :     /*--------------------------------------------------------------------------------*
     606             :      * TCX10
     607             :      *--------------------------------------------------------------------------------*/
     608             : 
     609        3750 :     if ( st->core == TCX_10_CORE )
     610             :     {
     611           0 :         prm = NULL; /* just to avoid MSVC warnings */
     612             : 
     613           0 :         for ( k = 0; k < 2; k++ )
     614             :         {
     615           0 :             if ( !bfi )
     616             :             {
     617             :                 /* Set pointer to parameters */
     618           0 :                 prm = param + ( k * DEC_NPRM_DIV );
     619             : 
     620             :                 /* Stability Factor */
     621           0 :                 st->stab_fac = lsf_stab( &lsf[( k + 1 ) * M], &lsf[k * M], 0, st->L_frame );
     622             :             }
     623             : 
     624           0 :             lsp2a_stab( &lsp[( k + 1 ) * M], Aq, M );
     625           0 :             IGFDecRestoreTCX10SubFrameData( st->hIGFDec, k );
     626             : 
     627             :             /* TCX decoder */
     628           0 :             decoder_tcx( st, prm, Aq, Aind, &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], bfi, k, 0 );
     629             :         }
     630             :     }
     631             : 
     632        3750 :     if ( st->core == TCX_10_CORE || st->core == TCX_20_CORE )
     633             :     {
     634        1938 :         if ( st->enablePlcWaveadjust ||          /* bfi      */
     635        1938 :              ( st->last_total_brate >= HQ_48k && /* recovery */
     636           0 :                st->last_codec_mode == MODE2 ) )
     637             :         {
     638             :             /* waveform adjustment */
     639           0 :             concealment_signal_tuning( st, bfi, synthFB, past_core_mode );
     640             : 
     641           0 :             if ( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && st->hPlcInfo->concealment_method == TCX_NONTONAL )
     642             :             {
     643           0 :                 lerp( synthFB, synth, L_frame, L_frameTCX );
     644             : 
     645           0 :                 if ( !bfi && st->prev_bfi )
     646             :                 {
     647           0 :                     st->hPlcInfo->Pitch = 0;
     648             :                 }
     649             :             }
     650             :         }
     651             : 
     652        1938 :         if ( !bfi )
     653             :         {
     654        1938 :             TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB, L_frameTCX );
     655             :         }
     656             : 
     657        1938 :         decoder_tcx_post( st, synth, synthFB, Aq, bfi, 0 );
     658             : 
     659        1938 :         if ( st->core == TCX_20_CORE )
     660             :         {
     661             :             /* LPC Interpolation for BWE/post-processing */
     662        1938 :             if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k )
     663             :             {
     664        1938 :                 int_lsp( L_frame, st->lspold_uw, lspnew_uw, Aq, M, interpol_frac_12k8, 0 );
     665        1938 :                 mvr2r( Aq, st->mem_Aq, nb_subfr * ( M + 1 ) );
     666             :             }
     667             :         }
     668             :     }
     669             : 
     670             : 
     671             :     /* PLC: [Common: Classification] */
     672             :     /* the classifier buffer is always updated if the sr is at
     673             :        16000 or below - the classification itself is just performed if(!st->tcxonly ) */
     674        3750 :     if ( st->sr_core <= INT_FS_16k )
     675             :     {
     676        3750 :         if ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || ( st->tcxonly && st->bfi ) )
     677             :         {
     678             :             float pitch_C[4];
     679             : 
     680             :             /* note: the classifier needs the pitch only for tcx_only == 0, i.e. not for TCX10 */
     681        1938 :             pitch_C[0] = pitch_C[1] = pitch_C[2] = pitch_C[3] = (float) floor( st->old_fpitch + 0.5f );
     682             : 
     683        1938 :             FEC_clas_estim( synth, pitch_C, st->L_frame, st->tcxonly ? GENERIC : 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, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : -1.0f, st->narrowBand, CLASSIFIER_TCX, bfi, st->preemph_fac, st->tcxonly, st->last_core_brate, -1 );
     684             :         }
     685             :     }
     686             : 
     687             :     /*--------------------------------------------------------------------------------*
     688             :      * Updates
     689             :      *--------------------------------------------------------------------------------*/
     690             : 
     691        3750 :     if ( bfi && st->last_core != ACELP_CORE )
     692             :     {
     693             :         /* Update FEC_scale_syn parameters */
     694           0 :         if ( hTcxLtpDec->tcxltp_gain == 0 )
     695             :         {
     696           0 :             fer_energy( L_frame, UNVOICED, synth, (float) ( L_frame / 2 ), &st->enr_old, L_frame );
     697             :         }
     698             :         else
     699             :         {
     700           0 :             fer_energy( L_frame, st->clas_dec, synth, st->old_fpitch, &st->enr_old, L_frame );
     701             :         }
     702             :     }
     703             : 
     704        3750 :     if ( !bfi && st->clas_dec >= VOICED_TRANSITION && st->clas_dec < INACTIVE_CLAS )
     705             :     {
     706        2907 :         if ( st->core == ACELP_CORE )
     707             :         {
     708        1458 :             offset = ( st->nb_subfr - 1 ) * ( M + 1 );
     709             :         }
     710             :         else
     711             :         {
     712             :             /* TCX */
     713        1449 :             offset = 0;
     714             :         }
     715             : 
     716             :         /* use latest LPC set */
     717        2907 :         st->old_enr_LP = enr_1_Az( Aq + offset, L_SUBFR );
     718             :     }
     719             : 
     720             : 
     721             :     /* Update */
     722        3750 :     mvr2r( synth_buf + L_frame, st->hTcxDec->old_synth, st->hTcxDec->old_synth_len );
     723        3750 :     mvr2r( st->hTcxDec->old_synthFB + L_frameTCX - NS2SA( st->output_Fs, PH_ECU_MEM_NS ), st->hTcxDec->synth_history, NS2SA( st->output_Fs, PH_ECU_MEM_NS ) );
     724        3750 :     mvr2r( synth_bufFB + L_frameTCX, st->hTcxDec->old_synthFB, st->hTcxDec->old_synth_lenFB );
     725        3750 :     mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
     726             : 
     727        3750 :     mvr2r( &lspnew_uw[( st->numlpc - 1 ) * M], st->lspold_uw, M );
     728        3750 :     mvr2r( &lsfnew_uw[( st->numlpc - 1 ) * M], st->lsfold_uw, M );
     729             : 
     730        3750 :     if ( bfi == 1 )
     731             :     {
     732           0 :         mvr2r( st->lspold_uw, st->lsp_old, M ); /* for recovery */
     733           0 :         mvr2r( st->lsfold_uw, st->lsf_old, M ); /* for recovery */
     734             :     }
     735             :     else
     736             :     {
     737        3750 :         mvr2r( &lsp[st->numlpc * M], st->lsp_old, M );
     738        3750 :         mvr2r( &lsf[st->numlpc * M], st->lsf_old, M );
     739             :     }
     740        3750 :     mvr2r( st->lsp_q_cng, st->old_lsp_q_cng, M );
     741        3750 :     mvr2r( st->lsf_q_cng, st->old_lsf_q_cng, M );
     742             : 
     743             :     /* Update MODE1 CNG parameters */
     744        3750 :     if ( !st->tcxonly && st->hTdCngDec != NULL )
     745             :     {
     746             :         /* update CNG parameters in active frames */
     747        3750 :         if ( st->bwidth == NB && hTcxDec->enableTcxLpc && st->core != ACELP_CORE )
     748           0 :         {
     749             :             float buf[L_LP], res[L_FRAME], A[M + 1], r[M + 1], tmp, lsptmp[M];
     750           0 :             assert( st->L_frame == L_FRAME );
     751           0 :             mvr2r( synth + L_FRAME - L_LP, buf, L_LP );
     752           0 :             tmp = synth[L_FRAME - L_LP - 1];
     753           0 :             preemph( buf, st->preemph_fac, L_LP, &tmp );
     754           0 :             autocorr( buf, r, M, L_LP, LP_assym_window, 0, 0, 0 );
     755           0 :             lag_wind( r, M, INT_FS_12k8, LAGW_WEAK );
     756           0 :             lev_dur( A, r, M, NULL );
     757           0 :             a2lsp_stab( A, lsptmp, &lspnew_uw[0] );
     758           0 :             residu( A, M, buf + L_LP - L_FRAME, res, L_FRAME );
     759             : 
     760           0 :             if ( st->hTdCngDec != NULL )
     761             :             {
     762           0 :                 cng_params_upd( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ, DEC, st->hTdCngDec->ho_env_circ, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth );
     763             :             }
     764             :         }
     765        3750 :         else if ( st->hTdCngDec != NULL )
     766             :         {
     767        3750 :             cng_params_upd( &lsp[M], st->old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ, DEC, st->hTdCngDec->ho_env_circ, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth );
     768             :         }
     769             : 
     770             :         /* Set 16k LSP flag for CNG buffer */
     771        3750 :         st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 );
     772             :     }
     773             : 
     774        3750 :     st->last_is_cng = 0;
     775             : 
     776             :     /* Postfiltering */
     777        3750 :     post_decoder( st, synth_buf, pit_gain, pitch, signal_out, bpf_noise_buf );
     778             : 
     779        3750 :     if ( signal_outFB )
     780             :     {
     781        3750 :         mvr2r( synthFB, signal_outFB, L_frameTCX );
     782             :     }
     783             : 
     784        3750 :     if ( st->enablePlcWaveadjust )
     785             :     {
     786           0 :         if ( !bfi )
     787             :         {
     788           0 :             st->hPlcInfo->nbLostCmpt = 0;
     789             :         }
     790             : 
     791           0 :         if ( st->core == ACELP_CORE ) /* may happen only if bfi==1 */
     792             :         {
     793           0 :             set_state( st->hPlcInfo->Transient, st->core, MAX_POST_LEN );
     794             :         }
     795             :     }
     796             : 
     797             : 
     798        3750 :     return;
     799             : }

Generated by: LCOV version 1.14