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

Generated by: LCOV version 1.14