LCOV - code coverage report
Current view: top level - lib_dec - ivas_mc_param_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 1537 1680 91.5 %
Date: 2025-08-23 01:22:27 Functions: 22 22 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 "options.h"
      35             : #include <stdint.h>
      36             : #include "cnst.h"
      37             : #include "rom_enc.h"
      38             : #include "rom_com.h"
      39             : #include "prot_fx.h"
      40             : #include "ivas_prot_rend_fx.h"
      41             : #include "ivas_cnst.h"
      42             : #include "ivas_rom_com.h"
      43             : #include "ivas_rom_dec.h"
      44             : #include "math.h"
      45             : #include "wmc_auto.h"
      46             : #include "rom_dec.h"
      47             : #include "ivas_prot_fx.h"
      48             : 
      49             : #define INV_EPSILON_MANT 214748365
      50             : 
      51             : /*-----------------------------------------------------------------------*
      52             :  * Local constants
      53             :  *-----------------------------------------------------------------------*/
      54             : 
      55             : #define PARAM_MC_LOCAL_SZ_LFE_MAP 5
      56             : 
      57             : /*-----------------------------------------------------------------------*
      58             :  * Local typedefs
      59             :  *-----------------------------------------------------------------------*/
      60             : 
      61             : typedef struct parameter_band_mapping_struct
      62             : {
      63             :     Word16 n_source_bands[20];
      64             :     Word16 source_band_idx[20][4];
      65             :     Word16 source_band_factor_fx[20][4]; /*Q15*/
      66             : 
      67             : } PARAM_MC_PARAMETER_BAND_MAPPING;
      68             : 
      69             : /*-----------------------------------------------------------------------*
      70             :  * Local function prototypes
      71             :  *-----------------------------------------------------------------------*/
      72             : 
      73             : static void ivas_param_mc_dec_init_fx( PARAM_MC_DEC_HANDLE hParamMC, const Word16 nchan_in, const Word16 nchan_out );
      74             : 
      75             : static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 nY, const Word16 slot_idx );
      76             : static Word16 ivas_param_mc_range_decoder_LC_fx( UWord16 *bit_buffer, Word16 *x, Word16 *BER_detect, const Word16 sz_seq, const Word16 sz_alphabet, const UWord16 *cft, const UWord16 *sft, const Word16 tot_shift, const Word16 nbbits );
      77             : 
      78             : 
      79             : static void ivas_param_mc_get_mixing_matrices_fx(
      80             :     PARAM_MC_DEC_HANDLE hParamMC, /* i  : Parametric MC handle */
      81             :     IVAS_OUTPUT_SETUP *hSynthesisOutputSetup,
      82             :     Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i  : input covariance for all parameter bands         */
      83             :     Word16 Cx_in_e,
      84             :     const Word16 param_band_idx,
      85             :     Word32 *mixing_matrix_fx[],
      86             :     Word16 *mixing_matrix_e,
      87             :     Word32 *mixing_matrix_res_fx[],
      88             :     Word16 *mixing_matrix_res_e,
      89             :     const Word16 nY_intern,                     /* i  : number of channels in the transported format     */
      90             :     const PARAM_MC_SYNTHESIS_CONF synth_config, /* i  : Parametric MC synthesis config                   */
      91             :     const Word16 nX,                            /* i  : number of transport channels                     */
      92             :     const Word16 nY_cov                         /* i  : number of covariance synthesis output channels   */
      93             : );
      94             : 
      95             : static Word16 ivas_param_mc_uniform_decoder_fx( Word16 *seq, const Word16 sz_seq, const Word16 *alphabet, const Word16 N, UWord16 bit_buffer[PARAM_MC_MAX_BITS] );
      96             : static void ivas_param_mc_dec_compute_interpolator_fx( const UWord16 bAttackPresent, const UWord16 attackPos, const UWord16 interp_length, Word16 *interpolator );
      97             : 
      98             : static void param_mc_set_num_synth_bands( const Word32 output_Fs, PARAM_MC_DEC_HANDLE hParamMC );
      99             : 
     100             : static void ivas_param_mc_get_param_band_mapping( const Word16 n_target_bands, const Word16 *target_band_grouping, const Word16 n_source_bands, const Word16 *source_band_grouping, PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping );
     101             : 
     102             : 
     103             : static void ivas_param_mc_bs_decode_parameter_values_fx( UWord16 bit_buffer[], Word16 *bit_pos, const Word16 max_bits, Word16 *BER_detect, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, const Word16 map_size_wo_lfe, const Word16 map_size, const Word16 num_lfe_bands, const Word16 band_step, const Word16 num_param_bands, Word16 *value_buffer );
     104             : static void ivas_param_mc_dequantize_cov_fx( PARAM_MC_DEC_HANDLE hParamMC, Word16 *ild_q_fx, Word16 *icc_q_fx, const Word16 param_band_index, const Word16 nY_cov, const PARAM_MC_SYNTHESIS_CONF synth_conf, const Word16 nY_int, const Word16 nX, Word32 *Cx_state_fx, Word16 Cx_state_e, Word32 *Cproto_fx, Word16 Cproto_e, Word32 *Cy_state_fx, Word16 *Cy_state_e );
     105             : static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, Word16 Q_proto_mtx );
     106             : static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Word32 *mixing_matrix[], Word16 *mixing_matrix_fx, Word32 *mixing_matrix_res[], Word16 *mixing_matrix_res_exp, const UWord16 nX, const UWord16 nY );
     107             : 
     108             : 
     109             : static void param_mc_protoSignalComputation_fx( Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const Word16 num_freq_bands, const Word16 Cldfb_Real_Imag_exp, Word16 *proto_frame_f_fx_q /* Word16 ImagBuffer_fx_e, Word16 *common_e*/ );
     110             : 
     111             : /*-------------------------------------------------------------------------
     112             :  * ivas_param_mc_dec_open()
     113             :  *
     114             :  * Open Parametric MC decoder handle
     115             :  *-------------------------------------------------------------------------*/
     116             : 
     117         279 : ivas_error ivas_param_mc_dec_open_fx(
     118             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
     119             : )
     120             : {
     121             :     Word16 k, nchan_transport;
     122             :     PARAM_MC_DEC_HANDLE hParamMC;
     123             :     Word16 nchan_out_transport;
     124             :     Word16 nchan_out_cov;
     125             :     Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
     126             :     Word32 proto_mtx_norm_fx, tmp32;
     127             :     Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
     128             :     Word16 max_param_band_residual;
     129             :     UWord16 config_index;
     130             :     MC_LS_SETUP mc_ls_setup;
     131             :     AUDIO_CONFIG output_config;
     132             :     Word32 output_Fs, ivas_total_brate;
     133             :     ivas_error error;
     134             : 
     135         279 :     error = IVAS_ERR_OK;
     136         279 :     move32();
     137             : 
     138             :     /*-----------------------------------------------------------------*
     139             :      * prepare library opening
     140             :      *-----------------------------------------------------------------*/
     141             : 
     142         279 :     IF( ( hParamMC = (PARAM_MC_DEC_HANDLE) malloc( sizeof( PARAM_MC_DEC_DATA ) ) ) == NULL )
     143             :     {
     144           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     145             :     }
     146             : 
     147         279 :     IF( ( hParamMC->hMetadataPMC = (HANDLE_IVAS_PARAM_MC_METADATA) malloc( sizeof( IVAS_PARAM_MC_METADATA ) ) ) == NULL )
     148             :     {
     149           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC metadata \n" ) );
     150             :     }
     151             : 
     152         279 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     153         279 :     move32();
     154         279 :     output_config = st_ivas->hDecoderConfig->output_config;
     155         279 :     move32();
     156         279 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     157         279 :     move32();
     158         279 :     mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
     159         279 :     nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
     160         279 :     hParamMC->hoa_encoder_fx = NULL;
     161             : 
     162             :     /* determine the synthesis config */
     163         279 :     test();
     164         279 :     test();
     165         279 :     test();
     166         279 :     test();
     167         279 :     test();
     168             : #ifdef FIX_1052_EXT_OUTPUT
     169         279 :     IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( st_ivas->transport_config, output_config ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
     170             : #else
     171             :     IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( st_ivas->transport_config, output_config ) )
     172             : #endif
     173             :     {
     174         222 :         hParamMC->synthesis_conf = PARAM_MC_SYNTH_DIRECT;
     175         222 :         move32();
     176             :     }
     177          57 :     ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
     178             :     {
     179           2 :         hParamMC->synthesis_conf = PARAM_MC_SYNTH_MONO_STEREO;
     180           2 :         move32();
     181             :     }
     182          55 :     ELSE IF( NE_32( st_ivas->transport_config, output_config ) )
     183             :     {
     184          55 :         test();
     185          55 :         test();
     186          55 :         IF( ( NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, audioCfg2channels( output_config ) ) ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, st_ivas->hOutSetup.nchan_out_woLFE ) ) )
     187             :         {
     188           1 :             hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_COV;
     189           1 :             move32();
     190             :             /* need to reset the intern config */
     191           1 :             st_ivas->intern_config = output_config;
     192           1 :             move32();
     193           1 :             ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
     194           1 :             IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
     195             :             {
     196           0 :                 st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk;
     197           0 :                 move32();
     198           0 :                 st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx;     // Q22
     199           0 :                 st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; // Q22
     200             :             }
     201             :         }
     202             :         ELSE
     203             :         {
     204          54 :             hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_CLDFB;
     205          54 :             move32();
     206             :         }
     207             :     }
     208             : 
     209         279 :     hParamMC->ls_conv_dmx_matrix_fx = NULL;
     210             : 
     211         279 :     test();
     212         279 :     IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     213             :     {
     214           3 :         nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
     215             :     }
     216             :     ELSE
     217             :     {
     218         276 :         nchan_out_cov = nchan_out_transport;
     219         276 :         move16();
     220             :     }
     221             : 
     222         279 :     st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
     223         279 :     move16();
     224         279 :     config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
     225         279 :     nchan_transport = st_ivas->nchan_transport;
     226         279 :     move16();
     227             : 
     228         279 :     SWITCH( nchan_transport )
     229             :     {
     230          17 :         case 4:
     231             :         case 3:
     232          17 :             st_ivas->nCPE = 2;
     233          17 :             move16();
     234          17 :             st_ivas->nSCE = 0;
     235          17 :             move16();
     236          17 :             st_ivas->element_mode_init = IVAS_CPE_MDCT;
     237          17 :             move16();
     238          17 :             BREAK;
     239         262 :         case 2:
     240         262 :             st_ivas->nCPE = 1;
     241         262 :             move16();
     242         262 :             st_ivas->nSCE = 0;
     243         262 :             move16();
     244         262 :             st_ivas->element_mode_init = IVAS_CPE_MDCT;
     245         262 :             move16();
     246             : 
     247         262 :             BREAK;
     248             :     }
     249             : 
     250             :     /*-----------------------------------------------------------------*
     251             :      * set input parameters
     252             :      *-----------------------------------------------------------------*/
     253             : 
     254             :     // hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX;
     255         279 :     Word16 temp_e;
     256         279 :     Word16 temp = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC, &temp_e );
     257         279 :     temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0
     258         279 :     temp = BASOP_Util_Divide1616_Scale( temp, CLDFB_NO_COL_MAX, &temp_e );
     259         279 :     temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0
     260         279 :     hParamMC->slot_size = temp;
     261         279 :     move16();
     262         279 :     set16_fx( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
     263         279 :     set16_fx( hParamMC->subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
     264         279 :     hParamMC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
     265         279 :     move16();
     266             : 
     267             :     // hParamMC->num_freq_bands = (int16_t)(output_Fs * INV_CLDFB_BANDWIDTH + 0.5f);
     268         279 :     hParamMC->num_freq_bands = extract_l( Mpy_32_32_r( output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) );
     269         279 :     move16();
     270         279 :     hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands;
     271         279 :     move16();
     272         279 :     ivas_param_mc_metadata_open_fx( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC );
     273             : 
     274             :     /* init arrays for quantized parameters */
     275             : 
     276         279 :     IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
     277             :     {
     278           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     279             :     }
     280         279 :     IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
     281             :     {
     282           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     283             :     }
     284         279 :     set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ) ); // Q8
     285         279 :     set16_fx( hParamMC->icc_q_fx, 0, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ) );                            // Q15
     286             : 
     287         279 :     param_mc_set_num_synth_bands( output_Fs, hParamMC );
     288             : 
     289             :     /* Band Grouping */
     290         279 :     IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) )
     291             :     {
     292           3 :         Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 );
     293             :     }
     294         276 :     ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) )
     295             :     {
     296         135 :         Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 );
     297             :     }
     298         141 :     ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) )
     299             :     {
     300         141 :         Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 );
     301             :     }
     302             :     ELSE
     303             :     {
     304           0 :         assert( 0 && "nbands must be 20, 14, or 10!" );
     305             :     }
     306             : 
     307             :     /* set max parameter band for abs cov */
     308         279 :     k = 0;
     309         279 :     move16();
     310        2514 :     WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) )
     311             :     {
     312        2235 :         hParamMC->max_param_band_abs_cov = k;
     313        2235 :         move16();
     314        2235 :         k = add( k, 1 );
     315             :     }
     316             : 
     317             :     /*-----------------------------------------------------------------*
     318             :      * open sub-modules
     319             :      *-----------------------------------------------------------------*/
     320             : 
     321             :     /* prototype signal computation */
     322             : 
     323         279 :     test();
     324         279 :     test();
     325         279 :     IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     326             :     {
     327          57 :         IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
     328             :         {
     329           0 :             return error;
     330             :         }
     331             : 
     332             :         /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */
     333          57 :         test();
     334          57 :         IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     335             :         {
     336           3 :             IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL )
     337             :             {
     338           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     339             :             }
     340             : 
     341          35 :             FOR( k = 0; k < nchan_out_transport; k++ )
     342             :             {
     343          32 :                 Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); /*Q30*/
     344             :             }
     345             : 
     346             :             /* convert ParamMC parameter bands to SFB */
     347           3 :             IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     348             :             {
     349           2 :                 st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth;
     350           2 :                 move16();
     351          30 :                 FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ )
     352             :                 {
     353          28 :                     st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] );
     354          28 :                     move16();
     355             :                 }
     356             :             }
     357             :             ELSE
     358             :             {
     359             :                 /* close the ls conversion handle immediately, it was only needed to get the DMX matrix in case of DMX in the covariance domain */
     360           1 :                 ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
     361             :             }
     362             :         }
     363             :     }
     364         279 :     IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL )
     365             :     {
     366           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     367             :     }
     368         279 :     Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, imult1616( nchan_transport, nchan_out_transport ) ); /*Q31*/
     369             : 
     370         279 :     hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport );
     371         279 :     move16();
     372             : 
     373         279 :     test();
     374         279 :     IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     375             :     {
     376           3 :         Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 );                                                                                                /*Q.26*/
     377           3 :         matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx ); /*Q.26*/
     378           3 :         Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 );                                                                                                 /*Q.26*/
     379           3 :         IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     380             :         {
     381           2 :             tmp32 = ONE_IN_Q26; /*Q26*/
     382           2 :             move32();
     383          14 :             FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ )
     384             :             {
     385          12 :                 tmp32 = L_max( L_abs( tmp32 ), L_abs( proto_matrix_fx[k] ) ); /*Q.26*/
     386             :             }
     387           2 :             proto_mtx_norm_fx = divide3232( ONE_IN_Q26, tmp32 ); /*Q15*/
     388             : 
     389             :             /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */
     390           8 :             FOR( k = 0; k < nchan_transport; k++ )
     391             :             {
     392          18 :                 FOR( Word16 i = 0; i < nchan_out_cov; i++ )
     393             :                 {
     394          12 :                     IF( EQ_32( proto_matrix_fx[k * nchan_out_cov + i], tmp32 ) )
     395             :                     {
     396           4 :                         st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = ONE_IN_Q30; // Q30
     397             :                     }
     398             :                     ELSE
     399             :                     {
     400           8 :                         st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[k * nchan_out_cov + i], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/
     401             :                     }
     402          12 :                     move32();
     403             :                 }
     404             :             }
     405             :         }
     406             :     }
     407             :     ELSE
     408             :     {
     409         276 :         Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); /*Q.31*/
     410         276 :         Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 );                                     /*Scaling down to 26*/
     411             :     }
     412             : 
     413         279 :     IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     414             :     {
     415           2 :         hParamMC->num_outputs_diff = 0;
     416           2 :         move16();
     417           2 :         hParamMC->diff_proto_info = NULL;
     418           2 :         hParamMC->h_output_synthesis_params.use_onset_filters = 0;
     419           2 :         move16();
     420           2 :         hParamMC->max_band_decorr = 0;
     421           2 :         move16();
     422           2 :         hParamMC->h_freq_domain_decorr_ap_params = NULL;
     423           2 :         hParamMC->h_freq_domain_decorr_ap_state = NULL;
     424             :     }
     425             :     ELSE
     426             :     {
     427         277 :         hParamMC->num_outputs_diff = nchan_out_cov;
     428         277 :         move16();
     429         277 :         IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL )
     430             :         {
     431           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     432             :         }
     433             : 
     434         277 :         IF( NE_32( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ), IVAS_ERR_OK ) )
     435             :         {
     436           0 :             return error;
     437             :         }
     438             : 
     439             :         /* decorrelation */
     440         277 :         hParamMC->h_freq_domain_decorr_ap_params = NULL;
     441         277 :         hParamMC->h_freq_domain_decorr_ap_state = NULL;
     442             : 
     443         277 :         ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0
     444             : 
     445         277 :         IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff,
     446             :                                                             hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ),
     447             :                    IVAS_ERR_OK ) )
     448             :         {
     449           0 :             return error;
     450             :         }
     451             : 
     452         277 :         hParamMC->h_output_synthesis_params.use_onset_filters = 0;
     453         277 :         move16();
     454         277 :         hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr;
     455         277 :         move16();
     456             :     }
     457         279 :     hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded];
     458         279 :     move16();
     459         279 :     max_param_band_residual = 0;
     460         279 :     move16();
     461             : 
     462        1006 :     FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
     463             :     {
     464        1006 :         IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
     465             :         {
     466         279 :             max_param_band_residual = k;
     467         279 :             move16();
     468         279 :             assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr );
     469         279 :             break;
     470             :         }
     471             :     }
     472             : 
     473             :     /* output synthesis */
     474         279 :     IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ), IVAS_ERR_OK ) )
     475             :     {
     476           0 :         return error;
     477             :     }
     478             : 
     479         279 :     ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx );
     480             : 
     481             :     /* Head or external rotation */
     482         279 :     test();
     483         279 :     test();
     484         279 :     test();
     485         279 :     IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
     486             :     {
     487          13 :         IF( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL )
     488             :         {
     489           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     490             :         }
     491          13 :         compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hParamMC->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER );
     492             :     }
     493             : 
     494             :     /*-----------------------------------------------------------------*
     495             :      * memory allocation
     496             :      *-----------------------------------------------------------------*/
     497             : 
     498         279 :     IF( hParamMC->max_band_decorr > 0 )
     499             :     {
     500         277 :         IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
     501             :         {
     502           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     503             :         }
     504         277 :         IF( ( hParamMC->proto_frame_dec_f_fx = (Word32 *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
     505             :         {
     506           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     507             :         }
     508             :     }
     509             :     ELSE
     510             :     {
     511           2 :         hParamMC->proto_frame_f_fx = NULL;
     512           2 :         hParamMC->proto_frame_dec_f_fx = NULL;
     513             :     }
     514             : 
     515         279 :     ivas_param_mc_dec_init_fx( hParamMC, nchan_transport, nchan_out_cov );
     516             : 
     517         279 :     IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     518             :     {
     519             :         Word16 n_cldfb_slots;
     520             : 
     521         277 :         n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS;
     522         277 :         move16();
     523         277 :         IF( st_ivas->hDecoderConfig->Opt_tsm )
     524             :         {
     525           4 :             n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS;
     526           4 :             move16();
     527             :         }
     528             : 
     529         277 :         Word16 cldfb_buf_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
     530         277 :         IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL )
     531             :         {
     532           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
     533             :         }
     534         277 :         set32_fx( hParamMC->Cldfb_RealBuffer_tc_fx, 0, cldfb_buf_size );
     535         277 :         hParamMC->Cldfb_RealBuffer_tc_e = 25; // Q6 , Initialised with Q6 to match non jbm and jbm cases
     536         277 :         move16();
     537         277 :         IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL )
     538             :         {
     539           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
     540             :         }
     541         277 :         set32_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, 0, cldfb_buf_size );
     542         277 :         hParamMC->Cldfb_ImagBuffer_tc_e = 25; // Q6 , Initialised with Q6 to match non jbm and jbm  cases
     543         277 :         move16();
     544         277 :         hParamMC->sz = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
     545         277 :         move16();
     546             : 
     547         277 :         IF( st_ivas->hTcBuffer == NULL )
     548             :         {
     549          10 :             IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
     550             :             {
     551           0 :                 return error;
     552             :             }
     553             :         }
     554             :     }
     555             :     ELSE
     556             :     {
     557           2 :         hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
     558           2 :         hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
     559             :     }
     560             : 
     561         279 :     hParamMC->subframes_rendered = 0;
     562         279 :     move16();
     563         279 :     hParamMC->slots_rendered = 0;
     564         279 :     move16();
     565             : 
     566         279 :     st_ivas->hParamMC = hParamMC;
     567         279 :     return error;
     568             : }
     569             : 
     570             : 
     571             : /*-------------------------------------------------------------------------
     572             :  * ivas_param_mc_get_param_band_mapping()
     573             :  *
     574             :  *
     575             :  *-------------------------------------------------------------------------*/
     576             : 
     577          65 : static void ivas_param_mc_get_param_band_mapping(
     578             :     const Word16 n_target_bands,
     579             :     const Word16 *target_band_grouping,
     580             :     const Word16 n_source_bands,
     581             :     const Word16 *source_band_grouping,
     582             :     PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping )
     583             : {
     584             :     Word16 target_band_idx;
     585          65 :     Word16 source_band_idx = 0;
     586          65 :     move16();
     587             :     Word16 source_band_cnt_total;
     588             : 
     589         851 :     FOR( target_band_idx = 0; target_band_idx < n_target_bands; target_band_idx++ )
     590             :     {
     591         786 :         Word16 upper = target_band_grouping[target_band_idx + 1];
     592         786 :         Word16 lower = target_band_grouping[target_band_idx];
     593         786 :         Word16 source_band_in_target_band_cnt = 0;
     594         786 :         Word16 norm_fac_fx = 32767; // 1.Q15
     595         786 :         source_band_cnt_total = 0;
     596         786 :         move16();
     597         786 :         move16();
     598         786 :         move16();
     599             : 
     600        4512 :         FOR( source_band_idx = 0; source_band_idx < n_source_bands; source_band_idx++ )
     601             :         {
     602             :             /* find lowest corresponding source band*/
     603        4512 :             test();
     604        4512 :             IF( LE_16( source_band_grouping[source_band_idx], lower ) && GE_16( source_band_grouping[source_band_idx + 1], lower ) )
     605             :             {
     606             :                 DO
     607             :                 {
     608        2006 :                     Word16 source_bands_in_target_band = sub( s_min( source_band_grouping[source_band_idx + 1], upper ), s_max( source_band_grouping[source_band_idx], lower ) );
     609        2006 :                     IF( source_bands_in_target_band )
     610             :                     {
     611        1048 :                         source_band_cnt_total = add( source_band_cnt_total, source_bands_in_target_band );
     612        1048 :                         parameter_band_mapping->source_band_idx[target_band_idx][source_band_in_target_band_cnt] = source_band_idx;
     613        1048 :                         parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_in_target_band_cnt++] = shl( source_bands_in_target_band, 10 ); /*Q10*/
     614        1048 :                         move16();
     615        1048 :                         move16();
     616             :                     }
     617        2006 :                     source_band_idx++;
     618             :                 }
     619        2006 :                 WHILE( LE_16( source_band_grouping[source_band_idx], upper ) && LT_16( source_band_idx, n_source_bands ) );
     620         786 :                 BREAK;
     621             :             }
     622             :         }
     623         786 :         norm_fac_fx = div_s( 1, source_band_cnt_total ); /*Q15*/
     624        1834 :         FOR( source_band_idx = 0; source_band_idx < source_band_in_target_band_cnt; source_band_idx++ )
     625             :         {
     626        1048 :             parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx] = shl_sat( mult( parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx], norm_fac_fx ) /*Q10*/, 5 ); /*Q15*/
     627        1048 :             move16();
     628             :         }
     629         786 :         parameter_band_mapping->n_source_bands[target_band_idx] = source_band_in_target_band_cnt;
     630         786 :         move16();
     631             :     }
     632          65 :     return;
     633             : }
     634             : 
     635             : 
     636             : /*-------------------------------------------------------------------------
     637             :  * ivas_param_mc_dec_reconfig()
     638             :  *
     639             :  * Reconfiguration of ParamMC decoder
     640             :  *-------------------------------------------------------------------------*/
     641             : 
     642          65 : ivas_error ivas_param_mc_dec_reconfig_fx(
     643             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
     644             : )
     645             : {
     646             :     Word16 k, nchan_transport;
     647             :     PARAM_MC_DEC_HANDLE hParamMC;
     648             :     Word16 nchan_out_transport;
     649             :     Word16 nchan_out_cov;
     650             :     Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
     651             :     Word32 proto_mtx_norm_fx;
     652             :     Word16 max_param_band_residual;
     653             :     UWord16 config_index;
     654             :     MC_LS_SETUP mc_ls_setup;
     655             :     Word32 output_Fs, ivas_total_brate;
     656             :     ivas_error error;
     657             :     Word16 nchan_transport_old;
     658             :     Word16 num_param_bands_old;
     659             :     PARAM_MC_PARAMETER_BAND_MAPPING parameter_band_mapping;
     660             :     Word16 band_grouping_old[20 + 1];
     661             : 
     662          65 :     hParamMC = st_ivas->hParamMC;
     663          65 :     error = IVAS_ERR_OK;
     664          65 :     move32();
     665             :     /* save important config information from the previous state */
     666          65 :     nchan_transport_old = st_ivas->nchan_transport;
     667          65 :     move32();
     668          65 :     num_param_bands_old = hParamMC->hMetadataPMC->num_parameter_bands;
     669          65 :     move32();
     670             : 
     671             :     /*-----------------------------------------------------------------*
     672             :      * prepare library opening
     673             :      *-----------------------------------------------------------------*/
     674             : 
     675          65 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     676          65 :     move32();
     677          65 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     678          65 :     move32();
     679          65 :     mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
     680          65 :     nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
     681             : 
     682          65 :     test();
     683          65 :     IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     684             :     {
     685           0 :         nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
     686             :     }
     687             :     ELSE
     688             :     {
     689          65 :         nchan_out_cov = nchan_out_transport;
     690          65 :         move16();
     691             :     }
     692             : 
     693          65 :     st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
     694          65 :     move16();
     695          65 :     config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
     696          65 :     nchan_transport = st_ivas->nchan_transport;
     697          65 :     move16();
     698             : 
     699          65 :     SWITCH( nchan_transport )
     700             :     {
     701           0 :         case 4:
     702             :         case 3:
     703           0 :             st_ivas->nCPE = 2;
     704           0 :             move16();
     705           0 :             st_ivas->nSCE = 0;
     706           0 :             move16();
     707           0 :             st_ivas->element_mode_init = IVAS_CPE_MDCT;
     708           0 :             move16();
     709           0 :             BREAK;
     710          65 :         case 2:
     711          65 :             st_ivas->nCPE = 1;
     712          65 :             move16();
     713          65 :             st_ivas->nSCE = 0;
     714          65 :             move16();
     715          65 :             st_ivas->element_mode_init = IVAS_CPE_MDCT;
     716          65 :             move16();
     717             : 
     718          65 :             BREAK;
     719             :     }
     720             : 
     721             :     /*-----------------------------------------------------------------*
     722             :      * set input parameters
     723             :      *-----------------------------------------------------------------*/
     724          65 :     hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); // Q0
     725          65 :     move16();
     726          65 :     hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands;
     727          65 :     move16();
     728             : 
     729          65 :     Copy( hParamMC->band_grouping, band_grouping_old, add( hParamMC->hMetadataPMC->num_parameter_bands, 1 ) );
     730          65 :     ivas_param_mc_metadata_open_fx( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC );
     731             :     /* Band Grouping */
     732          65 :     IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) )
     733             :     {
     734           0 :         Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 );
     735             :     }
     736          65 :     ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) )
     737             :     {
     738          34 :         Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 );
     739             :     }
     740          31 :     ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) )
     741             :     {
     742          31 :         Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 );
     743             :     }
     744             :     ELSE
     745             :     {
     746           0 :         assert( 0 && "nbands must be 20, 14, or 10!" );
     747             :     }
     748             : 
     749          65 :     ivas_param_mc_get_param_band_mapping( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->band_grouping, num_param_bands_old, band_grouping_old, &parameter_band_mapping );
     750             : 
     751          65 :     test();
     752          65 :     IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) )
     753             :     {
     754          62 :         Word16 *ild_q_old_fx = hParamMC->icld_q_fx; // Q8
     755          62 :         Word16 *icc_q_old_fx = hParamMC->icc_q_fx;  // Q15
     756             : 
     757          62 :         IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
     758             :         {
     759           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     760             :         }
     761          62 :         IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
     762             :         {
     763           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     764             :         }
     765          62 :         set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); /*Q8*/
     766          62 :         set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe );                            /*Q15*/
     767             : 
     768             :         /* map old to new parameter banding, only for same number of TCs, needs some more thought for a changing number of TCs */
     769          62 :         test();
     770          62 :         IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) )
     771             :         {
     772             :             Word16 new_param_band_idx, param_idx, source_param_idx;
     773             :             Word16 num_param_lfe;
     774          60 :             Word16 *p_icc_new_fx = hParamMC->icc_q_fx;  // Q15
     775          60 :             Word16 *p_ild_new_fx = hParamMC->icld_q_fx; // Q8
     776          60 :             Word16 p_ild_new_e = 23;
     777          60 :             move16();
     778             :             Word16 p_ild_new_tmp;
     779             : 
     780             :             /* ICC */
     781          60 :             num_param_lfe = hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe;
     782          60 :             move16();
     783         776 :             FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
     784             :             {
     785        4336 :                 FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ )
     786             :                 {
     787        3620 :                     *p_icc_new_fx = 0;
     788        3620 :                     move16();
     789        8484 :                     FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
     790             :                     {
     791        4864 :                         *p_icc_new_fx = add( *p_icc_new_fx, mult( icc_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); /*Q15*/
     792        4864 :                         move16();
     793             :                     }
     794        3620 :                     p_icc_new_fx++;
     795             :                 }
     796             :             }
     797             : 
     798             :             /* ILD */
     799          60 :             num_param_lfe = hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe;
     800          60 :             move16();
     801         776 :             FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
     802             :             {
     803        5052 :                 FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ )
     804             :                 {
     805        4336 :                     *p_ild_new_fx = 0;
     806        4336 :                     move16();
     807       10160 :                     FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
     808             :                     {
     809        5824 :                         p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); // 31 - p_ild_new_e - 16
     810        5824 :                         *p_ild_new_fx = add( *p_ild_new_fx, mult( p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) );
     811        5824 :                         move16();
     812             :                     }
     813        4336 :                     *p_ild_new_fx = extract_l( L_shr( Mpy_32_16_1( L_add( BASOP_Util_Log2( *p_ild_new_fx ), L_add( 16 << Q25, L_shl( p_ild_new_e, 25 ) ) ), 24660 /*3.Q13*/ ), 15 ) ); // Q8
     814        4336 :                     move16();
     815        4336 :                     p_ild_new_fx++;
     816             :                 }
     817             :             }
     818             :         }
     819          62 :         free( ild_q_old_fx );
     820          62 :         free( icc_q_old_fx );
     821             :     }
     822             : 
     823          65 :     param_mc_set_num_synth_bands( output_Fs, hParamMC );
     824             : 
     825             :     /* set max parameter band for abs cov */
     826          65 :     k = 0;
     827          65 :     move16();
     828         588 :     WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) )
     829             :     {
     830         523 :         hParamMC->max_param_band_abs_cov = k;
     831         523 :         move16();
     832         523 :         k = add( k, 1 );
     833             :     }
     834             : 
     835             :     /*-----------------------------------------------------------------*
     836             :      * open sub-modules
     837             :      *-----------------------------------------------------------------*/
     838             : 
     839             :     /* prototype signal computation */
     840             : 
     841          65 :     IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     842             :     {
     843           0 :         IF( NE_16( nchan_transport_old, nchan_transport ) )
     844             :         {
     845           0 :             IF( st_ivas->hLsSetUpConversion != NULL )
     846             :             {
     847           0 :                 ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
     848             :             }
     849             : 
     850           0 :             IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
     851             :             {
     852           0 :                 return error;
     853             :             }
     854             : 
     855             :             /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */
     856           0 :             free( hParamMC->ls_conv_dmx_matrix_fx );
     857             : 
     858           0 :             IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL )
     859             :             {
     860           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     861             :             }
     862           0 :             FOR( k = 0; k < nchan_out_transport; k++ )
     863             :             {
     864           0 :                 Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov );
     865             :             }
     866             :         }
     867             :         /* convert ParamMC parameter bands to SFB */
     868             : 
     869           0 :         st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth;
     870           0 :         move16();
     871           0 :         FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ )
     872             :         {
     873           0 :             st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] );
     874           0 :             move16();
     875             :         }
     876           0 :         FOR( ; k < MAX_SFB + 2; k++ )
     877             :         {
     878           0 :             st_ivas->hLsSetUpConversion->sfbOffset[k] = 0;
     879           0 :             move16();
     880             :         }
     881             :     }
     882             : 
     883          65 :     IF( NE_16( nchan_transport_old, nchan_transport ) )
     884             :     {
     885           2 :         free( hParamMC->proto_matrix_int_fx );
     886           2 :         IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL )
     887             :         {
     888           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     889             :         }
     890           2 :         hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport );
     891           2 :         move16();
     892           2 :         Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, hParamMC->proto_matrix_int_len ); /*Q31*/
     893             :     }
     894             : 
     895          65 :     test();
     896          65 :     IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     897             :     {
     898           0 :         Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); // Q30 -> Q26
     899           0 :         matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0,
     900             :                            ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0,
     901             :                            proto_matrix_fx /*Q26*/ );
     902           0 :         Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); // Q26 -> Q30
     903             : 
     904           0 :         IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     905             :         {
     906           0 :             proto_mtx_norm_fx = ONE_IN_Q26; // Q26
     907           0 :             move32();
     908           0 :             FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ )
     909             :             {
     910           0 :                 proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); // Q26
     911             :             }
     912           0 :             proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/
     913             : 
     914             :             /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */
     915           0 :             FOR( k = 0; k < nchan_transport; k++ )
     916             :             {
     917           0 :                 FOR( Word16 i = 0; i < nchan_out_cov; i++ )
     918             :                 {
     919           0 :                     st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); // Q26 -> Q30
     920           0 :                     move32();
     921             :                 }
     922             :             }
     923             :         }
     924             :     }
     925             :     ELSE
     926             :     {
     927          65 :         Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); // proto_matrix_fx -> Q31
     928          65 :         Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 );                                     // proto_matrix_fx -> Q26
     929             :     }
     930             : 
     931          65 :     test();
     932          65 :     IF( NE_16( nchan_transport_old, nchan_transport ) && NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
     933             :     {
     934             :         Word16 i;
     935             :         Word16 len;
     936             : 
     937             :         /* close decorrelator */
     938           2 :         ivas_dirac_dec_decorr_close_fx( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state );
     939             : 
     940             :         /* deallocate diffuse prototype info */
     941           2 :         IF( hParamMC->diff_proto_info )
     942             :         {
     943           8 :             FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ )
     944             :             {
     945           6 :                 free( hParamMC->diff_proto_info->source_chan_idx[i] );
     946           6 :                 hParamMC->diff_proto_info->source_chan_idx[i] = NULL;
     947             : 
     948           6 :                 free( hParamMC->diff_proto_info->proto_fac_fx[i] );
     949           6 :                 hParamMC->diff_proto_info->proto_fac_fx[i] = NULL;
     950             :             }
     951             : 
     952           2 :             free( hParamMC->diff_proto_info->source_chan_idx );
     953           2 :             hParamMC->diff_proto_info->source_chan_idx = NULL;
     954             : 
     955           2 :             free( hParamMC->diff_proto_info->proto_fac_fx );
     956           2 :             hParamMC->diff_proto_info->proto_fac_fx = NULL;
     957             : 
     958           2 :             free( hParamMC->diff_proto_info->proto_index_diff );
     959           2 :             hParamMC->diff_proto_info->proto_index_diff = NULL;
     960             : 
     961           2 :             free( hParamMC->diff_proto_info->num_source_chan_diff );
     962           2 :             hParamMC->diff_proto_info->num_source_chan_diff = NULL;
     963             : 
     964           2 :             free( hParamMC->diff_proto_info );
     965           2 :             hParamMC->diff_proto_info = NULL;
     966             :         }
     967             : 
     968           2 :         hParamMC->num_outputs_diff = nchan_out_cov;
     969           2 :         move16();
     970           2 :         IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL )
     971             :         {
     972           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
     973             :         }
     974           2 :         IF( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ) != IVAS_ERR_OK )
     975             :         {
     976           0 :             return error;
     977             :         }
     978             : 
     979             :         /* decorrelation */
     980           2 :         hParamMC->h_freq_domain_decorr_ap_params = NULL;
     981           2 :         hParamMC->h_freq_domain_decorr_ap_state = NULL;
     982             : 
     983             :         Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
     984           2 :         ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0
     985             : 
     986           2 :         IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff,
     987             :                                                             hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ),
     988             :                    IVAS_ERR_OK ) )
     989             :         {
     990           0 :             return error;
     991             :         }
     992           2 :         hParamMC->h_output_synthesis_params.use_onset_filters = 0;
     993           2 :         move16();
     994           2 :         hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr;
     995           2 :         move16();
     996             :         /* init decorrelation */
     997           2 :         IF( hParamMC->max_band_decorr > 0 )
     998             :         {
     999             : 
    1000           2 :             len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr );
    1001             : 
    1002             :             /* init onsetDetectionPower */
    1003           2 :             set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len );
    1004           2 :             set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len );
    1005           2 :             hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31;
    1006           2 :             move16();
    1007             :         }
    1008             :     }
    1009          65 :     hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded];
    1010          65 :     move16();
    1011          65 :     max_param_band_residual = 0;
    1012          65 :     move16();
    1013             : 
    1014         229 :     FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
    1015             :     {
    1016         229 :         IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
    1017             :         {
    1018          65 :             max_param_band_residual = k;
    1019          65 :             move16();
    1020          65 :             assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr );
    1021          65 :             BREAK;
    1022             :         }
    1023             :     }
    1024             : 
    1025          65 :     test();
    1026          65 :     IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) )
    1027             :     {
    1028          62 :         DIRAC_OUTPUT_SYNTHESIS_COV_STATE cov_state_old = hParamMC->h_output_synthesis_cov_state;
    1029          62 :         DIRAC_OUTPUT_SYNTHESIS_PARAMS params_old = hParamMC->h_output_synthesis_params;
    1030             : 
    1031             :         Word32 tmp_buf_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
    1032             : 
    1033          62 :         set_zero_fx( tmp_buf_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
    1034             : 
    1035             :         /* output synthesis */
    1036          62 :         IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS,
    1037             :                                                                           hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ),
    1038             :                    IVAS_ERR_OK ) )
    1039             :         {
    1040           0 :             return error;
    1041             :         }
    1042             : 
    1043          62 :         ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx );
    1044             : 
    1045          62 :         ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_out_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual );
    1046             : 
    1047             :         /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */
    1048          62 :         test();
    1049          62 :         IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) )
    1050             :         {
    1051             :             Word16 new_param_band_idx, source_param_idx;
    1052             : 
    1053         776 :             FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
    1054             :             {
    1055        1676 :                 FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
    1056             :                 {
    1057             :                     /* Cx */
    1058         960 :                     v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_transport_old ) );                                                                                                                                                                                                    // Q(31 - cov_state_old.cx_old_e)
    1059         960 :                     v_add_fixed_me( tmp_buf_fx, cov_state_old.cx_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], imult1616( nchan_transport_old, nchan_transport_old ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx])
    1060             :                     /* Cy */
    1061         960 :                     v_multc_fixed_16( cov_state_old.cy_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) );                                                                                                                                                                                                    // Q(31 - cov_state_old.cy_old_e)
    1062         960 :                     v_add_fixed_me( tmp_buf_fx, cov_state_old.cy_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx])
    1063             :                     /* mixing matrix*/
    1064         960 :                     v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_out_cov ) );                                                                                                                                                                                                                                                      // Q(31 - mixing_matrix_old_exp)
    1065         960 :                     v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx])
    1066             :                 }
    1067             :             }
    1068         627 :             FOR( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ )
    1069             :             {
    1070        1347 :                 FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
    1071             :                 {
    1072             :                     /* residual mixing matrix*/
    1073         780 :                     v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) );                                                                                                                                                                                                                                                                      // Q(31 - mixing_matrix_res_old_exp)
    1074         780 :                     v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_res_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx])
    1075             :                 }
    1076             :             }
    1077             :         }
    1078          62 :         ivas_dirac_dec_output_synthesis_cov_close_fx( &params_old, &cov_state_old );
    1079             :     }
    1080             : 
    1081             :     /*-----------------------------------------------------------------*
    1082             :      * memory allocation
    1083             :      *-----------------------------------------------------------------*/
    1084             : 
    1085          65 :     test();
    1086          65 :     IF( ( hParamMC->max_band_decorr > 0 ) && NE_16( nchan_transport_old, nchan_transport ) )
    1087             :     {
    1088           2 :         free( hParamMC->proto_frame_f_fx );
    1089           2 :         IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
    1090             :         {
    1091           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
    1092             :         }
    1093           2 :         set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) );
    1094             :     }
    1095             : 
    1096             : 
    1097          65 :     IF( NE_16( nchan_transport_old, nchan_transport ) )
    1098             :     {
    1099           2 :         IF( NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
    1100             :         {
    1101             :             Word16 n_cldfb_slots;
    1102           2 :             IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
    1103             :             {
    1104           2 :                 free( hParamMC->Cldfb_RealBuffer_tc_fx );
    1105           2 :                 hParamMC->Cldfb_RealBuffer_tc_fx = NULL; // Q12
    1106             :             }
    1107           2 :             IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
    1108             :             {
    1109           2 :                 free( hParamMC->Cldfb_ImagBuffer_tc_fx );
    1110           2 :                 hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; // Q12
    1111             :             }
    1112             : 
    1113           2 :             n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS;
    1114           2 :             move16();
    1115           2 :             IF( st_ivas->hDecoderConfig->Opt_tsm )
    1116             :             {
    1117           0 :                 n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS;
    1118           0 :                 move16();
    1119             :             }
    1120           2 :             Word16 cldfb_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
    1121           2 :             IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL )
    1122             :             {
    1123           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
    1124             :             }
    1125           2 :             set_zero_fx( hParamMC->Cldfb_RealBuffer_tc_fx, cldfb_size );
    1126             : 
    1127           2 :             IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL )
    1128             :             {
    1129           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
    1130             :             }
    1131           2 :             set_zero_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, cldfb_size );
    1132             :         }
    1133             :         ELSE
    1134             :         {
    1135           0 :             IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
    1136             :             {
    1137           0 :                 free( hParamMC->Cldfb_RealBuffer_tc_fx );
    1138           0 :                 hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
    1139             :             }
    1140           0 :             IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
    1141             :             {
    1142           0 :                 free( hParamMC->Cldfb_ImagBuffer_tc_fx );
    1143           0 :                 hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
    1144             :             }
    1145             :         }
    1146             :     }
    1147          65 :     return error;
    1148             : }
    1149             : 
    1150             : 
    1151             : /*-------------------------------------------------------------------------
    1152             :  * param_mc_get_num_cldfb_syntheses()
    1153             :  *
    1154             :  * calculate the necessary number of CLDFB synthesis instances
    1155             :  *------------------------------------------------------------------------*/
    1156             : 
    1157             : /*! r: number of cldfb synthesis instances */
    1158         314 : Word16 param_mc_get_num_cldfb_syntheses_fx(
    1159             :     Decoder_Struct *st_ivas /* i  : Parametric MC handle */
    1160             : )
    1161             : {
    1162             :     Word16 num_cldfb_syntheses;
    1163             : 
    1164         314 :     num_cldfb_syntheses = 0;
    1165         314 :     move16();
    1166             : 
    1167             :     /* sanity check*/
    1168         314 :     IF( st_ivas->hParamMC == NULL )
    1169             :     {
    1170           0 :         assert( 0 && "ParamMC handle does not exist!\n" );
    1171             :     }
    1172             : 
    1173         314 :     test();
    1174         314 :     IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    1175             :     {
    1176           0 :         num_cldfb_syntheses = 2;
    1177           0 :         move16();
    1178             :     }
    1179         314 :     ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    1180             :     {
    1181         144 :         num_cldfb_syntheses = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    1182             :     }
    1183         170 :     ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) )
    1184             :     {
    1185         170 :         num_cldfb_syntheses = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    1186             :     }
    1187             : 
    1188         314 :     return num_cldfb_syntheses;
    1189             : }
    1190             : 
    1191             : 
    1192             : /*-------------------------------------------------------------------------
    1193             :  * ivas_param_mc_dec_close()
    1194             :  *
    1195             :  * Close Parametric MC memories
    1196             :  *------------------------------------------------------------------------*/
    1197             : 
    1198         881 : void ivas_param_mc_dec_close_fx(
    1199             :     PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle   */
    1200             : )
    1201             : {
    1202             :     UWord16 i;
    1203             :     PARAM_MC_DEC_HANDLE hParamMC;
    1204             : 
    1205         881 :     IF( hParamMC_out == NULL || *hParamMC_out == NULL )
    1206             :     {
    1207         602 :         return;
    1208             :     }
    1209             : 
    1210         279 :     hParamMC = *hParamMC_out;
    1211             : 
    1212             :     /* close sub-modules */
    1213         279 :     ivas_dirac_dec_output_synthesis_cov_close_fx( &hParamMC->h_output_synthesis_params, &hParamMC->h_output_synthesis_cov_state );
    1214             : 
    1215         279 :     IF( hParamMC->h_freq_domain_decorr_ap_params != NULL || hParamMC->h_freq_domain_decorr_ap_state != NULL )
    1216             :     {
    1217         277 :         ivas_dirac_dec_decorr_close_fx( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state );
    1218             :     }
    1219             : 
    1220             :     /* parameter decoding */
    1221         279 :     IF( hParamMC->hMetadataPMC != NULL )
    1222             :     {
    1223         279 :         free( hParamMC->hMetadataPMC );
    1224         279 :         hParamMC->hMetadataPMC = NULL;
    1225             :     }
    1226         279 :     IF( hParamMC->icc_q_fx != NULL )
    1227             :     {
    1228         279 :         free( hParamMC->icc_q_fx );
    1229         279 :         hParamMC->icc_q_fx = NULL; // Q15
    1230             :     }
    1231             : 
    1232         279 :     IF( hParamMC->icld_q_fx != NULL )
    1233             :     {
    1234         279 :         free( hParamMC->icld_q_fx );
    1235         279 :         hParamMC->icld_q_fx = NULL; // Q8
    1236             :     }
    1237             :     /* diffuse prototype info */
    1238         279 :     IF( hParamMC->diff_proto_info )
    1239             :     {
    1240        1110 :         FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ )
    1241             :         {
    1242         833 :             free( hParamMC->diff_proto_info->source_chan_idx[i] );
    1243         833 :             hParamMC->diff_proto_info->source_chan_idx[i] = NULL;
    1244             : 
    1245         833 :             free( hParamMC->diff_proto_info->proto_fac_fx[i] );
    1246         833 :             hParamMC->diff_proto_info->proto_fac_fx[i] = NULL;
    1247             :         }
    1248             : 
    1249         277 :         free( hParamMC->diff_proto_info->source_chan_idx );
    1250         277 :         hParamMC->diff_proto_info->source_chan_idx = NULL;
    1251             : 
    1252         277 :         free( hParamMC->diff_proto_info->proto_fac_fx );
    1253         277 :         hParamMC->diff_proto_info->proto_fac_fx = NULL;
    1254             : 
    1255         277 :         free( hParamMC->diff_proto_info->proto_index_diff );
    1256         277 :         hParamMC->diff_proto_info->proto_index_diff = NULL;
    1257             : 
    1258         277 :         free( hParamMC->diff_proto_info->num_source_chan_diff );
    1259         277 :         hParamMC->diff_proto_info->num_source_chan_diff = NULL;
    1260             : 
    1261         277 :         free( hParamMC->diff_proto_info );
    1262         277 :         hParamMC->diff_proto_info = NULL;
    1263             :     }
    1264             :     /* States */
    1265             :     /* free prototype signal buffers */
    1266         279 :     IF( hParamMC->proto_frame_f_fx != NULL )
    1267             :     {
    1268         277 :         free( hParamMC->proto_frame_f_fx );
    1269         277 :         hParamMC->proto_frame_f_fx = NULL;
    1270             :     }
    1271             : 
    1272         279 :     IF( hParamMC->proto_frame_dec_f_fx != NULL )
    1273             :     {
    1274         277 :         free( hParamMC->proto_frame_dec_f_fx );
    1275         277 :         hParamMC->proto_frame_dec_f_fx = NULL;
    1276             :     }
    1277             : 
    1278         279 :     IF( hParamMC->ls_conv_dmx_matrix_fx != NULL )
    1279             :     {
    1280           3 :         free( hParamMC->ls_conv_dmx_matrix_fx );
    1281           3 :         hParamMC->ls_conv_dmx_matrix_fx = NULL;
    1282             :     }
    1283             : 
    1284         279 :     IF( hParamMC->proto_matrix_int_fx != NULL )
    1285             :     {
    1286         279 :         free( hParamMC->proto_matrix_int_fx );
    1287         279 :         hParamMC->proto_matrix_int_fx = NULL;
    1288             :     }
    1289             : 
    1290         279 :     IF( hParamMC->hoa_encoder_fx != NULL )
    1291             :     {
    1292          13 :         free( hParamMC->hoa_encoder_fx );
    1293          13 :         hParamMC->hoa_encoder_fx = NULL;
    1294             :     }
    1295         279 :     IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
    1296             :     {
    1297         277 :         free( hParamMC->Cldfb_RealBuffer_tc_fx );
    1298         277 :         hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
    1299             :     }
    1300         279 :     IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
    1301             :     {
    1302         277 :         free( hParamMC->Cldfb_ImagBuffer_tc_fx );
    1303         277 :         hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
    1304             :     }
    1305             : 
    1306         279 :     free( *hParamMC_out );
    1307         279 :     *hParamMC_out = NULL;
    1308             : 
    1309         279 :     return;
    1310             : }
    1311             : 
    1312             : 
    1313             : /*-------------------------------------------------------------------------
    1314             :  * ivas_param_mc_dec_read_BS()
    1315             :  *
    1316             :  * Read the Parametric MC metadata
    1317             :  *------------------------------------------------------------------------*/
    1318             : 
    1319       10249 : void ivas_param_mc_dec_read_BS_fx(
    1320             :     const Word32 ivas_total_brate, /* i  : IVAS total bitrate      */
    1321             :     Decoder_State *st,             /* i/o: decoder state structure */
    1322             :     PARAM_MC_DEC_HANDLE hParamMC,  /* i/o: decoder ParamMC handle  */
    1323             :     Word16 *nb_bits                /* o  : number of bits written  */
    1324             : )
    1325             : {
    1326             :     Word16 param_frame_idx;
    1327             :     Word16 band_step;
    1328             :     UWord16 bit_buffer[PARAM_MC_MAX_BITS];
    1329             :     Word16 bits_to_copy;
    1330             :     Word16 bit_pos;
    1331             :     Word16 num_lfe_bands;
    1332             :     Word16 num_param_bands;
    1333             :     Word16 metadata_bit_pos;
    1334             :     Word16 i, j, k;
    1335             :     Word16 icc_map_size;
    1336             :     Word16 icc_map_size_wo_lfe;
    1337             :     Word16 ild_map_size;
    1338             :     Word16 ild_map_size_wo_lfe;
    1339             :     HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC;
    1340             : 
    1341       10249 :     push_wmops( "param_mc_read_bs" );
    1342             : 
    1343             :     /* Inits */
    1344       10249 :     *nb_bits = 0;
    1345       10249 :     move16();
    1346       10249 :     hMetadataPMC = hParamMC->hMetadataPMC;
    1347       10249 :     icc_map_size = hMetadataPMC->icc_mapping_conf->icc_map_size_lfe;
    1348       10249 :     move16();
    1349       10249 :     icc_map_size_wo_lfe = hMetadataPMC->icc_mapping_conf->icc_map_size_wo_lfe;
    1350       10249 :     move16();
    1351       10249 :     ild_map_size = hMetadataPMC->ild_mapping_conf->ild_map_size_lfe;
    1352       10249 :     move16();
    1353       10249 :     ild_map_size_wo_lfe = hMetadataPMC->ild_mapping_conf->ild_map_size_wo_lfe;
    1354       10249 :     move16();
    1355             : 
    1356       10249 :     IF( !st->bfi )
    1357             :     {
    1358             :         /*metadata_bit_pos = extract_l(ivas_total_brate / FRAMES_PER_SEC - 1);
    1359             :         bits_to_copy = s_min(extract_l(ivas_total_brate / FRAMES_PER_SEC), PARAM_MC_MAX_BITS);*/
    1360       10216 :         Word16 temp = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
    1361       10216 :         metadata_bit_pos = sub( temp, 1 );
    1362       10216 :         bits_to_copy = s_min( temp, PARAM_MC_MAX_BITS );
    1363             : 
    1364             :         /* copy and reverse metadata */
    1365    10350440 :         FOR( bit_pos = 0; bit_pos < bits_to_copy; bit_pos++ )
    1366             :         {
    1367    10340224 :             bit_buffer[bit_pos] = st->bit_stream[metadata_bit_pos];
    1368    10340224 :             move16();
    1369    10340224 :             metadata_bit_pos = sub( metadata_bit_pos, 1 );
    1370    10340224 :             move16();
    1371             :         }
    1372             : 
    1373       10216 :         bit_pos = 0;
    1374       10216 :         move16();
    1375             : 
    1376             :         /* read reserved bit */
    1377       10216 :         hMetadataPMC->lfe_on = bit_buffer[bit_pos++];
    1378       10216 :         move16();
    1379             : 
    1380             :         /* get coded bwidth */
    1381             :         {
    1382             :             Word16 pos;
    1383       10216 :             Word16 bw = 0;
    1384       10216 :             move16();
    1385       30648 :             FOR( pos = 0; pos < 2; pos++ )
    1386             :             {
    1387       20432 :                 bw = add( bw, extract_l( L_shl( bit_buffer[bit_pos++], pos ) ) );
    1388             :             }
    1389       10216 :             hMetadataPMC->coded_bwidth = bw;
    1390       10216 :             move16();
    1391             :         }
    1392             : 
    1393             :         /* set tables if coded band width differs from last frame */
    1394       10216 :         IF( NE_16( hMetadataPMC->coded_bwidth, hMetadataPMC->last_coded_bwidth ) )
    1395             :         {
    1396          86 :             ivas_param_mc_set_coded_bands_fx( hMetadataPMC );
    1397          86 :             param_mc_set_num_synth_bands( st->output_Fs, hParamMC );
    1398          86 :             hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->num_param_bands_synth];
    1399          86 :             move16();
    1400             :         }
    1401             : 
    1402       10216 :         param_frame_idx = bit_buffer[bit_pos++];
    1403       10216 :         move16();
    1404       10216 :         hMetadataPMC->param_frame_idx = param_frame_idx;
    1405       10216 :         move16();
    1406       10216 :         num_param_bands = hMetadataPMC->nbands_in_param_frame[param_frame_idx];
    1407       10216 :         move16();
    1408             : 
    1409       10216 :         hMetadataPMC->bAttackPresent = bit_buffer[bit_pos++];
    1410       10216 :         move16();
    1411       10216 :         hMetadataPMC->attackIndex = 0;
    1412       10216 :         move16();
    1413       10216 :         band_step = 1;
    1414       10216 :         move16();
    1415       10216 :         num_lfe_bands = 0;
    1416       10216 :         move16();
    1417             : 
    1418       10216 :         IF( hMetadataPMC->bAttackPresent )
    1419             :         {
    1420        1968 :             FOR( i = 2; i >= 0; i-- )
    1421             :             {
    1422        1476 :                 hMetadataPMC->attackIndex = add( hMetadataPMC->attackIndex, extract_l( L_shl( bit_buffer[bit_pos++], i ) ) );
    1423             :             }
    1424             : 
    1425         492 :             band_step = PARAM_MC_TRANSIENT_BAND_STEP;
    1426         492 :             move16();
    1427             : 
    1428             :             /*num_lfe_bands = add(PARAM_MC_MAX_BAND_LFE / band_step, (PARAM_MC_MAX_BAND_LFE % band_step) ? 1 : 0);
    1429             :             num_param_bands = add(hMetadataPMC->nbands_coded / band_step, ((hMetadataPMC->nbands_coded % band_step) ? 1 : 0));*/
    1430             :             Word16 temp_e;
    1431         492 :             temp = BASOP_Util_Divide3232_Scale( PARAM_MC_MAX_BAND_LFE, band_step, &temp_e );
    1432         492 :             temp = shr( temp, sub( 15, temp_e ) );
    1433             :             Word16 temp1;
    1434         492 :             IF( PARAM_MC_MAX_BAND_LFE % band_step )
    1435             :             {
    1436         492 :                 temp1 = 1;
    1437             :             }
    1438             :             ELSE
    1439             :             {
    1440           0 :                 temp1 = 0;
    1441             :             }
    1442         492 :             move16();
    1443         492 :             num_lfe_bands = add( temp, temp1 );
    1444             : 
    1445         492 :             temp = BASOP_Util_Divide3232_Scale( hMetadataPMC->nbands_coded, band_step, &temp_e );
    1446         492 :             temp = shr( temp, sub( 15, temp_e ) );
    1447             :             Word16 temp2;
    1448         492 :             IF( hMetadataPMC->nbands_coded % band_step )
    1449             :             {
    1450          53 :                 temp2 = 1;
    1451             :             }
    1452             :             ELSE
    1453             :             {
    1454         439 :                 temp2 = 0;
    1455             :             }
    1456         492 :             move16();
    1457         492 :             num_param_bands = add( temp, temp2 );
    1458             :         }
    1459             :         ELSE
    1460             :         {
    1461       19448 :             FOR( j = 0; j < PARAM_MC_MAX_BAND_LFE; j += band_step )
    1462             :             {
    1463        9724 :                 IF( EQ_16( param_frame_idx, hMetadataPMC->coding_band_mapping[j] ) )
    1464             :                 {
    1465             :                     /* LFE ICC is always the last ICC in coding band 0 */
    1466        4873 :                     num_lfe_bands = add( num_lfe_bands, 1 );
    1467        4873 :                     move16();
    1468             :                 }
    1469             :             }
    1470             :         }
    1471             : 
    1472       10216 :         IF( !hMetadataPMC->lfe_on )
    1473             :         {
    1474        9151 :             num_lfe_bands = 0;
    1475        9151 :             move16();
    1476             :         }
    1477             : 
    1478       10216 :         ivas_param_mc_bs_decode_parameter_values_fx( bit_buffer, &bit_pos, bits_to_copy, &st->BER_detect, hMetadataPMC, &hMetadataPMC->icc_coding,
    1479             :                                                      icc_map_size_wo_lfe, icc_map_size, num_lfe_bands, band_step, num_param_bands, hParamMC->icc_q_fx );
    1480             : 
    1481       10216 :         IF( !st->BER_detect )
    1482             :         {
    1483       10216 :             ivas_param_mc_bs_decode_parameter_values_fx( bit_buffer, &bit_pos, bits_to_copy, &st->BER_detect, hMetadataPMC, &hMetadataPMC->ild_coding,
    1484             :                                                          ild_map_size_wo_lfe, ild_map_size, num_lfe_bands, band_step, num_param_bands, hParamMC->icld_q_fx );
    1485             :         }
    1486             :         /* set LFE ILD and ICC to zero above PARAM_MC_MAX_BAND_LFE for attack frames */
    1487       10216 :         IF( hMetadataPMC->bAttackPresent )
    1488             :         {
    1489         643 :             FOR( k = PARAM_MC_MAX_BAND_LFE; k < imult1616( band_step, num_lfe_bands ); k++ )
    1490             :             {
    1491         151 :                 hParamMC->icc_q_fx[L_sub( L_mult0( add( k, 1 ), icc_map_size ), 1 )] = 32767; /* 1.0f in Q15 */
    1492         151 :                 move16();
    1493         151 :                 hParamMC->icld_q_fx[L_sub( L_mult0( add( k, 1 ), ild_map_size ), 1 )] = PARAM_MC_DEFAULT_MIN_ILD_FX; /* -92.0f in Q8 */
    1494         151 :                 move16();
    1495             :             }
    1496             :         }
    1497             : 
    1498       10216 :         *nb_bits = bit_pos;
    1499       10216 :         move16();
    1500             : 
    1501             :     } /* if ( !st->bfi ) */
    1502             : 
    1503       10249 :     IF( st->bfi )
    1504             :     {
    1505             :         /* for PLC, use the saved ILDs and ICCs from the past and set the transient flag and transient position to zero */
    1506          33 :         hMetadataPMC->bAttackPresent = 0;
    1507          33 :         move16();
    1508          33 :         hMetadataPMC->attackIndex = 0;
    1509          33 :         move16();
    1510             :     }
    1511             : 
    1512       10249 :     pop_wmops();
    1513             : 
    1514       10249 :     return;
    1515             : }
    1516             : 
    1517             : 
    1518             : /*-------------------------------------------------------------------------
    1519             :  * ivas_param_mc_dec_digest_tc()
    1520             :  *
    1521             :  *
    1522             :  *------------------------------------------------------------------------*/
    1523             : 
    1524       10229 : void ivas_param_mc_dec_digest_tc_fx(
    1525             :     Decoder_Struct *st_ivas,  /* i/o: IVAS decoder handle                                       */
    1526             :     const UWord8 nCldfbSlots, /* i  : number of CLFBS slots in the transport channels           */
    1527             :     Word32 *transport_channels_f_fx[],
    1528             :     Word16 transport_f_e )
    1529             : {
    1530             :     PARAM_MC_DEC_HANDLE hParamMC;
    1531             :     Word16 i, ch;
    1532             :     Word16 is_next_band, skip_next_band;
    1533             :     Word16 slot_idx, param_band_idx;
    1534             :     Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb;
    1535             :     Word16 nchan_out_cov;
    1536             :     /*CLDFB*/
    1537             :     /* format converter */
    1538             :     Word16 channel_active[MAX_OUTPUT_CHANNELS];
    1539             :     IVAS_OUTPUT_SETUP *hSynthesisOutputSetup;
    1540             : 
    1541       10229 :     hParamMC = st_ivas->hParamMC;
    1542       10229 :     assert( hParamMC );
    1543             :     Word32 *pCx, *pCx_imag;
    1544             :     Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];                // Q(31 - cx_e)
    1545             :     Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];           // Q(31 - cx_imag_e)
    1546             :     Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];      // Q(31 - cx_next_band_e)
    1547             :     Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_next_band_e)
    1548             : 
    1549             :     Word16 cx_buff_e[2][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
    1550             :     Word16 cx_e;
    1551             :     Word16 cx_imag_e, tmp_e;
    1552             :     Word16 cx_imag_next_band_e, cx_next_band_e;
    1553       10229 :     Word16 qout = 0;
    1554       10229 :     move16();
    1555             : 
    1556             :     Word32 real_part_fx, imag_part_fx, L_tmp1, L_tmp2;
    1557             : 
    1558             :     Word16 max_e;
    1559             : 
    1560       10229 :     push_wmops( "param_mc_dec_digest_tc" );
    1561             : 
    1562       10229 :     set16_fx( channel_active, 0, MAX_CICP_CHANNELS );
    1563       10229 :     nchan_transport = st_ivas->nchan_transport;
    1564       10229 :     move16();
    1565       10229 :     nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    1566             : 
    1567       10229 :     test();
    1568       10229 :     test();
    1569       10229 :     IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    1570             :     {
    1571        8239 :         nchan_out_cldfb = BINAURAL_CHANNELS;
    1572        8239 :         move16();
    1573        8239 :         set16_fx( channel_active, 1, nchan_out_cldfb );
    1574        8239 :         nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    1575        8239 :         hSynthesisOutputSetup = &st_ivas->hTransSetup;
    1576             :     }
    1577        1990 :     ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
    1578             :     {
    1579         340 :         nchan_out_cov = nchan_out_transport;
    1580         340 :         move16();
    1581         340 :         nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    1582         340 :         hSynthesisOutputSetup = &st_ivas->hTransSetup;
    1583             :     }
    1584        1650 :     ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
    1585             :     {
    1586         150 :         nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    1587         150 :         nchan_out_cldfb = nchan_out_cov;
    1588         150 :         move16();
    1589         150 :         set16_fx( channel_active, 1, nchan_out_cov );
    1590         150 :         hSynthesisOutputSetup = &st_ivas->hOutSetup;
    1591             :     }
    1592             :     ELSE
    1593             :     {
    1594        1500 :         nchan_out_cov = nchan_out_transport;
    1595        1500 :         move16();
    1596        1500 :         nchan_out_cldfb = nchan_out_transport;
    1597        1500 :         move16();
    1598        1500 :         set16_fx( channel_active, 1, nchan_out_cov );
    1599        1500 :         hSynthesisOutputSetup = &st_ivas->hTransSetup;
    1600             :     }
    1601             : 
    1602             :     /* adapt transient position */
    1603       10229 :     IF( hParamMC->hMetadataPMC->bAttackPresent )
    1604             :     {
    1605         487 :         hParamMC->hMetadataPMC->attackIndex = s_max( 0, add( hParamMC->hMetadataPMC->attackIndex, shr( sub( nCldfbSlots, DEFAULT_JBM_CLDFB_TIMESLOTS ), 1 ) ) );
    1606         487 :         move16();
    1607             :     }
    1608             :     /* adapt subframes */
    1609       10229 :     hParamMC->num_slots = nCldfbSlots;
    1610       10229 :     move16();
    1611       10229 :     hParamMC->slots_rendered = 0;
    1612       10229 :     move16();
    1613       10229 :     hParamMC->subframes_rendered = 0;
    1614       10229 :     move16();
    1615       10229 :     ivas_jbm_dec_get_adapted_subframes( nCldfbSlots, hParamMC->subframe_nbslots, &hParamMC->nb_subframes );
    1616       10229 :     st_ivas->hTcBuffer->nb_subframes = hParamMC->nb_subframes;
    1617       10229 :     move16();
    1618       10229 :     Copy( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes );
    1619             : 
    1620       10229 :     ivas_param_mc_dec_compute_interpolator_fx( hParamMC->hMetadataPMC->bAttackPresent, hParamMC->hMetadataPMC->attackIndex, nCldfbSlots, hParamMC->h_output_synthesis_params.interpolator_fx );
    1621             : 
    1622             :     /* loop over two bands at a time */
    1623       77492 :     FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 )
    1624             :     {
    1625             :         /* don't process next band if it exceeds the limit */
    1626       67263 :         skip_next_band = ( ( param_band_idx + 1 ) == hParamMC->num_param_bands_synth ) ? 1 : 0;
    1627             : 
    1628       67263 :         set_zero_fx( cx_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
    1629       67263 :         set_zero_fx( cx_imag_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
    1630       67263 :         set_zero_fx( cx_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
    1631       67263 :         set_zero_fx( cx_imag_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
    1632             : 
    1633       67263 :         cx_e = 0;
    1634       67263 :         move16();
    1635       67263 :         cx_imag_e = 0;
    1636       67263 :         move16();
    1637       67263 :         cx_next_band_e = 0;
    1638       67263 :         move16();
    1639       67263 :         cx_imag_next_band_e = 0;
    1640       67263 :         move16();
    1641             :         /* slot loop for gathering the input data */
    1642     1143486 :         FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
    1643             :         {
    1644     1076223 :             IF( st_ivas->hDecoderConfig->Opt_tsm )
    1645             :             {
    1646        4495 :                 IF( param_band_idx == 0 ) /* only run cldfbAna once */
    1647             :                 {
    1648             :                     Word32 RealBuffer_fx[CLDFB_NO_CHANNELS_MAX];
    1649             :                     Word32 ImagBuffer_fx[CLDFB_NO_CHANNELS_MAX];
    1650             : 
    1651             :                     /* CLDFB Analysis*/
    1652        2089 :                     FOR( ch = 0; ch < nchan_transport; ch++ )
    1653             :                     {
    1654        1446 :                         qout = transport_f_e;
    1655        1446 :                         move16();
    1656        1446 :                         cldfbAnalysis_ts_fx_fixed_q( &( transport_channels_f_fx[ch][hParamMC->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hParamMC->num_freq_bands, st_ivas->cldfbAnaDec[ch], &qout );
    1657             : 
    1658        1446 :                         Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands );
    1659        1446 :                         Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands );
    1660             :                     }
    1661             : 
    1662         643 :                     hParamMC->Cldfb_ImagBuffer_tc_e = qout;
    1663         643 :                     move16();
    1664             :                 }
    1665             :             }
    1666     1076223 :             IF( GE_16( slot_idx, shl( hParamMC->hMetadataPMC->attackIndex, 1 ) ) )
    1667             :             {
    1668     3166671 :                 FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
    1669             :                 {
    1670     2111114 :                     test();
    1671     2111114 :                     IF( is_next_band && skip_next_band )
    1672             :                     {
    1673       27003 :                         CONTINUE;
    1674             :                     }
    1675     2084111 :                     IF( is_next_band )
    1676             :                     {
    1677     2057108 :                         ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
    1678             :                                                                                       /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
    1679     1028554 :                                                                                       &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
    1680             :                                                                                       /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
    1681             :                                                                                       cx_next_band_fx,
    1682             :                                                                                       &cx_next_band_e,
    1683             :                                                                                       cx_imag_next_band_fx,
    1684             :                                                                                       &cx_imag_next_band_e,
    1685             :                                                                                       hParamMC,
    1686     1028554 :                                                                                       add( param_band_idx, is_next_band ),
    1687             :                                                                                       nchan_transport );
    1688             :                     }
    1689             :                     ELSE
    1690             :                     {
    1691     2111114 :                         ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
    1692             :                                                                                       /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
    1693     1055557 :                                                                                       &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
    1694             :                                                                                       /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
    1695             :                                                                                       cx_fx,
    1696             :                                                                                       &cx_e,
    1697             :                                                                                       cx_imag_fx,
    1698             :                                                                                       &cx_imag_e,
    1699             :                                                                                       hParamMC,
    1700     1055557 :                                                                                       add( param_band_idx, is_next_band ),
    1701             :                                                                                       nchan_transport );
    1702             :                     }
    1703             :                 }
    1704             :             }
    1705             :         }
    1706             : 
    1707             :         Word16 tmp_cx_e, tmp_cx_imag_e;
    1708             :         /* map from complex input covariance to real values */
    1709      201789 :         FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
    1710             :         {
    1711      134526 :             test();
    1712      134526 :             IF( is_next_band && skip_next_band )
    1713             :             {
    1714        1739 :                 CONTINUE;
    1715             :             }
    1716             :             /* Cx for transport channels */
    1717      132787 :             IF( is_next_band )
    1718             :             {
    1719       65524 :                 pCx = &cx_next_band_fx[0];
    1720       65524 :                 pCx_imag = &cx_imag_next_band_fx[0];
    1721       65524 :                 tmp_cx_e = cx_next_band_e;
    1722       65524 :                 tmp_cx_imag_e = cx_imag_next_band_e;
    1723             :             }
    1724             :             ELSE
    1725             :             {
    1726       67263 :                 pCx = &cx_fx[0];
    1727       67263 :                 pCx_imag = &cx_imag_fx[0];
    1728       67263 :                 tmp_cx_e = cx_e;
    1729       67263 :                 tmp_cx_imag_e = cx_imag_e;
    1730             :             }
    1731             : 
    1732      670735 :             FOR( i = 0; i < nchan_transport * nchan_transport; i++ )
    1733             :             {
    1734      537948 :                 real_part_fx = pCx[i]; // Q(31 - cx_buff_e)
    1735      537948 :                 imag_part_fx = pCx_imag[i];
    1736      537948 :                 move32();
    1737      537948 :                 move32();
    1738      537948 :                 cx_buff_e[is_next_band][i] = tmp_cx_e;
    1739      537948 :                 move16();
    1740             :                 /* (a-ib)(c+id) = ac + bd + i(ad-bc) */
    1741      537948 :                 IF( LT_16( param_band_idx, hParamMC->max_param_band_abs_cov ) )
    1742             :                 {
    1743      316108 :                     L_tmp1 = Mpy_32_32( real_part_fx, real_part_fx );
    1744      316108 :                     L_tmp2 = Mpy_32_32( imag_part_fx, imag_part_fx );
    1745      316108 :                     L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp1, add( tmp_cx_e, tmp_cx_e ), L_tmp2, add( tmp_cx_imag_e, tmp_cx_imag_e ), &tmp_e );
    1746      316108 :                     pCx[i] = Sqrt32( L_tmp1, &tmp_e );
    1747      316108 :                     move32();
    1748      316108 :                     cx_buff_e[is_next_band][i] = tmp_e;
    1749      316108 :                     move16();
    1750             :                 }
    1751             :                 ELSE
    1752             :                 {
    1753      221840 :                     pCx[i] = real_part_fx;
    1754      221840 :                     move32();
    1755      221840 :                     cx_buff_e[is_next_band][i] = tmp_cx_e;
    1756      221840 :                     move16();
    1757             :                 }
    1758             :             }
    1759             :         }
    1760             : 
    1761       67263 :         max_e = cx_buff_e[0][0];
    1762       67263 :         move16();
    1763             : 
    1764             :         /* Cx for transport channels */
    1765      201789 :         FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
    1766             :         {
    1767      679430 :             FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
    1768             :             {
    1769             : 
    1770      544904 :                 IF( LT_16( max_e, cx_buff_e[is_next_band][i] ) )
    1771             :                 {
    1772       47061 :                     max_e = cx_buff_e[is_next_band][i];
    1773             :                 }
    1774             :             }
    1775             :         }
    1776             :         /* Cx for transport channels */
    1777      201789 :         FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
    1778             :         {
    1779      679430 :             FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
    1780             :             {
    1781      544904 :                 if ( is_next_band == 0 )
    1782             :                 {
    1783      272452 :                     cx_fx[i] = L_shr( cx_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
    1784             :                 }
    1785             :                 else
    1786             :                 {
    1787      272452 :                     cx_next_band_fx[i] = L_shr( cx_next_band_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
    1788             :                 }
    1789      544904 :                 move32();
    1790             :             }
    1791             :         }
    1792       67263 :         cx_e = max_e;
    1793       67263 :         move16();
    1794             : 
    1795             : 
    1796             :         /* we have to do it similar to the encoder in case of attacks (i.e. accumulate two bands) to ensure correct DMX of the target covariance*/
    1797             : 
    1798       67263 :         test();
    1799       67263 :         test();
    1800       67263 :         IF( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) )
    1801             :         {
    1802             : #ifdef NONBE_SVD_OPTIMIZATION
    1803          98 :             Word16 len = imult1616( nchan_transport, nchan_transport );
    1804          98 :             Word16 sc = s_min( getScaleFactor32( cx_fx, len ), getScaleFactor32( cx_next_band_fx, len ) );
    1805          98 :             IF( EQ_16( sc, 0 ) )
    1806             :             {
    1807          98 :                 Scale_sig32( cx_fx, len, -Q1 );           // add one bit head room
    1808          98 :                 Scale_sig32( cx_next_band_fx, len, -Q1 ); // add one bit head room
    1809          98 :                 cx_e = add( cx_e, Q1 );
    1810          98 :                 cx_next_band_e = add( cx_e, Q1 );
    1811             :             }
    1812          98 :             v_add_fx( cx_fx, cx_next_band_fx, cx_fx, len );
    1813          98 :             Copy32( cx_fx, cx_next_band_fx, len );
    1814             : #else
    1815             :             v_add_fx( cx_fx, cx_next_band_fx, cx_fx, imult1616( nchan_transport, nchan_transport ) );
    1816             :             Copy32( cx_fx, cx_next_band_fx, imult1616( nchan_transport, nchan_transport ) );
    1817             : #endif
    1818             :         }
    1819             : 
    1820      201789 :         FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
    1821             :         {
    1822      134526 :             test();
    1823      134526 :             IF( is_next_band && skip_next_band )
    1824             :             {
    1825        1739 :                 CONTINUE;
    1826             :             }
    1827             : 
    1828      132787 :             IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
    1829             :             {
    1830      132787 :                 IF( is_next_band )
    1831             :                 {
    1832             : 
    1833       65524 :                     ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_next_band_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
    1834             :                 }
    1835             :                 ELSE
    1836             :                 {
    1837             : 
    1838       67263 :                     ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
    1839             :                 }
    1840             :             }
    1841             :         }
    1842             :     }
    1843       10229 :     pop_wmops();
    1844             : 
    1845       10229 :     return;
    1846             : }
    1847             : 
    1848             : 
    1849             : /*-------------------------------------------------------------------------
    1850             :  * ivas_param_mc_dec()
    1851             :  *
    1852             :  * Parametric MC decoding process
    1853             :  *------------------------------------------------------------------------*/
    1854             : 
    1855       10260 : void ivas_param_mc_dec_render_fx(
    1856             :     Decoder_Struct *st_ivas,        /* i/o: IVAS decoder handle                                     */
    1857             :     const UWord16 nSamplesAsked,    /* i  : number of CLDFB slots requested                         */
    1858             :     UWord16 *nSamplesRendered,      /* o  : number of CLDFB slots rendered                          */
    1859             :     UWord16 *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render                   */
    1860             :     Word32 *output_f_fx[],          /* o  : rendered time signal                                    Q11*/
    1861             :     Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] )
    1862             : {
    1863             :     PARAM_MC_DEC_HANDLE hParamMC;
    1864             :     Word16 i, ch;
    1865             :     Word16 subframe_idx;
    1866             :     Word16 slot_idx, slot_idx_start, slot_idx_start_cldfb_synth, first_sf, last_sf, slots_to_render;
    1867             :     Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb;
    1868             :     Word16 nchan_out_cov;
    1869             : 
    1870             :     /*CLDFB*/
    1871             :     Word32 Cldfb_RealBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    1872             :     Word32 Cldfb_ImagBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    1873             :     Word32 Cldfb_RealBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    1874             :     Word32 Cldfb_ImagBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    1875             :     Word32 *p_output_f_fx[MAX_OUTPUT_CHANNELS];
    1876      174420 :     FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
    1877             :     {
    1878      164160 :         p_output_f_fx[i] = output_f_fx[i]; // Q11
    1879             :     }
    1880             :     /*Decorrelator*/
    1881             :     Word32 onset_filter_fx[MAX_CICP_CHANNELS * CLDFB_NO_CHANNELS_MAX]; // Q31
    1882             : 
    1883             :     /* format converter */
    1884             :     Word16 channel_active[MAX_OUTPUT_CHANNELS];
    1885             :     UWord16 nband_synth;
    1886             :     UWord32 output_Fs;
    1887       10260 :     Word16 tmp_q = 0;
    1888       10260 :     move16();
    1889             : 
    1890       10260 :     hParamMC = st_ivas->hParamMC;
    1891       10260 :     assert( hParamMC );
    1892             : 
    1893       10260 :     push_wmops( "param_mc_dec_render" );
    1894             : 
    1895       10260 :     set16_fx( channel_active, 0, MAX_CICP_CHANNELS );
    1896       10260 :     nchan_transport = st_ivas->nchan_transport;
    1897       10260 :     move16();
    1898       10260 :     nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    1899       10260 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
    1900       10260 :     move32();
    1901             : 
    1902       10260 :     test();
    1903       10260 :     test();
    1904       10260 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    1905             :     {
    1906        8270 :         nchan_out_cldfb = BINAURAL_CHANNELS;
    1907        8270 :         set16_fx( channel_active, 1, nchan_out_cldfb );
    1908        8270 :         nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    1909             :     }
    1910        1990 :     ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
    1911             :     {
    1912         340 :         nchan_out_cov = nchan_out_transport;
    1913         340 :         move16();
    1914         340 :         nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    1915             :     }
    1916        1650 :     ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
    1917             :     {
    1918         150 :         nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    1919         150 :         nchan_out_cldfb = nchan_out_cov;
    1920         150 :         move16();
    1921         150 :         set16_fx( channel_active, 1, nchan_out_cov );
    1922             :     }
    1923             :     ELSE
    1924             :     {
    1925        1500 :         nchan_out_cov = nchan_out_transport;
    1926        1500 :         move16();
    1927        1500 :         nchan_out_cldfb = nchan_out_transport;
    1928        1500 :         move16();
    1929        1500 :         set16_fx( channel_active, 1, nchan_out_cov );
    1930             :     }
    1931             : 
    1932             :     /* set everything to zero that will not be decoded */
    1933       10260 :     nband_synth = hParamMC->band_grouping[hParamMC->num_param_bands_synth];
    1934       10260 :     move16();
    1935      174420 :     FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
    1936             :     {
    1937      820800 :         FOR( slot_idx = 0; slot_idx < JBM_CLDFB_SLOTS_IN_SUBFRAME; slot_idx++ )
    1938             :         {
    1939      656640 :             set32_fx( &( Cldfb_RealBuffer_fx[ch][slot_idx][0] ), 0, CLDFB_NO_CHANNELS_MAX );
    1940      656640 :             set32_fx( &( Cldfb_ImagBuffer_fx[ch][slot_idx][0] ), 0, CLDFB_NO_CHANNELS_MAX );
    1941             :         }
    1942             :     }
    1943             : 
    1944             :     /* loop FOR synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    1945             :     /*slots_to_render = min(sub(hParamMC->num_slots, hParamMC->slots_rendered), nSamplesAsked / NS2SA(output_Fs, CLDFB_SLOT_NS));
    1946             :      *nSamplesRendered = slots_to_render * NS2SA(output_Fs, CLDFB_SLOT_NS);*/
    1947             :     Word16 temp_e;
    1948       10260 :     Word16 temp = BASOP_Util_Divide1616_Scale( nSamplesAsked, NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ), &temp_e );
    1949       10260 :     temp = shr( temp, sub( 15, temp_e ) );
    1950       10260 :     slots_to_render = s_min( sub( hParamMC->num_slots, hParamMC->slots_rendered ), temp );
    1951       10260 :     *nSamplesRendered = imult1616( slots_to_render, NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ) );
    1952       10260 :     move16();
    1953             :     Word16 j, k;
    1954       10260 :     first_sf = hParamMC->subframes_rendered;
    1955       10260 :     move16();
    1956       10260 :     last_sf = first_sf;
    1957       10260 :     move16();
    1958       51207 :     WHILE( slots_to_render > 0 )
    1959             :     {
    1960       40947 :         slots_to_render = sub( slots_to_render, hParamMC->subframe_nbslots[last_sf] );
    1961       40947 :         last_sf = add( last_sf, 1 );
    1962             :     }
    1963       10260 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    1964             :     {
    1965        1800 :         FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    1966             :         {
    1967        1440 :             slots_to_render = add( slots_to_render, hParamMC->subframe_nbslots[subframe_idx] );
    1968             :         }
    1969             :     }
    1970       10260 :     slot_idx_start = hParamMC->slots_rendered;
    1971       10260 :     move16();
    1972       10260 :     slot_idx_start_cldfb_synth = 0;
    1973       10260 :     move16();
    1974             : 
    1975      145687 :     FOR( j = 0; j < st_ivas->hParamMC->hMetadataPMC->nbands_coded; j++ )
    1976             :     {
    1977      135427 :         Flag is_zero = is_zero_arr( hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[j], hParamMC->h_output_synthesis_cov_state.mixing_matrix_len );
    1978             :         {
    1979      135427 :             if ( is_zero != 0 )
    1980             :             {
    1981        2191 :                 hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[j] = 0;
    1982        2191 :                 move16();
    1983             :             }
    1984             :         }
    1985      135427 :         IF( LT_16( st_ivas->hParamMC->band_grouping[j], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
    1986             :         {
    1987      107217 :             is_zero = is_zero_arr( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[j], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len );
    1988      107217 :             if ( is_zero != 0 )
    1989             :             {
    1990          45 :                 hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[j] = 0;
    1991          45 :                 move16();
    1992             :             }
    1993             :         }
    1994             :     }
    1995       51207 :     FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    1996             :     {
    1997      204614 :         FOR( slot_idx = 0; slot_idx < hParamMC->subframe_nbslots[subframe_idx]; ( slot_idx++, hParamMC->slots_rendered++ ) )
    1998             :         {
    1999      163667 :             IF( hParamMC->max_band_decorr > 0 )
    2000             :             {
    2001             :                 /*-----------------------------------------------------------------*
    2002             :                  * protoype signal computation
    2003             :                  *-----------------------------------------------------------------*/
    2004      163667 :                 param_mc_protoSignalComputation_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
    2005      163667 :                                                     &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
    2006      163667 :                                                     hParamMC->proto_frame_f_fx, hParamMC->diff_proto_info,
    2007      163667 :                                                     hParamMC->num_freq_bands, hParamMC->Cldfb_RealBuffer_tc_e, &hParamMC->proto_frame_f_fx_q );
    2008             :                 /*-----------------------------------------------------------------*
    2009             :                  * frequency domain decorrelation
    2010             :                  *-----------------------------------------------------------------*/
    2011             :                 /* decorrelate prototype frame */
    2012             : 
    2013      163667 :                 ivas_dirac_dec_decorr_process_fx( hParamMC->num_freq_bands,
    2014      163667 :                                                   hParamMC->num_outputs_diff,
    2015      163667 :                                                   hParamMC->diff_proto_info->num_protos_diff,
    2016             :                                                   DIRAC_SYNTHESIS_COV_MC_LS,
    2017             :                                                   nchan_transport,
    2018      163667 :                                                   hParamMC->proto_frame_f_fx,
    2019      163667 :                                                   hParamMC->proto_frame_f_fx_q,
    2020      163667 :                                                   hParamMC->diff_proto_info->num_protos_diff,
    2021      163667 :                                                   hParamMC->diff_proto_info->proto_index_diff,
    2022             :                                                   hParamMC->proto_frame_dec_f_fx, // output
    2023             :                                                   &tmp_q,
    2024             :                                                   onset_filter_fx,
    2025             :                                                   hParamMC->h_freq_domain_decorr_ap_params,
    2026             :                                                   hParamMC->h_freq_domain_decorr_ap_state );
    2027             : 
    2028             :                 /* copy decorrelated frame directly to output CLDFB buffer, acts also as intermediate */
    2029             :                 /* memory FOR the decorrelated signal                                                 */
    2030      163667 :                 ivas_param_mc_dec_copy_diffuse_proto( hParamMC, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nchan_out_cov, slot_idx ); // Returns Cldfb buffers in Q11(tmp_q)
    2031             : 
    2032     1163275 :                 FOR( k = 0; k < nchan_out_cov; k++ )
    2033             :                 {
    2034    20991768 :                     FOR( Word16 l = 0; l < hParamMC->h_output_synthesis_params.max_band_decorr; l++ )
    2035             :                     {
    2036    19992160 :                         Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6
    2037    19992160 :                         move32();
    2038    19992160 :                         Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6
    2039    19992160 :                         move32();
    2040             :                     }
    2041             :                 }
    2042             :             }
    2043             : 
    2044             :             /*-----------------------------------------------------------------*
    2045             :              * output synthesis
    2046             :              *-----------------------------------------------------------------*/
    2047      327334 :             ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx(
    2048      163667 :                 &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
    2049      163667 :                 &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, add( slot_idx, slot_idx_start ),
    2050             :                 nchan_transport, nchan_out_cov, hParamMC );
    2051             : 
    2052      163667 :             test();
    2053      163667 :             IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
    2054             :             {
    2055      131827 :                 test();
    2056      131827 :                 IF( st_ivas->hCombinedOrientationData && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
    2057       51523 :                 {
    2058             :                     Word16 Q_Cldfb_ImagBuffer, Q_Cldfb_RealBuffer;
    2059       51523 :                     Q_Cldfb_ImagBuffer = Q6 - 5; /*max value =MAX_INTERN_CHANNELS(=16)*Cldfb_ImagBuffer_fx*/
    2060       51523 :                     move16();
    2061       51523 :                     Q_Cldfb_RealBuffer = Q6 - 5;
    2062       51523 :                     move16();
    2063      875891 :                     FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
    2064             :                     {
    2065     4121840 :                         FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
    2066             :                         {
    2067     3297472 :                             Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_ImagBuffer, Q6 ) ); // Q1
    2068     3297472 :                             Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_RealBuffer, Q6 ) ); // Q1
    2069             :                         }
    2070             :                     }
    2071       51523 :                     ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hParamMC->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nband_synth, GAIN_LFE_FX );
    2072      875891 :                     FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
    2073             :                     {
    2074     4121840 :                         FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
    2075             :                         {
    2076     3297472 :                             Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_ImagBuffer ) ); // Q6
    2077     3297472 :                             Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_RealBuffer ) ); // Q6
    2078             :                         }
    2079             :                     }
    2080             :                 }
    2081             :                 ELSE
    2082             :                 {
    2083             :                     /* remove LFE */
    2084             :                     UWord16 idx_out;
    2085             :                     UWord16 idx_lfe;
    2086             :                     IVAS_OUTPUT_SETUP hLsSetup;
    2087             : 
    2088       80304 :                     hLsSetup = st_ivas->hTransSetup;
    2089             :                     /* If LFE should be rendered, add it to other channels before removing */
    2090       80304 :                     IF( st_ivas->hBinRenderer->render_lfe )
    2091             :                     {
    2092       80304 :                         Word16 tmp_exp = 0;
    2093       80304 :                         move16();
    2094       80304 :                         Word16 tmp = BASOP_Util_Divide1616_Scale( GAIN_LFE_FX, hLsSetup.nchan_out_woLFE, &tmp_exp );
    2095       80304 :                         tmp_exp = add( tmp_exp, ( 1 - 15 ) );
    2096      160608 :                         FOR( idx_lfe = 0; idx_lfe < hLsSetup.num_lfe; idx_lfe++ )
    2097             :                         {
    2098             :                             /* Copy just the first band of LFE*/
    2099       80304 :                             v_multc_fixed_16( Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], tmp, Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1 );
    2100       80304 :                             v_multc_fixed_16( Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], tmp, Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1 );
    2101             : 
    2102       80304 :                             Scale_sig32( Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1, tmp_exp );
    2103       80304 :                             Scale_sig32( Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1, tmp_exp );
    2104      565008 :                             FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ )
    2105             :                             {
    2106      484704 :                                 IF( hLsSetup.index_lfe[idx_lfe] != ch )
    2107             :                                 {
    2108      404400 :                                     v_add_fixed_no_hdrm( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_RealBuffer_fx[ch][slot_idx], 1 );
    2109      404400 :                                     v_add_fixed_no_hdrm( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], 1 );
    2110             :                                 }
    2111             :                             }
    2112             :                         }
    2113             :                     }
    2114             : 
    2115       80304 :                     idx_out = 0;
    2116       80304 :                     move16();
    2117       80304 :                     idx_lfe = 0;
    2118       80304 :                     move16();
    2119             : 
    2120      565008 :                     FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ )
    2121             :                     {
    2122      484704 :                         test();
    2123      484704 :                         IF( ( hLsSetup.num_lfe > 0 ) && EQ_16( hLsSetup.index_lfe[idx_lfe], ch ) )
    2124             :                         {
    2125       80304 :                             IF( LT_16( idx_lfe, ( sub( hLsSetup.num_lfe, 1 ) ) ) )
    2126             :                             {
    2127           0 :                                 idx_lfe = add( idx_lfe, 1 );
    2128             :                             }
    2129             :                         }
    2130      404400 :                         ELSE IF( NE_16( ch, idx_out ) )
    2131             :                         {
    2132      163488 :                             Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[idx_out][slot_idx], nband_synth );
    2133      163488 :                             Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[idx_out][slot_idx], nband_synth );
    2134      163488 :                             idx_out = add( idx_out, 1 );
    2135             :                         }
    2136             :                         ELSE
    2137             :                         {
    2138      240912 :                             idx_out = add( idx_out, 1 );
    2139             :                         }
    2140             :                     }
    2141             :                 }
    2142             :             }
    2143             :         }
    2144             : 
    2145       40947 :         test();
    2146       40947 :         IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    2147       32987 :         {
    2148       32987 :             Word16 input_q = 6;
    2149       32987 :             move16();
    2150             : 
    2151       32987 :             IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    2152             :             {
    2153           0 :                 IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
    2154             :                 {
    2155           0 :                     FOR( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
    2156             :                     {
    2157           0 :                         FOR( ch = 0; ch < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ); ch++ )
    2158             :                         {
    2159           0 :                             Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
    2160           0 :                             Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
    2161             :                         }
    2162             :                     }
    2163           0 :                     st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
    2164           0 :                     move16();
    2165             :                 }
    2166             :             }
    2167             : 
    2168             :             /* Implement binaural rendering */
    2169             :             /*Binaural output in Q6 format*/
    2170       32987 :             ivas_binRenderer_fx( st_ivas->hBinRenderer,
    2171           0 :                                  ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
    2172             :                                  st_ivas->hCombinedOrientationData,
    2173       32987 :                                  hParamMC->subframe_nbslots[subframe_idx],
    2174             :                                  Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
    2175             :                                  Cldfb_RealBuffer_fx,
    2176             :                                  Cldfb_ImagBuffer_fx, &input_q );
    2177             : 
    2178      560779 :             FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
    2179             :             {
    2180     2638960 :                 FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
    2181             :                 {
    2182   128781248 :                     FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
    2183             :                     {
    2184   126670080 :                         Cldfb_RealBuffer_fx[i][j][k] = L_shl( Cldfb_RealBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
    2185   126670080 :                         Cldfb_ImagBuffer_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
    2186             :                     }
    2187             :                 }
    2188             :             }
    2189             : 
    2190             :             Word16 pos_idx;
    2191       32987 :             IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    2192             :             {
    2193           0 :                 FOR( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
    2194             :                 {
    2195           0 :                     FOR( slot_idx = 0; slot_idx < hParamMC->subframe_nbslots[subframe_idx]; slot_idx++ )
    2196             :                     {
    2197           0 :                         FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
    2198             :                         {
    2199           0 :                             Copy32( Cldfb_RealBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
    2200           0 :                             Copy32( Cldfb_ImagBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
    2201             :                         }
    2202             :                     }
    2203             :                 }
    2204             :             }
    2205             :             /* update combined orientation access index */
    2206       32987 :             ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx] );
    2207             :         }
    2208        7960 :         ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
    2209             :         {
    2210             :             /* format conversion*/
    2211        1360 :             ivas_lssetupconversion_process_param_mc_fx( st_ivas, hParamMC->subframe_nbslots[subframe_idx], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, channel_active );
    2212             :         }
    2213             : 
    2214             : 
    2215             :         /* CLDFB synthesis */
    2216      164761 :         FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
    2217             :         {
    2218             :             Word32 *RealBuffer_fx[16];
    2219             :             Word32 *ImagBuffer_fx[16];
    2220             : 
    2221      123814 :             IF( channel_active[ch] )
    2222             :             {
    2223             :                 /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands FOR 48kHz */
    2224      578028 :                 FOR( i = 0; i < hParamMC->subframe_nbslots[subframe_idx]; i++ )
    2225             :                 {
    2226      462374 :                     IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    2227             :                     {
    2228      263654 :                         RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[0][ch][i]; // Q6
    2229      263654 :                         ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[0][ch][i]; // Q6
    2230             :                     }
    2231             :                     ELSE
    2232             :                     {
    2233      198720 :                         RealBuffer_fx[i] = Cldfb_RealBuffer_fx[ch][i]; // Q6
    2234      198720 :                         ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[ch][i]; // Q6
    2235             :                     }
    2236             :                 }
    2237             : 
    2238      115654 :                 Word16 len = add( imult1616( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) );
    2239      115654 :                 scale_sig32( output_f_fx[ch], len, 5 - 11 );
    2240      115654 :                 cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ),
    2241      115654 :                                         imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ), 0, 0, st_ivas->cldfbSynDec[ch] );
    2242             : 
    2243      115654 :                 scale_sig32( output_f_fx[ch], len, 11 - 5 ); // Q11
    2244             :             }
    2245             :             ELSE
    2246             :             {
    2247        8160 :                 set32_fx( &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), 0, imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) );
    2248             :             }
    2249             :         }
    2250       40947 :         slot_idx_start = add( slot_idx_start, hParamMC->subframe_nbslots[subframe_idx] );
    2251       40947 :         slot_idx_start_cldfb_synth = add( slot_idx_start_cldfb_synth, hParamMC->subframe_nbslots[subframe_idx] );
    2252             :     }
    2253       10260 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    2254             :     {
    2255         360 :         ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_f_fx, p_output_f_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
    2256             :     }
    2257             : 
    2258             :     /* update */
    2259             : 
    2260       10260 :     IF( EQ_16( hParamMC->slots_rendered, hParamMC->num_slots ) )
    2261             :     {
    2262       10229 :         hParamMC->hMetadataPMC->last_coded_bwidth = hParamMC->hMetadataPMC->coded_bwidth;
    2263       10229 :         move16();
    2264       10229 :         param_mc_update_mixing_matrices_fx( hParamMC, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_transport, nchan_out_cov );
    2265             :     }
    2266             : 
    2267             : 
    2268       10260 :     hParamMC->subframes_rendered = last_sf;
    2269       10260 :     move16();
    2270       10260 :     *nSamplesAvailableNext = imult1616( sub( hParamMC->num_slots, hParamMC->slots_rendered ), NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ) );
    2271       10260 :     move16();
    2272             : 
    2273      174420 :     FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
    2274             :     {
    2275      164160 :         channel_active_fx[i] = channel_active[i];
    2276      164160 :         move16();
    2277             :     }
    2278       10260 :     pop_wmops();
    2279             : 
    2280       10260 :     return;
    2281             : }
    2282             : 
    2283             : /*-------------------------------------------------------------------------
    2284             :  * param_mc_dec_init()
    2285             :  *
    2286             :  * Parametric MC decoding initialization
    2287             :  *------------------------------------------------------------------------*/
    2288             : 
    2289         279 : static void ivas_param_mc_dec_init_fx(
    2290             :     PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle                 */
    2291             :     const Word16 nchan_transport, /* i  : number of input (transport) channels */
    2292             :     const Word16 nchan_cov )      /* i  : number of cov synthesis channels     */
    2293             : {
    2294             :     Word16 k;
    2295             :     UWord16 max_param_band_residual;
    2296             :     Word16 len;
    2297             : 
    2298             :     /*-----------------------------------------------------------------*
    2299             :      * init sub-modules
    2300             :      *-----------------------------------------------------------------*/
    2301             : 
    2302             :     /* decorrelation */
    2303         279 :     IF( hParamMC->max_band_decorr > 0 )
    2304             :     {
    2305         277 :         len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr );
    2306             : 
    2307             :         /* init onsetDetectionPower */
    2308         277 :         set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len );
    2309         277 :         set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len );
    2310         277 :         hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31;
    2311         277 :         move16();
    2312             :     }
    2313             : 
    2314         279 :     max_param_band_residual = 0;
    2315         279 :     move16();
    2316             : 
    2317             :     /* output synthesis */
    2318        1006 :     FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
    2319             :     {
    2320        1006 :         IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
    2321             :         {
    2322         279 :             max_param_band_residual = k;
    2323         279 :             move16();
    2324         279 :             BREAK;
    2325             :         }
    2326             :     }
    2327             : 
    2328         279 :     ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual );
    2329             : 
    2330             :     /*-----------------------------------------------------------------*
    2331             :      * init proto frames
    2332             :      *-----------------------------------------------------------------*/
    2333             : 
    2334         279 :     IF( hParamMC->max_band_decorr > 0 )
    2335             :     {
    2336         277 :         set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) );
    2337         277 :         set32_fx( hParamMC->proto_frame_dec_f_fx, 0, shl( imult1616( nchan_cov, hParamMC->num_freq_bands ), 1 ) );
    2338             :     }
    2339             : 
    2340         279 :     return;
    2341             : }
    2342             : 
    2343             : 
    2344             : /*-------------------------------------------------------------------------
    2345             :  * Local functions
    2346             :  *-------------------------------------------------------------------------*/
    2347             : 
    2348             : 
    2349             : /*-------------------------------------------------------------------------
    2350             :  * ivas_param_mc_dec_compute_diffuse_proto()
    2351             :  *
    2352             :  * Compute prototypes for decorrelation
    2353             :  *------------------------------------------------------------------------*/
    2354             : 
    2355      163667 : static void param_mc_protoSignalComputation_fx(
    2356             :     Word32 *RealBuffer_fx,                           /* i  : CLDFB samples of the transport channels (real part)      */
    2357             :     Word32 *ImagBuffer_fx,                           /* i  : CLDFB samples of the transport channels (imaginary part) */
    2358             :     Word32 *proto_frame_f_fx,                        /* o  : interleaved complex prototype CLDFB samples              */
    2359             :     const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, /* i  : prototype generation information                         */
    2360             :     const Word16 num_freq_bands,                     /* i  : number of frequency bands for the prototypes             */
    2361             :     const Word16 Cldfb_Real_Imag_exp,                /*i: Exponent of real and imag buffers */
    2362             :     Word16 *proto_frame_f_fx_q )
    2363             : {
    2364             :     Word16 band;
    2365             :     Word16 proto_ch_idx, source_ch_cnt;
    2366             : 
    2367             :     Word32 *p_proto_frame_fx;
    2368             :     Word32 *p_real_buffer_fx; // Q12
    2369             :     Word32 *p_imag_buffer_fx; // Q12
    2370             : 
    2371      163667 :     set32_fx( proto_frame_f_fx, 0, shl( imult1616( num_freq_bands, diff_proto_info->num_protos_diff ), 1 ) );
    2372             : 
    2373             : 
    2374      659468 :     FOR( proto_ch_idx = 0; proto_ch_idx < diff_proto_info->num_protos_diff; proto_ch_idx++ )
    2375             :     {
    2376      495801 :         Word16 num_source_ch = diff_proto_info->num_source_chan_diff[proto_ch_idx];
    2377      495801 :         move16();
    2378             : 
    2379     1153829 :         FOR( source_ch_cnt = 0; source_ch_cnt < num_source_ch; source_ch_cnt++ )
    2380             :         {
    2381             : 
    2382      658028 :             Word32 fac_fx = diff_proto_info->proto_fac_fx[proto_ch_idx][source_ch_cnt];
    2383      658028 :             move32();
    2384             : 
    2385      658028 :             Word16 source_ch_idx = diff_proto_info->source_chan_idx[proto_ch_idx][source_ch_cnt];
    2386      658028 :             move16();
    2387             : 
    2388      658028 :             p_proto_frame_fx = &proto_frame_f_fx[shl( imult1616( proto_ch_idx, num_freq_bands ), 1 )];
    2389      658028 :             p_real_buffer_fx = &RealBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
    2390      658028 :             p_imag_buffer_fx = &ImagBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
    2391             : 
    2392    37717068 :             FOR( band = 0; band < num_freq_bands; band++ )
    2393             :             {
    2394             : 
    2395    37059040 :                 Word32 tmp_x = L_shl( Mpy_32_32( fac_fx, ( *( p_real_buffer_fx++ ) ) ), 4 ); // Q(26 + 4 + 6 - 31)  :: Q5
    2396             : 
    2397    37059040 :                 *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
    2398    37059040 :                 move32();
    2399    37059040 :                 p_proto_frame_fx++;
    2400             : 
    2401    37059040 :                 tmp_x = L_shl( Mpy_32_32( fac_fx, ( *( p_imag_buffer_fx++ ) ) ), 4 ); // Q(26 + 4 + 6 - 31)  :: Q5
    2402             : 
    2403    37059040 :                 *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
    2404    37059040 :                 move32();
    2405    37059040 :                 p_proto_frame_fx++;
    2406             :             }
    2407      658028 :             *proto_frame_f_fx_q = sub( 30, Cldfb_Real_Imag_exp );
    2408      658028 :             move16();
    2409             :         }
    2410             :     }
    2411             : 
    2412      163667 :     return;
    2413             : }
    2414             : 
    2415             : /*-------------------------------------------------------------------------
    2416             :  * ivas_param_mc_dec_compute_diffuse_proto()
    2417             :  *
    2418             :  * Transfer decorrelated signals back from the decorrelator buffer to
    2419             :  * the buffers used in the final synthesis
    2420             :  *------------------------------------------------------------------------*/
    2421             : 
    2422      163667 : static void ivas_param_mc_dec_copy_diffuse_proto(
    2423             :     PARAM_MC_DEC_HANDLE hParamMC,                                                                           /* i  : Parametric MC handle                                      */
    2424             :     Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o  : CLDFB buffer used in the final synthesis (real part)      */
    2425             :     Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o  : CLDFB buffer used in the final synthesis (imaginary part) */
    2426             :     const Word16 nY,                                                                                        /* i  : number of decorrelated channels                           */
    2427             :     const Word16 slot_idx                                                                                   /* i  : current time slot index                                   */
    2428             : )
    2429             : {
    2430             :     Word16 k, l;
    2431             :     Word16 num_freq_bands, num_freq_bands_diff;
    2432             :     Word32 *p_proto_diff_fx;
    2433      163667 :     num_freq_bands = hParamMC->num_freq_bands;
    2434      163667 :     move16();
    2435      163667 :     num_freq_bands_diff = hParamMC->h_output_synthesis_params.max_band_decorr;
    2436      163667 :     move16();
    2437             : 
    2438     1163275 :     FOR( k = 0; k < nY; k++ )
    2439             :     {
    2440      999608 :         p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); // Q11
    2441             : 
    2442    20991768 :         FOR( l = 0; l < num_freq_bands_diff; l++ )
    2443             :         {
    2444    19992160 :             Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
    2445    19992160 :             move32();
    2446    19992160 :             Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
    2447    19992160 :             move32();
    2448             :         }
    2449             :     }
    2450             : 
    2451      163667 :     return;
    2452             : }
    2453             : 
    2454             : /*-------------------------------------------------------------------------
    2455             :  * ivas_param_mc_bin2dec()
    2456             :  *
    2457             :  * decode a number of bits to an integer
    2458             :  *------------------------------------------------------------------------*/
    2459             : /* r : decoded integer */
    2460       12035 : static Word16 ivas_param_mc_bin2dec_fx(
    2461             :     UWord16 bits[PARAM_MC_MAX_BITS], /* i  : bit buffer               */
    2462             :     const Word16 N                   /* i  : number of bits to decode */
    2463             : )
    2464             : {
    2465             :     Word16 i;
    2466             :     Word16 out;
    2467             : 
    2468       12035 :     assert( N <= 16 );
    2469       12035 :     out = 0;
    2470       12035 :     move16();
    2471       48140 :     FOR( i = 0; i < N; i++ )
    2472             :     {
    2473       36105 :         out = add( out, shl( bits[i], sub( sub( N, 1 ), i ) ) );
    2474             :     }
    2475             : 
    2476       12035 :     return out;
    2477             : }
    2478             : 
    2479             : /*-------------------------------------------------------------------------
    2480             :  * ivas_param_mc_uniform_decoder()
    2481             :  *
    2482             :  * decode a uniformily coded sequence of float values
    2483             :  *------------------------------------------------------------------------*/
    2484         464 : static Word16 ivas_param_mc_uniform_decoder_fx(
    2485             :     Word16 *seq,                          /* o  : decoded sequence of float values hParamCodingInfo -> Q-quant*/
    2486             :     const Word16 sz_seq,                  /* i  : number of values to decode       */
    2487             :     const Word16 *alphabet,               /* i  : codebook                         hParamCodingInfo -> Q-quant*/
    2488             :     const Word16 N,                       /* i  : number of bits per coded index   */
    2489             :     UWord16 bit_buffer[PARAM_MC_MAX_BITS] /* i  : bit buffer to decode             */
    2490             : )
    2491             : {
    2492             :     Word16 i;
    2493             :     Word16 idx;
    2494             :     Word16 n_bits;
    2495             : 
    2496         464 :     n_bits = 0;
    2497         464 :     move16();
    2498         464 :     assert( N * sz_seq < PARAM_MC_MAX_BITS );
    2499             : 
    2500       12499 :     FOR( i = 0; i < sz_seq; ++i )
    2501             :     {
    2502       12035 :         idx = ivas_param_mc_bin2dec_fx( &bit_buffer[i * N], N );
    2503       12035 :         seq[i] = alphabet[idx];
    2504       12035 :         move16();
    2505             :     }
    2506             : 
    2507         464 :     n_bits = imult1616( N, sz_seq );
    2508             : 
    2509         464 :     return n_bits;
    2510             : }
    2511             : 
    2512             : 
    2513             : /*-------------------------------------------------------------------------
    2514             :  * ivas_param_mc_range_decoder_LC()
    2515             :  *
    2516             :  * decode a sequency of inidices coded with a range coder
    2517             :  *------------------------------------------------------------------------*/
    2518       19968 : static Word16 ivas_param_mc_range_decoder_LC_fx(
    2519             :     UWord16 *bit_buffer,      /* i  : bit buffer to read from                   */
    2520             :     Word16 *x,                /* o  : decoded indices                           */
    2521             :     Word16 *BER_detect,       /* o  : flag for indicating a bit error           */
    2522             :     const Word16 sz_seq,      /* i  : size of the sequence to be decoded        */
    2523             :     const Word16 sz_alphabet, /* i  : size of the alphabet                      */
    2524             :     const UWord16 *cft,       /* i  : cumulative frequency table                */
    2525             :     const UWord16 *sft,       /* i  : symbol frequency table                    */
    2526             :     const Word16 tot_shift,   /* i  : total frequency as a power of 2           */
    2527             :     const Word16 nbbits       /* i  : maximum bit budget                        */
    2528             : )
    2529             : {
    2530             :     RangeUniDecState rc_st_dec; /* State of the range decoder */
    2531             :     Word16 cur_bit_pos;
    2532             :     Word16 k;
    2533             :     Word16 r;
    2534             : 
    2535             :     /* Start Decoding */
    2536             :     /* Initialize range decoder */
    2537       19968 :     cur_bit_pos = 0;
    2538       19968 :     move16();
    2539       19968 :     rc_uni_dec_init_fx( &rc_st_dec, bit_buffer, sub( nbbits, 32 ) ); /* (nbbits + 30) entries are read by the decoder */
    2540             : 
    2541             :     /* Main Loop through the indices */
    2542      636765 :     FOR( k = 0; k < sz_seq; k++ )
    2543             :     {
    2544      616797 :         r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
    2545             :                                                                                              /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1}  */
    2546             : 
    2547             :         /* Update bitstream pointer */
    2548      616797 :         cur_bit_pos = rc_uni_dec_virtual_finish_fx( &rc_st_dec );
    2549             : 
    2550             :         /* Confirm that there is no overflow */
    2551      616797 :         IF( GT_16( cur_bit_pos, nbbits ) )
    2552             :         {
    2553           0 :             *BER_detect = s_or( *BER_detect, 1 );
    2554           0 :             move16();
    2555             :         }
    2556             : 
    2557      616797 :         x[k] = r;
    2558      616797 :         move16();
    2559             :     }
    2560             : 
    2561             :     /* We don't need to finish because virtual_finish() already does the same */
    2562             :     /*st->next_bit_pos = rc_uni_dec_finish(&rc_st_dec);*/
    2563             : 
    2564             :     /* Check for bitstream errors */
    2565       19968 :     IF( rc_st_dec.bit_error_detected != 0 )
    2566             :     {
    2567           0 :         *BER_detect = s_or( *BER_detect, 1 );
    2568           0 :         move16();
    2569             :     }
    2570             : 
    2571       19968 :     return cur_bit_pos;
    2572             : }
    2573             : 
    2574             : /*-------------------------------------------------------------------------
    2575             :  * param_mc_compute_interpolator()
    2576             :  *
    2577             :  * compute the interpolator used in the final synthesis
    2578             :  *------------------------------------------------------------------------*/
    2579             : 
    2580       10570 : static void ivas_param_mc_dec_compute_interpolator_fx(
    2581             :     const UWord16 bAttackPresent, /* i  : flag indicating if we have a transient in the current frame */
    2582             :     const UWord16 attackPos,      /* i  : position of the transient                                   */
    2583             :     const UWord16 interp_length,  /* i  : number of interpolation values to be calculated             */
    2584             :     Word16 *interpolator          /* o  : interpolator                                                */
    2585             : )
    2586             : {
    2587             :     Word16 idx;
    2588             : 
    2589       10570 :     IF( bAttackPresent )
    2590             :     {
    2591        3779 :         FOR( idx = 0; idx < attackPos * 2; idx++ )
    2592             :         {
    2593        3292 :             interpolator[idx] = 0;
    2594        3292 :             move16();
    2595             :         }
    2596        4987 :         FOR( ; idx < interp_length; idx++ )
    2597             :         {
    2598        4500 :             interpolator[idx] = 32767; /* 1.0f Q15 */
    2599        4500 :             move16();
    2600             :         }
    2601             :     }
    2602             :     ELSE
    2603             :     {
    2604       10083 :         ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, interp_length, interpolator );
    2605             :     }
    2606             : 
    2607       10570 :     return;
    2608             : }
    2609             : 
    2610             : 
    2611             : /*-------------------------------------------------------------------------
    2612             :  * remove_lfe_from_cy()
    2613             :  *
    2614             :  * remove all LFE related values from a covariance matrix
    2615             :  *------------------------------------------------------------------------*/
    2616             : 
    2617      131737 : static void remove_lfe_from_cy_fx(
    2618             :     const Word16 nY,                               /* i  : dimension of the covariance matrix */
    2619             :     Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP], /* i  : LFE index                          */
    2620             :     Word16 num_lfe,                                /* i  : number of LFEs                     */
    2621             :     Word32 *cy,                                    /* i  : covariance matrix                  */
    2622             :     Word32 *cy_woLFE                               /* o  : covariance matrix with LFE removed */
    2623             : )
    2624             : {
    2625             :     Word16 ch_idx1, ch_idx2;
    2626             :     Word16 lfe_idx1, lfe_idx2;
    2627             :     Word32 *ptrCy;
    2628             :     Word32 *ptrCy_out;
    2629             : 
    2630      131737 :     ptrCy = cy;
    2631      131737 :     ptrCy_out = cy_woLFE;
    2632             : 
    2633      395211 :     FOR( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ )
    2634             :     {
    2635      935759 :         FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
    2636             :         {
    2637     2016855 :             FOR( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ )
    2638             :             {
    2639     4819915 :                 FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
    2640             :                 {
    2641     3475345 :                     *( ptrCy_out++ ) = *( ptrCy++ );
    2642     3475345 :                     move32();
    2643             :                 }
    2644     1344570 :                 ptrCy++;
    2645             :             }
    2646      672285 :             ptrCy--;
    2647             :         }
    2648      263474 :         ptrCy += nY;
    2649             :     }
    2650             : 
    2651      131737 :     return;
    2652             : }
    2653             : 
    2654             : 
    2655             : /*-------------------------------------------------------------------------
    2656             :  * ivas_param_mc_get_mixing_matrices()
    2657             :  *
    2658             :  * calculate the direct and residual mixing matrices
    2659             :  * using the covariance method
    2660             :  *------------------------------------------------------------------------*/
    2661             : 
    2662      132787 : static void ivas_param_mc_get_mixing_matrices_fx(
    2663             :     PARAM_MC_DEC_HANDLE hParamMC, /* i  : Parametric MC handle */
    2664             :     IVAS_OUTPUT_SETUP *hSynthesisOutputSetup,
    2665             :     Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i  : input covariance for all parameter bands         Q(31 - Cx_in_e)*/
    2666             :     Word16 Cx_in_e,
    2667             :     const Word16 param_band_idx, /* i  : parameter band index                             */
    2668             :     Word32 *mixing_matrix_fx[],  // Q(31 - mixing_matrix_e)
    2669             :     Word16 *mixing_matrix_e,
    2670             :     Word32 *mixing_matrix_res_fx[], // Q(31 - mixing_matrix_res_e)
    2671             :     Word16 *mixing_matrix_res_e,
    2672             :     const Word16 nY_intern,                     /* i  : number of channels in the transported format     */
    2673             :     const PARAM_MC_SYNTHESIS_CONF synth_config, /* i  : Parametric MC synthesis config                   */
    2674             :     const Word16 nX,                            /* i  : number of transport channels                     */
    2675             :     const Word16 nY_cov                         /* i  : number of covariance synthesis output channels   */
    2676             : )
    2677             : {
    2678      132787 :     Word16 matSize = MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS;
    2679             :     Word16 nY_band;
    2680             :     Word16 num_lfe_bands;
    2681             :     Word16 brange[2];
    2682             :     UWord16 i;
    2683             :     Word16 ch_idx1, ch_idx2, lfe_idx1, lfe_idx2;
    2684             :     Word16 remove_lfe;
    2685             :     Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP];
    2686             : 
    2687             :     Word32 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
    2688             :     Word32 Cy_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
    2689             : 
    2690             :     Word32 Cy_full_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
    2691             : 
    2692             :     Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cr_e)
    2693             :     Word16 Cr_e;
    2694             :     Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Cy_diag_buff_e)
    2695             :     Word16 Cy_diag_buff_e[MAX_OUTPUT_CHANNELS];
    2696             :     Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - mixing_matrix_local_e)
    2697      132787 :     Word16 Cy_diag_e = 0, mixing_matrix_local_e = 0;
    2698             :     Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cproto_e)
    2699             :     Word16 Cproto_e;
    2700             :     Word32 *proto_matrix_ptr_fx; // Q(31 - proto_matrix_ptr_e)
    2701             :     Word32 *Cx_state_fx;         // Q(31 - Cx_state_e)
    2702             :     Word32 *Cx_old_state_fx;
    2703             :     Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cy_state_e)
    2704             :     Word32 *Cy_old_state_fx;
    2705             :     Word16 Cx_state_e;
    2706             :     Word16 Cy_state_e;
    2707             :     Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mixing_matrix_res_local_e)
    2708             :     Word16 mixing_matrix_res_local_e;
    2709             :     Word32 L_tmp;
    2710             :     Word16 tmp_e, tmp;
    2711             : 
    2712      132787 :     Word16 proto_matrix_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
    2713      132787 :     move16();
    2714             :     Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; // Q(31 - proto_matrix_noLFE_e)
    2715             : 
    2716             :     Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
    2717             : 
    2718             :     Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; // Q(31 - Cproto_diag_e)
    2719             :     Word16 mat_mult_buffer1_e, proto_matrix_ptr_e, Cproto_diag_e;
    2720             : 
    2721             :     Word32 *ptrMM_fx;
    2722             :     Word32 *ptrMM_out_fx;
    2723             : 
    2724             :     Word16 Cy_e, Cx_e;
    2725             :     Word16 Cy_full_e;
    2726      132787 :     Word16 new_e = 0;
    2727      132787 :     move16();
    2728             : 
    2729      132787 :     set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
    2730      132787 :     set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
    2731      132787 :     set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
    2732      132787 :     set_zero_fx( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
    2733      132787 :     set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
    2734      132787 :     Word16 proto_matrix_noLFE_e = 0;
    2735      132787 :     move16();
    2736             : 
    2737             :     Word32 Cx_in_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
    2738             : 
    2739      132787 :     Copy32( Cx_in_fixed, Cx_in_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
    2740             : 
    2741      132787 :     nY_band = nY_cov;
    2742      132787 :     move16();
    2743      132787 :     num_lfe_bands = 0;
    2744      132787 :     move16();
    2745      132787 :     remove_lfe = 0;
    2746      132787 :     move16();
    2747             : 
    2748      132787 :     set16_fx( lfe_indices, -1, PARAM_MC_LOCAL_SZ_LFE_MAP );
    2749      132787 :     IF( hSynthesisOutputSetup->num_lfe )
    2750             :     {
    2751             :         Word32 *proto_matrix_ptr_in_fx;
    2752      265574 :         FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe; lfe_idx1++ )
    2753             :         {
    2754      132787 :             lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1];
    2755      132787 :             move16();
    2756             :         }
    2757      132787 :         lfe_indices[hSynthesisOutputSetup->num_lfe + 1] = nY_cov;
    2758      132787 :         move16();
    2759      132787 :         proto_matrix_ptr_fx = &proto_matrix_noLFE_fx[0];
    2760      132787 :         proto_matrix_ptr_in_fx = &hParamMC->h_output_synthesis_params.proto_matrix_fx[0];
    2761      132787 :         proto_matrix_noLFE_e = proto_matrix_e;
    2762      132787 :         move16();
    2763             : 
    2764      132787 :         set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
    2765             : 
    2766      399721 :         FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
    2767             :         {
    2768      800802 :             FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
    2769             :             {
    2770     1904018 :                 FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
    2771             :                 {
    2772     1370150 :                     *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ );
    2773     1370150 :                     move32();
    2774             :                 }
    2775      533868 :                 proto_matrix_ptr_in_fx++;
    2776             :             }
    2777      266934 :             proto_matrix_ptr_in_fx--;
    2778             :         }
    2779             : 
    2780      132787 :         proto_matrix_ptr_e = proto_matrix_e;
    2781      132787 :         move16();
    2782             :     }
    2783             : 
    2784      132787 :     if ( hParamMC->hMetadataPMC->lfe_on )
    2785             :     {
    2786       13852 :         num_lfe_bands = PARAM_MC_MAX_BAND_LFE;
    2787       13852 :         move16();
    2788             :     }
    2789      132787 :     IF( hSynthesisOutputSetup->num_lfe > 0 && param_band_idx >= num_lfe_bands )
    2790             :     {
    2791      131737 :         remove_lfe = 1;
    2792      131737 :         move16();
    2793      131737 :         nY_band = sub( nY_cov, hSynthesisOutputSetup->num_lfe );
    2794      131737 :         proto_matrix_ptr_fx = proto_matrix_noLFE_fx;
    2795      131737 :         proto_matrix_ptr_e = proto_matrix_noLFE_e;
    2796      131737 :         move16();
    2797             :     }
    2798             :     ELSE
    2799             :     {
    2800        1050 :         proto_matrix_ptr_fx = hParamMC->h_output_synthesis_params.proto_matrix_fx;
    2801        1050 :         proto_matrix_ptr_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
    2802        1050 :         move16();
    2803             :     }
    2804             : 
    2805      132787 :     brange[0] = hParamMC->band_grouping[param_band_idx];
    2806      132787 :     move16();
    2807      132787 :     brange[1] = hParamMC->band_grouping[param_band_idx + 1];
    2808      132787 :     move16();
    2809             : 
    2810      132787 :     Cx_state_fx = Cx_in_fx;
    2811      132787 :     Cx_old_state_fx = hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx];
    2812      132787 :     Cy_old_state_fx = hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx];
    2813             : 
    2814             : 
    2815             :     /*  Getting mixing mtx */
    2816             :     /* estimate target cov from input cov and proto_matrix */
    2817             : 
    2818      132787 :     Cx_state_e = Cx_in_e;
    2819      132787 :     move16();
    2820      132787 :     matrix_product_fx( hParamMC->proto_matrix_int_fx, nY_intern, nX, 0, Cx_state_fx, nX, nX, 0, mat_mult_buffer1_fx );
    2821      132787 :     mat_mult_buffer1_e = add( hParamMC->proto_matrix_int_e, Cx_in_e );
    2822             : 
    2823      132787 :     matrix_product_fx( mat_mult_buffer1_fx, nY_intern, nX, 0, hParamMC->proto_matrix_int_fx, nY_intern, nX, 1, Cproto_fx );
    2824      132787 :     Cproto_e = add( mat_mult_buffer1_e, hParamMC->proto_matrix_int_e );
    2825             : 
    2826      948409 :     FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ )
    2827             :     {
    2828      815622 :         IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )], Cproto_e, 0, 0 ) < 0 )
    2829             :         {
    2830           0 :             Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )] = 0;
    2831           0 :             move32();
    2832             :         }
    2833             :     }
    2834             : 
    2835      132787 :     set_zero_fx( Cy_state_fx, matSize );
    2836      132787 :     Cy_state_e = 0;
    2837      132787 :     move16();
    2838             : 
    2839      398361 :     ivas_param_mc_dequantize_cov_fx( hParamMC,
    2840      132787 :                                      hParamMC->icld_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ),
    2841      132787 :                                      hParamMC->icc_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ),
    2842             :                                      param_band_idx, nY_cov,
    2843             :                                      synth_config,
    2844             :                                      nY_intern,
    2845             :                                      nX, Cx_state_fx, Cx_state_e, Cproto_fx, Cproto_e, Cy_state_fx, &Cy_state_e );
    2846             : 
    2847             :     // dbgwrite2_txt(Cy_state_fx,nY_intern*nY_intern,"../cy_state_fx.txt");
    2848             : 
    2849             :     /* Smoothing: Sum over two buffers */
    2850      132787 :     IF( hParamMC->hMetadataPMC->bAttackPresent )
    2851             :     {
    2852             :         /* no smoothing on attacks */
    2853        6064 :         Copy32( Cx_state_fx, Cx_fx, imult1616( nX, nX ) );
    2854        6064 :         Copy32( Cy_state_fx, Cy_full_fx, imult1616( nY_cov, nY_cov ) );
    2855        6064 :         Cy_full_e = Cy_state_e;
    2856        6064 :         move16();
    2857        6064 :         Cx_e = Cx_state_e;
    2858        6064 :         move16();
    2859             :     }
    2860             :     ELSE
    2861             :     {
    2862             :         /* smoothing gains are now identical to one, simply add up */
    2863             :         // v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov );
    2864             : 
    2865      126723 :         v_add_fixed_me( Cx_state_fx, Cx_state_e, Cx_old_state_fx, hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_fx, &Cx_e, imult1616( nX, nX ), 1 );
    2866      126723 :         v_add_fixed_me( Cy_state_fx, Cy_state_e, Cy_old_state_fx, hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_full_fx, &Cy_full_e, imult1616( nY_cov, nY_cov ), 1 );
    2867             :     }
    2868             : 
    2869      132787 :     Copy32( Cx_state_fx, Cx_old_state_fx, imult1616( nX, nX ) );
    2870             : 
    2871      132787 :     Copy32( Cy_state_fx, Cy_old_state_fx, imult1616( nY_cov, nY_cov ) );
    2872             : 
    2873      132787 :     hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = Cx_state_e;
    2874      132787 :     move16();
    2875      132787 :     hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = Cy_state_e;
    2876      132787 :     move16();
    2877             : 
    2878      132787 :     FOR( i = 0; i < nX * nX; i++ )
    2879             :     {
    2880      132787 :         if ( Cx_old_state_fx[i] != 0 )
    2881             :         {
    2882      132787 :             new_e = hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx];
    2883      132787 :             move16();
    2884      132787 :             BREAK;
    2885             :         }
    2886             :     }
    2887             : 
    2888      132787 :     hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = new_e;
    2889      132787 :     move16();
    2890             : 
    2891      132787 :     new_e = 0;
    2892      132787 :     move16();
    2893             : 
    2894      132787 :     FOR( i = 0; i < nY_cov * nY_cov; i++ )
    2895             :     {
    2896      132787 :         if ( Cy_old_state_fx[i] != 0 )
    2897             :         {
    2898      132787 :             new_e = hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx];
    2899      132787 :             move16();
    2900      132787 :             BREAK;
    2901             :         }
    2902             :     }
    2903             : 
    2904      132787 :     hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = new_e;
    2905      132787 :     move16();
    2906             : 
    2907             :     /* remove LFE IF necessary */
    2908      132787 :     IF( remove_lfe )
    2909             :     {
    2910             : 
    2911      131737 :         Cy_e = Cy_full_e;
    2912      131737 :         remove_lfe_from_cy_fx( nY_cov, lfe_indices, hSynthesisOutputSetup->num_lfe, Cy_full_fx, Cy_fx );
    2913             :     }
    2914             :     ELSE
    2915             :     {
    2916        1050 :         Copy32( Cy_full_fx, Cy_fx, imult1616( nY_band, nY_band ) );
    2917        1050 :         Cy_e = Cy_full_e;
    2918        1050 :         move16();
    2919             :     }
    2920             : 
    2921      132787 :     matrix_product_fx( proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx );
    2922      132787 :     mat_mult_buffer1_e = add( proto_matrix_ptr_e, Cx_e );
    2923             : 
    2924      132787 :     matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx, &Cproto_diag_e );
    2925             : 
    2926             :     /* make sure we have no negative entries in Cproto_diag due to rounding errors */
    2927             : 
    2928      812472 :     FOR( ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++ )
    2929             :     {
    2930      679685 :         if ( Cproto_diag_fx[ch_idx1] < 0 )
    2931             :         {
    2932           0 :             Cproto_diag_fx[ch_idx1] = 0;
    2933           0 :             move16();
    2934             :         }
    2935             :     }
    2936             : 
    2937             : 
    2938             :     /* Computing the mixing matrices */
    2939             : 
    2940             :     /* bands with decorr */
    2941      132787 :     IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
    2942             :     {
    2943      106849 :         computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 0, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e );
    2944             :         /* Compute mixing matrix FOR residual */
    2945      106849 :         computeMixingMatricesResidual_fx( nY_band, Cproto_diag_fx, Cproto_diag_e, Cr_fx, Cr_e, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_res_local_fx, &mixing_matrix_res_local_e );
    2946             : 
    2947      106849 :         IF( NE_16( mixing_matrix_res_local_e, mixing_matrix_local_e ) )
    2948             :         {
    2949       63935 :             tmp = getScaleFactor32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
    2950       63935 :             scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, tmp );
    2951       63935 :             mixing_matrix_local_e = sub( mixing_matrix_local_e, tmp );
    2952             : 
    2953       63935 :             tmp = getScaleFactor32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
    2954       63935 :             scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, tmp );
    2955       63935 :             mixing_matrix_res_local_e = sub( mixing_matrix_res_local_e, tmp );
    2956             : 
    2957       63935 :             scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, sub( mixing_matrix_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) );
    2958       63935 :             scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, sub( mixing_matrix_res_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) );
    2959             : 
    2960       63935 :             mixing_matrix_res_local_e = mixing_matrix_local_e = s_max( mixing_matrix_local_e, mixing_matrix_res_local_e );
    2961       63935 :             move16();
    2962             :         }
    2963      106849 :         IF( remove_lfe )
    2964             :         {
    2965      105799 :             set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
    2966             : 
    2967      105799 :             ptrMM_fx = mixing_matrix_res_local_fx;
    2968      105799 :             ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx];
    2969      317397 :             FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
    2970             :             {
    2971      751473 :                 FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
    2972             :                 {
    2973     1619625 :                     FOR( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ )
    2974             :                     {
    2975     3869685 :                         FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
    2976             :                         {
    2977     2789935 :                             *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
    2978     2789935 :                             move32();
    2979             :                         }
    2980     1079750 :                         ptrMM_out_fx++;
    2981             :                     }
    2982      539875 :                     ptrMM_out_fx--;
    2983             :                 }
    2984      211598 :                 ptrMM_out_fx += nY_cov;
    2985             :             }
    2986      105799 :             mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
    2987      105799 :             move16();
    2988             :         }
    2989             :         ELSE
    2990             :         {
    2991        1050 :             Copy32( mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
    2992        1050 :             mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
    2993        1050 :             move16();
    2994             :         }
    2995             :     }
    2996       25938 :     ELSE IF( brange[0] < hParamMC->max_band_energy_compensation )
    2997             :     {
    2998             :         /* Compute mixing matrices (energy compensation only) */
    2999       25938 :         computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 1, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e );
    3000             :     }
    3001             :     ELSE
    3002             :     {
    3003             :         /*IF neither decorrelation nor energy compensation is applied*/
    3004           0 :         FOR( i = 0; i < nY_band; i++ )
    3005             :         {
    3006           0 :             tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i], L_add( Cproto_diag_fx[i], EPSILON_FX ), &tmp_e );
    3007           0 :             tmp_e = add( Cy_diag_e, Cproto_diag_e );
    3008           0 :             L_tmp = Sqrt32( L_deposit_h( tmp ), &tmp_e );
    3009           0 :             Cy_diag_fx[i] = L_tmp;
    3010           0 :             move32();
    3011           0 :             Cy_diag_buff_e[i] = tmp_e;
    3012           0 :             move16();
    3013             :         }
    3014             : 
    3015             : 
    3016           0 :         Cy_diag_e = Cy_diag_buff_e[0];
    3017           0 :         move16();
    3018             : 
    3019           0 :         FOR( i = 1; i < nY_band; i++ )
    3020             :         {
    3021           0 :             if ( LT_16( Cy_diag_e, Cy_diag_buff_e[i] ) )
    3022             :             {
    3023           0 :                 Cy_diag_e = Cy_diag_buff_e[i];
    3024           0 :                 move16();
    3025             :             }
    3026             :         }
    3027             : 
    3028           0 :         FOR( i = 0; i < nY_band; i++ )
    3029             :         {
    3030           0 :             Cy_diag_fx[i] = L_shr( Cy_diag_fx[i], sub( Cy_diag_e, Cy_diag_buff_e[i] ) );
    3031           0 :             move32();
    3032             :         }
    3033             : 
    3034           0 :         diag_matrix_product_fx( Cy_diag_fx, Cy_diag_e, nY_band, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e );
    3035             :     }
    3036             : 
    3037      132787 :     IF( remove_lfe )
    3038             :     {
    3039      131737 :         set_zero_fx( mixing_matrix_fx[param_band_idx], imult1616( nX, nY_cov ) );
    3040      131737 :         ptrMM_fx = mixing_matrix_local_fx;
    3041      131737 :         ptrMM_out_fx = mixing_matrix_fx[param_band_idx];
    3042      396481 :         FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
    3043             :         {
    3044      794232 :             FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
    3045             :             {
    3046     1886068 :                 FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
    3047             :                 {
    3048     1356580 :                     *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
    3049     1356580 :                     move32();
    3050             :                 }
    3051      529488 :                 ptrMM_out_fx++;
    3052             :             }
    3053      264744 :             ptrMM_out_fx--;
    3054             :         }
    3055             : 
    3056      131737 :         mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
    3057      131737 :         move16();
    3058             :     }
    3059             :     ELSE
    3060             :     {
    3061        1050 :         Copy32( mixing_matrix_local_fx, mixing_matrix_fx[param_band_idx], imult1616( nY_cov, nX ) );
    3062        1050 :         mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
    3063        1050 :         move16();
    3064             :     }
    3065             : 
    3066      132787 :     return;
    3067             : }
    3068             : 
    3069             : 
    3070             : /*-------------------------------------------------------------------------
    3071             :  * param_mc_update_mixing_matrices()
    3072             :  *
    3073             :  * update mixing matrix buffers
    3074             :  *------------------------------------------------------------------------*/
    3075             : 
    3076       10229 : static void param_mc_update_mixing_matrices_fx(
    3077             :     PARAM_MC_DEC_HANDLE hParamMC, /* i/o: Parametric MC handle                                  */
    3078             :     Word32 *mixing_matrix[],      /* i  : direct mixing matrices for the frame just processed   */
    3079             :     Word16 *mixing_matrix_exp,
    3080             :     Word32 *mixing_matrix_res[], /* i  : residual mixing matrices for the frame just processed */
    3081             :     Word16 *mixing_matrix_res_exp,
    3082             :     const UWord16 nX,  /* i  : number of transport channels                          */
    3083             :     const UWord16 nY ) /* i  : number of synthesis channels                          */
    3084             : {
    3085             :     UWord16 param_band_idx;
    3086             : 
    3087      145166 :     FOR( param_band_idx = 0; param_band_idx < hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ )
    3088             :     {
    3089             :         Word16 brange[2];
    3090             : 
    3091      134937 :         brange[0] = hParamMC->band_grouping[param_band_idx];
    3092      134937 :         move16();
    3093      134937 :         brange[1] = hParamMC->band_grouping[param_band_idx + 1];
    3094      134937 :         move16();
    3095             : 
    3096      134937 :         Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nX, nY ) );
    3097      134937 :         hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = mixing_matrix_exp[param_band_idx];
    3098      134937 :         move16();
    3099             : 
    3100      134937 :         IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
    3101             :         {
    3102      106849 :             Copy32( mixing_matrix_res[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], imult1616( nY, nY ) );
    3103      106849 :             hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = mixing_matrix_res_exp[param_band_idx];
    3104      106849 :             move16();
    3105             :         }
    3106             :     }
    3107             : 
    3108       10229 :     return;
    3109             : }
    3110             : 
    3111             : 
    3112             : /*-------------------------------------------------------------------------
    3113             :  * ivas_param_mc_dequantize_cov()
    3114             :  *
    3115             :  * generate the target covariance matrix
    3116             :  *------------------------------------------------------------------------*/
    3117             : 
    3118             : 
    3119             : /*-------------------------------------------------------------------------
    3120             :  * ivas_param_mc_dequantize_cov_fx()
    3121             :  *
    3122             :  * generate the target covariance matrix
    3123             :  *------------------------------------------------------------------------*/
    3124             : 
    3125      132787 : static void ivas_param_mc_dequantize_cov_fx(
    3126             :     PARAM_MC_DEC_HANDLE hParamMC,             /* i  : Parametric MC handle                                    */
    3127             :     Word16 *ild_q_fx,                         /* i  : sequence of dequantized ILD values                   Q8 */
    3128             :     Word16 *icc_q_fx,                         /* i  : sequence of dequantized ICC values                   Q15*/
    3129             :     const Word16 param_band_index,            /* i  : current parameter band                                  */
    3130             :     const Word16 nY_cov,                      /* i  : number of output channels in the covariance synthesis   */
    3131             :     const PARAM_MC_SYNTHESIS_CONF synth_conf, /* i  : Parametric MC synthesis configuration                   */
    3132             :     const Word16 nY_int,                      /* i  : number of channels in the transported format            */
    3133             :     const Word16 nX,                          /* i  : number of transport channels                            */
    3134             :     Word32 *Cx_state_fx,                      /* i  : transport channel covariance matrix                     */
    3135             :     Word16 Cx_state_e,                        /* i  : exponent for transport channel covariance matrix        */
    3136             :     Word32 *Cproto_fx,                        /* i  : prototype matrix                                        */
    3137             :     Word16 Cproto_e,                          /* i  : exponent for prototype matrix                           */
    3138             :     Word32 *Cy_state_fx,                      /* o  : target covariance matrix                                */
    3139             :     Word16 *Cy_state_e                        /* o  : exponent for target covariance matrix                   */
    3140             : )
    3141             : {
    3142             :     Word16 Cy_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
    3143             :     Word16 Cp_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
    3144             : 
    3145             :     Word32 Nrqq_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Nrqq_e)
    3146             :     Word16 Nrqq_e[MAX_OUTPUT_CHANNELS];
    3147             :     Word32 a_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - a_e)
    3148             :     Word16 a_e[MAX_OUTPUT_CHANNELS];
    3149             :     Word16 k;
    3150             :     Word16 l;
    3151             :     Word32 *Cyp_fx; // Q(31 - Cyp_e)
    3152             :     Word16 *Cyp_e;
    3153             :     Word32 ap_fx; // Q(31 - ap_e)
    3154             :     Word16 ap_e;
    3155             :     Word32 L_tmp;
    3156             :     Word16 tmp, tmp_e;
    3157             :     const PARAM_MC_ILD_MAPPING *h_ild_mapping;
    3158             :     Word32 Cy_state_int_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
    3159             :     Word16 Cy_state_int_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
    3160             : 
    3161      132787 :     set16_fx( Cp_buf_e, Cproto_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
    3162      132787 :     set32_fx( Nrqq_fx, 0, MAX_OUTPUT_CHANNELS );
    3163      132787 :     set16_fx( Nrqq_e, 0, MAX_OUTPUT_CHANNELS );
    3164      132787 :     h_ild_mapping = hParamMC->hMetadataPMC->ild_mapping_conf;
    3165             : 
    3166             :     /*get back Nrg*/
    3167      132787 :     tmp = 0;
    3168      132787 :     move16();
    3169             : 
    3170      948409 :     FOR( k = 0; k < nY_int; k++ )
    3171             :     {
    3172      815622 :         Word32 ref_ener_fx = 0; // Q(31 - ref_ener_e)
    3173      815622 :         move32();
    3174      815622 :         Word16 ref_ener_e = 0;
    3175      815622 :         move16();
    3176             :         Word16 ref_channel_cnt;
    3177             :         Word16 ref_channel_idx;
    3178             : 
    3179     1894098 :         FOR( ref_channel_cnt = 0; ref_channel_cnt < h_ild_mapping->num_ref_channels[k]; ref_channel_cnt++ )
    3180             :         {
    3181     1078476 :             ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt];
    3182     1078476 :             move16();
    3183     1078476 :             ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[ref_channel_idx + ( ref_channel_idx * nX )], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e );
    3184     1078476 :             move32();
    3185             :         }
    3186             : 
    3187      815622 :         L_tmp = Mpy_32_16_1( 713378626, ild_q_fx[k] );     /*Q24 : L_tmp Q31 for log2(10)/10 -> 713378626 */
    3188      815622 :         L_tmp = BASOP_util_Pow2( L_tmp, 31 - 24, &tmp_e ); /*powf( 10.0f, ild_q_fx[k] / 10.0f )*/
    3189      815622 :         L_tmp = Mpy_32_32( L_tmp, Mpy_32_16_1( ref_ener_fx, hParamMC->hMetadataPMC->ild_factors_fx[k] ) );
    3190             : 
    3191      815622 :         Nrqq_fx[h_ild_mapping->ild_index[k]] = L_tmp;
    3192      815622 :         move32();
    3193      815622 :         Nrqq_e[h_ild_mapping->ild_index[k]] = add( tmp_e, ref_ener_e );
    3194      815622 :         move16();
    3195             :     }
    3196             : 
    3197             :     /*  estimate ICCs from estimated Cproto */
    3198             : 
    3199      948409 :     FOR( k = 0; k < nY_int; k++ )
    3200             :     {
    3201             :         // a_fx[k] = 1.f / ( sqrtf( Cproto_fx[k + nY_int * k] ) + EPSILON );
    3202      815622 :         tmp_e = Cp_buf_e[k + ( nY_int * k )];
    3203      815622 :         move16();
    3204             : 
    3205      815622 :         IF( Cproto_fx[k + ( nY_int * k )] != 0 )
    3206             :         {
    3207      815622 :             L_tmp = ISqrt32( Cproto_fx[k + ( nY_int * k )], &tmp_e );
    3208             :         }
    3209             :         ELSE
    3210             :         {
    3211           0 :             L_tmp = INV_EPSILON_MANT;
    3212           0 :             move32();
    3213           0 :             tmp_e = 15;
    3214           0 :             move16();
    3215             :         }
    3216      815622 :         a_fx[k] = L_tmp;
    3217      815622 :         move32();
    3218      815622 :         a_e[k] = tmp_e;
    3219      815622 :         move16();
    3220             : 
    3221     5880714 :         FOR( l = 0; l < nY_int; l++ )
    3222             :         {
    3223     5065092 :             Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cproto_fx[( k * nY_int ) + l], a_fx[k] );
    3224     5065092 :             move32();
    3225     5065092 :             Cy_state_int_e[( k * nY_int ) + l] = add( Cp_buf_e[( k * nY_int ) + l], a_e[k] );
    3226     5065092 :             move16();
    3227             :         }
    3228             :     }
    3229             : 
    3230      948409 :     FOR( k = 0; k < nY_int; k++ )
    3231             :     {
    3232      815622 :         Cyp_fx = Cy_state_int_fx + k;
    3233      815622 :         Cyp_e = Cy_state_int_e + k;
    3234      815622 :         ap_fx = a_fx[k];
    3235      815622 :         move32();
    3236      815622 :         ap_e = a_e[k];
    3237      815622 :         move16();
    3238             : 
    3239     5880714 :         FOR( l = 0; l < nY_int; l++ )
    3240             :         {
    3241     5065092 :             ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
    3242     5065092 :             move32();
    3243     5065092 :             *Cyp_e = add( *Cyp_e, ap_e );
    3244     5065092 :             move16();
    3245             : 
    3246     5065092 :             Cyp_fx += nY_int;
    3247     5065092 :             Cyp_e += nY_int;
    3248             :         }
    3249             :     }
    3250             : 
    3251             :     /*normalizing the Cy_state_int_fx to a common exponent*/
    3252             : 
    3253             :     /* replace some estimated ICCs with transmitted values */
    3254      815622 :     FOR( k = 0; k < hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; k++ )
    3255             :     {
    3256      682835 :         Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp );
    3257      682835 :         move32();
    3258      682835 :         Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = tmp;
    3259      682835 :         move16();
    3260      682835 :         Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp );
    3261      682835 :         move32();
    3262      682835 :         Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = tmp;
    3263      682835 :         move16();
    3264             :     }
    3265             : 
    3266      132787 :     test();
    3267      132787 :     IF( GE_16( param_band_index, PARAM_MC_MAX_BAND_LFE ) || ( hParamMC->hMetadataPMC->lfe_on == 0 ) )
    3268             :     {
    3269      939659 :         FOR( k = 0; k < nY_int; k++ )
    3270             :         {
    3271      807922 :             Cy_state_int_fx[k + ( 3 * nY_int )] = ONE_IN_Q31;
    3272      807922 :             move32();
    3273      807922 :             Cy_state_int_e[k + ( 3 * nY_int )] = 0;
    3274      807922 :             move16();
    3275      807922 :             Cy_state_int_fx[3 + ( k * nY_int )] = ONE_IN_Q31;
    3276      807922 :             move32();
    3277      807922 :             Cy_state_int_e[3 + ( k * nY_int )] = 0;
    3278      807922 :             move16();
    3279             :         }
    3280      131737 :         Nrqq_fx[3] = 0;
    3281      131737 :         move32();
    3282             :     }
    3283             : 
    3284             :     /* Generate back Covariance Mtx */
    3285      948409 :     FOR( k = 0; k < nY_int; k++ )
    3286             :     {
    3287      815622 :         tmp_e = Nrqq_e[k];
    3288      815622 :         move16();
    3289      815622 :         a_fx[k] = Sqrt32( Nrqq_fx[k], &tmp_e );
    3290      815622 :         move32();
    3291      815622 :         a_e[k] = tmp_e;
    3292      815622 :         move16();
    3293             : 
    3294             :         /* v_multc( Cy_state_int_fx + k * nY_int, a_fx[k], Cy_state_int_fx + k * nY_int, nY_int ) */
    3295     5880714 :         FOR( l = 0; l < nY_int; l++ )
    3296             :         {
    3297     5065092 :             Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cy_state_int_fx[( k * nY_int ) + l], a_fx[k] );
    3298     5065092 :             move32();
    3299     5065092 :             Cy_state_int_e[( k * nY_int ) + l] = add( Cy_state_int_e[( k * nY_int ) + l], a_e[k] );
    3300     5065092 :             move16();
    3301             :         }
    3302             :     }
    3303             : 
    3304      948409 :     FOR( k = 0; k < nY_int; k++ )
    3305             :     {
    3306      815622 :         Cyp_fx = Cy_state_int_fx + k;
    3307      815622 :         Cyp_e = Cy_state_int_e + k;
    3308      815622 :         ap_fx = a_fx[k];
    3309      815622 :         move32();
    3310      815622 :         ap_e = a_e[k];
    3311      815622 :         move16();
    3312             : 
    3313     5880714 :         FOR( l = 0; l < nY_int; l++ )
    3314             :         {
    3315     5065092 :             ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
    3316     5065092 :             move32();
    3317     5065092 :             ( *Cyp_e ) = add( *Cyp_e, ap_e );
    3318     5065092 :             move16();
    3319             : 
    3320     5065092 :             Cyp_fx += nY_int;
    3321     5065092 :             Cyp_e += nY_int;
    3322             :         }
    3323             :     }
    3324             : 
    3325      132787 :     IF( EQ_32( synth_conf, PARAM_MC_SYNTH_LS_CONV_COV ) )
    3326             :     {
    3327             :         /* Cy = dmx*Cy*dmx' */
    3328             :         Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
    3329             :         Word16 mat_mult_buffer1_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
    3330             :         Word32 target_ch_ener_fx[MAX_CICP_CHANNELS]; // Q(31 - target_ch_ener_e)
    3331             :         Word16 target_ch_ener_e[MAX_CICP_CHANNELS];
    3332             :         Word32 dmx_ch_ener_fx[MAX_CICP_CHANNELS];
    3333             : 
    3334             :         Word16 ls_conv_dmx_matrix_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
    3335             : 
    3336        2100 :         set32_fx( target_ch_ener_fx, 0, MAX_CICP_CHANNELS );
    3337        2100 :         set16_fx( target_ch_ener_e, 0, MAX_CICP_CHANNELS );
    3338        2100 :         set32_fx( dmx_ch_ener_fx, 0, MAX_CICP_CHANNELS );
    3339        2100 :         set16_fx( ls_conv_dmx_matrix_e, 1, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
    3340             : 
    3341        2100 :         matrix_product_mant_exp( hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 0,
    3342             :                                  Cy_state_int_fx, Cy_state_int_e, nY_int, nY_int, 0,
    3343             :                                  mat_mult_buffer1_fx, mat_mult_buffer1_e );
    3344             : 
    3345        2100 :         matrix_product_mant_exp( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_cov, nY_int, 0,
    3346        2100 :                                  hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 1,
    3347             :                                  Cy_state_fx, Cy_buf_e );
    3348             : 
    3349       14700 :         FOR( k = 0; k < nY_cov; k++ )
    3350             :         {
    3351      113400 :             FOR( l = 0; l < nY_int; l++ )
    3352             :             {
    3353      100800 :                 L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[k + ( l * nY_cov )], Nrqq_fx[l] );
    3354      100800 :                 tmp_e = add( ls_conv_dmx_matrix_e[k + ( l + nY_cov )], Nrqq_e[l] );
    3355      100800 :                 L_tmp = BASOP_Util_Add_Mant32Exp( target_ch_ener_fx[k], target_ch_ener_e[k], L_tmp, tmp_e, &tmp_e );
    3356      100800 :                 target_ch_ener_fx[k] = L_tmp;
    3357      100800 :                 move32();
    3358      100800 :                 target_ch_ener_e[k] = tmp_e;
    3359      100800 :                 move16();
    3360             :             }
    3361             : 
    3362       12600 :             dmx_ch_ener_fx[k] = Cy_state_fx[k + ( nY_cov * k )];
    3363       12600 :             move32();
    3364             : 
    3365       12600 :             IF( dmx_ch_ener_fx[k] < 0 )
    3366             :             {
    3367           0 :                 Cy_state_fx[k + ( nY_cov * k )] = L_negate( Cy_state_fx[k + ( nY_cov * k )] );
    3368           0 :                 move32();
    3369           0 :                 dmx_ch_ener_fx[k] = L_negate( dmx_ch_ener_fx[k] );
    3370           0 :                 move32();
    3371             :             }
    3372             : 
    3373       12600 :             IF( extract_h( dmx_ch_ener_fx[k] ) == 0 )
    3374             :             {
    3375        1950 :                 target_ch_ener_fx[k] = 0;
    3376        1950 :                 move32();
    3377        1950 :                 target_ch_ener_e[k] = 0;
    3378        1950 :                 move16();
    3379             :             }
    3380             :             ELSE
    3381             :             {
    3382       10650 :                 BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[k + ( nY_cov * k )], &tmp, &tmp_e );
    3383       10650 :                 tmp = Sqrt16( tmp, &tmp_e );
    3384       10650 :                 target_ch_ener_fx[k] = L_deposit_h( tmp );
    3385       10650 :                 move32();
    3386       10650 :                 target_ch_ener_e[k] = tmp_e;
    3387       10650 :                 move16();
    3388             :             }
    3389             : 
    3390       88200 :             FOR( l = 0; l < nY_cov; l++ )
    3391             :             {
    3392       75600 :                 Cy_state_fx[( k * nY_cov ) + l] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[( k * nY_cov ) + l] );
    3393       75600 :                 move32();
    3394       75600 :                 Cy_buf_e[( k * nY_cov ) + l] = add( target_ch_ener_e[k], Cy_buf_e[( k * nY_cov ) + l] );
    3395       75600 :                 move16();
    3396             :             }
    3397             : 
    3398       12600 :             Cyp_fx = Cy_state_fx + k;
    3399       12600 :             Cyp_e = Cy_buf_e + k;
    3400       12600 :             ap_fx = target_ch_ener_fx[k];
    3401       12600 :             move32();
    3402       12600 :             ap_e = target_ch_ener_e[k];
    3403       12600 :             move16();
    3404       88200 :             FOR( l = 0; l < nY_cov; l++ )
    3405             :             {
    3406       75600 :                 ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
    3407       75600 :                 move32();
    3408       75600 :                 *Cyp_e = add( *Cyp_e, ap_e );
    3409       75600 :                 move16();
    3410             : 
    3411       75600 :                 Cyp_fx += nY_cov;
    3412       75600 :                 Cyp_e += nY_cov;
    3413             :             }
    3414             :         }
    3415             :     }
    3416             :     ELSE
    3417             :     {
    3418      130687 :         Copy32( Cy_state_int_fx, Cy_state_fx, imult1616( nY_int, nY_int ) );
    3419      130687 :         Copy( Cy_state_int_e, Cy_buf_e, imult1616( nY_int, nY_int ) );
    3420             :     }
    3421             : 
    3422             :     /*normalize output matrix to a common exponent*/
    3423      132787 :     tmp = 0;
    3424     5197879 :     FOR( k = 0; k < nY_int * nY_int; k++ )
    3425             :     {
    3426     5065092 :         Cy_state_fx[k] = BASOP_Util_Add_Mant32Exp( Cy_state_fx[k], Cy_buf_e[k], 0, 0, &Cy_buf_e[k] );
    3427     5065092 :         move32();
    3428     5065092 :         tmp = s_max( tmp, Cy_buf_e[k] );
    3429             :     }
    3430     5197879 :     FOR( k = 0; k < nY_int * nY_int; k++ )
    3431             :     {
    3432     5065092 :         L_tmp = L_shr( Cy_state_fx[k], sub( tmp, Cy_buf_e[k] ) );
    3433     5065092 :         Cy_state_fx[k] = L_tmp;
    3434     5065092 :         move32();
    3435             :     }
    3436      132787 :     *Cy_state_e = tmp;
    3437      132787 :     move16();
    3438             : 
    3439      132787 :     return;
    3440             : }
    3441             : 
    3442             : /*-------------------------------------------------------------------------*
    3443             :  * param_mc_set_num_synth_bands()
    3444             :  *
    3445             :  * set the number of frequency bands to be synthesized
    3446             :  *-------------------------------------------------------------------------*/
    3447             : 
    3448         430 : static void param_mc_set_num_synth_bands(
    3449             :     const Word32 output_Fs,      /* i  : output sampling frequency */
    3450             :     PARAM_MC_DEC_HANDLE hParamMC /* i/o: Parametric MC handle      */
    3451             : )
    3452             : {
    3453             :     UWord16 max_param_band_synth;
    3454             :     const Word16 *param_mc_bands_coded;
    3455             : 
    3456         430 :     SWITCH( hParamMC->hMetadataPMC->num_parameter_bands )
    3457             :     {
    3458           3 :         case 20:
    3459           3 :             param_mc_bands_coded = param_mc_bands_coded_20;
    3460           3 :             BREAK;
    3461         216 :         case 10:
    3462         216 :             param_mc_bands_coded = param_mc_bands_coded_10;
    3463         216 :             BREAK;
    3464         211 :         case 14:
    3465             :         default:
    3466         211 :             param_mc_bands_coded = param_mc_bands_coded_14;
    3467         211 :             BREAK;
    3468             :     }
    3469         430 :     move16();
    3470         430 :     SWITCH( output_Fs )
    3471             :     {
    3472           0 :         case 8000:
    3473           0 :             max_param_band_synth = (UWord16) param_mc_bands_coded[NB];
    3474           0 :             BREAK;
    3475          77 :         case 16000:
    3476          77 :             max_param_band_synth = (UWord16) param_mc_bands_coded[WB];
    3477          77 :             BREAK;
    3478           7 :         case 32000:
    3479           7 :             max_param_band_synth = (UWord16) param_mc_bands_coded[SWB];
    3480           7 :             BREAK;
    3481         346 :         case 48000:
    3482             :         default:
    3483         346 :             max_param_band_synth = (UWord16) param_mc_bands_coded[FB];
    3484         346 :             BREAK;
    3485             :     }
    3486         430 :     move16();
    3487         430 :     hParamMC->num_param_bands_synth = s_min( hParamMC->hMetadataPMC->nbands_coded, max_param_band_synth );
    3488         430 :     move16();
    3489             : 
    3490         430 :     return;
    3491             : }
    3492             : 
    3493             : 
    3494             : /*-------------------------------------------------------------------------*
    3495             :  * param_mc_get_diff_proto_info()
    3496             :  *
    3497             :  * calculated the diffuse prototype information
    3498             :  *-------------------------------------------------------------------------*/
    3499             : 
    3500             : 
    3501         279 : static ivas_error param_mc_get_diff_proto_info_fx(
    3502             :     const Word32 *proto_mtx,                     /* i  : protoype matrix for the synthesis                     */
    3503             :     const UWord16 nchan_transport,               /* i  : number of transport channels                          */
    3504             :     const UWord16 nchan_out_cov,                 /* i  : number if output channels of the covariance synthesis */
    3505             :     PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, /* o  : generated diffuse prototype info                      */
    3506             :     Word16 Q_proto_mtx )
    3507             : {
    3508             :     Word32 proto_fac_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
    3509             :     UWord16 cur_out_ch;
    3510             :     UWord16 cur_diff_proto;
    3511             :     UWord16 cur_transport_ch;
    3512             :     UWord16 max_num_src_chan;
    3513             : 
    3514             :     /* Initializations */
    3515         279 :     max_num_src_chan = 0;
    3516         279 :     move16();
    3517             : 
    3518         279 :     set_zero_fx( proto_fac_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
    3519         279 :     IF( ( p_diff_proto_info->proto_index_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
    3520             :     {
    3521           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
    3522             :     }
    3523         279 :     set16_fx( p_diff_proto_info->proto_index_diff, 0, nchan_out_cov );
    3524             : 
    3525         279 :     IF( ( p_diff_proto_info->num_source_chan_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
    3526             :     {
    3527           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
    3528             :     }
    3529         279 :     set16_fx( p_diff_proto_info->num_source_chan_diff, 0, nchan_out_cov );
    3530             : 
    3531             :     /* we have at least one prototype, copy the first one */
    3532         279 :     p_diff_proto_info->num_protos_diff = 1;
    3533         279 :     move16();
    3534             : 
    3535         279 :     mvr2r_inc_fixed( proto_mtx, nchan_out_cov, proto_fac_fx, nchan_out_cov, nchan_transport );
    3536         279 :     p_diff_proto_info->proto_index_diff[0] = 0;
    3537         279 :     move16();
    3538             : 
    3539             :     /* search for distinct prototypes */
    3540        1788 :     FOR( cur_out_ch = 1; cur_out_ch < nchan_out_cov; cur_out_ch++ )
    3541             :     {
    3542        1509 :         UWord16 found = 0;
    3543        1509 :         move16();
    3544             : 
    3545        3246 :         FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
    3546             :         {
    3547        2686 :             Word32 diff_fx = 0;
    3548        2686 :             move32();
    3549        2686 :             Word32 *proto_fac_ptr_fx = proto_fac_fx + cur_diff_proto;
    3550        2686 :             const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
    3551        8310 :             FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
    3552             :             {
    3553        5624 :                 diff_fx = L_add( diff_fx, L_abs( L_sub( *proto_fac_ptr_fx, *proto_mtx_ptr ) ) );
    3554        5624 :                 proto_fac_ptr_fx += nchan_out_cov;
    3555        5624 :                 proto_mtx_ptr += nchan_out_cov;
    3556             :             }
    3557             : 
    3558             :             /* we already have this prototype, save the index */
    3559        2686 :             IF( LT_64( W_mult0_32_32( diff_fx, 10 ), L_shl_sat( 1, Q_proto_mtx ) ) )
    3560             :             {
    3561         949 :                 found = 1;
    3562         949 :                 move16();
    3563         949 :                 p_diff_proto_info->proto_index_diff[cur_out_ch] = cur_diff_proto;
    3564         949 :                 move16();
    3565         949 :                 BREAK;
    3566             :             }
    3567             :         }
    3568             : 
    3569             :         /* new distinct prototype, add it */
    3570        1509 :         IF( found == 0 )
    3571             :         {
    3572         560 :             const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
    3573             :             Word16 cur_num_src_chan;
    3574             : 
    3575         560 :             cur_num_src_chan = 0;
    3576         560 :             move16();
    3577        1710 :             FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
    3578             :             {
    3579        1150 :                 if ( GT_32( *proto_mtx_ptr, 0 /*EPSILON*/ ) )
    3580             :                 {
    3581         824 :                     cur_num_src_chan = add( cur_num_src_chan, 1 );
    3582             :                 }
    3583        1150 :                 proto_mtx_ptr += nchan_out_cov;
    3584             :             }
    3585             : 
    3586         560 :             mvr2r_inc_fixed( proto_mtx + cur_out_ch, nchan_out_cov, proto_fac_fx + p_diff_proto_info->num_protos_diff, nchan_out_cov, nchan_transport );
    3587             : 
    3588         560 :             p_diff_proto_info->proto_index_diff[cur_out_ch] = p_diff_proto_info->num_protos_diff;
    3589         560 :             move16();
    3590         560 :             p_diff_proto_info->num_protos_diff = add( p_diff_proto_info->num_protos_diff, 1 );
    3591         560 :             move16();
    3592         560 :             max_num_src_chan = s_max( max_num_src_chan, cur_num_src_chan );
    3593             :         }
    3594             :     }
    3595             : 
    3596             :     /* set up the prototype info struct */
    3597         279 :     IF( ( p_diff_proto_info->source_chan_idx = (Word16 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word16 * ) ) ) == NULL )
    3598             :     {
    3599           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
    3600             :     }
    3601             : 
    3602         279 :     IF( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL )
    3603             :     {
    3604           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
    3605             :     }
    3606        1118 :     FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
    3607             :     {
    3608             :         Word32 *proto_fac_ptr;
    3609             : 
    3610         839 :         IF( ( p_diff_proto_info->source_chan_idx[cur_diff_proto] = (Word16 *) malloc( max_num_src_chan * sizeof( Word16 ) ) ) == NULL )
    3611             :         {
    3612           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
    3613             :         }
    3614             : 
    3615         839 :         IF( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL )
    3616             :         {
    3617           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
    3618             :         }
    3619             : 
    3620         839 :         proto_fac_ptr = proto_fac_fx + cur_diff_proto;
    3621        2562 :         FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
    3622             :         {
    3623        1723 :             IF( GT_32( *proto_fac_ptr, EPSILON_FX_SMALL ) )
    3624             :             {
    3625        1103 :                 p_diff_proto_info->source_chan_idx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = cur_transport_ch;
    3626        1103 :                 move16();
    3627        1103 :                 p_diff_proto_info->proto_fac_fx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = *proto_fac_ptr; // (proto_fac_fx)Q26 = Q26
    3628        1103 :                 move16();
    3629        1103 :                 p_diff_proto_info->num_source_chan_diff[cur_diff_proto] = add( p_diff_proto_info->num_source_chan_diff[cur_diff_proto], 1 );
    3630        1103 :                 move16();
    3631             :             }
    3632        1723 :             proto_fac_ptr += nchan_out_cov;
    3633             :         }
    3634             :     }
    3635         279 :     return IVAS_ERR_OK;
    3636             : }
    3637             : 
    3638             : 
    3639             : /*-------------------------------------------------------------------------*
    3640             :  * ivas_param_mc_bs_decode_parameter_values()
    3641             :  *
    3642             :  * reads and decodes a sequence of Parametric MC parameters from the bitstream
    3643             :  *-------------------------------------------------------------------------*/
    3644             : 
    3645       20432 : static void ivas_param_mc_bs_decode_parameter_values_fx(
    3646             :     UWord16 bit_buffer[],                                   /* i  : bitstream buffer                                       */
    3647             :     Word16 *bit_pos,                                        /* i/o: current bitstream buffer position                      */
    3648             :     const Word16 max_bits,                                  /* i  : maximum available bits in the buffer                   */
    3649             :     Word16 *BER_detect,                                     /* i/o: bit error detection flag                               */
    3650             :     HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC,             /* i  : Parametric MC metadata information                     */
    3651             :     HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, /* i  : Parametric MC parameter quantization and coding tables */
    3652             :     const Word16 map_size_wo_lfe,                           /* i  : number of parameters per band (w/o LFEs)               */
    3653             :     const Word16 map_size,                                  /* i  : number of parameters per band (total)                  */
    3654             :     const Word16 num_lfe_bands,                             /* i  : number of parameter bands with coded LFE               */
    3655             :     const Word16 band_step,                                 /* i  : parameter band step                                    */
    3656             :     const Word16 num_param_bands,                           /* i  : number of parameter bands to decode                    */
    3657             :     Word16 *value_buffer                                    /* o  : output buffer for decoded parameter values             hParamCodingInfo -> Q-quant*/
    3658             : )
    3659             : {
    3660             :     Word16 range_coding;
    3661             :     Word16 sz_seq;
    3662             :     Word16 delta_coding;
    3663             :     Word16 delta_idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
    3664             :     Word16 idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
    3665             :     Word16 idx_prev;
    3666             :     Word16 idx_offset;
    3667             :     Word16 sz_alphabet;
    3668             :     Word16 i, j, k;
    3669             :     Word16 dequant_seq_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
    3670             :     Word16 dequant_ordered_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
    3671             :     Word16 n_lfe_idx;
    3672             : 
    3673       20432 :     range_coding = bit_buffer[*bit_pos];
    3674       20432 :     move16();
    3675       20432 :     *bit_pos = add( *bit_pos, 1 );
    3676       20432 :     move16();
    3677             : 
    3678             :     /* Decoding the sequence */
    3679       20432 :     n_lfe_idx = sub( map_size, map_size_wo_lfe );
    3680       20432 :     sz_seq = add( imult1616( num_param_bands, map_size_wo_lfe ), imult1616( num_lfe_bands, n_lfe_idx ) );
    3681             : 
    3682       20432 :     set16_fx( idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
    3683       20432 :     set16_fx( dequant_ordered_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
    3684       20432 :     set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
    3685       20432 :     IF( range_coding )
    3686             :     {
    3687       19968 :         delta_coding = bit_buffer[*bit_pos];
    3688       19968 :         move16();
    3689       19968 :         *bit_pos = add( *bit_pos, 1 );
    3690       19968 :         move16();
    3691             : 
    3692       19968 :         IF( delta_coding )
    3693             :         {
    3694       19715 :             idx_prev = sub( add( shr( hParamCodingInfo->quantizer_size, 1 ), hParamCodingInfo->quantizer_size % 2 ), 1 );
    3695       19715 :             sz_alphabet = sub( shl( hParamCodingInfo->quantizer_size, 1 ), 1 );
    3696       19715 :             idx_offset = sub( hParamCodingInfo->quantizer_size, 1 );
    3697             : 
    3698             :             /* read range coded delta ICC indices */
    3699       19715 :             *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], delta_idx, BER_detect, sz_seq, sz_alphabet,
    3700       19715 :                                                                          hParamCodingInfo->cum_freq_delta, hParamCodingInfo->sym_freq_delta, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
    3701       19715 :             move16();
    3702             : 
    3703             :             /* delta index to absolute index  */
    3704      629873 :             FOR( j = 0; j < sz_seq; j++ )
    3705             :             {
    3706      610158 :                 idx[j] = add( idx_prev, sub( delta_idx[j], idx_offset ) );
    3707      610158 :                 idx_prev = idx[j];
    3708      610158 :                 move16();
    3709             :             }
    3710             :         }
    3711             :         ELSE
    3712             :         {
    3713             :             /* read range coded absolute ICC indices */
    3714         253 :             sz_alphabet = hParamCodingInfo->quantizer_size;
    3715         253 :             move16();
    3716         253 :             *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], idx, BER_detect, sz_seq, sz_alphabet,
    3717         253 :                                                                          hParamCodingInfo->cum_freq, hParamCodingInfo->sym_freq, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
    3718         253 :             move16();
    3719             :         }
    3720             : 
    3721             :         /* dequantize */
    3722      636765 :         FOR( j = 0; j < sz_seq; j++ )
    3723             :         {
    3724      616797 :             dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; // hParamCodingInfo -> Q-quant
    3725      616797 :             move16();
    3726             :         }
    3727             :     }
    3728             :     ELSE
    3729             :     {
    3730         464 :         set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
    3731             :         /* read uniformly coded ICCs */
    3732         464 :         *bit_pos = add( *bit_pos, ivas_param_mc_uniform_decoder_fx( dequant_seq_fx, sz_seq, hParamCodingInfo->quantizer_fx, hParamCodingInfo->uni_bits, &bit_buffer[*bit_pos] ) );
    3733         464 :         move16();
    3734             :     }
    3735             : 
    3736             :     /* reorder from sequential to parameter-band-wise */
    3737       20432 :     k = 0;
    3738      115295 :     FOR( j = 0; j < map_size_wo_lfe; ++j )
    3739             :     {
    3740      722462 :         FOR( i = 0; i < num_param_bands; ++i )
    3741             :         {
    3742      627599 :             dequant_ordered_fx[j + ( i * map_size )] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
    3743      627599 :             move16();
    3744      627599 :             k = add( k, 1 );
    3745             :         }
    3746             :     }
    3747             : 
    3748       21600 :     FOR( i = 0; i < num_lfe_bands; i++ )
    3749             :     {
    3750        2401 :         FOR( j = 0; j < n_lfe_idx; j++ )
    3751             :         {
    3752        1233 :             dequant_ordered_fx[map_size - n_lfe_idx + j + i * map_size] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
    3753        1233 :             move16();
    3754        1233 :             k = add( k, 1 );
    3755             :         }
    3756             :     }
    3757             : 
    3758       20432 :     IF( !( *BER_detect ) )
    3759             :     {
    3760       20432 :         j = 0;
    3761      283922 :         FOR( k = 0; k < hMetadataPMC->nbands_coded; k += band_step )
    3762             :         {
    3763      263490 :             test();
    3764      263490 :             IF( hMetadataPMC->bAttackPresent || EQ_16( hMetadataPMC->param_frame_idx, hMetadataPMC->coding_band_mapping[k] ) )
    3765             :             {
    3766      134950 :                 Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); // hParamCodingInfo -> Q-quant
    3767      134950 :                 j++;
    3768             :             }
    3769      263490 :             IF( hMetadataPMC->bAttackPresent && k + 1 < hMetadataPMC->nbands_coded )
    3770             :             {
    3771        6264 :                 Copy( value_buffer + imult1616( k, map_size ), value_buffer + imult1616( add( k, 1 ), map_size ), map_size );
    3772             :             }
    3773             :         }
    3774             :     }
    3775             : 
    3776       20432 :     return;
    3777             : }

Generated by: LCOV version 1.14