LCOV - code coverage report
Current view: top level - lib_dec - ivas_spar_decoder_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 899 952 94.4 %
Date: 2025-05-03 01:55:50 Functions: 20 20 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 <stdint.h>
      34             : #include <math.h>
      35             : #include <assert.h>
      36             : #include "options.h"
      37             : #include "ivas_stat_dec.h"
      38             : #include "prot_fx.h"
      39             : #include "string.h"
      40             : #include "ivas_prot_rend_fx.h"
      41             : #include "rom_com.h"
      42             : #include "ivas_rom_com.h"
      43             : #include "ivas_rom_dec.h"
      44             : #include "ivas_stat_com.h"
      45             : #include "stat_com.h"
      46             : #include "wmc_auto.h"
      47             : #include "ivas_prot_fx.h"
      48             : #ifdef DEBUGGING
      49             : #include "debug.h"
      50             : #endif
      51             : 
      52             : /*-------------------------------------------------------------------*
      53             :  * Local function prototypes
      54             :  *--------------------------------------------------------------------*/
      55             : 
      56             : static ivas_error ivas_spar_dec_MD_fx( Decoder_Struct *st_ivas, Decoder_State *st0 );
      57             : 
      58             : 
      59             : /*-------------------------------------------------------------------------
      60             :  * ivas_spar_dec_open()
      61             :  *
      62             :  * Allocate and initialize SPAR decoder handle and sub-handles
      63             :  *------------------------------------------------------------------------*/
      64             : 
      65        1476 : ivas_error ivas_spar_dec_open_fx(
      66             :     Decoder_Struct *st_ivas,        /* i/o: IVAS decoder handle        */
      67             :     const Word16 spar_reconfig_flag /* i  : SPAR reconfiguration flag  Q0*/
      68             : )
      69             : {
      70             :     SPAR_DEC_HANDLE hSpar;
      71             :     ivas_error error;
      72             :     Word16 sba_order_internal, num_channels_internal;
      73             :     IVAS_FB_CFG *fb_cfg;
      74             :     Word16 i, j, b, active_w_mixing;
      75             :     Word32 output_Fs;
      76             :     Word16 num_decor_chs, map_idx;
      77             : 
      78        1476 :     error = IVAS_ERR_OK;
      79        1476 :     move32();
      80             : 
      81        1476 :     sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/
      82        1476 :     move16();
      83             : 
      84        1476 :     num_channels_internal = ivas_sba_get_nchan_metadata_fx( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/
      85             : 
      86        1476 :     hSpar = st_ivas->hSpar;
      87             : 
      88        1476 :     IF( !spar_reconfig_flag )
      89             :     {
      90             :         /* SPAR decoder handle */
      91         273 :         IF( ( hSpar = (SPAR_DEC_HANDLE) malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL )
      92             :         {
      93           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder" );
      94             :         }
      95             :     }
      96             : 
      97        1476 :     output_Fs = st_ivas->hDecoderConfig->output_Fs; /*Q0*/
      98        1476 :     move32();
      99        1476 :     IF( GT_16( num_channels_internal, ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 ) ) )
     100             :     {
     101          71 :         num_decor_chs = IVAS_HBR_MAX_DECOR_CHS; /*Q0*/
     102          71 :         move16();
     103             :     }
     104             :     ELSE
     105             :     {
     106        1405 :         num_decor_chs = sub( num_channels_internal, 1 ); /*Q0*/
     107             :     }
     108             : 
     109             :     /* TD decorr. */
     110        1476 :     test();
     111        1476 :     test();
     112        1476 :     test();
     113        1476 :     test();
     114        1476 :     IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && ( ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) || ( GE_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_256k ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) ) )
     115             :     {
     116         231 :         hSpar->hTdDecorr = NULL;
     117             :     }
     118             :     ELSE
     119             :     {
     120        1245 :         IF( ( error = ivas_td_decorr_dec_open_fx( &hSpar->hTdDecorr, output_Fs, add( num_decor_chs, 1 ), 1 ) ) != IVAS_ERR_OK )
     121             :         {
     122           0 :             return error;
     123             :         }
     124             :     }
     125             : 
     126             :     /* MD handle */
     127        1476 :     IF( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal, sba_order_internal, st_ivas->sid_format, st_ivas->last_active_ivas_total_brate ) ) != IVAS_ERR_OK )
     128             :     {
     129           0 :         return error;
     130             :     }
     131        1476 :     hSpar->hMdDec->td_decorr_flag = 1;
     132        1476 :     move16();
     133        1476 :     if ( hSpar->hTdDecorr )
     134             :     {
     135        1245 :         hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[hSpar->hMdDec->table_idx].td_ducking; /*Q0*/
     136        1245 :         move16();
     137             :     }
     138             : 
     139             :     /* set FB config. */
     140        1476 :     active_w_mixing = -1;
     141        1476 :     move16();
     142        1476 :     IF( NE_32( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, num_channels_internal, num_channels_internal, active_w_mixing, output_Fs, 0 ) ), IVAS_ERR_OK ) )
     143             :     {
     144           0 :         return error;
     145             :     }
     146        1476 :     fb_cfg->pcm_offset = NS2SA_FX2( output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); /*Q0*/
     147        1476 :     move16();
     148        1476 :     fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; /*Q0*/
     149        1476 :     move16();
     150             : 
     151             :     /* FB mixer handle */
     152        1476 :     IF( NE_32( ( error = ivas_FB_mixer_open_fx( &hSpar->hFbMixer, output_Fs, fb_cfg, spar_reconfig_flag ) ), IVAS_ERR_OK ) )
     153             :     {
     154           0 :         return error;
     155             :     }
     156             : 
     157             :     /* AGC handle */
     158        1476 :     IF( NE_32( ( error = ivas_spar_agc_dec_open_fx( &hSpar->hAgcDec, output_Fs ) ), IVAS_ERR_OK ) )
     159             :     {
     160           0 :         return error;
     161             :     }
     162             : 
     163             :     /* PCA handle */
     164        1476 :     hSpar->hPCA = NULL;
     165        1476 :     test();
     166        1476 :     IF( EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, PCA_BRATE ) && EQ_16( sba_order_internal, 1 ) )
     167             :     {
     168          32 :         IF( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL )
     169             :         {
     170           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" );
     171             :         }
     172             : 
     173          32 :         ivas_pca_dec_init_fx( hSpar->hPCA );
     174             :     }
     175             : 
     176             :     /* mixer_mat intitialization */
     177        8494 :     FOR( i = 0; i < num_channels_internal; i++ )
     178             :     {
     179       45426 :         FOR( j = 0; j < num_channels_internal; j++ )
     180             :         {
     181      499304 :             FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ )
     182             :             {
     183      460896 :                 hSpar->hMdDec->mixer_mat_fx[i][j][b] = 0;
     184      460896 :                 move32();
     185     2765376 :                 FOR( Word16 i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ )
     186             :                 {
     187     2304480 :                     hSpar->hMdDec->mixer_mat_prev_fx[i_ts][i][j][b] = 0;
     188     2304480 :                     move32();
     189             :                 }
     190             :             }
     191             :         }
     192             :     }
     193        1476 :     hSpar->hMdDec->Q_mixer_mat = Q31;
     194        1476 :     move16();
     195        1476 :     hSpar->i_subframe = 0;
     196        1476 :     move16();
     197        1476 :     hSpar->AGC_flag = 0;
     198        1476 :     move16();
     199             : 
     200             :     /*-----------------------------------------------------------------*
     201             :      * Configuration - set SPAR high-level parameters
     202             :      *-----------------------------------------------------------------*/
     203             : 
     204        1476 :     ivas_spar_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format );
     205             : 
     206        1476 :     SWITCH( sba_order_internal )
     207             :     {
     208        1236 :         case 1:
     209        1236 :             st_ivas->transport_config = IVAS_AUDIO_CONFIG_FOA;
     210        1236 :             move32();
     211        1236 :             BREAK;
     212          55 :         case 2:
     213          55 :             st_ivas->transport_config = IVAS_AUDIO_CONFIG_HOA2;
     214          55 :             move32();
     215          55 :             BREAK;
     216         185 :         case 3:
     217         185 :             st_ivas->transport_config = IVAS_AUDIO_CONFIG_HOA3;
     218         185 :             move32();
     219         185 :             BREAK;
     220             :     }
     221             : 
     222        1476 :     ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config );
     223             : 
     224        1476 :     set16_fx( hSpar->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
     225        1476 :     set16_fx( hSpar->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); /*Q0*/
     226        1476 :     hSpar->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;                                             /*Q0*/
     227        1476 :     move16();
     228        1476 :     hSpar->subframes_rendered = 0;
     229        1476 :     move16();
     230        1476 :     hSpar->slots_rendered = 0;
     231        1476 :     move16();
     232        1476 :     hSpar->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; /*Q0*/
     233        1476 :     move16();
     234             : 
     235             :     /* init render timeslot mapping */
     236        1476 :     set16_fx( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
     237       25092 :     FOR( map_idx = 0; map_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; map_idx++ )
     238             :     {
     239       23616 :         hSpar->render_to_md_map[map_idx] = map_idx; /*Q0*/
     240       23616 :         move16();
     241             :     }
     242             : 
     243             :     /* allocate transport channels*/
     244        1476 :     IF( st_ivas->hTcBuffer == NULL )
     245             :     {
     246             :         Word16 nchan_to_allocate;
     247             :         Word16 nchan_tc;
     248             :         TC_BUFFER_MODE buffer_mode;
     249             :         Word16 granularity;
     250             : 
     251         273 :         buffer_mode = TC_BUFFER_MODE_RENDERER;
     252         273 :         move32();
     253         273 :         nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/
     254         273 :         nchan_to_allocate = num_channels_internal;                 /*Q0*/
     255         273 :         move16();
     256             : 
     257         273 :         test();
     258         273 :         if ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     259             :         {
     260          12 :             nchan_to_allocate = add( nchan_to_allocate, st_ivas->nchan_ism ); /*Q0*/
     261             :         }
     262             : 
     263         273 :         granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/
     264         273 :         move16();
     265             : 
     266         273 :         test();
     267         273 :         test();
     268         273 :         test();
     269         273 :         IF( ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) )
     270             :         {
     271          14 :             test();
     272          14 :             test();
     273          14 :             IF( ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
     274             :             {
     275           1 :                 nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*Q0*/
     276           1 :                 nchan_to_allocate = nchan_tc;                                             /*Q0*/
     277           1 :                 move16();
     278             :             }
     279             :             ELSE
     280             :             {
     281          13 :                 buffer_mode = TC_BUFFER_MODE_BUFFER;
     282          13 :                 move32();
     283          13 :                 nchan_tc = st_ivas->hDecoderConfig->nchan_out; /*Q0*/
     284          13 :                 move16();
     285          13 :                 nchan_to_allocate = nchan_tc; /*Q0*/
     286          13 :                 move16();
     287             :             }
     288             :         }
     289         259 :         ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
     290             :         {
     291          47 :             nchan_to_allocate = 2 * BINAURAL_CHANNELS;
     292          47 :             move16();
     293             :         }
     294             : 
     295         273 :         test();
     296         273 :         test();
     297         273 :         test();
     298         273 :         IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     299             :         {
     300             :             /* get correct granularity in case of binaural rendering of the discrete objects with the td obj renderer */
     301             :             Word32 quo, rem;
     302           4 :             iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &quo, &rem, 0 );
     303           4 :             granularity = extract_l( quo ); /*Q0*/
     304             :         }
     305             : 
     306         273 :         IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) )
     307             :         {
     308           0 :             return error;
     309             :         }
     310             :     }
     311             : 
     312        1476 :     st_ivas->hSpar = hSpar;
     313             : 
     314        1476 :     return error;
     315             : }
     316             : 
     317             : 
     318             : /*-------------------------------------------------------------------------
     319             :  * ivas_spar_dec_close()
     320             :  *
     321             :  * Deallocate SPAR handle
     322             :  *------------------------------------------------------------------------*/
     323             : 
     324        1807 : void ivas_spar_dec_close_fx(
     325             :     SPAR_DEC_HANDLE *hSpar,         /* i/o: SPAR decoder handle        */
     326             :     const Word32 output_Fs,         /* i  : output sampling rate       Q0*/
     327             :     const Word16 spar_reconfig_flag /* i  : SPAR reconfiguration flag  Q0*/
     328             : )
     329             : {
     330        1807 :     test();
     331        1807 :     IF( hSpar == NULL || *hSpar == NULL )
     332             :     {
     333         331 :         return;
     334             :     }
     335             : 
     336             :     /* MD handle */
     337        1476 :     ivas_spar_md_dec_close( &( *hSpar )->hMdDec );
     338             : 
     339             :     /* TD decorrelator handle */
     340        1476 :     ivas_td_decorr_dec_close( &( *hSpar )->hTdDecorr );
     341             : 
     342             :     /* FB mixer handle */
     343        1476 :     ivas_FB_mixer_close_fx( &( *hSpar )->hFbMixer, output_Fs, spar_reconfig_flag );
     344             : 
     345             :     /* AGC */
     346        1476 :     ivas_spar_agc_dec_close_fx( &( *hSpar )->hAgcDec );
     347             : 
     348             :     /* PCA */
     349        1476 :     IF( ( *hSpar )->hPCA != NULL )
     350             :     {
     351          24 :         free( ( *hSpar )->hPCA );
     352          24 :         ( *hSpar )->hPCA = NULL;
     353             :     }
     354             : 
     355        1476 :     IF( !spar_reconfig_flag )
     356             :     {
     357         273 :         free( ( *hSpar ) );
     358         273 :         ( *hSpar ) = NULL;
     359             :     }
     360             : 
     361        1476 :     return;
     362             : }
     363             : 
     364             : 
     365             : /*-------------------------------------------------------------------*
     366             :  * ivas_spar_dec()
     367             :  *
     368             :  * Principal IVAS SPAR decoder routine
     369             :  *-------------------------------------------------------------------*/
     370             : 
     371      149027 : ivas_error ivas_spar_dec_fx(
     372             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct             */
     373             :     Word16 *nb_bits_read     /* o  : number of MD bits read          Q0*/
     374             : )
     375             : {
     376             :     DECODER_CONFIG_HANDLE hDecoderConfig;
     377             :     Word16 i, nb_bits_read_orig;
     378             :     Decoder_State *st0;
     379             :     Word16 next_bit_pos_orig, last_bit_pos;
     380             :     UWord16 bstr_meta[MAX_BITS_METADATA], *bit_stream_orig;
     381             :     ivas_error error;
     382             :     Word32 quo, rem;
     383             : 
     384      149027 :     push_wmops( "ivas_spar_decode" );
     385      149027 :     error = IVAS_ERR_OK;
     386      149027 :     move32();
     387      149027 :     hDecoderConfig = st_ivas->hDecoderConfig;
     388             : 
     389      149027 :     st0 = NULL;
     390      149027 :     IF( st_ivas->nSCE > 0 )
     391             :     {
     392       41554 :         st0 = st_ivas->hSCE[0]->hCoreCoder[0];
     393             :     }
     394             :     ELSE
     395             :     {
     396      107473 :         st0 = st_ivas->hCPE[0]->hCoreCoder[0];
     397             :     }
     398             : 
     399      149027 :     bit_stream_orig = st0->bit_stream;     /*Q0*/
     400      149027 :     next_bit_pos_orig = st0->next_bit_pos; /*Q0*/
     401      149027 :     move16();
     402             : 
     403      149027 :     IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     404             :     {
     405       30003 :         iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
     406       30003 :         last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); /*Q0*/
     407             :     }
     408             :     ELSE
     409             :     {
     410      119024 :         *nb_bits_read = 0;
     411      119024 :         move16();
     412      119024 :         last_bit_pos = 0;
     413      119024 :         move16();
     414             :     }
     415             : 
     416             :     /* read DirAC bitstream */
     417      149027 :     IF( st_ivas->hQMetaData != NULL )
     418             :     {
     419      149027 :         ivas_dirac_dec_read_BS_fx( hDecoderConfig->ivas_total_brate, st0, st_ivas->hDirAC, st_ivas->hSpatParamRendCom, st_ivas->hQMetaData, nb_bits_read, last_bit_pos, ivas_get_hodirac_flag_fx( hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ), st_ivas->hSpar->dirac_to_spar_md_bands );
     420             :     }
     421             : 
     422      149027 :     IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     423             :     {
     424       30003 :         iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
     425       30003 :         last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); /*Q0*/
     426             :     }
     427             :     ELSE
     428             :     {
     429      119024 :         iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
     430      119024 :         last_bit_pos = extract_l( L_sub( quo, 1 ) ); /*Q0*/
     431             :     }
     432             : 
     433      149027 :     test();
     434      149027 :     if ( !st0->bfi && EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
     435             :     {
     436         324 :         last_bit_pos = sub( last_bit_pos, SID_FORMAT_NBITS ); /*Q0*/
     437             :     }
     438      149027 :     nb_bits_read_orig = *nb_bits_read; /*Q0*/
     439      149027 :     move16();
     440      149027 :     last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /*Q0*/
     441             : 
     442             :     /* reverse the bitstream for easier reading of indices */
     443   225377204 :     FOR( i = 0; i < s_min( MAX_BITS_METADATA, last_bit_pos ); i++ )
     444             :     {
     445   225228177 :         bstr_meta[i] = st_ivas->bit_stream[( last_bit_pos - i )]; /*Q0*/
     446   225228177 :         move16();
     447             :     }
     448      149027 :     st0->bit_stream = bstr_meta; /*Q0*/
     449      149027 :     st0->next_bit_pos = 0;
     450      149027 :     move16();
     451      149027 :     st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) ); /*Q0*/
     452      149027 :     move16();
     453             : 
     454      149027 :     if ( !st0->bfi )
     455             :     {
     456      142968 :         st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ /*Q0*/
     457      142968 :         move32();
     458             :     }
     459             : 
     460             :     /*---------------------------------------------------------------------*
     461             :      * Decode SPAR metadata
     462             :      *---------------------------------------------------------------------*/
     463             : 
     464      149027 :     IF( NE_32( ( error = ivas_spar_dec_MD_fx( st_ivas, st0 ) ), IVAS_ERR_OK ) )
     465             :     {
     466           0 :         return error;
     467             :     }
     468             : 
     469      149027 :     *nb_bits_read = add( st0->next_bit_pos, nb_bits_read_orig ); /*Q0*/
     470      149027 :     move16();
     471      149027 :     st0->bit_stream = bit_stream_orig;     /*Q0*/
     472      149027 :     st0->next_bit_pos = next_bit_pos_orig; /*Q0*/
     473      149027 :     move16();
     474             : 
     475      149027 :     test();
     476      149027 :     IF( !st0->bfi && EQ_32( hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
     477             :     {
     478             :         Word16 zero_pad_bits;
     479         324 :         *nb_bits_read = add( *nb_bits_read, SID_FORMAT_NBITS ); /*Q0*/
     480         324 :         move16();
     481         324 :         zero_pad_bits = sub( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC, *nb_bits_read ); /*Q0*/
     482         324 :         assert( zero_pad_bits <= 1 );
     483         324 :         *nb_bits_read = add( *nb_bits_read, zero_pad_bits ); /*Q0*/
     484         324 :         move16();
     485             :     }
     486             : 
     487      149027 :     pop_wmops();
     488             : 
     489      149027 :     return error;
     490             : }
     491             : 
     492             : 
     493             : /*---------------------------------------------------------------------*
     494             :  * Function ivas_get_spar_table_idx_from_coded_idx()
     495             :  *
     496             :  * Get SPAR table index
     497             :  *---------------------------------------------------------------------*/
     498             : 
     499      140580 : static Word16 ivas_get_spar_table_idx_from_coded_idx(
     500             :     const Word32 ivas_total_brate, /* i  : IVAS total bitrate                              Q0*/
     501             :     const Word16 sba_order,        /* i  : Ambisonic (SBA) order                           Q0*/
     502             :     Decoder_State *st0,            /* i/o: decoder state structure - for bitstream handling*/
     503             :     Word16 *bitlen                 /* o  : number of bits                                  Q0*/
     504             : )
     505             : {
     506             :     Word16 table_idx, ind1[IVAS_SPAR_BR_TABLE_LEN];
     507             :     Word16 i, j, ind2;
     508             : 
     509      140580 :     j = 0;
     510      140580 :     move16();
     511     2952180 :     FOR( i = 0; i < IVAS_SPAR_BR_TABLE_LEN; i++ )
     512             :     {
     513     2811600 :         ind1[j] = 0;
     514     2811600 :         move16();
     515     2811600 :         test();
     516     2811600 :         IF( EQ_32( ivas_spar_br_table_consts[i].ivas_total_brate, ivas_total_brate ) && EQ_16( ivas_spar_br_table_consts[i].sba_order, sba_order ) )
     517             :         {
     518      140580 :             ind1[j] = i;
     519      140580 :             move16();
     520      140580 :             j = add( j, 1 );
     521             :         }
     522             :     }
     523             : 
     524      140580 :     assert( j > 0 );
     525      140580 :     *bitlen = ivas_get_bits_to_encode( sub( j, 1 ) ); /*Q0*/
     526      140580 :     move16();
     527             : 
     528      140580 :     ind2 = get_next_indice_fx( st0, *bitlen ); /*Q0*/
     529             : 
     530      140580 :     table_idx = ind1[ind2]; /*Q0*/
     531      140580 :     move16();
     532             : 
     533      140580 :     return table_idx;
     534             : }
     535             : 
     536             : 
     537             : /*---------------------------------------------------------------------*
     538             :  * Function ivas_parse_spar_header()
     539             :  *
     540             :  * Get SPAR table index
     541             :  *---------------------------------------------------------------------*/
     542             : 
     543      140580 : static Word16 ivas_parse_spar_header(
     544             :     const Word32 ivas_total_brate, /* i  : IVAS total bitrate                              Q0*/
     545             :     const Word16 sba_order,        /* i  : Ambisonic (SBA) order                           Q0*/
     546             :     Decoder_State *st0,            /* i/o: decoder state structure - for bitstream handling*/
     547             :     Word16 *table_idx /*Q0*/ )
     548             : {
     549             :     Word16 bitlen, bwidth;
     550             : 
     551      140580 :     *table_idx = ivas_get_spar_table_idx_from_coded_idx( ivas_total_brate, sba_order, st0, &bitlen ); /*Q0*/
     552      140580 :     move16();
     553             : 
     554      140580 :     bwidth = ivas_spar_br_table_consts[( *table_idx )].bwidth; /*Q0*/
     555      140580 :     move16();
     556             : 
     557      140580 :     return bwidth;
     558             : }
     559             : 
     560             : 
     561      571920 : static Word16 get_random_number_fx(
     562             :     Word16 *seed )
     563             : {
     564      571920 :     return Random( seed ); /*Q15*/
     565             : }
     566             : 
     567             : 
     568       10944 : static Word32 matrix_det_fx(
     569             :     const Word32 a00, /*Q27*/
     570             :     const Word32 a01, /*Q27*/
     571             :     const Word32 a10, /*Q27*/
     572             :     const Word32 a11  /*Q27*/
     573             : )
     574             : {
     575       10944 :     return L_sub( Mpy_32_32( a00, a11 ), Mpy_32_32( a01, a10 ) ); /*Q23*/
     576             : }
     577             : 
     578             : 
     579         912 : static void matrix_inverse_fx(
     580             :     Word32 in[3][3],  /*Q27*/
     581             :     Word32 out[3][3], /*out_q*/
     582             :     const Word16 size,
     583             :     Word16 *out_q )
     584             : {
     585             :     Word32 det, fac, tmp_32;
     586         912 :     Word32 eps_fx = 1;
     587         912 :     move32();
     588         912 :     Word16 q_fac, shift = 0, tmp_e = 0;
     589         912 :     move16();
     590         912 :     move16();
     591             : 
     592         912 :     IF( EQ_16( size, 1 ) )
     593             :     {
     594           0 :         tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q27, L_max( in[0][0], eps_fx ), &tmp_e ); /*Q: 15 - tmp_e*/
     595           0 :         shift = norm_l( tmp_32 );
     596           0 :         out[0][0] = L_shl( tmp_32, shift ); /*out_q*/
     597           0 :         move32();
     598           0 :         *out_q = add( shift, sub( Q15, tmp_e ) );
     599           0 :         move16();
     600             : 
     601           0 :         return;
     602             :     }
     603         912 :     ELSE IF( EQ_16( size, 2 ) )
     604             :     {
     605           0 :         det = matrix_det_fx( in[0][1], in[0][1], in[1][0], in[1][1] );                    /*Q23*/
     606           0 :         tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q23, L_max( det, eps_fx ), &tmp_e ); /*Q: 15 - tmp_e*/
     607           0 :         shift = norm_l( tmp_32 );
     608           0 :         fac = L_shl( tmp_32, shift ); /*q_fac*/
     609           0 :         q_fac = add( shift, sub( Q15, tmp_e ) );
     610             : 
     611           0 :         out[0][0] = Mpy_32_32( in[1][1], fac ); /*q_fac - 4*/
     612           0 :         move32();
     613           0 :         out[1][0] = Mpy_32_32( in[1][0], L_negate( fac ) ); /*q_fac - 4*/
     614           0 :         move32();
     615             : 
     616           0 :         out[0][1] = Mpy_32_32( in[0][1], L_negate( fac ) ); /*q_fac - 4*/
     617           0 :         move32();
     618           0 :         out[1][1] = Mpy_32_32( in[0][0], fac ); /*q_fac - 4*/
     619           0 :         move32();
     620             : 
     621           0 :         *out_q = add( Q27, sub( q_fac, 31 ) );
     622           0 :         move16();
     623             : 
     624           0 :         return;
     625             :     }
     626             : 
     627         912 :     det = L_add( L_sub( Mpy_32_32( in[0][0], matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ) ), Mpy_32_32( in[1][0], matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ) ) ), Mpy_32_32( in[2][0], matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ) ) ); /*Q19*/
     628         912 :     tmp_32 = BASOP_Util_Divide3232_Scale( ONE_IN_Q19, L_max( det, eps_fx ), &tmp_e );                                                                                                                                                                                       /*Q: 31 - tmp_e*/
     629         912 :     shift = norm_l( tmp_32 );
     630         912 :     fac = L_shl( tmp_32, shift ); /*q_fac*/
     631         912 :     q_fac = add( shift, sub( Q15, tmp_e ) );
     632             : 
     633         912 :     out[0][0] = Mpy_32_32( matrix_det_fx( in[1][1], in[1][2], in[2][1], in[2][2] ), fac ); /*q_fac-8*/
     634         912 :     move32();
     635         912 :     out[1][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][2], in[2][0], in[2][2] ), L_negate( fac ) ); /*q_fac-8*/
     636         912 :     move32();
     637         912 :     out[2][0] = Mpy_32_32( matrix_det_fx( in[1][0], in[1][1], in[2][0], in[2][1] ), fac ); /*q_fac-8*/
     638         912 :     move32();
     639             : 
     640         912 :     out[0][1] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[2][1], in[2][2] ), L_negate( fac ) ); /*q_fac-8*/
     641         912 :     move32();
     642         912 :     out[1][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[2][0], in[2][2] ), fac ); /*q_fac-8*/
     643         912 :     move32();
     644         912 :     out[2][1] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[2][0], in[2][1] ), L_negate( fac ) ); /*q_fac-8*/
     645         912 :     move32();
     646             : 
     647         912 :     out[0][2] = Mpy_32_32( matrix_det_fx( in[0][1], in[0][2], in[1][1], in[1][2] ), fac ); /*q_fac-8*/
     648         912 :     move32();
     649         912 :     out[1][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][2], in[1][0], in[1][2] ), L_negate( fac ) ); /*q_fac-8*/
     650         912 :     move32();
     651         912 :     out[2][2] = Mpy_32_32( matrix_det_fx( in[0][0], in[0][1], in[1][0], in[1][1] ), fac ); /*q_fac-8*/
     652         912 :     move32();
     653             : 
     654         912 :     *out_q = add( Q23, sub( q_fac, 31 ) );
     655         912 :     move16();
     656             : 
     657         912 :     return;
     658             : }
     659             : 
     660             : 
     661             : /*---------------------------------------------------------------------*
     662             :  * Function ivas_spar_get_cldfb_gains()
     663             :  *
     664             :  *
     665             :  *---------------------------------------------------------------------*/
     666             : 
     667         912 : void ivas_spar_get_cldfb_gains_fx(
     668             :     SPAR_DEC_HANDLE hSpar,
     669             :     HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0,
     670             :     HANDLE_CLDFB_FILTER_BANK cldfbSynDec0,
     671             :     const DECODER_CONFIG_HANDLE hDecoderConfig )
     672             : {
     673         912 :     Word32 output_Fs_fx = hDecoderConfig->output_Fs;
     674             :     Word16 *weights_fx;
     675             :     Word16 cf_start_s_fx, cf_len_s_fx;
     676             :     Word32 T_fx[3 * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX - CLDFB_NO_CHANNELS_MAX][3];
     677             :     Word32 Tt_T_fx[3][3];
     678             :     Word32 Tt_T_inv_fx[3][3];
     679             :     Word32 Tt_tgt_fx[3];
     680             :     Word32 ts_inout_fx[CLDFB_NO_CHANNELS_MAX];
     681             :     Word32 ts_re_fx[CLDFB_NO_CHANNELS_MAX];
     682             :     Word32 ts_im_fx[CLDFB_NO_CHANNELS_MAX];
     683             :     Word32 *pp_ts_im_fx[1], *pp_ts_re_fx[1];
     684             :     Word32 tgt_fx[( 3 - 1 ) * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX];
     685             :     Word16 pt_len, stride, num_cldfb_bands, decfb_delay;
     686             :     Word16 encfb_delay, cf_start, cf_end, cf_len;
     687             :     Word16 ts, cf_cldfb_start, cf_cldfb_end;
     688             :     Word16 sample, num_cf_slots, num_samples;
     689             :     Word16 seed, split_band, slot_row, slot_col, slot, tmp_idx;
     690             :     Word16 Q_cf_start_s;
     691             :     Word16 Q_cf_len_s;
     692             :     Word16 Q_weights;
     693             : 
     694         912 :     pt_len = cldfbAnaDec0->p_filter_length; /*Q0*/
     695         912 :     move16();
     696         912 :     num_cldfb_bands = cldfbAnaDec0->no_channels; /*Q0*/
     697         912 :     move16();
     698             : 
     699         912 :     stride = NS2SA_FX2( output_Fs_fx, DELAY_CLDFB_NS );            /*Q0*/
     700         912 :     encfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_ENC_DELAY_NS ); /*Q0*/
     701         912 :     decfb_delay = NS2SA_FX2( output_Fs_fx, IVAS_FB_DEC_DELAY_NS ); /*Q0*/
     702             : 
     703         912 :     cf_start = add( sub( hSpar->hFbMixer->cross_fade_start_offset, encfb_delay ), decfb_delay ); /* time domain after CLDFB synthesis*/ /*Q0*/
     704         912 :     cf_end = add( sub( hSpar->hFbMixer->cross_fade_end_offset, encfb_delay ), decfb_delay );                                            /*Q0*/
     705         912 :     cf_len = sub( cf_end, cf_start );
     706         912 :     weights_fx = hSpar->hFbMixer->cldfb_cross_fade_fx;                                                                                                              /*hSpar->hFbMixer->cldfb_cross_fade_q*/
     707         912 :     cf_cldfb_start = shr( extract_l( ceil_fixed( sub( divide1616( sub( cf_start, shr( decfb_delay, 1 ) ), shl( stride, 9 ) ), 32 ), 6 ) ), 6 );                     /*Q0*/
     708         912 :     cf_cldfb_end = shr( divide1616( add( sub( cf_start, shr( decfb_delay, 1 ) ), cf_len ), shl( stride, 9 ) ), 6 ); /*q-factor of stride is 9(as max value is 60)*/ /*Q0*/
     709         912 :     num_cf_slots = add( sub( cf_cldfb_end, cf_cldfb_start ), 1 );                                                                                                   /*Q0*/
     710         912 :     num_samples = add( imult1616( num_cf_slots, stride ), sub( pt_len, stride ) );                                                                                  /*Q0*/
     711         912 :     seed = RANDOM_INITSEED;
     712         912 :     move16();
     713         912 :     split_band = SPAR_DIRAC_SPLIT_START_BAND;
     714         912 :     move16();
     715         912 :     pp_ts_im_fx[0] = ts_im_fx; /*Q22*/
     716         912 :     pp_ts_re_fx[0] = ts_re_fx; /*Q22*/
     717         912 :     set32_fx( tgt_fx, 0, ( 3 - 1 ) * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX );
     718         912 :     cf_start_s_fx = divide3232( ( sub( cf_start, shr( decfb_delay, 1 ) ) ), output_Fs_fx );                                            /*Q_cf_start_s*/
     719         912 :     cf_len_s_fx = divide3232( sub( hSpar->hFbMixer->cross_fade_end_offset, hSpar->hFbMixer->cross_fade_start_offset ), output_Fs_fx ); /*Q_cf_len_s*/
     720         912 :     Q_cf_start_s = sub( norm_s( cf_start_s_fx ), 1 );
     721         912 :     Q_cf_len_s = norm_s( cf_len_s_fx );
     722         912 :     Q_weights = add( 15, sub( Q_cf_start_s, Q_cf_len_s ) );
     723       15504 :     FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
     724             :     {
     725       14592 :         weights_fx[ts] = divide1616( shl( sub( divide3232( L_mult0( add( shl( ts, 1 ), 1 ), shr( stride, 1 ) ), output_Fs_fx ), cf_start_s_fx ), Q_cf_start_s ), shl( cf_len_s_fx, Q_cf_len_s ) ); /*Q_weights*/
     726       14592 :         move16();
     727       14592 :         weights_fx[ts] = s_max( s_min( weights_fx[ts], shl( 1, Q_weights ) ), 0 ); /*Q_weights*/
     728       14592 :         move16();
     729             :     }
     730         912 :     hSpar->hFbMixer->cldfb_cross_fade_start = cf_cldfb_start; /*Q0*/
     731         912 :     move16();
     732         912 :     hSpar->hFbMixer->cldfb_cross_fade_end = cf_cldfb_end; /*Q0*/
     733         912 :     move16();
     734             : 
     735         912 :     test();
     736         912 :     test();
     737         912 :     test();
     738         912 :     if ( GT_16( num_cf_slots, 3 ) || GT_16( pt_len, 10 * CLDFB_NO_CHANNELS_MAX ) || GT_16( stride, CLDFB_NO_CHANNELS_MAX ) || EQ_16( split_band, IVAS_MAX_NUM_BANDS ) )
     739             :     {
     740           0 :         return;
     741             :     }
     742             : 
     743             :     /* optimization*/
     744             :     /* compute time-domain cross-fade for considered time slots*/
     745         912 :     tmp_idx = sub( cf_start, imult1616( cf_cldfb_start, stride ) ); /*Q0*/
     746      153424 :     FOR( sample = 0; sample < cf_len; sample++ )
     747             :     {
     748      152512 :         tgt_fx[tmp_idx] = L_deposit_h( hSpar->hFbMixer->pFilterbank_cross_fade_fx[sample] ); /*Q31*/
     749      152512 :         move32();
     750      152512 :         tmp_idx = add( tmp_idx, 1 );
     751             :         /* increasing window function */
     752             :     }
     753      344064 :     FOR( ; tmp_idx < num_samples; tmp_idx++ )
     754             :     {
     755             :         /* fill up with ones*/
     756      343152 :         tgt_fx[tmp_idx] = MAX_32; /*Q31*/
     757      343152 :         move32();
     758             :     }
     759      572832 :     FOR( sample = 0; sample < num_samples; sample++ )
     760             :     {
     761             :         /* initialize trasnform matrix with zeros*/
     762      571920 :         T_fx[sample][0] = T_fx[sample][1] = T_fx[sample][2] = 0;
     763      571920 :         move32();
     764      571920 :         move32();
     765      571920 :         move32();
     766             :     }
     767             : 
     768      429852 :     FOR( sample = 0; sample < sub( pt_len, stride ); sample++ )
     769             :     {
     770             :         /* fill internal CLDFB analysis time buffer with data*/
     771      428940 :         Word16 x_fx = get_random_number_fx( &seed );              /*Q15*/
     772      428940 :         cldfbAnaDec0->cldfb_state_fx[sample] = L_shl( x_fx, 12 ); /*Q27*/
     773      428940 :         move32();
     774             :     }
     775         912 :     Word16 q_cldfb = 27;
     776         912 :     move16();
     777         912 :     cldfbAnaDec0->Q_cldfb_state = q_cldfb;
     778         912 :     move16();
     779        3648 :     FOR( slot = 0; slot < num_cf_slots; slot++ )
     780             :     {
     781      145716 :         FOR( sample = 0; sample < stride; sample++ )
     782             :         {
     783      142980 :             Word16 x_fx = get_random_number_fx( &seed ); /*Q15*/
     784      142980 :             ts_inout_fx[sample] = L_shl( x_fx, 12 );     /*Q27*/
     785      142980 :             move32();
     786             :         }
     787             : 
     788        2736 :         cldfbAnalysis_ts_fx_fixed_q( ts_inout_fx, ts_re_fx, ts_im_fx, num_cldfb_bands, cldfbAnaDec0, &q_cldfb );
     789        2736 :         cldfb_reset_memory_fx( cldfbSynDec0 );
     790             : #ifdef OPT_AVOID_STATE_BUF_RESCALE
     791        2736 :         cldfbSynthesis_ivas_fx( pp_ts_re_fx, pp_ts_im_fx, ts_inout_fx, num_cldfb_bands, 0, 0, cldfbSynDec0 );
     792             : #else  /* OPT_AVOID_STATE_BUF_RESCALE */
     793             :         cldfbSynthesis_ivas_fx( pp_ts_re_fx, pp_ts_im_fx, ts_inout_fx, num_cldfb_bands, 0, cldfbSynDec0 );
     794             : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
     795      145716 :         FOR( sample = 0; sample < stride; sample++ )
     796             :         {
     797      142980 :             T_fx[( ( slot * stride ) + sample )][slot] = ts_inout_fx[sample]; /*Q21*/
     798      142980 :             move32();
     799             :         }
     800        2736 :         tmp_idx = sub( pt_len, 1 ); /*Q0*/
     801     1289556 :         FOR( sample = stride; sample < pt_len; sample++ )
     802             :         {
     803     1286820 :             T_fx[( ( slot * stride ) + sample )][slot] = cldfbSynDec0->cldfb_state_fx[tmp_idx]; /*Q21*/
     804     1286820 :             move32();
     805     1286820 :             tmp_idx = sub( tmp_idx, 1 ); /*Q0*/
     806             :         }
     807             :     }
     808             : 
     809             :     /* target is synthesis output times the cross-fade window*/
     810      572832 :     FOR( sample = 0; sample < num_samples; sample++ )
     811             :     {
     812      571920 :         tgt_fx[sample] = L_shl( Mpy_32_32( tgt_fx[sample], L_add( T_fx[sample][0], L_add( T_fx[sample][1], T_fx[sample][2] ) ) ), 10 ); /*Q31*/
     813      571920 :         move32();
     814             :     }
     815             :     /* compute matrices */
     816        3648 :     FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ )
     817             :     {
     818        8208 :         FOR( slot_col = slot_row; slot_col < num_cf_slots; slot_col++ )
     819             :         {
     820        5472 :             Tt_T_fx[slot_row][slot_col] = 0;
     821        5472 :             move32();
     822     3436992 :             FOR( sample = 0; sample < num_samples; sample++ )
     823             :             {
     824     3431520 :                 Tt_T_fx[slot_row][slot_col] = L_add( Tt_T_fx[slot_row][slot_col], Mpy_32_32( L_shl( T_fx[sample][slot_row], 8 ), L_shl( T_fx[sample][slot_col], 8 ) ) ); /*Q58-Q31*/
     825     3431520 :                 move32();
     826             :             }
     827             :         }
     828             :     }
     829             : 
     830         912 :     Tt_T_fx[1][0] = Tt_T_fx[0][1]; /*Q27*/
     831         912 :     move32();
     832         912 :     Tt_T_fx[2][0] = Tt_T_fx[0][2]; /*Q27*/
     833         912 :     move32();
     834         912 :     Tt_T_fx[2][1] = Tt_T_fx[1][2]; /*Q27*/
     835         912 :     move32();
     836        3648 :     FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ )
     837             :     {
     838        2736 :         Tt_tgt_fx[slot_row] = 0;
     839        2736 :         move32();
     840     1718496 :         FOR( sample = 0; sample < num_samples; sample++ )
     841             :         {
     842     1715760 :             Tt_tgt_fx[slot_row] = L_add( Tt_tgt_fx[slot_row], Mpy_32_32( T_fx[sample][slot_row], tgt_fx[sample] ) ); /*Q21*/
     843     1715760 :             move32();
     844             :         }
     845             :     }
     846         912 :     Word16 output_q = 27;
     847         912 :     move16();
     848         912 :     matrix_inverse_fx( Tt_T_fx, Tt_T_inv_fx, num_cf_slots, &output_q );
     849             :     /* compute the optimal coefficients */
     850        3648 :     FOR( slot_row = 0; slot_row < num_cf_slots; slot_row++ )
     851             :     {
     852        2736 :         Word32 tmp = 0;
     853        2736 :         move32();
     854       10944 :         FOR( slot_col = 0; slot_col < num_cf_slots; slot_col++ )
     855             :         {
     856        8208 :             tmp = L_add( tmp, Mpy_32_32( Tt_T_inv_fx[slot_row][slot_col], Tt_tgt_fx[slot_col] ) ); /*output_q-10*/
     857             :         }
     858        2736 :         weights_fx[( cf_cldfb_start + slot_row )] = extract_l( L_shr( L_max( L_min( tmp, L_shl( 1, sub( output_q, 10 ) ) ), 0 ), sub( sub( output_q, 10 ), Q_weights ) ) ); /*Q_weights*/
     859        2736 :         move16();
     860             :     }
     861         912 :     hSpar->hFbMixer->cldfb_cross_fade_q = Q_weights;
     862         912 :     move16();
     863             : 
     864         912 :     cldfb_reset_memory_fx( cldfbSynDec0 );
     865         912 :     cldfb_reset_memory_fx( cldfbAnaDec0 );
     866             : 
     867         912 :     return;
     868             : }
     869   126078252 : Word16 ivas_is_res_channel(
     870             :     const Word16 ch,             /* i  : ch index in WYZX ordering          Q0*/
     871             :     const Word16 nchan_transport /* i  : number of transport channels (1-4) Q0*/
     872             : )
     873             : {
     874   126078252 :     const Word16 rc_map[FOA_CHANNELS][FOA_CHANNELS] = {
     875             :         { 0, 0, 0, 0 },
     876             :         { 0, 1, 0, 0 },
     877             :         { 0, 1, 0, 1 },
     878             :         { 0, 1, 1, 1 }
     879             :     };
     880             : 
     881   126078252 :     if ( GE_16( ch, FOA_CHANNELS ) )
     882             :     {
     883             :         /* never transmitted */
     884    17441376 :         return 0;
     885             :     }
     886   108636876 :     assert( nchan_transport <= FOA_CHANNELS );
     887             : 
     888   108636876 :     return ( rc_map[nchan_transport - 1][ch] ); /*Q0*/
     889             : }
     890             : 
     891             : 
     892             : /*-------------------------------------------------------------------*
     893             :  * ivas_spar_dec_MD()
     894             :  *
     895             :  * IVAS SPAR MD decoder
     896             :  *-------------------------------------------------------------------*/
     897             : 
     898      149027 : static ivas_error ivas_spar_dec_MD_fx(
     899             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle                             */
     900             :     Decoder_State *st0       /* i/o: decoder state structure - for bitstream handling*/
     901             : )
     902             : {
     903             :     Word16 num_channels, table_idx, num_bands_out, bfi, sba_order;
     904             :     Word32 ivas_total_brate;
     905             :     Word16 num_md_sub_frames;
     906             :     ivas_error error;
     907      149027 :     DECODER_CONFIG_HANDLE hDecoderConfig = st_ivas->hDecoderConfig;
     908      149027 :     SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
     909             : 
     910      149027 :     push_wmops( "ivas_spar_dec_MD" );
     911             : 
     912             :     /*---------------------------------------------------------------------*
     913             :      * Initialization
     914             :      *---------------------------------------------------------------------*/
     915             : 
     916      149027 :     sba_order = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/
     917      149027 :     bfi = st_ivas->bfi;                                                   /*Q0*/
     918      149027 :     move16();
     919      149027 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /*Q0*/
     920      149027 :     move32();
     921      149027 :     num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate );                                                                 /*Q0*/
     922      149027 :     num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); /*Q0*/
     923             : 
     924      149027 :     num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/
     925      149027 :     move16();
     926             : 
     927      149027 :     test();
     928      149027 :     IF( ( ivas_total_brate > FRAME_NO_DATA ) && !bfi )
     929             :     {
     930      140904 :         IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
     931             :         {
     932      140580 :             ivas_parse_spar_header( hDecoderConfig->ivas_total_brate, sba_order, st0, &table_idx );
     933             : 
     934      140580 :             IF( hSpar->hMdDec->spar_hoa_md_flag )
     935             :             {
     936       20813 :                 hSpar->hMdDec->spar_md.num_bands = IVAS_MAX_NUM_BANDS;
     937       20813 :                 move16();
     938             :             }
     939             :             ELSE
     940             :             {
     941      119767 :                 hSpar->hMdDec->spar_md.num_bands = s_min( SPAR_DIRAC_SPLIT_START_BAND, IVAS_MAX_NUM_BANDS ); /*Q0*/
     942      119767 :                 move16();
     943             :             }
     944             : 
     945      140580 :             IF( NE_16( hSpar->hMdDec->table_idx, table_idx ) )
     946             :             {
     947         288 :                 hSpar->hMdDec->table_idx = table_idx; /*Q0*/
     948         288 :                 move16();
     949         288 :                 if ( hSpar->hTdDecorr )
     950             :                 {
     951         258 :                     hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; /*Q0*/
     952         258 :                     move16();
     953             :                 }
     954             : 
     955         288 :                 IF( NE_32( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels, sba_order ) ), IVAS_ERR_OK ) )
     956             :                 {
     957           0 :                     return error;
     958             :                 }
     959             :             }
     960             :         }
     961             : 
     962             :         /*---------------------------------------------------------------------*
     963             :          * Decode MD
     964             :          *---------------------------------------------------------------------*/
     965             : 
     966      140904 :         ivas_spar_md_dec_process_fx( st_ivas, st0, num_bands_out, sba_order );
     967             : 
     968             :         /*---------------------------------------------------------------------*
     969             :          * read PCA bits
     970             :          *---------------------------------------------------------------------*/
     971             : 
     972      140904 :         IF( hSpar->hPCA != NULL )
     973             :         {
     974        9840 :             ivas_pca_read_bits_fx( st0, hSpar->hPCA );
     975             :         }
     976             : 
     977             :         /*---------------------------------------------------------------------*
     978             :          * Read AGC bits
     979             :          *---------------------------------------------------------------------*/
     980             : 
     981      140904 :         test();
     982      140904 :         test();
     983      140904 :         IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && !bfi && hSpar->hMdDec->dtx_vad )
     984             :         {
     985      140347 :             IF( EQ_16( hSpar->hMdDec->spar_md_cfg.nchan_transport, 1 ) )
     986             :             {
     987       37355 :                 hSpar->AGC_flag = get_next_indice_fx( st0, 1 );
     988       37355 :                 move16();
     989             :             }
     990             : 
     991      140347 :             ivas_agc_read_bits_fx( hSpar->hAgcDec, st0, hSpar->hMdDec->spar_md_cfg.nchan_transport, hSpar->AGC_flag );
     992             :         }
     993             : 
     994             :         /*---------------------------------------------------------------------*
     995             :          * MD smoothing
     996             :          *---------------------------------------------------------------------*/
     997             : 
     998      140904 :         test();
     999      140904 :         test();
    1000      140904 :         test();
    1001      140904 :         IF( EQ_16( st0->m_old_frame_type, ZERO_FRAME ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && ( st0->prev_bfi == 0 ) && EQ_16( hSpar->hMdDec->spar_md_cfg.nchan_transport, 1 ) )
    1002             :         {
    1003         125 :             ivas_spar_setup_md_smoothing_fx( hSpar->hMdDec, num_bands_out, num_md_sub_frames );
    1004             :         }
    1005             :         ELSE
    1006             :         {
    1007      140779 :             ivas_spar_update_md_hist_fx( hSpar->hMdDec );
    1008             :         }
    1009             :     }
    1010             :     ELSE
    1011             :     {
    1012        8123 :         IF( !bfi )
    1013             :         {
    1014        2064 :             ivas_spar_smooth_md_dtx_fx( hSpar->hMdDec, num_bands_out, num_md_sub_frames );
    1015             :         }
    1016             : 
    1017        8123 :         set16_fx( hSpar->hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS );
    1018             :     }
    1019             : 
    1020      149027 :     pop_wmops();
    1021      149027 :     return IVAS_ERR_OK;
    1022             : }
    1023             : 
    1024             : 
    1025             : /*-------------------------------------------------------------------*
    1026             :  * ivas_spar_get_cldfb_slot_gain()
    1027             :  *
    1028             :  *
    1029             :  *-------------------------------------------------------------------*/
    1030             : 
    1031     2172452 : static Word16 ivas_spar_get_cldfb_slot_gain_fx(
    1032             :     SPAR_DEC_HANDLE hSpar,                      /* i/o: SPAR decoder handle     */
    1033             :     const DECODER_CONFIG_HANDLE hDecoderConfig, /* i  : configuration structure */
    1034             :     const Word16 time_slot_idx,                 /*Q0*/
    1035             :     Word16 *time_slot_idx0,                     /*Q0*/
    1036             :     Word16 *time_slot_idx1,                     /*Q0*/
    1037             :     Word16 *weight_lowfreq_fx                   /*Q15*/
    1038             : )
    1039             : {
    1040             :     Word16 weight_fx;
    1041             :     Word32 encfb_delay_fx, decfb_delay_fx;
    1042             :     Word32 xfade_start_ns_fx;
    1043             :     Word16 xfade_delay_subframes;
    1044             :     Word16 i_hist;
    1045             :     Word16 split_band;
    1046             : 
    1047     2172452 :     *weight_lowfreq_fx = hSpar->hFbMixer->cldfb_cross_fade_fx[time_slot_idx]; /*Q15*/
    1048     2172452 :     move16();
    1049             : 
    1050     2172452 :     encfb_delay_fx = IVAS_FB_ENC_DELAY_NS;
    1051     2172452 :     move32();
    1052     2172452 :     decfb_delay_fx = IVAS_FB_DEC_DELAY_NS;
    1053     2172452 :     move32();
    1054     2172452 :     Word32 one_by_outfs = 0; // Q15
    1055     2172452 :     move32();
    1056     2172452 :     SWITCH( hDecoderConfig->output_Fs )
    1057             :     {
    1058      192000 :         case 16000:
    1059      192000 :             one_by_outfs = 2048000000; /* 1000000000.0f/(output_Fs) in Q15 */
    1060      192000 :             move32();
    1061      192000 :             BREAK;
    1062      948144 :         case 32000:
    1063      948144 :             one_by_outfs = 1024000000; /* 1000000000.0f/(output_Fs) in Q15 */
    1064      948144 :             move32();
    1065      948144 :             BREAK;
    1066     1032308 :         case 48000:
    1067     1032308 :             one_by_outfs = 682666688; /* 1000000000.0f/(output_Fs) in Q15 */
    1068     1032308 :             move32();
    1069     1032308 :             BREAK;
    1070           0 :         default:
    1071           0 :             assert( 0 );
    1072             :     }
    1073             : 
    1074     2172452 :     Word64 fade_start = W_mult0_32_32( one_by_outfs, hSpar->hFbMixer->cross_fade_start_offset ); /*Q15*/
    1075     2172452 :     move64();
    1076     2172452 :     fade_start = W_shr( fade_start, 15 );                                                                                                             /*Q0*/
    1077     2172452 :     xfade_start_ns_fx = L_add( L_sub( W_extract_l( fade_start ), encfb_delay_fx ), L_shr( decfb_delay_fx, 1 ) );                                      /*Q0*/
    1078     2172452 :     xfade_delay_subframes = extract_l( Mpy_32_32( xfade_start_ns_fx, 429 /* 1 / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 -> 429 */ ) ); /*Q0*/
    1079             : 
    1080     2172452 :     i_hist = sub( 4, xfade_delay_subframes ); /*Q0*/
    1081     2172452 :     split_band = SPAR_DIRAC_SPLIT_START_BAND;
    1082     2172452 :     move16();
    1083             : 
    1084     2172452 :     IF( LT_16( split_band, IVAS_MAX_NUM_BANDS ) )
    1085             :     {
    1086     2172452 :         IF( GT_16( hSpar->i_subframe, 3 ) )
    1087             :         {
    1088     2152708 :             Word16 mod_res = time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES;
    1089     2152708 :             move16();
    1090     2152708 :             SWITCH( mod_res )
    1091             :             {
    1092      538189 :                 case 0:
    1093      538189 :                     weight_fx = 0;
    1094      538189 :                     move16();
    1095      538189 :                     BREAK;
    1096      538168 :                 case 1:
    1097      538168 :                     weight_fx = 8191; /*0.25f in Q15*/
    1098      538168 :                     move16();
    1099      538168 :                     BREAK;
    1100      538175 :                 case 2:
    1101      538175 :                     weight_fx = 16383; /*0.5f in Q15*/
    1102      538175 :                     move16();
    1103      538175 :                     BREAK;
    1104      538176 :                 case 3:
    1105      538176 :                     weight_fx = 24575; /*0.75f in Q15*/
    1106      538176 :                     move16();
    1107      538176 :                     BREAK;
    1108           0 :                 default:
    1109           0 :                     weight_fx = 0;
    1110           0 :                     move16();
    1111           0 :                     BREAK;
    1112             :             }
    1113             :         }
    1114             :         ELSE
    1115             :         {
    1116       19744 :             weight_fx = 0;
    1117       19744 :             move16();
    1118             :         }
    1119     2172452 :         *time_slot_idx0 = i_hist; /*Q0*/
    1120     2172452 :         move16();
    1121     2172452 :         *time_slot_idx1 = add( i_hist, 1 ); /*Q0*/
    1122     2172452 :         move16();
    1123             :     }
    1124             :     ELSE
    1125             :     {
    1126             :         /* determine cross-fade gain for current frame Parameters*/
    1127           0 :         *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; /*Q0*/
    1128           0 :         move16();
    1129           0 :         *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; /*Q0*/
    1130           0 :         move16();
    1131           0 :         weight_fx = *weight_lowfreq_fx; /*Q15*/
    1132           0 :         move16();
    1133             :     }
    1134             : 
    1135     2172452 :     return weight_fx; /*Q15*/
    1136             : }
    1137             : 
    1138             : 
    1139             : /*-------------------------------------------------------------------*
    1140             :  * ivas_spar_get_parameters()
    1141             :  *
    1142             :  *
    1143             :  *-------------------------------------------------------------------*/
    1144             : 
    1145     2172452 : void ivas_spar_get_parameters_fx(
    1146             :     SPAR_DEC_HANDLE hSpar,                                                    /* i/o: SPAR decoder handle     */
    1147             :     const DECODER_CONFIG_HANDLE hDecoderConfig,                               /* i  : configuration structure */
    1148             :     const Word16 ts,                                                          /*Q0*/
    1149             :     const Word16 num_ch_out,                                                  /*Q0*/
    1150             :     const Word16 num_ch_in,                                                   /*Q0*/
    1151             :     const Word16 num_spar_bands,                                              /*Q0*/
    1152             :     Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /*hSpar->hMdDec->Q_mixer_mat*/
    1153             : )
    1154             : {
    1155             :     Word16 spar_band, out_ch, in_ch;
    1156             :     Word16 weight_fx, weight_20ms_fx;
    1157             :     Word16 ts0, ts1, split_band;
    1158             : 
    1159             :     // weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms);
    1160     2172452 :     weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx ); /*Q15*/
    1161             : 
    1162     2172452 :     split_band = SPAR_DIRAC_SPLIT_START_BAND;
    1163     2172452 :     move16();
    1164     2172452 :     Word16 add_weight_fx = sub( MAX_WORD16, weight_fx );
    1165     2172452 :     Word16 add_weight_20ms_fx = sub( MAX_WORD16, weight_20ms_fx );
    1166    27857876 :     FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
    1167             :     {
    1168   145868496 :         FOR( out_ch = 0; out_ch < num_ch_out; out_ch++ )
    1169             :         {
    1170   120183072 :             test();
    1171   120183072 :             IF( LT_16( split_band, IVAS_MAX_NUM_BANDS )
    1172             :                 /* 20ms cross-fade for Transport channels in all frequency bands */
    1173             :                 && ( 0 == ivas_is_res_channel( out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/
    1174             :             )
    1175             :             {
    1176   534515712 :                 FOR( in_ch = 0; in_ch < num_ch_in; in_ch++ )
    1177             :                 {
    1178   451026336 :                     IF( GT_16( hSpar->i_subframe, 3 ) )
    1179             :                     {
    1180   446765088 :                         par_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx ),
    1181   446765088 :                                                                            hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], add_weight_fx );
    1182   446765088 :                         move32();
    1183             :                     }
    1184             :                     ELSE
    1185             :                     {
    1186     4261248 :                         par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; /*hSpar->hMdDec->Q_mixer_mat*/
    1187     4261248 :                         move32();
    1188             :                     }
    1189             :                 }
    1190             :             }
    1191             :             ELSE
    1192             :             {
    1193   235792608 :                 FOR( in_ch = 0; in_ch < num_ch_in; in_ch++ )
    1194             :                 {
    1195             :                     /* 20ms Transport channel reconstruction with matching encoder/decoder processing */
    1196   199098912 :                     Word16 prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */
    1197   199098912 :                     move16();
    1198   199098912 :                     par_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], add_weight_20ms_fx ),
    1199   199098912 :                                                                        hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx ); /*hSpar->hMdDec->Q_mixer_mat*/
    1200   199098912 :                     move32();
    1201             :                 }
    1202             :             }
    1203             :         }
    1204             :     }
    1205             : 
    1206     2172452 :     return;
    1207             : }
    1208             : 
    1209             : 
    1210             : /*-------------------------------------------------------------------*
    1211             :  * ivas_spar_get_skip_mat()
    1212             :  *
    1213             :  *
    1214             :  *-------------------------------------------------------------------*/
    1215             : 
    1216      396212 : static void ivas_spar_get_skip_mat_fx(
    1217             :     SPAR_DEC_HANDLE hSpar,                               /* i/o: SPAR decoder handle */
    1218             :     const Word16 num_ch_out,                             /*Q0*/
    1219             :     const Word16 num_ch_in,                              /*Q0*/
    1220             :     const Word16 num_spar_bands,                         /*Q0*/
    1221             :     Word16 skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q0*/
    1222             :     const Word16 num_md_sub_frames                       /*Q0*/
    1223             : )
    1224             : {
    1225             :     Word16 spar_band, out_ch, in_ch;
    1226             :     Word16 i_ts, skip_flag;
    1227             : 
    1228     2344422 :     FOR( out_ch = 0; out_ch < num_ch_out; out_ch++ )
    1229             :     {
    1230    13270070 :         FOR( in_ch = 0; in_ch < num_ch_in; in_ch++ )
    1231             :         {
    1232    11321860 :             skip_mat[out_ch][in_ch] = 1;
    1233    11321860 :             move16();
    1234    11321860 :             skip_flag = 1;
    1235    11321860 :             move16();
    1236    38592610 :             FOR( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ )
    1237             :             {
    1238   362530874 :                 FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
    1239             :                 {
    1240   335260124 :                     IF( hSpar->hMdDec->mixer_mat_prev_fx[1 + i_ts][out_ch][in_ch][spar_band] != 0 )
    1241             :                     {
    1242     4552618 :                         skip_flag = 0;
    1243     4552618 :                         move16();
    1244     4552618 :                         BREAK;
    1245             :                     }
    1246             :                 }
    1247             : 
    1248    31823368 :                 IF( skip_flag == 0 )
    1249             :                 {
    1250     4552618 :                     skip_mat[out_ch][in_ch] = 0;
    1251     4552618 :                     move16();
    1252     4552618 :                     BREAK;
    1253             :                 }
    1254             :             }
    1255             : 
    1256    11321860 :             IF( EQ_16( skip_mat[out_ch][in_ch], 1 ) )
    1257             :             {
    1258    24021594 :                 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ )
    1259             :                 {
    1260   221704902 :                     FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
    1261             :                     {
    1262   204452550 :                         IF( hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][( spar_band + ( i_ts * IVAS_MAX_NUM_BANDS ) )] != 0 )
    1263             :                         {
    1264       30830 :                             skip_flag = 0;
    1265       30830 :                             move16();
    1266       30830 :                             BREAK;
    1267             :                         }
    1268             :                     }
    1269             : 
    1270    17283182 :                     IF( skip_flag == 0 )
    1271             :                     {
    1272       30830 :                         skip_mat[out_ch][in_ch] = 0;
    1273       30830 :                         move16();
    1274       30830 :                         BREAK;
    1275             :                     }
    1276             :                 }
    1277             :             }
    1278             :         }
    1279             :     }
    1280             : 
    1281      396212 :     return;
    1282             : }
    1283             : 
    1284             : 
    1285        5132 : static void ivas_spar_calc_smooth_facs_fx(
    1286             :     Word32 *cldfb_in_ts_re_fx[CLDFB_NO_COL_MAX], // i q_cldfb
    1287             :     Word32 *cldfb_in_ts_im_fx[CLDFB_NO_COL_MAX], // i q_cldfb
    1288             :     Word16 q_cldfb,
    1289             :     Word16 nbands_spar,           /*Q0*/
    1290             :     const Word16 nSlots,          /*Q0*/
    1291             :     const Word16 isFirstSubframe, /*Q0*/
    1292             :     ivas_fb_bin_to_band_data_t *bin2band,
    1293             :     Word16 *smooth_fac_fx,                                                        // o Q15
    1294             :     Word32 smooth_buf_fx[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1] ) // o Q0
    1295             : {
    1296             :     Word16 b, bin, i, ts;
    1297             :     Word32 subframe_band_nrg_fx[IVAS_MAX_NUM_BANDS];
    1298             :     Word32 smooth_long_avg_fx[IVAS_MAX_NUM_BANDS];
    1299             :     Word32 smooth_short_avg_fx[IVAS_MAX_NUM_BANDS];
    1300             :     Word32 L_temp;
    1301             :     Word16 exp_tmp, q_tmp;
    1302        5132 :     bin = 0;
    1303        5132 :     move16();
    1304       62504 :     FOR( b = 0; b < nbands_spar; b++ )
    1305             :     {
    1306       61584 :         test();
    1307       61584 :         test();
    1308       61584 :         if ( GE_16( bin, CLDFB_NO_CHANNELS_MAX ) || ( ( b > 0 ) && LT_16( bin2band->p_cldfb_map_to_spar_band[bin], bin2band->p_cldfb_map_to_spar_band[bin - 1] ) ) )
    1309             :         {
    1310             :             BREAK;
    1311             :         }
    1312             : 
    1313             :         /* calculate band-wise subframe energies */
    1314       57372 :         subframe_band_nrg_fx[b] = 0;
    1315       57372 :         move32();
    1316      281052 :         WHILE( LT_16( bin, CLDFB_NO_CHANNELS_MAX ) && EQ_16( b, bin2band->p_cldfb_map_to_spar_band[bin] ) )
    1317             :         {
    1318      223680 :             test();
    1319     1118400 :             FOR( ts = 0; ts < nSlots; ts++ )
    1320             :             {
    1321      894720 :                 L_temp = L_add( L_shr( Mpy_32_32( cldfb_in_ts_re_fx[ts][bin], cldfb_in_ts_re_fx[ts][bin] ), 4 ), L_shr( Mpy_32_32( cldfb_in_ts_im_fx[ts][bin], cldfb_in_ts_im_fx[ts][bin] ), 4 ) ); // 2*q_cldfb - 35
    1322      894720 :                 subframe_band_nrg_fx[b] = L_add_sat( subframe_band_nrg_fx[b], L_temp );                                                                                                             // 2*q_cldfb - 35 (saturation reached in 1 orig pytest)
    1323      894720 :                 move32();
    1324             :             }
    1325      223680 :             bin = add( bin, 1 );
    1326             :         }
    1327       57372 :         exp_tmp = sub( 66, shl( q_cldfb, 1 ) );
    1328       57372 :         subframe_band_nrg_fx[b] = Sqrt32( subframe_band_nrg_fx[b], &exp_tmp );
    1329       57372 :         move32();
    1330       57372 :         q_tmp = sub( 31, exp_tmp );
    1331       57372 :         test();
    1332       57372 :         IF( isFirstSubframe && LT_16( nSlots, MAX_PARAM_SPATIAL_SUBFRAMES ) )
    1333             :         {
    1334             :             /* fill up to full 5ms subframe */
    1335           0 :             smooth_buf_fx[b][0] = L_add( smooth_buf_fx[b][0], L_shr( subframe_band_nrg_fx[b], q_tmp ) ); // Q0
    1336           0 :             move32();
    1337             :         }
    1338             :         ELSE
    1339             :         {
    1340       57372 :             smooth_buf_fx[b][0] = L_shr( subframe_band_nrg_fx[b], q_tmp ); // Q0
    1341       57372 :             move32();
    1342             :         }
    1343             :         /* calculate short and long energy averages */
    1344       57372 :         smooth_short_avg_fx[b] = 0;
    1345       57372 :         move32();
    1346      401604 :         FOR( i = 0; i < 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i++ )
    1347             :         {
    1348      344232 :             smooth_short_avg_fx[b] = L_add( smooth_short_avg_fx[b], smooth_buf_fx[b][i] ); // Q0
    1349      344232 :             move32();
    1350             :         }
    1351             : 
    1352       57372 :         smooth_long_avg_fx[b] = smooth_short_avg_fx[b]; // Q0
    1353       57372 :         move32();
    1354      860580 :         FOR( i = 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i < 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i++ )
    1355             :         {
    1356      803208 :             smooth_long_avg_fx[b] = L_add( smooth_long_avg_fx[b], smooth_buf_fx[b][i] ); // Q0
    1357      803208 :             move32();
    1358             :         }
    1359       57372 :         smooth_short_avg_fx[b] = Mpy_32_32( smooth_short_avg_fx[b], 357913941 /*(1/6 in Q31)*/ ); // Q0
    1360       57372 :         move32();
    1361       57372 :         smooth_long_avg_fx[b] = Mpy_32_32( smooth_long_avg_fx[b], 107374182 /*(1/20 in Q31)*/ ); // Q0
    1362       57372 :         move32();
    1363             : 
    1364             :         /* calculate smoothing factor based on energy averages */
    1365             :         /* reduce factor for higher short-term energy */
    1366       57372 :         IF( smooth_long_avg_fx[b] <= 0 )
    1367             :         {
    1368       23101 :             smooth_fac_fx[b] = 0;
    1369       23101 :             move16();
    1370             :         }
    1371       34271 :         ELSE IF( GE_32( smooth_long_avg_fx[b], smooth_short_avg_fx[b] ) )
    1372             :         {
    1373       17923 :             smooth_fac_fx[b] = MAX_16; // 1.0f in Q15
    1374       17923 :             move16();
    1375             :         }
    1376             :         ELSE
    1377             :         {
    1378       16348 :             smooth_fac_fx[b] = divide3232( smooth_long_avg_fx[b], smooth_short_avg_fx[b] ); // Q15
    1379       16348 :             move16();
    1380             :         }
    1381             : 
    1382             :         /* map factor to range [0;1] */
    1383       57372 :         smooth_fac_fx[b] = shl( mult_r( s_max( 0, sub( smooth_fac_fx[b], 9830 ) ), 23405 /*Q14*/ ), 1 ); // Q15
    1384       57372 :         move16();
    1385             : 
    1386             :         /* compress factor (higher compression in lowest bands) */
    1387       57372 :         IF( LT_16( b, 2 ) )
    1388             :         {
    1389       10264 :             exp_tmp = 0;
    1390       10264 :             move16();
    1391       10264 :             smooth_fac_fx[b] = Sqrt16( smooth_fac_fx[b], &exp_tmp );
    1392       10264 :             move16();
    1393       10264 :             smooth_fac_fx[b] = Sqrt16( smooth_fac_fx[b], &exp_tmp );
    1394       10264 :             move16();
    1395       10264 :             smooth_fac_fx[b] = shl( smooth_fac_fx[b], exp_tmp ); // Q15
    1396       10264 :             move16();
    1397             :         }
    1398             :         ELSE
    1399             :         {
    1400       47108 :             exp_tmp = 0;
    1401       47108 :             move16();
    1402       47108 :             smooth_fac_fx[b] = Sqrt16( smooth_fac_fx[b], &exp_tmp );
    1403       47108 :             move16();
    1404       47108 :             smooth_fac_fx[b] = shl( smooth_fac_fx[b], exp_tmp ); // Q15
    1405       47108 :             move16();
    1406             :         }
    1407             : 
    1408             :         /* apply upper bounds depending on band */
    1409       57372 :         smooth_fac_fx[b] = s_max( min_smooth_gains1_fx[b], s_min( max_smooth_gains2_fx[b], smooth_fac_fx[b] ) ); /*Q15*/
    1410       57372 :         move16();
    1411             :     }
    1412             : 
    1413             :     /* only update if we collected a full 5ms worth of energies for the buffer */
    1414        5132 :     test();
    1415        5132 :     IF( isFirstSubframe || EQ_16( nSlots, MAX_PARAM_SPATIAL_SUBFRAMES ) )
    1416             :     {
    1417       66716 :         FOR( b = 0; b < nbands_spar; b++ )
    1418             :         {
    1419     1293264 :             FOR( i = 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i > 0; i-- )
    1420             :             {
    1421     1231680 :                 smooth_buf_fx[b][i] = smooth_buf_fx[b][i - 1]; /*Q0*/
    1422     1231680 :                 move32();
    1423             :             }
    1424             :         }
    1425             :     }
    1426        5132 :     return;
    1427             : }
    1428             : 
    1429             : 
    1430             : /*-------------------------------------------------------------------*
    1431             :  * ivas_spar_dec_agc_pca()
    1432             :  *
    1433             :  *
    1434             :  *-------------------------------------------------------------------*/
    1435             : 
    1436       99723 : void ivas_spar_dec_agc_pca_fx(
    1437             :     Decoder_Struct *st_ivas,  /* i/o: IVAS decoder handle                     */
    1438             :     Word32 *output[],         /* i/o: input/output audio channels             Q14*/
    1439             :     const Word16 output_frame /* i  : output frame length                     Q0*/
    1440             : )
    1441             : {
    1442             :     Word16 nchan_transport;
    1443             :     Word16 num_in_ingest;
    1444             :     DECODER_CONFIG_HANDLE hDecoderConfig;
    1445             :     SPAR_DEC_HANDLE hSpar;
    1446             : 
    1447       99723 :     push_wmops( "ivas_spar_dec_agc_pca" );
    1448             : 
    1449       99723 :     hSpar = st_ivas->hSpar;
    1450       99723 :     hDecoderConfig = st_ivas->hDecoderConfig;
    1451       99723 :     nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/
    1452       99723 :     move16();
    1453             : 
    1454       99723 :     IF( GE_16( st_ivas->nchan_transport, 3 ) )
    1455             :     {
    1456             :         Word32 temp;
    1457             :         Word16 i;
    1458             :         /*convert WYZX downmix to WYXZ*/
    1459    50902238 :         FOR( i = 0; i < output_frame; i++ )
    1460             :         {
    1461    50839680 :             temp = output[2][i]; /*Q14*/
    1462    50839680 :             move32();
    1463    50839680 :             output[2][i] = output[3][i]; /*Q14*/
    1464    50839680 :             move32();
    1465    50839680 :             output[3][i] = temp; /*Q14*/
    1466    50839680 :             move32();
    1467             :         }
    1468             :     }
    1469             : 
    1470       99723 :     IF( hSpar->hMdDec->td_decorr_flag )
    1471             :     {
    1472       99723 :         num_in_ingest = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/
    1473             :     }
    1474             :     ELSE
    1475             :     {
    1476           0 :         num_in_ingest = nchan_transport; /*Q0*/
    1477           0 :         move16();
    1478             :     }
    1479             : 
    1480             :     /*---------------------------------------------------------------------*
    1481             :      * AGC
    1482             :      *---------------------------------------------------------------------*/
    1483             : 
    1484       99723 :     ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output ), ( output ), nchan_transport, output_frame );
    1485             : 
    1486       99723 :     IF( hSpar->hPCA != NULL )
    1487             :     {
    1488       10580 :         ivas_pca_dec_fx( hSpar->hPCA, output_frame, num_in_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output );
    1489             :     }
    1490       99723 :     pop_wmops();
    1491             : 
    1492       99723 :     return;
    1493             : }
    1494             : 
    1495             : 
    1496             : /*-------------------------------------------------------------------*
    1497             :  * ivas_spar_dec_set_render_map()
    1498             :  *
    1499             :  *
    1500             :  *-------------------------------------------------------------------*/
    1501             : 
    1502      135777 : void ivas_spar_dec_set_render_map_fx(
    1503             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure  */
    1504             :     const Word16 nCldfbTs    /* i  : number of CLDFB time slots Q0*/
    1505             : )
    1506             : {
    1507             :     SPAR_DEC_HANDLE hSpar;
    1508             : 
    1509      135777 :     hSpar = st_ivas->hSpar;
    1510             : 
    1511             :     /* adapt subframes */
    1512      135777 :     hSpar->num_slots = nCldfbTs; /*Q0*/
    1513      135777 :     move16();
    1514      135777 :     hSpar->slots_rendered = 0;
    1515      135777 :     move16();
    1516      135777 :     hSpar->subframes_rendered = 0;
    1517      135777 :     move16();
    1518             : 
    1519      135777 :     set16_fx( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
    1520      135777 :     ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpar->subframe_nbslots, &hSpar->nb_subframes );
    1521             : 
    1522             :     /* copy also to tc buffer */
    1523             :     /* only for non-combined formats and combinded formats w/o discrete objects */
    1524      135777 :     test();
    1525      135777 :     IF( !( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) )
    1526             :     {
    1527      124887 :         st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes; /*Q0*/
    1528      124887 :         move16();
    1529      124887 :         Copy( hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpar->nb_subframes ); /*Q0*/
    1530             :     }
    1531             : 
    1532      135777 :     ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, 1, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hSpar->render_to_md_map );
    1533             : 
    1534      135777 :     return;
    1535             : }
    1536             : 
    1537             : 
    1538             : /*-------------------------------------------------------------------*
    1539             :  * ivas_spar_dec_upmixer()
    1540             :  *
    1541             :  * IVAS SPAR upmixer
    1542             :  *-------------------------------------------------------------------*/
    1543             : 
    1544      135777 : void ivas_spar_dec_set_render_params_fx(
    1545             :     Decoder_Struct *st_ivas,   /* i/o: IVAS decoder handle                     */
    1546             :     const Word16 n_cldfb_slots /* i  : number of cldfb slots in this frame     Q0*/
    1547             : )
    1548             : {
    1549             :     SPAR_DEC_HANDLE hSpar;
    1550             :     Word16 nchan_transport;
    1551             :     Word16 num_bands_out;
    1552             : 
    1553      135777 :     hSpar = st_ivas->hSpar;
    1554      135777 :     nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/
    1555      135777 :     move16();
    1556      135777 :     num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/
    1557      135777 :     move16();
    1558      135777 :     ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) );
    1559             : 
    1560      135777 :     ivas_spar_dec_set_render_map_fx( st_ivas, n_cldfb_slots );
    1561             : 
    1562      135777 :     return;
    1563             : }
    1564             : 
    1565             : 
    1566             : /*-------------------------------------------------------------------*
    1567             :  * ivas_spar_dec_digest_tc()
    1568             :  *
    1569             :  *
    1570             :  *-------------------------------------------------------------------*/
    1571             : 
    1572      135777 : void ivas_spar_dec_digest_tc_fx(
    1573             :     Decoder_Struct *st_ivas,          /* i/o: IVAS decoder handle          */
    1574             :     const Word16 nchan_transport,     /* i  : number of transport channels Q0*/
    1575             :     const Word16 nCldfbSlots,         /* i  : number of CLDFB slots        Q0*/
    1576             :     const Word16 nSamplesForRendering /* i  : number of samples provided   Q0*/
    1577             : )
    1578             : {
    1579             :     SPAR_DEC_HANDLE hSpar;
    1580             : 
    1581      135777 :     hSpar = st_ivas->hSpar;
    1582      135777 :     test();
    1583      135777 :     test();
    1584      135777 :     IF( hSpar->hMdDec->td_decorr_flag && !( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
    1585             :     {
    1586             :         Word16 nchan_internal, ch;
    1587             :         Word16 ch_sba_idx;
    1588             :         Word16 nSamplesLeftForTD, default_frame;
    1589             :         Word32 *pPcm_tmp[MAX_SPAR_INTERNAL_CHANNELS];
    1590             :         Word32 *p_tc[MAX_SPAR_INTERNAL_CHANNELS];
    1591             :         Word32 Pcm_tmp[MAX_SPAR_INTERNAL_CHANNELS][L_FRAME48k];
    1592       98723 :         Word16 q_format = Q11;
    1593       98723 :         move16();
    1594             : 
    1595       98723 :         ch_sba_idx = 0;
    1596       98723 :         move16();
    1597       98723 :         IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    1598             :         {
    1599       17790 :             if ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    1600             :             {
    1601       10890 :                 ch_sba_idx = st_ivas->nchan_ism; /*Q0*/
    1602       10890 :                 move16();
    1603             :             }
    1604             :         }
    1605             : 
    1606             :         /* TD decorrelator */
    1607             :         Word32 quo, rem;
    1608       98723 :         iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &quo, &rem, 0 );
    1609       98723 :         default_frame = extract_l( quo );         /*Q0*/
    1610       98723 :         nSamplesLeftForTD = nSamplesForRendering; /*Q0*/
    1611       98723 :         move16();
    1612       98723 :         nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/
    1613             : 
    1614      584451 :         FOR( ch = 0; ch < nchan_internal; ch++ )
    1615             :         {
    1616      485728 :             pPcm_tmp[ch] = Pcm_tmp[ch];                                /*Q11*/
    1617      485728 :             p_tc[ch] = st_ivas->hTcBuffer->tc_fx[( ch + ch_sba_idx )]; /*Q11*/
    1618             :         }
    1619             : 
    1620      197448 :         WHILE( nSamplesLeftForTD )
    1621             :         {
    1622       98725 :             Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); /*Q0*/
    1623             : 
    1624       98725 :             IF( hSpar->hTdDecorr )
    1625             :             {
    1626             : 
    1627       89655 :                 ivas_td_decorr_process_fx( hSpar->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr );
    1628       89655 :                 st_ivas->hTcBuffer->q_tc_fx = s_min( st_ivas->hTcBuffer->q_tc_fx, q_format );
    1629       89655 :                 move16();
    1630       89655 :                 IF( GE_16( hSpar->hTdDecorr->num_apd_outputs, sub( nchan_internal, nchan_transport ) ) )
    1631             :                 {
    1632      243422 :                     FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ )
    1633             :                     {
    1634      161237 :                         Copy32( pPcm_tmp[( ( hSpar->hTdDecorr->num_apd_outputs - 1 ) - ch )], p_tc[( ( nchan_internal - 1 ) - ch )], nSamplesToDecorr ); /*Q11*/
    1635             :                     }
    1636             :                 }
    1637             :                 ELSE
    1638             :                 {
    1639       59760 :                     FOR( ch = 0; ch < sub( nchan_internal, nchan_transport ); ch++ )
    1640             :                     {
    1641       52290 :                         set32_fx( p_tc[( ( nchan_internal - 1 ) - ch )], 0, nSamplesToDecorr );
    1642             :                     }
    1643       22410 :                     FOR( ch = 0; ch < hSpar->hTdDecorr->num_apd_outputs; ch++ )
    1644             :                     {
    1645       14940 :                         Copy32( pPcm_tmp[( ( hSpar->hTdDecorr->num_apd_outputs - 1 ) - ch )], p_tc[( ( nchan_internal - 1 ) - ch )], nSamplesToDecorr ); /*Q11*/
    1646             :                     }
    1647             :                 }
    1648             :             }
    1649      584461 :             FOR( ch = 0; ch < nchan_internal; ch++ )
    1650             :             {
    1651      485736 :                 p_tc[ch] = p_tc[ch] + nSamplesToDecorr; /*Q11*/
    1652             :             }
    1653             : 
    1654       98725 :             nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); /*Q0*/
    1655             :         }
    1656             :     }
    1657             : 
    1658      135777 :     ivas_spar_dec_set_render_params_fx( st_ivas, nCldfbSlots );
    1659             : 
    1660      135777 :     return;
    1661             : }
    1662             : 
    1663             : 
    1664             : /*-------------------------------------------------------------------*
    1665             :  * ivas_spar_dec_upmixer_sf()
    1666             :  *
    1667             :  * IVAS SPAR upmixer
    1668             :  *-------------------------------------------------------------------*/
    1669             : 
    1670      396212 : void ivas_spar_dec_upmixer_sf_fx(
    1671             :     Decoder_Struct *st_ivas,    /* i/o: IVAS decoder handle                     */
    1672             :     Word32 *output_fx[],        /* o  : output audio channels                   Q11*/
    1673             :     const Word16 nchan_internal /* i  : number of internal channels             Q0*/
    1674             : )
    1675             : {
    1676             :     Word16 cldfb_band, num_cldfb_bands, numch_in, numch_out;
    1677             :     Word32 *cldfb_in_ts_re_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX];
    1678             :     Word32 *cldfb_in_ts_im_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX];
    1679             :     Word16 i, b, ts, out_ch, in_ch;
    1680             :     Word16 num_spar_bands, spar_band, nchan_transport;
    1681             :     Word16 num_in_ingest, split_band;
    1682             :     Word16 slot_size, slot_idx_start;
    1683             :     Word16 md_idx;
    1684             :     Word32 *p_tc_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS];
    1685             :     Word32 Pcm_tmp_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k];
    1686             :     Word16 numch_out_dirac;
    1687             :     Word32 mixer_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
    1688             :     Word16 b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
    1689             :     DECODER_CONFIG_HANDLE hDecoderConfig;
    1690             :     SPAR_DEC_HANDLE hSpar;
    1691             :     Word16 num_md_sub_frames;
    1692      396212 :     Word16 q1 = 30;
    1693             :     Word16 prod;
    1694      396212 :     move16();
    1695      396212 :     push_wmops( "ivas_spar_dec_upmixer_sf_fx" );
    1696      396212 :     hSpar = st_ivas->hSpar;
    1697      396212 :     hDecoderConfig = st_ivas->hDecoderConfig;
    1698      396212 :     nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; /*Q0*/
    1699      396212 :     move16();
    1700             : 
    1701      396212 :     num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; /*Q0*/
    1702      396212 :     move16();
    1703      396212 :     numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; /*Q0*/
    1704      396212 :     move16();
    1705      396212 :     numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; /*Q0*/
    1706      396212 :     move16();
    1707      396212 :     num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); /*Q0*/
    1708      396212 :     slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );                                                                            /*Q0*/
    1709      396212 :     move16();
    1710      396212 :     slot_idx_start = hSpar->slots_rendered; /*Q0*/
    1711      396212 :     move16();
    1712             : 
    1713      396212 :     prod = i_mult( slot_idx_start, slot_size );
    1714             : 
    1715      396212 :     test();
    1716      396212 :     IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    1717       43560 :     {
    1718             :         Word16 nchan_ism;
    1719             : 
    1720       43560 :         nchan_ism = st_ivas->nchan_ism;
    1721       43560 :         move16();
    1722             : 
    1723      378280 :         FOR( i = 0; i < nchan_internal; i++ )
    1724             :         {
    1725      334720 :             p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[( i + nchan_ism )] + prod; /*Q11*/
    1726             :         }
    1727             : 
    1728       43560 :         test();
    1729       43560 :         test();
    1730       43560 :         IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    1731             :         {
    1732       40000 :             FOR( i = 0; i < nchan_ism; i++ )
    1733             :             {
    1734       32000 :                 p_tc_fx[( i + nchan_internal )] = st_ivas->hTcBuffer->tc_fx[i] + prod; /*Q11*/
    1735             :             }
    1736             :         }
    1737             :     }
    1738             :     ELSE
    1739             :     {
    1740     1966142 :         FOR( i = 0; i < nchan_internal; i++ )
    1741             :         {
    1742     1613490 :             p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i] + prod; /*Q11*/
    1743             :         }
    1744             :     }
    1745             : 
    1746             : 
    1747             :     /*---------------------------------------------------------------------*
    1748             :      * TD Decorr and pcm ingest
    1749             :      *---------------------------------------------------------------------*/
    1750             : 
    1751      396212 :     IF( hSpar->hMdDec->td_decorr_flag )
    1752             :     {
    1753      396212 :         num_in_ingest = nchan_internal; /*Q0*/
    1754      396212 :         move16();
    1755             :     }
    1756             :     ELSE
    1757             :     {
    1758           0 :         num_in_ingest = nchan_transport; /*Q0*/
    1759           0 :         move16();
    1760             :     }
    1761             : 
    1762             :     /*---------------------------------------------------------------------*
    1763             :      * PCA decoder
    1764             :      *---------------------------------------------------------------------*/
    1765             : 
    1766      396212 :     hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; /*Q0*/
    1767      396212 :     move16();
    1768             : 
    1769             : 
    1770             :     /*---------------------------------------------------------------------*
    1771             :      * Prepare CLDFB buffers
    1772             :      *---------------------------------------------------------------------*/
    1773             : 
    1774      396212 :     set_zero_fx( &Pcm_tmp_fx[0][0], ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ) * L_FRAME48k );
    1775             :     /* set-up pointers */
    1776      396212 :     IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) )
    1777             :     {
    1778             :         /* at this point, output channels are used as intermediate procesing buffers */
    1779     4791612 :         FOR( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; in_ch++ )
    1780             :         {
    1781    22817200 :             FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ )
    1782             :             {
    1783    18253760 :                 cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ts * num_cldfb_bands )];                               /*Q11*/
    1784    18253760 :                 cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ( ts * num_cldfb_bands ) + ( 4 * num_cldfb_bands ) )]; /*Q11*/
    1785             :             }
    1786             :         }
    1787             :     }
    1788             :     ELSE
    1789             :     {
    1790      846200 :         FOR( in_ch = 0; in_ch < numch_in; in_ch++ )
    1791             :         {
    1792     3390800 :             FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ )
    1793             :             {
    1794     2712640 :                 cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ts * num_cldfb_bands )];                               /*Q11*/
    1795     2712640 :                 cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][( ( ts * num_cldfb_bands ) + ( 4 * num_cldfb_bands ) )]; /*Q11*/
    1796             :             }
    1797             :         }
    1798             :     }
    1799             : 
    1800             :     /*---------------------------------------------------------------------*
    1801             :      * CLDFB Processing and Synthesis
    1802             :      *---------------------------------------------------------------------*/
    1803             : 
    1804      396212 :     num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; /*Q0*/
    1805      396212 :     move16();
    1806             : 
    1807             :     /* apply parameters */
    1808             :     /* determine if we can skip certain data */
    1809      396212 :     ivas_spar_get_skip_mat_fx( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat, num_md_sub_frames ); /* this can be precomputed based on bitrate and format*/
    1810             : 
    1811      396212 :     numch_out_dirac = hDecoderConfig->nchan_out;
    1812      396212 :     move16();
    1813             : 
    1814             : 
    1815             :     /* CLDFB analysis of incoming frame */
    1816     2344422 :     FOR( in_ch = 0; in_ch < numch_in; in_ch++ )
    1817             :     {
    1818     9720074 :         FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    1819             :         {
    1820     7771864 :             Word16 q_cldfb = 11;
    1821     7771864 :             move16();
    1822     7771864 :             cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][( ts * num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb );
    1823             :         }
    1824             :     }
    1825             : 
    1826      396212 :     test();
    1827      396212 :     test();
    1828      396212 :     IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    1829             :     {
    1830       40000 :         FOR( ; in_ch < ( st_ivas->nchan_ism + numch_in ); in_ch++ )
    1831             :         {
    1832      160000 :             FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    1833             :             {
    1834      128000 :                 Word16 q_cldfb = 11;
    1835      128000 :                 move16();
    1836      128000 :                 cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][( ts * num_cldfb_bands )], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb );
    1837             :             }
    1838             :         }
    1839             :     }
    1840             : 
    1841      396212 :     test();
    1842      396212 :     test();
    1843      396212 :     IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) )
    1844             :     {
    1845        5132 :         Word16 q_cldfb = 6;
    1846        5132 :         move16();
    1847        5132 :         ivas_spar_calc_smooth_facs_fx( cldfb_in_ts_re_fx[0], cldfb_in_ts_im_fx[0], q_cldfb, num_spar_bands, hSpar->subframe_nbslots[hSpar->subframes_rendered],
    1848        5132 :                                        hSpar->subframes_rendered == 0, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_buf_fx );
    1849             :     }
    1850      396212 :     Word16 sh_l = sub( 31, q1 );
    1851     1975816 :     FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    1852             :     {
    1853     1579604 :         md_idx = hSpar->render_to_md_map[( ts + slot_idx_start )]; /*Q0*/
    1854     1579604 :         move16();
    1855     1579604 :         Scale_sig( hSpar->hFbMixer->cldfb_cross_fade_fx, CLDFB_NO_COL_MAX, Q15 - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ); /*Q15*/
    1856     1579604 :         st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q15;
    1857     1579604 :         move16();
    1858     1579604 :         ivas_spar_get_parameters_fx( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat_fx );
    1859             : 
    1860     1579604 :         test();
    1861     1579604 :         test();
    1862     1579604 :         IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) )
    1863             :         {
    1864      266864 :             FOR( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
    1865             :             {
    1866      246336 :                 Word16 diff = sub( 32767, hSpar->hMdDec->smooth_fac_fx[spar_band] );
    1867     1231680 :                 FOR( out_ch = 0; out_ch < numch_out; out_ch++ )
    1868             :                 {
    1869     4926720 :                     FOR( in_ch = 0; in_ch < numch_in; in_ch++ )
    1870             :                     {
    1871     3941376 :                         mixer_mat_fx[out_ch][in_ch][spar_band] = Madd_32_16( Mpy_32_16_1( mixer_mat_fx[out_ch][in_ch][spar_band], diff ), hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band], hSpar->hMdDec->smooth_fac_fx[spar_band] ); /*q1*/
    1872     3941376 :                         move32();
    1873     3941376 :                         hSpar->hMdDec->mixer_mat_prev2_fx[out_ch][in_ch][spar_band] = mixer_mat_fx[out_ch][in_ch][spar_band]; /*q1*/
    1874     3941376 :                         move32();
    1875             :                     }
    1876             :                 }
    1877             :             }
    1878             :         }
    1879             :         /* Note: This version splits the cldfb band loop into 2 loops, removing some inner-loop IF_statements */
    1880     1579604 :         Word16 min_cldf_band = s_min( CLDFB_PAR_WEIGHT_START_BAND, num_cldfb_bands );
    1881             :         Word32 out_re_fx[IVAS_SPAR_MAX_CH];
    1882             :         Word32 out_im_fx[IVAS_SPAR_MAX_CH];
    1883             :         Word32 cldfb_par_fx; /*q1*/
    1884     1579604 :         ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band;
    1885             : 
    1886             :         /* First loop from cldfb_band=0 till min_cldf_band (CLDFB_PAR_WEIGHT_START_BAND) */
    1887    12636832 :         FOR( cldfb_band = 0; cldfb_band < min_cldf_band; cldfb_band++ )
    1888             :         {
    1889    11057228 :             spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; /*Q0*/
    1890    11057228 :             move16();
    1891    65460276 :             FOR( out_ch = 0; out_ch < numch_out; out_ch++ )
    1892             :             {
    1893    54403048 :                 out_re_fx[out_ch] = 0;
    1894    54403048 :                 move32();
    1895    54403048 :                 out_im_fx[out_ch] = 0;
    1896    54403048 :                 move32();
    1897   370827800 :                 FOR( in_ch = 0; in_ch < numch_in; in_ch++ )
    1898             :                 {
    1899   316424752 :                     IF( b_skip_mat[out_ch][in_ch] == 0 )
    1900             :                     {
    1901   128006816 :                         cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; /*q1*/
    1902   128006816 :                         move32();
    1903   128006816 :                         out_re_fx[out_ch] = Madd_32_32( out_re_fx[out_ch], cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/
    1904   128006816 :                         move32();
    1905   128006816 :                         out_im_fx[out_ch] = Madd_32_32( out_im_fx[out_ch], cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/
    1906   128006816 :                         move32();
    1907             :                     }
    1908             :                 }
    1909             :             }
    1910             :             /*update CLDFB data with the parameter-modified data*/
    1911    65460276 :             FOR( out_ch = 0; out_ch < numch_out; out_ch++ )
    1912             :             {
    1913    54403048 :                 cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/
    1914    54403048 :                 move32();
    1915    54403048 :                 cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/
    1916    54403048 :                 move32();
    1917             :             }
    1918             :         }
    1919             : 
    1920             : 
    1921             :         /* Second loop from min_cldf_band (CLDFB_PAR_WEIGHT_START_BAND) till num_cldfb_bands */
    1922    68425336 :         FOR( ; cldfb_band < num_cldfb_bands; cldfb_band++ )
    1923             :         {
    1924   409443804 :             FOR( out_ch = 0; out_ch < numch_out; out_ch++ )
    1925             :             {
    1926   342598072 :                 Word32 Out_re_fx = L_add( 0, 0 );
    1927   342598072 :                 Word32 Out_im_fx = L_add( 0, 0 );
    1928  2446198600 :                 FOR( in_ch = 0; in_ch < numch_in; in_ch++ )
    1929             :                 {
    1930  2103600528 :                     IF( b_skip_mat[out_ch][in_ch] == 0 )
    1931             :                     {
    1932   831867904 :                         Word64 acc = 0;
    1933   831867904 :                         move64();
    1934             : 
    1935   831867904 :                         cldfb_par_fx = 0;
    1936   831867904 :                         move32();
    1937  4289370248 :                         FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ )
    1938             :                         {
    1939             :                             /* accumulate contributions from all SPAR bands */
    1940  3457502344 :                             acc = W_mac_32_32( acc, mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ); // q1+ Q23
    1941             :                         }
    1942   831867904 :                         cldfb_par_fx = W_shl_sat_l( acc, -23 );                                                      // q1
    1943   831867904 :                         Out_re_fx = Madd_32_32( Out_re_fx, cldfb_in_ts_re_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/
    1944   831867904 :                         Out_im_fx = Madd_32_32( Out_im_fx, cldfb_in_ts_im_fx[in_ch][ts][cldfb_band], cldfb_par_fx ); /*q1-25*/
    1945             :                     }
    1946             :                 }
    1947   342598072 :                 out_re_fx[out_ch] = Out_re_fx;
    1948   342598072 :                 out_im_fx[out_ch] = Out_im_fx;
    1949             :             }
    1950             : 
    1951             :             /*update CLDFB data with the parameter-modified data*/
    1952   409443804 :             FOR( out_ch = 0; out_ch < numch_out; out_ch++ )
    1953             :             {
    1954   342598072 :                 cldfb_in_ts_re_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], sh_l ); /*Q=6*/
    1955   342598072 :                 move32();
    1956   342598072 :                 cldfb_in_ts_im_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], sh_l ); /*Q=6*/
    1957   342598072 :                 move32();
    1958             :             }
    1959             :         }
    1960     1579604 :         test();
    1961     1579604 :         IF( ( EQ_16( ( add( add( slot_idx_start, ts ), 1 ) ), hSpar->num_slots ) ) || ( NE_16( ( shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */ ), ( hSpar->render_to_md_map[( ( slot_idx_start + ts ) + 1 )] / JBM_CLDFB_SLOTS_IN_SUBFRAME /*It's value is 4*/ ) ) ) )
    1962             :         {
    1963             :             /* we have crossed an unadapted parameter sf border, update previous mixing matrices */
    1964      394906 :             Word16 md_sf = shr( md_idx, 2 ) /* md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME */; /*Q0*/
    1965      394906 :             split_band = SPAR_DIRAC_SPLIT_START_BAND;
    1966      394906 :             move16();
    1967      394906 :             if ( NE_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) )
    1968             :             {
    1969       60440 :                 md_sf = 0;
    1970       60440 :                 move16();
    1971             :             }
    1972      394906 :             IF( LT_16( split_band, IVAS_MAX_NUM_BANDS ) )
    1973             :             {
    1974             : 
    1975     2337910 :                 FOR( out_ch = 0; out_ch < numch_out; out_ch++ )
    1976             :                 {
    1977    13244148 :                     FOR( in_ch = 0; in_ch < numch_in; in_ch++ )
    1978             :                     {
    1979   145634872 :                         FOR( b = 0; b < num_spar_bands; b++ )
    1980             :                         {
    1981   134333728 :                             hSpar->hMdDec->mixer_mat_prev_fx[0][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_prev_fx[1][out_ch][in_ch][b];
    1982   134333728 :                             hSpar->hMdDec->mixer_mat_prev_fx[1][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_prev_fx[2][out_ch][in_ch][b];
    1983   134333728 :                             hSpar->hMdDec->mixer_mat_prev_fx[2][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_prev_fx[3][out_ch][in_ch][b];
    1984   134333728 :                             hSpar->hMdDec->mixer_mat_prev_fx[3][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b];
    1985   134333728 :                             move32();
    1986   134333728 :                             move32();
    1987   134333728 :                             move32();
    1988   134333728 :                             move32();
    1989             : 
    1990   134333728 :                             hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][( b + ( md_sf * IVAS_MAX_NUM_BANDS ) )]; /*hSpar->hMdDec->Q_mixer_mat*/
    1991   134333728 :                             move32();
    1992             :                         }
    1993             :                     }
    1994             :                 }
    1995      394906 :                 hSpar->i_subframe = add( hSpar->i_subframe, 1 ); /*Q0*/
    1996      394906 :                 move16();
    1997      394906 :                 hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); /*Q0*/
    1998      394906 :                 move16();
    1999             :             }
    2000             :         }
    2001             :     }
    2002             : 
    2003      396212 :     test();
    2004      396212 :     test();
    2005      396212 :     IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
    2006             :     {
    2007      228172 :         ivas_dirac_dec_render_sf_fx( st_ivas, output_fx, nchan_internal, cldfb_in_ts_re_fx, cldfb_in_ts_im_fx );
    2008             :     }
    2009             :     /*------------------------------------------------------------------ends*/
    2010      396212 :     IF( st_ivas->hDirAC != NULL )
    2011             :     {
    2012             :         Word16 outchannels, idx_in, idx_lfe, ch;
    2013      228172 :         idx_in = 0;
    2014      228172 :         move16();
    2015      228172 :         idx_lfe = 0;
    2016      228172 :         move16();
    2017             : 
    2018      228172 :         outchannels = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); /*Q0*/
    2019             : 
    2020     1900774 :         FOR( ch = 0; ch < outchannels; ch++ )
    2021             :         {
    2022     1672602 :             test();
    2023     1672602 :             IF( ( st_ivas->hOutSetup.num_lfe > 0 ) && ( EQ_16( st_ivas->hOutSetup.index_lfe[idx_lfe], ch ) ) )
    2024             :             {
    2025       41000 :                 set_zero_fx( output_fx[ch], i_mult( hSpar->subframe_nbslots[hSpar->subframes_rendered], num_cldfb_bands ) );
    2026       41000 :                 if ( LT_16( idx_lfe, ( sub( st_ivas->hDirACRend->hOutSetup.num_lfe, 1 ) ) ) )
    2027             :                 {
    2028           0 :                     idx_lfe = add( idx_lfe, 1 );
    2029             :                 }
    2030             :             }
    2031             :             ELSE
    2032             :             {
    2033     1631602 :                 test();
    2034     1631602 :                 test();
    2035     1631602 :                 test();
    2036     1631602 :                 test();
    2037     1631602 :                 test();
    2038     1631602 :                 test();
    2039     1631602 :                 IF( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) || !( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) &&
    2040             :                     !( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
    2041             :                 {
    2042     6676176 :                     FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    2043             :                     {
    2044             : #ifdef OPT_AVOID_STATE_BUF_RESCALE
    2045     5329024 :                         cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[idx_in][ts], &cldfb_in_ts_im_fx[idx_in][ts], &output_fx[ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, 6, 0, st_ivas->cldfbSynDec[idx_in] );
    2046             : #else  /* OPT_AVOID_STATE_BUF_RESCALE */
    2047             :                         cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[idx_in][ts], &cldfb_in_ts_im_fx[idx_in][ts], &output_fx[ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, 6, st_ivas->cldfbSynDec[idx_in] );
    2048             : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
    2049             :                     }
    2050             :                 }
    2051             : 
    2052     1631602 :                 idx_in = add( idx_in, 1 );
    2053             :             }
    2054             :         }
    2055             :     }
    2056             :     ELSE
    2057             :     {
    2058             :         /* CLDFB to time synthesis (overwrite mixer output) */
    2059      840200 :         FOR( out_ch = 0; out_ch < numch_out_dirac; out_ch++ )
    2060             :         {
    2061     3360800 :             FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    2062             :             {
    2063             : #ifdef OPT_AVOID_STATE_BUF_RESCALE
    2064     2688640 :                 cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[out_ch][ts], &cldfb_in_ts_im_fx[out_ch][ts], &output_fx[out_ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, 6, 0, st_ivas->cldfbSynDec[out_ch] );
    2065             : #else  /* OPT_AVOID_STATE_BUF_RESCALE */
    2066             :                 cldfbSynthesis_ivas_fx( &cldfb_in_ts_re_fx[out_ch][ts], &cldfb_in_ts_im_fx[out_ch][ts], &output_fx[out_ch][i_mult( ts, num_cldfb_bands )], num_cldfb_bands, 6, st_ivas->cldfbSynDec[out_ch] );
    2067             : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
    2068             :             }
    2069             :         }
    2070             :     }
    2071             : 
    2072      396212 :     hSpar->slots_rendered = add( hSpar->slots_rendered, hSpar->subframe_nbslots[hSpar->subframes_rendered] ); /*Q0*/
    2073      396212 :     move16();
    2074      396212 :     hSpar->subframes_rendered = add( hSpar->subframes_rendered, 1 ); /*Q0*/
    2075      396212 :     move16();
    2076             : 
    2077      396212 :     pop_wmops();
    2078             : 
    2079      396212 :     return;
    2080             : }

Generated by: LCOV version 1.14