LCOV - code coverage report
Current view: top level - lib_dec - ivas_jbm_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ da9cc8ead0679b4682d329fdff98cf1616159273 Lines: 1910 2102 90.9 %
Date: 2025-10-13 22:24:20 Functions: 25 25 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 "options.h"
      35             : #include "cnst.h"
      36             : #include "ivas_cnst.h"
      37             : #include "rom_com.h"
      38             : #include "prot_fx.h"
      39             : #include "ivas_prot_fx.h"
      40             : #include "ivas_prot_rend_fx.h"
      41             : #include "ivas_rom_com.h"
      42             : #include <math.h>
      43             : #include "wmc_auto.h"
      44             : #include "ivas_prot_fx.h"
      45             : #ifdef DEBUGGING
      46             : #include "debug.h"
      47             : #endif
      48             : 
      49             : 
      50             : /*-----------------------------------------------------------------------*
      51             :  * Local function prototypes
      52             :  *-----------------------------------------------------------------------*/
      53             : 
      54             : static void ivas_jbm_dec_copy_tc( Decoder_Struct *st_ivas, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *data, Word32 *tc_digest_f[], Word16 data_q );
      55             : 
      56             : static void ivas_jbm_dec_tc_buffer_playout_fx( Decoder_Struct *st_ivas, const UWord16 nSamplesAsked, UWord16 *nSamplesRendered, Word32 *output_fx[] );
      57             : 
      58             : static void ivas_jbm_dec_copy_masa_meta_to_buffer( Decoder_Struct *st_ivas );
      59             : 
      60             : static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const Word16 nCldfbTs );
      61             : 
      62             : 
      63             : static Word16 ceil_fx16( Word16 inp, Word16 Q );
      64      238231 : static Word16 ceil_fx16( Word16 inp, Word16 Q )
      65             : {
      66      238231 :     Word16 ret = shr( inp, Q );
      67      238231 :     IF( ( s_and( inp, sub( shl( 1, Q ), 1 ) ) ) > 0 )
      68             :     {
      69        3213 :         ret = add( ret, 1 );
      70             :     }
      71      238231 :     return ret;
      72             : }
      73             : 
      74             : /*--------------------------------------------------------------------------*
      75             :  * ivas_jbm_dec_tc()
      76             :  *
      77             :  * Principal IVAS JBM decoder routine, decoding of metadata and transport channels
      78             :  *--------------------------------------------------------------------------*/
      79             : 
      80      410125 : ivas_error ivas_jbm_dec_tc_fx(
      81             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure         */
      82             :     Word32 *data_fx          /*Q11*/
      83             : )
      84             : {
      85             :     Word16 ch, n, output_frame, nchan_out, i, ii;
      86             :     Decoder_State *st;                           /* used for bitstream handling */
      87             :     Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* buffer for output synthesis */
      88             :     Word16 nchan_remapped;
      89             :     Word16 nb_bits_metadata[MAX_SCE + 1];
      90             :     Word32 output_Fs, ivas_total_brate;
      91             :     AUDIO_CONFIG output_config;
      92             :     ivas_error error;
      93             :     Word16 num_md_sub_frames;
      94             :     Word32 ism_total_brate;
      95             :     Word16 s;
      96             : 
      97             :     CPE_DEC_HANDLE hCPE;
      98             :     SCE_DEC_HANDLE hSCE;
      99      410125 :     push_wmops( "ivas_jbm_dec_tc" );
     100             : 
     101             :     /*----------------------------------------------------------------*
     102             :      * Initialization of local vars after struct has been set
     103             :      *----------------------------------------------------------------*/
     104             : 
     105      410125 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     106      410125 :     move32();
     107      410125 :     nchan_out = st_ivas->hTcBuffer->nchan_transport_jbm;
     108      410125 :     move16();
     109      410125 :     output_config = st_ivas->hDecoderConfig->output_config;
     110      410125 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     111      410125 :     move32();
     112             : 
     113      410125 :     output_frame = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) /* output_Fs / FRAMES_PER_SEC */;
     114             : 
     115     5331625 :     FOR( n = 0; n < MAX_TRANSPORT_CHANNELS; n++ )
     116             :     {
     117     4921500 :         p_output_fx[n] = st_ivas->p_output_fx[n];
     118             : 
     119     4921500 :         IF( p_output_fx[n] != NULL )
     120             :         {
     121     2326345 :             set32_fx( p_output_fx[n], 0, L_FRAME48k );
     122             :         }
     123             :     }
     124             : 
     125             :     /*----------------------------------------------------------------*
     126             :      * Decoding + pre-rendering
     127             :      *----------------------------------------------------------------*/
     128             : 
     129      410125 :     test();
     130      410125 :     test();
     131      410125 :     IF( st_ivas->bfi != 0 && st_ivas->ini_frame == 0 )
     132             :     {
     133             :         /* zero output when first frame(s) is lost */
     134           0 :         FOR( n = 0; n < nchan_out; n++ )
     135             :         {
     136           0 :             set32_fx( p_output_fx[n], 0, output_frame );
     137             :         }
     138             :     }
     139      410125 :     ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
     140             :     {
     141       72481 :         st_ivas->hCPE[0]->element_brate = ivas_total_brate;
     142       72481 :         move32();
     143       72481 :         Word16 q_output = 11;
     144       72481 :         move16();
     145       72481 :         set32_fx( &p_output_fx[0][0], 0, L_FRAME48k );
     146       72481 :         set32_fx( &p_output_fx[1][0], 0, L_FRAME48k );
     147             : 
     148       72481 :         IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, 0 ) ) != IVAS_ERR_OK )
     149             :         {
     150           0 :             return error;
     151             :         }
     152             : 
     153       72481 :         IF( NE_16( q_output, Q11 ) )
     154             :         {
     155           0 :             Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11
     156           0 :             Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11
     157             :         }
     158             : 
     159             :         /* HP filtering */
     160      193543 :         FOR( n = 0; n < s_min( nchan_out, st_ivas->nchan_transport ); n++ )
     161             :         {
     162             : #ifdef HP20_FIX32_RECODING
     163      121062 :             hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
     164             : #else
     165             :             hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
     166             : #endif
     167             :         }
     168             :     }
     169      337644 :     ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
     170             :     {
     171             :         /* Metadata decoding and configuration */
     172       94838 :         test();
     173       94838 :         IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) )
     174        2113 :         {
     175        2113 :             ivas_ism_dtx_dec_fx( st_ivas, nb_bits_metadata );
     176             : 
     177        2113 :             set32_fx( p_output_fx[st_ivas->hISMDTX.sce_id_dtx], 0, L_FRAME48k );
     178             : 
     179        2113 :             IF( ( error = ivas_sce_dec_fx( st_ivas, st_ivas->hISMDTX.sce_id_dtx, &p_output_fx[st_ivas->hISMDTX.sce_id_dtx], output_frame, nb_bits_metadata[st_ivas->hISMDTX.sce_id_dtx] ) ) != IVAS_ERR_OK )
     180             :             {
     181           0 :                 return error;
     182             :             }
     183             :             Word16 Q_cngNoiseLevel[MAX_SCE];
     184       10565 :             FOR( ch = 0; ch < 4; ch++ )
     185             :             {
     186        8452 :                 IF( st_ivas->hSCE[ch] != NULL )
     187             :                 {
     188        5234 :                     Word16 shift = getScaleFactor32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
     189        5234 :                     if ( LT_16( sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
     190             :                     {
     191        1939 :                         shift = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
     192             :                     }
     193        5234 :                     scale_sig32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-(cngNoiseLevelExp -shift) )
     194        5234 :                     st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
     195        5234 :                     Q_cngNoiseLevel[ch] = sub( 31, st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp );
     196        5234 :                     move16();
     197        5234 :                     move16();
     198             :                 }
     199             :             }
     200        2113 :             ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( st_ivas->hSCE, st_ivas->hISMDTX.sce_id_dtx, st_ivas->nchan_transport, Q_cngNoiseLevel );
     201             : #ifdef OBJ_EDITING_API
     202        2113 :             ivas_param_ism_dec_dequant_md_fx( st_ivas );
     203             : #endif
     204             :         }
     205       92725 :         ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
     206             :         {
     207       15920 :             IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ), IVAS_ERR_OK ) )
     208             :             {
     209           0 :                 return error;
     210             :             }
     211             : #ifdef OBJ_EDITING_API
     212       15920 :             ivas_param_ism_dec_dequant_md_fx( st_ivas );
     213             : #endif
     214             :         }
     215             :         ELSE /* ISM_MODE_DISC */
     216             :         {
     217       76805 :             IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ), IVAS_ERR_OK ) )
     218             :             {
     219           0 :                 return error;
     220             :             }
     221             :         }
     222             : 
     223      338341 :         FOR( n = 0; n < st_ivas->nchan_transport; n++ )
     224             :         {
     225             :             /* for DTX frames, dominant object has already been decoded before */
     226      243503 :             test();
     227      243503 :             test();
     228      243503 :             IF( !( ( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) && EQ_16( n, st_ivas->hISMDTX.sce_id_dtx ) ) )
     229             :             {
     230      241390 :                 set32_fx( p_output_fx[n], 0, L_FRAME48k );
     231             : 
     232      241390 :                 IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, n, &p_output_fx[n], output_frame, nb_bits_metadata[n] ) ), IVAS_ERR_OK ) )
     233             :                 {
     234           0 :                     return error;
     235             :                 }
     236             :             }
     237             : 
     238             :             /* HP filtering */
     239             : #ifdef HP20_FIX32_RECODING
     240      243503 :             hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
     241             : #else
     242             :             hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
     243             : #endif
     244             :         }
     245             : 
     246       94838 :         test();
     247       94838 :         test();
     248       94838 :         test();
     249       94838 :         IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
     250             :         {
     251        3970 :             ivas_ism_mono_dmx_fx( st_ivas, p_output_fx, output_frame );
     252             : 
     253        3970 :             Scale_sig32( p_output_fx[0], L_FRAME48k, 3 );
     254             :         }
     255       90868 :         ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( 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 ) ) )
     256             :         {
     257             :             /* loudness correction */
     258        7955 :             ivas_dirac_dec_binaural_sba_gain_fx( p_output_fx, st_ivas->nchan_transport, output_frame ); /*returns Q-1*/
     259             : 
     260       23865 :             FOR( i = 0; i < st_ivas->nchan_transport; i++ )
     261             :             {
     262       15910 :                 Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q
     263             :             }
     264             :         }
     265             :     }
     266      242806 :     ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
     267      153562 :     {
     268      153562 :         set16_fx( nb_bits_metadata, 0, MAX_SCE );
     269             : 
     270             : 
     271             :         /* read parameters from the bitstream */
     272      153562 :         test();
     273      153562 :         IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->hQMetaData != NULL )
     274             :         {
     275             :             // st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
     276             : 
     277       32544 :             IF( st_ivas->nSCE > 0 )
     278             :             {
     279       14097 :                 st = st_ivas->hSCE[0]->hCoreCoder[0];
     280             :             }
     281             :             ELSE
     282             :             {
     283       18447 :                 st = st_ivas->hCPE[0]->hCoreCoder[0];
     284             :             }
     285             : 
     286       32544 :             IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
     287             :             {
     288           0 :                 return error;
     289             :             }
     290             : 
     291       32544 :             test();
     292       32544 :             IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && st_ivas->hDecoderConfig->Opt_tsm )
     293             :             {
     294        1152 :                 ivas_jbm_dec_copy_masa_meta_to_buffer( st_ivas );
     295             :             }
     296             :         }
     297      121018 :         ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
     298             :         {
     299      121018 :             IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) )
     300             :             {
     301           0 :                 return error;
     302             :             }
     303             :         }
     304             : 
     305      153562 :         test();
     306      153562 :         IF( EQ_16( st_ivas->nchan_transport, CPE_CHANNELS ) && GE_16( st_ivas->nCPE, 1 ) )
     307             :         {
     308       52934 :             st_ivas->hCPE[0]->brate_surplus = 0;
     309       52934 :             move32();
     310       52934 :             st_ivas->hCPE[0]->element_brate = ivas_total_brate;
     311       52934 :             move32();
     312             :         }
     313             : 
     314             :         /* core-decoding of transport channels */
     315      153562 :         Word16 q_output = Q11;
     316      153562 :         move16();
     317      153562 :         IF( EQ_16( st_ivas->nSCE, 1 ) )
     318             :         {
     319       49390 :             set32_fx( p_output_fx[0], 0, L_FRAME48k );
     320             : 
     321       49390 :             IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
     322             :             {
     323           0 :                 return error;
     324             :             }
     325             :         }
     326      104172 :         ELSE IF( EQ_16( st_ivas->nCPE, 1 ) )
     327             :         {
     328       52934 :             set32_fx( &p_output_fx[0][0], 0, L_FRAME48k );
     329       52934 :             set32_fx( &p_output_fx[1][0], 0, L_FRAME48k );
     330             : 
     331       52934 :             IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
     332             :             {
     333           0 :                 return error;
     334             :             }
     335             : 
     336       52934 :             IF( NE_16( q_output, Q11 ) )
     337             :             {
     338           0 :                 Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11
     339           0 :                 Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11
     340             :             }
     341             :         }
     342       51238 :         ELSE IF( GT_16( st_ivas->nCPE, 1 ) )
     343             :         {
     344       51238 :             IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
     345             :             {
     346           0 :                 return error;
     347             :             }
     348             :         }
     349             : 
     350             :         /* TCs remapping */
     351      153562 :         nchan_remapped = st_ivas->nchan_transport;
     352      153562 :         move16();
     353             : 
     354      153562 :         test();
     355      153562 :         test();
     356      153562 :         test();
     357      153562 :         test();
     358      153562 :         test();
     359      153562 :         IF( st_ivas->sba_dirac_stereo_flag )
     360             :         {
     361        6610 :             nchan_remapped = nchan_out;
     362        6610 :             move16();
     363             : 
     364        6610 :             IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) )
     365             :             {
     366       20540 :                 FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ )
     367             :                 {
     368       13930 :                     Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14
     369             :                 }
     370        6610 :                 SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
     371             :                 Word16 nchan_transport;
     372        6610 :                 nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
     373        6610 :                 move16();
     374        6610 :                 nchan_out = nchan_transport;
     375        6610 :                 move16();
     376        6610 :                 ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx ), ( p_output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );
     377             : 
     378        6610 :                 IF( st_ivas->hSpar->hPCA != NULL )
     379             :                 {
     380           0 :                     ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, p_output_fx );
     381             :                 }
     382             : 
     383        6610 :                 ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ) );
     384             :             }
     385             :             {
     386             :                 Word16 q;
     387        6610 :                 hCPE = st_ivas->hCPE[0];
     388        6610 :                 hSCE = st_ivas->hSCE[0];
     389             : 
     390        6610 :                 s = 0;
     391        6610 :                 move16();
     392       19830 :                 FOR( i = 0; i < 2; i++ )
     393             :                 {
     394       13220 :                     s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 ) /* Guard bits */; // L_frame should be used instead of L_FRAME48k */
     395             :                 }
     396       19830 :                 FOR( i = 0; i < 2; i++ )
     397             :                 {
     398       13220 :                     Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s)
     399             :                 }
     400        6610 :                 hCPE->hStereoDft->q_dft = add( Q11, s );
     401        6610 :                 move16();
     402        6610 :                 IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
     403             :                 {
     404          61 :                     hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft;
     405          61 :                     move16();
     406          61 :                     hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft;
     407          61 :                     move16();
     408             :                 }
     409        6610 :                 q = hCPE->hStereoDft->q_dft;
     410        6610 :                 move16();
     411        6610 :                 scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
     412       19830 :                 FOR( i = 0; i < CPE_CHANNELS; ++i )
     413             :                 {
     414       13220 :                     scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );                                          // q_dft
     415       13220 :                     scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
     416             :                 }
     417        6610 :                 IF( hCPE->hCoreCoder[0] != NULL )
     418             :                 {
     419        6610 :                     Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q
     420        6610 :                     Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda );          // q
     421        6610 :                     hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q;
     422        6610 :                     move16();
     423             :                 }
     424        6610 :                 IF( hCPE->hStereoDft != NULL )
     425             :                 {
     426        6610 :                     IF( LE_16( st_ivas->nchan_transport, 1 ) )
     427             :                     {
     428        2970 :                         st = hCPE->hCoreCoder[0];
     429        2970 :                         test();
     430        2970 :                         test();
     431        2970 :                         test();
     432        2970 :                         test();
     433        2970 :                         test();
     434        2970 :                         IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) )
     435             :                         {
     436        1456 :                             test();
     437        1456 :                             test();
     438        1456 :                             test();
     439        1456 :                             test();
     440        1456 :                             test();
     441        1456 :                             test();
     442        1456 :                             test();
     443        1456 :                             test();
     444        1456 :                             IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && ( st->last_core == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */
     445             :                             {
     446        1357 :                                 scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
     447             :                             }
     448          99 :                             ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */
     449             :                             {
     450          99 :                                 IF( !st->tcxonly )
     451             :                                 {
     452          99 :                                     scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
     453             :                                 }
     454             :                             }
     455             :                         }
     456             :                         ELSE /* ACELP core */
     457             :                         {
     458        1514 :                             test();
     459        1514 :                             test();
     460        1514 :                             IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */
     461             :                             {
     462          79 :                                 test();
     463          79 :                                 test();
     464          79 :                                 test();
     465          79 :                                 test();
     466          79 :                                 IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) )
     467             :                                 {
     468          79 :                                     scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
     469             :                                 }
     470             :                             }
     471             :                         }
     472             :                     }
     473        6610 :                     scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft
     474        6610 :                     hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft;
     475        6610 :                     move16();
     476             :                 }
     477             : 
     478        6610 :                 IF( hSCE != NULL )
     479             :                 {
     480        2970 :                     Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_hb_synth_fx ) ); // q_dft
     481        2970 :                     hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft;
     482        2970 :                     move16();
     483        2970 :                     Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_synth_fx ) ); // q_dft
     484        2970 :                     hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft;
     485        2970 :                     move16();
     486             :                 }
     487       19830 :                 FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
     488             :                 {
     489       13220 :                     scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
     490       13220 :                     hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft;
     491       13220 :                     move16();
     492             :                 }
     493       19830 :                 FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
     494             :                 {
     495       13220 :                     Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx
     496             :                 }
     497             : 
     498        6610 :                 ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame, st_ivas->ivas_format == MC_FORMAT );
     499             : 
     500       19830 :                 FOR( i = 0; i < 2; i++ )
     501             :                 {
     502       13220 :                     Scale_sig32( p_output_fx[i], L_FRAME48k, negate( s ) );
     503             :                 }
     504       19830 :                 FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
     505             :                 {
     506       13220 :                     Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->q_prev_synth_fx ) ); // Q11
     507             :                 }
     508             : 
     509        6610 :                 scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) );
     510       19830 :                 FOR( i = 0; i < CPE_CHANNELS; ++i )
     511             :                 {
     512       13220 :                     scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) );                                          // Q11
     513       13220 :                     scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
     514             :                 }
     515             : 
     516        6610 :                 IF( hCPE->hCoreCoder[0] != NULL )
     517             :                 {
     518        6610 :                     Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); // Q_old_wtda_LB
     519        6610 :                     Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q );          // Q_old_wtda_LB
     520             :                 }
     521        6610 :                 IF( hCPE->hStereoDft != NULL )
     522             :                 {
     523        6610 :                     IF( LE_16( st_ivas->nchan_transport, 1 ) )
     524             :                     {
     525        2970 :                         st = hCPE->hCoreCoder[0];
     526        2970 :                         test();
     527        2970 :                         test();
     528        2970 :                         test();
     529        2970 :                         test();
     530        2970 :                         test();
     531        2970 :                         IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && st->core == ACELP_CORE && EQ_16( st->con_tcx, 1 ) ) )
     532             :                         {
     533        1456 :                             test();
     534        1456 :                             test();
     535        1456 :                             test();
     536        1456 :                             test();
     537        1456 :                             test();
     538        1456 :                             test();
     539        1456 :                             test();
     540        1456 :                             test();
     541        1456 :                             IF( ( ( st->last_core != ACELP_CORE || ( EQ_16( st->prev_bfi, 1 ) && st->last_core == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */
     542             :                             {
     543        1456 :                                 scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
     544             :                             }
     545           0 :                             ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */
     546             :                             {
     547           0 :                                 IF( !st->tcxonly )
     548             :                                 {
     549           0 :                                     scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
     550             :                                 }
     551             :                             }
     552             :                         }
     553             :                         ELSE /* ACELP core */
     554             :                         {
     555        1514 :                             test();
     556        1514 :                             test();
     557        1514 :                             IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */
     558             :                             {
     559           0 :                                 test();
     560           0 :                                 test();
     561           0 :                                 test();
     562           0 :                                 test();
     563           0 :                                 IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) )
     564             :                                 {
     565           0 :                                     scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
     566             :                                 }
     567             :                             }
     568             :                         }
     569             :                     }
     570        6610 :                     scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11
     571        6610 :                     hCPE->hStereoDft->q_ap_fade_mem_fx = Q11;
     572        6610 :                     test();
     573             :                 }
     574             : 
     575        6610 :                 st_ivas->hSpar->hMdDec->Q_mixer_mat = 30;
     576        6610 :                 move16();
     577       19830 :                 FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
     578             :                 {
     579       13220 :                     scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
     580       13220 :                     hCPE->q_output_mem_fx[ii] = Q11;
     581       13220 :                     move16();
     582             :                 }
     583             :             }
     584             :         }
     585      146952 :         ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && st_ivas->nCPE > 0 && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) )
     586             :         {
     587        8022 :             nchan_remapped = 1; /* Only one channel transported */
     588        8022 :             move16();
     589             :         }
     590             : 
     591             :         /* HP filtering */
     592      481358 :         FOR( n = 0; n < nchan_remapped; n++ )
     593             :         {
     594             : #ifdef HP20_FIX32_RECODING
     595      327796 :             hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
     596             : #else
     597             :             hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
     598             : #endif
     599             :         }
     600             : 
     601      153562 :         IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
     602             :         {
     603      121018 :             nchan_remapped = ivas_sba_remapTCs_fx( p_output_fx, st_ivas, output_frame );
     604             : 
     605      121018 :             test();
     606      121018 :             IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
     607       29835 :             {
     608       29835 :                 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate );
     609             : 
     610       29835 :                 SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
     611       29835 :                 Word16 Q_p_output = MAX_16, temp_min;
     612       29835 :                 move16();
     613             :                 Word16 nchan_transport;
     614             : 
     615       29835 :                 nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
     616       29835 :                 move16();
     617       29835 :                 nchan_out = nchan_transport;
     618       29835 :                 move16();
     619       77240 :                 FOR( ch = 0; ch < nchan_transport; ch++ )
     620             :                 {
     621       47405 :                     temp_min = L_norm_arr( p_output_fx[ch], output_frame );
     622       47405 :                     Q_p_output = s_min( Q_p_output, temp_min );
     623             :                 }
     624       29835 :                 Q_p_output = sub( Q_p_output, 2 );
     625       29835 :                 if ( GT_16( Q_p_output, 20 ) )
     626             :                 {
     627          11 :                     Q_p_output = 20;
     628          11 :                     move16();
     629             :                 }
     630       77240 :                 FOR( ch = 0; ch < nchan_transport; ch++ )
     631             :                 {
     632       47405 :                     Scale_sig32( p_output_fx[ch], output_frame, Q_p_output ); // Q(11+Q_p_output)
     633             :                 }
     634             : 
     635       29835 :                 ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, Q_p_output );
     636       77240 :                 FOR( Word16 c = 0; c < nchan_transport; c++ )
     637             :                 {
     638       47405 :                     Scale_sig32( p_output_fx[c], output_frame, 11 ); // Q11
     639             :                 }
     640             :             }
     641       91183 :             ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) )
     642             :             {
     643       82933 :                 Word16 size = st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport;
     644       82933 :                 move16();
     645       82933 :                 if ( EQ_16( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, 3 ) )
     646       25069 :                     size = add( size, 1 );
     647             : 
     648      325337 :                 FOR( i = 0; i < size; i++ )
     649             :                 {
     650      242404 :                     Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14
     651             :                 }
     652             : 
     653       82933 :                 ivas_spar_dec_agc_pca_fx( st_ivas, p_output_fx, output_frame );
     654             :             }
     655             :         }
     656             : 
     657      153562 :         test();
     658      153562 :         test();
     659      153562 :         IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
     660             :         {
     661       32544 :             Word16 q_shift = 0;
     662       32544 :             move16();
     663             : 
     664       32544 :             ivas_masa_prerender_fx( st_ivas, p_output_fx, &q_shift, output_frame, nchan_remapped );
     665       97632 :             FOR( i = 0; i < 2; i++ )
     666             :             {
     667       65088 :                 Scale_sig32( p_output_fx[i], output_frame, negate( q_shift ) );
     668             :             }
     669             : 
     670       32544 :             test();
     671             :             /* external output */
     672       32544 :             IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_32( st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) )
     673             :             {
     674         190 :                 FOR( n = 0; n < st_ivas->nchan_ism; n++ )
     675             :                 {
     676         152 :                     set_zero_fx( p_output_fx[add( st_ivas->nchan_transport, n )], output_frame );
     677             :                 }
     678             : 
     679          38 :                 ivas_omasa_rearrange_channels_fx( p_output_fx, st_ivas->nchan_ism, output_frame );
     680             :             }
     681             :         }
     682      121018 :         ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
     683             :         {
     684             :             /* loudness correction */
     685       29835 :             ivas_dirac_dec_binaural_sba_gain_fx( p_output_fx, nchan_remapped, output_frame );
     686             : 
     687       77240 :             FOR( i = 0; i < st_ivas->nchan_transport; i++ )
     688             :             {
     689       47405 :                 Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q
     690             :             }
     691             :         }
     692             :     }
     693       89244 :     ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
     694             :     {
     695             :         Word16 nchan_ism, nchan_transport_ism;
     696             :         Word16 dirac_bs_md_write_idx;
     697             : 
     698        6530 :         set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 );
     699             : 
     700             :         /* Set the number of objects for the parametric rendering */
     701        6530 :         dirac_bs_md_write_idx = 0;
     702        6530 :         move16();
     703        6530 :         IF( st_ivas->hSpatParamRendCom != NULL )
     704             :         {
     705        4880 :             st_ivas->hSpatParamRendCom->numIsmDirections = 0;
     706        4880 :             move16();
     707        4880 :             test();
     708        4880 :             if ( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
     709             :             {
     710        1288 :                 st_ivas->hSpatParamRendCom->numIsmDirections = st_ivas->nchan_ism;
     711        1288 :                 move16();
     712             :             }
     713             : 
     714        4880 :             dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */
     715        4880 :             move16();
     716             :         }
     717             : 
     718             : 
     719             :         /* set ISM parameters and decode ISM metadata in OMASA format */
     720        6530 :         Word16 q_output = 11;
     721        6530 :         move16();
     722             :         // NOTE: the following is done to calculate the number of hIsmMetaData indices
     723             :         Word16 tmp_nchan_ism;
     724        6530 :         IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
     725             :         {
     726        2065 :             tmp_nchan_ism = 1;
     727        2065 :             move16();
     728             :         }
     729        4465 :         ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
     730             :         {
     731        1663 :             tmp_nchan_ism = 0;
     732        1663 :             move16();
     733             :         }
     734             :         ELSE
     735             :         {
     736        2802 :             tmp_nchan_ism = st_ivas->nchan_ism;
     737        2802 :             move16();
     738             :         }
     739             : 
     740       16070 :         FOR( n = 0; n < tmp_nchan_ism; n++ )
     741             :         {
     742        9540 :             set32_fx( p_output_fx[n], 0, L_FRAME48k );
     743             :         }
     744             : 
     745             :         /* MASA metadata decoding */
     746        6530 :         IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
     747             :         {
     748           0 :             return error;
     749             :         }
     750             : 
     751             :         /* Configuration of combined-format bit-budget distribution */
     752        6530 :         ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate );
     753             : 
     754        6530 :         st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] );
     755             : 
     756        6530 :         IF( NE_32( ( error = ivas_omasa_ism_metadata_dec_fx( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
     757             :         {
     758           0 :             return error;
     759             :         }
     760             : 
     761       17733 :         FOR( n = 0; n < nchan_transport_ism; n++ )
     762             :         {
     763       11203 :             IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, n, &p_output_fx[st_ivas->nchan_transport + n], output_frame, nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
     764             :             {
     765           0 :                 return error;
     766             :             }
     767             :         }
     768             : 
     769             :         /* decode MASA channels */
     770        6530 :         IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
     771             :         {
     772           0 :             return error;
     773             :         }
     774             : 
     775             :         /* shifting both the channels from variable q_output to constant Q-factor (Q11) */
     776     5531970 :         FOR( Word16 k = 0; k < output_frame; k++ )
     777             :         {
     778     5525440 :             p_output_fx[0][k] = L_shr( p_output_fx[0][k], sub( Q11, q_output ) );
     779     5525440 :             move32();
     780     5525440 :             p_output_fx[1][k] = L_shr( p_output_fx[1][k], sub( Q11, q_output ) );
     781     5525440 :             move32();
     782             :         }
     783             : 
     784        6530 :         IF( EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) )
     785             :         {
     786        1332 :             Copy32( p_output_fx[0], p_output_fx[1], output_frame ); /* Copy mono signal to stereo output channels */
     787             :         }
     788             : 
     789       30793 :         FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
     790             :         {
     791             : #ifdef HP20_FIX32_RECODING
     792       24263 :             hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
     793             : #else
     794             :             hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
     795             : #endif
     796             :         }
     797             : 
     798        6530 :         Word16 output_q = 11;
     799        6530 :         move16();
     800        6530 :         IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
     801             :         {
     802         975 :             ivas_ism_mono_dmx_fx( st_ivas, p_output_fx, output_frame );
     803             : 
     804         975 :             output_q = 8;
     805         975 :             move16();
     806             :         }
     807        5555 :         ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
     808             :         {
     809         715 :             IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
     810             :             {
     811         639 :                 ivas_omasa_rearrange_channels_fx( p_output_fx, nchan_transport_ism, output_frame );
     812             :             }
     813          76 :             ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
     814             :             {
     815             :                 /* Convert separate object to MASA, combine with the original MASA, and output combined MASA + empty objects. */
     816          36 :                 ivas_omasa_combine_separate_ism_with_masa_fx( st_ivas, p_output_fx, &output_q, st_ivas->nchan_ism, output_frame );
     817             :             }
     818          40 :             ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
     819             :             {
     820             :                 /* Extract objects from MASA, output MASA + all objects (i.e., extracted and separated objects) */
     821          40 :                 ivas_omasa_render_objects_from_mix_fx( st_ivas, p_output_fx, st_ivas->nchan_ism, output_frame, &output_q );
     822             :             }
     823             : 
     824         715 :             IF( st_ivas->hDecoderConfig->Opt_tsm )
     825             :             {
     826         153 :                 ivas_jbm_dec_copy_masa_meta_to_buffer( st_ivas );
     827             :             }
     828             :         }
     829        6530 :         IF( NE_16( output_q, Q11 ) )
     830             :         {
     831        4660 :             FOR( n = 0; n < s_max( getNumChanSynthesis( st_ivas ), nchan_transport_ism + st_ivas->nchan_transport ); n++ )
     832             :             {
     833        3685 :                 Scale_sig32( p_output_fx[n], output_frame, sub( Q11, output_q ) ); // Q11
     834             :             }
     835             :         }
     836             :     }
     837       82714 :     ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     838             :     {
     839             :         Word16 nchan_ism, sba_ch_idx;
     840             : 
     841       34004 :         set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 );
     842       34004 :         nchan_ism = st_ivas->nchan_ism;
     843       34004 :         move16();
     844       34004 :         IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     845             :         {
     846             :             /* set ISM parameters and decode ISM metadata in OSBA format */
     847       19680 :             IF( NE_32( ( error = ivas_osba_ism_metadata_dec_fx( st_ivas, ivas_total_brate, &nchan_ism, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
     848             :             {
     849           0 :                 return error;
     850             :             }
     851       19680 :             sba_ch_idx = st_ivas->nchan_ism;
     852       19680 :             move16();
     853             :         }
     854             :         ELSE
     855             :         {
     856       14324 :             nb_bits_metadata[1] = add( nb_bits_metadata[1], NO_BITS_MASA_ISM_NO_OBJ );
     857       14324 :             sba_ch_idx = 0;
     858       14324 :             move16();
     859       14324 :             move16();
     860             :         }
     861             : 
     862             :         /* SBA metadata decoding */
     863       34004 :         IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) )
     864             :         {
     865           0 :             return error;
     866             :         }
     867             : 
     868       34004 :         test();
     869       34004 :         IF( EQ_16( st_ivas->nchan_transport, CPE_CHANNELS ) && GE_16( st_ivas->nCPE, 1 ) )
     870             :         {
     871        6189 :             st_ivas->hCPE[0]->element_brate = ivas_total_brate;
     872        6189 :             move32();
     873             :         }
     874             : 
     875             :         /* core-decoding of transport channels */
     876       34004 :         Word16 q_output = 11;
     877       34004 :         move16();
     878             : 
     879       34004 :         IF( EQ_16( st_ivas->nSCE, 1 ) )
     880             :         {
     881        6615 :             set32_fx( p_output_fx[0], 0, L_FRAME48k );
     882             : 
     883        6615 :             IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
     884             :             {
     885           0 :                 return error;
     886             :             }
     887             :         }
     888       27389 :         ELSE IF( EQ_16( st_ivas->nCPE, 1 ) )
     889             :         {
     890             : 
     891        6189 :             IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, add( nb_bits_metadata[0], nb_bits_metadata[1] ) ) ), IVAS_ERR_OK ) )
     892             :             {
     893           0 :                 return error;
     894             :             }
     895             : 
     896        6189 :             IF( NE_16( q_output, Q11 ) )
     897             :             {
     898           0 :                 Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
     899           0 :                 Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
     900             :             }
     901             :         }
     902       21200 :         ELSE IF( GT_16( st_ivas->nCPE, 1 ) )
     903             :         {
     904       21200 :             IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
     905             :             {
     906           0 :                 return error;
     907             :             }
     908             :         }
     909             : 
     910       34004 :         IF( st_ivas->sba_dirac_stereo_flag )
     911             :         {
     912       12320 :             FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ )
     913             :             {
     914        9320 :                 Scale_sig32( p_output_fx[i + sba_ch_idx], output_frame, Q14 - Q11 ); // Q14
     915             :             }
     916        3000 :             SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
     917             :             Word16 nchan_transport;
     918        3000 :             nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
     919        3000 :             move16();
     920        3000 :             nchan_out = nchan_transport;
     921        3000 :             move16();
     922        3000 :             ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx + sba_ch_idx ), ( p_output_fx + sba_ch_idx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );
     923             : 
     924        3000 :             IF( st_ivas->hSpar->hPCA != NULL )
     925             :             {
     926           0 :                 ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, &p_output_fx[sba_ch_idx] );
     927             :             }
     928        3000 :             ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, 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 ) );
     929             :             {
     930             :                 Word16 q;
     931        3000 :                 hCPE = st_ivas->hCPE[0];
     932        3000 :                 hSCE = st_ivas->hSCE[0];
     933        3000 :                 s = 0;
     934        3000 :                 move16();
     935        9000 :                 FOR( i = 0; i < 2; i++ )
     936             :                 {
     937        6000 :                     s = s_min( s, L_norm_arr( p_output_fx[sba_ch_idx + i], L_FRAME48k ) - 11 /* Guard bits */ );
     938             :                 }
     939        9000 :                 FOR( i = 0; i < 2; i++ )
     940             :                 {
     941        6000 :                     Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, s ); // Q(11+s)
     942             :                 }
     943        3000 :                 hCPE->hStereoDft->q_dft = add( Q11, s );
     944        3000 :                 move16();
     945        3000 :                 IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
     946             :                 {
     947          30 :                     hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft;
     948          30 :                     hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft;
     949          30 :                     move16();
     950          30 :                     move16();
     951             :                 }
     952             : 
     953        3000 :                 q = hCPE->hStereoDft->q_dft;
     954        3000 :                 move16();
     955        3000 :                 scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );
     956        9000 :                 FOR( i = 0; i < CPE_CHANNELS; ++i )
     957             :                 {
     958        6000 :                     scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );                                          // q_dft
     959        6000 :                     scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
     960             :                 }
     961        3000 :                 IF( hCPE->hCoreCoder[0] != NULL )
     962             :                 {
     963        3000 :                     Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q
     964        3000 :                     Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) );          // q
     965        3000 :                     hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q;
     966        3000 :                     move16();
     967             :                 }
     968        3000 :                 IF( hCPE->hStereoDft != NULL )
     969             :                 {
     970        3000 :                     scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) );                           // q_dft
     971        3000 :                     scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft
     972        3000 :                     hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft;
     973        3000 :                     move16();
     974             :                 }
     975             : 
     976        3000 :                 IF( hSCE != NULL )
     977             :                 {
     978         361 :                     Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft
     979         361 :                     hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft;
     980         361 :                     move16();
     981         361 :                     Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft
     982         361 :                     hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft;
     983         361 :                     move16();
     984             :                 }
     985        9000 :                 FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
     986             :                 {
     987        6000 :                     scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
     988        6000 :                     hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft;
     989        6000 :                     move16();
     990             :                 }
     991        9000 :                 FOR( i = 0; i < CPE_CHANNELS; i++ )
     992        6000 :                 Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx
     993        3000 :                 ivas_sba_dirac_stereo_dec_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame, 0 );
     994        9000 :                 FOR( i = 0; i < 2; i++ )
     995             :                 {
     996        6000 :                     Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, negate( s ) );
     997             :                 }
     998             : 
     999        9000 :                 FOR( i = 0; i < CPE_CHANNELS; i++ )
    1000        6000 :                 Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11
    1001             : 
    1002        3000 :                 scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
    1003        9000 :                 FOR( i = 0; i < CPE_CHANNELS; ++i )
    1004             :                 {
    1005        6000 :                     scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) );                                          // Q11
    1006        6000 :                     scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
    1007             :                 }
    1008             : 
    1009        3000 :                 IF( hCPE->hCoreCoder[0] != NULL )
    1010             :                 {
    1011        3000 :                     Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB
    1012        3000 :                     Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) );          // Q_old_wtda
    1013             :                 }
    1014        3000 :                 IF( hCPE->hStereoDft != NULL )
    1015             :                 {
    1016        3000 :                     scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) );       // Q11
    1017        3000 :                     scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11
    1018        3000 :                     hCPE->hStereoDft->q_ap_fade_mem_fx = Q11;
    1019        3000 :                     move16();
    1020             :                 }
    1021             : 
    1022        9000 :                 FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
    1023             :                 {
    1024        6000 :                     scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
    1025        6000 :                     hCPE->q_output_mem_fx[ii] = Q11;
    1026        6000 :                     move16();
    1027             :                 }
    1028             :             }
    1029             :         }
    1030             : 
    1031             :         /* HP filtering */
    1032      184546 :         FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
    1033             :         {
    1034             : #ifdef HP20_FIX32_RECODING
    1035      150542 :             hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1036             : #else
    1037             :             hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1038             : #endif
    1039             :         }
    1040             : 
    1041       34004 :         nchan_remapped = ivas_sba_remapTCs_fx( &p_output_fx[sba_ch_idx], st_ivas, output_frame );
    1042             : 
    1043       34004 :         test();
    1044       34004 :         test();
    1045       34004 :         IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
    1046        7745 :         {
    1047        7745 :             num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate );
    1048        7745 :             SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
    1049             :             Word16 nchan_transport;
    1050             :             // num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands;
    1051        7745 :             nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
    1052        7745 :             move16();
    1053        7745 :             nchan_out = nchan_transport;
    1054        7745 :             move16();
    1055             :             Word16 Q_p_output;
    1056        7745 :             Word16 min_norm = 31;
    1057        7745 :             move16();
    1058             : 
    1059       19341 :             FOR( ch = 0; ch < nchan_transport; ++ch )
    1060             :             {
    1061       11596 :                 Word16 norm = L_norm_arr( p_output_fx[sba_ch_idx + ch], output_frame ); // Normalize per channel
    1062       11596 :                 min_norm = s_min( norm, min_norm );
    1063             :             }
    1064             : 
    1065        7745 :             Q_p_output = s_max( 3, sub( min_norm, 1 ) );
    1066             : 
    1067        7745 :             Q_p_output = s_min( Q_p_output, 19 ); // to restrict Q-factor of p_ouptut to Q30
    1068       19341 :             FOR( ch = 0; ch < nchan_transport; ch++ )
    1069             :             {
    1070       11596 :                 Scale_sig32( p_output_fx[sba_ch_idx + ch], output_frame, Q_p_output ); // Q_p_output + Q11
    1071             :             }
    1072        7745 :             Q_p_output = add( Q11, Q_p_output );
    1073        7745 :             hSpar->hMdDec->Q_mixer_mat = 31;
    1074        7745 :             move16();
    1075             : 
    1076        7745 :             ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, &p_output_fx[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, sub( Q_p_output, Q11 ) );
    1077       19341 :             FOR( Word16 c = 0; c < nchan_transport; c++ )
    1078             :             {
    1079       11596 :                 Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); // Q11
    1080             :             }
    1081             :         }
    1082       26259 :         ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->sba_dirac_stereo_flag == 0 )
    1083             :         {
    1084       22259 :             Word16 size = add( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, sba_ch_idx );
    1085       22259 :             if ( EQ_16( size, 3 ) )
    1086             :             {
    1087         449 :                 size = add( size, 1 );
    1088             :             }
    1089             : 
    1090       97694 :             FOR( i = sba_ch_idx; i < size; i++ )
    1091             :             {
    1092       75435 :                 Scale_sig32( p_output_fx[i], output_frame, ( Q14 - Q11 ) ); // Q14
    1093             :             }
    1094             : 
    1095       22259 :             ivas_spar_dec_agc_pca_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame );
    1096             :         }
    1097             : 
    1098       34004 :         test();
    1099       34004 :         test();
    1100       34004 :         IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
    1101             :         {
    1102             :             /* loudness correction */
    1103        7745 :             ivas_dirac_dec_binaural_sba_gain_fx( &p_output_fx[sba_ch_idx], nchan_remapped, output_frame ); /*returns Q-1*/
    1104             : 
    1105       19341 :             FOR( i = 0; i < nchan_remapped; i++ )
    1106             :             {
    1107       11596 :                 Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q
    1108             :             }
    1109             :         }
    1110       26259 :         ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    1111             :         {
    1112        1000 :             ivas_ism_mono_dmx_fx( st_ivas, p_output_fx, output_frame );
    1113             : 
    1114        1000 :             Scale_sig32( p_output_fx[0], L_FRAME48k, Q11 - Q8 ); // Q11
    1115             : 
    1116             :             /* add W */
    1117        2000 :             FOR( n = 0; n < nchan_out; n++ )
    1118             :             {
    1119        1000 :                 v_add_32( p_output_fx[n], p_output_fx[n + s_max( nchan_out, nchan_ism )], p_output_fx[n], output_frame );
    1120             :             }
    1121             :         }
    1122             :     }
    1123       48710 :     ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
    1124             :     {
    1125             : 
    1126             :         // st = (st_ivas->nSCE > 0) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
    1127       48710 :         IF( st_ivas->nSCE > 0 )
    1128             :         {
    1129       11179 :             st = st_ivas->hSCE[0]->hCoreCoder[0];
    1130             :         }
    1131             :         ELSE
    1132             :         {
    1133       37531 :             st = st_ivas->hCPE[0]->hCoreCoder[0];
    1134             :         }
    1135             : 
    1136       48710 :         IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
    1137             :         {
    1138             :             /* LFE channel decoder */
    1139       26082 :             ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] );
    1140             : 
    1141       26082 :             Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11
    1142       26082 :             IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ), IVAS_ERR_OK ) )
    1143             :             {
    1144           0 :                 return error;
    1145             :             }
    1146             :             /* HP filtering */
    1147      195258 :             FOR( n = 0; n < st_ivas->nchan_transport; n++ )
    1148             :             {
    1149      169176 :                 IF( NE_16( n, LFE_CHANNEL ) )
    1150             :                 {
    1151             : #ifdef HP20_FIX32_RECODING
    1152      143094 :                     hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1153             : #else
    1154             :                     hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1155             : #endif
    1156             :                 }
    1157             :             }
    1158             : 
    1159       26082 :             test();
    1160       26082 :             test();
    1161       26082 :             test();
    1162       26082 :             IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) )
    1163             :             {
    1164         150 :                 IF( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) )
    1165             :                 {
    1166           0 :                     ivas_mc2sba_fx( st_ivas->hTransSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX );
    1167             :                 }
    1168             :             }
    1169             : 
    1170       26082 :             test();
    1171       26082 :             test();
    1172       26082 :             IF( ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) )
    1173             :             {
    1174        3030 :                 IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
    1175             :                 {
    1176        3030 :                     s = Q16 - Q11;
    1177        3030 :                     move16();
    1178        3030 :                     s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) );
    1179       21390 :                     FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i )
    1180             :                     {
    1181       18360 :                         Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s)
    1182             :                     }
    1183        3030 :                     ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx );
    1184       21390 :                     FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i )
    1185             :                     {
    1186       18360 :                         Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11
    1187             :                     }
    1188             :                 }
    1189           0 :                 ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    1190             :                 {
    1191           0 :                     ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hOutSetup.ambisonics_order, 0 );
    1192             :                 }
    1193             :             }
    1194             :         }
    1195       22628 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
    1196             :         {
    1197             :             /* LFE channel decoder */
    1198         790 :             ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] );
    1199             : 
    1200         790 :             Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11
    1201             : 
    1202         790 :             ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] );
    1203             : 
    1204         790 :             IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
    1205             :             {
    1206           0 :                 return error;
    1207             :             }
    1208             :             /* HP filtering */
    1209        7110 :             FOR( n = 0; n < st_ivas->nchan_transport; n++ )
    1210             :             {
    1211        6320 :                 IF( NE_16( n, LFE_CHANNEL ) )
    1212             :                 {
    1213             : #ifdef HP20_FIX32_RECODING
    1214        5530 :                     hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1215             : #else
    1216             :                     hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1217             : #endif
    1218             :                 }
    1219             :             }
    1220             : 
    1221             :             /* Rendering */
    1222         790 :             test();
    1223         790 :             test();
    1224         790 :             IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
    1225             :             {
    1226             :                 /* Compensate loudness for not doing full upmix */
    1227          50 :                 FOR( n = 4; n < 8; n++ )
    1228             :                 {
    1229          40 :                     Scale_sig32( p_output_fx[n], output_frame, 1 );
    1230             :                 }
    1231             : 
    1232          10 :                 test();
    1233          10 :                 IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
    1234             :                 {
    1235          10 :                     s = Q16 - Q11;
    1236          10 :                     move16();
    1237             :                     Word16 nchan_transport;
    1238          10 :                     nchan_transport = audioCfg2channels( IVAS_AUDIO_CONFIG_5_1_2 );
    1239          10 :                     s = sub( s, find_guarded_bits_fx( nchan_transport ) );
    1240          90 :                     FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i )
    1241             :                     {
    1242          80 :                         Scale_sig32( p_output_fx[i], output_frame, s );
    1243             :                     }
    1244          10 :                     ivas_ls_setup_conversion_fx( st_ivas, nchan_transport, output_frame, p_output_fx, p_output_fx );
    1245          90 :                     FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i )
    1246             :                     {
    1247          80 :                         Scale_sig32( p_output_fx[i], output_frame, negate( s ) );
    1248             :                     }
    1249             :                 }
    1250             :             }
    1251             :         }
    1252       21838 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
    1253             :         {
    1254             :             /* read Parametric MC parameters from the bitstream */
    1255       10249 :             ivas_param_mc_dec_read_BS_fx( ivas_total_brate, st, st_ivas->hParamMC, &nb_bits_metadata[0] );
    1256             : 
    1257       10249 :             IF( EQ_16( st_ivas->nCPE, 1 ) )
    1258             :             {
    1259       10139 :                 Word16 q_output = 11;
    1260       10139 :                 move16();
    1261             : 
    1262       10139 :                 IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
    1263             :                 {
    1264           0 :                     return error;
    1265             :                 }
    1266       10139 :                 IF( NE_16( q_output, Q11 ) )
    1267             :                 {
    1268           0 :                     Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
    1269           0 :                     Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
    1270             :                 }
    1271             :             }
    1272         110 :             ELSE IF( GT_16( st_ivas->nCPE, 1 ) )
    1273             :             {
    1274         110 :                 IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
    1275             :                 {
    1276           0 :                     return error;
    1277             :                 }
    1278             :             }
    1279             : 
    1280             :             /* HP filtering */
    1281       30857 :             FOR( n = 0; n < st_ivas->nchan_transport; n++ )
    1282             :             {
    1283             : #ifdef HP20_FIX32_RECODING
    1284       20608 :                 hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1285             : #else
    1286             :                 hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1287             : #endif
    1288             :             }
    1289             : 
    1290             :             /* Rendering */
    1291       10249 :             test();
    1292       10249 :             IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
    1293             :             {
    1294          20 :                 ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx );
    1295             :             }
    1296             :         }
    1297       11589 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
    1298             :         {
    1299       11589 :             IF( st_ivas->hOutSetup.separateChannelEnabled )
    1300             :             {
    1301         595 :                 st = st_ivas->hCPE[0]->hCoreCoder[0]; /* Metadata is always with CPE in the case of separated channel */
    1302             :             }
    1303             : 
    1304             :             /* read McMASA parameters from the bitstream */
    1305             : 
    1306       11589 :             IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
    1307             :             {
    1308           0 :                 return error;
    1309             :             }
    1310             : 
    1311       11589 :             IF( st_ivas->hOutSetup.separateChannelEnabled )
    1312             :             {
    1313             :                 /* Decode the transport audio signals */
    1314         595 :                 Word16 q_output = 11;
    1315         595 :                 move16();
    1316             : 
    1317         595 :                 IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
    1318             :                 {
    1319           0 :                     return error;
    1320             :                 }
    1321         595 :                 IF( NE_16( q_output, Q11 ) )
    1322             :                 {
    1323           0 :                     Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
    1324           0 :                     Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
    1325             :                 }
    1326             : 
    1327             :                 /* Identify the index of the separated channel, always LFE_CHANNEL-1 here */
    1328         595 :                 n = LFE_CHANNEL - 1;
    1329         595 :                 move16();
    1330             : 
    1331             :                 /* Decode the separated channel to output[n] to be combined with the synthesized channels */
    1332             : 
    1333         595 :                 set32_fx( p_output_fx[n], 0, L_FRAME48k );
    1334             : 
    1335         595 :                 IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[n], output_frame, 0 ) ), IVAS_ERR_OK ) )
    1336             :                 {
    1337           0 :                     return error;
    1338             :                 }
    1339         595 :                 test();
    1340         595 :                 test();
    1341         595 :                 test();
    1342         595 :                 test();
    1343         595 :                 test();
    1344         595 :                 test();
    1345         595 :                 test();
    1346             :                 /* Delay the separated channel to sync with CLDFB delay of the DirAC synthesis, and synthesize the LFE signal. */
    1347         595 :                 IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
    1348             :                     EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
    1349             :                 {
    1350         195 :                     ivas_lfe_synth_with_filters_fx( st_ivas->hMasa->hMasaLfeSynth, p_output_fx, output_frame, n, LFE_CHANNEL );
    1351             :                 }
    1352         400 :                 ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 )
    1353             :                 {
    1354             :                     /* Delay the separated channel to sync with the DirAC rendering */
    1355           0 :                     delay_signal32_fx( p_output_fx[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size );
    1356             :                 }
    1357             :             }
    1358             :             ELSE
    1359             :             {
    1360       10994 :                 Word16 q_output = 11;
    1361       10994 :                 move16();
    1362       10994 :                 IF( EQ_16( st_ivas->nSCE, 1 ) )
    1363             :                 {
    1364       10584 :                     set32_fx( p_output_fx[0], 0, L_FRAME48k );
    1365             : 
    1366       10584 :                     IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
    1367             :                     {
    1368           0 :                         return error;
    1369             :                     }
    1370             :                 }
    1371         410 :                 ELSE IF( EQ_16( st_ivas->nCPE, 1 ) )
    1372             :                 {
    1373             : 
    1374         410 :                     IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
    1375             :                     {
    1376           0 :                         return error;
    1377             :                     }
    1378         410 :                     IF( NE_16( q_output, Q11 ) )
    1379             :                     {
    1380           0 :                         Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
    1381           0 :                         Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
    1382             :                     }
    1383             :                 }
    1384             :             }
    1385             : 
    1386       11589 :             IF( st_ivas->sba_dirac_stereo_flag != 0 ) /* use the flag to trigger the DFT upmix */
    1387             :             {
    1388             :                 Word16 q;
    1389        1180 :                 hCPE = st_ivas->hCPE[0];
    1390        1180 :                 hSCE = st_ivas->hSCE[0];
    1391        1180 :                 s = 0;
    1392        1180 :                 move16();
    1393        3540 :                 FOR( i = 0; i < 2; i++ )
    1394             :                 {
    1395        2360 :                     s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 /* Guard bits */ );
    1396             :                 }
    1397        3540 :                 FOR( i = 0; i < 2; i++ )
    1398             :                 {
    1399        2360 :                     Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s)
    1400             :                 }
    1401             : 
    1402        1180 :                 hCPE->hStereoDft->q_dft = add( Q11, s );
    1403        1180 :                 move16();
    1404        1180 :                 IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
    1405             :                 {
    1406        1180 :                     hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft;
    1407        1180 :                     hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft;
    1408             : 
    1409        1180 :                     move16();
    1410        1180 :                     move16();
    1411             :                 }
    1412             : 
    1413        1180 :                 q = hCPE->hStereoDft->q_dft;
    1414        1180 :                 move16();
    1415             : 
    1416        1180 :                 scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );
    1417        3540 :                 FOR( i = 0; i < CPE_CHANNELS; ++i )
    1418             :                 {
    1419        2360 :                     scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );                                          // q_dft
    1420        2360 :                     scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
    1421             :                 }
    1422             : 
    1423        1180 :                 IF( hCPE->hCoreCoder[0] != NULL )
    1424             :                 {
    1425        1180 :                     Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q
    1426        1180 :                     Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda );          // q
    1427        1180 :                     hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q;
    1428        1180 :                     move16();
    1429             :                 }
    1430        1180 :                 IF( hCPE->hStereoDft != NULL )
    1431             :                 {
    1432        1180 :                     scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) );                           // q_dft
    1433        1180 :                     scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft
    1434        1180 :                     hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft;
    1435        1180 :                     move16();
    1436             :                 }
    1437        1180 :                 IF( st_ivas->hSpar != NULL )
    1438             :                 {
    1439           0 :                     st_ivas->hSpar->hMdDec->Q_mixer_mat = 30;
    1440           0 :                     move16();
    1441             :                 }
    1442             : 
    1443        1180 :                 IF( hSCE != NULL )
    1444             :                 {
    1445        1180 :                     Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft
    1446        1180 :                     hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft;
    1447        1180 :                     move16();
    1448        1180 :                     Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft
    1449        1180 :                     hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft;
    1450        1180 :                     move16();
    1451             :                 }
    1452        3540 :                 FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
    1453             :                 {
    1454        2360 :                     scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->q_output_mem_fx[ii] ) ); // q_dft
    1455        2360 :                     hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft;
    1456        2360 :                     move16();
    1457             :                 }
    1458        3540 :                 FOR( i = 0; i < CPE_CHANNELS; i++ )
    1459        2360 :                 Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx
    1460        1180 :                 ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame, 1 );
    1461        3540 :                 FOR( i = 0; i < 2; i++ )
    1462             :                 {
    1463        2360 :                     Scale_sig32( p_output_fx[i], L_FRAME48k, negate( s ) );
    1464             :                 }
    1465        3540 :                 FOR( i = 0; i < CPE_CHANNELS; i++ )
    1466        2360 :                 Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->q_prev_synth_fx ) ); // Q11
    1467             : 
    1468        1180 :                 scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) );
    1469        3540 :                 FOR( i = 0; i < CPE_CHANNELS; ++i )
    1470             :                 {
    1471        2360 :                     scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) );                                          // Q11
    1472        2360 :                     scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
    1473             :                 }
    1474             : 
    1475        1180 :                 IF( hCPE->hCoreCoder[0] != NULL )
    1476             :                 {
    1477        1180 :                     Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB
    1478        1180 :                     Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) );          // Q_old_wtda
    1479             :                 }
    1480        1180 :                 IF( hCPE->hStereoDft != NULL )
    1481             :                 {
    1482        1180 :                     scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) );       // Q11
    1483        1180 :                     scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11
    1484        1180 :                     hCPE->hStereoDft->q_ap_fade_mem_fx = Q11;
    1485        1180 :                     move16();
    1486             :                 }
    1487        1180 :                 IF( st_ivas->hSpar != NULL )
    1488             :                 {
    1489           0 :                     FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
    1490             :                     {
    1491           0 :                         scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
    1492           0 :                         hCPE->q_output_mem_fx[ii] = Q11;
    1493           0 :                         move16();
    1494             :                     }
    1495             :                 }
    1496             :             }
    1497             : 
    1498             :             /* HP filtering */
    1499       25958 :             FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
    1500             :             {
    1501             : #ifdef HP20_FIX32_RECODING
    1502       14369 :                 hp20_fx_32_opt( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1503             : #else
    1504             :                 hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
    1505             : #endif
    1506             :             }
    1507             : 
    1508       11589 :             IF( EQ_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) )
    1509             :             {
    1510         500 :                 ivas_mono_stereo_downmix_mcmasa_fx( st_ivas, p_output_fx, output_frame );
    1511             :             }
    1512             :         }
    1513             :     }
    1514             : 
    1515             :     /*----------------------------------------------------------------*
    1516             :      * Write IVAS transport channels
    1517             :      *----------------------------------------------------------------*/
    1518             : 
    1519      410125 :     IF( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) )
    1520             :     {
    1521       19551 :         ivas_syn_output_f_fx( p_output_fx, output_frame, st_ivas->hTcBuffer->nchan_transport_jbm, data_fx );
    1522             :     }
    1523             :     ELSE
    1524             :     {
    1525             :         /* directly copy to tc buffers */
    1526             :         /*note : the q of cldfb buffers (imag/real) are needed to be Q_p_output - 5 here 6 is taken for that*/
    1527      390574 :         ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, output_frame );
    1528             :     }
    1529             : 
    1530             :     /*----------------------------------------------------------------*
    1531             :      * Common updates
    1532             :      *----------------------------------------------------------------*/
    1533             : 
    1534      410125 :     IF( !st_ivas->bfi ) /* do not update if first frame(s) are lost or NO_DATA */
    1535             :     {
    1536      401402 :         st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate;
    1537      401402 :         move32();
    1538      401402 :         IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) )
    1539             :         {
    1540       17093 :             st_ivas->last_active_ivas_total_brate = st_ivas->last_active_ivas_total_brate;
    1541       17093 :             move32();
    1542             :         }
    1543             :         ELSE
    1544             :         {
    1545      384309 :             st_ivas->last_active_ivas_total_brate = ivas_total_brate;
    1546      384309 :             move32();
    1547             :         }
    1548             :     }
    1549             : 
    1550      410125 :     test();
    1551      410125 :     test();
    1552      410125 :     if ( LT_16( st_ivas->ini_frame, MAX_FRAME_COUNTER ) && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) ) /* keep "st_ivas->ini_frame = 0" until first good received frame */
    1553             :     {
    1554      115387 :         st_ivas->ini_frame = add( st_ivas->ini_frame, 1 );
    1555      115387 :         move16();
    1556             :     }
    1557             : 
    1558      410125 :     test();
    1559      410125 :     test();
    1560      410125 :     if ( LT_16( st_ivas->ini_active_frame, MAX_FRAME_COUNTER ) && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */
    1561             :     {
    1562      115307 :         st_ivas->ini_active_frame = add( st_ivas->ini_active_frame, 1 );
    1563      115307 :         move16();
    1564             :     }
    1565             : 
    1566      410125 :     st_ivas->last_ivas_format = st_ivas->ivas_format;
    1567      410125 :     move32();
    1568      410125 :     pop_wmops();
    1569             : 
    1570      410125 :     return IVAS_ERR_OK;
    1571             : }
    1572             : 
    1573             : 
    1574             : /*--------------------------------------------------------------------------*
    1575             :  * ivas_jbm_dec_feed_tc_to_renderer()
    1576             :  *
    1577             :  * Feed decoded transport channels and metadata to the IVAS JBM renderer routine
    1578             :  *--------------------------------------------------------------------------*/
    1579      413225 : void ivas_jbm_dec_feed_tc_to_renderer_fx(
    1580             :     Decoder_Struct *st_ivas,           /* i/o: IVAS decoder structure                          */
    1581             :     const Word16 nSamplesForRendering, /* i  : number of TC samples available for rendering    */
    1582             :     Word16 *nSamplesResidual,          /* o  : number of samples not fitting into the renderer grid and buffer for the next call*/
    1583             :     Word32 *data_fx                    /* i  : transport channels                              Q11*/
    1584             : )
    1585             : {
    1586      413225 :     Word32 data_f_fx[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* Word32 buffer for transport channels that will be directly converted with the CLDFB */
    1587             :     Word32 *p_data_f_fx[MAX_CLDFB_DIGEST_CHANNELS];
    1588             :     Word16 i;
    1589             : 
    1590     3719025 :     FOR( i = 0; i < MAX_CLDFB_DIGEST_CHANNELS; i++ )
    1591             :     {
    1592     3305800 :         set_zero_fx( data_f_fx[i], MAX_JBM_L_FRAME48k );
    1593             :     }
    1594      413225 :     if ( st_ivas->hTcBuffer )
    1595             :     {
    1596      413225 :         st_ivas->hTcBuffer->q_tc_fx = 11;
    1597      413225 :         move16();
    1598             :     }
    1599             :     Word16 n, n_render_timeslots;
    1600             : 
    1601      413225 :     push_wmops( "ivas_jbm_dec_feed_tc_to_rendererer" );
    1602     3719025 :     FOR( n = 0; n < MAX_CLDFB_DIGEST_CHANNELS; n++ )
    1603             :     {
    1604     3305800 :         p_data_f_fx[n] = &data_f_fx[n][0];
    1605             :     }
    1606             : 
    1607      413225 :     IF( st_ivas->hDecoderConfig->Opt_tsm == 0 )
    1608             :     {
    1609     2861618 :         FOR( n = 0; n < ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ )
    1610             :         {
    1611     2467944 :             st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; /* note: buffers needed in the TD decorellator */
    1612             :         }
    1613             :     }
    1614             : 
    1615      413225 :     IF( st_ivas->hDecoderConfig->Opt_tsm )
    1616             :     {
    1617       19551 :         ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data_fx, p_data_f_fx, 11 );
    1618             :     }
    1619             :     ELSE
    1620             :     {
    1621      393674 :         *nSamplesResidual = 0;
    1622      393674 :         move16();
    1623             :     }
    1624      413225 :     n_render_timeslots = idiv1616( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity );
    1625             : 
    1626             : #ifndef OBJ_EDITING_API
    1627             :     test();
    1628             :     IF( EQ_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
    1629             :     {
    1630             :         ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    1631             : 
    1632             :         test();
    1633             :         test();
    1634             :         test();
    1635             :         IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && st_ivas->hDecoderConfig->Opt_tsm )
    1636             :         {
    1637             :             ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
    1638             :         }
    1639             :     }
    1640             :     ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) )
    1641             :     {
    1642             :         ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    1643             :     }
    1644             :     ELSE
    1645             : #endif
    1646      413225 :     IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
    1647             :     {
    1648             :         /* Rendering */
    1649       94838 :         IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) )
    1650             :         {
    1651       16208 :             test();
    1652             : #ifndef OBJ_EDITING_API
    1653             :             test();
    1654             :             test();
    1655             :             IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
    1656             :             {
    1657             :                 ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots );
    1658             : 
    1659             :                 ivas_param_ism_params_to_masa_param_mapping_fx( st_ivas );
    1660             :             }
    1661             :             ELSE
    1662             : #endif
    1663       16208 :             IF( EQ_16( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    1664             :             {
    1665             : 
    1666        5253 :                 ivas_param_ism_dec_digest_tc_fx( st_ivas, n_render_timeslots, p_data_f_fx, Q11 );
    1667             :             }
    1668             :         }
    1669             : #ifndef OBJ_EDITING_API
    1670             :         ELSE /* ISM_MODE_DISC */
    1671             :         {
    1672             :             ivas_ism_dec_digest_tc_fx( st_ivas );
    1673             :         }
    1674             : #endif
    1675             :     }
    1676             : #ifndef OBJ_EDITING_API
    1677             :     ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
    1678             :     {
    1679             :         IF( st_ivas->hSCE[0] )
    1680             :         {
    1681             :             Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    1682             :             IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    1683             :             {
    1684             :                 shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    1685             :             }
    1686             :             scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
    1687             :             st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    1688             :         }
    1689             :         ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    1690             :     }
    1691             :     ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    1692             :     {
    1693             : 
    1694             :         IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    1695             :         {
    1696             :             ivas_ism_dec_digest_tc_fx( st_ivas );
    1697             : 
    1698             :             test();
    1699             :             test();
    1700             :             test();
    1701             :             test();
    1702             :             /* delay the objects here for all renderers where it is needed */
    1703             :             IF(
    1704             :                 (
    1705             :                     EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
    1706             :                     EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
    1707             :                     EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
    1708             :                     EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
    1709             :                     EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) &&
    1710             :                 ( NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) )
    1711             :             {
    1712             :                 FOR( n = 0; n < st_ivas->nchan_ism; n++ )
    1713             :                 {
    1714             :                     delay_signal32_fx( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer_fx[n], st_ivas->hSbaIsmData->delayBuffer_size );
    1715             :                 }
    1716             :             }
    1717             : 
    1718             :             IF( !st_ivas->sba_dirac_stereo_flag )
    1719             :             {
    1720             :                 IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
    1721             :                 {
    1722             :                     Word16 temp, temp_e;
    1723             :                     temp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size, &temp_e );
    1724             :                     n_render_timeslots = extract_l( L_shr( L_mult0( n_render_timeslots, temp ), sub( 15, temp_e ) ) );
    1725             :                 }
    1726             : 
    1727             :                 IF( st_ivas->hSCE[0] )
    1728             :                 {
    1729             :                     Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    1730             :                     if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    1731             :                     {
    1732             :                         shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    1733             :                     }
    1734             :                     scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
    1735             :                     st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    1736             :                 }
    1737             :                 ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    1738             :             }
    1739             :         }
    1740             :         ELSE
    1741             :         {
    1742             :             ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    1743             : 
    1744             :             IF( st_ivas->hSCE[0] )
    1745             :             {
    1746             :                 Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    1747             :                 if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    1748             :                 {
    1749             :                     shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    1750             :                 }
    1751             :                 scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
    1752             :                 st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    1753             :             }
    1754             :             ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    1755             :         }
    1756             :     }
    1757             :     ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
    1758             :     {
    1759             :         test();
    1760             :         IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) )
    1761             :         {
    1762             :             ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    1763             :             IF( st_ivas->hDecoderConfig->Opt_tsm )
    1764             :             {
    1765             :                 ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
    1766             :             }
    1767             :         }
    1768             :         ELSE
    1769             :         {
    1770             :             test();
    1771             :             IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
    1772             :             {
    1773             :                 n_render_timeslots = i_mult( n_render_timeslots, idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ) );
    1774             :             }
    1775             : 
    1776             :             IF( st_ivas->hSCE[0] )
    1777             :             {
    1778             :                 Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    1779             :                 if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    1780             :                 {
    1781             :                     shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    1782             :                 }
    1783             :                 scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31- (st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp - shift)
    1784             :                 st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    1785             :                 move16();
    1786             :             }
    1787             :             ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    1788             : 
    1789             :             IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
    1790             :             {
    1791             :                 ivas_ism_dec_digest_tc_fx( st_ivas );
    1792             :             }
    1793             :         }
    1794             : 
    1795             :         test();
    1796             :         IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) )
    1797             :         {
    1798             :             Word16 num_objects;
    1799             : 
    1800             :             /* Delay the signal to match CLDFB delay. Delay the whole buffer. */
    1801             :             num_objects = 0;
    1802             :             move16();
    1803             : 
    1804             :             test();
    1805             :             test();
    1806             :             IF( ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) )
    1807             :             {
    1808             :                 num_objects = 1;
    1809             :                 move16();
    1810             :             }
    1811             :             ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
    1812             :             {
    1813             :                 num_objects = st_ivas->nchan_ism;
    1814             :                 move16();
    1815             :             }
    1816             :             FOR( n = 0; n < num_objects; n++ )
    1817             :             {
    1818             :                 test();
    1819             :                 IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) )
    1820             :                 {
    1821             :                     v_multc_fixed_16( st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], OMASA_TDREND_MATCHING_GAIN_FX, st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available );
    1822             :                 }
    1823             :                 delay_signal32_fx( st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hMasaIsmData->delayBuffer_fx[n], st_ivas->hMasaIsmData->delayBuffer_size );
    1824             :             }
    1825             :         }
    1826             :     }
    1827             :     ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
    1828             :     {
    1829             :         IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
    1830             :         {
    1831             :             ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    1832             :         }
    1833             :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
    1834             :         {
    1835             :             ivas_mc_paramupmix_dec_digest_tc( st_ivas, (UWord8) n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    1836             :         }
    1837             :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
    1838             :         {
    1839             : 
    1840             :             Word16 nchan_transport = st_ivas->nchan_transport;
    1841             :             move16();
    1842             :             Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    1843             :             Word16 nchan_out_cov;
    1844             :             test();
    1845             :             test();
    1846             :             IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    1847             :             {
    1848             :                 nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    1849             :             }
    1850             :             ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
    1851             :             {
    1852             :                 nchan_out_cov = nchan_out_transport;
    1853             :                 move16();
    1854             :             }
    1855             :             ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
    1856             :             {
    1857             :                 nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    1858             :             }
    1859             :             ELSE
    1860             :             {
    1861             :                 nchan_out_cov = nchan_out_transport;
    1862             :                 move16();
    1863             :             }
    1864             : 
    1865             :             scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); // Q(31-1)
    1866             :             st_ivas->hParamMC->proto_matrix_int_e = 1;
    1867             :             move16();
    1868             : 
    1869             :             ivas_param_mc_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, (Word32 **) p_data_f_fx, Q11 );
    1870             : 
    1871             :             scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); // Q(31-1+1)
    1872             : 
    1873             :             Word16 shift;
    1874             :             FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ )
    1875             :             {
    1876             :                 shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ) );
    1877             :                 scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, i_mult( nchan_transport, nchan_transport ) ), shift ); // Q(31-cx_old_e+shift)
    1878             :                 st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], shift );
    1879             :                 move16();
    1880             : 
    1881             :                 shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov );
    1882             :                 scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], i_mult( nchan_out_cov, nchan_out_cov ), shift ); // Q(31-cy_old_e+shift)
    1883             :                 st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], shift );
    1884             :                 move16();
    1885             :             }
    1886             :         }
    1887             :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
    1888             :         {
    1889             :             IF( st_ivas->hSCE[0] )
    1890             :             {
    1891             :                 Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    1892             :                 if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    1893             :                 {
    1894             :                     shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    1895             :                 }
    1896             :                 scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
    1897             :                 st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    1898             :                 move16();
    1899             :             }
    1900             :             ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    1901             :         }
    1902             :     }
    1903             : #else
    1904      318387 :     ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
    1905             :     {
    1906       48710 :         test();
    1907       48710 :         IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && EQ_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_RENDERER ) )
    1908             :         {
    1909       10229 :             ivas_param_mc_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, (Word32 **) p_data_f_fx, Q11 );
    1910             :         }
    1911             :     }
    1912             : #endif
    1913             : 
    1914      413225 :     pop_wmops();
    1915      413225 :     return;
    1916             : }
    1917             : 
    1918             : /*--------------------------------------------------------------------------*
    1919             :  * ivas_dec_render()
    1920             :  *
    1921             :  * Principal IVAS JBM rendering routine
    1922             :  *--------------------------------------------------------------------------*/
    1923      426600 : ivas_error ivas_jbm_dec_render_fx(
    1924             :     Decoder_Struct *st_ivas,        /* i/o: IVAS decoder structure                                      */
    1925             :     const UWord16 nSamplesAsked,    /* i  : number of samples wanted                                    */
    1926             :     UWord16 *nSamplesRendered,      /* o  : number of samples rendered                                  */
    1927             :     UWord16 *nSamplesAvailableNext, /* o  : number of samples still available in the rendering pipeline */
    1928             :     Word16 *data                    /* o  : output synthesis signal                                      Q0*/
    1929             : )
    1930             : {
    1931             :     Word16 n, nchan_out;
    1932             :     Word16 nchan_transport;
    1933             :     Word16 nchan_remapped;
    1934             :     Word32 output_Fs;
    1935             :     AUDIO_CONFIG output_config;
    1936             :     Word16 nSamplesAskedLocal;
    1937             :     ivas_error error;
    1938             :     Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS];
    1939             :     Word32 *p_tc_fx[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS];
    1940             :     Word16 subframe_len, gd_bits, exp, nchan_in, i, j, ch;
    1941      426600 :     const Word16 output_q_factor = Q11;
    1942      426600 :     move16();
    1943             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    1944             :     Word16 nchan_out_syn_output;
    1945             : 
    1946      426600 :     push_wmops( "ivas_dec_render" );
    1947             :     /*----------------------------------------------------------------*
    1948             :      * Initialization of local vars after struct has been set
    1949             :      *----------------------------------------------------------------*/
    1950             : 
    1951      426600 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1952      426600 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
    1953      426600 :     move32();
    1954      426600 :     nchan_out = st_ivas->hDecoderConfig->nchan_out;
    1955      426600 :     move16();
    1956      426600 :     nchan_transport = st_ivas->hTcBuffer->nchan_transport_jbm;
    1957      426600 :     move16();
    1958      426600 :     output_config = st_ivas->hDecoderConfig->output_config;
    1959      426600 :     move32();
    1960      426600 :     nSamplesAskedLocal = add( nSamplesAsked, st_ivas->hTcBuffer->n_samples_discard );
    1961      426600 :     move16();
    1962             : 
    1963     8958600 :     FOR( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
    1964             :     {
    1965     8532000 :         p_output_fx[n] = st_ivas->p_output_fx[n];
    1966             :     }
    1967      426600 :     IF( !st_ivas->hDecoderConfig->Opt_tsm )
    1968             :     {
    1969     1741381 :         FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ )
    1970             :         {
    1971     1347707 :             p_tc_fx[n] = &p_output_fx[n][st_ivas->hTcBuffer->n_samples_rendered];
    1972             :         }
    1973             : 
    1974     6692458 :         FOR( n = 0; n < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; n++ )
    1975             :         {
    1976     6298784 :             st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n];
    1977             :         }
    1978             :     }
    1979             :     ELSE
    1980             :     {
    1981      132852 :         FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ )
    1982             :         {
    1983       99926 :             p_tc_fx[n] = &st_ivas->hTcBuffer->tc_fx[n][st_ivas->hTcBuffer->n_samples_rendered];
    1984             :         }
    1985             :     }
    1986             : 
    1987      426600 :     st_ivas->hTcBuffer->no_channels = st_ivas->hTcBuffer->nchan_buffer_full;
    1988      426600 :     move16();
    1989             :     /*----------------------------------------------------------------*
    1990             :      * Update combined orientation access index
    1991             :      *----------------------------------------------------------------*/
    1992             : 
    1993      426600 :     IF( st_ivas->hCombinedOrientationData != NULL )
    1994             :     {
    1995             :         /* take the discard samples into account here to make sure head rotation stays on the correct 5ms grid */
    1996       69735 :         st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start = sub( st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start, st_ivas->hTcBuffer->n_samples_discard );
    1997       69735 :         move16();
    1998             : 
    1999       69735 :         ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
    2000             :     }
    2001             : 
    2002             :     /*----------------------------------------------------------------*
    2003             :      * Rendering
    2004             :      *----------------------------------------------------------------*/
    2005      426600 :     test();
    2006      426600 :     IF( EQ_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) )
    2007             :     {
    2008           0 :         assert( 0 );
    2009             :     }
    2010      426600 :     ELSE IF( EQ_32( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
    2011             :     {
    2012             :         Word16 slot_size, tmp, e;
    2013             : 
    2014      130226 :         slot_size = st_ivas->hTcBuffer->n_samples_granularity;
    2015      130226 :         move16();
    2016             : 
    2017             :         /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    2018      130226 :         tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e );
    2019      130226 :         tmp = shr( tmp, sub( 15, e ) );
    2020             : 
    2021      130226 :         ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx );
    2022             :     }
    2023      296374 :     ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
    2024             :     {
    2025             :         /* Rendering */
    2026           0 :         IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
    2027             :         {
    2028           0 :             *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
    2029           0 :             move16();
    2030             : 
    2031           0 :             ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx );
    2032             :         }
    2033             :     }
    2034      296374 :     ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
    2035             :     {
    2036             :         /* Rendering */
    2037       71806 :         IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
    2038             :         {
    2039       15136 :             test();
    2040       15136 :             test();
    2041       15136 :             test();
    2042       15136 :             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 ) )
    2043             :             {
    2044        8597 :                 ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output_fx );
    2045             :             }
    2046        6539 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    2047             :             {
    2048        6539 :                 ivas_param_ism_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx );
    2049             : 
    2050        6539 :                 IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    2051             :                 {
    2052             :                     /* Convert CICP19 -> Ambisonics */
    2053        4496 :                     ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
    2054             :                 }
    2055             :             }
    2056             :         }
    2057             :         ELSE /* ISM_MODE_DISC */
    2058             :         {
    2059       56670 :             *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
    2060       56670 :             move16();
    2061             : 
    2062       56670 :             test();
    2063       56670 :             test();
    2064             :             /* Loudspeaker or Ambisonics rendering */
    2065       56670 :             IF( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
    2066             :             {
    2067             :                 /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */
    2068       20804 :                 ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output_fx, *nSamplesRendered );
    2069             :             }
    2070       35866 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
    2071             :             {
    2072        1500 :                 ivas_apply_non_diegetic_panning_fx( p_tc_fx[0], p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered );
    2073             :             }
    2074             : #ifdef DEBUGGING
    2075             :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
    2076             : #else
    2077       34366 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    2078             : #endif
    2079             :             {
    2080             :                 /* Convert to Ambisonics */
    2081       20780 :                 FOR( i = 0; i < st_ivas->nchan_transport; i++ )
    2082             :                 {
    2083      270028 :                     FOR( j = 0; j < HOA3_CHANNELS; j++ )
    2084             :                     {
    2085      254144 :                         st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29
    2086      254144 :                         move32();
    2087      254144 :                         st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29
    2088      254144 :                         move32();
    2089             :                     }
    2090             :                 }
    2091             : 
    2092        4896 :                 ivas_ism2sba_sf_fx( st_ivas->hTcBuffer->tc_fx, p_output_fx, st_ivas->hIsmRendererData, st_ivas->nchan_transport, *nSamplesRendered, st_ivas->hTcBuffer->n_samples_rendered, st_ivas->hIntSetup.ambisonics_order );
    2093             : 
    2094        4896 :                 Word16 sba_num_chans = imult1616( add( st_ivas->hIntSetup.ambisonics_order, 1 ), add( st_ivas->hIntSetup.ambisonics_order, 1 ) );
    2095       65032 :                 FOR( j = 0; j < sba_num_chans; j++ )
    2096             :                 {
    2097       60136 :                     scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); // Q11
    2098             :                 }
    2099             : 
    2100       20780 :                 FOR( i = 0; i < st_ivas->nchan_transport; i++ )
    2101             :                 {
    2102      270028 :                     FOR( j = 0; j < 16; j++ )
    2103             :                     {
    2104      254144 :                         st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30
    2105      254144 :                         move32();
    2106      254144 :                         st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q29 -> Q30
    2107      254144 :                         move32();
    2108             :                     }
    2109             :                 }
    2110             :             }
    2111             : 
    2112             :             /* Binaural rendering */
    2113       56670 :             IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
    2114             :             {
    2115       29470 :                 IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    2116             :                 {
    2117           0 :                     IF( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK )
    2118             :                     {
    2119           0 :                         return error;
    2120             :                     }
    2121             :                 }
    2122             :                 ELSE
    2123             :                 {
    2124       29470 :                     IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
    2125             :                     {
    2126           0 :                         return error;
    2127             :                     }
    2128             :                 }
    2129             :             }
    2130       27200 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
    2131             :             {
    2132       10704 :                 st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
    2133       10704 :                 subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity );
    2134       10704 :                 gd_bits = find_guarded_bits_fx( subframe_len );
    2135       10704 :                 exp = 13;
    2136       10704 :                 move16();
    2137       10704 :                 nchan_in = 12;
    2138       10704 :                 move16();
    2139       10704 :                 nchan_out = 2;
    2140       10704 :                 move16();
    2141       10704 :                 exp = sub( exp, gd_bits );
    2142       10704 :                 *st_ivas->hCrendWrapper->p_io_qfactor = exp;
    2143       10704 :                 move16();
    2144      139152 :                 FOR( i = 0; i < nchan_in; i++ )
    2145             :                 {
    2146      128448 :                     scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11
    2147             :                 }
    2148             : 
    2149       10704 :                 IF( NE_32( ( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs, 0 ) ), IVAS_ERR_OK ) )
    2150             :                 {
    2151           0 :                     return error;
    2152             :                 }
    2153             : 
    2154       32112 :                 FOR( i = 0; i < nchan_out; i++ )
    2155             :                 {
    2156       21408 :                     scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11
    2157             :                 }
    2158             :             }
    2159             :         }
    2160             :     }
    2161      224568 :     ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
    2162             :     {
    2163      146253 :         nchan_remapped = nchan_transport;
    2164      146253 :         move16();
    2165      146253 :         test();
    2166      146253 :         test();
    2167             :         /* Loudspeakers, Ambisonics or Binaural rendering */
    2168      146253 :         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 ) )
    2169             :         {
    2170       46402 :             ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
    2171             :         }
    2172       99851 :         ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
    2173             :         {
    2174       15978 :             IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
    2175             :             {
    2176       15978 :                 ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx );
    2177             :             }
    2178             :         }
    2179             :         ELSE
    2180             :         {
    2181       83873 :             IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
    2182             :             {
    2183           0 :                 return error;
    2184             :             }
    2185             :         }
    2186             :     }
    2187       78315 :     ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
    2188             :     {
    2189        5516 :         nchan_remapped = st_ivas->nchan_transport;
    2190        5516 :         move16();
    2191        5516 :         test();
    2192        5516 :         test();
    2193        5516 :         test();
    2194        5516 :         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 ) )
    2195             :         {
    2196        2698 :             test();
    2197        2698 :             IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) )
    2198             :             {
    2199         122 :                 IF( NE_32( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ), IVAS_ERR_OK ) )
    2200             :                 {
    2201           0 :                     return error;
    2202             :                 }
    2203             :             }
    2204             :             ELSE
    2205             :             {
    2206        2576 :                 ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
    2207             :             }
    2208             :         }
    2209        2818 :         ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
    2210             :         {
    2211        2742 :             ivas_omasa_dirac_rend_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
    2212             :         }
    2213          76 :         ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) )
    2214             :         {
    2215          76 :             ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx );
    2216          76 :             ivas_omasa_rearrange_channels_fx( p_output_fx, st_ivas->nchan_ism, *nSamplesRendered );
    2217             :         }
    2218             :     }
    2219       72799 :     ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    2220             :     {
    2221       31337 :         nchan_remapped = nchan_transport;
    2222       31337 :         move16();
    2223             :         /* Loudspeakers, Ambisonics or Binaural rendering */
    2224       31337 :         IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    2225             :         {
    2226       19050 :             test();
    2227       19050 :             test();
    2228       19050 :             IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
    2229             :             {
    2230             :                 SPAR_DEC_HANDLE hSpar;
    2231        9250 :                 hSpar = st_ivas->hSpar;
    2232        9250 :                 hSpar->hMdDec->Q_mixer_mat = 30;
    2233        9250 :                 move16();
    2234             : 
    2235        9250 :                 IF( NE_32( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
    2236             :                 {
    2237           0 :                     return error;
    2238             :                 }
    2239             :             }
    2240        9800 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) )
    2241             :             {
    2242        1400 :                 *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
    2243        1400 :                 move16();
    2244             : 
    2245        1400 :                 test();
    2246             :                 /* shift SBA channels to avoid overwrite by ISM upmix in 1 object case and non-TSM unified channel memory*/
    2247        1400 :                 IF( EQ_16( st_ivas->nchan_ism, 1 ) && EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 0 ) )
    2248             :                 {
    2249           0 :                     Copy32( p_tc_fx[2], p_output_fx[3], *nSamplesRendered );
    2250           0 :                     Copy32( p_tc_fx[1], p_output_fx[2], *nSamplesRendered );
    2251           0 :                     p_tc_fx[1] = p_output_fx[2];
    2252           0 :                     p_tc_fx[2] = p_output_fx[3];
    2253             :                 }
    2254             : 
    2255             :                 /* render objects */
    2256        1400 :                 ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output_fx, *nSamplesRendered );
    2257             : 
    2258             :                 /* add already rendered SBA part */
    2259             : #ifdef OBJ_EDITING_API
    2260        1400 :                 test();
    2261        1400 :                 IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    2262        1400 :                 {
    2263        1400 :                     Word32 gain = st_ivas->hSbaIsmData->gain_bed_fx;
    2264        1400 :                     test();
    2265             :                     // TODO: Enable gain editing feature (NE_32 ( gain, ONE_IN_Q_gain ) )
    2266        1400 :                     IF( NE_32( gain, ONE_IN_Q31 ) && GT_32( gain, 0 ) )
    2267             :                     {
    2268           0 :                         FOR( n = 0; n < nchan_out; n++ )
    2269             :                         {
    2270           0 :                             FOR( i = 0; i < *nSamplesRendered; i++ )
    2271             :                             {
    2272           0 :                                 Word32 tmp1 = Mpy_32_32( p_tc_fx[n + st_ivas->nchan_ism][i], gain ); // Q11 + Q30 - 32 = Q9
    2273           0 :                                 tmp1 = L_shl( tmp1, 2 );                                             // Q9 --> Q11
    2274           0 :                                 p_output_fx[n][i] = L_add_sat( p_output_fx[n][i], tmp1 );            // Q11
    2275             :                             }
    2276             :                         }
    2277             :                     }
    2278             :                     ELSE
    2279             :                     {
    2280        2800 :                         FOR( n = 0; n < nchan_out; n++ )
    2281             :                         {
    2282        4200 :                             FOR( n = 0; n < nchan_out; n++ )
    2283             :                             {
    2284     2434800 :                                 FOR( i = 0; i < *nSamplesRendered; i++ )
    2285             :                                 {
    2286     2432000 :                                     p_output_fx[n][i] = L_add_sat( p_output_fx[n][i], p_tc_fx[n + st_ivas->nchan_ism][i] ); // Q11
    2287             :                                 }
    2288             :                             }
    2289             :                         }
    2290             :                     }
    2291             :                 }
    2292             :                 ELSE
    2293             : #endif
    2294             :                 {
    2295           0 :                     ivas_osba_stereo_add_channels_fx( p_tc_fx, p_output_fx, ONE_IN_Q11, nchan_out, st_ivas->nchan_ism, *nSamplesRendered );
    2296             :                 }
    2297             :             }
    2298        8400 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    2299             :             {
    2300        6000 :                 IF( NE_32( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
    2301             :                 {
    2302           0 :                     return error;
    2303             :                 }
    2304             :             }
    2305        2400 :             ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/
    2306             :             {
    2307        2400 :                 IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism] ) ), IVAS_ERR_OK ) )
    2308             :                 {
    2309           0 :                     return error;
    2310             :                 }
    2311             : 
    2312        9000 :                 FOR( n = 0; n < st_ivas->nchan_ism; n++ )
    2313             :                 {
    2314        6600 :                     Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered );
    2315             :                 }
    2316             :             }
    2317             :             ELSE
    2318             :             {
    2319           0 :                 IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
    2320             :                 {
    2321           0 :                     return error;
    2322             :                 }
    2323             :             }
    2324             :         }
    2325       12287 :         ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
    2326             :         {
    2327        8188 :             ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
    2328       24564 :             FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
    2329             :             {
    2330       16376 :                 scale_sig32( p_output_fx[n], *nSamplesRendered, 1 );
    2331             :             }
    2332             :         }
    2333             :         ELSE
    2334             :         {
    2335        4099 :             IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
    2336             :             {
    2337           0 :                 return error;
    2338             :             }
    2339             : 
    2340        4099 :             IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
    2341             :             {
    2342       10200 :                 FOR( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- )
    2343             :                 {
    2344        9600 :                     Copy32( p_output_fx[n], p_output_fx[n + st_ivas->nchan_ism], *nSamplesRendered );
    2345             :                 }
    2346        3000 :                 FOR( n = 0; n < st_ivas->nchan_ism; n++ )
    2347             :                 {
    2348        2400 :                     set32_fx( p_output_fx[n], 0, *nSamplesRendered );
    2349             :                 }
    2350             :             }
    2351       43097 :             FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
    2352             :             {
    2353       38998 :                 scale_sig32( p_output_fx[n], *nSamplesRendered, 1 );
    2354             :             }
    2355             :         }
    2356             :     }
    2357       41462 :     ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
    2358             :     {
    2359             : 
    2360      222224 :         FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ )
    2361             :         {
    2362      180762 :             p_tc_fx[n] = &st_ivas->hTcBuffer->tc_fx[n][st_ivas->hTcBuffer->n_samples_rendered];
    2363             :         }
    2364             : 
    2365       41462 :         IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
    2366             :         {
    2367       21493 :             Word16 crendInPlaceRotation = FALSE;
    2368       21493 :             move16();
    2369       21493 :             *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
    2370       21493 :             move16();
    2371             : 
    2372       21493 :             test();
    2373       21493 :             test();
    2374       21493 :             test();
    2375       21493 :             IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) )
    2376             :             {
    2377         150 :                 IF( LT_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) )
    2378             :                 {
    2379         150 :                     crendInPlaceRotation = TRUE;
    2380         150 :                     move16();
    2381             : 
    2382         150 :                     ivas_mc2sba_fx( st_ivas->hTransSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX );
    2383             :                 }
    2384             :             }
    2385             : 
    2386       21493 :             test();
    2387             :             /* Rendering */
    2388       21493 :             IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
    2389             :             {
    2390       13462 :                 st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
    2391       13462 :                 subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity );
    2392       13462 :                 gd_bits = find_guarded_bits_fx( subframe_len );
    2393       13462 :                 exp = 13;
    2394       13462 :                 move16();
    2395       13462 :                 IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ), IVAS_ERR_OK ) )
    2396             :                 {
    2397           0 :                     return error;
    2398             :                 }
    2399       13462 :                 IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) )
    2400             :                 {
    2401           0 :                     return error;
    2402             :                 }
    2403       13462 :                 exp = sub( exp, gd_bits );
    2404       13462 :                 *st_ivas->hCrendWrapper->p_io_qfactor = exp;
    2405       13462 :                 move16();
    2406             : 
    2407      105034 :                 FOR( i = 0; i < nchan_in; i++ )
    2408             :                 {
    2409       91572 :                     scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q = *st_ivas->hCrendWrapper->p_io_qfactor
    2410       91572 :                     IF( st_ivas->hDecoderConfig->Opt_tsm )
    2411             :                     {
    2412           0 :                         scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q = *st_ivas->hCrendWrapper->p_io_qfactor
    2413             :                     }
    2414             :                 }
    2415             : 
    2416       13462 :                 IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    2417             :                 {
    2418           0 :                     IF( ( error = ivas_rend_crendProcessSubframesSplitBin( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
    2419             :                                                                            &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK )
    2420             :                     {
    2421           0 :                         return error;
    2422             :                     }
    2423             :                 }
    2424             :                 ELSE
    2425             :                 {
    2426       13462 :                     IF( NE_32( ( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
    2427             :                                                                             &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs, 0 ) ),
    2428             :                                IVAS_ERR_OK ) )
    2429             :                     {
    2430           0 :                         return error;
    2431             :                     }
    2432             : 
    2433             :                     // Todo main-pc update: This might be needed also in the split rendering path
    2434       13462 :                     IF( st_ivas->hDecoderConfig->Opt_tsm )
    2435             :                     {
    2436           0 :                         IF( NE_16( exp, *st_ivas->hCrendWrapper->p_io_qfactor ) )
    2437             :                         {
    2438           0 :                             FOR( i = 0; i < nchan_in; i++ )
    2439             :                             {
    2440           0 :                                 scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( *st_ivas->hCrendWrapper->p_io_qfactor, exp ) );
    2441             :                             }
    2442             :                         }
    2443             :                     }
    2444             : 
    2445       13462 :                     ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx );
    2446             :                 }
    2447             : 
    2448      105034 :                 FOR( i = 0; i < nchan_in; i++ )
    2449             :                 {
    2450       91572 :                     scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11
    2451       91572 :                     IF( st_ivas->hDecoderConfig->Opt_tsm )
    2452             :                     {
    2453           0 :                         scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11
    2454             :                     }
    2455             :                 }
    2456             :             }
    2457        8031 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
    2458             :             {
    2459        4397 :                 *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
    2460        4397 :                 move16();
    2461             : 
    2462        4397 :                 ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx );
    2463             :             }
    2464        3634 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    2465             :             {
    2466         490 :                 ivas_mc2sba_fx( st_ivas->hIntSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
    2467             :             }
    2468        3144 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
    2469             :             {
    2470        3144 :                 IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    2471             :                 {
    2472           0 :                     IF( NE_32( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
    2473             :                     {
    2474           0 :                         return error;
    2475             :                     }
    2476             :                 }
    2477             :                 else
    2478             :                 {
    2479        3144 :                     IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
    2480             :                     {
    2481           0 :                         return error;
    2482             :                     }
    2483             : 
    2484        3144 :                     ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx );
    2485             :                 }
    2486             :             }
    2487             :         }
    2488       19969 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
    2489             :         {
    2490         780 :             ivas_mc_paramupmix_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc_fx, p_output_fx );
    2491             : 
    2492         780 :             test();
    2493         780 :             test();
    2494             :             /* Rendering */
    2495         780 :             IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && !st_ivas->hDecoderConfig->Opt_Headrotation )
    2496             :             {
    2497             :                 /* handled in CLDFB domain already */
    2498         160 :                 IF( NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    2499             :                 {
    2500         160 :                     ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx );
    2501             :                 }
    2502             :             }
    2503         620 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
    2504             :             {
    2505           0 :                 ivas_ls_setup_conversion_fx( st_ivas, MC_PARAMUPMIX_MAX_INPUT_CHANS, *nSamplesRendered, p_output_fx, p_output_fx );
    2506             :             }
    2507         620 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    2508             :             {
    2509          10 :                 ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
    2510             :             }
    2511             :         }
    2512       19189 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
    2513             :         {
    2514             :             Word16 channel_active_fx[MAX_OUTPUT_CHANNELS];
    2515             :             Word16 nchan_out_cov;
    2516       10260 :             Word16 nchan_out_cldfb = 0;
    2517       10260 :             move16();
    2518             : 
    2519       10260 :             set16_fx( channel_active_fx, 0, MAX_CICP_CHANNELS );
    2520       10260 :             Word16 nchan_transport_tmp = st_ivas->nchan_transport;
    2521       10260 :             move16();
    2522       10260 :             output_Fs = st_ivas->hDecoderConfig->output_Fs;
    2523       10260 :             move32();
    2524       10260 :             Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    2525       10260 :             test();
    2526       10260 :             test();
    2527       10260 :             IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    2528             :             {
    2529        8270 :                 nchan_out_cldfb = BINAURAL_CHANNELS;
    2530        8270 :                 move16();
    2531        8270 :                 set16_fx( channel_active_fx, 1, BINAURAL_CHANNELS );
    2532        8270 :                 nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    2533             :             }
    2534        1990 :             ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
    2535             :             {
    2536         340 :                 nchan_out_cov = nchan_out_transport;
    2537         340 :                 move16();
    2538         340 :                 nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    2539             :             }
    2540        1650 :             ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
    2541             :             {
    2542         150 :                 nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    2543         150 :                 nchan_out_cldfb = nchan_out_cov;
    2544         150 :                 move16();
    2545         150 :                 set16_fx( channel_active_fx, 1, nchan_out_cov );
    2546             :             }
    2547             :             ELSE
    2548             :             {
    2549        1500 :                 nchan_out_cov = nchan_out_transport;
    2550        1500 :                 move16();
    2551        1500 :                 nchan_out_cldfb = nchan_out_transport;
    2552        1500 :                 move16();
    2553        1500 :                 set16_fx( channel_active_fx, 1, nchan_out_cov );
    2554             :             }
    2555       10260 :             IF( st_ivas->hParamMC->max_band_decorr > 0 )
    2556             :             {
    2557             :                 Word16 tmp;
    2558       10260 :                 tmp = L_norm_arr( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len );
    2559       10260 :                 scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); // Q(st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer+ tmp)
    2560       10260 :                 st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp );
    2561       10260 :                 move16();
    2562             :             }
    2563             :             /* CLDFB synthesis */
    2564       41260 :             FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
    2565             :             {
    2566       31000 :                 IF( st_ivas->cldfbSynDec[ch] )
    2567             :                 {
    2568       31000 :                     scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, ( Q5 - Q11 ) ); // Q5
    2569       31000 :                     st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5;
    2570       31000 :                     move16();
    2571             :                 }
    2572             :             }
    2573             :             Word16 tempp;
    2574      143496 :             FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ )
    2575             :             {
    2576      133236 :                 tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len );
    2577      133236 :                 scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len, tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp))
    2578      133236 :                 st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], tempp );
    2579      133236 :                 move16();
    2580             : 
    2581      133236 :                 IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
    2582             :                 {
    2583      107217 :                     tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len );
    2584      107217 :                     scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len, tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp))
    2585      107217 :                     st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], tempp );
    2586      107217 :                     move16();
    2587             :                 }
    2588             :             }
    2589             : 
    2590       10260 :             ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx );
    2591             : 
    2592       41260 :             FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
    2593             :             {
    2594       31000 :                 IF( st_ivas->cldfbSynDec[ch] )
    2595             :                 {
    2596       31000 :                     scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q11
    2597       31000 :                     st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
    2598       31000 :                     move16();
    2599             :                 }
    2600             :             }
    2601       10260 :             IF( EQ_16( st_ivas->hParamMC->slots_rendered, st_ivas->hParamMC->num_slots ) )
    2602             :             {
    2603      145166 :                 FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ )
    2604             :                 {
    2605      134937 :                     IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
    2606             :                     {
    2607      106849 :                         Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], imult1616( nchan_transport_tmp, nchan_out_cov ) );
    2608      106849 :                         st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx];
    2609      106849 :                         move16();
    2610             :                     }
    2611      134937 :                     Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nchan_transport_tmp, nchan_out_cov ) );
    2612      134937 :                     st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx];
    2613      134937 :                     move16();
    2614             :                 }
    2615             :             }
    2616             :         }
    2617        8929 :         ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
    2618             :         {
    2619        8929 :             Word16 offset = imult1616( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->slot_size );
    2620        8929 :             nchan_remapped = st_ivas->nchan_transport;
    2621        8929 :             move16();
    2622             : 
    2623        8929 :             test();
    2624        8929 :             test();
    2625        8929 :             test();
    2626        8929 :             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 ) )
    2627             :             {
    2628        7049 :                 ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
    2629             :             }
    2630        1880 :             ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) /* rendering to CICPxx and Ambisonics */
    2631             :             {
    2632        1880 :                 ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx );
    2633             : 
    2634        1880 :                 test();
    2635        1880 :                 test();
    2636        1880 :                 test();
    2637        1880 :                 IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    2638             :                 {
    2639             :                     /* we still need to copy the separate channel if available  */
    2640         290 :                     IF( st_ivas->hOutSetup.separateChannelEnabled )
    2641             :                     {
    2642          25 :                         Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
    2643             :                     }
    2644             : 
    2645         290 :                     ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
    2646             :                 }
    2647        1590 :                 ELSE IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ) )
    2648             :                 {
    2649           0 :                     FOR( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < ( st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); n++ )
    2650             :                     {
    2651           0 :                         set32_fx( p_output_fx[n], 0, *nSamplesRendered );
    2652             :                     }
    2653             :                 }
    2654             :             }
    2655             : 
    2656             :             /* copy discrete C and TD LFE from internal TC to output  */
    2657        8929 :             IF( st_ivas->hOutSetup.separateChannelEnabled )
    2658             :             {
    2659         245 :                 test();
    2660         245 :                 test();
    2661         245 :                 test();
    2662         245 :                 test();
    2663         245 :                 test();
    2664         245 :                 test();
    2665         245 :                 test();
    2666         245 :                 IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
    2667             :                     EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
    2668             :                     EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) )
    2669             :                 {
    2670         150 :                     Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL] + offset, p_output_fx[LFE_CHANNEL], *nSamplesRendered );
    2671         150 :                     Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
    2672             :                 }
    2673          95 :                 ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 )
    2674             :                 {
    2675             :                     /* Delay the separated channel to sync with the DirAC rendering */
    2676           0 :                     Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
    2677             :                 }
    2678             :             }
    2679             :         }
    2680             :     }
    2681             : 
    2682             :     /*----------------------------------------------------------------*
    2683             :      * Write IVAS output channels
    2684             :      *   - compensation for saturation
    2685             :      *   - float to integer conversion
    2686             :      *----------------------------------------------------------------*/
    2687             : 
    2688      426600 :     st_ivas->hTcBuffer->n_samples_available = sub( st_ivas->hTcBuffer->n_samples_available, *nSamplesRendered );
    2689      426600 :     st_ivas->hTcBuffer->n_samples_rendered = add( st_ivas->hTcBuffer->n_samples_rendered, *nSamplesRendered );
    2690      426600 :     move16();
    2691      426600 :     move16();
    2692             : 
    2693             :     /* update global combined orientation start index */
    2694      426600 :     ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
    2695             : 
    2696      426600 :     IF( st_ivas->hTcBuffer->n_samples_discard > 0 )
    2697             :     {
    2698         899 :         FOR( n = 0; n < s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); n++ )
    2699             :         {
    2700         826 :             p_output_fx[n] += st_ivas->hTcBuffer->n_samples_discard;
    2701             :         }
    2702          73 :         *nSamplesRendered = sub( (Word16) *nSamplesRendered, st_ivas->hTcBuffer->n_samples_discard );
    2703          73 :         move16();
    2704          73 :         st_ivas->hTcBuffer->n_samples_discard = 0;
    2705          73 :         move16();
    2706             :     }
    2707             : 
    2708      426600 :     IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    2709             :     {
    2710           0 :         FOR( i = 0; i < st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS; i++ )
    2711             :         {
    2712           0 :             Copy32( p_output_fx[i], st_ivas->hSplitBinRend->hMultiBinCldfbData->output_fx[i], *nSamplesRendered );
    2713             :         }
    2714             :     }
    2715      426600 :     nchan_out_syn_output = nchan_out;
    2716      426600 :     move16();
    2717             : 
    2718      426600 :     IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 )
    2719             :     {
    2720      426600 :         IF( NE_32( st_ivas->ivas_format, MONO_FORMAT ) )
    2721             :         {
    2722             : #ifndef DISABLE_LIMITER
    2723      423500 :             ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, nchan_out, *nSamplesRendered, st_ivas->BER_detect, output_q_factor );
    2724             : #endif
    2725             :         }
    2726             :     }
    2727             : 
    2728      426600 :     ivas_syn_output_fx( p_output_fx, output_q_factor, *nSamplesRendered, nchan_out_syn_output, data );
    2729             : 
    2730      426600 :     *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available;
    2731      426600 :     move16();
    2732             : 
    2733      426600 :     pop_wmops();
    2734      426600 :     return IVAS_ERR_OK;
    2735             : }
    2736             : 
    2737             : /*--------------------------------------------------------------------------*
    2738             :  * ivas_jbm_dec_flush_renderer()
    2739             :  *
    2740             :  * Flush samples if renderer granularity changes on a bitrate change
    2741             :  *--------------------------------------------------------------------------*/
    2742             : 
    2743         353 : ivas_error ivas_jbm_dec_flush_renderer_fx(
    2744             :     Decoder_Struct *st_ivas,                     /* i/o: IVAS decoder structure    */
    2745             :     const Word16 tc_granularity_new,             /* i  : new renderer granularity  */
    2746             :     const RENDERER_TYPE renderer_type_old,       /* i  : old renderer type         */
    2747             :     const AUDIO_CONFIG intern_config_old,        /* i  : old internal config       */
    2748             :     const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i  : old internal output setup */
    2749             :     const MC_MODE mc_mode_old,                   /* i  : old MC mode               */
    2750             :     const ISM_MODE ism_mode_old,                 /* i  : old ISM mode              */
    2751             :     UWord16 *nSamplesRendered,                   /* o  : number of samples flushed */
    2752             :     Word16 *data                                 /* o  : output synthesis signal  Q0*/
    2753             : )
    2754             : {
    2755             :     ivas_error error;
    2756             :     Word16 n_samples_still_available;
    2757             :     Word16 n_slots_still_available;
    2758             :     Word16 n_samples_to_render;
    2759             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    2760             :     Word32 *p_output_fx[MAX_CICP_CHANNELS + MAX_NUM_OBJECTS];
    2761             :     Word16 nchan_in, nchan_out;
    2762             : 
    2763         353 :     IF( !st_ivas->hDecoderConfig->Opt_tsm )
    2764             :     {
    2765         258 :         return IVAS_ERR_OK;
    2766             :     }
    2767             : 
    2768          95 :     *nSamplesRendered = 0;
    2769          95 :     move16();
    2770          95 :     hTcBuffer = st_ivas->hTcBuffer;
    2771             : 
    2772             :     /* get number of possible slots in new granularity */
    2773          95 :     n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered );
    2774             : 
    2775             :     // n_slots_still_available = n_samples_still_available / tc_granularity_new;
    2776             :     Word16 tmp, tmp_e;
    2777          95 :     tmp = BASOP_Util_Divide1616_Scale( n_samples_still_available, tc_granularity_new, &tmp_e );
    2778          95 :     n_slots_still_available = shr( tmp, sub( 15, tmp_e ) );
    2779          95 :     *nSamplesRendered = imult1616( n_slots_still_available, tc_granularity_new );
    2780          95 :     n_samples_to_render = *nSamplesRendered;
    2781          95 :     move16();
    2782          95 :     move16();
    2783          95 :     n_samples_still_available = sub( n_samples_still_available, n_samples_to_render );
    2784          95 :     assert( n_samples_still_available < tc_granularity_new );
    2785             : 
    2786             :     /* update combined orientation access index */
    2787          95 :     ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
    2788             : 
    2789          95 :     IF( n_slots_still_available )
    2790             :     {
    2791             :         Word16 ch_idx;
    2792             : 
    2793             :         /* render what is still there with zero padding */
    2794         314 :         FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
    2795             :         {
    2796             :             /* move it at the beginning of the TC buffer with zero padding */
    2797         242 :             Copy32( hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch_idx], n_samples_to_render );
    2798         242 :             set_zero_fx( hTcBuffer->tc_fx[ch_idx] + n_samples_to_render, hTcBuffer->n_samples_granularity - n_samples_to_render );
    2799         242 :             Copy32( hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered + n_samples_to_render, hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_granularity, n_samples_still_available );
    2800             :         }
    2801             :         /* simple change of the slot info */
    2802          72 :         hTcBuffer->num_slots = 1;
    2803          72 :         hTcBuffer->nb_subframes = 1;
    2804          72 :         hTcBuffer->subframes_rendered = 0;
    2805          72 :         hTcBuffer->slots_rendered = 0;
    2806          72 :         hTcBuffer->subframe_nbslots[0] = 1;
    2807          72 :         hTcBuffer->n_samples_buffered = add( hTcBuffer->n_samples_granularity, n_samples_still_available );
    2808          72 :         hTcBuffer->n_samples_available = 0;
    2809          72 :         hTcBuffer->n_samples_flushed = n_samples_to_render;
    2810          72 :         hTcBuffer->n_samples_rendered = 0;
    2811          72 :         move16();
    2812          72 :         move16();
    2813          72 :         move16();
    2814          72 :         move16();
    2815          72 :         move16();
    2816          72 :         move16();
    2817          72 :         move16();
    2818          72 :         move16();
    2819          72 :         move16();
    2820             : 
    2821        1512 :         FOR( ch_idx = 0; ch_idx < ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ); ch_idx++ )
    2822             :         {
    2823        1440 :             p_output_fx[ch_idx] = st_ivas->p_output_fx[ch_idx];
    2824             :         }
    2825             : 
    2826          72 :         test();
    2827          72 :         IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
    2828             :         {
    2829          64 :             IF( EQ_16( ism_mode_old, ISM_MODE_DISC ) )
    2830             :             {
    2831             :                 /* Binaural rendering */
    2832          64 :                 IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_OBJECTS_TD ) )
    2833             :                 {
    2834           0 :                     IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) )
    2835             :                     {
    2836           0 :                         return error;
    2837             :                     }
    2838             :                 }
    2839          64 :                 ELSE IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
    2840             :                 {
    2841             :                     /*TODO :To be tested : no stream entering---------------------------------------*/
    2842             :                     /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */
    2843          64 :                     set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); // 32767=1.0f in Q15
    2844             : 
    2845          64 :                     ivas_ism_render_sf_fx( st_ivas, renderer_type_old, p_output_fx, hTcBuffer->n_samples_granularity );
    2846             : 
    2847          64 :                     st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
    2848          64 :                     *st_ivas->hCrendWrapper->p_io_qfactor = 11;
    2849             : 
    2850          64 :                     move16();
    2851          64 :                     IF( NE_32( ( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL,
    2852             :                                                                             NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs, 0 ) ),
    2853             :                                IVAS_ERR_OK ) )
    2854             :                     {
    2855           0 :                         return error;
    2856             :                     }
    2857             :                 }
    2858             :             }
    2859             :             ELSE
    2860             :             {
    2861           0 :                 return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong ISM_MODE in VoIP renderer flushing!" );
    2862             :             }
    2863             :         }
    2864           8 :         ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
    2865             :         {
    2866           1 :             IF( EQ_16( mc_mode_old, MC_MODE_MCT ) )
    2867             :             {
    2868           1 :                 Word16 crendInPlaceRotation = FALSE;
    2869             : 
    2870           1 :                 test();
    2871           1 :                 test();
    2872           1 :                 test();
    2873           1 :                 IF( NE_16( st_ivas->transport_config, intern_config_old ) && ( EQ_16( intern_config_old, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( intern_config_old, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( intern_config_old, IVAS_AUDIO_CONFIG_HOA3 ) ) )
    2874             :                 {
    2875           0 :                     IF( GT_16( sub( add( hIntSetupOld->nchan_out_woLFE, hIntSetupOld->num_lfe ), add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ) ), 0 ) )
    2876             :                     {
    2877           0 :                         crendInPlaceRotation = TRUE;
    2878           0 :                         move16();
    2879           0 :                         ivas_mc2sba_fx( st_ivas->hTransSetup, hTcBuffer->tc_fx, p_output_fx, hTcBuffer->n_samples_granularity, hIntSetupOld->ambisonics_order, GAIN_LFE_FX );
    2880             :                     }
    2881             :                 }
    2882             : 
    2883           1 :                 test();
    2884           1 :                 IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
    2885             :                 {
    2886             :                     /*TODO :To be tested : no stream entering*/
    2887           0 :                     st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
    2888           0 :                     IF( NE_32( ( error = getAudioConfigNumChannels( intern_config_old, &nchan_in ) ), IVAS_ERR_OK ) )
    2889             :                     {
    2890           0 :                         return error;
    2891             :                     }
    2892           0 :                     IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) )
    2893             :                     {
    2894           0 :                         return error;
    2895             :                     }
    2896           0 :                     *st_ivas->hCrendWrapper->p_io_qfactor = 11;
    2897           0 :                     move16();
    2898             : 
    2899           0 :                     IF( NE_32( error = ivas_rend_crendProcessSubframe_fx( st_ivas->hCrendWrapper, intern_config_old, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
    2900             :                                                                           hIntSetupOld, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : st_ivas->hTcBuffer->tc_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs, 0 ),
    2901             :                                IVAS_ERR_OK ) )
    2902             :                     {
    2903           0 :                         return error;
    2904             :                     }
    2905             : 
    2906           0 :                     ivas_binaural_add_LFE_fx( st_ivas, hTcBuffer->n_samples_granularity, st_ivas->hTcBuffer->tc_fx, p_output_fx );
    2907             :                 }
    2908           1 :                 ELSE IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_OBJECTS_TD ) )
    2909             :                 {
    2910           1 :                     IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) )
    2911             :                     {
    2912           0 :                         return error;
    2913             :                     }
    2914           1 :                     ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, st_ivas->hTcBuffer->tc_fx, p_output_fx );
    2915             :                 }
    2916             :                 ELSE
    2917             :                 {
    2918           0 :                     return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong renderer in MCT VoIP renderer flushing!" );
    2919             :                 }
    2920             :             }
    2921             :             ELSE
    2922             :             {
    2923           0 :                 return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong MC_MODE in VoIP renderer flushing!" );
    2924             :             }
    2925             :         }
    2926           7 :         ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
    2927             :         {
    2928           7 :             IF( EQ_16( ism_mode_old, ISM_MASA_MODE_DISC ) )
    2929             :             {
    2930             :                 Word32 *tc_local_fx[MAX_NUM_OBJECTS];
    2931             : #ifdef NONBE_1302_FIX_OMASA_JBM_FLUSH
    2932             :                 Word16 last_dirac_md_idx;
    2933             :                 UWord16 nSamplesAvailableNext;
    2934             :                 ISM_MODE ism_mode_orig;
    2935             :                 RENDERER_TYPE renderer_type_orig;
    2936             :                 Word32 ivas_total_brate;
    2937             : #endif
    2938             : 
    2939             :                 /* copy from ISM delay buffer to the correct place in TCs */
    2940           7 :                 move16();
    2941          23 :                 FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
    2942             :                 {
    2943          16 :                     tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered];
    2944          16 :                     Copy32( st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hMasaIsmData->delayBuffer_size ); /*Q11*/
    2945             :                 }
    2946             : 
    2947             : #ifdef NONBE_1302_FIX_OMASA_JBM_FLUSH
    2948             :                 /* to render flushed samples, use configuration from the last received frame */
    2949           7 :                 ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
    2950           7 :                 renderer_type_orig = st_ivas->renderer_type;
    2951           7 :                 ism_mode_orig = st_ivas->ism_mode;
    2952           7 :                 st_ivas->ism_mode = ism_mode_old;
    2953           7 :                 st_ivas->renderer_type = renderer_type_old;
    2954           7 :                 st_ivas->hDecoderConfig->ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate;
    2955           7 :                 last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1];
    2956             : 
    2957             :                 /* transfer adapted sf info from hTcBuffer to DirAC */
    2958           7 :                 st_ivas->hSpatParamRendCom->nb_subframes = 1;
    2959           7 :                 st_ivas->hSpatParamRendCom->subframes_rendered = 0;
    2960           7 :                 st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
    2961           7 :                 st_ivas->hSpatParamRendCom->slots_rendered = 0;
    2962           7 :                 st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
    2963           7 :                 set16_fx( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available );
    2964             : 
    2965           7 :                 IF( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, (UWord16) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, CPE_CHANNELS, p_output_fx ) ) != IVAS_ERR_OK )
    2966             :                 {
    2967           0 :                     return error;
    2968             :                 }
    2969             : 
    2970             :                 /* restore original configuration */
    2971           7 :                 st_ivas->ism_mode = ism_mode_orig;
    2972           7 :                 st_ivas->renderer_type = renderer_type_orig;
    2973           7 :                 st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate;
    2974             : #else
    2975             :                 IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) )
    2976             :                 {
    2977             :                     return error;
    2978             :                 }
    2979             : #endif
    2980             :             }
    2981             :         }
    2982           0 :         ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    2983             :         {
    2984             :             Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS];
    2985             :             Word16 last_spar_md_idx;
    2986             :             Word16 last_dirac_md_idx;
    2987             :             UWord16 nSamplesAvailableNext;
    2988             : 
    2989             :             /* to render flushed samples, use configuration from the last received frame */
    2990             : 
    2991           0 :             last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1];
    2992           0 :             last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1];
    2993           0 :             move16();
    2994           0 :             move16();
    2995             : 
    2996             :             /* copy from ISM delay buffer to the correct place in TCs */
    2997           0 :             FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
    2998             :             {
    2999           0 :                 tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered];
    3000           0 :                 Copy32( st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hSbaIsmData->delayBuffer_size );
    3001             :             }
    3002             : 
    3003             :             /* transfer adapted sf info from hTcBuffer to SPAR and DirAC */
    3004           0 :             st_ivas->hSpar->nb_subframes = 1;
    3005           0 :             st_ivas->hSpar->subframes_rendered = 0;
    3006           0 :             st_ivas->hSpar->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
    3007           0 :             st_ivas->hSpar->slots_rendered = 0;
    3008           0 :             st_ivas->hSpar->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
    3009           0 :             st_ivas->hSpatParamRendCom->nb_subframes = 1;
    3010           0 :             st_ivas->hSpatParamRendCom->subframes_rendered = 0;
    3011           0 :             st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
    3012           0 :             st_ivas->hSpatParamRendCom->slots_rendered = 0;
    3013           0 :             st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
    3014           0 :             move16();
    3015           0 :             move16();
    3016           0 :             move16();
    3017           0 :             move16();
    3018           0 :             move16();
    3019           0 :             move16();
    3020           0 :             move16();
    3021           0 :             move16();
    3022           0 :             move16();
    3023           0 :             move16();
    3024             : 
    3025             :             /* also adapt md maps, just use the last index */
    3026           0 :             set16_fx( st_ivas->hSpar->render_to_md_map, last_spar_md_idx, n_slots_still_available );
    3027           0 :             set16_fx( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available );
    3028             : 
    3029             :             /* render the last subframe */
    3030           0 :             IF( NE_32( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, (UWord16) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
    3031             :             {
    3032           0 :                 return error;
    3033             :             }
    3034             : 
    3035             :             /* restore original configuration */
    3036             :         }
    3037             :         ELSE
    3038             :         {
    3039           0 :             return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong IVAS format in VoIP renderer flushing!" );
    3040             :         }
    3041          72 :         hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity;
    3042             :     }
    3043             : 
    3044             :     /* update global combined orientation start index */
    3045          95 :     ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
    3046             : 
    3047          95 :     *nSamplesRendered = n_samples_to_render;
    3048          95 :     move16();
    3049             : 
    3050             :     /* Only write out the valid data*/
    3051          95 :     IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 )
    3052             :     {
    3053          95 :         IF( NE_16( st_ivas->ivas_format, MONO_FORMAT ) )
    3054             :         {
    3055             : #ifndef DISABLE_LIMITER
    3056          95 :             Word16 ch_idx, exp = 11;
    3057          95 :             move16();
    3058        1995 :             FOR( ch_idx = 0; ch_idx < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
    3059             :             {
    3060        1900 :                 p_output_fx[ch_idx] = st_ivas->p_output_fx[ch_idx];
    3061             :             }
    3062          95 :             ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, exp );
    3063             : #endif
    3064             :         }
    3065             :     }
    3066             : 
    3067          95 :     ivas_syn_output_fx( p_output_fx, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, data );
    3068          95 :     return IVAS_ERR_OK;
    3069             : }
    3070             : 
    3071             : 
    3072             : /*--------------------------------------------------------------------------*
    3073             :  * ivas_jbm_dec_set_discard_samples()
    3074             :  *
    3075             :  * Set number of samples to discard in the first subframe if the renderer granularity changes on a bitrate change
    3076             :  *--------------------------------------------------------------------------*/
    3077             : 
    3078         366 : ivas_error ivas_jbm_dec_set_discard_samples(
    3079             :     Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */
    3080             : )
    3081             : {
    3082             :     Word16 nMaxSlotsPerSubframe, nSlotsInFirstSubframe;
    3083             :     Word16 temp, temp_e;
    3084             :     /* render first frame with front zero padding and discarding those samples */
    3085             :     // nMaxSlotsPerSubframe = (Word16)(st_ivas->hDecoderConfig->output_Fs / (FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES)) / st_ivas->hTcBuffer->n_samples_granularity;
    3086         366 :     temp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), &temp_e );
    3087         366 :     temp = shr( temp, sub( 15, temp_e ) );
    3088         366 :     nMaxSlotsPerSubframe = BASOP_Util_Divide1616_Scale( temp, st_ivas->hTcBuffer->n_samples_granularity, &temp_e );
    3089         366 :     nMaxSlotsPerSubframe = shr( nMaxSlotsPerSubframe, sub( 15, temp_e ) ); // Q0
    3090         366 :     nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] );
    3091         366 :     IF( nSlotsInFirstSubframe > 0 )
    3092             :     {
    3093          73 :         st_ivas->hTcBuffer->n_samples_discard = imult1616( sub( nMaxSlotsPerSubframe, nSlotsInFirstSubframe ), st_ivas->hTcBuffer->n_samples_granularity );
    3094             :         /* set last subframes number to max to ensure correct continuation */
    3095          73 :         st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nMaxSlotsPerSubframe;
    3096          73 :         move16();
    3097          73 :         move16();
    3098             :     }
    3099             : 
    3100         366 :     return IVAS_ERR_OK;
    3101             : }
    3102             : 
    3103             : 
    3104             : /*--------------------------------------------------------------------------*
    3105             :  * ivas_jbm_dec_get_adapted_linear_interpolator()
    3106             :  *
    3107             :  * Get an interpolator that is adapted to time scale modified IVAS frame
    3108             :  *--------------------------------------------------------------------------*/
    3109       28133 : void ivas_jbm_dec_get_adapted_linear_interpolator_fx(
    3110             :     const Word16 default_interp_length, /* i  : default length of the (full-frame) interpolator */
    3111             :     const Word16 interp_length,         /* i  : length of the interpolator to be created        */
    3112             :     Word16 *interpolator_fx             /* o  : the interpolator                               Q15 */
    3113             : )
    3114             : {
    3115             :     Word16 jbm_segment_len, idx;
    3116             :     Word16 dec_fx;
    3117             :     Word16 dec_e;
    3118             : 
    3119       28133 :     jbm_segment_len = shr( default_interp_length, 1 );
    3120       28133 :     dec_fx = divide1616( 1, default_interp_length ); /*32767 / default_interp_length*/
    3121             : 
    3122       28133 :     interpolator_fx[interp_length - 1] = 32767; /* (1.0f in Q15) -1 */
    3123       28133 :     move16();
    3124       28133 :     interpolator_fx[interp_length - 2] = add( sub( 32767, dec_fx ), 1 ); // Use 32768 to maintain precision
    3125       28133 :     move16();
    3126     1541718 :     FOR( idx = interp_length - 3; idx >= jbm_segment_len; idx-- )
    3127             :     {
    3128     1513585 :         interpolator_fx[idx] = s_max( 0, sub( interpolator_fx[idx + 1], dec_fx ) );
    3129     1513585 :         move16();
    3130             :     }
    3131             : 
    3132       28133 :     IF( interpolator_fx[idx + 1] > 0 )
    3133             :     {
    3134       28133 :         dec_fx = BASOP_Util_Divide1616_Scale( interpolator_fx[idx + 1], add( jbm_segment_len, 1 ), &dec_e );
    3135       28133 :         dec_fx = shr( dec_fx, sub( 15, dec_e ) ); // Q0
    3136     1597821 :         FOR( ; idx >= 0; idx-- )
    3137             :         {
    3138     1569688 :             interpolator_fx[idx] = sub( interpolator_fx[idx + 1], dec_fx );
    3139     1569688 :             move16();
    3140             :         }
    3141             :     }
    3142             :     ELSE
    3143             :     {
    3144           0 :         set16_fx( interpolator_fx, 0, idx + 1 );
    3145             :     }
    3146             : 
    3147       28133 :     return;
    3148             : }
    3149             : 
    3150             : /*--------------------------------------------------------------------------*
    3151             :  * ivas_jbm_dec_get_adapted_subframes()
    3152             :  *
    3153             :  * Get an interpolator that is adapted to time scale modified IVAS frame
    3154             :  *--------------------------------------------------------------------------*/
    3155             : 
    3156      305483 : void ivas_jbm_dec_get_adapted_subframes(
    3157             :     const Word16 nCldfbTs,    /* i  : number of time slots in the current frame */
    3158             :     Word16 *subframe_nbslots, /* i/o: subframe grid                             */
    3159             :     Word16 *nb_subframes      /* i/o: number of subframes in the frame          */
    3160             : )
    3161             : {
    3162             :     UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe;
    3163      305483 :     UWord16 nCldfbSlotsLocal = nCldfbTs;
    3164      305483 :     move16();
    3165             :     Word16 temp, temp_e;
    3166             :     /* get last subframe size from previous frame, determine how many slots have to be processed
    3167             :                in the first subframe (i.e. potential leftover of a 5ms subframe) */
    3168      305483 :     nSlotsInFirstSubframe = ( sub( PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, subframe_nbslots[*nb_subframes - 1] ) );
    3169      305483 :     *nb_subframes = 0;
    3170      305483 :     move16();
    3171      305483 :     IF( nSlotsInFirstSubframe > 0 )
    3172             :     {
    3173        9932 :         *nb_subframes = 1;
    3174        9932 :         move16();
    3175        9932 :         nCldfbSlotsLocal = sub( nCldfbSlotsLocal, nSlotsInFirstSubframe );
    3176             :     }
    3177             : 
    3178      305483 :     temp = BASOP_Util_Divide3232_Scale( L_add( nCldfbSlotsLocal, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1 ), PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, &temp_e );
    3179      305483 :     *nb_subframes = add( *nb_subframes, shr( temp, sub( 15, temp_e ) ) ); // Q0
    3180      305483 :     move16();
    3181      305483 :     nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME;
    3182      305483 :     move16();
    3183             : 
    3184      305483 :     set16_fx( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
    3185      305483 :     set16_fx( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes );
    3186             : 
    3187      305483 :     IF( nSlotsInFirstSubframe > 0 )
    3188             :     {
    3189        9932 :         subframe_nbslots[0] = nSlotsInFirstSubframe;
    3190        9932 :         move16();
    3191             :     }
    3192             : 
    3193      305483 :     IF( nSlotsInLastSubframe > 0 )
    3194             :     {
    3195        9947 :         subframe_nbslots[*nb_subframes - 1] = nSlotsInLastSubframe;
    3196        9947 :         move16();
    3197             :     }
    3198             : 
    3199      305483 :     return;
    3200             : }
    3201             : /*--------------------------------------------------------------------------*
    3202             :  * ivas_jbm_dec_get_adapted_linear_interpolator()
    3203             :  *
    3204             :  * Get an meta data map adapted to a time scale modified IVAS frame
    3205             :  *--------------------------------------------------------------------------*/
    3206             : 
    3207      268421 : void ivas_jbm_dec_get_md_map(
    3208             :     const Word16 default_len,  /* i  : default frame length in metadata slots         */
    3209             :     const Word16 len,          /* i  : length of the modfied frames in metadata slots */
    3210             :     const Word16 subframe_len, /* i  : default length of a subframe                   */
    3211             :     const Word16 offset,       /* i  : current read offset into the md buffer         */
    3212             :     const Word16 buf_len,      /* i  : length of the metadata buffer                  */
    3213             :     Word16 *map                /* o  : metadata index map                             */
    3214             : )
    3215             : {
    3216             :     Word16 jbm_segment_len, map_idx, src_idx, src_idx_map;
    3217             :     Word32 dec_fx, src_idx_fx;
    3218             :     Word16 temp_e;
    3219             :     Word16 temp;
    3220      268421 :     jbm_segment_len = shr( default_len, 1 );
    3221             : 
    3222     2415933 :     FOR( ( map_idx = len - 1, src_idx = default_len - 1 ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) )
    3223             :     {
    3224     2147512 :         temp = BASOP_Util_Divide1616_Scale( src_idx, subframe_len, &temp_e );
    3225     2147512 :         temp = shr( temp, sub( 15, temp_e ) ); // Q0
    3226     2147512 :         src_idx_map = s_max( 0, temp );
    3227     2147512 :         map[map_idx] = add( offset, src_idx_map ) % buf_len;
    3228     2147512 :         move16();
    3229             :     }
    3230             : 
    3231             :     /* changed part (first segment), interpolate index to parameters
    3232             :                (we do not want to interpolate and smooth acutal direction/diffuseness values even more) */
    3233      268421 :     IF( src_idx >= 0 )
    3234             :     {
    3235      268414 :         dec_fx = BASOP_Util_Divide3232_Scale( L_shl( add( src_idx, 1 ), 16 ), jbm_segment_len, &temp_e );
    3236      268414 :         dec_fx = L_shr( dec_fx, sub( 15, temp_e ) );
    3237      268414 :         src_idx_fx = L_sub( L_shl( add( src_idx, 1 ), 16 ), dec_fx );
    3238     2415726 :         FOR( ; map_idx >= 0; map_idx-- )
    3239             :         {
    3240     2147312 :             temp = BASOP_Util_Divide1616_Scale( round_fx( src_idx_fx ), subframe_len, &temp_e );
    3241     2147312 :             temp = shr( temp, sub( 15, temp_e ) ); // Q0
    3242     2147312 :             src_idx = s_max( 0, temp );
    3243     2147312 :             map[map_idx] = add( offset, src_idx ) % buf_len;
    3244     2147312 :             src_idx_fx = L_sub( src_idx_fx, dec_fx );
    3245             :         }
    3246             :     }
    3247             :     ELSE
    3248             :     {
    3249           7 :         set16_fx( map, offset, add( map_idx, 1 ) );
    3250             :     }
    3251             : 
    3252      268421 :     return;
    3253             : }
    3254             : 
    3255             : /*--------------------------------------------------------------------------*
    3256             :  * ivas_jbm_dec_get_md_map_even_spacing()
    3257             :  *
    3258             :  * Get an meta data map adapted to a time scale modified IVAS frame. Distribute slots evenly across the modified frame.
    3259             :  *--------------------------------------------------------------------------*/
    3260             : 
    3261       28138 : void ivas_jbm_dec_get_md_map_even_spacing(
    3262             :     const Word16 len,          /* i  : length of the modfied frames in metadata slots */
    3263             :     const Word16 subframe_len, /* i  : default length of a subframe                   */
    3264             :     const Word16 offset,       /* i  : current read offset into the md buffer         */
    3265             :     const Word16 buf_len,      /* i  : length of the metadata buffer                  */
    3266             :     Word16 *map                /* o  : metadata index map                             */
    3267             : )
    3268             : {
    3269             :     Word16 map_idx, sf_idx, sf_length, increment, subframes_written;
    3270             :     Word32 decimal_fx, decimal_sum_fx, eps_fx; // q = 16
    3271             :     Word16 subframe_map_length[MAX_PARAM_SPATIAL_SUBFRAMES];
    3272             : 
    3273             :     /* subframe map length */
    3274       28138 :     sf_length = idiv1616( len, subframe_len );
    3275       28138 :     IF( len % subframe_len == 0 )
    3276             :     {
    3277             :         /* even subframes */
    3278      140650 :         FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    3279             :         {
    3280      112520 :             subframe_map_length[sf_idx] = sf_length;
    3281      112520 :             move16();
    3282             :         }
    3283             :     }
    3284             :     ELSE
    3285             :     {
    3286             :         /* uneven subframes */
    3287             :         Word32 temp;
    3288             :         Word16 temp_e;
    3289           8 :         temp = BASOP_Util_Divide3232_Scale( L_shl( len, 16 ), subframe_len, &temp_e );
    3290           8 :         temp = L_shr( temp, sub( 15, temp_e ) );            // Q16
    3291           8 :         decimal_fx = L_sub( temp, L_shl( sf_length, 16 ) ); // Q16
    3292           8 :         decimal_sum_fx = decimal_fx;
    3293             : 
    3294           8 :         eps_fx = 65;
    3295           8 :         move32();
    3296           8 :         move32();
    3297          40 :         FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    3298             :         {
    3299          32 :             increment = extract_l( L_shr( L_add( decimal_sum_fx, eps_fx ), 16 ) );
    3300          32 :             subframe_map_length[sf_idx] = add( sf_length, increment );
    3301          32 :             move16();
    3302          32 :             IF( increment > 0 )
    3303             :             {
    3304          17 :                 decimal_sum_fx = L_sub( decimal_sum_fx, ONE_IN_Q16 );
    3305             :             }
    3306          32 :             decimal_sum_fx = L_add( decimal_sum_fx, decimal_fx );
    3307             :         }
    3308             :     }
    3309             : 
    3310             :     /* map slots to subframes */
    3311       28138 :     sf_idx = 0;
    3312       28138 :     subframes_written = 0;
    3313       28138 :     move16();
    3314       28138 :     move16();
    3315      478443 :     FOR( map_idx = 0; map_idx < len; map_idx++ )
    3316             :     {
    3317      450305 :         map[map_idx] = add( offset, sf_idx ) % buf_len;
    3318      450305 :         move16();
    3319      450305 :         IF( GE_16( sub( map_idx, subframes_written ), sub( subframe_map_length[sf_idx], 1 ) ) )
    3320             :         {
    3321      112552 :             subframes_written = add( subframes_written, subframe_map_length[sf_idx] );
    3322      112552 :             sf_idx = add( sf_idx, 1 );
    3323             :         }
    3324             :     }
    3325             : 
    3326       28138 :     return;
    3327             : }
    3328             : 
    3329             : /*--------------------------------------------------------------------------*
    3330             :  * ivas_jbm_dec_get_num_tc_channels()
    3331             :  *
    3332             :  * Get the number of transport channels provided by the JBM transport channel decode function
    3333             :  *--------------------------------------------------------------------------*/
    3334             : 
    3335             : 
    3336        7177 : Word16 ivas_jbm_dec_get_num_tc_channels_fx(
    3337             :     Decoder_Struct *st_ivas /* i  : IVAS decoder handle */
    3338             : )
    3339             : {
    3340             :     Word16 num_tc;
    3341             :     Word32 ivas_total_brate;
    3342             :     AUDIO_CONFIG output_config;
    3343             : 
    3344             : 
    3345        7177 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) )
    3346             :     {
    3347         931 :         num_tc = st_ivas->hDecoderConfig->nchan_out;
    3348         931 :         move16();
    3349             :     }
    3350             :     ELSE
    3351             :     {
    3352        6246 :         num_tc = st_ivas->nchan_transport;
    3353        6246 :         move16();
    3354             :     }
    3355        7177 :     output_config = st_ivas->hDecoderConfig->output_config;
    3356        7177 :     move16();
    3357             : 
    3358        7177 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
    3359        7177 :     move32();
    3360             : 
    3361        7177 :     test();
    3362        7177 :     test();
    3363        7177 :     test();
    3364        7177 :     IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) )
    3365             :     {
    3366           3 :         num_tc = st_ivas->hDecoderConfig->nchan_out;
    3367           3 :         move16();
    3368             :     }
    3369        7174 :     ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) )
    3370             :     {
    3371          22 :         num_tc = 1;
    3372          22 :         move16();
    3373             :     }
    3374        7152 :     ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
    3375             :     {
    3376        1048 :         if ( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
    3377             :         {
    3378           2 :             num_tc = 1;
    3379           2 :             move16();
    3380             :         }
    3381             :     }
    3382        6104 :     ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
    3383             :     {
    3384        3070 :         test();
    3385        3070 :         test();
    3386        3070 :         test();
    3387        3070 :         test();
    3388        3070 :         test();
    3389        3070 :         test();
    3390        3070 :         IF( st_ivas->sba_dirac_stereo_flag )
    3391             :         {
    3392         124 :             num_tc = CPE_CHANNELS;
    3393         124 :             move16();
    3394             :         }
    3395        2946 :         ELSE IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && GT_16( st_ivas->nCPE, 0 ) && st_ivas->hCPE[0] != NULL && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) )
    3396             :         {
    3397         633 :             num_tc = 1; /* Only one channel transported */
    3398         633 :             move16();
    3399             :         }
    3400             : 
    3401        3070 :         test();
    3402        3070 :         test();
    3403        3070 :         test();
    3404        3070 :         test();
    3405        3070 :         IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_16( st_ivas->nchan_transport, 2 ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
    3406             :         {
    3407          18 :             num_tc = CPE_CHANNELS;
    3408          18 :             move16();
    3409             :         }
    3410        3070 :         IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) )
    3411             :         {
    3412        1265 :             if ( EQ_16( num_tc, 3 ) )
    3413             :             {
    3414         269 :                 num_tc = add( num_tc, 1 );
    3415             :             }
    3416             :         }
    3417             :     }
    3418        3034 :     ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
    3419             :     {
    3420        1154 :         IF( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
    3421             :         {
    3422        1095 :             test();
    3423        1095 :             IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
    3424             :             {
    3425         693 :                 num_tc = add( num_tc, 1 );
    3426             :             }
    3427         402 :             ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
    3428             :             {
    3429         402 :                 num_tc = add( num_tc, st_ivas->nchan_ism );
    3430             :             }
    3431             :         }
    3432             :     }
    3433        1880 :     ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    3434             :     {
    3435             : 
    3436             : 
    3437         596 :         if ( st_ivas->sba_dirac_stereo_flag )
    3438             :         {
    3439          94 :             num_tc = CPE_CHANNELS;
    3440          94 :             move16();
    3441             :         }
    3442             : 
    3443         596 :         if ( EQ_16( num_tc, 3 ) )
    3444             :         {
    3445         137 :             num_tc = add( num_tc, 1 );
    3446             :         }
    3447         596 :         if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    3448             :         {
    3449         236 :             num_tc = add( num_tc, st_ivas->nchan_ism );
    3450             :         }
    3451             :     }
    3452        1284 :     ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
    3453             :     {
    3454        1238 :         IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
    3455             :         {
    3456           5 :             num_tc = 1;
    3457           5 :             move16();
    3458             :         }
    3459        1233 :         ELSE IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) )
    3460             :         {
    3461          26 :             num_tc = 2;
    3462          26 :             move16();
    3463             :         }
    3464        1207 :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
    3465             :         {
    3466             :             /* do all static dmx already in the TC decoder if less channels than transported... */
    3467         590 :             test();
    3468         590 :             test();
    3469         590 :             test();
    3470         590 :             test();
    3471         590 :             test();
    3472         590 :             IF( NE_16( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) )
    3473             :             {
    3474           1 :                 if ( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) )
    3475             :                 {
    3476           0 :                     num_tc = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
    3477             :                 }
    3478             :             }
    3479         589 :             ELSE IF( ( EQ_16( st_ivas->renderer_type, RENDERER_MC ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) )
    3480             :             {
    3481           0 :                 num_tc = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    3482             :             }
    3483             :         }
    3484         617 :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
    3485             :         {
    3486          11 :             num_tc = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
    3487          11 :             move16();
    3488             :         }
    3489         606 :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
    3490             :         {
    3491         274 :             if ( st_ivas->hOutSetup.separateChannelEnabled )
    3492             :             {
    3493          18 :                 num_tc = add( num_tc, 1 );
    3494             :             }
    3495         274 :             test();
    3496         274 :             test();
    3497         274 :             test();
    3498         274 :             test();
    3499         274 :             test();
    3500         274 :             test();
    3501         274 :             test();
    3502         291 :             if ( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
    3503          51 :                                                                 EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
    3504          34 :                                                                 EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) ) )
    3505             :             {
    3506             :                 /* LFE is synthesized in TD with the TCs*/
    3507           1 :                 num_tc = add( num_tc, 1 );
    3508             :             }
    3509             :         }
    3510             :     }
    3511          46 :     ELSE IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
    3512             :     {
    3513           0 :         num_tc = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN;
    3514           0 :         move16();
    3515             :     }
    3516             : 
    3517        7177 :     return num_tc;
    3518             : }
    3519             : 
    3520             : /*--------------------------------------------------------------------------*
    3521             :  * ivas_jbm_dec_copy_tc()
    3522             :  *
    3523             :  * Copy interleaved transport chnannels to the correct buffers, update the TC
    3524             :  * buffer handle
    3525             :  *--------------------------------------------------------------------------*/
    3526       19551 : static void ivas_jbm_dec_copy_tc(
    3527             :     Decoder_Struct *st_ivas,           /* i/o: IVAS decoder structure                                 */
    3528             :     const Word16 nSamplesForRendering, /* i  : number of samples to digest                            */
    3529             :     Word16 *nSamplesResidual,          /* o  : number of samples that will be left for the next frame */
    3530             :     Word32 *data,                      /* i  : (interleaved) transport channel samples                data_q*/
    3531             :     Word32 *tc_digest_f[],             /* o  : samples that will be directly digested (e.g. by CLDFB) data_q*/
    3532             :     Word16 data_q )
    3533             : {
    3534             :     Word16 ch;
    3535             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    3536             :     Word16 n_samples_still_available, m;
    3537             :     Word16 n_ch_full_copy;
    3538             :     Word16 n_ch_res_copy;
    3539             : 
    3540       19551 :     hTcBuffer = st_ivas->hTcBuffer;
    3541       19551 :     n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered );
    3542       19551 :     hTcBuffer->n_samples_buffered = add( add( n_samples_still_available, nSamplesForRendering ), hTcBuffer->n_samples_discard );
    3543       19551 :     hTcBuffer->n_samples_available = i_mult( hTcBuffer->n_samples_granularity, idiv1616( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_granularity ) );
    3544       19551 :     *nSamplesResidual = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_available );
    3545       19551 :     move16();
    3546       19551 :     move16();
    3547       19551 :     move16();
    3548       19551 :     n_ch_full_copy = s_min( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
    3549       19551 :     n_ch_res_copy = sub( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
    3550             : 
    3551       61340 :     FOR( ch = 0; ch < n_ch_full_copy; ch++ )
    3552             :     {
    3553       41789 :         set32_fx( hTcBuffer->tc_fx[ch], 0, hTcBuffer->n_samples_discard );
    3554       41789 :         Copy32( hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_discard, n_samples_still_available );
    3555    32923474 :         FOR( m = 0; m < nSamplesForRendering; m++ )
    3556             :         {
    3557    32881685 :             hTcBuffer->tc_fx[ch][n_samples_still_available + hTcBuffer->n_samples_discard + m] = data[m * st_ivas->hTcBuffer->nchan_transport_jbm + ch];
    3558    32881685 :             move32();
    3559             :         }
    3560             :     }
    3561             : 
    3562       19551 :     IF( n_ch_res_copy > 0 )
    3563             :     {
    3564        4648 :         FOR( ; ch < hTcBuffer->nchan_transport_jbm; ch++ )
    3565             :         {
    3566        3102 :             Copy32( hTcBuffer->tc_fx[ch], tc_digest_f[ch], n_samples_still_available );
    3567     2952586 :             FOR( m = 0; m < nSamplesForRendering; m++ )
    3568             :             {
    3569     2949484 :                 tc_digest_f[ch][n_samples_still_available + m] = data[( m * st_ivas->hTcBuffer->nchan_transport_jbm ) + ch]; // data_q
    3570     2949484 :                 move32();
    3571             :             }
    3572        3102 :             Copy32( tc_digest_f[ch] + hTcBuffer->n_samples_available, hTcBuffer->tc_fx[ch], *nSamplesResidual );
    3573             :         }
    3574             :     }
    3575       19551 :     hTcBuffer->q_tc_fx = data_q;
    3576       19551 :     move16();
    3577       19551 :     hTcBuffer->n_samples_rendered = 0;
    3578       19551 :     move16();
    3579       19551 :     hTcBuffer->subframes_rendered = 0;
    3580       19551 :     move16();
    3581             : 
    3582       19551 :     return;
    3583             : }
    3584             : 
    3585             : /*--------------------------------------------------------------------------*
    3586             :  * ivas_jbm_dec_get_render_granularity()
    3587             :  *
    3588             :  *
    3589             :  *--------------------------------------------------------------------------*/
    3590             : 
    3591             : /*! r: render granularity */
    3592             : 
    3593             : 
    3594       10818 : Word16 ivas_jbm_dec_get_render_granularity(
    3595             :     const RENDERER_TYPE rendererType, /* i  : renderer type     */
    3596             :     const IVAS_FORMAT ivas_format,    /* i  : ivas format */
    3597             :     const MC_MODE mc_mode,            /* i  : MC mode */
    3598             :     const Word32 output_Fs            /* i  : sampling rate     Q0*/
    3599             : )
    3600             : {
    3601             :     Word16 render_granularity;
    3602             : 
    3603       10818 :     test();
    3604       10818 :     test();
    3605       10818 :     IF( EQ_32( rendererType, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
    3606             :     {
    3607         770 :         test();
    3608         770 :         IF( ( EQ_32( ivas_format, MC_FORMAT ) ) && ( EQ_32( mc_mode, MC_MODE_PARAMUPMIX ) ) )
    3609             :         {
    3610           0 :             render_granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS );
    3611             :         }
    3612             :         ELSE
    3613             :         {
    3614         770 :             render_granularity = NS2SA_FX2( output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
    3615             :         }
    3616             :     }
    3617             :     ELSE
    3618             :     {
    3619       10048 :         render_granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS );
    3620             :     }
    3621             : 
    3622       10818 :     return render_granularity;
    3623             : }
    3624             : 
    3625             : 
    3626             : /*--------------------------------------------------------------------------*
    3627             :  * ivas_jbm_dec_tc_buffer_open()
    3628             :  *
    3629             :  * open and initialize JBM transport channel buffer
    3630             :  *--------------------------------------------------------------------------*/
    3631             : 
    3632             : 
    3633         614 : ivas_error ivas_jbm_dec_tc_buffer_open_fx(
    3634             :     Decoder_Struct *st_ivas,               /* i/o: IVAS decoder structure              */
    3635             :     const TC_BUFFER_MODE tc_buffer_mode,   /* i  : buffer mode                         */
    3636             :     const Word16 nchan_transport_jbm,      /* i  : number of real transport channels   */
    3637             :     const Word16 nchan_transport_internal, /* i  : number of totally buffered channels */
    3638             :     const Word16 nchan_full,               /* i  : number of channels to fully store   */
    3639             :     const Word16 n_samples_granularity     /* i  : granularity of the renderer/buffer  */
    3640             : )
    3641             : {
    3642             :     Word16 nsamp_to_allocate;
    3643             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    3644             :     Word16 nMaxSlotsPerSubframe;
    3645             :     Word16 nchan_residual;
    3646             :     Word16 ch_idx;
    3647             :     Word16 tmp, tmp_e;
    3648             :     Word32 tmp32;
    3649             : 
    3650             :     /*-----------------------------------------------------------------*
    3651             :      * prepare library opening
    3652             :      *-----------------------------------------------------------------*/
    3653             : 
    3654         614 :     IF( ( hTcBuffer = (DECODER_TC_BUFFER_HANDLE) malloc( sizeof( DECODER_TC_BUFFER ) ) ) == NULL )
    3655             :     {
    3656           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) );
    3657             :     }
    3658             : 
    3659         614 :     hTcBuffer->tc_buffer_mode = tc_buffer_mode;
    3660         614 :     move16();
    3661         614 :     hTcBuffer->nchan_transport_jbm = nchan_transport_jbm;
    3662         614 :     move16();
    3663         614 :     hTcBuffer->nchan_transport_internal = nchan_transport_internal;
    3664         614 :     move16();
    3665         614 :     hTcBuffer->nchan_buffer_full = nchan_full;
    3666         614 :     move16();
    3667         614 :     nchan_residual = sub( nchan_transport_internal, nchan_full );
    3668         614 :     hTcBuffer->n_samples_granularity = n_samples_granularity;
    3669         614 :     move16();
    3670         614 :     hTcBuffer->n_samples_available = 0;
    3671         614 :     move16();
    3672         614 :     hTcBuffer->n_samples_buffered = 0;
    3673         614 :     move16();
    3674         614 :     hTcBuffer->n_samples_rendered = 0;
    3675         614 :     move16();
    3676         614 :     hTcBuffer->slots_rendered = 0;
    3677         614 :     move16();
    3678         614 :     hTcBuffer->subframes_rendered = 0;
    3679         614 :     move16();
    3680         614 :     hTcBuffer->n_samples_discard = 0;
    3681         614 :     move16();
    3682         614 :     hTcBuffer->n_samples_flushed = 0;
    3683         614 :     move16();
    3684         614 :     hTcBuffer->nb_subframes = MAX_PARAM_SPATIAL_SUBFRAMES;
    3685         614 :     move16();
    3686         614 :     nsamp_to_allocate = 0;
    3687         614 :     move16();
    3688             : 
    3689         614 :     tmp32 = L_mult0( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity ); // Q0
    3690         614 :     tmp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, tmp32, &tmp_e );
    3691         614 :     nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); // Q0
    3692             : 
    3693         614 :     hTcBuffer->num_slots = mult0( nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES );
    3694         614 :     move16();
    3695             : 
    3696         614 :     set16_fx( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
    3697         614 :     set16_fx( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES );
    3698             : 
    3699             :     {
    3700             :         Word16 n_samp_full, n_samp_residual;
    3701             :         Word32 offset;
    3702         614 :         IF( st_ivas->hDecoderConfig->Opt_tsm )
    3703             :         {
    3704          28 :             n_samp_full = add( NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ), sub( hTcBuffer->n_samples_granularity, 1 ) );
    3705          28 :             n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 );
    3706             :         }
    3707             :         ELSE
    3708             :         {
    3709             :             /* n_samp_full = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */
    3710         586 :             n_samp_full = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) );
    3711         586 :             n_samp_residual = 0;
    3712         586 :             move16();
    3713             :         }
    3714             : 
    3715         614 :         nsamp_to_allocate = mult0( hTcBuffer->nchan_buffer_full, n_samp_full );
    3716         614 :         nsamp_to_allocate = add( nsamp_to_allocate, mult0( nchan_residual, n_samp_residual ) );
    3717             : 
    3718         614 :         IF( nsamp_to_allocate == 0 )
    3719             :         {
    3720          15 :             hTcBuffer->tc_buffer_fx = NULL;
    3721             : 
    3722         255 :             FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
    3723             :             {
    3724         240 :                 hTcBuffer->tc_fx[ch_idx] = NULL;
    3725             :             }
    3726             :         }
    3727             :         ELSE
    3728             :         {
    3729         599 :             IF( st_ivas->hDecoderConfig->Opt_tsm )
    3730             :             {
    3731             :                 /* note: the maximum buffer length is for OSBA DISC mode with ISMs -> 15*(1920+239)=32385 samples */
    3732          28 :                 IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL )
    3733             :                 {
    3734           0 :                     return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) );
    3735             :                 }
    3736          28 :                 set32_fx( hTcBuffer->tc_buffer_fx, 0, nsamp_to_allocate );
    3737             : 
    3738          28 :                 offset = 0;
    3739          28 :                 move16();
    3740         126 :                 FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
    3741             :                 {
    3742          98 :                     hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
    3743          98 :                     offset = L_add( offset, n_samp_full );
    3744             :                 }
    3745          30 :                 FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ )
    3746             :                 {
    3747           2 :                     hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
    3748           2 :                     offset = L_add( offset, n_samp_residual );
    3749             :                 }
    3750         376 :                 FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
    3751             :                 {
    3752         348 :                     hTcBuffer->tc_fx[ch_idx] = NULL;
    3753             :                 }
    3754             :             }
    3755             :             ELSE
    3756             :             {
    3757         571 :                 hTcBuffer->tc_buffer_fx = NULL;
    3758             :             }
    3759             :         }
    3760             :     }
    3761             : 
    3762         614 :     st_ivas->hTcBuffer = hTcBuffer;
    3763             : 
    3764         614 :     return IVAS_ERR_OK;
    3765             : }
    3766             : 
    3767             : 
    3768             : /*--------------------------------------------------------------------------*
    3769             :  * ivas_jbm_dec_tc_buffer_reconfigure()
    3770             :  *
    3771             :  * open and initialize JBM transport channel buffer
    3772             :  *--------------------------------------------------------------------------*/
    3773             : 
    3774        3798 : ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx(
    3775             :     Decoder_Struct *st_ivas,               /* i/o: IVAS decoder structure                  */
    3776             :     const TC_BUFFER_MODE tc_buffer_mode,   /* i  : new buffer mode                         */
    3777             :     const Word16 nchan_transport_jbm,      /* i  : new number of real transport channels   */
    3778             :     const Word16 nchan_transport_internal, /* i  : new number of totally buffered channels */
    3779             :     const Word16 nchan_full,               /* i  : new number of channels to fully store   */
    3780             :     const Word16 n_samples_granularity     /* i  : new granularity of the renderer/buffer  */
    3781             : )
    3782             : {
    3783             :     Word16 nsamp_to_allocate, n_samp_full, n_samp_residual, offset, nchan_residual;
    3784             :     Word16 ch_idx;
    3785             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    3786             : 
    3787        3798 :     hTcBuffer = st_ivas->hTcBuffer;
    3788        3798 :     move16();
    3789             : 
    3790             :     /* if granularity changes, adapt subframe_nb_slots */
    3791        3798 :     IF( NE_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) )
    3792             :     {
    3793             :         Word16 nMaxSlotsPerSubframeNew;
    3794             : 
    3795         725 :         nMaxSlotsPerSubframeNew = idiv1616( divide3216( st_ivas->hDecoderConfig->output_Fs, ( ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) >> 1 ) ), n_samples_granularity ); // Q0
    3796             :         /* if samples were flushed, take that into account here */
    3797         725 :         test();
    3798         725 :         IF( LT_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) && hTcBuffer->n_samples_flushed > 0 )
    3799             :         {
    3800          72 :             hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = idiv1616( hTcBuffer->n_samples_flushed, n_samples_granularity );
    3801          72 :             hTcBuffer->n_samples_flushed = 0;
    3802          72 :             move16();
    3803          72 :             move16();
    3804             :         }
    3805             :         ELSE
    3806             :         {
    3807         653 :             hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = nMaxSlotsPerSubframeNew;
    3808         653 :             move16();
    3809             :         }
    3810             :     }
    3811             : 
    3812        3798 :     hTcBuffer->tc_buffer_mode = tc_buffer_mode;
    3813        3798 :     move16();
    3814        3798 :     hTcBuffer->nchan_transport_jbm = nchan_transport_jbm;
    3815        3798 :     move16();
    3816        3798 :     hTcBuffer->nchan_transport_internal = nchan_transport_internal;
    3817        3798 :     move16();
    3818        3798 :     hTcBuffer->nchan_buffer_full = nchan_full;
    3819        3798 :     move16();
    3820        3798 :     nchan_residual = sub( nchan_transport_internal, nchan_full );
    3821        3798 :     hTcBuffer->n_samples_granularity = n_samples_granularity;
    3822        3798 :     move16();
    3823             : 
    3824             :     /* realloc buffers */
    3825        3798 :     IF( hTcBuffer->tc_buffer_fx != NULL )
    3826             :     {
    3827         947 :         free( hTcBuffer->tc_buffer_fx );
    3828         947 :         hTcBuffer->tc_buffer_fx = NULL;
    3829             :     }
    3830             : 
    3831        3798 :     IF( st_ivas->hDecoderConfig->Opt_tsm )
    3832             :     {
    3833         947 :         n_samp_full = ( add( NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ), sub( hTcBuffer->n_samples_granularity, 1 ) ) );
    3834         947 :         n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 );
    3835             :     }
    3836             :     ELSE
    3837             :     {
    3838        2851 :         n_samp_full = extract_l( Mult_32_16( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) );
    3839        2851 :         n_samp_residual = 0;
    3840        2851 :         move16();
    3841             :     }
    3842             : 
    3843        3798 :     nsamp_to_allocate = imult1616( hTcBuffer->nchan_buffer_full, n_samp_full );
    3844        3798 :     nsamp_to_allocate = add( nsamp_to_allocate, imult1616( nchan_residual, n_samp_residual ) );
    3845             : 
    3846        3798 :     IF( nsamp_to_allocate == 0 )
    3847             :     {
    3848         327 :         hTcBuffer->tc_buffer_fx = NULL;
    3849        5559 :         FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
    3850             :         {
    3851        5232 :             hTcBuffer->tc_fx[ch_idx] = NULL;
    3852             :         }
    3853             :     }
    3854             :     ELSE
    3855             :     {
    3856        3471 :         IF( st_ivas->hDecoderConfig->Opt_tsm )
    3857             :         {
    3858         947 :             IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL )
    3859             :             {
    3860           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR JBM TC Buffer\n" ) );
    3861             :             }
    3862         947 :             set32_fx( hTcBuffer->tc_buffer_fx, 0, nsamp_to_allocate );
    3863             : 
    3864         947 :             offset = 0;
    3865         947 :             move16();
    3866        4292 :             FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
    3867             :             {
    3868        3345 :                 hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
    3869        3345 :                 offset = add( offset, n_samp_full );
    3870             :             }
    3871         956 :             FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ )
    3872             :             {
    3873           9 :                 hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
    3874           9 :                 offset = add( offset, n_samp_residual );
    3875             :             }
    3876       12745 :             FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
    3877             :             {
    3878       11798 :                 hTcBuffer->tc_fx[ch_idx] = NULL;
    3879             :             }
    3880             :         }
    3881             :         ELSE
    3882             :         {
    3883        2524 :             hTcBuffer->tc_buffer_fx = NULL;
    3884             :         }
    3885             :     }
    3886             : 
    3887        3798 :     return IVAS_ERR_OK;
    3888             : }
    3889             : 
    3890             : 
    3891             : /*--------------------------------------------------------------------------*
    3892             :  * ivas_jbm_dec_tc_buffer_playout()
    3893             :  *
    3894             :  *
    3895             :  *--------------------------------------------------------------------------*/
    3896             : 
    3897      130302 : static void ivas_jbm_dec_tc_buffer_playout_fx(
    3898             :     Decoder_Struct *st_ivas,
    3899             :     const UWord16 nSamplesAsked,
    3900             :     UWord16 *nSamplesRendered,
    3901             :     Word32 *output_fx[] /*Q11*/
    3902             : )
    3903             : {
    3904             :     Word16 ch_idx, slot_size, slots_to_render, first_sf, last_sf, tmp, e;
    3905             : 
    3906      130302 :     slot_size = st_ivas->hTcBuffer->n_samples_granularity;
    3907      130302 :     move16();
    3908             : 
    3909             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    3910      130302 :     tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e );
    3911      130302 :     tmp = shr( tmp, sub( 15, e ) ); // Q0
    3912      130302 :     slots_to_render = s_min( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), tmp );
    3913      130302 :     st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); // Q0
    3914      130302 :     *nSamplesRendered = (UWord16) L_mult0( slots_to_render, slot_size );
    3915      130302 :     first_sf = st_ivas->hTcBuffer->subframes_rendered;
    3916      130302 :     last_sf = first_sf;
    3917      130302 :     move16();
    3918      130302 :     move16();
    3919      130302 :     move16();
    3920      130302 :     move16();
    3921             : 
    3922      646336 :     WHILE( slots_to_render > 0 )
    3923             :     {
    3924      516034 :         slots_to_render = sub( slots_to_render, st_ivas->hTcBuffer->subframe_nbslots[last_sf] );
    3925      516034 :         last_sf = add( last_sf, 1 );
    3926             :     }
    3927             : #ifdef DEBUGGING
    3928             :     assert( slots_to_render == 0 );
    3929             : #endif
    3930             : 
    3931      381667 :     FOR( ch_idx = 0; ch_idx < st_ivas->hTcBuffer->nchan_transport_jbm; ch_idx++ )
    3932             :     {
    3933      251365 :         Copy32( st_ivas->hTcBuffer->tc_fx[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered, output_fx[ch_idx], *nSamplesRendered );
    3934             :     }
    3935             : 
    3936      130302 :     st_ivas->hTcBuffer->subframes_rendered = last_sf;
    3937      130302 :     move16();
    3938             : 
    3939      130302 :     return;
    3940             : }
    3941             : 
    3942             : 
    3943             : /*--------------------------------------------------------------------------*
    3944             :  * ivas_jbm_dec_tc_buffer_close()
    3945             :  *
    3946             :  * Close JBM transport channel buffer
    3947             :  *--------------------------------------------------------------------------*/
    3948             : 
    3949         614 : void ivas_jbm_dec_tc_buffer_close(
    3950             :     DECODER_TC_BUFFER_HANDLE *phTcBuffer /* i/o: TC buffer handle */
    3951             : )
    3952             : {
    3953             :     Word16 i;
    3954             : 
    3955         614 :     IF( *phTcBuffer != NULL )
    3956             :     {
    3957       10438 :         FOR( i = 0; i < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; i++ )
    3958             :         {
    3959        9824 :             ( *phTcBuffer )->tc_fx[i] = NULL;
    3960             :         }
    3961             : 
    3962         614 :         IF( ( *phTcBuffer )->tc_buffer_fx != NULL )
    3963             :         {
    3964          28 :             free( ( *phTcBuffer )->tc_buffer_fx );
    3965          28 :             ( *phTcBuffer )->tc_buffer_fx = NULL;
    3966             :         }
    3967             : 
    3968         614 :         free( *phTcBuffer );
    3969         614 :         *phTcBuffer = NULL;
    3970             :     }
    3971             : 
    3972         614 :     return;
    3973             : }
    3974             : 
    3975             : /*--------------------------------------------------------------------------*
    3976             :  * ivas_jbm_dec_td_renderers_adapt_subframes()
    3977             :  *
    3978             :  * Close JBM transport channel buffer
    3979             :  *--------------------------------------------------------------------------*/
    3980      238231 : void ivas_jbm_dec_td_renderers_adapt_subframes(
    3981             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
    3982             : )
    3983             : {
    3984             :     Word16 nMaxSlotsPerSubframe, nSlotsAvailable, tmp, exp, tmp1, tmp2, s1, s2;
    3985             :     UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe;
    3986             : 
    3987             :     /* nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; */
    3988      238231 :     tmp = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) );
    3989      238231 :     tmp = BASOP_Util_Divide1616_Scale( tmp, st_ivas->hTcBuffer->n_samples_granularity, &exp );
    3990      238231 :     nMaxSlotsPerSubframe = shr( tmp, sub( 15, exp ) ); // Q0
    3991             : 
    3992             :     /* nSlotsAvailable = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; */
    3993      238231 :     tmp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &exp );
    3994      238231 :     nSlotsAvailable = shr( tmp, sub( 15, exp ) ); // Q0
    3995             : 
    3996      238231 :     st_ivas->hTcBuffer->num_slots = nSlotsAvailable;
    3997      238231 :     move16();
    3998             :     /* st_ivas->hTcBuffer->n_samples_available = nSlotsAvailable * st_ivas->hTcBuffer->n_samples_granularity; */
    3999      238231 :     st_ivas->hTcBuffer->n_samples_available = i_mult( nSlotsAvailable, st_ivas->hTcBuffer->n_samples_granularity );
    4000      238231 :     move16();
    4001      238231 :     nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] );
    4002      238231 :     st_ivas->hTcBuffer->nb_subframes = 0;
    4003      238231 :     move16();
    4004             : 
    4005      238231 :     IF( nSlotsInFirstSubframe > 0 )
    4006             :     {
    4007        3205 :         st_ivas->hTcBuffer->nb_subframes = 1;
    4008        3205 :         move16();
    4009        3205 :         nSlotsAvailable = sub( nSlotsAvailable, nSlotsInFirstSubframe );
    4010             :     }
    4011             : 
    4012      238231 :     s1 = sub( norm_s( nSlotsAvailable ), 1 );
    4013      238231 :     s2 = norm_s( nMaxSlotsPerSubframe );
    4014             : 
    4015      238231 :     tmp1 = shl( nSlotsAvailable, s1 );
    4016      238231 :     tmp2 = shl( nMaxSlotsPerSubframe, s2 );
    4017             : 
    4018      238231 :     tmp = div_s( tmp1, tmp2 );
    4019      238231 :     st_ivas->hTcBuffer->nb_subframes = add( st_ivas->hTcBuffer->nb_subframes, ceil_fx16( tmp, sub( 15, sub( s2, s1 ) ) ) );
    4020      238231 :     move16();
    4021             : 
    4022      238231 :     nSlotsInLastSubframe = nSlotsAvailable % nMaxSlotsPerSubframe;
    4023      238231 :     move16();
    4024      238231 :     set16_fx( st_ivas->hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
    4025      238231 :     set16_fx( st_ivas->hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, st_ivas->hTcBuffer->nb_subframes );
    4026             : 
    4027      238231 :     if ( nSlotsInFirstSubframe > 0 )
    4028             :     {
    4029        3205 :         st_ivas->hTcBuffer->subframe_nbslots[0] = nSlotsInFirstSubframe;
    4030        3205 :         move16();
    4031             :     }
    4032             : 
    4033      238231 :     if ( nSlotsInLastSubframe > 0 )
    4034             :     {
    4035        3213 :         st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nSlotsInLastSubframe;
    4036        3213 :         move16();
    4037             :     }
    4038             : 
    4039      238231 :     st_ivas->hTcBuffer->slots_rendered = 0;
    4040      238231 :     move16();
    4041      238231 :     st_ivas->hTcBuffer->subframes_rendered = 0;
    4042      238231 :     move16();
    4043             : 
    4044      238231 :     return;
    4045             : }
    4046             : /*--------------------------------------------------------------------------*
    4047             :  * ivas_jbm_dec_get_tc_buffer_mode()
    4048             :  *
    4049             :  *
    4050             :  *--------------------------------------------------------------------------*/
    4051             : 
    4052        5038 : TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode(
    4053             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
    4054             : )
    4055             : {
    4056             :     TC_BUFFER_MODE buffer_mode;
    4057        5038 :     buffer_mode = TC_BUFFER_MODE_BUFFER;
    4058        5038 :     move16();
    4059             : 
    4060        5038 :     SWITCH( st_ivas->renderer_type )
    4061             :     {
    4062             :             /* all renderers where we are done after TC decoding (might include DMX to mono/stereo */
    4063         797 :         case RENDERER_DISABLE:
    4064             :         case RENDERER_MCMASA_MONO_STEREO:
    4065             :         case RENDERER_OSBA_STEREO:
    4066             :         case RENDERER_MONO_DOWNMIX:
    4067         797 :             buffer_mode = TC_BUFFER_MODE_BUFFER;
    4068         797 :             move16();
    4069         797 :             BREAK;
    4070        3725 :         case RENDERER_TD_PANNING:
    4071             :         case RENDERER_BINAURAL_OBJECTS_TD:
    4072             :         case RENDERER_BINAURAL_FASTCONV:
    4073             :         case RENDERER_BINAURAL_FASTCONV_ROOM:
    4074             :         case RENDERER_BINAURAL_PARAMETRIC:
    4075             :         case RENDERER_BINAURAL_PARAMETRIC_ROOM:
    4076             :         case RENDERER_STEREO_PARAMETRIC:
    4077             :         case RENDERER_DIRAC:
    4078             :         case RENDERER_PARAM_ISM:
    4079             :         case RENDERER_BINAURAL_MIXER_CONV:
    4080             :         case RENDERER_BINAURAL_MIXER_CONV_ROOM:
    4081             :         case RENDERER_OMASA_OBJECT_EXT:
    4082             :         case RENDERER_OMASA_MIX_EXT:
    4083             :         case RENDERER_OSBA_AMBI:
    4084             :         case RENDERER_OSBA_LS:
    4085        3725 :             buffer_mode = TC_BUFFER_MODE_RENDERER;
    4086        3725 :             move16();
    4087        3725 :             BREAK;
    4088           2 :         case RENDERER_NON_DIEGETIC_DOWNMIX:
    4089           2 :             IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) )
    4090             :             {
    4091           1 :                 buffer_mode = TC_BUFFER_MODE_BUFFER;
    4092           1 :                 move16();
    4093             :             }
    4094             :             ELSE
    4095             :             {
    4096           1 :                 buffer_mode = TC_BUFFER_MODE_RENDERER;
    4097           1 :                 move16();
    4098             :             }
    4099           2 :             break;
    4100          86 :         case RENDERER_MC_PARAMMC:
    4101          86 :             IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
    4102             :             {
    4103           2 :                 buffer_mode = TC_BUFFER_MODE_BUFFER; /* TCs are already the DMX to mono or stereo */
    4104           2 :                 move16();
    4105             :             }
    4106             :             ELSE
    4107             :             {
    4108          84 :                 buffer_mode = TC_BUFFER_MODE_RENDERER;
    4109          84 :                 move16();
    4110             :             }
    4111          86 :             BREAK;
    4112         102 :         case RENDERER_MC:
    4113         102 :             if ( NE_16( ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ), st_ivas->hDecoderConfig->nchan_out ) )
    4114             :             {
    4115          95 :                 buffer_mode = TC_BUFFER_MODE_RENDERER;
    4116          95 :                 move16();
    4117             :             }
    4118         102 :             BREAK;
    4119         326 :         case RENDERER_SBA_LINEAR_ENC:
    4120         326 :             test();
    4121         326 :             test();
    4122         326 :             test();
    4123         326 :             test();
    4124         326 :             IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) && ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( ( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ) ), ( add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) )
    4125             :             {
    4126           0 :                 buffer_mode = TC_BUFFER_MODE_BUFFER;
    4127           0 :                 move16();
    4128             :             }
    4129             :             ELSE
    4130             :             {
    4131         326 :                 buffer_mode = TC_BUFFER_MODE_RENDERER;
    4132         326 :                 move16();
    4133             :             }
    4134         326 :             BREAK;
    4135           0 :         case RENDERER_SBA_LINEAR_DEC:
    4136           0 :             test();
    4137           0 :             test();
    4138           0 :             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 ) ) )
    4139             :             {
    4140           0 :                 buffer_mode = TC_BUFFER_MODE_BUFFER;
    4141           0 :                 move16();
    4142             :             }
    4143             :             ELSE
    4144             :             {
    4145           0 :                 buffer_mode = TC_BUFFER_MODE_RENDERER;
    4146           0 :                 move16();
    4147             :             }
    4148           0 :             BREAK;
    4149             :     }
    4150             : 
    4151        5038 :     return buffer_mode;
    4152             : }
    4153             : 
    4154             : 
    4155             : /*--------------------------------------------------------------------------*
    4156             :  * ivas_jbm_dec_copy_tc_no_tsm()
    4157             :  *
    4158             :  *
    4159             :  *--------------------------------------------------------------------------*/
    4160             : 
    4161      393674 : void ivas_jbm_dec_copy_tc_no_tsm_fx(
    4162             :     Decoder_Struct *st_ivas,  /* i/o: IVAS decoder handle        Q0  */
    4163             :     Word32 *tc_fx[],          /* i  : transport channels         Q11 */
    4164             :     const Word16 output_frame /* i  : output frame size          Q0  */
    4165             : )
    4166             : {
    4167             :     Word16 Q_tc;
    4168             :     Word16 n_ch_cldfb;
    4169             :     Word16 ch_idx;
    4170             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    4171             : 
    4172      393674 :     hTcBuffer = st_ivas->hTcBuffer;
    4173      393674 :     hTcBuffer->n_samples_buffered = output_frame;
    4174      393674 :     hTcBuffer->n_samples_available = hTcBuffer->n_samples_buffered;
    4175      393674 :     move16();
    4176      393674 :     move16();
    4177      393674 :     n_ch_cldfb = sub( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
    4178             : 
    4179      393674 :     Q_tc = 11; /*tc buffer is at Q11*/
    4180      393674 :     move16();
    4181             : 
    4182             : #ifdef DEBUGGING
    4183             :     assert( st_ivas->hDecoderConfig->Opt_tsm == 0 );
    4184             : #endif
    4185             :     /* CLDFB ana for ParamMC/ParamISM */
    4186      393674 :     IF( n_ch_cldfb > 0 )
    4187             :     {
    4188             :         Word32 *cldfb_real_buffer_fx;
    4189             :         Word32 *cldfb_imag_buffer_fx;
    4190             :         Word16 cldfb_ch, slot_idx, num_freq_bands;
    4191             : 
    4192       13936 :         cldfb_real_buffer_fx = NULL;
    4193       13936 :         cldfb_imag_buffer_fx = NULL;
    4194       13936 :         num_freq_bands = 0;
    4195       13936 :         move16();
    4196             : 
    4197       13936 :         IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) ISM_FORMAT ) )
    4198             :         {
    4199        3747 :             cldfb_real_buffer_fx = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx;
    4200        3747 :             cldfb_imag_buffer_fx = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx;
    4201        3747 :             num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands;
    4202        3747 :             move16();
    4203             : 
    4204        3747 :             ivas_ism_param_dec_tc_gain_ajust_fx( st_ivas, output_frame, output_frame / 2, tc_fx, &Q_tc );
    4205        3747 :             Scale_sig32( tc_fx[0], output_frame, sub( Q11, Q_tc ) ); /*keepeing tc_fx at Q11*/
    4206        3747 :             Scale_sig32( tc_fx[1], output_frame, sub( Q11, Q_tc ) ); /*keepeing tc_fx at Q11*/
    4207             :         }
    4208       10189 :         ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) MC_FORMAT ) )
    4209             :         {
    4210       10189 :             cldfb_real_buffer_fx = st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx;
    4211       10189 :             cldfb_imag_buffer_fx = st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx;
    4212       10189 :             num_freq_bands = st_ivas->hParamMC->num_freq_bands;
    4213       10189 :             move16();
    4214             :         }
    4215             : 
    4216             :         /* CLDFB Analysis*/
    4217       41888 :         FOR( ( ch_idx = 0, cldfb_ch = 0 ); cldfb_ch < n_ch_cldfb; ( cldfb_ch++, ch_idx++ ) )
    4218             :         {
    4219      475184 :             FOR( slot_idx = 0; slot_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; slot_idx++ )
    4220             :             {
    4221      447232 :                 Q_tc = 11;
    4222      447232 :                 move16();
    4223      447232 :                 cldfbAnalysis_ts_fx_fixed_q( &( tc_fx[ch_idx][num_freq_bands * slot_idx] ),
    4224      447232 :                                              &cldfb_real_buffer_fx[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
    4225      447232 :                                              &cldfb_imag_buffer_fx[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
    4226             :                                              num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch], &Q_tc );
    4227             :             }
    4228             :         }
    4229       13936 :         IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) MC_FORMAT ) )
    4230             :         {
    4231       10189 :             st_ivas->hParamMC->Cldfb_RealBuffer_tc_e = 25; // 31-Q_tc = 31-(11-5)
    4232       10189 :             st_ivas->hParamMC->Cldfb_ImagBuffer_tc_e = 25; // 31-Q_tc = 31-(11-5)
    4233       10189 :             move16();
    4234       10189 :             move16();
    4235             :         }
    4236             :     }
    4237      393674 :     hTcBuffer->n_samples_rendered = 0;
    4238      393674 :     move16();
    4239      393674 :     hTcBuffer->subframes_rendered = 0;
    4240      393674 :     move16();
    4241             : 
    4242      393674 :     return;
    4243             : }
    4244             : 
    4245             : /*--------------------------------------------------------------------------*
    4246             :  * ivas_jbm_dec_metadata_open()
    4247             :  *
    4248             :  * Open structure for metadata buffering in JBM
    4249             :  *--------------------------------------------------------------------------*/
    4250             : 
    4251           3 : ivas_error ivas_jbm_dec_metadata_open(
    4252             :     Decoder_Struct *st_ivas )
    4253             : {
    4254             :     JBM_METADATA_HANDLE hJbmMetadata;
    4255           3 :     IF( ( hJbmMetadata = (JBM_METADATA_HANDLE) malloc( sizeof( JBM_METADATA ) ) ) == NULL )
    4256             :     {
    4257           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM metadata handle\n" ) );
    4258             :     }
    4259           3 :     hJbmMetadata->sf_write_idx = 0;
    4260           3 :     move16();
    4261           3 :     hJbmMetadata->sf_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_PARAM_SPATIAL_SUBFRAMES;
    4262           3 :     move16();
    4263             : 
    4264           3 :     hJbmMetadata->slot_write_idx = 0;
    4265           3 :     move16();
    4266           3 :     hJbmMetadata->slot_read_idx = 0;
    4267           3 :     move16();
    4268           3 :     hJbmMetadata->slot_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
    4269           3 :     move16();
    4270             : 
    4271           3 :     st_ivas->hJbmMetadata = hJbmMetadata;
    4272             : 
    4273           3 :     return IVAS_ERR_OK;
    4274             : }
    4275             : 
    4276             : 
    4277             : /*--------------------------------------------------------------------------*
    4278             :  * ivas_jbm_dec_copy_masa_meta_to_buffer()
    4279             :  *
    4280             :  * Copy decoded MASA metadata to a ring buffer
    4281             :  *--------------------------------------------------------------------------*/
    4282             : 
    4283        1305 : static void ivas_jbm_dec_copy_masa_meta_to_buffer(
    4284             :     Decoder_Struct *st_ivas )
    4285             : {
    4286             :     Word16 sf, dir, band;
    4287             :     JBM_METADATA_HANDLE hJbmMetadata;
    4288             :     MASA_DECODER_EXT_OUT_META *extOutMeta;
    4289             :     Word16 write_idx;
    4290             : 
    4291        1305 :     hJbmMetadata = st_ivas->hJbmMetadata;
    4292        1305 :     extOutMeta = st_ivas->hMasa->data.extOutMeta;
    4293             : 
    4294        6525 :     FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
    4295             :     {
    4296        5220 :         write_idx = ( hJbmMetadata->sf_write_idx + sf ) % hJbmMetadata->sf_md_buffer_length;
    4297        5220 :         move16();
    4298       15660 :         FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
    4299             :         {
    4300      261000 :             FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    4301             :             {
    4302      250560 :                 hJbmMetadata->directionIndexBuffer[dir][write_idx][band] = extOutMeta->directionIndex[dir][sf][band];
    4303      250560 :                 move16();
    4304      250560 :                 hJbmMetadata->directToTotalRatioBuffer[dir][write_idx][band] = extOutMeta->directToTotalRatio[dir][sf][band];
    4305      250560 :                 move16();
    4306      250560 :                 hJbmMetadata->spreadCoherenceBuffer[dir][write_idx][band] = extOutMeta->spreadCoherence[dir][sf][band];
    4307      250560 :                 move16();
    4308             :             }
    4309             :         }
    4310             : 
    4311      130500 :         FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    4312             :         {
    4313      125280 :             hJbmMetadata->diffuseToTotalRatioBuffer[write_idx][band] = extOutMeta->diffuseToTotalRatio[sf][band];
    4314      125280 :             move16();
    4315      125280 :             hJbmMetadata->surroundCoherenceBuffer[write_idx][band] = extOutMeta->surroundCoherence[sf][band];
    4316      125280 :             move16();
    4317             :         }
    4318             : 
    4319        5220 :         hJbmMetadata->numberOfDirections[write_idx] = extOutMeta->descriptiveMeta.numberOfDirections;
    4320        5220 :         move16();
    4321             :     }
    4322             : 
    4323        1305 :     return;
    4324             : }
    4325             : 
    4326             : 
    4327             : /*--------------------------------------------------------------------------*
    4328             :  * ivas_jbm_masa_sf_to_slot_map()
    4329             :  *
    4330             :  * Map input MASA metadata subframes to slots in JBM processing
    4331             :  *--------------------------------------------------------------------------*/
    4332        1305 : static void ivas_jbm_masa_sf_to_slot_map(
    4333             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure     */
    4334             :     const Word16 nCldfbTs    /* i  : number of CLDFB time slots */
    4335             : )
    4336             : {
    4337             :     Word16 sf_to_slot_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME];
    4338             :     Word16 num_slots_in_subfr;
    4339             :     JBM_METADATA_HANDLE hJbmMetadata;
    4340             :     Word16 slot_idx;
    4341             :     Word16 write_idx, sf_index;
    4342             : 
    4343             :     /* Set values */
    4344        1305 :     hJbmMetadata = st_ivas->hJbmMetadata;
    4345        1305 :     num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
    4346        1305 :     move16();
    4347             : 
    4348             :     /* Map input subframes to slots */
    4349        1305 :     ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, MAX_PARAM_SPATIAL_SUBFRAMES, sf_to_slot_map );
    4350             : 
    4351       22205 :     FOR( slot_idx = 0; slot_idx < nCldfbTs; slot_idx++ )
    4352             :     {
    4353       20900 :         write_idx = ( add( hJbmMetadata->slot_write_idx, slot_idx ) ) % hJbmMetadata->slot_md_buffer_length;
    4354       20900 :         move16();
    4355       20900 :         sf_index = ( add( hJbmMetadata->sf_write_idx, sf_to_slot_map[slot_idx] ) ) % hJbmMetadata->sf_md_buffer_length;
    4356       20900 :         move16();
    4357             : 
    4358       20900 :         hJbmMetadata->sf_to_slot_map[write_idx] = sf_index;
    4359       20900 :         move16();
    4360             :     }
    4361             : 
    4362        1305 :     hJbmMetadata->sf_write_idx = ( add( hJbmMetadata->sf_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) ) % hJbmMetadata->sf_md_buffer_length;
    4363        1305 :     move16();
    4364        1305 :     hJbmMetadata->slot_write_idx = ( add( hJbmMetadata->slot_write_idx, nCldfbTs ) ) % hJbmMetadata->slot_md_buffer_length;
    4365        1305 :     move16();
    4366             : 
    4367        1305 :     return;
    4368             : }
    4369             : 
    4370             : /*--------------------------------------------------------------------------*
    4371             :  * ivas_jbm_masa_sf_to_sf_map()
    4372             :  *
    4373             :  * Map input MASA metadata subframes to output subframes in JBM processing
    4374             :  *--------------------------------------------------------------------------*/
    4375             : 
    4376        1305 : void ivas_jbm_masa_sf_to_sf_map(
    4377             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
    4378             : )
    4379             : {
    4380             :     Word16 sf_to_sf_map[MAX_PARAM_SPATIAL_SUBFRAMES];
    4381             :     JBM_METADATA_HANDLE hJbmMetadata;
    4382             :     MASA_DECODER_EXT_OUT_META *extOutMeta;
    4383             :     Word16 slot_read_idx, sf_read_idx;
    4384             :     Word16 sf_idx;
    4385             :     Word16 dir, band;
    4386             :     UWord8 numberOfDirections;
    4387             : 
    4388             :     /* Set values */
    4389        1305 :     hJbmMetadata = st_ivas->hJbmMetadata;
    4390        1305 :     extOutMeta = st_ivas->hMasa->data.extOutMeta;
    4391             : 
    4392             :     /* Map slots to subframes */
    4393        6525 :     FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    4394             :     {
    4395        5220 :         slot_read_idx = ( add( hJbmMetadata->slot_read_idx, 2 ) ) % hJbmMetadata->slot_md_buffer_length; /* Take the latter one of the middle slots of the output subframe */
    4396        5220 :         move16();
    4397        5220 :         sf_to_sf_map[sf_idx] = hJbmMetadata->sf_to_slot_map[slot_read_idx];
    4398        5220 :         move16();
    4399        5220 :         hJbmMetadata->slot_read_idx = ( add( hJbmMetadata->slot_read_idx, CLDFB_SLOTS_PER_SUBFRAME ) ) % hJbmMetadata->slot_md_buffer_length;
    4400        5220 :         move16();
    4401             :     }
    4402             : 
    4403             :     /* Copy mapped metadata to the EXT meta buffer for writing */
    4404        6525 :     FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    4405             :     {
    4406        5220 :         sf_read_idx = sf_to_sf_map[sf_idx];
    4407        5220 :         move16();
    4408             : 
    4409       15660 :         FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
    4410             :         {
    4411      261000 :             FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    4412             :             {
    4413      250560 :                 extOutMeta->directionIndex[dir][sf_idx][band] = hJbmMetadata->directionIndexBuffer[dir][sf_read_idx][band];
    4414      250560 :                 move16();
    4415      250560 :                 extOutMeta->directToTotalRatio[dir][sf_idx][band] = hJbmMetadata->directToTotalRatioBuffer[dir][sf_read_idx][band];
    4416      250560 :                 move16();
    4417      250560 :                 extOutMeta->spreadCoherence[dir][sf_idx][band] = hJbmMetadata->spreadCoherenceBuffer[dir][sf_read_idx][band];
    4418      250560 :                 move16();
    4419             :             }
    4420             :         }
    4421             : 
    4422      130500 :         FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    4423             :         {
    4424      125280 :             extOutMeta->diffuseToTotalRatio[sf_idx][band] = hJbmMetadata->diffuseToTotalRatioBuffer[sf_read_idx][band];
    4425      125280 :             move16();
    4426      125280 :             extOutMeta->surroundCoherence[sf_idx][band] = hJbmMetadata->surroundCoherenceBuffer[sf_read_idx][band];
    4427      125280 :             move16();
    4428             :         }
    4429             :     }
    4430             : 
    4431             :     /* Determine the number of directions for the frame to be written */
    4432        1305 :     numberOfDirections = 0;
    4433        1305 :     move16();
    4434        5579 :     FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    4435             :     {
    4436        4512 :         sf_read_idx = sf_to_sf_map[sf_idx];
    4437        4512 :         move16();
    4438             : 
    4439        4512 :         IF( hJbmMetadata->numberOfDirections[sf_read_idx] == 1 )
    4440             :         {
    4441         238 :             numberOfDirections = 1;
    4442         238 :             move16();
    4443         238 :             BREAK;
    4444             :         }
    4445             :     }
    4446             : 
    4447        1305 :     extOutMeta->descriptiveMeta.numberOfDirections = numberOfDirections;
    4448        1305 :     move16();
    4449             : 
    4450        1305 :     return;
    4451             : }
    4452             : 
    4453             : #ifdef OBJ_EDITING_API
    4454             : /*--------------------------------------------------------------------------*
    4455             :  * ivas_jbm_dec_prepare_renderer()
    4456             :  *
    4457             :  * prepare IVAS JBM renderer routine
    4458             :  *--------------------------------------------------------------------------*/
    4459             : 
    4460      413225 : void ivas_jbm_dec_prepare_renderer(
    4461             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure                                      */
    4462             : )
    4463             : {
    4464             :     Word16 n, n_render_timeslots, tmp, exp;
    4465             : 
    4466      413225 :     push_wmops( "ivas_jbm_dec_feed_tc_to_rendererer" );
    4467             : 
    4468             :     /* n_render_timeslots = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; */
    4469      413225 :     tmp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &exp );
    4470      413225 :     n_render_timeslots = shr( tmp, sub( 15, exp ) ); // Q0
    4471             : 
    4472             : 
    4473      413225 :     IF( EQ_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
    4474             :     {
    4475      128632 :         ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    4476             : 
    4477      128632 :         test();
    4478      128632 :         test();
    4479      128632 :         test();
    4480      128632 :         IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && st_ivas->hDecoderConfig->Opt_tsm )
    4481             :         {
    4482        1305 :             ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
    4483             :         }
    4484             :     }
    4485      284593 :     ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) )
    4486             :     {
    4487           0 :         ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    4488             :     }
    4489      284593 :     ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
    4490             :     {
    4491             :         /* Rendering */
    4492       69225 :         IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) )
    4493             :         {
    4494       13208 :             test();
    4495       13208 :             test();
    4496       13208 :             IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
    4497             :             {
    4498        7955 :                 ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots );
    4499             : 
    4500        7955 :                 ivas_param_ism_params_to_masa_param_mapping_fx( st_ivas );
    4501             :             }
    4502        5253 :             ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
    4503             :             {
    4504        5253 :                 ivas_param_ism_dec_prepare_renderer_fx( st_ivas, n_render_timeslots );
    4505             :             }
    4506             :         }
    4507             :         ELSE /* ISM_MODE_DISC */
    4508             :         {
    4509       56017 :             ivas_ism_dec_digest_tc_fx( st_ivas );
    4510             :         }
    4511             :     }
    4512      215368 :     ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
    4513             :     {
    4514      139601 :         IF( st_ivas->hSCE[0] )
    4515             :         {
    4516       44371 :             Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    4517       44371 :             IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    4518             :             {
    4519        3718 :                 shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    4520             :             }
    4521       44371 :             scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
    4522       44371 :             st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    4523             :         }
    4524      139601 :         ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    4525             :     }
    4526       75767 :     ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    4527             :     {
    4528             : 
    4529       30404 :         IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    4530             :         {
    4531       18680 :             ivas_ism_dec_digest_tc_fx( st_ivas );
    4532             : 
    4533       18680 :             test();
    4534       18680 :             test();
    4535       18680 :             test();
    4536       18680 :             test();
    4537             :             /* delay the objects here for all renderers where it is needed */
    4538       18680 :             IF(
    4539             :                 (
    4540             :                     EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
    4541             :                     EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
    4542             :                     EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
    4543             :                     EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
    4544             :                     EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) &&
    4545             :                 ( NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) )
    4546             :             {
    4547       70240 :                 FOR( n = 0; n < st_ivas->nchan_ism; n++ )
    4548             :                 {
    4549       52960 :                     delay_signal32_fx( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer_fx[n], st_ivas->hSbaIsmData->delayBuffer_size );
    4550             :                 }
    4551             :             }
    4552             : 
    4553       18680 :             IF( !st_ivas->sba_dirac_stereo_flag )
    4554             :             {
    4555       17280 :                 IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
    4556             :                 {
    4557             :                     Word16 temp, temp_e;
    4558        8880 :                     temp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size, &temp_e );
    4559        8880 :                     n_render_timeslots = extract_l( L_shr( L_mult0( n_render_timeslots, temp ), sub( 15, temp_e ) ) );
    4560             :                 }
    4561             : 
    4562       17280 :                 IF( st_ivas->hSCE[0] )
    4563             :                 {
    4564           0 :                     Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    4565           0 :                     if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    4566             :                     {
    4567           0 :                         shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    4568             :                     }
    4569           0 :                     scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
    4570           0 :                     st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    4571             :                 }
    4572       17280 :                 ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    4573             :             }
    4574             :         }
    4575             :         ELSE
    4576             :         {
    4577       11724 :             ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    4578             : 
    4579       11724 :             IF( st_ivas->hSCE[0] )
    4580             :             {
    4581        6254 :                 Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    4582        6254 :                 if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    4583             :                 {
    4584         130 :                     shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    4585             :                 }
    4586        6254 :                 scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
    4587        6254 :                 st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    4588             :             }
    4589       11724 :             ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    4590             :         }
    4591             :     }
    4592       45363 :     ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
    4593             :     {
    4594        4916 :         test();
    4595        4916 :         IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) )
    4596             :         {
    4597          76 :             ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    4598          76 :             IF( st_ivas->hDecoderConfig->Opt_tsm )
    4599             :             {
    4600           0 :                 ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
    4601             :             }
    4602             :         }
    4603             :         ELSE
    4604             :         {
    4605        4840 :             test();
    4606        4840 :             IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
    4607             :             {
    4608         108 :                 n_render_timeslots = i_mult( n_render_timeslots, idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ) );
    4609             :             }
    4610             : 
    4611        4840 :             IF( st_ivas->hSCE[0] )
    4612             :             {
    4613        4840 :                 Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    4614        4840 :                 if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    4615             :                 {
    4616         426 :                     shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    4617             :                 }
    4618        4840 :                 scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31- (st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp - shift)
    4619        4840 :                 st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    4620        4840 :                 move16();
    4621             :             }
    4622        4840 :             ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    4623             : 
    4624        4840 :             IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
    4625             :             {
    4626        1783 :                 ivas_ism_dec_digest_tc_fx( st_ivas );
    4627             :             }
    4628             :         }
    4629             : 
    4630        4916 :         test();
    4631        4916 :         IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) )
    4632             :         {
    4633             :             Word16 num_objects;
    4634             : 
    4635             :             /* Delay the signal to match CLDFB delay. Delay the whole buffer. */
    4636        2848 :             num_objects = 0;
    4637        2848 :             move16();
    4638             : 
    4639        2848 :             test();
    4640        2848 :             test();
    4641        2848 :             IF( ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) )
    4642             :             {
    4643        1410 :                 num_objects = 1;
    4644        1410 :                 move16();
    4645             :             }
    4646        1438 :             ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
    4647             :             {
    4648        1062 :                 num_objects = st_ivas->nchan_ism;
    4649        1062 :                 move16();
    4650             :             }
    4651        7046 :             FOR( n = 0; n < num_objects; n++ )
    4652             :             {
    4653        4198 :                 test();
    4654        4198 :                 IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) )
    4655             :                 {
    4656         432 :                     v_multc_fixed_16( st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], OMASA_TDREND_MATCHING_GAIN_FX, st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available );
    4657             :                 }
    4658        4198 :                 delay_signal32_fx( st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hMasaIsmData->delayBuffer_fx[n], st_ivas->hMasaIsmData->delayBuffer_size );
    4659             :             }
    4660             :         }
    4661             :     }
    4662       40447 :     ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
    4663             :     {
    4664       40447 :         IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
    4665             :         {
    4666       20539 :             ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    4667             :         }
    4668       19908 :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
    4669             :         {
    4670         780 :             ivas_mc_paramupmix_dec_digest_tc( st_ivas, (UWord8) n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    4671             :         }
    4672       19128 :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
    4673             :         {
    4674       10229 :             Word16 nchan_transport = st_ivas->nchan_transport;
    4675       10229 :             move16();
    4676       10229 :             Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    4677             :             Word16 nchan_out_cov;
    4678       10229 :             test();
    4679       10229 :             test();
    4680       10229 :             IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    4681             :             {
    4682        8239 :                 nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
    4683             :             }
    4684        1990 :             ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
    4685             :             {
    4686         340 :                 nchan_out_cov = nchan_out_transport;
    4687         340 :                 move16();
    4688             :             }
    4689        1650 :             ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
    4690             :             {
    4691         150 :                 nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
    4692             :             }
    4693             :             ELSE
    4694             :             {
    4695        1500 :                 nchan_out_cov = nchan_out_transport;
    4696        1500 :                 move16();
    4697             :             }
    4698             : 
    4699       10229 :             scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); // Q(31-1)
    4700       10229 :             st_ivas->hParamMC->proto_matrix_int_e = 1;
    4701       10229 :             move16();
    4702             : 
    4703       10229 :             ivas_param_mc_dec_prepare_renderer( st_ivas, (UWord8) n_render_timeslots );
    4704             : 
    4705       10229 :             scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); // Q(31-1+1)
    4706             : 
    4707             :             Word16 shift;
    4708      143016 :             FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ )
    4709             :             {
    4710      132787 :                 shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ) );
    4711      132787 :                 scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, i_mult( nchan_transport, nchan_transport ) ), shift ); // Q(31-cx_old_e+shift)
    4712      132787 :                 st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], shift );
    4713      132787 :                 move16();
    4714             : 
    4715      132787 :                 shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov );
    4716      132787 :                 scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], i_mult( nchan_out_cov, nchan_out_cov ), shift ); // Q(31-cy_old_e+shift)
    4717      132787 :                 st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], shift );
    4718      132787 :                 move16();
    4719             :             }
    4720             :         }
    4721        8899 :         ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
    4722             :         {
    4723        8899 :             IF( st_ivas->hSCE[0] )
    4724             :             {
    4725        8649 :                 Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
    4726        8649 :                 if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
    4727             :                 {
    4728        1164 :                     shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
    4729             :                 }
    4730        8649 :                 scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
    4731        8649 :                 st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
    4732        8649 :                 move16();
    4733             :             }
    4734        8899 :             ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    4735             :         }
    4736             :     }
    4737             : 
    4738      413225 :     pop_wmops();
    4739      413225 :     return;
    4740             : }
    4741             : #endif

Generated by: LCOV version 1.14