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

Generated by: LCOV version 1.14