LCOV - code coverage report
Current view: top level - lib_dec - ivas_dirac_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 43b7b28dcb1471ff5d355252c4b8f37ee7ecc268 Lines: 1928 2116 91.1 %
Date: 2025-11-02 02:02:47 Functions: 10 11 90.9 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <assert.h>
      34             : #include <stdint.h>
      35             : #include "options.h"
      36             : #include <math.h>
      37             : #include "cnst.h"
      38             : #include "prot_fx.h"
      39             : #include "ivas_prot_rend_fx.h"
      40             : #include "ivas_cnst.h"
      41             : #include "ivas_rom_com.h"
      42             : #include "ivas_rom_dec.h"
      43             : #include "ivas_rom_rend.h"
      44             : #include "wmc_auto.h"
      45             : #include "ivas_prot_fx.h"
      46             : 
      47             : 
      48             : /*-----------------------------------------------------------------------*
      49             :  * Local function prototypes
      50             :  *-----------------------------------------------------------------------*/
      51             : 
      52        4668 : static ivas_error ivas_dirac_dec_config_internal_fx(
      53             :     Decoder_Struct *st_ivas,                /* i/o: IVAS decoder structure  */
      54             :     const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
      55             : )
      56             : {
      57             :     DIRAC_DEC_HANDLE hDirAC;
      58             :     ivas_error error;
      59             :     DIRAC_CONFIG_FLAG flag_config;
      60             : 
      61        4668 :     IF( EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
      62             :     {
      63           0 :         flag_config = DIRAC_RECONFIGURE;
      64           0 :         move32();
      65             :     }
      66             :     ELSE
      67             :     {
      68        4668 :         flag_config = flag_config_inp;
      69        4668 :         move32();
      70             :     }
      71        4668 :     error = IVAS_ERR_OK;
      72        4668 :     move32();
      73             : 
      74        4668 :     hDirAC = NULL;
      75             : 
      76        4668 :     IF( EQ_32( flag_config, DIRAC_RECONFIGURE ) )
      77             :     {
      78        4150 :         hDirAC = st_ivas->hDirAC;
      79             :     }
      80         518 :     ELSE IF( EQ_32( flag_config, DIRAC_OPEN ) )
      81             :     {
      82             :         /*-----------------------------------------------------------------*
      83             :          * prepare library opening
      84             :          *-----------------------------------------------------------------*/
      85             : 
      86         518 :         IF( ( hDirAC = (DIRAC_DEC_HANDLE) malloc( sizeof( DIRAC_DEC_DATA ) ) ) == NULL )
      87             :         {
      88           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
      89             :         }
      90             : 
      91         518 :         IF( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL )
      92             :         {
      93           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) );
      94             :         }
      95             : 
      96         518 :         st_ivas->hDirAC = hDirAC;
      97             :     }
      98             : 
      99             :     /*-----------------------------------------------------------------*
     100             :      * DirAC main configuration
     101             :      *-----------------------------------------------------------------*/
     102             : 
     103        4668 :     IF( NE_32( ( error = ivas_dirac_config_fx( (void *) st_ivas, DEC ) ), IVAS_ERR_OK ) )
     104             :     {
     105           0 :         return error;
     106             :     }
     107             : 
     108        4668 :     IF( EQ_32( flag_config, DIRAC_OPEN ) )
     109             :     {
     110         518 :         test();
     111         518 :         IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     112             :         {
     113         139 :             hDirAC->spar_to_dirac_write_idx = DELAY_DIRAC_PARAM_DEC_SFR;
     114         139 :             move16();
     115             :         }
     116             :         ELSE
     117             :         {
     118         379 :             hDirAC->spar_to_dirac_write_idx = 0;
     119         379 :             move16();
     120             :         }
     121         518 :         hDirAC->dithering_seed = DIRAC_DITH_SEED;
     122         518 :         move16();
     123         518 :         st_ivas->hDirAC = hDirAC;
     124             :     }
     125             : 
     126        4668 :     return error;
     127             : }
     128             : 
     129        2290 : static ivas_error ivas_dirac_rend_config_fx(
     130             :     Decoder_Struct *st_ivas,                 /* i/o: IVAS decoder structure  */
     131             :     const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
     132             :     const Word16 dec_param_estim_old )
     133             : {
     134             :     DIRAC_DEC_HANDLE hDirAC;
     135             :     Word16 nchan_out_woLFE;
     136             :     Word16 nchan_transport;
     137             :     Word16 nchan_transport_old;
     138             :     Word16 num_outputs_dir_old;
     139             :     Word16 num_outputs_diff_old;
     140             :     Word16 num_protos_diff_old;
     141             :     Word32 *proto_frame_f_old_fx;
     142             :     Word16 proto_signal_decorr_on_old;
     143             :     UWord16 i, j, k;
     144             :     Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS];
     145             :     Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS];
     146             :     Word32 output_Fs, ivas_total_brate;
     147             :     ivas_error error;
     148             :     Word16 nchan_transport_orig;
     149             :     Word16 hodirac_flag;
     150             :     DIRAC_CONFIG_FLAG flag_config;
     151             :     DIRAC_REND_HANDLE hDirACRend;
     152             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
     153             : 
     154       38930 :     FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
     155             :     {
     156       36640 :         ls_azimuth_fx[i] = 0;
     157       36640 :         move32();
     158       36640 :         ls_elevation_fx[i] = 0;
     159       36640 :         move32();
     160             :     }
     161             : 
     162        2290 :     IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
     163             :     {
     164         705 :         flag_config = DIRAC_RECONFIGURE;
     165         705 :         move32();
     166             :     }
     167             :     ELSE
     168             :     {
     169        1585 :         flag_config = flag_config_inp;
     170        1585 :         move32();
     171             :     }
     172        2290 :     error = IVAS_ERR_OK;
     173        2290 :     move32();
     174             : 
     175        2290 :     hDirACRend = NULL;
     176        2290 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     177        2290 :     move32();
     178        2290 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     179        2290 :     move32();
     180        2290 :     hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
     181             : 
     182        2290 :     hDirAC = st_ivas->hDirAC;
     183        2290 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
     184             : 
     185        2290 :     IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) )
     186             :     {
     187        1857 :         hDirACRend = st_ivas->hDirACRend;
     188             :     }
     189         433 :     ELSE IF( EQ_16( flag_config, DIRAC_OPEN ) )
     190             :     {
     191             :         /*-----------------------------------------------------------------*
     192             :          * prepare library opening
     193             :          *-----------------------------------------------------------------*/
     194             : 
     195         433 :         IF( ( hDirACRend = (DIRAC_REND_HANDLE) malloc( sizeof( DIRAC_REND_DATA ) ) ) == NULL )
     196             :         {
     197           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC renderer\n" ) );
     198             :         }
     199             : 
     200         433 :         nchan_transport_old = 0;
     201         433 :         move16();
     202             :     }
     203             : 
     204        2290 :     nchan_transport_old = 0;
     205        2290 :     move16();
     206        2290 :     num_outputs_dir_old = 0;
     207        2290 :     move16();
     208        2290 :     num_outputs_diff_old = 0;
     209        2290 :     move16();
     210        2290 :     num_protos_diff_old = 0;
     211        2290 :     move16();
     212             : 
     213        2290 :     nchan_transport_orig = st_ivas->nchan_transport;
     214        2290 :     move16();
     215        2290 :     test();
     216        2290 :     IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     217             :     {
     218         939 :         st_ivas->nchan_transport = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
     219         939 :         move16();
     220             :     }
     221             : 
     222        2290 :     nchan_transport = st_ivas->nchan_transport;
     223        2290 :     move16();
     224        2290 :     test();
     225        2290 :     test();
     226        2290 :     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 ) )
     227             :     {
     228         275 :         nchan_transport = 1;
     229         275 :         move16();
     230             :     }
     231        2290 :     test();
     232        2290 :     test();
     233        2290 :     IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
     234             :     {
     235             :         Word16 tmp1, tmp2, tmp3;
     236         705 :         ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 );
     237             :     }
     238             : 
     239             :     /*-----------------------------------------------------------------*
     240             :      * output setup: for parametric binaural renderer, use output setup, otherwise internal setup
     241             :      *-----------------------------------------------------------------*/
     242             : 
     243        2290 :     hDirACRend->hOutSetup = st_ivas->hIntSetup;
     244        2290 :     nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE;
     245        2290 :     move16();
     246             : 
     247        2290 :     test();
     248        2290 :     IF( hDirACRend->hOutSetup.ls_azimuth_fx != NULL && hDirACRend->hOutSetup.ls_elevation_fx != NULL )
     249             :     {
     250         934 :         Copy32( hDirACRend->hOutSetup.ls_azimuth_fx, ls_azimuth_fx, nchan_out_woLFE );
     251         934 :         Copy32( hDirACRend->hOutSetup.ls_elevation_fx, ls_elevation_fx, nchan_out_woLFE );
     252             :     }
     253             : 
     254        2290 :     IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, -1 ) )
     255             :     {
     256        1043 :         hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */
     257        1043 :         move16();
     258        1043 :         test();
     259        1043 :         if ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) )
     260             :         {
     261         109 :             hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER;
     262         109 :             move16();
     263             :         }
     264             :     }
     265        1247 :     ELSE IF( GE_16( hDirACRend->hOutSetup.ambisonics_order, SBA_FOA_ORDER ) )
     266             :     {
     267        1247 :         Copy32( ls_azimuth_4d4_fx, ls_azimuth_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
     268        1247 :         Copy32( ls_elevation_4d4_fx, ls_elevation_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
     269             :     }
     270             : 
     271        2290 :     test();
     272        2290 :     test();
     273        2290 :     test();
     274        2290 :     test();
     275        2290 :     test();
     276        2290 :     test();
     277        2290 :     test();
     278        2290 :     IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
     279             :     {
     280             :         /* Remove the channel of the separated signal from the output setup of the spatial synthesis */
     281          25 :         hDirACRend->hOutSetup.nchan_out_woLFE = sub( hDirACRend->hOutSetup.nchan_out_woLFE, 1 );
     282          25 :         move16();
     283          25 :         nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE;
     284          25 :         move16();
     285          25 :         Copy32( &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) );
     286          25 :         Copy32( &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) );
     287             :     }
     288             : 
     289             :     /*-----------------------------------------------------------------*
     290             :      * set input parameters
     291             :      *-----------------------------------------------------------------*/
     292             : 
     293        2290 :     st_ivas->nchan_transport = nchan_transport_orig;
     294        2290 :     move16();
     295             : 
     296        2290 :     test();
     297        2290 :     test();
     298        2290 :     test();
     299        2290 :     test();
     300        2290 :     test();
     301        2290 :     test();
     302        2290 :     test();
     303        2290 :     test();
     304        2290 :     test();
     305        2290 :     test();
     306        2290 :     test();
     307        2290 :     IF( GT_16( nchan_transport_orig, 2 ) && hDirACRend->hOutSetup.is_loudspeaker_setup && EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && !hodirac_flag )
     308             :     {
     309          46 :         hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
     310          46 :         move32();
     311          46 :         hDirACRend->panningConf = DIRAC_PANNING_VBAP;
     312          46 :         move32();
     313             :     }
     314        2244 :     ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) )
     315             :     {
     316         109 :         hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO;
     317         109 :         move32();
     318         109 :         hDirACRend->panningConf = DIRAC_PANNING_HOA3;
     319         109 :         move32();
     320         109 :         nchan_out_woLFE = 1;
     321         109 :         move16();
     322             :     }
     323        2135 :     ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && hDirACRend->hOutSetup.is_loudspeaker_setup )
     324             :     {
     325         830 :         hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
     326         830 :         move32();
     327         830 :         hDirACRend->panningConf = DIRAC_PANNING_VBAP;
     328         830 :         move32();
     329             :     }
     330        1305 :     ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && !hDirACRend->hOutSetup.is_loudspeaker_setup && GT_32( st_ivas->nchan_transport, 1 ) )
     331             :     {
     332         409 :         hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD;
     333         409 :         move32();
     334         409 :         hDirACRend->panningConf = DIRAC_PANNING_HOA3;
     335         409 :         move32();
     336             :     }
     337             :     ELSE
     338             :     {
     339         896 :         hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD;
     340         896 :         move32();
     341         896 :         hDirACRend->panningConf = DIRAC_PANNING_HOA3;
     342         896 :         move32();
     343             :     }
     344             : 
     345        2290 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     346             :     {
     347         433 :         IF( ( hDirACRend->frequency_axis_fx = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL )
     348             :         {
     349           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     350             :         }
     351         433 :         set16_fx( hDirACRend->frequency_axis_fx, 0, hSpatParamRendCom->num_freq_bands );
     352         433 :         ivas_dirac_dec_get_frequency_axis_fx( hDirACRend->frequency_axis_fx, output_Fs, hSpatParamRendCom->num_freq_bands );
     353             :     }
     354             : 
     355        2290 :     test();
     356        2290 :     test();
     357        2290 :     test();
     358        2290 :     IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) && EQ_16( nchan_transport, 2 ) )
     359             :     {
     360         136 :         test();
     361         136 :         test();
     362         136 :         IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect == NULL ) || EQ_16( flag_config, DIRAC_OPEN ) )
     363             :         {
     364          82 :             IF( ( hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL )
     365             :             {
     366           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     367             :             }
     368             :         }
     369         136 :         ivas_masa_init_stereotype_detection_fx( hDirACRend->masa_stereo_type_detect );
     370             :     }
     371             :     ELSE
     372             :     {
     373        2154 :         test();
     374        2154 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect != NULL )
     375             :         {
     376          24 :             free( hDirACRend->masa_stereo_type_detect );
     377             :         }
     378        2154 :         hDirACRend->masa_stereo_type_detect = NULL;
     379             :     }
     380             : 
     381        2290 :     hSpatParamRendCom->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */
     382        2290 :     move16();
     383             : 
     384             :     /*-----------------------------------------------------------------*
     385             :      * (re)configure sub-modules
     386             :      *-----------------------------------------------------------------*/
     387             : 
     388             :     /* prototype signal computation */
     389        2290 :     IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) )
     390             :     {
     391        1857 :         num_outputs_dir_old = hDirACRend->num_outputs_dir;
     392        1857 :         move16();
     393        1857 :         num_outputs_diff_old = hDirACRend->num_outputs_diff;
     394        1857 :         move16();
     395        1857 :         num_protos_diff_old = hDirACRend->num_protos_diff;
     396        1857 :         move16();
     397             :     }
     398             : 
     399             :     /* allocate output setup related arrays */
     400        2290 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
     401             :     {
     402             :         /* Directional and diffuses components in output LS format */
     403         876 :         hDirACRend->num_outputs_diff = nchan_out_woLFE;
     404         876 :         move16();
     405         876 :         hDirACRend->num_outputs_dir = nchan_out_woLFE;
     406         876 :         move16();
     407             :     }
     408        1414 :     ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
     409             :     {
     410             :         /* Directional and diffuses components in SHD */
     411             :         /* Diffuseness components up to 1st order */
     412         896 :         hDirACRend->num_outputs_diff = mult0( ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) );
     413         896 :         move16();
     414         896 :         hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 );
     415         896 :         move16();
     416             :     }
     417         518 :     ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
     418             :     {
     419         409 :         hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS;
     420         409 :         move16();
     421         409 :         hDirACRend->num_outputs_dir = nchan_out_woLFE;
     422         409 :         move16();
     423             :     }
     424         109 :     ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
     425             :     {
     426         109 :         hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */
     427         109 :         move16();
     428         109 :         hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */
     429         109 :         move16();
     430             :     }
     431             :     ELSE
     432             :     {
     433           0 :         assert( 0 && "DirAC: not existing synthesis methods!" );
     434             :     }
     435             : 
     436        2290 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     437             :     {
     438         433 :         num_outputs_dir_old = hDirACRend->num_outputs_dir;
     439         433 :         move16();
     440         433 :         IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL )
     441             :         {
     442           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     443             :         }
     444         433 :         num_outputs_diff_old = hDirACRend->num_outputs_diff;
     445         433 :         move16();
     446         433 :         IF( ( hDirACRend->proto_index_diff = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_diff ) ) == NULL )
     447             :         {
     448           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     449             :         }
     450             :     }
     451             : 
     452        2290 :     test();
     453        2290 :     IF( NE_16( hDirACRend->num_outputs_dir, num_outputs_dir_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) )
     454             :     {
     455          61 :         free( hDirACRend->proto_index_dir );
     456          61 :         IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL )
     457             :         {
     458           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     459             :         }
     460             :     }
     461        2290 :     set16_fx( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir );
     462             : 
     463        2290 :     test();
     464        2290 :     IF( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) )
     465             :     {
     466          61 :         free( hDirACRend->proto_index_diff );
     467          61 :         IF( ( hDirACRend->proto_index_diff = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_diff ) ) == NULL )
     468             :         {
     469           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     470             :         }
     471             :     }
     472        2290 :     set16_fx( hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff );
     473             : 
     474        2290 :     hDirACRend->sba_map_tc = sba_map_tc;
     475             : 
     476        2290 :     test();
     477        2290 :     IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
     478             :     {
     479         939 :         test();
     480         939 :         if ( GT_16( st_ivas->sba_order, SBA_FOA_ORDER ) && GE_32( ivas_total_brate, IVAS_512k ) )
     481             :         {
     482          66 :             hDirACRend->sba_map_tc = sba_map_tc_512;
     483             :         }
     484             :     }
     485             : 
     486        2290 :     IF( EQ_16( nchan_transport, 1 ) )
     487             :     {
     488         482 :         hDirACRend->num_protos_ambi = 1;
     489         482 :         move16();
     490         482 :         hDirACRend->num_protos_dir = 1;
     491         482 :         move16();
     492         482 :         hDirACRend->num_protos_diff = 1;
     493         482 :         move16();
     494             :     }
     495        1808 :     ELSE IF( EQ_16( nchan_transport, 2 ) )
     496             :     {
     497         869 :         IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
     498             :         {
     499           0 :             hDirACRend->num_protos_ambi = 2;
     500           0 :             move16();
     501           0 :             hDirACRend->num_protos_diff = 1;
     502           0 :             move16();
     503           0 :             hDirACRend->num_protos_dir = 2;
     504           0 :             move16();
     505           0 :             hDirACRend->proto_index_dir[1] = 1;
     506           0 :             move16();
     507             :         }
     508         869 :         ELSE IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) )
     509             :         {
     510             :             /* Following the foa rendering for code compatibility */
     511         109 :             hDirACRend->num_protos_ambi = 2;
     512         109 :             move16();
     513         109 :             hDirACRend->num_protos_dir = 2;
     514         109 :             move16();
     515         109 :             hDirACRend->num_protos_diff = 3;
     516         109 :             move16();
     517         109 :             hDirACRend->proto_index_dir[0] = 0;
     518         109 :             move16();
     519         109 :             hDirACRend->proto_index_diff[0] = 0;
     520         109 :             move16();
     521             :         }
     522             :         ELSE
     523             :         {
     524         760 :             hDirACRend->num_protos_ambi = 2;
     525         760 :             move16();
     526         760 :             hDirACRend->num_protos_diff = 3;
     527         760 :             move16();
     528             : 
     529        6829 :             FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ )
     530             :             {
     531        6069 :                 IF( ls_azimuth_fx[k] > 0 )
     532             :                 {
     533        2817 :                     hDirACRend->proto_index_diff[k] = 1;
     534        2817 :                     move16();
     535             :                 }
     536        3252 :                 ELSE IF( ls_azimuth_fx[k] < 0 )
     537             :                 {
     538        2817 :                     hDirACRend->proto_index_diff[k] = 2;
     539        2817 :                     move16();
     540             :                 }
     541             :                 ELSE
     542             :                 {
     543         435 :                     hDirACRend->proto_index_diff[k] = 0;
     544         435 :                     move16();
     545             :                 }
     546             :             }
     547             : 
     548         760 :             IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
     549             :             {
     550         460 :                 hDirACRend->num_protos_dir = 3;
     551         460 :                 move16();
     552         460 :                 Copy( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE );
     553             :             }
     554             :             ELSE
     555             :             {
     556         300 :                 hDirACRend->num_protos_dir = 2;
     557         300 :                 move16();
     558         300 :                 hDirACRend->proto_index_dir[1] = 1;
     559         300 :                 move16();
     560             :             }
     561             :         }
     562             :     }
     563             :     ELSE /* nchan_transport > 2 */
     564             :     {
     565         939 :         hDirACRend->num_protos_ambi = 4;
     566         939 :         move16();
     567         939 :         IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
     568             :         {
     569          46 :             hDirACRend->num_protos_diff = hDirACRend->num_outputs_diff;
     570          46 :             move16();
     571         547 :             FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ )
     572             :             {
     573         501 :                 hDirACRend->proto_index_diff[k] = k;
     574         501 :                 move16();
     575             :             }
     576             : 
     577          46 :             hDirACRend->num_protos_dir = hDirACRend->num_outputs_dir;
     578          46 :             move16();
     579         547 :             FOR( k = 0; k < hDirACRend->num_outputs_dir; k++ )
     580             :             {
     581         501 :                 hDirACRend->proto_index_dir[k] = k;
     582         501 :                 move16();
     583             :             }
     584             :         }
     585             :         ELSE
     586             :         {
     587         893 :             hDirACRend->num_protos_diff = 1;
     588         893 :             move16();
     589         893 :             hDirACRend->num_protos_dir = nchan_transport;
     590         893 :             move16();
     591             : 
     592        5255 :             FOR( k = 0; k < s_min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ )
     593             :             {
     594        4362 :                 if ( LT_16( hDirACRend->sba_map_tc[k], hDirACRend->num_outputs_dir ) )
     595             :                 {
     596        4362 :                     hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k;
     597        4362 :                     move16();
     598             :                 }
     599             :             }
     600             :         }
     601             :     }
     602             : 
     603        2290 :     test();
     604             :     /* direct/diffuse responses */
     605        2290 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     606             :     {
     607         433 :         IF( ( hDirACRend->diffuse_response_function_fx = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL )
     608             :         {
     609           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     610             :         }
     611             :     }
     612             :     /* reallocate static memory */
     613        1857 :     ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && NE_16( hDirACRend->num_outputs_dir, num_outputs_dir_old ) )
     614             :     {
     615          61 :         free( hDirACRend->diffuse_response_function_fx );
     616          61 :         hDirACRend->diffuse_response_function_fx = NULL;
     617          61 :         IF( ( hDirACRend->diffuse_response_function_fx = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL )
     618             :         {
     619           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     620             :         }
     621             :     }
     622             : 
     623        2290 :     test();
     624        2290 :     test();
     625        2290 :     IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) )
     626             :     {
     627        1394 :         initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, nchan_out_woLFE, hDirACRend->hOutSetup.output_config,
     628        1394 :                                  hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config );
     629             :     }
     630             :     ELSE
     631             :     {
     632         896 :         initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, hDirACRend->num_outputs_dir, IVAS_AUDIO_CONFIG_FOA,
     633         896 :                                  hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, IVAS_AUDIO_CONFIG_INVALID );
     634             :     }
     635             : 
     636        2290 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
     637             :     {
     638         409 :         test();
     639         409 :         test();
     640         409 :         IF( EQ_16( flag_config, DIRAC_OPEN ) )
     641             :         {
     642          10 :             IF( ( hDirACRend->hoa_encoder_fx = (Word32 *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL )
     643             :             {
     644           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     645             :             }
     646             :         }
     647         399 :         ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder_fx && ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) )
     648             :         {
     649           0 :             free( hDirACRend->hoa_encoder_fx );
     650           0 :             hDirACRend->hoa_encoder_fx = NULL;
     651           0 :             IF( ( hDirACRend->hoa_encoder_fx = (Word32 *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL )
     652             :             {
     653           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     654             :             }
     655             :         }
     656         409 :         set32_fx( hDirACRend->hoa_encoder_fx, 0, nchan_out_woLFE * hDirACRend->num_outputs_diff );
     657         409 :         compute_hoa_encoder_mtx_fx( ls_azimuth_fx, ls_elevation_fx, hDirACRend->hoa_encoder_fx, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order );
     658             :     }
     659             :     ELSE
     660             :     {
     661        1881 :         test();
     662        1881 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder_fx )
     663             :         {
     664           0 :             free( hDirACRend->hoa_encoder_fx );
     665             :         }
     666        1881 :         hDirACRend->hoa_encoder_fx = NULL;
     667             :     }
     668             : 
     669             :     /* VBAP */
     670        2290 :     if ( EQ_16( flag_config, DIRAC_OPEN ) )
     671             :     {
     672         433 :         st_ivas->hVBAPdata = NULL;
     673             :     }
     674             : 
     675        2290 :     test();
     676        2290 :     IF( EQ_32( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) )
     677             :     {
     678         876 :         test();
     679         876 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL )
     680             :         {
     681         718 :             vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
     682             :         }
     683         876 :         IF( NE_32( ( error = vbap_init_data_fx( &( st_ivas->hVBAPdata ), ls_azimuth_fx, ls_elevation_fx, nchan_out_woLFE, st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
     684             :         {
     685           0 :             return error;
     686             :         }
     687             :     }
     688        1414 :     ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
     689             :     {
     690         109 :         test();
     691         109 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL )
     692             :         {
     693           0 :             vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
     694             :         }
     695         109 :         hDirACRend->hoa_decoder = NULL;
     696             :     }
     697        1305 :     ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL )
     698             :     {
     699          24 :         vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
     700             :     }
     701             : 
     702             :     /* HOA panning/dec */
     703        2290 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     704             :     {
     705         433 :         hDirACRend->hoa_decoder = NULL;
     706         433 :         test();
     707         433 :         test();
     708         433 :         IF( ( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || ( GT_16( nchan_transport, 2 ) ) )
     709             :         {
     710         302 :             IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
     711             :             {
     712          71 :                 IF( st_ivas->hoa_dec_mtx != NULL )
     713             :                 {
     714          50 :                     free( st_ivas->hoa_dec_mtx );
     715          50 :                     st_ivas->hoa_dec_mtx = NULL;
     716             :                 }
     717          71 :                 IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ), IVAS_ERR_OK ) )
     718             :                 {
     719           0 :                     return error;
     720             :                 }
     721             : 
     722          71 :                 hDirACRend->hoa_decoder = st_ivas->hoa_dec_mtx;
     723             :             }
     724             :         }
     725             :     }
     726             : 
     727             :     /* decorrelation */
     728        2290 :     IF( flag_config == DIRAC_RECONFIGURE )
     729             :     {
     730        1857 :         proto_signal_decorr_on_old = hDirACRend->proto_signal_decorr_on;
     731        1857 :         move16();
     732             :     }
     733             :     ELSE
     734             :     {
     735         433 :         proto_signal_decorr_on_old = 0;
     736         433 :         move16();
     737             :     }
     738        2290 :     hDirACRend->proto_signal_decorr_on = 1;
     739        2290 :     move16();
     740        2290 :     test();
     741        2290 :     if ( ( GT_16( nchan_transport, 2 ) ) && ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) ) )
     742             :     {
     743             :         /*switch off decorrelation for 4 transport channels*/
     744          46 :         hDirACRend->proto_signal_decorr_on = 0;
     745          46 :         move16();
     746             :     }
     747        2290 :     if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
     748             :     {
     749         109 :         hDirACRend->proto_signal_decorr_on = 0;
     750         109 :         move16();
     751             :     }
     752             : 
     753        2290 :     test();
     754        2290 :     test();
     755        2290 :     test();
     756        2290 :     test();
     757        2290 :     test();
     758        2290 :     test();
     759        2290 :     test();
     760        2290 :     test();
     761        2290 :     IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirACRend->proto_signal_decorr_on ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) )
     762         399 :     {
     763             :         Word16 nchan_transport_tmp;
     764         399 :         IF( GT_16( nchan_transport, 2 ) )
     765             :         {
     766         255 :             nchan_transport_tmp = 4;
     767         255 :             move16();
     768             :         }
     769             :         ELSE
     770             :         {
     771         144 :             nchan_transport_tmp = nchan_transport;
     772         144 :             move16();
     773             :         }
     774         399 :         IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff,
     775             :                                                             hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport_tmp, output_Fs ) ),
     776             :                    IVAS_ERR_OK ) )
     777             :         {
     778           0 :             return error;
     779             :         }
     780             :     }
     781        1891 :     ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) )
     782             :     {
     783          24 :         ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
     784             :     }
     785        1867 :     ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old )
     786             :     {
     787        1736 :         test();
     788        1736 :         test();
     789        1736 :         IF( NE_16( nchan_transport, nchan_transport_old ) || NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) || EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
     790             :         {
     791             :             Word16 nchan_transport_tmp;
     792        1736 :             IF( GT_16( nchan_transport, 2 ) )
     793             :             {
     794         638 :                 nchan_transport_tmp = 4;
     795         638 :                 move16();
     796             :             }
     797             :             ELSE
     798             :             {
     799        1098 :                 nchan_transport_tmp = nchan_transport;
     800        1098 :                 move16();
     801             :             }
     802             : 
     803             :             /* close and reopen the decorrelator */
     804        1736 :             ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
     805             : 
     806        1736 :             IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff,
     807             :                                                                 hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport_tmp, output_Fs ) ),
     808             :                        IVAS_ERR_OK ) )
     809             :             {
     810           0 :                 return error;
     811             :             }
     812             :         }
     813             :     }
     814             : 
     815             :     /* output synthesis */
     816        2290 :     test();
     817        2290 :     test();
     818        2290 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     819             :     {
     820         433 :         IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ), IVAS_ERR_OK ) )
     821             :         {
     822           0 :             return error;
     823             :         }
     824         433 :         hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on;
     825         433 :         move16();
     826             :     }
     827        1857 :     ELSE IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) && ( ( NE_16( nchan_transport, nchan_transport_old ) ) || ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) )
     828             :     {
     829        1834 :         ivas_dirac_dec_output_synthesis_close_fx( hDirACRend );
     830             : 
     831        1834 :         IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ), IVAS_ERR_OK ) )
     832             :         {
     833           0 :             return error;
     834             :         }
     835        1834 :         hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on;
     836        1834 :         move16();
     837             :     }
     838             : 
     839        2290 :     test();
     840        2290 :     if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
     841             :     {
     842        1305 :         hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0;
     843        1305 :         move16();
     844             :     }
     845             : 
     846             :     /*-----------------------------------------------------------------*
     847             :      * memory allocation
     848             :      *-----------------------------------------------------------------*/
     849             : 
     850        2290 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
     851             :     {
     852         896 :         test();
     853         896 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx )
     854             :         {
     855          24 :             free( hDirACRend->proto_frame_f_fx );
     856             :         }
     857         896 :         hDirACRend->proto_frame_f_fx = NULL;
     858             :     }
     859             :     ELSE
     860             :     {
     861        1394 :         test();
     862        1394 :         test();
     863        1394 :         test();
     864        1394 :         IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) )
     865             :         {
     866         223 :             IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL )
     867             :             {
     868           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     869             :             }
     870             :         }
     871        1171 :         ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) )
     872             :         {
     873         297 :             proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx;
     874         297 :             free( proto_frame_f_old_fx );
     875         297 :             IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL )
     876             :             {
     877           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     878             :             }
     879             :         }
     880        1394 :         hDirACRend->proto_frame_f_len = imult1616( 2, imult1616( hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands ) );
     881        1394 :         move16();
     882             :     }
     883             : 
     884        2290 :     if ( EQ_16( flag_config, DIRAC_OPEN ) )
     885             :     {
     886         433 :         hDirACRend->buffer_energy_fx = NULL;
     887             :     }
     888             : 
     889        2290 :     test();
     890        2290 :     test();
     891        2290 :     test();
     892        2290 :     test();
     893        2290 :     test();
     894        2290 :     test();
     895        2290 :     test();
     896        2290 :     test();
     897        2290 :     IF( ( EQ_16( flag_config, DIRAC_OPEN ) && EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && ( dec_param_estim_old == FALSE ) ) ) )
     898             :     {
     899         244 :         hDirACRend->index_buffer_intensity = 0;
     900         244 :         move16();
     901         976 :         FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
     902             :         {
     903       24156 :             FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
     904             :             {
     905       23424 :                 IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL )
     906             :                 {
     907           0 :                     return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     908             :                 }
     909       23424 :                 set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
     910             :             }
     911             :         }
     912         244 :         set16_fx( hDirACRend->q_buffer_intensity_real, Q31, DIRAC_NO_COL_AVG_DIFF );
     913         244 :         IF( hDirACRend->buffer_energy_fx == NULL )
     914             :         {
     915         244 :             IF( ( hDirACRend->buffer_energy_fx = (Word32 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL )
     916             :             {
     917           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     918             :             }
     919             :         }
     920         244 :         set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX );
     921         244 :         set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF );
     922             :     }
     923        2046 :     ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( ( hDirAC->hConfig->dec_param_estim == FALSE ) && EQ_16( dec_param_estim_old, TRUE ) ) ) )
     924             :     {
     925        1236 :         FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
     926             :         {
     927       30591 :             FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
     928             :             {
     929       29664 :                 test();
     930       29664 :                 IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] )
     931             :                 {
     932        6144 :                     free( hDirACRend->buffer_intensity_real_fx[i][j] );
     933             :                 }
     934       29664 :                 hDirACRend->buffer_intensity_real_fx[i][j] = NULL;
     935             :             }
     936             :         }
     937         309 :         IF( hDirACRend->buffer_energy_fx != NULL )
     938             :         {
     939          64 :             free( hDirACRend->buffer_energy_fx );
     940          64 :             hDirACRend->buffer_energy_fx = NULL;
     941             :         }
     942             :     }
     943             :     /* output synthesis */
     944        2290 :     ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag );
     945             : 
     946             :     /* Allocate stack memory */
     947        2290 :     IF( NE_16( flag_config, DIRAC_OPEN ) )
     948             :     {
     949        1857 :         ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) );
     950             :     }
     951        2290 :     IF( NE_32( ( error = ivas_dirac_alloc_mem_fx( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ), IVAS_ERR_OK ) )
     952             :     {
     953           0 :         return error;
     954             :     }
     955             : 
     956        2290 :     if ( EQ_16( flag_config, DIRAC_OPEN ) )
     957             :     {
     958         433 :         st_ivas->hDirACRend = hDirACRend;
     959             :     }
     960             : 
     961        2290 :     return error;
     962             : }
     963             : 
     964             : 
     965             : /*-------------------------------------------------------------------------
     966             :  * ivas_dirac_dec_config()
     967             :  *
     968             :  * Open or reconfigure decoder DirAC/MASA handle
     969             :  *-------------------------------------------------------------------------*/
     970             : 
     971        4668 : ivas_error ivas_dirac_dec_config_fx(
     972             :     Decoder_Struct *st_ivas,                /* i/o: IVAS decoder structure  */
     973             :     const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
     974             : )
     975             : {
     976             :     ivas_error error;
     977             :     Word32 output_Fs;
     978             :     Word16 hodirac_flag;
     979             :     Word16 sparfoa_flag;
     980             :     DIRAC_CONFIG_FLAG dec_config_flag;
     981             :     DIRAC_CONFIG_FLAG rend_config_flag;
     982             :     DIRAC_CONFIG_FLAG common_rend_config_flag;
     983             :     Word16 need_dirac_rend;
     984             :     Word16 need_parambin;
     985             :     Word16 dec_param_estim_old;
     986             :     Word16 dec_param_estim_new;
     987             :     Word16 num_poses, pos_idx;
     988             : 
     989        4668 :     error = IVAS_ERR_OK;
     990        4668 :     move32();
     991             : 
     992             :     /* Solve and setup flags for inits */
     993        4668 :     IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
     994             :     {
     995        1207 :         dec_config_flag = DIRAC_RECONFIGURE;
     996        1207 :         move32();
     997             :     }
     998             :     ELSE
     999             :     {
    1000        3461 :         dec_config_flag = flag_config_inp;
    1001        3461 :         move32();
    1002             :     }
    1003             : 
    1004        4668 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
    1005        4668 :     move32();
    1006        4668 :     hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
    1007        4668 :     IF( EQ_32( dec_config_flag, DIRAC_RECONFIGURE ) )
    1008             :     {
    1009        4150 :         dec_param_estim_old = st_ivas->hDirAC->hConfig->dec_param_estim;
    1010        4150 :         move16();
    1011             :     }
    1012             :     ELSE
    1013             :     {
    1014         518 :         dec_param_estim_old = FALSE;
    1015         518 :         move16();
    1016             :     }
    1017             : 
    1018        4668 :     num_poses = 1;
    1019        4668 :     move16();
    1020        4668 :     IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    1021             :     {
    1022           0 :         num_poses = st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses;
    1023           0 :         move16();
    1024             :     }
    1025             : 
    1026        4668 :     sparfoa_flag = 0;
    1027        4668 :     move16();
    1028        4668 :     test();
    1029        4668 :     test();
    1030        4668 :     if ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && !hodirac_flag )
    1031             :     {
    1032           0 :         sparfoa_flag = 1;
    1033           0 :         move16();
    1034             :     }
    1035             : 
    1036        4668 :     IF( NE_32( ( error = ivas_dirac_dec_config_internal_fx( st_ivas, dec_config_flag ) ), IVAS_ERR_OK ) )
    1037             :     {
    1038           0 :         return error;
    1039             :     }
    1040             : 
    1041             :     /* This is required for parambin */
    1042        4668 :     test();
    1043        4668 :     test();
    1044        4668 :     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 ) )
    1045             :     {
    1046        2342 :         st_ivas->hDirAC->hConfig->dec_param_estim = FALSE;
    1047        2342 :         move16();
    1048             :     }
    1049             : 
    1050        4668 :     dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim;
    1051        4668 :     move16();
    1052             : 
    1053             :     /* Setup renderers and meta */
    1054             :     /* First, free everything if in reconfig and not the active renderer */
    1055        4668 :     need_parambin = 0;
    1056        4668 :     move16();
    1057        4668 :     SWITCH( st_ivas->renderer_type )
    1058             :     {
    1059        2342 :         case RENDERER_BINAURAL_PARAMETRIC:
    1060             :         case RENDERER_BINAURAL_PARAMETRIC_ROOM:
    1061             :         case RENDERER_STEREO_PARAMETRIC:
    1062        2342 :             need_parambin = 1;
    1063        2342 :             move16();
    1064        2342 :             BREAK;
    1065        2326 :         default:
    1066        2326 :             need_parambin = 0;
    1067        2326 :             move16();
    1068             :     }
    1069             : 
    1070        4668 :     IF( !need_parambin )
    1071             :     {
    1072        2326 :         ivas_dirac_dec_close_binaural_data_fx( st_ivas->hDiracDecBin );
    1073             :     }
    1074             : 
    1075        4668 :     need_dirac_rend = 0;
    1076        4668 :     move16();
    1077        4668 :     SWITCH( st_ivas->renderer_type )
    1078             :     {
    1079        2290 :         case RENDERER_DIRAC:
    1080             :         case RENDERER_BINAURAL_FASTCONV:
    1081             :         case RENDERER_BINAURAL_FASTCONV_ROOM:
    1082             :         case RENDERER_SBA_LINEAR_ENC:
    1083             :         case RENDERER_SBA_LINEAR_DEC:
    1084             :         case RENDERER_OSBA_AMBI:
    1085             :         case RENDERER_OSBA_LS:
    1086        2290 :             need_dirac_rend = 1;
    1087        2290 :             move16();
    1088        2290 :             BREAK;
    1089        2378 :         default:
    1090        2378 :             need_dirac_rend = 0;
    1091        2378 :             move16();
    1092             :     }
    1093             : 
    1094        4668 :     IF( !need_dirac_rend )
    1095             :     {
    1096        2378 :         ivas_dirac_rend_close_fx( &st_ivas->hDirACRend );
    1097             :     }
    1098             : 
    1099        4668 :     IF( !sparfoa_flag )
    1100             :     {
    1101        4668 :         IF( st_ivas->hSpatParamRendCom == NULL )
    1102             :         {
    1103         518 :             common_rend_config_flag = DIRAC_OPEN;
    1104         518 :             move32();
    1105             :         }
    1106             :         ELSE
    1107             :         {
    1108        4150 :             common_rend_config_flag = flag_config_inp;
    1109        4150 :             move32();
    1110             :         }
    1111             : 
    1112        4668 :         IF( NE_32( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new,
    1113             :                                                                     st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ),
    1114             :                    IVAS_ERR_OK ) )
    1115             :         {
    1116           0 :             return error;
    1117             :         }
    1118             : 
    1119        4668 :         IF( need_dirac_rend )
    1120             :         {
    1121        2290 :             IF( st_ivas->hDirACRend == NULL )
    1122             :             {
    1123         433 :                 rend_config_flag = DIRAC_OPEN;
    1124         433 :                 move32();
    1125             :             }
    1126             :             ELSE
    1127             :             {
    1128        1857 :                 rend_config_flag = flag_config_inp;
    1129        1857 :                 move32();
    1130             :             }
    1131        2290 :             IF( NE_32( ( error = ivas_dirac_rend_config_fx( st_ivas, rend_config_flag, dec_param_estim_old ) ), IVAS_ERR_OK ) )
    1132             :             {
    1133           0 :                 return error;
    1134             :             }
    1135             :         }
    1136             : 
    1137        4668 :         IF( need_parambin )
    1138             :         {
    1139        2342 :             IF( NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
    1140             :             {
    1141        1681 :                 IF( NE_32( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) )
    1142             :                 {
    1143           0 :                     return error;
    1144             :                 }
    1145             :             }
    1146             : 
    1147        2342 :             IF( st_ivas->hDiracDecBin[0] == NULL )
    1148             :             {
    1149         394 :                 IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, &( st_ivas->hHrtfParambin ) ) ), IVAS_ERR_OK ) )
    1150             :                 {
    1151           0 :                     return error;
    1152             :                 }
    1153             :             }
    1154             :             ELSE
    1155             :             {
    1156             :                 /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */
    1157        1948 :                 test();
    1158        1948 :                 test();
    1159        1948 :                 IF( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params != NULL && !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->nSCE > 0 ) )
    1160             :                 {
    1161         854 :                     ivas_dirac_dec_decorr_close_fx( &st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_state ); // done
    1162             :                 }
    1163             : 
    1164        1948 :                 IF( NE_32( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin[0]->hTdDecorr ), &( st_ivas->hDiracDecBin[0]->useTdDecorr ) ) ), IVAS_ERR_OK ) )
    1165             :                 {
    1166           0 :                     return error;
    1167             :                 }
    1168             : 
    1169             :                 /* copy td-decorr flag to split renderer side rendereres */
    1170        1948 :                 FOR( pos_idx = 1; pos_idx < num_poses; pos_idx++ )
    1171             :                 {
    1172           0 :                     st_ivas->hDiracDecBin[pos_idx]->useTdDecorr = st_ivas->hDiracDecBin[0]->useTdDecorr;
    1173             :                 }
    1174             : 
    1175        1948 :                 IF( !st_ivas->hDiracDecBin[0]->useTdDecorr )
    1176             :                 {
    1177        1114 :                     IF( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params == NULL )
    1178             :                     {
    1179             :                         Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
    1180             : 
    1181         859 :                         ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands );
    1182             : 
    1183         859 :                         IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS,
    1184             :                                                                             DIRAC_SYNTHESIS_PSD_LS, frequency_axis_fx, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ),
    1185             :                                    IVAS_ERR_OK ) )
    1186             :                         {
    1187           0 :                             return error;
    1188             :                         }
    1189             :                     }
    1190             :                 }
    1191             : 
    1192        3896 :                 FOR( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
    1193             :                 {
    1194        1948 :                     st_ivas->hDiracDecBin[pos_idx]->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate );
    1195        1948 :                     move16();
    1196             :                 }
    1197             :             }
    1198             :         }
    1199             :     }
    1200             : 
    1201        4668 :     return error;
    1202             : }
    1203             : 
    1204             : 
    1205             : /*-------------------------------------------------------------------------
    1206             :  * ivas_dirac_dec_close()
    1207             :  *
    1208             :  * Close DirAC memories
    1209             :  *------------------------------------------------------------------------*/
    1210             : 
    1211        1686 : void ivas_dirac_dec_close_fx(
    1212             :     DIRAC_DEC_HANDLE *hDirAC_out )
    1213             : {
    1214             :     DIRAC_DEC_HANDLE hDirAC;
    1215             : 
    1216        1686 :     test();
    1217        1686 :     IF( hDirAC_out == NULL || *hDirAC_out == NULL )
    1218             :     {
    1219        1168 :         return;
    1220             :     }
    1221             : 
    1222         518 :     hDirAC = *hDirAC_out;
    1223             : 
    1224             :     /* Config & CLDFB */
    1225         518 :     IF( hDirAC->hConfig != NULL )
    1226             :     {
    1227         518 :         free( hDirAC->hConfig );
    1228         518 :         hDirAC->hConfig = NULL;
    1229             :     }
    1230             : 
    1231         518 :     free( *hDirAC_out );
    1232         518 :     *hDirAC_out = NULL;
    1233             : 
    1234         518 :     return;
    1235             : }
    1236             : 
    1237             : 
    1238             : /*-------------------------------------------------------------------------
    1239             :  * ivas_dirac_dec_read_BS_fx()
    1240             :  *
    1241             :  * Read DirAC parameters from the bitstream
    1242             :  *------------------------------------------------------------------------*/
    1243             : 
    1244      158013 : void ivas_dirac_dec_read_BS_fx(
    1245             :     const Word32 ivas_total_brate,                        /* i  : IVAS total bitrate              */
    1246             :     Decoder_State *st,                                    /* i/o: decoder state structure         */
    1247             :     DIRAC_DEC_HANDLE hDirAC,                              /* i/o: decoder DirAC handle            */
    1248             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle    */
    1249             :     IVAS_QMETADATA_HANDLE hQMetaData,                     /* i/o: q_metadata                      */
    1250             :     Word16 *nb_bits,                                      /* o  : number of bits read             */
    1251             :     const Word16 last_bit_pos,                            /* i  : last read bitstream position    */
    1252             :     const Word16 hodirac_flag,                            /* i  : flag to indicate HO-DirAC mode  */
    1253             :     const Word16 nchan_transport,                         /* i  : number of transport channels    */
    1254             :     Word16 *dirac_to_spar_md_bands                        /* o  : DirAC->SPAR MD bands            */
    1255             : )
    1256             : {
    1257             :     Word16 i, j, b, dir, orig_dirac_bands;
    1258             :     Word16 next_bit_pos_orig;
    1259             : 
    1260      158013 :     test();
    1261      158013 :     test();
    1262      158013 :     IF( !st->bfi && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
    1263             :     {
    1264      150745 :         next_bit_pos_orig = st->next_bit_pos;
    1265      150745 :         move16();
    1266      150745 :         st->next_bit_pos = sub( extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), 1 );
    1267      150745 :         move16();
    1268      150745 :         if ( last_bit_pos > 0 )
    1269             :         {
    1270       36736 :             st->next_bit_pos = last_bit_pos;
    1271       36736 :             move16();
    1272             :         }
    1273             :         /* 1 bit flag for signaling metadata to read */
    1274      150745 :         b = st->bit_stream[( st->next_bit_pos )--];
    1275      150745 :         move16();
    1276      150745 :         ( *nb_bits )++;
    1277             : 
    1278      150745 :         IF( EQ_16( b, 1 ) ) /* WB 4TCs condition, no other metadata to read*/
    1279             :         {
    1280         389 :             orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
    1281         389 :             move16();
    1282             : 
    1283         389 :             hQMetaData->sba_inactive_mode = 1;
    1284         389 :             move16();
    1285             : 
    1286             :             /* if we start with a SID frame, we need to init the azi/ele arrays.*/
    1287         389 :             IF( st->ini_frame == 0 )
    1288             :             {
    1289           0 :                 FOR( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ )
    1290             :                 {
    1291           0 :                     set32_fx( hQMetaData->q_direction[0].band_data[b].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
    1292           0 :                     set32_fx( hQMetaData->q_direction[0].band_data[b].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
    1293             :                 }
    1294             :             }
    1295             : 
    1296         389 :             *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), nchan_transport, NULL, SBA_FORMAT ) );
    1297         389 :             move16();
    1298             : 
    1299        1945 :             FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
    1300             :             {
    1301        1556 :                 hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0];
    1302        1556 :                 move32();
    1303        1556 :                 hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0];
    1304        1556 :                 move32();
    1305        1556 :                 hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[0];
    1306        1556 :                 move32();
    1307        1556 :                 hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_index[0];
    1308        1556 :                 move16();
    1309             :             }
    1310        1945 :             FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
    1311             :             {
    1312        4668 :                 FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- )
    1313             :                 {
    1314        3112 :                     hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0];
    1315        3112 :                     move32();
    1316        3112 :                     hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0];
    1317        3112 :                     move32();
    1318        3112 :                     hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0];
    1319        3112 :                     move32();
    1320        3112 :                     hQMetaData->q_direction[0].band_data[j].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_index[0];
    1321        3112 :                     move16();
    1322             :                 }
    1323             :             }
    1324             : 
    1325         389 :             hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
    1326         389 :             move16();
    1327             :         }
    1328             :         ELSE
    1329             :         {
    1330      150356 :             hQMetaData->sba_inactive_mode = 0;
    1331      150356 :             move16();
    1332      150356 :             hQMetaData->is_masa_ivas_format = 0;
    1333      150356 :             move16();
    1334      150356 :             IF( hQMetaData->useLowerRes )
    1335             :             {
    1336       11461 :                 hQMetaData->q_direction[0].cfg.nblocks = 1;
    1337       11461 :                 move16();
    1338             :             }
    1339             :             ELSE
    1340             :             {
    1341      138895 :                 hQMetaData->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES;
    1342      138895 :                 move16();
    1343             :             }
    1344      150356 :             *nb_bits = add( *nb_bits, ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag ) );
    1345      150356 :             move16();
    1346             :         }
    1347             : 
    1348      150745 :         st->next_bit_pos = next_bit_pos_orig;
    1349      150745 :         move16();
    1350             :     }
    1351        7268 :     ELSE IF( !st->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
    1352             :     {
    1353         110 :         next_bit_pos_orig = st->next_bit_pos;
    1354         110 :         move16();
    1355             : 
    1356             :         /* subtract mode signaling bits, since bitstream was moved after mode reading */
    1357         110 :         i = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
    1358         110 :         st->next_bit_pos = sub( sub( i, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS );
    1359             : 
    1360         110 :         move16();
    1361             :         /* 1 bit flag for signaling metadata to read */
    1362         110 :         b = st->bit_stream[( st->next_bit_pos )--];
    1363         110 :         move16();
    1364         110 :         ( *nb_bits )++;
    1365         110 :         hQMetaData->sba_inactive_mode = 1;
    1366         110 :         move16();
    1367         110 :         orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
    1368         110 :         move16();
    1369             : 
    1370             :         /* if we start with a SID frame, we need to init the azi/ele arrays.*/
    1371         110 :         IF( st->ini_frame == 0 )
    1372             :         {
    1373           0 :             FOR( dir = 0; dir < hQMetaData->no_directions; dir++ )
    1374             :             {
    1375           0 :                 FOR( b = 0; b < hQMetaData->q_direction[dir].cfg.nbands; b++ )
    1376             :                 {
    1377           0 :                     set32_fx( hQMetaData->q_direction[dir].band_data[b].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
    1378           0 :                     set32_fx( hQMetaData->q_direction[dir].band_data[b].elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
    1379             :                 }
    1380             :             }
    1381             :         }
    1382         110 :         *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), nchan_transport, NULL, SBA_FORMAT ) );
    1383         110 :         move16();
    1384             : 
    1385         550 :         FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
    1386             :         {
    1387         440 :             hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0];
    1388         440 :             move32();
    1389         440 :             hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0];
    1390         440 :             move32();
    1391         440 :             hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[0];
    1392         440 :             move32();
    1393         440 :             hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_index[0];
    1394         440 :             move16();
    1395             :         }
    1396         550 :         FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
    1397             :         {
    1398        1320 :             FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- )
    1399             :             {
    1400         880 :                 hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0];
    1401         880 :                 move32();
    1402         880 :                 hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0];
    1403         880 :                 move32();
    1404         880 :                 hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0];
    1405         880 :                 move32();
    1406         880 :                 hQMetaData->q_direction[0].band_data[j].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_index[0];
    1407         880 :                 move16();
    1408             :             }
    1409             :         }
    1410             : 
    1411         110 :         hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
    1412         110 :         move16();
    1413             : 
    1414         110 :         st->next_bit_pos = next_bit_pos_orig;
    1415         110 :         move16();
    1416             :     }
    1417             : 
    1418      158013 :     test();
    1419      158013 :     IF( hDirAC != NULL && hSpatParamRendCom != NULL )
    1420             :     {
    1421      102091 :         ivas_qmetadata_to_dirac_fx( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands );
    1422             :     }
    1423             : 
    1424      158013 :     return;
    1425             : }
    1426             : 
    1427             : 
    1428             : /*-----------------------------------------------------------------------*
    1429             :  * ivas_qmetadata_to_dirac()
    1430             :  *
    1431             :  * Copy qmetedata to DirAC parameters for rendering
    1432             :  *-----------------------------------------------------------------------*/
    1433             : 
    1434      143255 : void ivas_qmetadata_to_dirac_fx(
    1435             :     const IVAS_QMETADATA_HANDLE hQMetaData,               /* i  : frame of MASA q_metadata        */
    1436             :     DIRAC_DEC_HANDLE hDirAC,                              /* i  : DirAC decoder structure         */
    1437             :     MASA_DECODER_HANDLE hMasa,                            /* i  : MASA decoder structure          */
    1438             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle     */
    1439             :     const Word32 ivas_total_brate,                        /* i  : IVAS total bitrate              */
    1440             :     const IVAS_FORMAT ivas_format,                        /* i  : IVAS format                     */
    1441             :     const Word16 hodirac_flag,                            /* i  : flag to indicate HO-DirAC mode  */
    1442             :     Word16 *dirac_to_spar_md_bands                        /* o  : DirAC->SPAR MD bands            Q0*/
    1443             : )
    1444             : {
    1445             :     Word16 block, band;
    1446             :     Word16 *seed_ptr;
    1447             :     Word16 band_start, band_end, diff_idx;
    1448             :     Word16 b, ele, azi;
    1449             :     Word32 azimuth_fx, elevation_fx;
    1450             :     Word32 diffuseness_fx;
    1451             :     IVAS_QDIRECTION *q_direction;
    1452             :     Word16 *band_mapping;
    1453             :     Word16 *band_grouping;
    1454             :     Word16 start_band;
    1455      143255 :     Word16 nbands = 0;
    1456      143255 :     move16();
    1457      143255 :     Word16 nblocks = 0;
    1458      143255 :     move16();
    1459             :     Word16 qBand_idx;
    1460      143255 :     Word16 idx_sec = 0;
    1461      143255 :     move16();
    1462      143255 :     Word16 no_secs = 1;
    1463      143255 :     move16();
    1464      143255 :     q_direction = &( hQMetaData->q_direction[0] );
    1465             : 
    1466      143255 :     hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions;
    1467      143255 :     move16();
    1468      143255 :     hSpatParamRendCom->numSimultaneousDirections = add( hSpatParamRendCom->numParametricDirections, hSpatParamRendCom->numIsmDirections );
    1469      143255 :     move16();
    1470      143255 :     test();
    1471      143255 :     IF( hMasa != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
    1472       40053 :     {
    1473             :         Word16 meta_write_index;
    1474       40053 :         band_mapping = hMasa->data.band_mapping;
    1475       40053 :         move16();
    1476             : 
    1477      200265 :         FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
    1478             :         {
    1479      160212 :             meta_write_index = add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) % hSpatParamRendCom->dirac_md_buffer_length;
    1480             : 
    1481     1360360 :             FOR( band = 0; band < hMasa->config.numCodingBands; ++band )
    1482             :             {
    1483    10126548 :                 FOR( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
    1484             :                 {
    1485             :                     /* Right shifting -1 -> -1, Hence this change is done */
    1486     8926400 :                     Word32 L_tmp = L_abs( q_direction->band_data[band].azimuth_fx[block] );
    1487     8926400 :                     hSpatParamRendCom->azimuth[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
    1488     8926400 :                     move16();
    1489             : 
    1490     8926400 :                     IF( q_direction->band_data[band].azimuth_fx[block] < 0 )
    1491             :                     {
    1492     4686307 :                         hSpatParamRendCom->azimuth[meta_write_index][b] = negate( hSpatParamRendCom->azimuth[meta_write_index][b] );
    1493     4686307 :                         move16();
    1494             :                     }
    1495             : 
    1496     8926400 :                     L_tmp = L_abs( q_direction->band_data[band].elevation_fx[block] );
    1497     8926400 :                     hSpatParamRendCom->elevation[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
    1498     8926400 :                     move16();
    1499             : 
    1500     8926400 :                     IF( q_direction->band_data[band].elevation_fx[block] < 0 )
    1501             :                     {
    1502     2798093 :                         hSpatParamRendCom->elevation[meta_write_index][b] = negate( hSpatParamRendCom->elevation[meta_write_index][b] );
    1503     2798093 :                         move16();
    1504             :                     }
    1505             : 
    1506     8926400 :                     hSpatParamRendCom->energy_ratio1_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block];
    1507     8926400 :                     move32();
    1508     8926400 :                     hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub( ONE_IN_Q30, q_direction->band_data[band].energy_ratio_fx[block] );
    1509     8926400 :                     move32();
    1510             : 
    1511     8926400 :                     IF( q_direction->coherence_band_data != NULL )
    1512             :                     {
    1513     5200560 :                         hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]];
    1514     5200560 :                         move16();
    1515             :                     }
    1516             :                     ELSE
    1517             :                     {
    1518     3725840 :                         hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = 0;
    1519     3725840 :                         move16();
    1520             :                     }
    1521             : 
    1522     8926400 :                     IF( hQMetaData->surcoh_band_data != NULL )
    1523             :                     {
    1524     5200560 :                         hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = ivas_divde_255[hQMetaData->surcoh_band_data[band].surround_coherence[block]]; /*q15*/
    1525     5200560 :                         move16();
    1526             :                     }
    1527             :                     ELSE
    1528             :                     {
    1529     3725840 :                         hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = 0;
    1530     3725840 :                         move16();
    1531             :                     }
    1532             :                 }
    1533             :             }
    1534             :         }
    1535             : 
    1536       40053 :         test();
    1537       40053 :         test();
    1538       40053 :         test();
    1539       40053 :         IF( EQ_32( hQMetaData->no_directions, 2 ) )
    1540             :         {
    1541        3947 :             q_direction = &( hQMetaData->q_direction[1] );
    1542       19735 :             FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
    1543             :             {
    1544       15788 :                 meta_write_index = ( add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) ) % hSpatParamRendCom->dirac_md_buffer_length;
    1545             : 
    1546      204944 :                 FOR( band = 0; band < hMasa->config.numCodingBands; ++band )
    1547             :                 {
    1548     1075716 :                     FOR( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b )
    1549             :                     {
    1550             :                         /* Right shifting -1 -> -1, Hence this change is done */
    1551      886560 :                         Word32 L_tmp = L_abs( q_direction->band_data[band].azimuth_fx[block] );
    1552      886560 :                         hSpatParamRendCom->azimuth2[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
    1553      886560 :                         move16();
    1554      886560 :                         IF( q_direction->band_data[band].azimuth_fx[block] < 0 )
    1555             :                         {
    1556      195459 :                             hSpatParamRendCom->azimuth2[meta_write_index][b] = negate( hSpatParamRendCom->azimuth2[meta_write_index][b] );
    1557      195459 :                             move16();
    1558             :                         }
    1559             : 
    1560      886560 :                         L_tmp = L_abs( q_direction->band_data[band].elevation_fx[block] );
    1561      886560 :                         hSpatParamRendCom->elevation2[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
    1562      886560 :                         move16();
    1563      886560 :                         IF( q_direction->band_data[band].elevation_fx[block] < 0 )
    1564             :                         {
    1565       39033 :                             hSpatParamRendCom->elevation2[meta_write_index][b] = negate( hSpatParamRendCom->elevation2[meta_write_index][b] );
    1566       39033 :                             move16();
    1567             :                         }
    1568             : 
    1569      886560 :                         hSpatParamRendCom->energy_ratio2_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block];
    1570      886560 :                         move32();
    1571      886560 :                         hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b], q_direction->band_data[band].energy_ratio_fx[block] );
    1572      886560 :                         move32();
    1573             : 
    1574             :                         /* Sanitize diffuseness for rare cases where floating point inaccuracy could result in negative diffuseness. */
    1575      886560 :                         if ( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] < 0 )
    1576             :                         {
    1577           0 :                             hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = 0;
    1578           0 :                             move32();
    1579             :                         }
    1580             : 
    1581      886560 :                         IF( q_direction->coherence_band_data != NULL )
    1582             :                         {
    1583      886560 :                             hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]];
    1584      886560 :                             move16();
    1585             :                         }
    1586             :                         ELSE
    1587             :                         {
    1588           0 :                             hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = 0;
    1589           0 :                             move16();
    1590             :                         }
    1591             :                     }
    1592             :                 }
    1593             :             }
    1594             :         }
    1595       36106 :         ELSE IF( hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2_fx != NULL && hSpatParamRendCom->spreadCoherence2_fx != NULL )
    1596             :         {
    1597             :             /* zero out old dir2 data */
    1598      136040 :             FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
    1599             :             {
    1600      108832 :                 meta_write_index = add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) % hSpatParamRendCom->dirac_md_buffer_length;
    1601      108832 :                 set16_fx( hSpatParamRendCom->azimuth2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
    1602      108832 :                 set16_fx( hSpatParamRendCom->elevation2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
    1603             : 
    1604      108832 :                 set32_fx( hSpatParamRendCom->energy_ratio2_fx[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
    1605      108832 :                 set16_fx( hSpatParamRendCom->spreadCoherence2_fx[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
    1606             :             }
    1607             :         }
    1608             :     }
    1609             :     ELSE /* SBA mode/SID/Zero frame*/
    1610             :     {
    1611             :         Word16 tmp_write_idx_param_band;
    1612             :         Word16 tmp_write_idx_band;
    1613             : 
    1614      103202 :         Word32 diffuseness_sec_fx = 0;
    1615      103202 :         move32();
    1616             : 
    1617             :         /* ungroup */
    1618      103202 :         seed_ptr = &hDirAC->dithering_seed;
    1619      103202 :         nblocks = q_direction->cfg.nblocks;
    1620      103202 :         move16();
    1621      103202 :         nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands];
    1622      103202 :         move16();
    1623      103202 :         band_grouping = hDirAC->band_grouping;
    1624             : 
    1625      103202 :         test();
    1626      103202 :         IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_format, SBA_FORMAT ) )
    1627             :         {
    1628             :             /* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/
    1629        1111 :             start_band = 0;
    1630        1111 :             move16();
    1631        1111 :             hDirAC->hConfig->nbands = 5;
    1632        1111 :             move16();
    1633             : 
    1634        1111 :             ivas_dirac_config_bands_fx( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL, 1 );
    1635             : 
    1636        1111 :             nbands = 5;
    1637        1111 :             move16();
    1638             :         }
    1639             :         ELSE
    1640             :         {
    1641      102091 :             start_band = hDirAC->hConfig->enc_param_start_band;
    1642      102091 :             move16();
    1643      102091 :             IF( EQ_32( ivas_format, SBA_FORMAT ) )
    1644             :             {
    1645      102091 :                 hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS;
    1646      102091 :                 move16();
    1647             :             }
    1648             :             ELSE
    1649             :             {
    1650           0 :                 hDirAC->hConfig->nbands = q_direction->cfg.nbands;
    1651           0 :                 move16();
    1652             :             }
    1653             : 
    1654      102091 :             ivas_dirac_config_bands_fx( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hDirAC->hConfig->enc_param_start_band, hDirAC->hFbMdft, 0 );
    1655             : 
    1656      102091 :             nbands = hDirAC->hConfig->nbands;
    1657      102091 :             move16();
    1658      102091 :             if ( hQMetaData->q_direction[0].cfg.nblocks == 0 )
    1659             :             {
    1660             :                 /* No transmission -> no copy from qmetadata buffers*/
    1661           0 :                 nbands = start_band;
    1662           0 :                 move16();
    1663             :             }
    1664             :         }
    1665             : 
    1666             :         /* Low-Bands with no spatial data transmitted, analysis at decoder side */
    1667      810890 :         FOR( band = 0; band < start_band; band++ )
    1668             :         {
    1669      707688 :             band_start = band_grouping[band];
    1670      707688 :             move16();
    1671      707688 :             band_end = band_grouping[band + 1];
    1672      707688 :             move16();
    1673      707688 :             tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
    1674      707688 :             move16();
    1675             : 
    1676     3538440 :             FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
    1677             :             {
    1678     6723036 :                 FOR( b = band_start; b < band_end; b++ )
    1679             :                 {
    1680     3892284 :                     tmp_write_idx_band = tmp_write_idx_param_band;
    1681     3892284 :                     move16();
    1682             : 
    1683     3892284 :                     hSpatParamRendCom->spreadCoherence_fx[block][b] = 0;
    1684     3892284 :                     move16();
    1685     3892284 :                     hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0;
    1686     3892284 :                     move16();
    1687     3892284 :                     hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0;
    1688     3892284 :                     move32();
    1689     3892284 :                     hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
    1690     3892284 :                     move16();
    1691     3892284 :                     hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
    1692     3892284 :                     move16();
    1693     3892284 :                     hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
    1694     3892284 :                     move32();
    1695     3892284 :                     hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
    1696     3892284 :                     move16();
    1697     3892284 :                     hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
    1698     3892284 :                     move16();
    1699             : 
    1700     3892284 :                     tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
    1701             :                 }
    1702             :             }
    1703             :         }
    1704             : 
    1705             :         /* Bands with spatial data transmitted */
    1706      103202 :         if ( hodirac_flag )
    1707             :         {
    1708       13630 :             no_secs = DIRAC_HO_NUMSECTORS;
    1709       13630 :             move16();
    1710             :         }
    1711             : 
    1712      220034 :         FOR( idx_sec = 0; idx_sec < no_secs; idx_sec++ )
    1713             :         {
    1714      803351 :             FOR( band = start_band; band < nbands; band++ )
    1715             :             {
    1716      686519 :                 band_start = band_grouping[band];
    1717      686519 :                 move16();
    1718      686519 :                 band_end = band_grouping[band + 1];
    1719      686519 :                 move16();
    1720      686519 :                 tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
    1721      686519 :                 move16();
    1722             : 
    1723      686519 :                 IF( EQ_32( ivas_format, SBA_FORMAT ) )
    1724             :                 {
    1725      680964 :                     qBand_idx = sub( dirac_to_spar_md_bands[band], start_band );
    1726             :                 }
    1727             :                 ELSE
    1728             :                 {
    1729        5555 :                     qBand_idx = band;
    1730        5555 :                     move16();
    1731             :                 }
    1732      686519 :                 diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0];
    1733      686519 :                 move16();
    1734             : 
    1735      686519 :                 diffuseness_fx = L_sub( ONE_IN_Q30, q_direction->band_data[qBand_idx].energy_ratio_fx[0] );
    1736             : 
    1737     3432595 :                 FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
    1738             :                 {
    1739             :                     Word16 block_qmetadata;
    1740             : 
    1741     2746076 :                     block_qmetadata = s_min( block, sub( nblocks, 1 ) );
    1742     2746076 :                     block_qmetadata = s_max( block_qmetadata, 0 );
    1743             : 
    1744             : 
    1745     2746076 :                     if ( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] < 0 )
    1746             :                     {
    1747     1191131 :                         q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] = L_add( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata], 1509949440 /*360.0F in Q22*/ );
    1748     1191131 :                         move32();
    1749             :                     }
    1750             : 
    1751     2746076 :                     test();
    1752     2746076 :                     IF( hMasa == NULL && hodirac_flag )
    1753             :                     {
    1754     1308480 :                         azimuth_fx = q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata];
    1755     1308480 :                         move32();
    1756     1308480 :                         elevation_fx = q_direction[idx_sec].band_data[qBand_idx].elevation_fx[block_qmetadata];
    1757     1308480 :                         move32();
    1758     1308480 :                         diffuseness_fx = L_sub( ONE_IN_Q30, q_direction[0].band_data[qBand_idx].energy_ratio_fx[block_qmetadata] );
    1759     1308480 :                         diffuseness_sec_fx = q_direction[1].band_data[qBand_idx].energy_ratio_fx[block_qmetadata];
    1760     1308480 :                         move32();
    1761     1308480 :                         assert( diffuseness_sec_fx < 1073849216 /*1.0001f in Q30*/ && diffuseness_sec_fx > -107374 /*-0.0001f in Q30*/ );
    1762             :                     }
    1763             :                     ELSE
    1764             :                     {
    1765     1437596 :                         azimuth_fx = q_direction->band_data[qBand_idx].azimuth_fx[block_qmetadata];
    1766     1437596 :                         move32();
    1767     1437596 :                         elevation_fx = q_direction->band_data[qBand_idx].elevation_fx[block_qmetadata];
    1768     1437596 :                         move32();
    1769             :                     }
    1770    22605712 :                     FOR( b = band_start; b < band_end; b++ )
    1771             :                     {
    1772    19859636 :                         tmp_write_idx_band = tmp_write_idx_param_band;
    1773    19859636 :                         move16();
    1774             : 
    1775    19859636 :                         IF( hodirac_flag )
    1776             :                         {
    1777     6460800 :                             azi = extract_h( L_shr( ( L_add( azimuth_fx, ONE_IN_Q21 ) ), 6 ) );
    1778     6460800 :                             ele = extract_h( L_shr( ( L_add( elevation_fx, ONE_IN_Q21 ) ), 6 ) );
    1779             :                             /*addition of one to compensate precision loss*/
    1780     6460800 :                             if ( azi < 0 )
    1781             :                             {
    1782           0 :                                 azi = add( azi, 1 );
    1783             :                             }
    1784     6460800 :                             if ( ele < 0 )
    1785             :                             {
    1786      911319 :                                 ele = add( ele, 1 );
    1787             :                             }
    1788             :                         }
    1789             :                         ELSE
    1790             :                         {
    1791             :                             Word16 a, b_tmp;
    1792             : 
    1793    13398836 :                             Word16 exp_factor = 0;
    1794    13398836 :                             move16();
    1795    13398836 :                             a = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor
    1796             : 
    1797    13398836 :                             Word32 tmp1_32 = L_mult( a, dirac_dithering_azi_scale_fx[diff_idx] ); // exp_factor + 5
    1798             :                             Word16 final_1_exp;
    1799             :                             Word32 final_1_32;
    1800    13398836 :                             Word16 norm_op1 = norm_l( azimuth_fx );
    1801    13398836 :                             Word16 norm_op2 = norm_l( tmp1_32 );
    1802    13398836 :                             Word16 op2_e = add( exp_factor, 5 );
    1803    13398836 :                             final_1_exp = add( s_max( s_max( sub( 9, norm_op1 ), sub( op2_e, norm_op2 ) ), 0 ), 2 ); // 2 for headroom
    1804    13398836 :                             final_1_32 = L_add( L_shr( azimuth_fx, sub( final_1_exp, 9 ) ), L_shr( tmp1_32, sub( final_1_exp, op2_e ) ) );
    1805             : 
    1806    13398836 :                             b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor );               // q = exp_factor
    1807    13398836 :                             Word32 tmp4_32 = L_mult( b_tmp, dirac_dithering_ele_scale_fx[diff_idx] ); // exp_factor + 4
    1808             : 
    1809             :                             Word16 final_2_exp;
    1810             :                             Word32 final_2_32;
    1811    13398836 :                             norm_op1 = norm_l( elevation_fx );
    1812    13398836 :                             norm_op2 = norm_l( tmp4_32 );
    1813    13398836 :                             op2_e = add( exp_factor, 4 );
    1814    13398836 :                             final_2_exp = add( s_max( s_max( sub( 9, norm_op1 ), sub( op2_e, norm_op2 ) ), 0 ), 2 ); // 2 for headroom
    1815    13398836 :                             final_2_32 = L_add( L_shr( elevation_fx, sub( final_2_exp, 9 ) ), L_shr( tmp4_32, sub( final_2_exp, op2_e ) ) );
    1816             : 
    1817    13398836 :                             final_1_32 = L_add( final_1_32, L_shl( 1, sub( 30, final_1_exp ) ) ); /*0.5 in q31*/
    1818    13398836 :                             final_2_32 = L_add( final_2_32, L_shl( 1, sub( 30, final_2_exp ) ) );
    1819    13398836 :                             azi = extract_h( L_shr( final_1_32, sub( 15, final_1_exp ) ) );
    1820    13398836 :                             ele = extract_h( L_shr( final_2_32, sub( 15, final_2_exp ) ) );
    1821             : 
    1822             : 
    1823             :                             /*addition of one to compensate precision loss*/
    1824    13398836 :                             if ( azi < 0 )
    1825             :                             {
    1826     1441650 :                                 azi = add( azi, 1 );
    1827             :                             }
    1828    13398836 :                             if ( ele < 0 )
    1829             :                             {
    1830     5003240 :                                 ele = add( ele, 1 );
    1831             :                             }
    1832             :                             /* limit the elevation to [-90, 90] */
    1833    13398836 :                             ele = s_min( 90, ele );
    1834    13398836 :                             ele = s_max( -90, ele );
    1835             :                         }
    1836             : 
    1837    19859636 :                         test();
    1838    19859636 :                         IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && q_direction->coherence_band_data != NULL )
    1839             :                         {
    1840           0 :                             hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[q_direction->coherence_band_data[qBand_idx].spread_coherence[block]];
    1841           0 :                             move16();
    1842             :                         }
    1843             :                         ELSE
    1844             :                         {
    1845    19859636 :                             hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
    1846    19859636 :                             move16();
    1847             :                         }
    1848             : 
    1849    19859636 :                         test();
    1850    19859636 :                         IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && q_direction->coherence_band_data != NULL )
    1851             :                         {
    1852           0 :                             hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = ivas_divde_255[hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0]];
    1853           0 :                             move16();
    1854             :                         }
    1855             :                         ELSE
    1856             :                         {
    1857    19859636 :                             hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
    1858    19859636 :                             move16();
    1859             :                         }
    1860             : 
    1861    19859636 :                         hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio_fx[0];
    1862    19859636 :                         move32();
    1863    19859636 :                         hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx;
    1864    19859636 :                         move32();
    1865             : 
    1866    19859636 :                         IF( hodirac_flag )
    1867             :                         {
    1868     6460800 :                             IF( idx_sec == 0 )
    1869             :                             {
    1870     3230400 :                                 hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
    1871     3230400 :                                 move16();
    1872     3230400 :                                 hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
    1873     3230400 :                                 move16();
    1874     3230400 :                                 hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
    1875     3230400 :                                 move32();
    1876             :                             }
    1877             :                             ELSE
    1878             :                             {
    1879     3230400 :                                 assert( idx_sec == 1 );
    1880     3230400 :                                 hSpatParamRendCom->elevation2[tmp_write_idx_band][b] = ele;
    1881     3230400 :                                 move16();
    1882     3230400 :                                 hSpatParamRendCom->azimuth2[tmp_write_idx_band][b] = azi;
    1883     3230400 :                                 move16();
    1884     3230400 :                                 hSpatParamRendCom->energy_ratio2_fx[tmp_write_idx_band][b] = L_sub( ONE_IN_Q30, diffuseness_sec_fx );
    1885     3230400 :                                 move32();
    1886             :                             }
    1887             :                         }
    1888             :                         ELSE
    1889             :                         {
    1890    13398836 :                             hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
    1891    13398836 :                             move16();
    1892    13398836 :                             hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
    1893    13398836 :                             move16();
    1894             :                         }
    1895             :                     }
    1896     2746076 :                     tmp_write_idx_param_band = add( tmp_write_idx_param_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
    1897             : 
    1898             : 
    1899             :                 } /* for ( block =...) */
    1900             :             }     /* for ( band = ...) */
    1901             :         }         /* for ( idx_sec = ...)*/
    1902             : 
    1903             :         /* Bands not transmitted -> zeroed*/
    1904      103202 :         FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ )
    1905             :         {
    1906           0 :             tmp_write_idx_band = hSpatParamRendCom->dirac_bs_md_write_idx;
    1907           0 :             move16();
    1908             : 
    1909           0 :             FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
    1910             :             {
    1911           0 :                 hSpatParamRendCom->spreadCoherence_fx[block][b] = 0;
    1912           0 :                 move16();
    1913           0 :                 hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0;
    1914           0 :                 move16();
    1915           0 :                 hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0;
    1916           0 :                 move32();
    1917           0 :                 hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
    1918           0 :                 move16();
    1919           0 :                 hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
    1920           0 :                 move16();
    1921           0 :                 hSpatParamRendCom->energy_ratio1_fx[block][b] = 0;
    1922           0 :                 move32();
    1923           0 :                 hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
    1924           0 :                 move32();
    1925           0 :                 hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
    1926           0 :                 move16();
    1927           0 :                 hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
    1928           0 :                 move16();
    1929             : 
    1930           0 :                 tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
    1931             :             }
    1932             :         }
    1933             :     }
    1934             :     /* update buffer write index */
    1935      143255 :     hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length;
    1936      143255 :     move16();
    1937             : 
    1938      143255 :     return;
    1939             : }
    1940             : 
    1941             : 
    1942             : /*-------------------------------------------------------------------------
    1943             :  * ivas_dirac_dec_set_md_map()
    1944             :  *
    1945             :  * Set metadata index mapping for DirAC
    1946             :  *------------------------------------------------------------------------*/
    1947             : 
    1948      160568 : void ivas_dirac_dec_set_md_map_fx(
    1949             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure     */
    1950             :     const Word16 nCldfbTs    /* i  : number of CLDFB time slots */
    1951             : )
    1952             : {
    1953             :     Word16 num_slots_in_subfr;
    1954             :     DIRAC_DEC_HANDLE hDirAC;
    1955             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    1956             : 
    1957      160568 :     hDirAC = st_ivas->hDirAC;
    1958      160568 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1959             : 
    1960             :     /* adapt subframes */
    1961      160568 :     hSpatParamRendCom->num_slots = nCldfbTs;
    1962      160568 :     move16();
    1963      160568 :     hSpatParamRendCom->slots_rendered = 0;
    1964      160568 :     move16();
    1965      160568 :     num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
    1966      160568 :     move16();
    1967      160568 :     hSpatParamRendCom->subframes_rendered = 0;
    1968      160568 :     move16();
    1969             : 
    1970      160568 :     ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes );
    1971             : 
    1972             :     /* copy also to tc buffer */
    1973             :     /* only for non-combined formats and combinded formats w/o discrete objects */
    1974      160568 :     test();
    1975      160568 :     test();
    1976      160568 :     test();
    1977      160568 :     IF( ( NE_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) && !( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) )
    1978             :     {
    1979      139760 :         st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes;
    1980      139760 :         move16();
    1981      139760 :         Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes );
    1982             :     }
    1983             : 
    1984             :     /* set mapping according to dirac_read_idx */
    1985      160568 :     set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
    1986             : 
    1987      160568 :     test();
    1988      160568 :     test();
    1989      160568 :     IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
    1990             :     {
    1991       26872 :         ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
    1992             :     }
    1993      133696 :     ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
    1994             :     {
    1995       83570 :         ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
    1996             :     }
    1997             :     ELSE
    1998             :     {
    1999       50126 :         ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map );
    2000             :     }
    2001             : 
    2002      160568 :     test();
    2003      160568 :     test();
    2004      160568 :     IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
    2005             :     {
    2006             :         Word16 sf_idx, slot_idx, slot_idx_abs;
    2007             :         Word32 tmp_fx;
    2008             :         Word32 num;
    2009             :         Word16 denom, norm_denom, exp_denom, exp_num, norm_num, exp;
    2010             :         Word32 ans, ans_fix_32;
    2011             :         Word16 ans_fix_16, exp_final;
    2012             : 
    2013      110442 :         slot_idx_abs = 0;
    2014      110442 :         move16();
    2015      558259 :         FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ )
    2016             :         {
    2017      447817 :             tmp_fx = 0;
    2018      447817 :             move32();
    2019     2215073 :             FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ )
    2020             :             {
    2021     1767256 :                 tmp_fx = L_add( tmp_fx, L_deposit_h( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) );
    2022     1767256 :                 slot_idx_abs = add( slot_idx_abs, 1 );
    2023             :             }
    2024             : 
    2025      447817 :             exp_denom = 15, exp_num = 31;
    2026      447817 :             move16();
    2027      447817 :             move16();
    2028      447817 :             norm_num = norm_l( tmp_fx );
    2029      447817 :             num = L_shl( tmp_fx, norm_num );
    2030      447817 :             exp_num = sub( exp_num, norm_num );
    2031             : 
    2032      447817 :             norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] );
    2033      447817 :             denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom );
    2034      447817 :             exp_denom = sub( exp_denom, norm_denom );
    2035             : 
    2036      447817 :             exp = sub( exp_num, exp_denom );
    2037             : 
    2038      447817 :             IF( GT_32( num, L_deposit_l( denom ) ) )
    2039             :             {
    2040      337349 :                 num = L_shr( num, 1 );
    2041      337349 :                 exp = add( exp, 1 );
    2042             :             }
    2043             : 
    2044      447817 :             ans = div_l( num, denom );
    2045      447817 :             ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final );
    2046      447817 :             ans_fix_16 = round_fx( L_shr( ans_fix_32, sub( sub( Q31, exp_final ), Q16 ) ) );
    2047             : 
    2048      447817 :             hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; // Q0
    2049      447817 :             move16();
    2050             :         }
    2051      110442 :         set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) );
    2052             :     }
    2053             : 
    2054      160568 :     return;
    2055             : }
    2056             : 
    2057             : 
    2058             : /*-------------------------------------------------------------------------
    2059             :  * ivas_dirac_dec_render_fx()
    2060             :  *
    2061             :  * DirAC decoding renderer process
    2062             :  *------------------------------------------------------------------------*/
    2063             : 
    2064       20830 : void ivas_dirac_dec_render_fx(
    2065             :     Decoder_Struct *st_ivas,        /* i/o: IVAS decoder handle                      */
    2066             :     const Word16 nchan_transport,   /* i  : number of transport channels             */
    2067             :     const UWord16 nSamplesAsked,    /* i  : number of CLDFB slots requested          */
    2068             :     UWord16 *nSamplesRendered,      /* o  : number of CLDFB slots rendered           */
    2069             :     UWord16 *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render    */
    2070             :     Word32 *output_fx[]             /* o  : rendered time signal                     Q(6-1)*/
    2071             : )
    2072             : {
    2073             :     Word16 slots_to_render, first_sf, last_sf, subframe_idx;
    2074             :     UWord16 slot_size, n_samples_sf, ch, nchan_intern;
    2075       20830 :     Word16 temp = 0;
    2076       20830 :     move16();
    2077             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    2078             :     Word32 *output_fx_local[MAX_OUTPUT_CHANNELS];
    2079             : #ifdef FIX_RENDERER_STACK
    2080             :     Word32 *p_output_fx[MAX_OUTPUT_CHANNELS];
    2081             :     Word32 output_fx_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    2082             : #else
    2083             :     Word32 output_fx_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 };
    2084             : #endif
    2085             : 
    2086       20830 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    2087             : 
    2088       20830 :     nchan_intern = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
    2089      152587 :     FOR( ch = 0; ch < nchan_intern; ch++ )
    2090             :     {
    2091      131757 :         output_fx_local[ch] = output_fx_local_buff[ch];
    2092             : #ifdef FIX_RENDERER_STACK
    2093      131757 :         p_output_fx[ch] = output_fx[ch];
    2094             : #else
    2095             :         set_zero_fx( output_fx_local[ch], nSamplesAsked );
    2096             : #endif
    2097             :     }
    2098       20830 :     slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL
    2099             : 
    2100             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    2101       20830 :     slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) );
    2102             : 
    2103       20830 :     *nSamplesRendered = i_mult( slots_to_render, slot_size );
    2104       20830 :     move16();
    2105             : 
    2106       20830 :     first_sf = hSpatParamRendCom->subframes_rendered;
    2107       20830 :     move16();
    2108       20830 :     last_sf = first_sf;
    2109       20830 :     move16();
    2110             : 
    2111       92557 :     WHILE( slots_to_render > 0 )
    2112             :     {
    2113       71727 :         slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] );
    2114       71727 :         last_sf = add( last_sf, 1 );
    2115             :     }
    2116             : 
    2117       92557 :     FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    2118             :     {
    2119       71727 :         ivas_dirac_dec_render_sf_fx( st_ivas, output_fx_local, nchan_transport, NULL, NULL );
    2120             : 
    2121       71727 :         n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size );
    2122             : 
    2123      548045 :         FOR( ch = 0; ch < nchan_intern; ch++ )
    2124             :         {
    2125             : #ifdef FIX_RENDERER_STACK
    2126             :             /* move to output */
    2127      476318 :             test();
    2128      476318 :             test();
    2129      476318 :             IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) )
    2130             :             {
    2131      474566 :                 Copy32( output_fx_local_buff[ch], p_output_fx[ch], n_samples_sf );
    2132             :             }
    2133             : 
    2134      476318 :             p_output_fx[ch] += n_samples_sf;
    2135             : #else
    2136             :             output_fx_local[ch] += n_samples_sf;
    2137             : #endif
    2138             :         }
    2139             : 
    2140             :         /* update combined orientation access index */
    2141       71727 :         ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
    2142             :     }
    2143             : 
    2144             : #ifndef FIX_RENDERER_STACK
    2145             :     FOR( ch = 0; ch < nchan_intern; ch++ )
    2146             :     {
    2147             :         test();
    2148             :         test();
    2149             :         IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) )
    2150             :         {
    2151             :             Copy32( output_fx_local_buff[ch], output_fx[ch], *nSamplesRendered );
    2152             :         }
    2153             :     }
    2154             : #endif
    2155             :     /* clang-format off */
    2156       20830 :     IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) )
    2157             :     {
    2158       17648 :         IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) )
    2159             :         {
    2160           0 :             temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS );
    2161           0 :             hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
    2162             :         }
    2163             :         ELSE
    2164             :         {
    2165       17648 :             temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS );
    2166       17648 :             hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
    2167             :         }
    2168             :     }
    2169             : 
    2170       20830 :     *nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); // Q0
    2171       20830 :     move16();
    2172             : 
    2173       20830 :     return;
    2174             : }
    2175             : /* clang-format on */
    2176             : 
    2177             : 
    2178             : #ifdef FIX_1319_STACK_SBA_DECODER
    2179             : /*-------------------------------------------------------------------------
    2180             :  * Local functions to perform binaural rendering with optimized stack
    2181             :  *------------------------------------------------------------------------*/
    2182             : 
    2183           0 : static void binRenderer_split_fx(
    2184             :     BINAURAL_RENDERER_HANDLE hBinRenderer,                                                                        /* i/o: binaural renderer handle                      */
    2185             :     ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend,                                                             /* i/o: ISAR split binaural rendering handle          */
    2186             :     COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,                                                         /* i  : combined head and external orientation handle */
    2187             :     const Word16 numTimeSlots,                                                                                    /* i  : number of time slots to render                */
    2188             :     Word32 Cldfb_RealBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Rotated Binaural signals                      */
    2189             :     Word32 Cldfb_ImagBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Rotated Binaural signals                      */
    2190             :     Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],                                   /* i  : LS signals                                    */
    2191             :     Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],                                   /* i  : LS signals                                    */
    2192             :     const Word16 slot_idx_start,
    2193             :     const Word16 num_freq_bands,
    2194             :     const Word16 nchan_out )
    2195             : {
    2196             :     Word16 pos_idx, slot_idx, ch, input_q;
    2197             :     Word32 Cldfb_RealBuffer_Binaural_loc[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2198             :     Word32 Cldfb_ImagBuffer_Binaural_loc[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2199             : 
    2200           0 :     input_q = Q6;
    2201           0 :     move16();
    2202             : 
    2203             :     /* Perform binaural rendering */
    2204           0 :     ivas_binRenderer_fx( hBinRenderer, &hSplitBinRend->splitrend.multiBinPoseData, hCombinedOrientationData, numTimeSlots,
    2205             : #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG
    2206             :                          NULL,
    2207             : #endif
    2208             :                          Cldfb_RealBuffer_Binaural_loc, Cldfb_ImagBuffer_Binaural_loc, RealBuffer_fx, ImagBuffer_fx, &input_q );
    2209             : 
    2210           0 :     FOR( slot_idx = 0; slot_idx < numTimeSlots; slot_idx++ )
    2211             :     {
    2212           0 :         FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    2213             :         {
    2214           0 :             Copy32( Cldfb_RealBuffer_Binaural_loc[0][ch][slot_idx], Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], num_freq_bands );
    2215           0 :             Copy32( Cldfb_ImagBuffer_Binaural_loc[0][ch][slot_idx], Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], num_freq_bands );
    2216             :         }
    2217             :     }
    2218             : 
    2219           0 :     FOR( pos_idx = 0; pos_idx < hBinRenderer->numPoses; pos_idx++ )
    2220             :     {
    2221           0 :         FOR( slot_idx = 0; slot_idx < numTimeSlots; slot_idx++ )
    2222             :         {
    2223           0 :             FOR( ch = 0; ch < nchan_out; ch++ )
    2224             :             {
    2225           0 :                 Copy32( Cldfb_RealBuffer_Binaural_loc[pos_idx][ch][slot_idx], hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], num_freq_bands );
    2226           0 :                 Copy32( Cldfb_ImagBuffer_Binaural_loc[pos_idx][ch][slot_idx], hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], num_freq_bands );
    2227             :             }
    2228             :         }
    2229             :     }
    2230             : 
    2231           0 :     return;
    2232             : }
    2233             : 
    2234             : 
    2235      125727 : static void binRenderer_fx(
    2236             :     BINAURAL_RENDERER_HANDLE hBinRenderer,                                                                        /* i/o: binaural renderer handle                      */
    2237             :     COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,                                                         /* i  : combined head and external orientation handle */
    2238             :     const Word16 numTimeSlots,                                                                                    /* i  : number of time slots to render                */
    2239             :     Word32 Cldfb_RealBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Rotated Binaural signals                      */
    2240             :     Word32 Cldfb_ImagBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Rotated Binaural signals                      */
    2241             :     Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],                                   /* i  : LS signals                                    */
    2242             :     Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]                                    /* i  : LS signals                                    */
    2243             : )
    2244             : {
    2245             :     Word16 input_q;
    2246             : 
    2247      125727 :     input_q = Q6;
    2248      125727 :     move16();
    2249             : 
    2250             :     /* Perform binaural rendering */
    2251      125727 :     ivas_binRenderer_fx( hBinRenderer, NULL, hCombinedOrientationData, numTimeSlots,
    2252             : #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG
    2253             :                          NULL,
    2254             : #endif
    2255             :                          Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, RealBuffer_fx, ImagBuffer_fx, &input_q );
    2256             : 
    2257      125727 :     return;
    2258             : }
    2259             : #endif
    2260             : 
    2261             : 
    2262             : /*-------------------------------------------------------------------------
    2263             :  * ivas_dirac_dec_render_sf_fx()
    2264             :  *
    2265             :  * DirAC decoding renderer process
    2266             :  *------------------------------------------------------------------------*/
    2267             : 
    2268      318389 : void ivas_dirac_dec_render_sf_fx(
    2269             :     Decoder_Struct *st_ivas,      /* i/o: IVAS decoder structure                                  */
    2270             :     Word32 *output_buf_fx[],      /* i/o: synthesized core-coder transport channels/DirAC output  Q(6-1)*/
    2271             :     const Word16 nchan_transport, /* i  : number of transport channels                            */
    2272             : #ifdef FIX_1319_STACK_SBA_DECODER
    2273             :     Word32 *pppQMfFrame_ts_re_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX],
    2274             :     Word32 *pppQMfFrame_ts_im_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX]
    2275             : #else
    2276             :     Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], /*Q6*/
    2277             :     Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX]  /*Q6*/
    2278             : #endif
    2279             : )
    2280             : {
    2281             :     Word16 i, ch, idx_in, idx_lfe;
    2282             :     DIRAC_DEC_HANDLE hDirAC;
    2283             :     DIRAC_REND_HANDLE hDirACRend;
    2284             :     Word16 subframe_idx;
    2285             :     Word16 slot_idx, index_slot;
    2286             :     Word16 hodirac_flag;
    2287             :     Word16 slot_idx_start, slot_idx_start_cldfb_synth, md_idx;
    2288             : 
    2289             :     /*CLDFB: last output channels reserved to LFT for CICPx*/
    2290             : #ifdef FIX_1319_STACK_SBA_DECODER
    2291             :     Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2292             :     Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2293             :     Word32 Cldfb_RealBuffer_Binaural_fx[1][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2294             :     Word32 Cldfb_ImagBuffer_Binaural_fx[1][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2295             : #else
    2296             :     Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
    2297             :     Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
    2298             :     Word32 Cldfb_RealBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
    2299             :     Word32 Cldfb_ImagBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
    2300             : #endif
    2301      318389 :     Word16 index = 0, num_freq_bands = 0;
    2302      318389 :     move16();
    2303      318389 :     move16();
    2304             : 
    2305             :     /* local copies of azi, ele, diffuseness */
    2306             :     Word16 azimuth[CLDFB_NO_CHANNELS_MAX];
    2307             :     Word16 elevation[CLDFB_NO_CHANNELS_MAX];
    2308             :     Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX];
    2309             :     Word32 *p_Rmat_fx;
    2310             :     Word32 *reference_power_fx, *reference_power_smooth_fx, *onset_filter_fx, *onset_filter_subframe_fx;
    2311             :     Word32 dirEne_fx;
    2312             :     Word32 surCohEner_fx;
    2313             :     Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX];
    2314      318389 :     Word16 surCohRatio_q_fx = 0, temp_q = 0;
    2315      318389 :     move16();
    2316      318389 :     move16();
    2317             : #ifndef FIX_1319_STACK_SBA_DECODER
    2318             :     Word32 Cldfb_RealBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2319             :     Word32 Cldfb_ImagBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2320             : #endif
    2321             : #ifndef FIX_2140_OBJECT_EDITING_SANITIZER_ISSUES
    2322             :     Word16 cldfb_buf_q;
    2323             : #endif
    2324      318389 :     Word16 offset = 0, buff_len = 0;
    2325      318389 :     move16();
    2326      318389 :     move16();
    2327      318389 :     Word16 q_cldfb, q_temp_cldfb = 0;
    2328      318389 :     move16();
    2329      318389 :     Word16 proto_length = 0;
    2330      318389 :     move16();
    2331             :     Word16 q_proto_direct_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
    2332             :     Word16 q_proto_diffuse_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
    2333             :     Word16 size, size_ho;
    2334             : 
    2335             :     DIRAC_DEC_STACK_MEM DirAC_mem;
    2336      318389 :     Word32 *p_onset_filter_fx = NULL;
    2337             :     UWord16 coherence_flag;
    2338             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    2339      318389 :     Word16 scale = 0;
    2340      318389 :     move16();
    2341             :     DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
    2342             :     DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
    2343             :     Word16 num_channels_dir, exp;
    2344      318389 :     Word16 q_diffuseness_vector = Q31, q_reference_power_smooth[2] = { Q31, Q31 };
    2345      318389 :     move16();
    2346      318389 :     move16();
    2347      318389 :     move16();
    2348      318389 :     Word16 proto_power_smooth_len = 0;
    2349      318389 :     move16();
    2350             :     Word16 tmp1;
    2351             : 
    2352      318389 :     push_wmops( "ivas_dirac_dec_render" );
    2353             : 
    2354             :     /* Initialize aux buffers */
    2355     5412613 :     FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
    2356             :     {
    2357    25471120 :         FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
    2358             :         {
    2359    20376896 :             set32_fx( Cldfb_RealBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
    2360    20376896 :             set32_fx( Cldfb_ImagBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
    2361             :         }
    2362             :     }
    2363             : 
    2364      318389 :     hDirAC = st_ivas->hDirAC;
    2365      318389 :     hDirACRend = st_ivas->hDirACRend;
    2366      318389 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    2367             : 
    2368      318389 :     DirAC_mem = hDirACRend->stack_mem;
    2369             : 
    2370      318389 :     reference_power_fx = DirAC_mem.reference_power_fx;
    2371      318389 :     IF( DirAC_mem.reference_power_fx == NULL )
    2372             :     {
    2373        8647 :         reference_power_smooth_fx = NULL;
    2374             :     }
    2375             :     ELSE
    2376             :     {
    2377      309742 :         reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands;
    2378             :     }
    2379      318389 :     onset_filter_fx = DirAC_mem.onset_filter_fx;
    2380      318389 :     IF( DirAC_mem.onset_filter_fx == NULL )
    2381             :     {
    2382       22224 :         onset_filter_subframe_fx = NULL;
    2383             :     }
    2384             :     ELSE
    2385             :     {
    2386      296165 :         onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands;
    2387             :     }
    2388      318389 :     q_cldfb = Q11;
    2389      318389 :     move16();
    2390      318389 :     set16_fx( q_proto_direct_buffer, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
    2391      318389 :     set16_fx( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
    2392      318389 :     set_zero_fx( surCohRatio_fx, CLDFB_NO_CHANNELS_MAX );
    2393             : 
    2394      318389 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
    2395             :     {
    2396        8228 :         IF( hDirACRend->masa_stereo_type_detect )
    2397             :         {
    2398        8228 :             hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = 0;
    2399        8228 :             move32();
    2400        8228 :             hDirACRend->masa_stereo_type_detect->q_subtract_power_y = Q31;
    2401        8228 :             move16();
    2402             :         }
    2403             :     }
    2404             : 
    2405      318389 :     test();
    2406      318389 :     IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
    2407             :     {
    2408       68848 :         IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 )
    2409             :         {
    2410       54852 :             DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state );
    2411       54852 :             tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len );
    2412             : 
    2413       54852 :             scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); // Q(proto_power_diff_smooth_q + tmp1)
    2414       54852 :             state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 );
    2415       54852 :             move16();
    2416             :         }
    2417             :     }
    2418             : 
    2419      318389 :     h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
    2420      318389 :     h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
    2421      318389 :     num_channels_dir = hDirACRend->num_outputs_dir;
    2422      318389 :     move16();
    2423      318389 :     hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
    2424      318389 :     if ( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
    2425             :     {
    2426       55721 :         num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
    2427       55721 :         move16();
    2428             :     }
    2429             : 
    2430      318389 :     test();
    2431      318389 :     test();
    2432      318389 :     IF( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) )
    2433             :     {
    2434       41725 :         tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    2435       41725 :         scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); // tmp1
    2436       41725 :         h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1;
    2437       41725 :         move16();
    2438             :     }
    2439             : 
    2440      318389 :     test();
    2441      318389 :     IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2442             :     {
    2443             :         Word16 shift;
    2444       13996 :         shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    2445       13996 :         scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift
    2446       13996 :         h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift );
    2447       13996 :         move16();
    2448       13996 :         shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    2449       13996 :         scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift
    2450       13996 :         h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift );
    2451       13996 :         move16();
    2452       13996 :         tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    2453       13996 :         scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + tmp1
    2454       13996 :         h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 );
    2455       13996 :         move16();
    2456             :     }
    2457             : 
    2458      318389 :     test();
    2459      318389 :     test();
    2460      318389 :     IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    2461             :     {
    2462      377181 :         FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
    2463             :         {
    2464      251454 :             st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
    2465      251454 :             move16();
    2466             :         }
    2467             :     }
    2468      192662 :     ELSE IF( !( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
    2469             :     {
    2470             :         Word16 outchannels;
    2471       71727 :         idx_lfe = 0;
    2472       71727 :         move16();
    2473       71727 :         idx_in = 0;
    2474       71727 :         move16();
    2475       71727 :         outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
    2476             : 
    2477       71727 :         test();
    2478       71727 :         test();
    2479       71727 :         test();
    2480       71727 :         test();
    2481       71727 :         test();
    2482       71727 :         test();
    2483       71727 :         test();
    2484       71727 :         IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
    2485             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
    2486             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
    2487             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
    2488             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
    2489             :                                                               ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
    2490             :         {
    2491         876 :             outchannels = add( outchannels, 1 );
    2492             :         }
    2493             : 
    2494       71727 :         test();
    2495       71727 :         IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
    2496             :         {
    2497           0 :             FOR( ch = 0; ch < outchannels; ch++ )
    2498             :             {
    2499           0 :                 test();
    2500           0 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    2501             :                 {
    2502           0 :                     IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    2503             :                     {
    2504           0 :                         idx_lfe = add( idx_lfe, 1 );
    2505             :                     }
    2506             :                 }
    2507             :             }
    2508             :         }
    2509             :         ELSE
    2510             :         {
    2511      548045 :             FOR( ch = 0; ch < outchannels; ch++ )
    2512             :             {
    2513             : 
    2514      476318 :                 test();
    2515      476318 :                 test();
    2516      476318 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    2517             :                 {
    2518       41725 :                     test();
    2519       41725 :                     IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
    2520             :                     {
    2521             :                         Word16 cldfbSynIdx;
    2522        6640 :                         cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
    2523        6640 :                         st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
    2524        6640 :                         move16();
    2525             :                     }
    2526             :                 }
    2527      434593 :                 ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
    2528             :                 {
    2529             :                 }
    2530             :                 ELSE
    2531             :                 {
    2532      433717 :                     st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
    2533      433717 :                     move16();
    2534      433717 :                     idx_in = add( idx_in, 1 );
    2535             :                 }
    2536             :             }
    2537             :         }
    2538             :     }
    2539             : 
    2540      318389 :     size = imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
    2541      318389 :     IF( hodirac_flag )
    2542             :     {
    2543       53840 :         size_ho = imult1616( size, DIRAC_HO_NUMSECTORS );
    2544             :     }
    2545             :     ELSE
    2546             :     {
    2547      264549 :         size_ho = size;
    2548      264549 :         move16();
    2549             :     }
    2550      318389 :     scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26
    2551      318389 :     hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26;
    2552      318389 :     move16();
    2553             : 
    2554      318389 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2555             :     {
    2556             :         Word16 shift;
    2557      241313 :         shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho );
    2558      241313 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth + shift)
    2559      241313 :         hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift );
    2560      241313 :         move16();
    2561             : 
    2562      241313 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26
    2563      241313 :         hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26;
    2564      241313 :         move16();
    2565             : 
    2566      241313 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26
    2567      241313 :         hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26;
    2568      241313 :         move16();
    2569             : 
    2570      241313 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26
    2571      241313 :         hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26;
    2572      241313 :         move16();
    2573             :     }
    2574             :     ELSE
    2575             :     {
    2576             :         Word16 shift;
    2577       77076 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26
    2578       77076 :         hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26;
    2579       77076 :         move16();
    2580             : 
    2581       77076 :         shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho );
    2582       77076 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); // Q( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev+ shift)
    2583       77076 :         hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift );
    2584       77076 :         move16();
    2585       77076 :         shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho );
    2586       77076 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev + shift)
    2587       77076 :         hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift );
    2588       77076 :         move16();
    2589       77076 :         tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ) );
    2590       77076 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev+ tmp1)
    2591       77076 :         hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp1 );
    2592       77076 :         move16();
    2593       77076 :         tmp1 = 31;
    2594       77076 :         move16();
    2595      327130 :         FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
    2596             :         {
    2597      250054 :             tmp1 = s_min( tmp1, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
    2598             :         }
    2599      327130 :         FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
    2600             :         {
    2601      250054 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q tmp1)
    2602             :         }
    2603       77076 :         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0], tmp1 );
    2604       77076 :         move16();
    2605       77076 :         tmp1 = 31;
    2606       77076 :         move16();
    2607      327130 :         FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
    2608             :         {
    2609      250054 :             tmp1 = s_min( tmp1, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ) );
    2610             :         }
    2611      327130 :         FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
    2612             :         {
    2613      250054 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q tmp1)
    2614             :         }
    2615       77076 :         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1], tmp1 );
    2616       77076 :         move16();
    2617       77076 :         IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
    2618             :         {
    2619       54852 :             tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) );
    2620       54852 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q+ tmp1)
    2621       54852 :             hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, tmp1 );
    2622       54852 :             move16();
    2623             :         }
    2624             :     }
    2625             : 
    2626      318389 :     hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
    2627             : 
    2628      318389 :     test();
    2629      318389 :     test();
    2630      318389 :     IF( st_ivas->hQMetaData != NULL && NE_32( st_ivas->ivas_format, SBA_FORMAT ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    2631             :     {
    2632       71727 :         coherence_flag = st_ivas->hQMetaData->coherence_flag;
    2633       71727 :         move16();
    2634             :     }
    2635             :     ELSE
    2636             :     {
    2637      246662 :         coherence_flag = 0;
    2638      246662 :         move16();
    2639             :     }
    2640             :     /* Subframe loop */
    2641      318389 :     slot_idx_start = hSpatParamRendCom->slots_rendered;
    2642      318389 :     move16();
    2643      318389 :     slot_idx_start_cldfb_synth = 0;
    2644      318389 :     move16();
    2645             : 
    2646      318389 :     subframe_idx = hSpatParamRendCom->subframes_rendered;
    2647      318389 :     move16();
    2648      318389 :     IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
    2649             :     {
    2650      125567 :         md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
    2651      125567 :         move16();
    2652             :     }
    2653             :     ELSE
    2654             :     {
    2655      192822 :         md_idx = hSpatParamRendCom->render_to_md_map[slot_idx_start];
    2656      192822 :         move16();
    2657             :     }
    2658             : 
    2659             :     /* copy parameters into local buffers*/
    2660      318389 :     IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
    2661             :     {
    2662      125567 :         Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
    2663      125567 :         q_diffuseness_vector = Q30;
    2664      125567 :         move16();
    2665      125567 :         Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands );
    2666      125567 :         Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands );
    2667             :     }
    2668             :     ELSE
    2669             :     {
    2670      192822 :         set32_fx( diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands );
    2671      192822 :         q_diffuseness_vector = Q31;
    2672      192822 :         move16();
    2673             :     }
    2674             : 
    2675      318389 :     IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2676             :     {
    2677       77076 :         set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands );
    2678             :     }
    2679             :     ELSE
    2680             :     {
    2681      241313 :         set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands );
    2682             :     }
    2683             : 
    2684      318389 :     test();
    2685      318389 :     IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] )
    2686             :     {
    2687       41400 :         p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0];
    2688             : 
    2689       41400 :         IF( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
    2690             :         {
    2691       36800 :             num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
    2692       36800 :             move16();
    2693       36800 :             IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
    2694             :             {
    2695           0 :                 rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
    2696             :             }
    2697             :         }
    2698             :     }
    2699             :     ELSE
    2700             :     {
    2701      276989 :         p_Rmat_fx = 0;
    2702      276989 :         move32();
    2703             :     }
    2704             : 
    2705      318389 :     IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
    2706             :     {
    2707             :         Word16 *masa_band_mapping;
    2708             :         /* compute response */
    2709      125567 :         IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2710             :         {
    2711       63080 :             ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands,
    2712             :                                                      diffuseness_vector_fx,
    2713       63080 :                                                      hDirACRend->h_output_synthesis_psd_params.max_band_decorr,
    2714             :                                                      hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
    2715             :                                                      hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx );
    2716             : 
    2717       63080 :             hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29;
    2718       63080 :             move16();
    2719       63080 :             hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29;
    2720       63080 :             move16();
    2721             : 
    2722       63080 :             IF( coherence_flag )
    2723             :             {
    2724     1650855 :                 FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
    2725             :                 {
    2726     1621080 :                     dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // Q29
    2727     1621080 :                     move32();
    2728     1621080 :                     surCohEner_fx = Mpy_32_16_1( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // Q29 + Q15 - Q15 = Q29
    2729             : 
    2730     1621080 :                     hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx ); // Q29
    2731     1621080 :                     move32();
    2732     1621080 :                     hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); // Q29
    2733     1621080 :                     move32();
    2734             : 
    2735     1621080 :                     surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale_newton( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q );
    2736     1621080 :                     move32();
    2737     1621080 :                     surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], sub( temp_q, 16 ) ); // Q15
    2738     1621080 :                     move32();
    2739             :                 }
    2740             :             }
    2741             :             ELSE
    2742             :             {
    2743       33305 :                 set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
    2744             :             }
    2745       63080 :             surCohRatio_q_fx = Q15;
    2746       63080 :             move16();
    2747             :         }
    2748             :         ELSE
    2749             :         {
    2750             :             Word16 max_exp_direct, max_exp_diffusion;
    2751       62487 :             max_exp_direct = 0;
    2752       62487 :             move16();
    2753       62487 :             max_exp_diffusion = 0;
    2754       62487 :             move16();
    2755       62487 :             ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands,
    2756       62487 :                                                     hSpatParamRendCom->diffuseness_vector_fx[md_idx],
    2757             :                                                     hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
    2758             :                                                     hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx,
    2759             :                                                     &max_exp_direct, &max_exp_diffusion );
    2760             : 
    2761       62487 :             hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( Q31, max_exp_direct );
    2762       62487 :             move16();
    2763       62487 :             hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( Q31, max_exp_diffusion );
    2764       62487 :             move16();
    2765             : 
    2766       62487 :             IF( coherence_flag )
    2767             :             {
    2768      263947 :                 FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
    2769             :                 {
    2770      259620 :                     surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] );
    2771      259620 :                     move32();
    2772             :                 }
    2773             :             }
    2774             :             ELSE
    2775             :             {
    2776       58160 :                 set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
    2777             :             }
    2778       62487 :             surCohRatio_q_fx = Q15;
    2779       62487 :             move16();
    2780             :         }
    2781             : 
    2782      125567 :         IF( st_ivas->hMasa == NULL )
    2783             :         {
    2784       53840 :             masa_band_mapping = NULL;
    2785             :         }
    2786             :         ELSE
    2787             :         {
    2788       71727 :             masa_band_mapping = st_ivas->hMasa->data.band_mapping;
    2789             :         }
    2790      125567 :         ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom,
    2791             :                                                          hDirACRend,
    2792             :                                                          st_ivas->hVBAPdata,
    2793             :                                                          masa_band_mapping,
    2794             :                                                          st_ivas->hMasaIsmData,
    2795             :                                                          azimuth,
    2796             :                                                          elevation,
    2797             :                                                          md_idx,
    2798             :                                                          surCohRatio_fx,
    2799             :                                                          surCohRatio_q_fx,
    2800             :                                                          hodirac_flag );
    2801             :     }
    2802             : 
    2803      318389 :     test();
    2804      318389 :     IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
    2805             :     {
    2806       50647 :         FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    2807             :         {
    2808       40273 :             index_slot = add( slot_idx_start, slot_idx );
    2809       40273 :             offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
    2810             :             /* CLDFB Analysis*/
    2811      120819 :             FOR( ch = 0; ch < nchan_transport; ch++ )
    2812             :             {
    2813       80546 :                 q_temp_cldfb = Q11;
    2814       80546 :                 move16();
    2815             : #ifdef FIX_1319_STACK_SBA_DECODER
    2816       80546 :                 cldfbAnalysis_ts_fx_fixed_q( &( st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ),
    2817       80546 :                                              Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], /* note: it is a tmp. buffer at this point */
    2818       80546 :                                              Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], /* note: it is a tmp. buffer at this point */
    2819       80546 :                                              hSpatParamRendCom->num_freq_bands,
    2820             :                                              st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
    2821             : #else
    2822             :                 cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset],
    2823             :                                              Cldfb_RealBuffer_Temp_fx[ch][slot_idx],
    2824             :                                              Cldfb_ImagBuffer_Temp_fx[ch][slot_idx],
    2825             :                                              hSpatParamRendCom->num_freq_bands,
    2826             :                                              st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
    2827             : #endif
    2828             :             }
    2829       40273 :             q_cldfb = q_temp_cldfb;
    2830       40273 :             move16();
    2831             :         }
    2832             : 
    2833       10374 :         IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
    2834             :         {
    2835             : #ifdef FIX_1319_STACK_SBA_DECODER
    2836             : #ifdef FIX_2140_OBJECT_EDITING_SANITIZER_ISSUES
    2837        2713 :             ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( st_ivas, Cldfb_RealBuffer_Binaural_fx[0], Cldfb_ImagBuffer_Binaural_fx[0], &q_cldfb, hSpatParamRendCom->num_freq_bands, subframe_idx );
    2838             : #else
    2839             :             ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( st_ivas, Cldfb_RealBuffer_Binaural_fx[0], Cldfb_ImagBuffer_Binaural_fx[0], &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx );
    2840             : #endif
    2841             : #else
    2842             :             ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx );
    2843             : #endif
    2844             :         }
    2845             :     }
    2846             : 
    2847     1583279 :     FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    2848             :     {
    2849     1264890 :         index_slot = add( slot_idx_start, slot_idx );
    2850     1264890 :         IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
    2851             :         {
    2852      767083 :             md_idx = hSpatParamRendCom->render_to_md_map[index_slot];
    2853      767083 :             move16();
    2854             :         }
    2855             :         ELSE
    2856             :         {
    2857      497807 :             md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
    2858      497807 :             move16();
    2859             :         }
    2860     1264890 :         test();
    2861     1264890 :         test();
    2862     1264890 :         IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
    2863             :         {
    2864     6415783 :             FOR( ch = 0; ch < nchan_transport; ch++ )
    2865             :             {
    2866     5433340 :                 Copy32( pppQMfFrame_ts_re_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2867     5433340 :                 Copy32( pppQMfFrame_ts_im_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2868             :             }
    2869      982443 :             q_cldfb = Q6;
    2870      982443 :             move16();
    2871             :         }
    2872      282447 :         ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
    2873             :         {
    2874      120819 :             FOR( ch = 0; ch < nchan_transport; ch++ )
    2875             :             {
    2876             : #ifdef FIX_1319_STACK_SBA_DECODER
    2877       80546 :                 Copy32( Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2878       80546 :                 Copy32( Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2879             : #else
    2880             :                 Copy32( Cldfb_RealBuffer_Temp_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2881             :                 Copy32( Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2882             : #endif
    2883             :             }
    2884             :         }
    2885             :         ELSE
    2886             :         {
    2887             :             /* CLDFB Analysis*/
    2888      242174 :             offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
    2889      579671 :             FOR( ch = 0; ch < nchan_transport; ch++ )
    2890             :             {
    2891      337497 :                 q_temp_cldfb = Q11;
    2892      337497 :                 move16();
    2893      337497 :                 cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset],
    2894      337497 :                                              Cldfb_RealBuffer_fx[ch][0],
    2895      337497 :                                              Cldfb_ImagBuffer_fx[ch][0],
    2896      337497 :                                              hSpatParamRendCom->num_freq_bands,
    2897             :                                              st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
    2898             :             }
    2899      242174 :             q_cldfb = q_temp_cldfb;
    2900      242174 :             move16();
    2901             :         }
    2902             : 
    2903             :         /* CNG in DirAC, extra CLDFB ana for CNA*/
    2904     1264890 :         test();
    2905     1264890 :         test();
    2906     1264890 :         test();
    2907     1264890 :         test();
    2908     1264890 :         IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) )
    2909             :         {
    2910       34588 :             Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
    2911       34588 :             Word16 Q_input = Q11;
    2912       34588 :             move16();
    2913       34588 :             q_temp_cldfb = Q11;
    2914       34588 :             move16();
    2915       34588 :             test();
    2916       34588 :             test();
    2917       34588 :             test();
    2918      103764 :             generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom,
    2919             :                                                   st_ivas->cldfbAnaDec[1],
    2920       34588 :                                                   &st_ivas->hTcBuffer->tc_fx[1][hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->slots_rendered],
    2921             :                                                   Cldfb_RealBuffer_fx[1][0],
    2922             :                                                   Cldfb_ImagBuffer_fx[1][0],
    2923             :                                                   slot_idx,
    2924       34588 :                                                   st->cna_dirac_flag && st->flag_cna,
    2925       34588 :                                                   ( ( ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &q_temp_cldfb );
    2926       34588 :             Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
    2927       34588 :             Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
    2928             :         }
    2929             : 
    2930             :         /* LFE synthesis */
    2931     1264890 :         test();
    2932     1264890 :         test();
    2933     1264890 :         test();
    2934     1264890 :         IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && hDirACRend->hOutSetup.num_lfe == 0 ) )
    2935             :         {
    2936       26560 :             ivas_lfe_synth_with_cldfb_fx( st_ivas->hMasa->hMasaLfeSynth,
    2937             :                                           Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    2938             :                                           Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1],
    2939             :                                           slot_idx,
    2940             :                                           md_idx,
    2941             :                                           nchan_transport, q_cldfb );
    2942             :         }
    2943             : 
    2944             :         /*-----------------------------------------------------------------*
    2945             :          * protoype signal computation
    2946             :          *-----------------------------------------------------------------*/
    2947     1264890 :         IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2948             :         {
    2949      961047 :             test();
    2950      961047 :             test();
    2951      961047 :             IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
    2952             :             {
    2953      147200 :                 protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    2954             :                                                hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    2955             :                                                &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    2956             :                                                hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
    2957             :                                                &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
    2958             :                                                reference_power_fx, DirAC_mem.reference_power_q,
    2959             :                                                slot_idx, nchan_transport,
    2960      147200 :                                                hDirACRend->num_outputs_diff,
    2961      147200 :                                                hSpatParamRendCom->num_freq_bands,
    2962             :                                                p_Rmat_fx, q_cldfb );
    2963             :             }
    2964             :             ELSE
    2965             :             {
    2966      813847 :                 protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    2967             :                                                hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    2968             :                                                &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    2969             :                                                hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
    2970             :                                                &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
    2971             :                                                reference_power_fx, DirAC_mem.reference_power_q,
    2972             :                                                slot_idx, nchan_transport,
    2973      813847 :                                                hDirACRend->num_outputs_diff,
    2974      813847 :                                                hSpatParamRendCom->num_freq_bands,
    2975             :                                                0, q_cldfb );
    2976             :             }
    2977             : 
    2978      961047 :             q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
    2979      961047 :             move16();
    2980      961047 :             q_proto_diffuse_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q;
    2981      961047 :             move16();
    2982             :         }
    2983      303843 :         ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
    2984             :         {
    2985       29979 :             protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
    2986             :                                         &hDirACRend->proto_frame_f_q,
    2987             :                                         hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    2988             :                                         &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    2989             :                                         reference_power_fx,
    2990             :                                         DirAC_mem.reference_power_q,
    2991             :                                         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
    2992       29979 :                                         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
    2993       29979 :                                         0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect,
    2994             :                                         q_cldfb );
    2995             : 
    2996       29979 :             q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
    2997       29979 :             move16();
    2998             : 
    2999       29979 :             proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
    3000       29979 :             proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
    3001             :         }
    3002             :         ELSE
    3003             :         {
    3004      273864 :             SWITCH( nchan_transport )
    3005             :             {
    3006       55984 :                 case 11:
    3007             :                 case 8:
    3008             :                 case 6:
    3009             :                 case 4:
    3010       55984 :                     protoSignalComputation4_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    3011             :                                                 hDirACRend->proto_frame_f_fx,
    3012             :                                                 &hDirACRend->proto_frame_f_q,
    3013             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    3014             :                                                 &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    3015             :                                                 reference_power_fx,
    3016             :                                                 DirAC_mem.reference_power_q,
    3017             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
    3018       55984 :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
    3019       55984 :                                                 slot_idx, hDirACRend->num_outputs_diff,
    3020       55984 :                                                 hSpatParamRendCom->num_freq_bands,
    3021             :                                                 hDirACRend->hoa_decoder,
    3022             :                                                 nchan_transport,
    3023             :                                                 hDirACRend->sba_map_tc, q_cldfb );
    3024       55984 :                     proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    3025       55984 :                     proto_power_smooth_len = i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff );
    3026       55984 :                     BREAK;
    3027      105617 :                 case 2:
    3028      105617 :                     protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
    3029             :                                                 &hDirACRend->proto_frame_f_q,
    3030             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    3031             :                                                 &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    3032             :                                                 reference_power_fx,
    3033             :                                                 DirAC_mem.reference_power_q,
    3034             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
    3035      105617 :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
    3036      105617 :                                                 hDirACRend->hOutSetup.is_loudspeaker_setup,
    3037             :                                                 slot_idx,
    3038      105617 :                                                 hSpatParamRendCom->num_freq_bands,
    3039             :                                                 hDirACRend->masa_stereo_type_detect,
    3040             :                                                 q_cldfb );
    3041      105617 :                     proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
    3042      105617 :                     IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
    3043             :                     {
    3044       71168 :                         proto_power_smooth_len = i_mult( 3, hSpatParamRendCom->num_freq_bands );
    3045             :                     }
    3046             :                     ELSE
    3047             :                     {
    3048       34449 :                         proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
    3049             :                     }
    3050      105617 :                     BREAK;
    3051      112263 :                 case 1:
    3052      112263 :                     protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    3053             :                                                 hDirACRend->proto_frame_f_fx,
    3054             :                                                 &hDirACRend->proto_frame_f_q,
    3055             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    3056             :                                                 &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    3057             :                                                 reference_power_fx,
    3058             :                                                 DirAC_mem.reference_power_q,
    3059             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
    3060      112263 :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
    3061             :                                                 slot_idx,
    3062      112263 :                                                 hDirACRend->num_protos_diff,
    3063      112263 :                                                 hSpatParamRendCom->num_freq_bands, q_cldfb );
    3064      112263 :                     proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_diff ) );
    3065      112263 :                     proto_power_smooth_len = hSpatParamRendCom->num_freq_bands;
    3066      112263 :                     move16();
    3067      112263 :                     BREAK;
    3068           0 :                 default:
    3069           0 :                     return;
    3070             :             }
    3071      273864 :             q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
    3072      273864 :             move16();
    3073             :         }
    3074             : 
    3075             :         /*-----------------------------------------------------------------*
    3076             :          * Compute DirAC parameters at decoder side
    3077             :          *-----------------------------------------------------------------*/
    3078     1264890 :         IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
    3079             :         {
    3080      767083 :             Copy( &hSpatParamRendCom->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) );
    3081      767083 :             Copy( &hSpatParamRendCom->elevation[md_idx][hDirAC->hConfig->enc_param_start_band], &elevation[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) );
    3082             : 
    3083      767083 :             test();
    3084      767083 :             test();
    3085      767083 :             IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
    3086             :             {
    3087      147200 :                 num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
    3088      147200 :                 move16();
    3089      147200 :                 rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
    3090             :             }
    3091             : 
    3092             :             /*hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1 */
    3093      767083 :             IF( hDirACRend->index_buffer_intensity == 0 )
    3094             :             {
    3095         241 :                 hDirACRend->index_buffer_intensity = 1;
    3096         241 :                 move16();
    3097             :             }
    3098             :             ELSE
    3099             :             {
    3100      766842 :                 hDirACRend->index_buffer_intensity = add( sub( hDirACRend->index_buffer_intensity, i_mult( shr( hDirACRend->index_buffer_intensity, DIRAC_NO_COL_AVG_DIFF_LOG2 ), DIRAC_NO_COL_AVG_DIFF ) ), 1 ); /* averaging_length = 32 */
    3101      766842 :                 move16();
    3102             :             }
    3103             : 
    3104      767083 :             index = hDirACRend->index_buffer_intensity;
    3105      767083 :             move16();
    3106      767083 :             num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
    3107      767083 :             move16();
    3108             : 
    3109      767083 :             computeIntensityVector_dec_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    3110             :                                            q_cldfb, num_freq_bands,
    3111      767083 :                                            hDirACRend->buffer_intensity_real_fx[0][index - 1],
    3112      767083 :                                            hDirACRend->buffer_intensity_real_fx[1][index - 1],
    3113      767083 :                                            hDirACRend->buffer_intensity_real_fx[2][index - 1],
    3114      767083 :                                            &hDirACRend->q_buffer_intensity_real[index - 1] );
    3115             : 
    3116      767083 :             computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][index - 1],
    3117      767083 :                                        hDirACRend->buffer_intensity_real_fx[1][index - 1],
    3118      767083 :                                        hDirACRend->buffer_intensity_real_fx[2][index - 1],
    3119      767083 :                                        hDirACRend->q_buffer_intensity_real[index - 1],
    3120             :                                        num_freq_bands, azimuth, elevation );
    3121             : 
    3122      767083 :             Copy32( reference_power_fx, &( hDirACRend->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands );
    3123      767083 :             Scale_sig32( &( hDirACRend->buffer_energy_fx[add( i_mult( sub( index, 1 ), num_freq_bands ), CLDFB_NO_CHANNELS_HALF )] ), s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_q[1] ) );
    3124      767083 :             hDirACRend->q_buffer_energy[index - 1] = DirAC_mem.reference_power_q[0];
    3125      767083 :             move16();
    3126             : 
    3127      767083 :             computeDiffuseness_fx( hDirACRend->buffer_intensity_real_fx, hDirACRend->buffer_energy_fx, num_freq_bands, hSpatParamRendCom->diffuseness_vector_fx[md_idx], hDirACRend->q_buffer_intensity_real, hDirACRend->q_buffer_energy, &hSpatParamRendCom->q_diffuseness_vector );
    3128             :         }
    3129             : 
    3130             :         /*-----------------------------------------------------------------*
    3131             :          * frequency domain decorrelation
    3132             :          *-----------------------------------------------------------------*/
    3133             : 
    3134     1264890 :         IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) )
    3135             :         {
    3136             :             /* decorrelate prototype frame */
    3137     1178927 :             IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3138             :             {
    3139     2883141 :                 ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
    3140      961047 :                                                   hDirACRend->num_outputs_diff,
    3141      961047 :                                                   hDirACRend->num_protos_diff,
    3142             :                                                   hDirACRend->synthesisConf,
    3143             :                                                   nchan_transport,
    3144      961047 :                                                   &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[imult1616( imult1616( imult1616( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), hDirACRend->num_outputs_diff )],
    3145      961047 :                                                   hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
    3146      961047 :                                                   hDirACRend->num_protos_diff,
    3147      961047 :                                                   hDirACRend->proto_index_diff,
    3148      961047 :                                                   &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[( ( ( slot_idx * 2 ) * hSpatParamRendCom->num_freq_bands ) * hDirACRend->num_outputs_diff ) + ( ( 2 * hSpatParamRendCom->num_freq_bands ) * s_min( 4, nchan_transport ) )],
    3149             :                                                   &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
    3150             :                                                   onset_filter_fx,
    3151             :                                                   hDirACRend->h_freq_domain_decorr_ap_params,
    3152             :                                                   hDirACRend->h_freq_domain_decorr_ap_state );
    3153             : 
    3154      961047 :                 v_multc_fx( onset_filter_fx, 536870912 /* 0.25f in Q31 */, onset_filter_fx, hSpatParamRendCom->num_freq_bands );
    3155             : 
    3156      961047 :                 v_add_fx_no_hdrm( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */
    3157      961047 :                 p_onset_filter_fx = onset_filter_subframe_fx;
    3158             :             }
    3159             :             ELSE
    3160             :             {
    3161      217880 :                 scale = L_norm_arr( hDirACRend->proto_frame_f_fx, proto_length );
    3162      217880 :                 Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); // Q(proto_frame_f_q+scale)
    3163      217880 :                 hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, scale );
    3164      217880 :                 move16();
    3165      217880 :                 ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
    3166      217880 :                                                   hDirACRend->num_outputs_diff,
    3167      217880 :                                                   hDirACRend->num_protos_diff,
    3168             :                                                   hDirACRend->synthesisConf,
    3169             :                                                   nchan_transport,
    3170      217880 :                                                   hDirACRend->proto_frame_f_fx,
    3171      217880 :                                                   hDirACRend->proto_frame_f_q,
    3172      217880 :                                                   hDirACRend->num_protos_diff,
    3173      217880 :                                                   hDirACRend->proto_index_diff,
    3174             :                                                   DirAC_mem.frame_dec_f_fx,
    3175             :                                                   &DirAC_mem.frame_dec_f_q,
    3176             :                                                   onset_filter_fx,
    3177             :                                                   hDirACRend->h_freq_domain_decorr_ap_params,
    3178             :                                                   hDirACRend->h_freq_domain_decorr_ap_state );
    3179             : 
    3180      217880 :                 hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx;
    3181      217880 :                 hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q;
    3182      217880 :                 move16();
    3183      217880 :                 hDirACRend->proto_frame_dec_f_len = DirAC_mem.frame_dec_f_len;
    3184      217880 :                 move16();
    3185      217880 :                 p_onset_filter_fx = onset_filter_fx;
    3186             :             }
    3187             :         }
    3188             :         ELSE
    3189             :         {
    3190       85963 :             IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3191             :             {
    3192           0 :                 set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands );
    3193           0 :                 p_onset_filter_fx = onset_filter_subframe_fx;
    3194             :             }
    3195             :             ELSE
    3196             :             {
    3197             :                 /* no frequency domain decorrelation: use prototype frame */
    3198       85963 :                 hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx;
    3199       85963 :                 hDirACRend->proto_frame_dec_f_len = hDirACRend->proto_frame_f_len;
    3200       85963 :                 move16();
    3201       85963 :                 hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q;
    3202       85963 :                 move16();
    3203       85963 :                 p_onset_filter_fx = NULL;
    3204             :             }
    3205             :         }
    3206             : 
    3207             :         /*-----------------------------------------------------------------*
    3208             :          * output synthesis
    3209             :          *-----------------------------------------------------------------*/
    3210             : 
    3211     1264890 :         test();
    3212     1264890 :         IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
    3213             :         {
    3214             :             DIRAC_OUTPUT_SYNTHESIS_STATE *state;
    3215             :             Word16 diffuse_start;
    3216      273864 :             state = &( hDirACRend->h_output_synthesis_psd_state );
    3217      273864 :             diffuse_start = i_mult( i_mult( slot_idx, 2 ), i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) );
    3218             : 
    3219      273864 :             exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len );
    3220      273864 :             scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); // hDirACRend->proto_frame_dec_f_q + exp
    3221      273864 :             hDirACRend->proto_frame_dec_f_q = add( hDirACRend->proto_frame_dec_f_q, exp );
    3222      273864 :             move16();
    3223      273864 :             exp = getScaleFactor32( state->proto_diffuse_buffer_f_fx, diffuse_start );
    3224      273864 :             scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); // state->proto_diffuse_buffer_f_q + exp
    3225      273864 :             state->proto_diffuse_buffer_f_q = add( state->proto_diffuse_buffer_f_q, exp );
    3226      273864 :             move16();
    3227             :             /*Compute diffuse prototypes*/
    3228      273864 :             ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx );
    3229             :         }
    3230             : 
    3231             :         /*Compute PSDs*/
    3232     1264890 :         h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
    3233     1264890 :         h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
    3234     1264890 :         num_channels_dir = hDirACRend->num_outputs_dir;
    3235     1264890 :         move16();
    3236             : 
    3237     1264890 :         if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
    3238             :         {
    3239      221699 :             num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
    3240      221699 :             move16();
    3241             :         }
    3242             : 
    3243     1264890 :         test();
    3244     1264890 :         test();
    3245     1264890 :         IF( ( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) )
    3246             :         {
    3247      165715 :             Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31
    3248      165715 :             h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
    3249      165715 :             move16();
    3250             : 
    3251      165715 :             exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    3252      165715 :             scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth + exp
    3253      165715 :             h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
    3254      165715 :             move16();
    3255             :         }
    3256             : 
    3257     1264890 :         test();
    3258     1264890 :         IF( ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) )
    3259             :         {
    3260       55984 :             scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); // Q31
    3261       55984 :             h_dirac_output_synthesis_state->direct_power_factor_q = Q31;
    3262       55984 :             move16();
    3263             : 
    3264       55984 :             scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31
    3265       55984 :             h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
    3266       55984 :             move16();
    3267             : 
    3268       55984 :             scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_q ) ); // Q31
    3269       55984 :             h_dirac_output_synthesis_state->direct_responses_q = Q31;
    3270       55984 :             move16();
    3271             : 
    3272       55984 :             scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); // Q31
    3273       55984 :             h_dirac_output_synthesis_state->direct_responses_square_q = Q31;
    3274       55984 :             move16();
    3275             : 
    3276       55984 :             exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    3277       55984 :             scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp
    3278       55984 :             h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp );
    3279       55984 :             move16();
    3280       55984 :             exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    3281       55984 :             scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth+ exp
    3282       55984 :             h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, exp );
    3283       55984 :             move16();
    3284       55984 :             exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    3285       55984 :             scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth+ exp
    3286       55984 :             h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
    3287       55984 :             move16();
    3288             :         }
    3289             : 
    3290     1264890 :         ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fx,
    3291             :                                                          DirAC_mem.reference_power_q,
    3292             :                                                          p_onset_filter_fx,
    3293             :                                                          azimuth,
    3294             :                                                          elevation,
    3295     1264890 :                                                          hSpatParamRendCom->diffuseness_vector_fx[md_idx],
    3296     1264890 :                                                          hSpatParamRendCom->q_diffuseness_vector,
    3297             :                                                          hSpatParamRendCom,
    3298             :                                                          hDirACRend,
    3299             :                                                          st_ivas->hVBAPdata,
    3300             :                                                          hDirACRend->hOutSetup,
    3301             :                                                          nchan_transport,
    3302             :                                                          md_idx,
    3303             :                                                          hodirac_flag,
    3304     1264890 :                                                          hDirAC->hConfig->dec_param_estim );
    3305             : 
    3306             : 
    3307     1264890 :         IF( hDirAC->hConfig->dec_param_estim )
    3308             :         {
    3309             :             Word16 fac;
    3310      767083 :             fac = BASOP_Util_Divide3232_Scale( 1, hSpatParamRendCom->subframe_nbslots[subframe_idx], &exp );
    3311      767083 :             fac = shl_sat( fac, exp );
    3312             : 
    3313      767083 :             IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) )
    3314             :             {
    3315           0 :                 scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); // q_diffuseness_vector
    3316           0 :                 hSpatParamRendCom->q_diffuseness_vector = q_diffuseness_vector;
    3317           0 :                 move16();
    3318             :             }
    3319             :             ELSE
    3320             :             {
    3321      767083 :                 scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); // q_diffuseness_vector
    3322      767083 :                 q_diffuseness_vector = hSpatParamRendCom->q_diffuseness_vector;
    3323      767083 :                 move16();
    3324             :             }
    3325      767083 :             v_multc_acc_32_16( hSpatParamRendCom->diffuseness_vector_fx[md_idx], fac, diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
    3326             :         }
    3327             : 
    3328     1264890 :         IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3329             :         {
    3330      303843 :             v_add_fx_me( reference_power_fx, sub( 31, DirAC_mem.reference_power_q[0] ),
    3331      303843 :                          reference_power_smooth_fx, sub( 31, q_reference_power_smooth[0] ),
    3332             :                          reference_power_smooth_fx, &temp_q,
    3333      303843 :                          s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), 1 );
    3334      303843 :             q_reference_power_smooth[0] = sub( 31, temp_q );
    3335      303843 :             v_add_fx_me( reference_power_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, DirAC_mem.reference_power_q[1] ),
    3336      303843 :                          reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, q_reference_power_smooth[1] ),
    3337             :                          reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, &temp_q,
    3338      303843 :                          s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), 1 );
    3339      303843 :             q_reference_power_smooth[1] = sub( 31, temp_q );
    3340             :         }
    3341             :     }
    3342             : 
    3343      318389 :     minimum_s( q_proto_direct_buffer, add( hSpatParamRendCom->subframe_nbslots[subframe_idx], 1 ), &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q );
    3344      318389 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3345             :     {
    3346      241313 :         minimum_s( q_proto_diffuse_buffer, add( hSpatParamRendCom->subframe_nbslots[subframe_idx], 1 ), &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q );
    3347             :     }
    3348     1583279 :     FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3349             :     {
    3350     1264890 :         IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3351             :         {
    3352      961047 :             offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    3353      961047 :             buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
    3354      961047 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); // proto_diffuse_buffer_f_q
    3355      961047 :             offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) );
    3356      961047 :             buff_len = i_mult( 2, i_mult( nchan_transport, hSpatParamRendCom->num_freq_bands ) );
    3357      961047 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
    3358             :         }
    3359      303843 :         ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
    3360             :         {
    3361       29979 :             offset = i_mult( slot_idx, i_mult( 4, hSpatParamRendCom->num_freq_bands ) );
    3362       29979 :             buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
    3363       29979 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
    3364             :         }
    3365             :         ELSE
    3366             :         {
    3367      273864 :             SWITCH( nchan_transport )
    3368             :             {
    3369       55984 :                 case 11:
    3370             :                 case 8:
    3371             :                 case 6:
    3372             :                 case 4:
    3373       55984 :                     offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    3374       55984 :                     buff_len = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    3375       55984 :                     scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
    3376       55984 :                     BREAK;
    3377      105617 :                 case 2:
    3378      105617 :                     IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
    3379             :                     {
    3380       71168 :                         offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 3 );
    3381       71168 :                         buff_len = i_mult( 6, hSpatParamRendCom->num_freq_bands );
    3382             :                     }
    3383             :                     ELSE
    3384             :                     {
    3385       34449 :                         offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 2 );
    3386       34449 :                         buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
    3387             :                     }
    3388      105617 :                     scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
    3389      105617 :                     BREAK;
    3390      112263 :                 case 1:
    3391      112263 :                     offset = i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) );
    3392      112263 :                     buff_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
    3393      112263 :                     scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
    3394      112263 :                     BREAK;
    3395             :             }
    3396     1264890 :         }
    3397             :     }
    3398      318389 :     test();
    3399      318389 :     IF( EQ_16( slot_idx, hSpatParamRendCom->subframe_nbslots[subframe_idx] ) && sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, add( offset, buff_len ) ) > 0 )
    3400             :     {
    3401        4333 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + add( offset, buff_len ), sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, add( offset, buff_len ) ), sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
    3402        4333 :         offset = i_mult( i_mult( sub( slot_idx, 1 ), 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    3403        4333 :         buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
    3404        4333 :         IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) && sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, add( offset, buff_len ) ) > 0 )
    3405             :         {
    3406        2103 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + add( offset, buff_len ), sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, add( offset, buff_len ) ), sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); // proto_direct_buffer_f_q
    3407             :         }
    3408             :     }
    3409      318389 :     ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    3410             : 
    3411      318389 :     size = i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
    3412      318389 :     IF( hodirac_flag )
    3413             :     {
    3414       53840 :         size_ho = i_mult( size, DIRAC_HO_NUMSECTORS );
    3415             :     }
    3416             :     ELSE
    3417             :     {
    3418      264549 :         size_ho = size;
    3419      264549 :         move16();
    3420             :     }
    3421             : 
    3422      318389 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3423             :     {
    3424      241313 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, Q26 ) )
    3425             :         {
    3426      222869 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); // Q26
    3427      222869 :             hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26;
    3428      222869 :             move16();
    3429             :         }
    3430      241313 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, Q26 ) )
    3431             :         {
    3432           0 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26
    3433             :         }
    3434      241313 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
    3435             :         {
    3436       96654 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31
    3437             :         }
    3438      241313 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
    3439             :         {
    3440        8647 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size_ho, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31
    3441             :         }
    3442      241313 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
    3443             :         {
    3444       95469 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31
    3445             :         }
    3446      241313 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, Q26 ) )
    3447             :         {
    3448           0 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26
    3449             :         }
    3450      241313 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, Q26 ) )
    3451             :         {
    3452           0 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26
    3453             :         }
    3454      241313 :         IF( NE_16( q_diffuseness_vector, Q30 ) )
    3455             :         {
    3456           0 :             scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); // Q30
    3457             :         }
    3458      241313 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
    3459             :         {
    3460           0 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26
    3461             :         }
    3462      241313 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
    3463             :         {
    3464         800 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26
    3465             :         }
    3466             : 
    3467      241313 :         ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx,
    3468             :                                                                       Cldfb_ImagBuffer_fx,
    3469             :                                                                       hSpatParamRendCom,
    3470             :                                                                       hDirACRend,
    3471             :                                                                       nchan_transport,
    3472      241313 :                                                                       hSpatParamRendCom->subframe_nbslots[subframe_idx],
    3473             :                                                                       p_onset_filter_fx,
    3474             :                                                                       diffuseness_vector_fx,
    3475             :                                                                       hodirac_flag,
    3476      241313 :                                                                       hDirAC->hConfig->dec_param_estim,
    3477             :                                                                       &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev,
    3478             :                                                                       &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev );
    3479             : 
    3480      241313 :         test();
    3481      241313 :         IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL )
    3482             :         {
    3483      494000 :             FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
    3484             :             {
    3485     2235000 :                 FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3486             :                 {
    3487     1788000 :                     scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6
    3488     1788000 :                     scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6
    3489             :                 }
    3490             :             }
    3491             :         }
    3492             :         ELSE
    3493             :         {
    3494     3059737 :             FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ )
    3495             :             {
    3496    14259840 :                 FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3497             :                 {
    3498    11394416 :                     scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6
    3499    11394416 :                     scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6
    3500             :                 }
    3501             :             }
    3502             :         }
    3503             :     }
    3504             :     ELSE
    3505             :     {
    3506             :         /* Determine encoding quality based additional smoothing factor */
    3507       77076 :         Word32 qualityBasedSmFactor_fx = ONE_IN_Q31;
    3508       77076 :         move32();
    3509       77076 :         Word16 q_Cldfb = 0;
    3510       77076 :         move16();
    3511             : 
    3512       77076 :         IF( st_ivas->hMasa != NULL )
    3513             :         {
    3514       63080 :             qualityBasedSmFactor_fx = L_mult( st_ivas->hMasa->data.dir_decode_quality_fx, st_ivas->hMasa->data.dir_decode_quality_fx ); /* (Q15, Q15) -> Q31 */
    3515             :         }
    3516             : 
    3517       77076 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
    3518             :         {
    3519       63080 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31
    3520             :         }
    3521       77076 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
    3522             :         {
    3523       63080 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31
    3524             :         }
    3525       77076 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
    3526             :         {
    3527       21355 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31
    3528             :         }
    3529       77076 :         IF( NE_16( q_diffuseness_vector, Q31 ) )
    3530             :         {
    3531       77076 :             Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); // Q31
    3532             :         }
    3533       77076 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, Q31 ) )
    3534             :         {
    3535       63080 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); // Q31
    3536             :         }
    3537             : 
    3538       77076 :         exp = L_norm_arr( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) );
    3539       77076 :         scale_sig32( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), exp ); // q_reference_power_smooth[0] + exp
    3540       77076 :         q_reference_power_smooth[0] = add( q_reference_power_smooth[0], exp );
    3541       77076 :         IF( LT_16( q_reference_power_smooth[0], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] ) )
    3542             :         {
    3543        2929 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( q_reference_power_smooth[0], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] ) ); // q_reference_power_smooth[0]
    3544        2929 :             hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] = q_reference_power_smooth[0];
    3545        2929 :             move16();
    3546             :         }
    3547             :         ELSE
    3548             :         {
    3549             :             Word32 temp;
    3550     2279687 :             FOR( i = 0; i < s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ); i++ )
    3551             :             {
    3552     2205540 :                 temp = L_shl( reference_power_smooth_fx[i], sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0], q_reference_power_smooth[0] ) );
    3553     2205540 :                 reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
    3554     2205540 :                 move32();
    3555             :             }
    3556       74147 :             q_reference_power_smooth[0] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0];
    3557       74147 :             move16();
    3558             :         }
    3559             : 
    3560       77076 :         exp = L_norm_arr( reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
    3561       77076 :         scale_sig32( reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), exp ); // q_reference_power_smooth + exp
    3562       77076 :         q_reference_power_smooth[1] = add( q_reference_power_smooth[1], exp );
    3563       77076 :         IF( LT_16( q_reference_power_smooth[1], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] ) )
    3564             :         {
    3565        2577 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( q_reference_power_smooth[1], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] ) ); // q_reference_power_smooth
    3566        2577 :             hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] = q_reference_power_smooth[1];
    3567        2577 :             move16();
    3568             :         }
    3569             :         ELSE
    3570             :         {
    3571             :             Word32 temp;
    3572     2066209 :             FOR( i = CLDFB_NO_CHANNELS_HALF; i < hSpatParamRendCom->num_freq_bands; i++ )
    3573             :             {
    3574     1991710 :                 temp = L_shl( reference_power_smooth_fx[i], sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1], q_reference_power_smooth[1] ) );
    3575     1991710 :                 reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
    3576     1991710 :                 move32();
    3577             :             }
    3578       74499 :             q_reference_power_smooth[1] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1];
    3579       74499 :             move16();
    3580             :         }
    3581             : 
    3582       77076 :         IF( hDirACRend->masa_stereo_type_detect != NULL )
    3583             :         {
    3584       11416 :             IF( LT_16( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) )
    3585             :             {
    3586       11415 :                 hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); // q_subtract_power_y
    3587       11415 :                 move32();
    3588       11415 :                 hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = hDirACRend->masa_stereo_type_detect->q_subtract_power_y;
    3589       11415 :                 move16();
    3590             :             }
    3591             :             ELSE
    3592             :             {
    3593           1 :                 hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); // q_subtract_power_y
    3594           1 :                 move32();
    3595           1 :                 hDirACRend->masa_stereo_type_detect->q_subtract_power_y = hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth;
    3596           1 :                 move16();
    3597             :             }
    3598             :         }
    3599             : 
    3600       77076 :         exp = 31;
    3601       77076 :         move16();
    3602      327130 :         FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3603             :         {
    3604      250054 :             exp = s_min( exp, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + i, s_min( CLDFB_NO_CHANNELS_HALF, hSpatParamRendCom->num_freq_bands ) ) );
    3605             :         }
    3606      327130 :         FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3607             :         {
    3608      250054 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + i, s_min( CLDFB_NO_CHANNELS_HALF, hSpatParamRendCom->num_freq_bands ), exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + exp)
    3609             :         }
    3610       77076 :         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], exp );
    3611       77076 :         move16();
    3612       77076 :         exp = 31;
    3613       77076 :         move16();
    3614      327130 :         FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3615             :         {
    3616      250054 :             exp = s_min( exp, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ) );
    3617             :         }
    3618      327130 :         FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3619             :         {
    3620      250054 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + i, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + exp)
    3621             :         }
    3622       77076 :         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], exp );
    3623       77076 :         move16();
    3624             : 
    3625       77076 :         IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] ) )
    3626             :         {
    3627      113246 :             FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3628             :             {
    3629       86046 :                 scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + i, s_min( CLDFB_NO_CHANNELS_HALF, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] ) ); // proto_power_smooth_q
    3630             :             }
    3631       27200 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0];
    3632       27200 :             move16();
    3633             :         }
    3634             :         ELSE
    3635             :         {
    3636      213884 :             FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3637             :             {
    3638      164008 :                 scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + i, s_min( CLDFB_NO_CHANNELS_HALF, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] ) ); // proto_power_smooth_prev_q
    3639             :             }
    3640       49876 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0];
    3641       49876 :             move16();
    3642             :         }
    3643       77076 :         IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] ) )
    3644             :         {
    3645      138915 :             FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3646             :             {
    3647      106462 :                 scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] ) ); // proto_power_smooth_q
    3648             :             }
    3649       32453 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1];
    3650       32453 :             move16();
    3651             :         }
    3652             :         ELSE
    3653             :         {
    3654      188215 :             FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3655             :             {
    3656      143592 :                 scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + i, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] ) ); // proto_power_smooth_prev_q
    3657             :             }
    3658       44623 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1];
    3659       44623 :             move16();
    3660             :         }
    3661             : 
    3662       77076 :         exp = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) );
    3663       77076 :         scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + exp)
    3664       77076 :         hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, exp );
    3665       77076 :         move16();
    3666       77076 :         IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
    3667             :         {
    3668       54852 :             IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) )
    3669             :             {
    3670       24312 :                 scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); // proto_power_diff_smooth_q
    3671       24312 :                 hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q;
    3672       24312 :                 move16();
    3673             :             }
    3674             :             ELSE
    3675             :             {
    3676       30540 :                 scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); // proto_power_diff_smooth_prev_q
    3677       30540 :                 hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q;
    3678       30540 :                 move16();
    3679             :             }
    3680             :         }
    3681             : 
    3682       77076 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
    3683             :         {
    3684           0 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26
    3685             :         }
    3686       77076 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
    3687             :         {
    3688           0 :             scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26
    3689             :         }
    3690       77076 :         IF( hDirACRend->proto_signal_decorr_on )
    3691             :         {
    3692       54852 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ) ); // proto_direct_buffer_f_q
    3693       54852 :             hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
    3694       54852 :             move16();
    3695             :         }
    3696             : 
    3697       77076 :         ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx,
    3698             :                                                                     Cldfb_ImagBuffer_fx,
    3699             :                                                                     hSpatParamRendCom,
    3700             :                                                                     hDirACRend,
    3701       77076 :                                                                     hSpatParamRendCom->subframe_nbslots[subframe_idx],
    3702             :                                                                     diffuseness_vector_fx,
    3703             :                                                                     reference_power_smooth_fx,
    3704             :                                                                     q_reference_power_smooth,
    3705             :                                                                     qualityBasedSmFactor_fx,
    3706       77076 :                                                                     hDirAC->hConfig->enc_param_start_band,
    3707             :                                                                     &q_Cldfb );
    3708             : 
    3709       77076 :         Word16 allZero = 1;
    3710       77076 :         move16();
    3711    14613776 :         FOR( i = 0; i < proto_power_smooth_len; i++ )
    3712             :         {
    3713    14536700 :             if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx[i] != 0 )
    3714             :             {
    3715           0 :                 allZero = 0;
    3716           0 :                 move16();
    3717             :             }
    3718             :         }
    3719       77076 :         if ( allZero )
    3720             :         {
    3721       77076 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = 31;
    3722       77076 :             move16();
    3723             :         }
    3724       77076 :         if ( allZero )
    3725             :         {
    3726       77076 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = 31;
    3727       77076 :             move16();
    3728             :         }
    3729             : 
    3730      603025 :         FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
    3731             :         {
    3732     2617145 :             FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3733             :             {
    3734     2091196 :                 scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
    3735     2091196 :                 scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
    3736             :             }
    3737             :         }
    3738             :     }
    3739             : 
    3740             :     /*-----------------------------------------------------------------*
    3741             :      * CLDFB synthesis (and binaural rendering)
    3742             :      *-----------------------------------------------------------------*/
    3743             : 
    3744      318389 :     index_slot = slot_idx_start_cldfb_synth;
    3745      318389 :     move16();
    3746             : 
    3747      318389 :     test();
    3748      318389 :     test();
    3749      318389 :     IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
    3750             :     {
    3751             :         /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */
    3752      125727 :         test();
    3753      125727 :         test();
    3754      125727 :         IF( ( ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
    3755             :         {
    3756             :             Word16 j, k, l;
    3757             :             Word16 num_objects, nchan_out_woLFE;
    3758             :             Word16 n_slots_to_render;
    3759             :             Word16 n_samples_to_render;
    3760             :             Word32 gain_fx, prev_gain_fx;
    3761             : 
    3762       16000 :             num_objects = st_ivas->nchan_ism;
    3763       16000 :             move16();
    3764       16000 :             nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
    3765       16000 :             move16();
    3766       16000 :             n_slots_to_render = st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->subframes_rendered];
    3767       16000 :             move16();
    3768       16000 :             n_samples_to_render = imult1616( hSpatParamRendCom->num_freq_bands, n_slots_to_render );
    3769             : 
    3770       16000 :             test();
    3771       16000 :             IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] )
    3772             :             {
    3773           0 :                 ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx );
    3774           0 :                 st_ivas->hIsmRendererData->interp_offset_fx = 0;
    3775           0 :                 move16();
    3776             :             }
    3777             : 
    3778       76000 :             FOR( i = 0; i < num_objects; i++ )
    3779             :             {
    3780             :                 /* Combined rotation: rotate the object positions depending the head and external orientations */
    3781       60000 :                 test();
    3782       60000 :                 IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
    3783             :                 {
    3784           0 :                     Word16 az_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ) );
    3785           0 :                     Word16 el_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, Q22 ) );
    3786             :                     Word32 az1_32, el1_32;
    3787             : 
    3788           0 :                     rotateAziEle_fx32( az_q0, el_q0, &az1_32, &el1_32, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup );
    3789             : 
    3790           0 :                     IF( st_ivas->hEFAPdata != NULL )
    3791             :                     {
    3792           0 :                         const Word32 azi_fx = L_shl( az1_32, Q22 - Q16 ); // Q16 -> Q22
    3793           0 :                         const Word32 ele_fx = L_shl( el1_32, Q22 - Q16 ); // Q16 -> Q22
    3794           0 :                         efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azi_fx, ele_fx, EFAP_MODE_EFAP );
    3795             :                         // TODO: Align Q-values
    3796           0 :                         IF( NE_32( st_ivas->hIsmMetaData[i]->edited_gain_fx, ONE_IN_Q29 ) )
    3797             :                         {
    3798           0 :                             v_multc_fx( st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIsmMetaData[i]->edited_gain_fx, st_ivas->hIsmRendererData->gains_fx[i], nchan_out_woLFE ); // Q30, Q29 --> Q28
    3799           0 :                             Scale_sig32( st_ivas->hIsmRendererData->gains_fx[i], nchan_out_woLFE, Q2 );                                                                              // Q28 --> Q30
    3800             :                         }
    3801             :                     }
    3802             :                 }
    3803             : 
    3804      720000 :                 FOR( j = 0; j < nchan_out_woLFE; j++ )
    3805             :                 {
    3806      660000 :                     gain_fx = st_ivas->hIsmRendererData->gains_fx[i][j];
    3807      660000 :                     move32();
    3808      660000 :                     prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j];
    3809      660000 :                     move32();
    3810      660000 :                     test();
    3811      660000 :                     IF( ( L_abs( gain_fx ) > 0 || L_abs( prev_gain_fx ) > 0 ) )
    3812             :                     {
    3813             :                         Word32 *tc_re_fx, *tc_im_fx;
    3814             :                         Word16 *w1_fx, w2_fx;
    3815             : 
    3816      300124 :                         w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[st_ivas->hIsmRendererData->interp_offset_fx];
    3817      300124 :                         tc_re_fx = pppQMfFrame_ts_re_fx[nchan_transport + i][0];
    3818      300124 :                         move32();
    3819      300124 :                         tc_im_fx = pppQMfFrame_ts_im_fx[nchan_transport + i][0];
    3820      300124 :                         move32();
    3821     1500620 :                         FOR( k = 0; k < n_slots_to_render; k++ )
    3822             :                         {
    3823             :                             Word32 g_fx;
    3824     1200496 :                             w2_fx = sub( MAX16B, *w1_fx );
    3825     1200496 :                             g_fx = Madd_32_16( Mpy_32_16_1( gain_fx, *w1_fx ), prev_gain_fx, w2_fx ); // Q15
    3826    65916016 :                             FOR( l = 0; l < hSpatParamRendCom->num_freq_bands; l++ )
    3827             :                             {
    3828    64715520 :                                 Cldfb_RealBuffer_fx[j][k][l] = Madd_32_32( Cldfb_RealBuffer_fx[j][k][l], g_fx, L_shl( *tc_re_fx, 1 ) );
    3829    64715520 :                                 move32();
    3830    64715520 :                                 tc_re_fx++;
    3831    64715520 :                                 Cldfb_ImagBuffer_fx[j][k][l] = Madd_32_32( Cldfb_ImagBuffer_fx[j][k][l], g_fx, L_shl( *tc_im_fx, 1 ) );
    3832    64715520 :                                 move32();
    3833    64715520 :                                 tc_im_fx++;
    3834             :                             }
    3835     1200496 :                             w1_fx += hSpatParamRendCom->num_freq_bands;
    3836             :                         }
    3837             :                     }
    3838             :                     /* update here only in case of head rotation */
    3839      660000 :                     test();
    3840      660000 :                     IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
    3841             :                     {
    3842           0 :                         st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx;
    3843           0 :                         move32();
    3844             :                     }
    3845             :                 }
    3846             :             }
    3847       16000 :             st_ivas->hIsmRendererData->interp_offset_fx = add( st_ivas->hIsmRendererData->interp_offset_fx, i_mult( hSpatParamRendCom->num_freq_bands, st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->subframes_rendered] ) );
    3848             :         }
    3849             : 
    3850             :         /* Perform binaural rendering, output in Q6 format */
    3851             : #ifdef FIX_1319_STACK_SBA_DECODER
    3852      125727 :         test();
    3853      125727 :         IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    3854             :         {
    3855           0 :             IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
    3856             :             {
    3857           0 :                 FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3858             :                 {
    3859           0 :                     FOR( ch = 0; ch < st_ivas->hBinRenderer->nInChannels; ch++ )
    3860             :                     {
    3861           0 :                         Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands );
    3862           0 :                         Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands );
    3863             :                     }
    3864             :                 }
    3865           0 :                 st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
    3866           0 :                 move16();
    3867             :             }
    3868             : 
    3869           0 :             binRenderer_split_fx( st_ivas->hBinRenderer, st_ivas->hSplitBinRend, st_ivas->hCombinedOrientationData, hSpatParamRendCom->subframe_nbslots[subframe_idx],
    3870           0 :                                   Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, slot_idx_start, hSpatParamRendCom->num_freq_bands, st_ivas->hDecoderConfig->nchan_out );
    3871             :         }
    3872             :         ELSE
    3873             :         {
    3874      125727 :             binRenderer_fx( st_ivas->hBinRenderer, st_ivas->hCombinedOrientationData, hSpatParamRendCom->subframe_nbslots[subframe_idx],
    3875             :                             Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx );
    3876             :         }
    3877             : #else
    3878             :         IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    3879             :         {
    3880             :             IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
    3881             :             {
    3882             :                 FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3883             :                 {
    3884             :                     FOR( ch = 0; ch < st_ivas->hBinRenderer->nInChannels; ch++ )
    3885             :                     {
    3886             :                         Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands );
    3887             :                         Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][add( slot_idx_start, slot_idx )], hSpatParamRendCom->num_freq_bands );
    3888             :                     }
    3889             :                 }
    3890             :                 st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
    3891             :                 move16();
    3892             :             }
    3893             :         }
    3894             : 
    3895             :         /*Binaural output in Q6 format*/
    3896             :         ivas_binRenderer_fx( st_ivas->hBinRenderer,
    3897             :                              ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
    3898             :                              st_ivas->hCombinedOrientationData,
    3899             :                              hSpatParamRendCom->subframe_nbslots[subframe_idx],
    3900             :                              Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
    3901             :                              Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &input_q );
    3902             : #endif
    3903             : 
    3904             :         /* Inverse CLDFB*/
    3905      377181 :         FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
    3906             :         {
    3907             :             /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
    3908      251454 :             Word32 *synth_fx = &output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands];
    3909             : #ifdef FIX_1319_STACK_SBA_DECODER
    3910             :             Word32 *RealBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
    3911             :             Word32 *ImagBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
    3912             : #else
    3913             :             Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
    3914             :             Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
    3915             : #endif
    3916     1256310 :             FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    3917             :             {
    3918     1004856 :                 RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[0][ch][i];
    3919     1004856 :                 move32();
    3920     1004856 :                 ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[0][ch][i];
    3921     1004856 :                 move32();
    3922             :             }
    3923             : 
    3924      251454 :             scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q6-1
    3925      251454 :             st_ivas->cldfbSynDec[ch]->Q_cldfb_state = ( Q6 - 1 );
    3926      251454 :             move16();
    3927             : 
    3928      251454 :             cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, synth_fx, i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), 0, 0, st_ivas->cldfbSynDec[ch] );
    3929             : 
    3930      251454 :             Word16 no_col = st_ivas->cldfbSynDec[ch]->no_col;
    3931      251454 :             move16();
    3932      251454 :             Word16 no_channels = st_ivas->cldfbSynDec[ch]->no_channels;
    3933      251454 :             move16();
    3934      251454 :             Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    3935      251454 :             move16();
    3936      251454 :             IF( GT_16( samplesToProcess, -1 ) )
    3937             :             {
    3938             :                 Word16 tmp, tmp_e;
    3939      251454 :                 tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ), st_ivas->cldfbSynDec[ch]->no_channels, &tmp_e );
    3940      251454 :                 tmp = shr( tmp, 15 - tmp_e );
    3941      251454 :                 no_col = s_min( no_col, tmp );
    3942             :             }
    3943      251454 :             Word16 synth_len = imult1616( no_col, no_channels );
    3944             : 
    3945      251454 :             scale_sig32( synth_fx, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
    3946             :         }
    3947             :     }
    3948      192662 :     ELSE IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
    3949             :     {
    3950     1593959 :         FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
    3951             :         {
    3952     7305520 :             FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3953             :             {
    3954     5832496 :                 Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], pppQMfFrame_ts_re_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
    3955     5832496 :                 Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], pppQMfFrame_ts_im_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
    3956             :             }
    3957             :         }
    3958             :     }
    3959             :     ELSE
    3960             :     {
    3961             : #ifdef FIX_1319_STACK_SBA_DECODER
    3962             :         Word32 *RealBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
    3963             :         Word32 *ImagBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
    3964             : #else
    3965             :         Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
    3966             :         Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
    3967             : #endif
    3968             :         Word16 outchannels;
    3969             : 
    3970       71727 :         idx_in = 0;
    3971       71727 :         move16();
    3972       71727 :         idx_lfe = 0;
    3973       71727 :         move16();
    3974             : 
    3975       71727 :         outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
    3976             : 
    3977       71727 :         test();
    3978       71727 :         test();
    3979       71727 :         test();
    3980       71727 :         test();
    3981       71727 :         test();
    3982       71727 :         test();
    3983       71727 :         test();
    3984       71727 :         IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
    3985             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
    3986             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
    3987             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
    3988             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
    3989             :                                                               ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
    3990             :         {
    3991         876 :             outchannels = add( outchannels, 1 );
    3992             :         }
    3993             : 
    3994       71727 :         test();
    3995       71727 :         IF( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
    3996           0 :         {
    3997             :             Word32 tmp_separated_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    3998             :             Word32 tmp_lfe_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    3999           0 :             const Word16 subframe_start_sample = imult1616( index_slot, hSpatParamRendCom->num_freq_bands );
    4000           0 :             const Word16 num_samples_subframe = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    4001             : 
    4002             :             /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */
    4003           0 :             Copy32( &( output_buf_fx[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated_fx, num_samples_subframe );
    4004           0 :             if ( hDirACRend->hOutSetup.num_lfe > 0 )
    4005             :             {
    4006           0 :                 Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe );
    4007             :             }
    4008             : 
    4009           0 :             FOR( ch = 0; ch < outchannels; ch++ )
    4010             :             {
    4011             : 
    4012           0 :                 test();
    4013           0 :                 test();
    4014           0 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    4015             :                 {
    4016             :                     /* Move the LFE channel to the correct place */
    4017           0 :                     Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
    4018             : 
    4019           0 :                     IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    4020             :                     {
    4021           0 :                         idx_lfe = add( idx_lfe, 1 );
    4022             :                     }
    4023             :                 }
    4024           0 :                 ELSE IF( ( st_ivas->hLsSetupCustom->separate_ch_found ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
    4025             :                 {
    4026             :                     /*  Move the separated channel to the correct place. Thus, the separated channel is
    4027             :                      *  combined with the synthesized channels here when there is a matching channel. */
    4028           0 :                     Copy32( tmp_separated_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
    4029             :                 }
    4030             :                 ELSE
    4031             :                 {
    4032             :                     /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
    4033           0 :                     FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    4034             :                     {
    4035           0 :                         RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i];
    4036           0 :                         move32();
    4037           0 :                         ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i];
    4038           0 :                         move32();
    4039             :                     }
    4040           0 :                     cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe, 0, 0, st_ivas->cldfbSynDec[idx_in] );
    4041             : 
    4042           0 :                     IF( !st_ivas->hLsSetupCustom->separate_ch_found )
    4043             :                     {
    4044             :                         /* Pan the separated channel and mix with the synthesized channels. Thus, the separated channel
    4045             :                          * is combined with the synthesized channels here when there is no matching channel. */
    4046           0 :                         v_multc_acc_32_16( tmp_separated_fx, st_ivas->hLsSetupCustom->separate_ch_gains_fx[idx_in], &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
    4047             :                     }
    4048             : 
    4049           0 :                     idx_in = add( idx_in, 1 );
    4050             :                 }
    4051             :             }
    4052             :         }
    4053             :         ELSE
    4054             :         {
    4055      548045 :             FOR( ch = 0; ch < outchannels; ch++ )
    4056             :             {
    4057      476318 :                 test();
    4058      476318 :                 test();
    4059      476318 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    4060             :                 {
    4061       41725 :                     test();
    4062       41725 :                     test();
    4063       41725 :                     IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
    4064        6640 :                     {
    4065       33200 :                         FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    4066             :                         {
    4067       26560 :                             RealBuffer_fx[i] = Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i];
    4068       26560 :                             move32();
    4069       26560 :                             ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i];
    4070       26560 :                             move32();
    4071             :                         }
    4072        6640 :                         Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
    4073        6640 :                         Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    4074        6640 :                         Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] );
    4075             : 
    4076        6640 :                         scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); // Q6-1
    4077        6640 :                         st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = ( Q6 - 1 );
    4078        6640 :                         move16();
    4079        6640 :                         cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[cldfbSynIdx] );
    4080             : 
    4081             :                         // Calculating length of output
    4082        6640 :                         Word16 no_col = st_ivas->cldfbSynDec[cldfbSynIdx]->no_col;
    4083        6640 :                         move16();
    4084        6640 :                         Word16 no_channels = st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels;
    4085        6640 :                         move16();
    4086        6640 :                         IF( GT_16( samplesToProcess, -1 ) )
    4087             :                         {
    4088             :                             Word16 tmp, tmp_e;
    4089        6640 :                             tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ), st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, &tmp_e );
    4090        6640 :                             tmp = shr( tmp, 15 - tmp_e );
    4091        6640 :                             no_col = s_min( no_col, tmp );
    4092             :                         }
    4093        6640 :                         Word16 synth_len = imult1616( no_col, no_channels );
    4094             : 
    4095        6640 :                         scale_sig32( p_out, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
    4096             :                     }
    4097       35085 :                     ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && hDirACRend->hOutSetup.separateChannelEnabled )
    4098             :                     {
    4099             :                         /* LFE has been synthesized in the time domain, do nothing. */
    4100             :                     }
    4101             :                     ELSE
    4102             :                     {
    4103       34209 :                         set32_fx( &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) );
    4104             :                     }
    4105       41725 :                     IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    4106             :                     {
    4107           0 :                         idx_lfe = add( idx_lfe, 1 );
    4108             :                     }
    4109             :                 }
    4110      434593 :                 ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
    4111             :                 {
    4112             :                     /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated
    4113             :                      * channel is combined with the synthesized channels here. */
    4114             :                 }
    4115             :                 ELSE
    4116             :                 {
    4117             :                     /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
    4118      433717 :                     Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] );
    4119             :                     Word16 samplesToProcess, out_len;
    4120     2155985 :                     FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    4121             :                     {
    4122     1722268 :                         RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; // Q6
    4123     1722268 :                         move32();
    4124     1722268 :                         ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; // Q6
    4125     1722268 :                         move32();
    4126             :                     }
    4127      433717 :                     samplesToProcess = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    4128             : 
    4129             :                     // Calculating length of processed output
    4130      433717 :                     Word16 no_col = st_ivas->cldfbSynDec[idx_in]->no_col;
    4131      433717 :                     move16();
    4132      433717 :                     Word16 no_channels = st_ivas->cldfbSynDec[idx_in]->no_channels;
    4133      433717 :                     move16();
    4134      433717 :                     IF( GT_16( samplesToProcess, -1 ) )
    4135             :                     {
    4136             :                         Word16 tmp, tmp_e;
    4137      433717 :                         tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[idx_in]->no_channels, 1 ) ), st_ivas->cldfbSynDec[idx_in]->no_channels, &tmp_e );
    4138      433717 :                         tmp = shr( tmp, 15 - tmp_e );
    4139      433717 :                         no_col = s_min( no_col, tmp );
    4140             :                     }
    4141      433717 :                     out_len = imult1616( no_col, no_channels );
    4142             : 
    4143             :                     // Scaling cldfb_state to Q6-1
    4144      433717 :                     scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) );
    4145      433717 :                     st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = ( Q6 - 1 );
    4146      433717 :                     move16();
    4147      433717 :                     cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[idx_in] );
    4148             : 
    4149             :                     // Scaling output from Q6-1 to Q11
    4150      433717 :                     Scale_sig32( p_out, out_len, ( Q11 - ( Q6 - 1 ) ) );
    4151             : 
    4152      433717 :                     idx_in = add( idx_in, 1 );
    4153             :                 }
    4154             :             }
    4155             :         }
    4156             :     }
    4157             : 
    4158      318389 :     hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    4159      318389 :     move16();
    4160      318389 :     hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 );
    4161      318389 :     move16();
    4162             : 
    4163      318389 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    4164             :     {
    4165      241313 :         hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev;
    4166      241313 :         move16();
    4167      241313 :         hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev;
    4168      241313 :         move16();
    4169             :     }
    4170             : 
    4171      318389 :     test();
    4172      318389 :     test();
    4173      318389 :     IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    4174             :     {
    4175      377181 :         FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ )
    4176             :         {
    4177      251454 :             scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); // Q11
    4178      251454 :             st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11;
    4179      251454 :             move16();
    4180             :         }
    4181             :     }
    4182      192662 :     ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    4183             :     {
    4184             :     }
    4185             :     ELSE
    4186             :     {
    4187             :         Word16 outchannels;
    4188       71727 :         idx_lfe = 0;
    4189       71727 :         move16();
    4190       71727 :         idx_in = 0;
    4191       71727 :         move16();
    4192       71727 :         outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
    4193             : 
    4194       71727 :         test();
    4195       71727 :         test();
    4196       71727 :         test();
    4197       71727 :         test();
    4198       71727 :         test();
    4199       71727 :         test();
    4200       71727 :         test();
    4201       71727 :         IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
    4202             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
    4203             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
    4204             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
    4205             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
    4206             :                                                               ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
    4207             :         {
    4208         876 :             outchannels = add( outchannels, 1 );
    4209             :         }
    4210             : 
    4211       71727 :         test();
    4212       71727 :         IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
    4213             :         {
    4214           0 :             FOR( ch = 0; ch < outchannels; ch++ )
    4215             :             {
    4216           0 :                 test();
    4217           0 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    4218             :                 {
    4219           0 :                     IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    4220             :                     {
    4221           0 :                         idx_lfe = add( idx_lfe, 1 );
    4222             :                     }
    4223             :                 }
    4224             :             }
    4225             :         }
    4226             :         ELSE
    4227             :         {
    4228      548045 :             FOR( ch = 0; ch < outchannels; ch++ )
    4229             :             {
    4230             : 
    4231      476318 :                 test();
    4232      476318 :                 test();
    4233      476318 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    4234             :                 {
    4235       41725 :                     test();
    4236       41725 :                     IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
    4237             :                     {
    4238        6640 :                         Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
    4239        6640 :                         scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); // Q11
    4240        6640 :                         st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
    4241        6640 :                         move16();
    4242             :                     }
    4243             :                 }
    4244      434593 :                 ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
    4245             :                 {
    4246      433717 :                     scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); // Q11
    4247      433717 :                     st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
    4248      433717 :                     move16();
    4249      433717 :                     idx_in = add( idx_in, 1 );
    4250             :                 }
    4251             :             }
    4252             :         }
    4253       71727 :         test();
    4254       71727 :         IF( !hDirACRend->hOutSetup.separateChannelEnabled || NE_32( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
    4255             :         {
    4256       71727 :             Word16 tmp_lfe_idx = 0;
    4257       71727 :             move16();
    4258      548045 :             FOR( ch = 0; ch < outchannels; ch++ )
    4259             :             {
    4260      476318 :                 test();
    4261      476318 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[tmp_lfe_idx], ch ) ) )
    4262             :                 {
    4263       41725 :                     IF( LT_16( tmp_lfe_idx, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    4264             :                     {
    4265           0 :                         tmp_lfe_idx = add( tmp_lfe_idx, 1 );
    4266             :                     }
    4267             :                 }
    4268             :             }
    4269             :         }
    4270             :     }
    4271             : 
    4272      318389 :     pop_wmops();
    4273             : 
    4274      318389 :     return;
    4275             : }

Generated by: LCOV version 1.14