LCOV - code coverage report
Current view: top level - lib_dec - ivas_tcx_core_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 268 299 89.6 %
Date: 2025-05-23 08:37:30 Functions: 4 4 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             : #include <assert.h>
      34             : #include <stdint.h>
      35             : #include "options.h"
      36             : #ifdef DEBUGGING
      37             : #include "debug.h"
      38             : #endif
      39             : #include <math.h>
      40             : #include "prot.h"
      41             : #include "rom_com.h"
      42             : #include "stat_dec.h"
      43             : #include "wmc_auto.h"
      44             : #include "basop_proto_func.h"
      45             : #include "stat_com.h"
      46             : #include "ivas_prot.h"
      47             : 
      48             : /*-------------------------------------------------------------*
      49             :  * Local prototypes
      50             :  *-------------------------------------------------------------*/
      51             : 
      52             : static void dec_prm_tcx( Decoder_State *st, int16_t param[], int16_t param_lpc[], int16_t *total_nbbits, const int16_t last_element_mode, int16_t *bitsRead );
      53             : static void stereo_tcx_dec_mode_switch_reconf( Decoder_State *st, const int16_t MCT_flag, const int16_t last_element_mode );
      54             : 
      55             : 
      56             : /*-------------------------------------------------------------*
      57             :  * stereo_tcx_init_dec()
      58             :  *
      59             :  * Initialize stereo TCX decoder
      60             :  *-------------------------------------------------------------*/
      61             : 
      62     2794374 : void stereo_tcx_init_dec(
      63             :     Decoder_State *st,              /* i/o: decoder state structure             */
      64             :     const int16_t MCT_flag,         /* i  : hMCT handle allocated (1) or not (0)*/
      65             :     const int16_t last_element_mode /* i  : element mode of previous frame      */
      66             : )
      67             : {
      68     2794374 :     TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
      69     2794374 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
      70             : 
      71     2794374 :     st->rate_switching_init = 0;
      72     2794374 :     st->m_frame_type = ACTIVE_FRAME;
      73     2794374 :     st->core_brate = st->total_brate;
      74             : 
      75             :     /*sampling rate*/
      76     2794374 :     st->sr_core = getCoreSamplerateMode2( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format );
      77     2794374 :     st->fscale = sr2fscale( st->sr_core );
      78             : 
      79             :     /*frame size*/
      80     2794374 :     st->L_frame = (int16_t) ( st->sr_core / FRAMES_PER_SEC );
      81     2794374 :     hTcxDec->L_frameTCX = (int16_t) ( st->output_Fs / FRAMES_PER_SEC );
      82             : 
      83     2794374 :     if ( ( st->L_frame == L_FRAME16k && ( st->bits_frame_nominal * FRAMES_PER_SEC ) <= MAX_ACELP_BRATE ) || ( st->tcxonly && ( st->sr_core == 32000 || st->sr_core == INT_FS_16k ) ) )
      84             :     {
      85     1753731 :         st->nb_subfr = NB_SUBFR16k;
      86             :     }
      87             :     else
      88             :     {
      89     1040643 :         st->nb_subfr = NB_SUBFR;
      90             :     }
      91             : 
      92             :     /*TCX tools*/
      93     2794374 :     st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->rf_flag );
      94     2794374 :     st->hTcxCfg->resq = getResq( st->bits_frame_nominal * FRAMES_PER_SEC );
      95     2794374 :     hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->bits_frame_nominal * FRAMES_PER_SEC, st->rf_flag, st->element_mode );
      96     2794374 :     st->igf = getIgfPresent( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag );
      97             : 
      98     2794374 :     if ( st->element_mode != EVS_MONO )
      99             :     {
     100     2794374 :         st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->bits_frame_nominal * FRAMES_PER_SEC, st->igf, st->element_mode );
     101             :     }
     102     2794374 :     if ( hTcxLtpDec != NULL )
     103             :     {
     104     2794374 :         hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core );
     105             :     }
     106             : 
     107     2794374 :     if ( st->element_mode == IVAS_SCE )
     108             :     {
     109      660345 :         st->tcxonly = getTcxonly( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, MCT_flag, st->is_ism_format );
     110             : 
     111             :         /* LPC quantization */
     112      660345 :         if ( st->sr_core <= INT_FS_16k && st->tcxonly == 0 )
     113             :         {
     114      339603 :             st->lpcQuantization = 1;
     115             :         }
     116             :         else
     117             :         {
     118      320742 :             st->lpcQuantization = 0;
     119             :         }
     120             : 
     121      660345 :         if ( st->tcxonly == 0 )
     122             :         {
     123      339603 :             st->numlpc = 1;
     124             :         }
     125             :         else
     126             :         {
     127      320742 :             st->numlpc = 2;
     128             :         }
     129             :     }
     130             : 
     131     2794374 :     if ( ( st->bits_frame_nominal != st->last_bits_frame_nominal ) ||
     132     2749710 :          ( st->bwidth != st->last_bwidth ) ||
     133     2743692 :          ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) ||
     134     2720496 :          ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ) )
     135             :     {
     136             :         /*re-initialization*/
     137       74079 :         stereo_tcx_dec_mode_switch_reconf( st, MCT_flag, last_element_mode );
     138             :     }
     139             : 
     140     2794374 :     return;
     141             : }
     142             : 
     143             : 
     144             : /*-------------------------------------------------------------------*
     145             :  * stereo_tcx_core_dec()
     146             :  *
     147             :  * stereo TCX decoder
     148             :  *-------------------------------------------------------------------*/
     149             : 
     150      704082 : void stereo_tcx_core_dec(
     151             :     Decoder_State *st,                   /* i/o: decoder state structure            */
     152             :     const FRAME_MODE frameMode,          /* i  : Decoder frame mode                 */
     153             :     float *signal_out,                   /* o  : synthesis @internal_Fs             */
     154             :     float *signal_outFB,                 /* o  : synthesis @output_Fs               */
     155             :     float pitch_buf[],                   /* o  : floating pitch for each subframe   */
     156             :     const int16_t sba_dirac_stereo_flag, /* i  : signal stereo output for SBA DirAC */
     157             :     STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle           */
     158             :     const int16_t last_element_mode,     /* i  : last element mode                  */
     159             :     const int16_t flag_sec_CNA,          /* i  : CNA flag for secondary channel     */
     160             :     STEREO_CNG_DEC_HANDLE hStereoCng,    /* i  : Stereo CNG handle                  */
     161             :     const int16_t nchan_out,             /* i  : number of output channels          */
     162             :     const IVAS_FORMAT ivas_format        /* i  : IVAS format                        */
     163             : )
     164             : {
     165             :     int16_t i, k;
     166             : 
     167             :     /*Bitstream*/
     168             :     int16_t total_nbbits, bitsRead;
     169             :     int16_t *prm, param[DEC_NPRM_DIV * NB_DIV];
     170             :     int16_t param_lpc[NPRM_LPC_NEW];
     171             : 
     172             :     /*LPC*/
     173             :     int16_t LSF_Q_prediction; /* o  : LSF prediction mode */
     174             :     float lsf[( NB_DIV + 1 ) * M], lsp[( NB_DIV + 1 ) * M], lspmid[M], lsfmid[M];
     175             :     float lspnew_uw[NB_DIV * M], lsfnew_uw[NB_DIV * M];
     176             :     float Aq[( NB_SUBFR16k + 1 ) * ( M + 1 )];
     177             :     int16_t pitch[NB_SUBFR16k];
     178             :     float pit_gain[NB_SUBFR16k];
     179             :     Word16 Aind[M + 1], lspind[M];
     180             : 
     181             :     /*Synth*/
     182             : #ifdef FIX_1320_STACK_CPE_DECODER
     183             :     float synth_buf[OLD_SYNTH_INTERNAL_DEC + L_FRAME_PLUS_INTERNAL + M];
     184             : #else
     185             :     float synth_buf[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M];
     186             : #endif
     187             :     float *synth;
     188             :     float synth_bufFB[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M];
     189             :     float *synthFB;
     190             : 
     191             :     /*Concealment*/
     192             :     int16_t bfi;
     193             : 
     194             :     float psd[L_FRAME16k], psd_part[NPART_SHAPING];
     195             : 
     196      704082 :     TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
     197      704082 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
     198             : 
     199      704082 :     push_wmops( "stereo_tcx_core_dec" );
     200             : 
     201             :     /*Sanity check*/
     202      704082 :     assert( !( st->total_brate == FRAME_NO_DATA || st->total_brate == SID_2k40 ) ); /*Active frame*/
     203      704082 :     assert( st->rf_flag == 0 );
     204      704082 :     assert( st->prev_use_partial_copy == 0 ); /* No channel aware mode */
     205      704082 :     assert( st->codec_mode == MODE1 );        /* must be in Mode 1 */
     206      704082 :     assert( st->mdct_sw == MODE1 );           /* must be switched to TCX in MODE1 */
     207             : 
     208      704082 :     bfi = 0;
     209             : 
     210             :     /*--------------------------------------------------------------------------------*
     211             :      * Initialization or re-configuration of Stereo TCX
     212             :      *--------------------------------------------------------------------------------*/
     213             : 
     214      704082 :     stereo_tcx_init_dec( st, 0, last_element_mode );
     215             : 
     216             :     /*--------------------------------------------------------------------------------*
     217             :      * Initializations
     218             :      *--------------------------------------------------------------------------------*/
     219             : 
     220      704082 :     total_nbbits = (int16_t) ( st->total_brate / FRAMES_PER_SEC );
     221      704082 :     bitsRead = 0;
     222      704082 :     LSF_Q_prediction = -1; /* to avoid compilation warnings */
     223             : 
     224      704082 :     if ( frameMode == FRAMEMODE_NORMAL )
     225             :     {
     226      690318 :         st->m_decodeMode = DEC_NO_FRAM_LOSS;
     227      690318 :         bfi = 0;
     228             :     }
     229             : 
     230      704082 :     if ( frameMode == FRAMEMODE_MISSING )
     231             :     {
     232       13764 :         st->m_decodeMode = DEC_CONCEALMENT_EXT;
     233       13764 :         bfi = 1;
     234             :     }
     235             : 
     236             :     /* for bass postfilter */
     237      704082 :     if ( st->tcxonly )
     238             :     {
     239      320742 :         st->p_bpf_noise_buf = NULL;
     240             :     }
     241             :     else
     242             :     {
     243      383340 :         st->p_bpf_noise_buf = st->bpf_noise_buf;
     244      383340 :         set_s( pitch, L_SUBFR, st->nb_subfr );
     245      383340 :         set_zero( pit_gain, st->nb_subfr );
     246             :     }
     247             : 
     248             :     /* Initialize pointers */
     249      704082 :     synth = synth_buf + hTcxDec->old_synth_len;
     250      704082 :     synthFB = synth_bufFB + hTcxDec->old_synth_lenFB;
     251      704082 :     mvr2r( hTcxDec->old_synth, synth_buf, hTcxDec->old_synth_len );
     252      704082 :     mvr2r( hTcxDec->old_synthFB, synth_bufFB, hTcxDec->old_synth_lenFB );
     253             : #ifdef FIX_1320_STACK_CPE_DECODER
     254      704082 :     set_zero( synth, L_FRAME_PLUS_INTERNAL + M );
     255             : #else
     256             :     set_zero( synth, L_FRAME_PLUS + M );
     257             : #endif
     258      704082 :     set_zero( synthFB, L_FRAME_PLUS + M );
     259             : 
     260             : #ifdef DEBUG_MODE_INFO_PLC
     261             :     dbgwrite( synth_buf, sizeof( float ), OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M, 1, "res/synth_buf_init" );
     262             :     dbgwrite( synth_bufFB, sizeof( float ), OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M, 1, "res/synthFB_buf_init" );
     263             : #endif
     264             : 
     265             :     /*--------------------------------------------------------------------------------*
     266             :      * BITSTREAM DECODING
     267             :      *--------------------------------------------------------------------------------*/
     268             : 
     269      704082 :     if ( !bfi )
     270             :     {
     271      690318 :         st->second_last_core = st->last_core;
     272             : 
     273      690318 :         dec_prm_tcx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead );
     274             :     }
     275             :     else
     276             :     {
     277       13764 :         if ( st->nbLostCmpt > 1 )
     278             :         {
     279        4131 :             st->flagGuidedAcelp = 0;
     280             :         }
     281             : 
     282             :         /* PLC: [Common: mode decision]
     283             :          * PLC: Decide which Concealment to use. Update pitch lags if needed */
     284       13764 :         st->core = GetPLCModeDecision( st );
     285             :     }
     286             : 
     287             :     /*--------------------------------------------------------------------------------*
     288             :      * LPC PARAMETERS
     289             :      *--------------------------------------------------------------------------------*/
     290             : 
     291      704082 :     st->acelp_cfg.midLpc = 0;
     292             : 
     293      704082 :     if ( !bfi )
     294             :     {
     295      690318 :         if ( hTcxDec->enableTcxLpc )
     296             :         {
     297             :             int16_t tcx_lpc_cdk;
     298             : 
     299       50958 :             if ( bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD )
     300             :             {
     301           0 :                 tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC );
     302             :             }
     303             :             else
     304             :             {
     305       50958 :                 tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type );
     306             :             }
     307             : 
     308       50958 :             mvr2r( st->lsf_old, &lsf[0], M );
     309       50958 :             mvr2r( st->lsp_old, &lsp[0], M );
     310             : 
     311       50958 :             D_lsf_tcxlpc( param_lpc, &lsf[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA );
     312             : 
     313       50958 :             lsf2lsp( &lsf[M], &lsp[M], M, st->sr_core );
     314             : 
     315       50958 :             lsf_update_memory( st->narrowBand, &lsf[M], st->mem_MA, st->mem_MA );
     316       50958 :             mvr2r( &lsf[M], st->mem_AR, M );
     317       50958 :             hTcxDec->envWeighted = 1;
     318             : 
     319       50958 :             E_LPC_lsp_unweight( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma );
     320             :         }
     321             :         else
     322             :         {
     323      639360 :             if ( hTcxDec->envWeighted )
     324             :             {
     325           0 :                 mvr2r( st->lspold_uw, st->lsp_old, M );
     326           0 :                 mvr2r( st->lsfold_uw, st->lsf_old, M );
     327           0 :                 hTcxDec->envWeighted = 0;
     328             :             }
     329             : 
     330      639360 :             lpc_unquantize( st, lsf, lsp, param_lpc, lspmid, lsfmid, AUDIO, &LSF_Q_prediction );
     331             : 
     332     1284831 :             for ( k = 0; k < st->numlpc; ++k )
     333             :             {
     334      645471 :                 mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M );
     335      645471 :                 mvr2r( &lsf[( k + 1 ) * M], &lsfnew_uw[k * M], M );
     336             :             }
     337             :         }
     338             : 
     339             :         /* PLC: [LPD: LPC concealment] built the moving average for the LPC concealment */
     340     1386747 :         for ( k = 0; k < st->numlpc; k++ )
     341             :         {
     342    11839293 :             for ( i = 0; i < M; i++ )
     343             :             {
     344    11142864 :                 st->lsf_adaptive_mean[i] = ( st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + lsfnew_uw[k * M + i] ) / 3;
     345    11142864 :                 st->lsfoldbfi1[i] = st->lsfoldbfi0[i];
     346    11142864 :                 st->lsfoldbfi0[i] = lsfnew_uw[k * M + i];
     347             :             }
     348             :         }
     349             :     }
     350             :     else
     351             :     {
     352             :         /* PLC: [LPD: LPC concealment] Conceal the LPC from the lost frame */
     353             :         const float *lsfBase; /* base for differential lsf coding */
     354             : 
     355       13764 :         if ( st->tcxonly == 0 || st->core < TCX_10_CORE )
     356             :         {
     357       13671 :             st->numlpc = 1;
     358             :         }
     359             :         else
     360             :         {
     361          93 :             st->numlpc = 2;
     362             :         }
     363             : 
     364       13764 :         if ( st->nbLostCmpt == 1 )
     365             :         {
     366        9633 :             mvr2r( st->lsf_old, st->old_lsf_q_cng, M );
     367        9633 :             mvr2r( st->lsp_old, st->old_lsp_q_cng, M );
     368             :         }
     369             : 
     370       13764 :         lsfBase = PlcGetlsfBase( st->lpcQuantization, st->narrowBand, st->sr_core );
     371             : 
     372       13764 :         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 );
     373             : 
     374       13764 :         hTcxDec->envWeighted = 0;
     375             : 
     376       13764 :         mvr2r( st->lspold_uw, lsp, M );
     377       13764 :         mvr2r( st->lsfold_uw, lsf, M );
     378             : 
     379       27621 :         for ( k = 0; k < st->numlpc; k++ )
     380             :         {
     381       13857 :             mvr2r( &lsfnew_uw[k * M], &lsf[( k + 1 ) * M], M );
     382             : 
     383       13857 :             lsf2lsp( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core );
     384       13857 :             lsf2lsp( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core );
     385             : 
     386       13857 :             mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M );
     387             :         }
     388             :     }
     389             : 
     390             :     /*---------------------------------------------------------------*
     391             :      * Rate switching
     392             :      *---------------------------------------------------------------*/
     393             : 
     394      704082 :     if ( st->rate_switching_reset )
     395             :     {
     396        4638 :         mvr2r( &( lsf[M] ), &( lsf[0] ), M );
     397        4638 :         mvr2r( &( lsp[M] ), &( lsp[0] ), M );
     398        4638 :         mvr2r( &( lsf[M] ), st->lsf_old, M );
     399        4638 :         mvr2r( &( lsp[M] ), st->lsp_old, M );
     400        4638 :         mvr2r( &( lsf[M] ), lsfmid, M );
     401        4638 :         mvr2r( &( lsp[M] ), lspmid, M );
     402        4638 :         lsp2a_stab( st->lsp_old, st->old_Aq_12_8, M );
     403             :     }
     404             : 
     405      704082 :     if ( st->enablePlcWaveadjust && bfi )
     406             :     {
     407           0 :         st->hPlcInfo->nbLostCmpt++;
     408             :     }
     409             : 
     410             :     /*--------------------------------------------------------------------------------*
     411             :      * TD-TCX concealment
     412             :      *--------------------------------------------------------------------------------*/
     413             : 
     414      704082 :     if ( st->core == ACELP_CORE )
     415             :     {
     416        4563 :         assert( bfi ); /*must only happen in BFI*/
     417             : 
     418        4563 :         if ( !st->tcxonly )
     419             :         {
     420             :             /*LPC interpolation*/
     421        3204 :             int_lsp( st->L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 );
     422        3204 :             int_lsp( st->L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_12k8, 0 );
     423             :         }
     424             : 
     425             :         /* PLC: [TCX: TD PLC] */
     426        4563 :         con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL );
     427        4563 :         lerp( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX );
     428        4563 :         st->con_tcx = 1;
     429        4563 :         set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr );
     430             : 
     431             :         /* LPC for ACELP/BWE */
     432        4563 :         if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k )
     433             :         {
     434        3204 :             mvr2r( Aq, st->mem_Aq, st->nb_subfr * ( M + 1 ) );
     435             :         }
     436             : 
     437             :         /* PLC: [TCX: Tonal Concealment] */
     438             :         /* Signal that this frame is not TCX */
     439        4563 :         if ( st->hTonalMDCTConc != NULL )
     440             :         {
     441        4563 :             TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, 0, 0, 0, 0 );
     442             :         }
     443             :     }
     444             : 
     445             :     /*--------------------------------------------------------------------------------*
     446             :      * TCX20
     447             :      *--------------------------------------------------------------------------------*/
     448             : 
     449             :     /* Set pointer to parameters */
     450      704082 :     prm = param;
     451      704082 :     if ( st->core == TCX_20_CORE )
     452             :     {
     453             :         /* Stability Factor */
     454      693315 :         if ( !bfi )
     455             :         {
     456      684207 :             st->stab_fac = lsf_stab( &lsf[M], &lsf[0], 0, st->L_frame );
     457             :         }
     458             : 
     459      693315 :         if ( hTcxDec->enableTcxLpc )
     460             :         {
     461             :             /* Convert quantized lsp to A */
     462       52128 :             lsp2a_stab( &lsp[M], Aq, M );
     463             :         }
     464             :         else
     465             :         {
     466      641187 :             if ( !st->tcxonly )
     467             :             {
     468      328008 :                 if ( !bfi && st->prev_bfi && !( st->safety_net ) && st->rate_switching_reset )
     469             :                 {
     470             :                     /* diffuse LPC power on rate switching*/
     471          75 :                     RecLpcSpecPowDiffuseLc( &lsp[M], &lsp[0], &lsf[M], st, 0 );
     472          75 :                     int_lsp( st->L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 );
     473          75 :                     mvr2r( &lsf[M], lsfnew_uw, M );
     474             :                 }
     475             :                 else
     476             :                 {
     477             :                     /* LPC Interpolation for TCX */
     478      327933 :                     E_LPC_int_lpc_tcx( &lsp[0], &lsp[M], Aq );
     479             :                 }
     480             :             }
     481             :             else
     482             :             {
     483      313179 :                 lsp2a_stab( &lsp[M], Aq, M );
     484             :             }
     485             :         }
     486             : 
     487      693315 :         if ( !bfi && hTcxDec->tcx_lpc_shaped_ari )
     488             :         {
     489       50958 :             basop_E_LPC_f_lsp_a_conversion( lspind, Aind, M );
     490             :         }
     491             : 
     492             :         /* TCX decoder */
     493      693315 :         decoder_tcx( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, sba_dirac_stereo_flag );
     494             :     }
     495             : 
     496             :     /*--------------------------------------------------------------------------------*
     497             :      * TCX10
     498             :      *--------------------------------------------------------------------------------*/
     499             : 
     500      704082 :     if ( st->core == TCX_10_CORE )
     501             :     {
     502        6204 :         prm = NULL; /* just to avoid MSVC warnings */
     503             : 
     504       18612 :         for ( k = 0; k < 2; k++ )
     505             :         {
     506             :             /* Set pointer to parameters */
     507       12408 :             prm = param + ( k * DEC_NPRM_DIV );
     508             : 
     509             :             /* Stability Factor */
     510       12408 :             if ( !bfi )
     511             :             {
     512       12222 :                 st->stab_fac = lsf_stab( &lsf[( k + 1 ) * M], &lsf[k * M], 0, st->L_frame );
     513             :             }
     514             : 
     515       12408 :             lsp2a_stab( &lsp[( k + 1 ) * M], Aq, M );
     516             :             {
     517       12408 :                 IGFDecRestoreTCX10SubFrameData( st->hIGFDec, k );
     518             :             }
     519             : 
     520             :             /* TCX decoder */
     521       12408 :             decoder_tcx( st, prm, Aq, Aind, &synth[k * st->L_frame / 2], &synthFB[k * hTcxDec->L_frameTCX / 2], bfi, k, sba_dirac_stereo_flag );
     522             :         }
     523             :     }
     524             : 
     525             : #ifdef DEBUG_MODE_TCX
     526             :     {
     527             :         int16_t tmp[L_FRAME48k];
     528             : 
     529             :         for ( i = 0; i < st->L_frame; i++ )
     530             :         {
     531             :             tmp[i] = (int16_t) ( synth[i] + 0.5f );
     532             :         }
     533             :         dbgwrite( tmp, sizeof( int16_t ), st->L_frame, 1, "./res/stereo_tcx_dec_synth.pcm" );
     534             :     }
     535             : #endif
     536             : 
     537             :     /*--------------------------------------------------------------------------------*
     538             :      * Post-processing
     539             :      *--------------------------------------------------------------------------------*/
     540             : 
     541      704082 :     if ( st->core == TCX_10_CORE || st->core == TCX_20_CORE )
     542             :     {
     543      699519 :         if ( st->enablePlcWaveadjust ||          /* bfi      */
     544      699519 :              ( st->last_total_brate >= HQ_48k && /* recovery */
     545      297630 :                st->last_codec_mode == MODE2 ) )
     546             :         {
     547             :             /* waveform adjustment */
     548           0 :             concealment_signal_tuning( st, bfi, synthFB, st->last_core_bfi );
     549             : 
     550           0 :             if ( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && st->hPlcInfo->concealment_method == TCX_NONTONAL )
     551             :             {
     552           0 :                 lerp( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX );
     553             : 
     554           0 :                 if ( !bfi && st->prev_bfi )
     555             :                 {
     556           0 :                     st->hPlcInfo->Pitch = 0;
     557             :                 }
     558             :             }
     559             :         }
     560             : 
     561      699519 :         if ( !bfi && st->hTonalMDCTConc != NULL )
     562             :         {
     563      690318 :             TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB, hTcxDec->L_frameTCX );
     564             :         }
     565             : 
     566      699519 :         decoder_tcx_post( st, synth, synthFB, Aq, bfi, 0 );
     567             : 
     568      699519 :         if ( st->core == TCX_20_CORE )
     569             :         {
     570             :             /* LPC Interpolation for BWE/post-processing */
     571      693315 :             if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k )
     572             :             {
     573      381594 :                 int_lsp( st->L_frame, st->lspold_uw, lspnew_uw, Aq, M, interpol_frac_12k8, 0 );
     574      381594 :                 mvr2r( Aq, st->mem_Aq, st->nb_subfr * ( M + 1 ) );
     575             :             }
     576             :         }
     577             :     }
     578             : 
     579             :     /* PLC: [Common: Classification] */
     580             :     /* the classifier buffer is always updated if the sr is at
     581             :        16000 or below - the classification itself is just performed if(!st->tcxonly ) */
     582      704082 :     if ( st->sr_core <= INT_FS_16k )
     583             :     {
     584      384840 :         if ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || ( st->tcxonly && st->bfi ) )
     585             :         {
     586             :             float pitch_C[4];
     587             : 
     588             :             /* note: the classifier needs the pitch only for tcx_only == 0, i.e. not for TCX10 */
     589      381636 :             set_f( pitch_C, floorf( st->old_fpitch + 0.5f ), 4 );
     590             : 
     591             :             /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/
     592      381636 :             FEC_clas_estim( synth, pitch_C, st->L_frame, st->tcxonly ? GENERIC : st->core_ext_mode, MODE2, 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 );
     593             :         }
     594             :     }
     595             : 
     596             :     /*--------------------------------------------------------------------------------*
     597             :      * Updates
     598             :      *--------------------------------------------------------------------------------*/
     599             : 
     600      704082 :     if ( bfi && st->last_core != ACELP_CORE )
     601             :     {
     602             :         /* Update FEC_scale_syn parameters */
     603       13764 :         if ( hTcxLtpDec->tcxltp_gain == 0 )
     604             :         {
     605        8250 :             fer_energy( st->L_frame, UNVOICED, synth, (float) ( st->L_frame / 2 ), &st->enr_old, st->L_frame );
     606             :         }
     607             :         else
     608             :         {
     609        5514 :             fer_energy( st->L_frame, st->clas_dec, synth, st->old_fpitch, &st->enr_old, st->L_frame );
     610             :         }
     611             :     }
     612             : 
     613      704082 :     if ( !bfi && st->clas_dec >= VOICED_TRANSITION && st->clas_dec < INACTIVE_CLAS )
     614             :     {
     615             :         /* use latest LPC set */
     616      425190 :         st->old_enr_LP = enr_1_Az( Aq, L_SUBFR );
     617             :     }
     618             : 
     619             :     /* Update past buffers */
     620      704082 :     mvr2r( synth_buf + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len );
     621      704082 :     mvr2r( hTcxDec->old_synthFB + hTcxDec->L_frameTCX - NS2SA( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->synth_history, NS2SA( st->output_Fs, PH_ECU_MEM_NS ) );
     622      704082 :     mvr2r( synth_bufFB + hTcxDec->L_frameTCX, hTcxDec->old_synthFB, hTcxDec->old_synth_lenFB );
     623      704082 :     mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB + hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
     624             : 
     625      704082 :     mvr2r( &lspnew_uw[( st->numlpc - 1 ) * M], st->lspold_uw, M );
     626      704082 :     mvr2r( &lsfnew_uw[( st->numlpc - 1 ) * M], st->lsfold_uw, M );
     627             : 
     628      704082 :     if ( bfi == 1 )
     629             :     {
     630       13764 :         mvr2r( st->lspold_uw, st->lsp_old, M ); /* for recovery */
     631       13764 :         mvr2r( st->lsfold_uw, st->lsf_old, M ); /* for recovery */
     632             :     }
     633             :     else
     634             :     {
     635      690318 :         mvr2r( &lsp[st->numlpc * M], st->lsp_old, M );
     636      690318 :         mvr2r( &lsf[st->numlpc * M], st->lsf_old, M );
     637             :     }
     638      704082 :     mvr2r( st->lsp_q_cng, st->old_lsp_q_cng, M );
     639      704082 :     mvr2r( st->lsf_q_cng, st->old_lsf_q_cng, M );
     640             : 
     641             :     /* Update CNG parameters */
     642      704082 :     if ( !st->tcxonly && st->hTdCngDec != NULL )
     643             :     {
     644             :         /* update CNG parameters in active frames */
     645      236196 :         if ( st->bwidth == NB && hTcxDec->enableTcxLpc && st->core != ACELP_CORE )
     646           0 :         {
     647             :             float buf[L_LP], res[L_FRAME], A[M + 1], r[M + 1], tmp, lsptmp[M];
     648           0 :             assert( st->L_frame == L_FRAME );
     649             : 
     650           0 :             mvr2r( synth + L_FRAME - L_LP, buf, L_LP );
     651           0 :             tmp = synth[L_FRAME - L_LP - 1];
     652           0 :             preemph( buf, st->preemph_fac, L_LP, &tmp );
     653           0 :             autocorr( buf, r, M, L_LP, LP_assym_window, 0, 0, 0 );
     654           0 :             lag_wind( r, M, INT_FS_12k8, LAGW_WEAK );
     655           0 :             lev_dur( A, r, M, NULL );
     656           0 :             a2lsp_stab( A, lsptmp, &lspnew_uw[0] );
     657           0 :             residu( A, M, buf + L_LP - L_FRAME, res, L_FRAME );
     658             : 
     659           0 :             if ( st->hTdCngDec != NULL )
     660             :             {
     661           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 );
     662             :             }
     663             :         }
     664      236196 :         else if ( st->hTdCngDec != NULL )
     665             :         {
     666      236196 :             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 );
     667             :         }
     668             : 
     669             :         /* Set 16k LSP flag for CNG buffer */
     670      236196 :         st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 );
     671             :     }
     672      704082 :     st->last_is_cng = 0;
     673             : 
     674             :     /* Postfiltering */
     675      704082 :     post_decoder( st, synth_buf, pit_gain, pitch, signal_out, st->p_bpf_noise_buf );
     676             : 
     677      704082 :     if ( signal_outFB )
     678             :     {
     679      704082 :         mvr2r( synthFB, signal_outFB, hTcxDec->L_frameTCX );
     680             :     }
     681             : 
     682      704082 :     if ( !bfi )
     683             :     {
     684      690318 :         if ( st->enablePlcWaveadjust )
     685             :         {
     686           0 :             st->hPlcInfo->nbLostCmpt = 0;
     687             :         }
     688             : 
     689      690318 :         if ( param[1 + NOISE_FILL_RANGES] != 0 )
     690             :         {
     691      342108 :             set_f( pitch_buf, hTcxLtpDec->tcxltp_pitch_int + (float) hTcxLtpDec->tcxltp_pitch_fr / (float) st->pit_res_max, NB_SUBFR16k );
     692             :         }
     693             :         else
     694             :         {
     695      348210 :             set_f( pitch_buf, L_SUBFR, NB_SUBFR16k );
     696             :         }
     697             :     }
     698             : 
     699      704082 :     if ( bfi )
     700             :     {
     701             :         /*"LPD dec - All BFI"*/
     702       13764 :         bitsRead = 0; /*to avoid empty counting */
     703             :     }
     704             : 
     705             :     /* updates */
     706      704082 :     st->last_voice_factor = 0.0f;
     707      704082 :     st->last_coder_type = st->coder_type;
     708             : 
     709             :     /* -------------------------------------------------------------- *
     710             :      * In FFT domain: perform noise estimation during active frames
     711             :      * -------------------------------------------------------------- */
     712             : 
     713      704082 :     if ( st->hFdCngDec != NULL && ( st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) && st->total_brate <= MAX_ACELP_BRATE )
     714             :     {
     715      376149 :         noisy_speech_detection( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, signal_out );
     716             : 
     717      376149 :         st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech;
     718             : 
     719      376149 :         st->lp_noise = st->hFdCngDec->lp_noise;
     720             : 
     721      376149 :         if ( st->element_mode != IVAS_CPE_TD )
     722             :         {
     723      375660 :             if ( ivas_format == ISM_FORMAT )
     724             :             {
     725             :                 float buffer[L_FRAME16k];
     726      232107 :                 lerp( signal_outFB, buffer, st->L_frame, hTcxDec->L_frameTCX );
     727      232107 :                 ApplyFdCng( buffer, NULL, NULL, NULL, st, st->bfi, 0 );
     728             :             }
     729             :             else
     730             :             {
     731      143553 :                 ApplyFdCng( signal_out, NULL, NULL, NULL, st, st->bfi, 0 );
     732             :             }
     733             :         }
     734             : 
     735             :         /* Generate additional comfort noise to mask potential coding artefacts */
     736      376149 :         if ( st->m_frame_type == ACTIVE_FRAME && st->flag_cna && !st->cna_dirac_flag )
     737             :         {
     738      121728 :             if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 )
     739             :             {
     740           0 :                 if ( st->element_mode != last_element_mode )
     741             :                 {
     742             :                     /* Clear memory for secondary channel CNA */
     743           0 :                     set_f( hStereoCng->olapBufferSynth22, 0.0f, st->hFdCngDec->hFdCngCom->frameSize / 2 );
     744             :                 }
     745           0 :                 expand_range( st->hFdCngDec->msPsd, psd_part, st->hFdCngDec->nFFTpart_shaping );
     746           0 :                 scalebands( psd_part, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->midband_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand, psd, 1 );
     747           0 :                 generate_stereo_masking_noise( signal_out, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out );
     748             :             }
     749      121728 :             else if ( st->element_mode != IVAS_CPE_DFT )
     750             :             {
     751       79041 :                 generate_masking_noise( signal_out, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out );
     752             :             }
     753             :         }
     754             : 
     755      376149 :         if ( st->element_mode == IVAS_CPE_TD && st->idchan == 0 )
     756             :         {
     757         489 :             ApplyFdCng( signal_out, NULL, NULL, NULL, st, st->bfi, 0 );
     758             :         }
     759             :     }
     760             : 
     761             : #ifdef DEBUG_MODE_TCX
     762             :     {
     763             :         int16_t tmp[L_FRAME48k];
     764             :         static FILE *sP = NULL;
     765             : 
     766             :         for ( i = 0; i < hTcxDec->L_frameTCX; i++ )
     767             :         {
     768             :             tmp[i] = (int16_t) ( signal_outFB[i] + 0.5f );
     769             :         }
     770             :         dbgwrite( tmp, sizeof( int16_t ), hTcxDec->L_frameTCX, 1, "./res/stereo_tcx_dec_synthFB.pcm" );
     771             : 
     772             :         for ( i = 0; i < hTcxDec->L_frameTCX; i++ )
     773             :         {
     774             :             tmp[i] = (int16_t) ( signal_out[i] + 0.5f );
     775             :         }
     776             :         dbgwrite( tmp, sizeof( int16_t ), hTcxDec->L_frameTCX, 1, "./res/stereo_tcx_dec_synthLB.pcm" );
     777             : 
     778             :         if ( sP == NULL )
     779             :             sP = fopen( "./res/stereo_tcx_core_dec_swicthes.txt", "w" );
     780             : 
     781             :         fprintf( sP, "frame:%d\t mdct_sw=%d\t rf_mode=%d tcxonly=%d\t tcxMode=%d\t core=%d\t, enableTcxLpc=%d\t igf=%d\t envWeighted=%d\t lpcQuantization=%d\t enablePlcWaveadjust=%d\t tcxltp=%d\t fIsTNSAllowed=%d\t tcx_lpc_shaped_ari=%d\t ctx_hm=%d\t \n", frame, st->mdct_sw, 0, st->tcxonly, 0, st->core, hTcxDec->enableTcxLpc, st->igf, hTcxDec->envWeighted, st->lpcQuantization, st->enablePlcWaveadjust, hTcxLtpDec->tcxltp, st->hTcxCfg->fIsTNSAllowed, 0, st->hTcxCfg->ctx_hm );
     782             :     }
     783             : #endif
     784             : 
     785             : 
     786      704082 :     pop_wmops();
     787      704082 :     return;
     788             : }
     789             : 
     790             : 
     791             : /*-----------------------------------------------------------------*
     792             :  * Function dec_prm_tcx()
     793             :  *
     794             :  * Decode TCX parameters
     795             :  *-----------------------------------------------------------------*/
     796             : 
     797      690318 : static void dec_prm_tcx(
     798             :     Decoder_State *st,               /* i/o: decoder memory state            */
     799             :     int16_t param[],                 /* o  : decoded parameters              */
     800             :     int16_t param_lpc[],             /* o  : LPC parameters                  */
     801             :     int16_t *total_nbbits,           /* i/o: number of bits / decoded bits   */
     802             :     const int16_t last_element_mode, /* i  : last element mode               */
     803             :     int16_t *bitsRead                /* o  : number of read bits             */
     804             : )
     805             : {
     806             :     int16_t start_bit_pos, bits_common;
     807             :     CONTEXT_HM_CONFIG hm_cfg;
     808             :     int16_t indexBuffer[N_MAX + 1];
     809             : #ifdef DEBUG_MODE_TCX
     810             :     int16_t nbits_tcx;
     811             :     static FILE *pF = NULL;
     812             :     if ( pF == NULL )
     813             :         pF = fopen( "./res/stereo_tcx_dec_ind.txt", "w" );
     814             : #endif
     815             : 
     816      690318 :     assert( st->mdct_sw == MODE1 );
     817             : 
     818             :     /*--------------------------------------------------------------------------------*
     819             :      * INIT
     820             :      *--------------------------------------------------------------------------------*/
     821             : 
     822      690318 :     hm_cfg.indexBuffer = indexBuffer;
     823             : #ifdef DEBUG_MODE_TCX
     824             :     fprintf( pF, "== stereo Chan %d - Nominal Bits %d - Allocated Bits %d ==\n", st->idchan, st->bits_frame_nominal, (int16_t) ( st->total_brate / FRAMES_PER_SEC ) );
     825             :     fprintf( pF, "stereo Common Header: %d bits\n", st->next_bit_pos );
     826             : #endif
     827      690318 :     if ( st->element_mode != IVAS_CPE_MDCT )
     828             :     {
     829      690318 :         st->bits_frame_core = (int16_t) ( ( st->total_brate / FRAMES_PER_SEC ) - st->next_bit_pos );
     830             :     }
     831      690318 :     start_bit_pos = st->next_bit_pos;
     832             : 
     833             :     /* Init LTP data */
     834      690318 :     st->hTcxDec->tcx_hm_LtpPitchLag = -1;
     835      690318 :     st->hTcxLtpDec->tcxltp_gain = 0.0f;
     836             : 
     837             :     /*--------------------------------------------------------------------------------*
     838             :      * header
     839             :      *--------------------------------------------------------------------------------*/
     840             : 
     841             :     /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */
     842      690318 :     getTCXMode( st, st, 0 /* <- MCT_flag */ );
     843             : 
     844             :     /* last_core for error concealment */
     845      690318 :     if ( !st->use_partial_copy && st->element_mode != IVAS_CPE_MDCT )
     846             :     {
     847      690318 :         st->last_core_from_bs = get_next_indice( st, 1 ); /* Store decoder memory of last_core */
     848      690318 :         if ( st->last_core == ACELP_CORE && st->last_core_from_bs != ACELP_CORE )
     849             :         {
     850             :             /* A mismatch between the memory and the last_core
     851             :                from the bitstream indicates a frame was lost. If prev_bfi is
     852             :                not set the frame loss occured during CNG and the prev_bfi needs to be set. */
     853         294 :             st->prev_bfi = 1;
     854             :         }
     855             : 
     856             :         /* possible need for reconfiguration can only be decided correctly once last_core_from_bs has been decoded */
     857      690318 :         if ( ( st->last_core != st->last_core_from_bs ) && ( st->last_core_from_bs != TCX_20_CORE && st->last_core_from_bs != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core_from_bs == ACELP_CORE && st->last_con_tcx == 1 ) ) )
     858             :         {
     859         177 :             stereo_tcx_dec_mode_switch_reconf( st, 0, last_element_mode );
     860             :         }
     861             : 
     862      690318 :         st->last_core = st->last_core_from_bs;
     863             : 
     864             :         /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/
     865      690318 :         if ( st->core == TCX_10_CORE )
     866             :         {
     867        6111 :             st->last_core = TCX_20_CORE;
     868             :         }
     869             :     }
     870             : 
     871      690318 :     if ( !st->use_partial_copy )
     872             :     {
     873      690318 :         if ( st->element_mode != IVAS_CPE_MDCT )
     874             :         {
     875      690318 :             getTCXWindowing( st->core, st->last_core, st->element_mode, st->hTcxCfg, st );
     876             :         }
     877      690318 :         st->flagGuidedAcelp = 0;
     878             : 
     879      690318 :         if ( st->dec_glr )
     880             :         {
     881           0 :             st->dec_glr_idx = -1;
     882             :         }
     883             :     }
     884             : 
     885             : #ifdef DEBUG_MODE_TCX
     886             :     fprintf( pF, "\t TCX Header: %d bits: %d %d %d %d\n", st->next_bit_pos - start_bit_pos, st->tcxonly, st->core, st->tcxonly ? st->clas_dec : st->hTcxCfg->coder_type, st->hTcxCfg->tcx_curr_overlap_mode );
     887             :     nbits_tcx = st->next_bit_pos;
     888             : #endif
     889             : 
     890             :     /*--------------------------------------------------------------------------------*
     891             :      * LPC parameters
     892             :      *--------------------------------------------------------------------------------*/
     893             : 
     894      690318 :     getLPCparam( st, param_lpc, st, -1, 0 );
     895             : 
     896      690318 :     bits_common = st->next_bit_pos - start_bit_pos;
     897             : 
     898             : #ifdef DEBUG_MODE_TCX
     899             :     fprintf( pF, "\t TCX LPC: %d bits\n", st->next_bit_pos - nbits_tcx );
     900             : #endif
     901             : 
     902             :     /*--------------------------------------------------------------------------------*
     903             :      * TCX20/10 parameters
     904             :      *--------------------------------------------------------------------------------*/
     905             : 
     906      690318 :     if ( st->use_partial_copy == 0 )
     907             :     {
     908      690318 :         getTCXparam( st, st, hm_cfg, param, bits_common, start_bit_pos, NULL, NULL, NULL, -1 );
     909             :     }
     910             : 
     911      690318 :     if ( !st->use_partial_copy )
     912             :     {
     913      690318 :         if ( *total_nbbits - bitsRead[0] < ( st->next_bit_pos - start_bit_pos ) )
     914             :         {
     915           0 :             st->BER_detect = 1;
     916           0 :             st->next_bit_pos = start_bit_pos + *total_nbbits - bitsRead[0];
     917             :         }
     918             : 
     919      690318 :         bitsRead[0] = st->next_bit_pos - start_bit_pos;
     920             :     }
     921             : 
     922      690318 :     return;
     923             : }
     924             : 
     925             : /*-----------------------------------------------------------------*
     926             :  * Function stereo_tcx_dec_mode_switch_reconf()
     927             :  *
     928             :  * Reconfigure stereo TCX parameters
     929             :  *-----------------------------------------------------------------*/
     930             : 
     931       74256 : static void stereo_tcx_dec_mode_switch_reconf(
     932             :     Decoder_State *st,              /* i/o: decoder state structure             */
     933             :     const int16_t MCT_flag,         /* i  : hMCT handle allocated (1) or not (0)*/
     934             :     const int16_t last_element_mode /* i  : element mode of previous frame      */
     935             : )
     936             : {
     937             :     int16_t frame_size_index;
     938             : 
     939       74256 :     st->rate_switching_init = 1;
     940             : 
     941             :     /* Identify frame type - TCX Reconfiguration */
     942      690633 :     for ( frame_size_index = 0; frame_size_index < FRAME_SIZE_NB; frame_size_index++ )
     943             :     {
     944      690633 :         if ( frame_size_index < FRAME_SIZE_NB - 1 )
     945             :         {
     946      677037 :             if ( ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal ) && ( FrameSizeConfig[frame_size_index + 1].frame_bits > st->bits_frame_nominal ) )
     947             :             {
     948       60660 :                 break;
     949             :             }
     950             :         }
     951             :         else
     952             :         {
     953       13596 :             if ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal )
     954             :             {
     955       13596 :                 break;
     956             :             }
     957             :         }
     958             :     }
     959             : 
     960             :     /* Reconfigure Core */
     961       74256 :     mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, MCT_flag, last_element_mode );
     962             : 
     963       74256 :     return;
     964             : }

Generated by: LCOV version 1.14