LCOV - code coverage report
Current view: top level - lib_dec - ivas_mct_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ da9cc8ead0679b4682d329fdff98cf1616159273 Lines: 656 716 91.6 %
Date: 2025-10-13 22:24:20 Functions: 6 6 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             : #include <math.h>
      37             : #include "cnst.h"
      38             : #include "ivas_cnst.h"
      39             : #include "rom_com.h"
      40             : #include "prot_fx.h"
      41             : #include "ivas_prot_rend_fx.h"
      42             : #include "ivas_rom_com.h"
      43             : #include "wmc_auto.h"
      44             : #include "ivas_prot_fx.h"
      45             : 
      46             : 
      47             : /*-----------------------------------------------------------------------*
      48             :  * Local function prototypes
      49             :  *-----------------------------------------------------------------------*/
      50             : 
      51             : #ifdef FIX_HRTF_LOAD
      52             : static ivas_error ivas_mc_dec_reconfig_fx( Decoder_Struct *st_ivas );
      53             : #else
      54             : static ivas_error ivas_mc_dec_reconfig_fx( Decoder_Struct *st_ivas, UWord16 *nSamplesRendered, Word16 *data );
      55             : #endif
      56             : 
      57             : 
      58             : /*--------------------------------------------------------------------------*
      59             :  * ivas_mct_dec()
      60             :  *
      61             :  * Multi-channel Coding Tool (MCT) decoding routine
      62             :  *--------------------------------------------------------------------------*/
      63             : 
      64       99420 : ivas_error ivas_mct_dec_fx(
      65             :     Decoder_Struct *st_ivas,      /* i/o: IVAS decoder structure          */
      66             :     Word32 *output_fx[],          /* o  : output synthesis signal         Q11*/
      67             :     const Word16 output_frame,    /* i  : output frame length per channel */
      68             :     const Word16 nb_bits_metadata /* i  : number of metadata bits         */
      69             : )
      70             : {
      71             :     Word16 nCPE, cpe_id;
      72             :     MCT_DEC_HANDLE hMCT;
      73             :     CPE_DEC_HANDLE hCPE;
      74             :     Word16 param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV];
      75             :     Word16 param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW];
      76             :     Word16 p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV];
      77             :     Word16 nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV];
      78             :     Word16 fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV];
      79             :     STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV];
      80             :     Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; // Q12
      81             :     Word32 output_lfe_ch_fx[L_FRAME48k];
      82       99420 :     Word16 q_output = 11;
      83             :     Word16 n, i;
      84             : 
      85             :     Word32 *x_fx[CPE_CHANNELS][NB_DIV]; //(Q(31 - x_e)
      86             :     Word16 x_len[CPE_CHANNELS][NB_DIV];
      87       99420 :     set16_fx( x_len[0], 0, NB_DIV );
      88       99420 :     set16_fx( x_len[1], 0, NB_DIV );
      89             :     Decoder_State **sts;
      90             :     Word32 *p_output_orig_fx[2];
      91             :     Word32 synth_fx_32[CPE_CHANNELS][L_FRAME_PLUS];
      92             :     Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; //(Q_synth)
      93             :     Word32 ivas_total_brate;
      94             :     ivas_error error;
      95       99420 :     Word16 e_sig[CPE_CHANNELS] = { 15, 15 };
      96       99420 :     move16();
      97       99420 :     move16();
      98             : 
      99       99420 :     push_wmops( "ivas_mct_dec" );
     100             : 
     101       99420 :     error = IVAS_ERR_OK;
     102       99420 :     move32();
     103       99420 :     nCPE = st_ivas->nCPE;
     104       99420 :     move16();
     105       99420 :     hMCT = st_ivas->hMCT;
     106             : 
     107       99420 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     108       99420 :     move32();
     109             : 
     110       99420 :     test();
     111       99420 :     test();
     112       99420 :     test();
     113       99420 :     test();
     114       99420 :     IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) )
     115             :     {
     116             :         /* save LFE channel */
     117       26872 :         Copy32( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); // Q11
     118             :     }
     119             : 
     120       99420 :     IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) && ( st_ivas->bfi == 0 ) )
     121             :     {
     122             :         /* get the number of channels from the signalled MC LS setup */
     123       25931 :         n = ivas_mc_ls_setup_get_num_channels_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ) );
     124             : 
     125       25931 :         IF( NE_16( n, st_ivas->nchan_transport ) )
     126             :         {
     127             :             /* IVAS_fmToDo: more work needed for switching the number of transport channels */
     128           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!" );
     129             :         }
     130             :     }
     131             : 
     132      362864 :     FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
     133             :     {
     134             :         /*initialize param_lpc buffer*/
     135      790332 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     136             :         {
     137      526888 :             set16_fx( param_lpc[cpe_id][n], 0, NPRM_LPC_NEW );
     138             :         }
     139             : 
     140      263444 :         set32_fx( &output_fx[0][0], 0, L_FRAME48k );
     141      263444 :         set32_fx( &output_fx[1][0], 0, L_FRAME48k );
     142      263444 :         IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, cpe_id, &output_fx[0], output_frame, 0 ) ), IVAS_ERR_OK ) )
     143             :         {
     144           0 :             return error;
     145             :         }
     146             : 
     147      263444 :         if ( cpe_id == 0 )
     148             :         {
     149       99420 :             st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */
     150       99420 :             move32();
     151             :         }
     152             : 
     153      263444 :         IF( st_ivas->bfi == 0 )
     154             :         {
     155      259737 :             ivas_mdct_dec_side_bits_frame_channel_fx( st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1,
     156      259737 :                                                       (Word16) GT_16( i_mult( add( cpe_id, 1 ), CPE_CHANNELS ), hMCT->nchan_out_woLFE ) );
     157             : 
     158      259737 :             st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect );
     159      259737 :             test();
     160      259737 :             st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect );
     161      259737 :             test();
     162             :         }
     163             :     }
     164             : 
     165             :     /* MCT side bits decoder */
     166       99420 :     ivas_mct_side_bits_fx( hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata );
     167             : 
     168             :     /* in case of switching from an SID frame (with ACELP core) to MCT, buffer of L_FRAME_PLUS samples is needed -> use synth[] as a temporary buffer */
     169       99420 :     IF( st_ivas->hCPE[0]->hCoreCoder[0]->last_core == ACELP_CORE )
     170             :     {
     171           6 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     172             :         {
     173           4 :             p_output_orig_fx[n] = output_fx[n];
     174           4 :             output_fx[n] = synth_fx_32[n];
     175             :         }
     176             :     }
     177             : 
     178      362864 :     FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
     179             :     {
     180      263444 :         st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect = s_or( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect, st_ivas->BER_detect );
     181      263444 :         move16();
     182      263444 :         st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect = s_or( st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect, st_ivas->BER_detect );
     183      263444 :         move16();
     184             : 
     185      790332 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     186             :         {
     187      526888 :             x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11
     188      526888 :             move16();
     189      526888 :             x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11
     190      526888 :             move16();
     191             : 
     192      526888 :             set32_fx( x_fx[n][0], 0, L_FRAME48k / 2 );
     193      526888 :             set32_fx( x_fx[n][1], 0, L_FRAME48k / 2 );
     194             :         }
     195             : 
     196      263444 :         ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id],
     197      263444 :                                 fUseTns[cpe_id], tnsData[cpe_id], x_fx, 20, x_fx, 20, x_len, Aq_fx[cpe_id], NULL, 1 );
     198             : 
     199             : 
     200      263444 :         st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect );
     201      263444 :         move16();
     202      263444 :         st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect );
     203      263444 :         move16();
     204             :     }
     205             : 
     206             : 
     207             :     /* MCT core decoder */
     208             :     Word16 q_x[MAX_TRANSPORT_CHANNELS];
     209       99420 :     ivas_mct_core_dec( hMCT, st_ivas->hCPE, nCPE, output_fx, q_x );
     210             :     // Scaling output buffer back to Q11
     211             : 
     212             : 
     213             :     /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/
     214       99420 :     test();
     215       99420 :     IF( ( st_ivas->sba_dirac_stereo_flag != 0 ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     216             :     {
     217        4940 :         FOR( cpe_id = 1; cpe_id < nCPE; cpe_id++ )
     218             :         {
     219        7410 :             FOR( n = 0; n < CPE_CHANNELS; n++ )
     220             :             {
     221        4940 :                 st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE;
     222        4940 :                 move16();
     223             :             }
     224             :         }
     225             :     }
     226             : 
     227             :     Word32 Aq_fx_32[6][2][102];
     228             :     /* MCT reconstruction and CoreCoder updates */
     229      362864 :     FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
     230             :     {
     231      263444 :         hCPE = st_ivas->hCPE[cpe_id];
     232             : 
     233      790332 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     234             :         {
     235      526888 :             Copy_Scale_sig_16_32_DEPREC( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, Q16 - Q12 ); // Q16
     236      526888 :             x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )];                                // Q11
     237      526888 :             x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 );           // Q11
     238      526888 :             move16();
     239      526888 :             move16();
     240             :         }
     241             : 
     242      263444 :         ivas_mdct_core_tns_ns_fx( hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32[cpe_id], 1, 20 );
     243             :     }
     244             : 
     245             : 
     246       99420 :     test();
     247       99420 :     test();
     248       99420 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_MC ) )
     249             :     {
     250             :         /* Equalization in MDCT Domain */
     251        6504 :         ivas_ls_setup_conversion_process_mdct_fx( st_ivas, output_fx );
     252             :     }
     253       92916 :     ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) && ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
     254             :     {
     255             :         Word16 x_all_e[MAX_CICP_CHANNELS][NB_DIV];
     256         340 :         FOR( i = 0; i < MAX_CICP_CHANNELS; i++ )
     257             :         {
     258         320 :             set16_fx( x_all_e[i], 0, NB_DIV );
     259             :         }
     260             :         Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; //(Q(31 - x_all_e)
     261          60 :         FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
     262             :         {
     263         120 :             FOR( n = 0; n < CPE_CHANNELS; n++ )
     264             :             {
     265          80 :                 x_all_fx[n + ( cpe_id * CPE_CHANNELS )][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )];                      // Q11
     266          80 :                 x_all_fx[n + ( cpe_id * CPE_CHANNELS )][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11
     267          80 :                 x_all_e[n + ( cpe_id * CPE_CHANNELS )][1] = 20;
     268          80 :                 move16();
     269          80 :                 x_all_e[n + ( cpe_id * CPE_CHANNELS )][0] = 20;
     270          80 :                 move16();
     271             :             }
     272             :         }
     273             : 
     274          20 :         ivas_ls_setup_conversion_process_mdct_param_mc_fx( st_ivas, x_all_fx, x_all_e );
     275             : 
     276          60 :         FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
     277             :         {
     278         120 :             FOR( n = 0; n < CPE_CHANNELS; n++ )
     279             :             {
     280          80 :                 Scale_sig32( x_all_fx[n + ( cpe_id * CPE_CHANNELS )][0], ( L_FRAME48k / 2 ), sub( x_all_e[n + ( cpe_id * CPE_CHANNELS )][0], 20 ) ); // Q11
     281          80 :                 Scale_sig32( x_all_fx[n + ( cpe_id * CPE_CHANNELS )][1], ( L_FRAME48k / 2 ), sub( x_all_e[n + ( cpe_id * CPE_CHANNELS )][1], 20 ) ); // Q11
     282             :             }
     283             :         }
     284             :     }
     285             : 
     286      362864 :     FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
     287             :     {
     288      263444 :         hCPE = st_ivas->hCPE[cpe_id];
     289      263444 :         sts = hCPE->hCoreCoder;
     290             : 
     291      790332 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     292             :         {
     293      526888 :             x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )];                      // Q11
     294      526888 :             x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11
     295             :         }
     296      263444 :         Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ) );
     297      263444 :         Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0], 1 ) ) ) ) );
     298      263444 :         ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, q_output, e_sig );
     299             :         Word16 hdrm;
     300      263444 :         hdrm = getScaleFactor16( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX );
     301      263444 :         IF( hdrm != 0 )
     302             :         {
     303      256387 :             hdrm = sub( hdrm, 1 );
     304      256387 :             Scale_sig( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, hdrm );
     305      256387 :             e_sig[0] = sub( e_sig[0], hdrm );
     306      256387 :             move16();
     307             :         }
     308      263444 :         hdrm = getScaleFactor16( synth_fx[1], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX );
     309      263444 :         IF( hdrm != 0 )
     310             :         {
     311      197990 :             hdrm = sub( hdrm, 1 );
     312      197990 :             Scale_sig( synth_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, hdrm );
     313      197990 :             e_sig[1] = sub( e_sig[1], hdrm );
     314      197990 :             move16();
     315             :         }
     316             : 
     317      790332 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     318             :         {
     319      526888 :             IF( hCPE->hCoreCoder[n]->hBPF )
     320             :             {
     321           0 :                 hCPE->hCoreCoder[n]->hBPF->pst_mem_deemp_err_fx = extract_l( L_shr( hCPE->hCoreCoder[n]->mem_error, sub( Q16, sub( hCPE->hCoreCoder[n]->Q_syn2, 1 ) ) ) );
     322           0 :                 Scale_sig( hCPE->hCoreCoder[n]->hBPF->pst_old_syn_fx, NBPSF_PIT_MAX, sub( hCPE->hCoreCoder[n]->Q_syn2, 1 ) );
     323           0 :                 move16();
     324             :             }
     325             :         }
     326             : 
     327             :         /* set pointers back */
     328      263444 :         test();
     329      263444 :         IF( cpe_id == 0 && st_ivas->hCPE[0]->hCoreCoder[0]->last_core == ACELP_CORE )
     330             :         {
     331           6 :             FOR( n = 0; n < CPE_CHANNELS; n++ )
     332             :             {
     333           4 :                 output_fx[n] = p_output_orig_fx[n];
     334             :             }
     335             :         }
     336             : 
     337             : 
     338             :         /*----------------------------------------------------------------*
     339             :          * CoreCoder Post-processing and updates
     340             :          *----------------------------------------------------------------*/
     341             : 
     342      790332 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     343             :         {
     344      526888 :             test();
     345      526888 :             test();
     346      526888 :             IF( ( st_ivas->sba_dirac_stereo_flag != 0 ) && ( NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) )
     347             :             {
     348       19764 :                 Copy_Scale_sig_16_32_no_sat( synth_fx[n], synth_fx_32[n], output_frame, sub( Q11, ( sub( 15, e_sig[n] ) ) ) ); // Q11
     349       19764 :                 Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->old_out_fx32, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) );
     350       19764 :                 ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1, Q11 );
     351       19764 :                 Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, sub( sub( 15, e_sig[n] ), Q11 ) ); // Q0
     352             :             }
     353             : 
     354             :             /* Postprocessing for ACELP/MDCT core switching and synchronization */
     355             :             Word16 output_mem_fx[L_FRAME48k];
     356      526888 :             IF( hCPE->output_mem_fx[1] != NULL )
     357             :             {
     358       24984 :                 Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA_FX2( sts[n]->output_Fs, 3125000 ), -Q11 );
     359             :             }
     360             :             ELSE
     361             :             {
     362      501904 :                 set16_fx( output_mem_fx, 0, NS2SA_FX2( sts[n]->output_Fs, 3125000 ) );
     363             :             }
     364             : 
     365      526888 :             Word16 Q_synth = sub( 15, e_sig[n] );
     366      526888 :             move16();
     367             : 
     368             :             Word16 dirac_stereo_flag;
     369      526888 :             test();
     370      526888 :             IF( NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) )
     371             :             {
     372      465688 :                 dirac_stereo_flag = st_ivas->sba_dirac_stereo_flag;
     373             :             }
     374             :             ELSE
     375             :             {
     376       61200 :                 dirac_stereo_flag = 0;
     377             :             }
     378      526888 :             IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) )
     379             :             {
     380           0 :                 return error;
     381             :             }
     382      526888 :             Copy_Scale_sig_16_32_no_sat( synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_frame, sub( Q11, Q_synth ) ); // Q11
     383             :             /* Save synthesis for HQ FEC */
     384             :             Word32 output_fx_[L_FRAME48k];
     385      526888 :             Copy32( output_fx[( cpe_id * CPE_CHANNELS ) + n], output_fx_, L_FRAME48k );                                                                     // Q11
     386      526888 :             Scale_sig32( output_fx_, L_FRAME48k, Q16 - Q11 );                                                                                               // Q11 -> Q16
     387      526888 :             Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -Q11 ); // Q11 -> Q0
     388      526888 :             sts[n]->q_prev_synth_buffer_fx = 0;
     389      526888 :             move16();
     390             : 
     391      526888 :             save_synthesis_hq_fec_fx( sts[n], NULL, output_fx_, output_frame, 0, hCPE );
     392             : 
     393             :             /* CoreCoder common updates */
     394      526888 :             ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[( cpe_id * CPE_CHANNELS ) + n], 11 );
     395             : 
     396             :         } /* n_channels loop */
     397             : 
     398      790332 :         FOR( n = 0; n < 2; n++ )
     399             :         {
     400      526888 :             IF( hCPE->hCoreCoder[n] )
     401             :             {
     402      526888 :                 Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11 ); // Q0 -> Q11
     403             :             }
     404             :         }
     405             : 
     406             :         /* synthesis synchronization between stereo modes */
     407      263444 :         test();
     408      263444 :         test();
     409      263444 :         IF( ( st_ivas->sba_dirac_stereo_flag == 0 ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && LT_16( cpe_id, sub( nCPE, 2 ) ) ) )
     410             :         {
     411      253562 :             synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + imult1616( cpe_id, CPE_CHANNELS ), output_frame, 0, Q11 );
     412             :         }
     413             :     }
     414             : 
     415             :     /* move channels after LFE to correct output for multi-channel MCT */
     416       99420 :     test();
     417       99420 :     test();
     418       99420 :     IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) )
     419             :     {
     420             :         Word32 tmp[L_FRAME48k];
     421             : 
     422             :         /*save center channel output*/
     423       26872 :         Copy32( output_fx[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); // Q11
     424             : 
     425       94880 :         FOR( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- )
     426             :         {
     427       68008 :             Copy32( output_fx[n - 1], output_fx[n + 1], output_frame ); // Q11
     428             :         }
     429       26872 :         Copy32( tmp, output_fx[LFE_CHANNEL - 1], output_frame ); // Q11
     430             : 
     431             :         /* save LFE channel */
     432       26872 :         Copy32( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); // Q11
     433             :     }
     434             : 
     435       99420 :     pop_wmops();
     436       99420 :     return error;
     437             : }
     438             : 
     439             : 
     440             : /*-------------------------------------------------------------------------
     441             :  * create_mct_dec()
     442             :  *
     443             :  * Create, allocate and initialize IVAS decoder MCT handle
     444             :  *-------------------------------------------------------------------------*/
     445         916 : ivas_error create_mct_dec_fx(
     446             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
     447             : )
     448             : {
     449             :     MCT_DEC_HANDLE hMCT;
     450             :     Word16 n;
     451             :     Word32 cp_bitrate;
     452             :     Word16 max_blocks;
     453             :     Word16 cpe_id;
     454             : 
     455             :     /*---------------------------------------------------------   --------*
     456             :      * Allocate MCT handle
     457             :      *-----------------------------------------------------------------*/
     458             : 
     459         916 :     IF( ( hMCT = (MCT_DEC_HANDLE) malloc( sizeof( MCT_DEC_DATA ) ) ) == NULL )
     460             :     {
     461           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n" ) );
     462             :     }
     463             : 
     464             :     /*-----------------------------------------------------------------*
     465             :      * Allocate MCT BlockData handles
     466             :      *-----------------------------------------------------------------*/
     467             : 
     468             :     /* Determine active channels */
     469         916 :     test();
     470         916 :     test();
     471         916 :     test();
     472         916 :     test();
     473         916 :     IF( ( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     474             :     {
     475         570 :         hMCT->nchan_out_woLFE = st_ivas->nchan_transport;
     476         570 :         move16();
     477         570 :         if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     478             :         {
     479         162 :             hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->nchan_ism );
     480         162 :             move16();
     481             :         }
     482             :     }
     483         346 :     ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
     484             :     {
     485         335 :         hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe );
     486         335 :         move16();
     487             :     }
     488          11 :     ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
     489             :     {
     490          11 :         hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe );
     491          11 :         move16();
     492             :     }
     493             :     ELSE
     494             :     {
     495           0 :         assert( !"IVAS format currently not supported for MCT" );
     496             :     }
     497             : 
     498         916 :     cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, hMCT->nchan_out_woLFE ) ), 1 );
     499             : 
     500         916 :     IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     501             :     {
     502         162 :         cp_bitrate = L_shl( Mult_32_16( st_ivas->hDecoderConfig->ivas_total_brate, div_s( 1, st_ivas->nchan_transport ) ), 1 );
     503             :     }
     504             : 
     505             :     /* indicate LFE for appropriate core-coder channel */
     506        3480 :     FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
     507             :     {
     508        7692 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     509             :         {
     510        5128 :             st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
     511        5128 :             move32();
     512             :         }
     513             :     }
     514             : 
     515             :     /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */
     516         916 :     if ( hMCT->nchan_out_woLFE % 2 )
     517             :     {
     518         671 :         st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE;
     519         671 :         move32();
     520             :     }
     521             : 
     522             :     /*Initialize MCT block data */
     523         916 :     max_blocks = shr( hMCT->nchan_out_woLFE, 1 );
     524             : 
     525        2809 :     FOR( n = 0; n < max_blocks; n++ )
     526             :     {
     527        1893 :         IF( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_DEC_BLOCK_DATA ) ) ) == NULL )
     528             :         {
     529           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) );
     530             :         }
     531             : 
     532             :         /*Initialize all parameters to zero*/
     533        1893 :         hMCT->hBlockData[n]->ch1 = 0;
     534        1893 :         hMCT->hBlockData[n]->ch2 = 0;
     535        1893 :         move16();
     536        1893 :         move16();
     537             :         /*-----------------------------------------------------------------*
     538             :          * MDCT stereo initialization
     539             :          *-----------------------------------------------------------------*/
     540             : 
     541        1893 :         IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL )
     542             :         {
     543           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
     544             :         }
     545             : 
     546        1893 :         initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB );
     547        1893 :         hMCT->hBlockData[n]->hStereoMdct->use_itd = 0;
     548        1893 :         hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0;
     549        1893 :         move16();
     550        1893 :         move16();
     551        1893 :         hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; // Q26
     552        1893 :         move32();
     553             :     }
     554        4519 :     FOR( ; n < MCT_MAX_BLOCKS; n++ )
     555             :     {
     556        3603 :         hMCT->hBlockData[n] = NULL;
     557             :     }
     558             : 
     559             :     /*-----------------------------------------------------------------*
     560             :      * Initializations
     561             :      *-----------------------------------------------------------------*/
     562             : 
     563         916 :     hMCT->currBlockDataCnt = 0;
     564         916 :     move16();
     565             : 
     566             :     /*Initialize bits required to signal channel-pair index*/
     567             :     // hMCT->bitsChannelPairIndex = max( 1, (Word16) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) );
     568         916 :     hMCT->bitsChannelPairIndex = s_max( 1, add( floor_log_2( sub( shr( imult1616( hMCT->nchan_out_woLFE, sub( hMCT->nchan_out_woLFE, 1 ) ), 1 ), 1 ) ), 1 ) );
     569             : 
     570         916 :     set16_fx( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS );
     571         916 :     set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS );
     572             : 
     573         916 :     st_ivas->hMCT = hMCT;
     574             : 
     575         916 :     return IVAS_ERR_OK;
     576             : }
     577             : 
     578             : /*-------------------------------------------------------------------------
     579             :  * mct_dec_reconfigure()
     580             :  *
     581             :  * Reconfigure IVAS decoder MCT handle
     582             :  *-------------------------------------------------------------------------*/
     583             : 
     584         429 : ivas_error mct_dec_reconfigure_fx(
     585             :     Decoder_Struct *st_ivas,     /* i/o: IVAS decoder structure                  */
     586             :     const UWord16 b_nchan_change /* i  : flag indicating different channel count */
     587             : )
     588             : {
     589             :     MCT_DEC_HANDLE hMCT;
     590             :     Decoder_State *st;
     591             :     Word16 n, cpe_id, max_blocks;
     592             :     Word32 cp_bitrate, L_tmp;
     593             :     Word16 tmp_exp, tmp;
     594             : 
     595         429 :     hMCT = st_ivas->hMCT;
     596             : 
     597             :     /*-----------------------------------------------------------------*
     598             :      * Allocate and initialize MCT BlockData handles
     599             :      *-----------------------------------------------------------------*/
     600         429 :     IF( b_nchan_change )
     601             :     {
     602             :         /* Determine active channels */
     603         147 :         test();
     604         147 :         test();
     605         147 :         test();
     606         147 :         test();
     607         147 :         IF( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     608             :         {
     609         139 :             hMCT->nchan_out_woLFE = st_ivas->nchan_transport;
     610         139 :             move16();
     611         139 :             IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     612             :             {
     613          45 :                 hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->nchan_ism );
     614          45 :                 move16();
     615             :             }
     616             :         }
     617           8 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
     618             :         {
     619           7 :             hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe );
     620           7 :             move16();
     621             :         }
     622           1 :         ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
     623             :         {
     624           1 :             hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe );
     625           1 :             move16();
     626             :         }
     627             :         ELSE
     628             :         {
     629           0 :             assert( !"IVAS format currently not supported for MCT" );
     630             :         }
     631             :     }
     632             : 
     633             :     /* indicate LFE for appropriate core-coder channel */
     634        1613 :     FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
     635             :     {
     636        3552 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     637             :         {
     638        2368 :             st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
     639        2368 :             move32();
     640             :         }
     641             :     }
     642             : 
     643             :     /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */
     644         429 :     IF( hMCT->nchan_out_woLFE % 2 )
     645             :     {
     646         339 :         st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE;
     647         339 :         move32();
     648             :     }
     649             : 
     650         429 :     tmp = BASOP_Util_Divide3216_Scale( st_ivas->hDecoderConfig->ivas_total_brate, hMCT->nchan_out_woLFE, &tmp_exp );
     651         429 :     cp_bitrate = L_shl( tmp, add( tmp_exp, 2 ) );
     652             : 
     653         429 :     IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     654             :     {
     655          74 :         tmp = BASOP_Util_Divide3216_Scale( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, &tmp_exp );
     656          74 :         cp_bitrate = L_shl( tmp, add( tmp_exp, 2 ) );
     657             :     }
     658             : 
     659             :     /* set correct nominal bitrates and igf config already here, otherwise we
     660             :      * run into a number of problems */
     661        1613 :     FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
     662             :     {
     663        1184 :         st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate;
     664        1184 :         move32();
     665        3552 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
     666             :         {
     667        2368 :             st = st_ivas->hCPE[cpe_id]->hCoreCoder[n];
     668             : 
     669        2368 :             st->total_brate = st_ivas->hCPE[cpe_id]->element_brate;
     670        2368 :             move32();
     671             : 
     672        2368 :             IF( NE_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
     673             :             {
     674             :                 /* st->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[cpe_id]->element_brate / FRAMES_PER_SEC ); */
     675        2029 :                 st->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[cpe_id]->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
     676        2029 :                 move16();
     677        2029 :                 st->igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->rf_flag ); // no floating point so directly pluggable
     678        2029 :                 move16();
     679             : 
     680        2029 :                 IF( st->igf )
     681             :                 {
     682        1182 :                     IGFDecSetMode_ivas_fx( st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag );
     683             :                 }
     684             :             }
     685             :         }
     686             :     }
     687             : 
     688             :     /*Initialize MCT block data */
     689             :     /* max_blocks = hMCT->nchan_out_woLFE / 2; */
     690         429 :     max_blocks = shr( hMCT->nchan_out_woLFE, 1 );
     691             : 
     692        1274 :     FOR( n = 0; n < max_blocks; n++ )
     693             :     {
     694         845 :         IF( b_nchan_change )
     695             :         {
     696         311 :             IF( hMCT->hBlockData[n] == NULL )
     697             :             {
     698         103 :                 IF( ( hMCT->hBlockData[n] = (MCT_DEC_BLOCK_DATA_HANDLE) malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL )
     699             :                 {
     700           0 :                     return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) );
     701             :                 }
     702             : 
     703             :                 /*Initialize all parameters to zero*/
     704         103 :                 hMCT->hBlockData[n]->ch1 = 0;
     705         103 :                 move16();
     706         103 :                 hMCT->hBlockData[n]->ch2 = 0;
     707         103 :                 move16();
     708             : 
     709             :                 /* MDCT stereo initialization */
     710         103 :                 IF( ( hMCT->hBlockData[n]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL )
     711             :                 {
     712           0 :                     return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
     713             :                 }
     714             :             }
     715             :         }
     716             : 
     717         845 :         initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, st_ivas->hCPE[0]->hCoreCoder[0]->bwidth );
     718             : 
     719         845 :         hMCT->hBlockData[n]->hStereoMdct->use_itd = 0;
     720         845 :         move16();
     721             :     }
     722             : 
     723        2158 :     FOR( ; n < MCT_MAX_BLOCKS; n++ )
     724             :     {
     725             :         /* deallocate no longer needed blocks */
     726        1729 :         IF( hMCT->hBlockData[n] != NULL )
     727             :         {
     728          93 :             IF( hMCT->hBlockData[n]->hStereoMdct != NULL )
     729             :             {
     730          93 :                 free( hMCT->hBlockData[n]->hStereoMdct );
     731          93 :                 hMCT->hBlockData[n]->hStereoMdct = NULL;
     732             :             }
     733             : 
     734          93 :             free( hMCT->hBlockData[n] );
     735          93 :             hMCT->hBlockData[n] = NULL;
     736             :         }
     737             :     }
     738             : 
     739             :     /*-----------------------------------------------------------------*
     740             :      * Initializations
     741             :      *-----------------------------------------------------------------*/
     742             : 
     743         429 :     IF( b_nchan_change )
     744             :     {
     745         147 :         hMCT->currBlockDataCnt = 0;
     746         147 :         move16();
     747             : 
     748             :         /*Initialize bits required to signal channel-pair index*/
     749             : 
     750             :         Word32 log_tmp;
     751         147 :         L_tmp = L_sub( L_shr( L_mult0( hMCT->nchan_out_woLFE, sub( hMCT->nchan_out_woLFE, 1 ) ), 1 ), 1 );
     752         147 :         tmp_exp = norm_l( L_tmp );
     753         147 :         L_tmp = L_shl( L_tmp, tmp_exp );
     754         147 :         log_tmp = BASOP_Util_Log2( L_tmp );                            // ( 31 - tmp_exp )
     755         147 :         log_tmp = L_add( log_tmp, L_shl( sub( Q31, tmp_exp ), Q25 ) ); // Q25
     756             :         // scale down from Q25 to Q0
     757             : 
     758         147 :         tmp = extract_l( L_shr( log_tmp, Q25 ) );
     759         147 :         tmp = add( tmp, 1 );
     760         147 :         hMCT->bitsChannelPairIndex = s_max( 1, tmp );
     761         147 :         move16();
     762             : 
     763         147 :         set16_fx( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS );
     764         147 :         set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS );
     765             :     }
     766             : 
     767         429 :     return IVAS_ERR_OK;
     768             : }
     769             : 
     770             : 
     771             : /*-------------------------------------------------------------------------
     772             :  * create_mct_dec_close()
     773             :  *
     774             :  * Close IVAS decoder MCT handle
     775             :  *-------------------------------------------------------------------------*/
     776             : 
     777        1356 : void ivas_mct_dec_close(
     778             :     MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure       */
     779             : )
     780             : {
     781             :     Word16 n, maxBlocks;
     782             : 
     783        1356 :     test();
     784        1356 :     IF( hMCT == NULL || *hMCT == NULL )
     785             :     {
     786         440 :         return;
     787             :     }
     788             : 
     789         916 :     maxBlocks = shr( ( *hMCT )->nchan_out_woLFE, 1 );
     790             : 
     791        2819 :     FOR( n = 0; n < maxBlocks; n++ )
     792             :     {
     793        1903 :         IF( ( *hMCT )->hBlockData[n] != NULL )
     794             :         {
     795        1903 :             IF( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL )
     796             :             {
     797        1903 :                 free( ( *hMCT )->hBlockData[n]->hStereoMdct );
     798        1903 :                 ( *hMCT )->hBlockData[n]->hStereoMdct = NULL;
     799             :             }
     800             : 
     801        1903 :             free( ( *hMCT )->hBlockData[n] );
     802        1903 :             ( *hMCT )->hBlockData[n] = NULL;
     803             :         }
     804             :     }
     805             : 
     806         916 :     free( *hMCT );
     807         916 :     *hMCT = NULL;
     808             : 
     809         916 :     return;
     810             : }
     811             : 
     812             : 
     813             : /*-------------------------------------------------------------------------
     814             :  * ivas_mc_dec_config()
     815             :  *
     816             :  * - read transported MC LS setup
     817             :  * - select MC format mode
     818             :  * - reconfigure the MC format decoder
     819             :  *-------------------------------------------------------------------------*/
     820             : 
     821             : /*! r : MC format mode */
     822       48468 : ivas_error ivas_mc_dec_config_fx(
     823             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure                */
     824             :     const Word16 idx         /* i  : LS config. index                      */
     825             : #ifndef FIX_HRTF_LOAD
     826             :     ,
     827             :     UWord16 *nSamplesRendered, /* o  : samples flushed from last frame (JBM) */
     828             :     Word16 *data               /* o  : output synthesis signal                 */
     829             : #endif
     830             : )
     831             : {
     832             :     AUDIO_CONFIG signaled_config;
     833             :     MC_MODE last_mc_mode;
     834             :     ivas_error error;
     835             : 
     836             :     /* store last frame MC mode */
     837       48468 :     last_mc_mode = st_ivas->mc_mode;
     838       48468 :     move16();
     839             : 
     840       48468 :     IF( st_ivas->bfi == 0 )
     841             :     {
     842             :         /* set transported MC LS setup */
     843       48468 :         signaled_config = ivas_mc_map_ls_setup_to_output_config_fx( idx );
     844             : 
     845       48468 :         if ( st_ivas->ini_frame == 0 )
     846             :         {
     847          81 :             st_ivas->transport_config = signaled_config;
     848          81 :             move32();
     849             :         }
     850             : 
     851             :         /* select MC format mode */
     852       48468 :         st_ivas->mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate );
     853       48468 :         move32();
     854             : 
     855             :         /* MC format switching */
     856       48468 :         IF( st_ivas->ini_frame != 0 )
     857             :         {
     858       48387 :             test();
     859       48387 :             IF( NE_32( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->hDecoderConfig->ivas_total_brate ) || last_mc_mode != st_ivas->mc_mode )
     860             :             {
     861        1065 :                 IF( st_ivas->hRenderConfig )
     862             :                 {
     863        2770 :                     FOR( Word16 i = 0; i < 4; i++ )
     864             :                     {
     865        2216 :                         st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2] = shl_sat( st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2], 9 ); // Q15
     866        2216 :                         move16();
     867             :                     }
     868             :                 }
     869             : 
     870             : #ifdef FIX_HRTF_LOAD
     871        1065 :                 IF( NE_32( ( error = ivas_mc_dec_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) )
     872             : #else
     873             :                 IF( NE_32( ( error = ivas_mc_dec_reconfig_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
     874             : #endif
     875             :                 {
     876           0 :                     return error;
     877             :                 }
     878             : 
     879        1065 :                 IF( st_ivas->hRenderConfig )
     880             :                 {
     881        2770 :                     FOR( Word16 i = 0; i < 4; i++ )
     882             :                     {
     883        2216 :                         st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2] = shr( st_ivas->hRenderConfig->directivity_fx[( i * 3 ) + 2], 9 ); // Q15
     884        2216 :                         move16();
     885             :                     }
     886             :                 }
     887             :             }
     888             :         }
     889             : 
     890       48468 :         st_ivas->transport_config = signaled_config;
     891       48468 :         move32();
     892             :     }
     893             : 
     894       48468 :     return IVAS_ERR_OK;
     895             : }
     896             : 
     897             : 
     898             : /*-------------------------------------------------------------------------
     899             :  * ivas_mc_dec_reconfig()
     900             :  *
     901             :  * reconfigure the MC format decoder
     902             :  *-------------------------------------------------------------------------*/
     903             : 
     904        1065 : static ivas_error ivas_mc_dec_reconfig_fx(
     905             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
     906             : #ifndef FIX_HRTF_LOAD
     907             :     ,
     908             :     UWord16 *nSamplesRendered, /* o  : number of samples flushed from the last frame (JBM) */
     909             :     Word16 *data               /* o  : output synthesis signal                 */
     910             : #endif
     911             : )
     912             : {
     913             :     Word16 nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old;
     914             :     Word16 numCldfbAnalyses_old, numCldfbSyntheses_old;
     915             :     Word32 new_brate_SCE, new_brate_CPE, ivas_total_brate;
     916             :     RENDERER_TYPE renderer_type_old;
     917             :     Decoder_State *st;
     918             :     ivas_error error;
     919             :     MC_MODE mc_mode, last_mc_mode;
     920             :     TC_BUFFER_MODE tc_buffer_mode_new;
     921             :     Word16 tc_nchan_tc_new;
     922             :     Word16 tc_nchan_allocate_new;
     923             :     Word16 tc_granularity_new;
     924             : #ifndef FIX_HRTF_LOAD
     925             :     AUDIO_CONFIG intern_config_old;
     926             :     IVAS_OUTPUT_SETUP hIntSetupOld;
     927             : #endif
     928             :     Word16 nchan_out_buff_old, nchan_out_buff;
     929             : 
     930             : 
     931             : #ifndef FIX_HRTF_LOAD
     932             :     error = IVAS_ERR_OK;
     933             :     move32();
     934             : #endif
     935        1065 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     936        1065 :     move32();
     937        1065 :     nchan_transport_old = st_ivas->nchan_transport;
     938        1065 :     move16();
     939        1065 :     nchan_out_buff_old = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 );
     940        1065 :     last_mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */
     941             : 
     942             :     /* temporally set the current mc_mode back to the previous one to make sure the following call to
     943             :        ivas_init_dec_get_num_cldfb_instances() returns the correct counts */
     944        1065 :     mc_mode = st_ivas->mc_mode;
     945        1065 :     move32();
     946        1065 :     st_ivas->mc_mode = last_mc_mode;
     947        1065 :     move32();
     948        1065 :     ivas_init_dec_get_num_cldfb_instances_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
     949             : 
     950        1065 :     st_ivas->mc_mode = mc_mode;
     951        1065 :     move32();
     952             : 
     953        1065 :     nSCE_old = st_ivas->nSCE;
     954        1065 :     move16();
     955        1065 :     nCPE_old = st_ivas->nCPE;
     956        1065 :     move16();
     957        1065 :     sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag;
     958        1065 :     move16();
     959             : 
     960             :     /* special handling needed for the hp20 buffers for McMASA */
     961        1065 :     IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) )
     962             :     {
     963         274 :         nchan_hp20_old = getNumChanSynthesis( st_ivas );
     964             :     }
     965             :     ELSE
     966             :     {
     967         791 :         nchan_hp20_old = nchan_transport_old;
     968         791 :         move16();
     969             :     }
     970        1065 :     st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
     971        1065 :     move16();
     972             : 
     973             : #ifndef FIX_HRTF_LOAD
     974             :     /* save old IntSetup, might be needed for JBM flushing...*/
     975             :     intern_config_old = st_ivas->intern_config;
     976             :     move32();
     977             :     hIntSetupOld = st_ivas->hIntSetup;
     978             :     tc_granularity_new = 1;
     979             :     move16();
     980             : #endif
     981             :     /* renderer might have changed, reselect */
     982        1065 :     renderer_type_old = st_ivas->renderer_type;
     983        1065 :     move32();
     984        1065 :     ivas_renderer_select( st_ivas );
     985             : 
     986             :     /* side effect of the renderer selection can be a changed internal config */
     987        1065 :     ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
     988             : 
     989             :     /* transfer subframe info from DirAC or ParamMC to central tc buffer */
     990             : 
     991        1065 :     if ( st_ivas->hTcBuffer->tc_buffer_mode != TC_BUFFER_MODE_BUFFER )
     992             :     {
     993        1031 :         test();
     994        1031 :         IF( EQ_16( last_mc_mode, MC_MODE_PARAMMC ) )
     995             :         {
     996         331 :             st_ivas->hTcBuffer->nb_subframes = st_ivas->hParamMC->nb_subframes;
     997         331 :             move16();
     998         331 :             st_ivas->hTcBuffer->subframes_rendered = st_ivas->hParamMC->subframes_rendered;
     999         331 :             move16();
    1000         331 :             st_ivas->hTcBuffer->num_slots = st_ivas->hParamMC->num_slots;
    1001         331 :             move16();
    1002         331 :             st_ivas->hTcBuffer->slots_rendered = st_ivas->hParamMC->slots_rendered;
    1003         331 :             move16();
    1004         331 :             Copy( st_ivas->hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
    1005             :         }
    1006         700 :         ELSE IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) && st_ivas->hSpatParamRendCom != NULL )
    1007             :         {
    1008         265 :             st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes;
    1009         265 :             move16();
    1010         265 :             st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered;
    1011         265 :             move16();
    1012         265 :             st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots;
    1013         265 :             move16();
    1014         265 :             st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered;
    1015         265 :             move16();
    1016         265 :             Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
    1017             :         }
    1018             :     }
    1019             : 
    1020             :     /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv
    1021             :                     render what still fits in the new granularity */
    1022        1065 :     tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs );
    1023        1065 :     move16();
    1024        1065 :     IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ){
    1025             : #ifdef FIX_HRTF_LOAD
    1026             :     /* flush already done in IVAS_DEC_ReadFormat() */
    1027             : #else
    1028             :         IF( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ), IVAS_ERR_OK ) ){
    1029             :             return error;
    1030             : }
    1031             : #endif
    1032             :     }
    1033             :     /* JBM: when granularity goes up set samples to discard at the beginning of the frame */
    1034             :     ELSE
    1035         908 :     IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
    1036             :     {
    1037         162 :         IF( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) )
    1038             :         {
    1039           0 :             return error;
    1040             :         }
    1041             :     }
    1042        1065 :     IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
    1043             :     {
    1044         465 :         st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ) );
    1045         465 :         move16();
    1046         465 :         st_ivas->nSCE = 0;
    1047         465 :         move16();
    1048         465 :         st_ivas->nCPE = shr( st_ivas->nchan_transport, 1 );
    1049         465 :         move16();
    1050             : 
    1051         465 :         IF( NE_16( last_mc_mode, MC_MODE_MCT ) )
    1052             :         {
    1053             :             /*De-allocate handles for other MC modes*/
    1054         306 :             IF( st_ivas->hParamMC != NULL )
    1055             :             {
    1056         173 :                 ivas_param_mc_dec_close_fx( &st_ivas->hParamMC );
    1057             : 
    1058             :                 /* remove ls conversion if it was allocated by ParamMC */
    1059         173 :                 ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
    1060             :             }
    1061             : 
    1062         306 :             IF( EQ_16( last_mc_mode, MC_MODE_PARAMUPMIX ) )
    1063             :             {
    1064           3 :                 ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) );
    1065           3 :                 ivas_ls_setup_conversion_close_fx( &( st_ivas->hLsSetUpConversion ) );
    1066             :             }
    1067             : 
    1068             :             /* De-allocate McMasa-related handles */
    1069         306 :             ivas_masa_dec_close_fx( &( st_ivas->hMasa ) );
    1070             : 
    1071         306 :             ivas_qmetadata_close_fx( &st_ivas->hQMetaData );
    1072             : #ifndef NONBE_FIX_1220_OMASA_JBM_EXT_USAN
    1073             :             IF( st_ivas->hDirAC != NULL )
    1074             :             {
    1075             : #endif
    1076         306 :                 ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) );
    1077         306 :                 ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) );
    1078         306 :                 ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) );
    1079         306 :                 vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
    1080             : #ifndef NONBE_FIX_1220_OMASA_JBM_EXT_USAN
    1081             :             }
    1082             : #endif
    1083             : 
    1084             :             /* init LS conversion if the renderer type asks for it */
    1085         306 :             test();
    1086         306 :             IF( EQ_16( st_ivas->renderer_type, RENDERER_MC ) && st_ivas->hLsSetUpConversion == NULL )
    1087             :             {
    1088          62 :                 IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
    1089             :                 {
    1090           0 :                     return error;
    1091             :                 }
    1092             :             }
    1093             :         }
    1094             :     }
    1095         600 :     ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
    1096             :     {
    1097           7 :         st_ivas->nSCE = 0;
    1098           7 :         move16();
    1099           7 :         st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2;
    1100           7 :         move16();
    1101           7 :         st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
    1102           7 :         move16();
    1103             : 
    1104           7 :         IF( NE_16( last_mc_mode, MC_MODE_PARAMUPMIX ) )
    1105             :         {
    1106             :             /*De-allocate handles for other MC modes*/
    1107           7 :             IF( st_ivas->hParamMC != NULL )
    1108             :             {
    1109           1 :                 ivas_param_mc_dec_close_fx( &st_ivas->hParamMC );
    1110             : 
    1111             :                 /* remove ls conversion if it was allocated by ParamMC */
    1112           1 :                 ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
    1113             :             }
    1114             : 
    1115           7 :             ivas_masa_dec_close_fx( &( st_ivas->hMasa ) );
    1116           7 :             ivas_qmetadata_close_fx( &st_ivas->hQMetaData );
    1117             : 
    1118             :             /* init LS conversion if the renderer type asks for it */
    1119           7 :             test();
    1120           7 :             IF( ( EQ_16( st_ivas->renderer_type, RENDERER_MC ) ) && st_ivas->hLsSetUpConversion == NULL )
    1121             :             {
    1122           1 :                 IF( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK )
    1123             :                 {
    1124           0 :                     return error;
    1125             :                 }
    1126             :             }
    1127             : 
    1128           7 :             IF( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK )
    1129             :             {
    1130           0 :                 return error;
    1131             :             }
    1132             :         }
    1133             :     }
    1134         593 :     ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
    1135             :     {
    1136         334 :         IF( NE_16( last_mc_mode, MC_MODE_PARAMMC ) )
    1137             :         {
    1138             :             /* remove old ls conversion for MCT if open, gets reopened correctly within ivas_param_mc_dec_open when needed */
    1139         269 :             test();
    1140         269 :             IF( EQ_16( renderer_type_old, RENDERER_MC ) && st_ivas->hLsSetUpConversion != NULL )
    1141             :             {
    1142          37 :                 ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
    1143             :             }
    1144             : 
    1145         269 :             IF( NE_32( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
    1146             :             {
    1147           0 :                 return error;
    1148             :             }
    1149             :         }
    1150             :         ELSE
    1151             :         {
    1152          65 :             IF( NE_32( ( error = ivas_param_mc_dec_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) )
    1153             :             {
    1154           0 :                 return error;
    1155             :             }
    1156             :         }
    1157             : 
    1158             :         /* De-allocate McMasa-related handles */
    1159         334 :         ivas_masa_dec_close_fx( &( st_ivas->hMasa ) );
    1160         334 :         ivas_qmetadata_close_fx( &st_ivas->hQMetaData );
    1161             : 
    1162             : #ifndef NONBE_FIX_1220_OMASA_JBM_EXT_USAN
    1163             :         IF( st_ivas->hDirAC != NULL )
    1164             :         {
    1165             : #endif
    1166         334 :             ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) );
    1167         334 :             ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) );
    1168         334 :             ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) );
    1169         334 :             vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
    1170             : #ifndef NONBE_FIX_1220_OMASA_JBM_EXT_USAN
    1171             :         }
    1172             : #endif
    1173             : 
    1174         334 :         IF( EQ_16( last_mc_mode, MC_MODE_MCT ) )
    1175             :         {
    1176         175 :             test();
    1177         175 :             IF( st_ivas->hMCT != NULL && LE_16( st_ivas->nchan_transport, CPE_CHANNELS ) )
    1178             :             {
    1179         170 :                 ivas_mct_dec_close( &st_ivas->hMCT );
    1180             :             }
    1181             :         }
    1182         159 :         ELSE IF( EQ_16( last_mc_mode, MC_MODE_PARAMUPMIX ) )
    1183             :         {
    1184           0 :             ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) );
    1185             :         }
    1186             : 
    1187             :         /* LFE handle */
    1188         334 :         ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) );
    1189             :     }
    1190         259 :     ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
    1191             :     {
    1192         259 :         ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate );
    1193             : 
    1194         259 :         IF( NE_16( last_mc_mode, MC_MODE_MCMASA ) )
    1195             :         {
    1196         215 :             IF( NE_32( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) )
    1197             :             {
    1198           0 :                 return error;
    1199             :             }
    1200             :         }
    1201             : 
    1202         259 :         IF( NE_32( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ), IVAS_ERR_OK ) )
    1203             :         {
    1204           0 :             return error;
    1205             :         }
    1206             : 
    1207             :         /* LS conversion */
    1208         259 :         IF( st_ivas->hLsSetUpConversion != NULL )
    1209             :         {
    1210          41 :             ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
    1211             :         }
    1212             : 
    1213         259 :         ivas_mc_paramupmix_dec_close( &( st_ivas->hMCParamUpmix ) );
    1214             : 
    1215         259 :         IF( st_ivas->hParamMC != NULL )
    1216             :         {
    1217          94 :             ivas_param_mc_dec_close_fx( &st_ivas->hParamMC );
    1218          94 :             st_ivas->hParamMC = NULL;
    1219             :         }
    1220             : 
    1221         259 :         IF( EQ_16( last_mc_mode, MC_MODE_MCT ) )
    1222             :         {
    1223         121 :             ivas_mct_dec_close( &st_ivas->hMCT );
    1224             :         }
    1225             : 
    1226             :         /* LFE handle */
    1227         259 :         ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) );
    1228             :     }
    1229             : 
    1230        1065 :     IF( NE_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
    1231             :     {
    1232         806 :         IF( EQ_16( st_ivas->nchan_transport, 1 ) )
    1233             :         {
    1234           0 :             st_ivas->element_mode_init = IVAS_SCE;
    1235             :         }
    1236             :         ELSE
    1237             :         {
    1238         806 :             st_ivas->element_mode_init = IVAS_CPE_MDCT;
    1239             :         }
    1240         806 :         move16();
    1241             :     }
    1242             : 
    1243             :     /*-----------------------------------------------------------------*
    1244             :      * Reconfigure core coder
    1245             :      *-----------------------------------------------------------------*/
    1246             : 
    1247             :     /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1
    1248             :            and might have IGF static memory not allocated and the bit stream index list not set,
    1249             :            set correct mct_chan_mode and init missing static mem (IGF, HQ)  and some config (TNS)  do it here since it is _very_ MC specific */
    1250        1065 :     test();
    1251        1065 :     test();
    1252        1065 :     IF( EQ_16( last_mc_mode, MC_MODE_MCT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && GT_16( st_ivas->nchan_transport, CPE_CHANNELS ) )
    1253             :     {
    1254           5 :         st = st_ivas->hCPE[1]->hCoreCoder[1];
    1255             : 
    1256           5 :         IF( EQ_16( st_ivas->nchan_transport, 3 ) )
    1257             :         {
    1258           5 :             st->mct_chan_mode = MCT_CHAN_MODE_IGNORE;
    1259             :         }
    1260             :         ELSE
    1261             :         {
    1262           0 :             st->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
    1263             :         }
    1264           5 :         move32();
    1265             : 
    1266           5 :         IF( st->hIGFDec == NULL )
    1267             :         {
    1268           0 :             IF( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL )
    1269             :             {
    1270           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) );
    1271             :             }
    1272             : 
    1273           0 :             st->igf = 0;
    1274           0 :             move16();
    1275           0 :             init_igf_dec( st->hIGFDec );
    1276             :         }
    1277             : 
    1278           5 :         IF( st->hHQ_core == NULL )
    1279             :         {
    1280           0 :             IF( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL )
    1281             :             {
    1282           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) );
    1283             :             }
    1284             : 
    1285             :             /* HQ core initialization */
    1286           0 :             HQ_core_dec_init_fx( st->hHQ_core );
    1287             :         }
    1288             : 
    1289             :         /* check if we have a doubly used hTxcCfg, if so, allocate a distint one for the old MCT LFE channel */
    1290           5 :         IF( st->hTcxCfg == st_ivas->hCPE[1]->hCoreCoder[0]->hTcxCfg )
    1291             :         {
    1292           0 :             IF( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL )
    1293             :             {
    1294           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) );
    1295             :             }
    1296             :         }
    1297             : 
    1298           5 :         st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( ivas_total_brate, st->igf, st->element_mode );
    1299           5 :         move16();
    1300             :     }
    1301        1065 :     IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
    1302             :     {
    1303             :         UWord8 separateChannelEnabled;
    1304             :         Word16 separateChannelIndex;
    1305         259 :         ivas_mcmasa_set_separate_channel_mode_fx( &separateChannelEnabled, &separateChannelIndex, ivas_total_brate );
    1306         259 :         ivas_mcmasa_split_brate_fx( separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE );
    1307             :     }
    1308         806 :     ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
    1309             :     {
    1310         465 :         new_brate_SCE = 0;
    1311         465 :         move32();
    1312             :         Word16 temp_e;
    1313         465 :         Word32 L_temp = BASOP_Util_Divide3232_Scale_newton( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &temp_e );
    1314         465 :         L_temp = L_shr( L_temp, sub( 31, temp_e ) );
    1315         465 :         new_brate_CPE = L_shl( L_temp, 1 ) /*CPE_CHANNELS*/;
    1316             :     }
    1317         341 :     ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
    1318             :     {
    1319           7 :         new_brate_SCE = 0;
    1320           7 :         move32();
    1321             :         Word16 temp_e;
    1322           7 :         Word32 L_temp = BASOP_Util_Divide3232_Scale_newton( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &temp_e );
    1323           7 :         L_temp = L_shr( L_temp, sub( 31, temp_e ) );
    1324           7 :         new_brate_CPE = L_shl( L_temp, 1 ) /*CPE_CHANNELS*/;
    1325             :     }
    1326             :     ELSE
    1327             :     {
    1328         334 :         new_brate_SCE = 0; /* ivas_total_brate / st_ivas->nchan_transport;*/
    1329         334 :         move32();
    1330             :         Word16 temp_e;
    1331         334 :         Word32 L_temp = BASOP_Util_Divide3232_Scale_newton( ivas_total_brate, st_ivas->nchan_transport, &temp_e );
    1332         334 :         L_temp = L_shr( L_temp, sub( 31, temp_e ) );
    1333         334 :         new_brate_CPE = L_shl( L_temp, 1 ) /*CPE_CHANNELS*/;
    1334             :     }
    1335             : 
    1336        1065 :     test();
    1337        1065 :     test();
    1338        1065 :     IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ), IVAS_ERR_OK ) )
    1339             :     {
    1340           0 :         return error;
    1341             :     }
    1342        1065 :     IF( EQ_16( last_mc_mode, MC_MODE_MCT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && GT_16( st_ivas->nchan_transport, CPE_CHANNELS ) )
    1343             :     {
    1344           5 :         st = st_ivas->hCPE[1]->hCoreCoder[1];
    1345             : 
    1346             :         /* TCX-LTP */
    1347           5 :         IF( st->hTcxLtpDec == NULL )
    1348             :         {
    1349           0 :             IF( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL )
    1350             :             {
    1351           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) );
    1352             :             }
    1353           0 :             tcxltp_dec_init_fx( st->hTcxLtpDec, 0, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core );
    1354             :         }
    1355             :     }
    1356             : 
    1357             :     /*-----------------------------------------------------------------*
    1358             :      * re-configure HP20 memories
    1359             :      *-----------------------------------------------------------------*/
    1360        1065 :     IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ), IVAS_ERR_OK ) )
    1361             :     {
    1362           0 :         return error;
    1363             :     }
    1364             : 
    1365             : 
    1366             :     /*-----------------------------------------------------------------*
    1367             :      * Reconfigure renderers
    1368             :      *-----------------------------------------------------------------*/
    1369             : 
    1370        1065 :     IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
    1371             :     {
    1372         259 :         test();
    1373             : #ifndef NONBE_FIX_1220_OMASA_JBM_EXT_USAN
    1374             :         test();
    1375             : #endif
    1376         259 :         IF( ( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) && ( NE_16( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) )
    1377             :         {
    1378         251 :             IF( st_ivas->hDirAC != NULL )
    1379             :             {
    1380             :                 /* reconfigure existing DirAC dec */
    1381         251 :                 IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) )
    1382             :                 {
    1383           0 :                     return error;
    1384             :                 }
    1385             :             }
    1386             :             ELSE
    1387             :             {
    1388             :                 /* init a new DirAC dec */
    1389           0 :                 IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) )
    1390             :                 {
    1391           0 :                     return error;
    1392             :                 }
    1393             :             }
    1394             :         }
    1395             : #ifdef NONBE_FIX_1220_OMASA_JBM_EXT_USAN
    1396           8 :         ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) )
    1397             : #else
    1398             :     ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->hDirAC != NULL )
    1399             : #endif
    1400             :         {
    1401           3 :             ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) );
    1402           3 :             ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) );
    1403           3 :             ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) );
    1404           3 :             vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
    1405             :         }
    1406             :     }
    1407             : 
    1408        1065 :     IF( NE_16( renderer_type_old, st_ivas->renderer_type ) )
    1409             :     {
    1410             :         AUDIO_CONFIG output_config;
    1411             : 
    1412         628 :         output_config = st_ivas->hDecoderConfig->output_config;
    1413         628 :         move32();
    1414             : 
    1415             :         /* binaural renderers*/
    1416         628 :         test();
    1417         628 :         test();
    1418         628 :         test();
    1419         628 :         test();
    1420         628 :         test();
    1421         628 :         test();
    1422         628 :         test();
    1423         628 :         test();
    1424         628 :         IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    1425             :         {
    1426             :             /* remove unneeded binaural renderers */
    1427         419 :             test();
    1428         419 :             test();
    1429         419 :             IF( st_ivas->hBinRenderer != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
    1430             :             {
    1431         143 :                 ivas_binRenderer_close_fx( &st_ivas->hBinRenderer );
    1432         143 :                 test();
    1433         143 :                 IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
    1434             :                 {
    1435           7 :                     efap_free_data_fx( &st_ivas->hEFAPdata );
    1436             :                 }
    1437             :             }
    1438             : 
    1439         419 :             test();
    1440         419 :             test();
    1441         419 :             test();
    1442         419 :             test();
    1443         419 :             test();
    1444         419 :             IF( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hCrend[0] != NULL ) && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || NE_16( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) )
    1445             :             {
    1446             : #ifdef FIX_CREND_SIMPLIFY_CODE
    1447         151 :                 ivas_rend_closeCrend_fx( &( st_ivas->hCrendWrapper ) );
    1448             : #else
    1449             :             ivas_rend_closeCrend_fx( &( st_ivas->hCrendWrapper ), ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses );
    1450             : #endif
    1451             :             }
    1452             : 
    1453         419 :             test();
    1454         419 :             IF( st_ivas->hBinRendererTd != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) )
    1455             :             {
    1456           6 :                 ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd );
    1457             :             }
    1458             : 
    1459         419 :             IF( st_ivas->hDiracDecBin[0] != NULL )
    1460             :             {
    1461         231 :                 test();
    1462         231 :                 test();
    1463         231 :                 IF( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
    1464             :                 {
    1465         119 :                     ivas_dirac_dec_close_binaural_data_fx( st_ivas->hDiracDecBin );
    1466             :                 }
    1467             :             }
    1468             : 
    1469             :             /* init necessary new renderers */
    1470         419 :             test();
    1471         419 :             test();
    1472         419 :             test();
    1473         419 :             test();
    1474         419 :             test();
    1475         419 :             IF( st_ivas->hBinRenderer == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
    1476             :             {
    1477         145 :                 IF( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK )
    1478             :                 {
    1479           0 :                     return error;
    1480             :                 }
    1481             :             }
    1482         274 :             ELSE IF( st_ivas->hBinRendererTd == NULL && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
    1483           8 :             {
    1484             :                 Word16 num_src;
    1485             :                 Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
    1486             : 
    1487           8 :                 IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK )
    1488             :                 {
    1489           0 :                     return error;
    1490             :                 }
    1491           8 :                 IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
    1492             :                 {
    1493           4 :                     IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) )
    1494             :                     {
    1495           0 :                         return error;
    1496             :                     }
    1497             :                 }
    1498           8 :                 IF( EQ_16( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
    1499             :                 {
    1500           0 :                     IF( ( error = ivas_rend_initCrendWrapper_fx( &st_ivas->hCrendWrapper, 1 ) ) != IVAS_ERR_OK )
    1501             :                     {
    1502           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" );
    1503             :                     }
    1504             : 
    1505           0 :                     st_ivas->hCrendWrapper->hCrend[0] = NULL;
    1506           0 :                     st_ivas->hCrendWrapper->hHrtfCrend = NULL;
    1507           0 :                     IF( ( st_ivas->hCrendWrapper->hCrend[0] = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL )
    1508             :                     {
    1509           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" );
    1510             :                     }
    1511             :                 }
    1512             :             }
    1513         266 :             ELSE IF( st_ivas->hCrendWrapper == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) )
    1514             :             {
    1515             : #ifdef FIX_CREND_SIMPLIFY_CODE
    1516         154 :                 IF( ( error = ivas_rend_openCrend_fx( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hHrtfCrend, st_ivas->hHrtfStatistics, st_ivas->hDecoderConfig->output_Fs, 0, ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ) ) != IVAS_ERR_OK )
    1517             : #else
    1518             :             IF( ( error = ivas_rend_openCrend_fx( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hHrtfStatistics, st_ivas->hDecoderConfig->output_Fs, ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ) ) != IVAS_ERR_OK )
    1519             : #endif
    1520             :                 {
    1521           0 :                     return error;
    1522             :                 }
    1523         154 :                 st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns;
    1524         154 :                 move32();
    1525             :             }
    1526             :         }
    1527             :     }
    1528             :     /*-----------------------------------------------------------------*
    1529             :      * CLDFB instances
    1530             :      *-----------------------------------------------------------------*/
    1531             : 
    1532        1065 :     IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) )
    1533             :     {
    1534           0 :         return error;
    1535             :     }
    1536             : 
    1537             :     /*-----------------------------------------------------------------*
    1538             :      * Allocate the LFE handle that is coded separately after the allocation of the core coders
    1539             :      *-----------------------------------------------------------------*/
    1540        1065 :     test();
    1541        1065 :     IF( ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) )
    1542             :     {
    1543             :         Word32 delay_ns;
    1544         472 :         IF( NE_16( st_ivas->hIntSetup.index_lfe[0], -1 ) )
    1545             :         {
    1546         472 :             delay_ns = st_ivas->binaural_latency_ns;
    1547             :         }
    1548             :         ELSE
    1549             :         {
    1550           0 :             delay_ns = 0;
    1551             :         }
    1552         472 :         move32();
    1553         472 :         IF( st_ivas->hBinRenderer != NULL )
    1554             :         {
    1555           2 :             IF( st_ivas->hBinRenderer->render_lfe )
    1556             :             {
    1557             :                 /* Account for filterbank delay */
    1558           2 :                 delay_ns = L_add( delay_ns, IVAS_FB_DEC_DELAY_NS );
    1559             :             }
    1560             :             ELSE
    1561             :             {
    1562           0 :                 delay_ns = 0;
    1563           0 :                 move32();
    1564             :             }
    1565             :         }
    1566             :         ELSE
    1567             :         {
    1568         470 :             IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) && ( st_ivas->cldfbSynDec[0] != NULL ) )
    1569             :             {
    1570           4 :                 delay_ns = L_add( delay_ns, IVAS_FB_DEC_DELAY_NS );
    1571             :             }
    1572             :         }
    1573             : 
    1574         472 :         IF( st_ivas->hLFE != NULL )
    1575             :         {
    1576         162 :             IF( NE_32( st_ivas->hLFE->delay_ns, delay_ns ) )
    1577             :             {
    1578           3 :                 ivas_lfe_dec_close_fx( &( st_ivas->hLFE ) );
    1579             :             }
    1580             :         }
    1581             : 
    1582         472 :         IF( st_ivas->hLFE == NULL )
    1583             :         {
    1584         313 :             IF( NE_32( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, st_ivas->hDecoderConfig->output_Fs, delay_ns ) ), IVAS_ERR_OK ) )
    1585             :             {
    1586           0 :                 return error;
    1587             :             }
    1588             : 
    1589         313 :             set32_fx( st_ivas->hLFE->prevsynth_buf_fx, 0, LFE_PLC_BUFLEN );
    1590         313 :             set32_fx( st_ivas->hLFE->prior_out_buffer_fx, 0, L_FRAME48k );
    1591             :         }
    1592             :     }
    1593             : 
    1594             :     /*-----------------------------------------------------------------*
    1595             :      * JBM TC buffers
    1596             :      *-----------------------------------------------------------------*/
    1597             : 
    1598             :     {
    1599             :         Word16 tc_nchan_full_new;
    1600             :         DECODER_TC_BUFFER_HANDLE hTcBuffer;
    1601             : 
    1602        1065 :         hTcBuffer = st_ivas->hTcBuffer;
    1603        1065 :         tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas );
    1604        1065 :         tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
    1605        1065 :         tc_nchan_allocate_new = tc_nchan_tc_new;
    1606        1065 :         move16();
    1607        1065 :         tc_nchan_full_new = tc_nchan_tc_new;
    1608        1065 :         move16();
    1609             : 
    1610        1065 :         test();
    1611        1065 :         test();
    1612        1065 :         IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
    1613             :         {
    1614         127 :             tc_nchan_allocate_new = BINAURAL_CHANNELS * 2;
    1615         127 :             move16();
    1616         127 :             tc_nchan_full_new = tc_nchan_allocate_new;
    1617         127 :             move16();
    1618             :         }
    1619             : 
    1620        1065 :         test();
    1621        1065 :         test();
    1622        1065 :         IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) )
    1623             :         {
    1624         332 :             tc_nchan_full_new = 0;
    1625         332 :             move16();
    1626             :         }
    1627         733 :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
    1628             :         {
    1629           7 :             tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS;
    1630           7 :             move16();
    1631           7 :             tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER;
    1632           7 :             move32();
    1633           7 :             test();
    1634           7 :             IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
    1635             :             {
    1636           1 :                 tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER;
    1637           1 :                 move32();
    1638           1 :                 tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out;
    1639           1 :                 move16();
    1640           1 :                 tc_nchan_allocate_new = tc_nchan_tc_new;
    1641           1 :                 move16();
    1642             :             }
    1643           7 :             tc_nchan_full_new = tc_nchan_allocate_new;
    1644           7 :             move16();
    1645             :         }
    1646             : 
    1647             :         /* reconfigure buffer */
    1648        1065 :         test();
    1649        1065 :         test();
    1650        1065 :         test();
    1651        1065 :         test();
    1652        1065 :         IF( NE_16( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) ||
    1653             :             NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) ||
    1654             :             NE_16( tc_granularity_new, hTcBuffer->n_samples_granularity ) )
    1655             :         {
    1656         822 :             IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ), IVAS_ERR_OK ) )
    1657             :             {
    1658           0 :                 return error;
    1659             :             }
    1660             :         }
    1661             :         /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */
    1662        1065 :         IF( st_ivas->hSpatParamRendCom != NULL )
    1663             :         {
    1664         257 :             st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
    1665         257 :             move16();
    1666         257 :             st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
    1667         257 :             move16();
    1668         257 :             st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots;
    1669         257 :             move16();
    1670         257 :             st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered;
    1671         257 :             move16();
    1672         257 :             Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
    1673             :         }
    1674         808 :         ELSE IF( st_ivas->hParamMC != NULL )
    1675             :         {
    1676         334 :             st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
    1677         334 :             move16();
    1678         334 :             st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
    1679         334 :             move16();
    1680         334 :             st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots;
    1681         334 :             move16();
    1682         334 :             st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered;
    1683         334 :             move16();
    1684         334 :             Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
    1685             :         }
    1686             :     }
    1687             : 
    1688             : 
    1689             :     /*-----------------------------------------------------------------*
    1690             :      * floating-point output audio buffers
    1691             :      *-----------------------------------------------------------------*/
    1692             : 
    1693        1065 :     nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 );
    1694             : 
    1695        1065 :     IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) )
    1696             :     {
    1697           0 :         return error;
    1698             :     }
    1699             : 
    1700             : #ifdef FIX_HRTF_LOAD
    1701        1065 :     return IVAS_ERR_OK;
    1702             : #else
    1703             : return error;
    1704             : #endif
    1705             : }

Generated by: LCOV version 1.14