LCOV - code coverage report
Current view: top level - lib_dec - ivas_dirac_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ b9bfbe380d1c207f5198ba67a82398b3d313550e Lines: 1929 2119 91.0 %
Date: 2025-11-16 02:22: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       12654 : 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       12654 :     IF( EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
      62             :     {
      63           0 :         flag_config = DIRAC_RECONFIGURE;
      64           0 :         move32();
      65             :     }
      66             :     ELSE
      67             :     {
      68       12654 :         flag_config = flag_config_inp;
      69       12654 :         move32();
      70             :     }
      71       12654 :     error = IVAS_ERR_OK;
      72       12654 :     move32();
      73             : 
      74       12654 :     hDirAC = NULL;
      75             : 
      76       12654 :     IF( EQ_32( flag_config, DIRAC_RECONFIGURE ) )
      77             :     {
      78       12025 :         hDirAC = st_ivas->hDirAC;
      79             :     }
      80         629 :     ELSE IF( EQ_32( flag_config, DIRAC_OPEN ) )
      81             :     {
      82             :         /*-----------------------------------------------------------------*
      83             :          * prepare library opening
      84             :          *-----------------------------------------------------------------*/
      85             : 
      86         629 :         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         629 :         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         629 :         st_ivas->hDirAC = hDirAC;
      97             :     }
      98             : 
      99             :     /*-----------------------------------------------------------------*
     100             :      * DirAC main configuration
     101             :      *-----------------------------------------------------------------*/
     102             : 
     103       12654 :     IF( NE_32( ( error = ivas_dirac_config_fx( (void *) st_ivas, DEC ) ), IVAS_ERR_OK ) )
     104             :     {
     105           0 :         return error;
     106             :     }
     107             : 
     108       12654 :     IF( EQ_32( flag_config, DIRAC_OPEN ) )
     109             :     {
     110         629 :         test();
     111         629 :         IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     112             :         {
     113         140 :             hDirAC->spar_to_dirac_write_idx = DELAY_DIRAC_PARAM_DEC_SFR;
     114         140 :             move16();
     115             :         }
     116             :         ELSE
     117             :         {
     118         489 :             hDirAC->spar_to_dirac_write_idx = 0;
     119         489 :             move16();
     120             :         }
     121         629 :         hDirAC->dithering_seed = DIRAC_DITH_SEED;
     122         629 :         move16();
     123         629 :         st_ivas->hDirAC = hDirAC;
     124             :     }
     125             : 
     126       12654 :     return error;
     127             : }
     128             : 
     129        3970 : 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       67490 :     FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
     155             :     {
     156       63520 :         ls_azimuth_fx[i] = 0;
     157       63520 :         move32();
     158       63520 :         ls_elevation_fx[i] = 0;
     159       63520 :         move32();
     160             :     }
     161             : 
     162        3970 :     IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
     163             :     {
     164         736 :         flag_config = DIRAC_RECONFIGURE;
     165         736 :         move32();
     166             :     }
     167             :     ELSE
     168             :     {
     169        3234 :         flag_config = flag_config_inp;
     170        3234 :         move32();
     171             :     }
     172        3970 :     error = IVAS_ERR_OK;
     173        3970 :     move32();
     174             : 
     175        3970 :     hDirACRend = NULL;
     176        3970 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     177        3970 :     move32();
     178        3970 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     179        3970 :     move32();
     180        3970 :     hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
     181             : 
     182        3970 :     hDirAC = st_ivas->hDirAC;
     183        3970 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
     184             : 
     185        3970 :     IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) )
     186             :     {
     187        3446 :         hDirACRend = st_ivas->hDirACRend;
     188             :     }
     189         524 :     ELSE IF( EQ_16( flag_config, DIRAC_OPEN ) )
     190             :     {
     191             :         /*-----------------------------------------------------------------*
     192             :          * prepare library opening
     193             :          *-----------------------------------------------------------------*/
     194             : 
     195         524 :         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         524 :         nchan_transport_old = 0;
     201         524 :         move16();
     202             :     }
     203             : 
     204        3970 :     nchan_transport_old = 0;
     205        3970 :     move16();
     206        3970 :     num_outputs_dir_old = 0;
     207        3970 :     move16();
     208        3970 :     num_outputs_diff_old = 0;
     209        3970 :     move16();
     210        3970 :     num_protos_diff_old = 0;
     211        3970 :     move16();
     212             : 
     213        3970 :     nchan_transport_orig = st_ivas->nchan_transport;
     214        3970 :     move16();
     215        3970 :     test();
     216        3970 :     IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     217             :     {
     218         997 :         st_ivas->nchan_transport = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
     219         997 :         move16();
     220             :     }
     221             : 
     222        3970 :     nchan_transport = st_ivas->nchan_transport;
     223        3970 :     move16();
     224        3970 :     test();
     225        3970 :     test();
     226        3970 :     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         685 :         nchan_transport = 1;
     229         685 :         move16();
     230             :     }
     231        3970 :     test();
     232        3970 :     test();
     233        3970 :     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         736 :         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        3970 :     hDirACRend->hOutSetup = st_ivas->hIntSetup;
     244        3970 :     nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE;
     245        3970 :     move16();
     246             : 
     247        3970 :     test();
     248        3970 :     IF( hDirACRend->hOutSetup.ls_azimuth_fx != NULL && hDirACRend->hOutSetup.ls_elevation_fx != NULL )
     249             :     {
     250        1530 :         Copy32( hDirACRend->hOutSetup.ls_azimuth_fx, ls_azimuth_fx, nchan_out_woLFE );
     251        1530 :         Copy32( hDirACRend->hOutSetup.ls_elevation_fx, ls_elevation_fx, nchan_out_woLFE );
     252             :     }
     253             : 
     254        3970 :     IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, -1 ) )
     255             :     {
     256        1767 :         hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */
     257        1767 :         move16();
     258        1767 :         test();
     259        1767 :         if ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) )
     260             :         {
     261         237 :             hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER;
     262         237 :             move16();
     263             :         }
     264             :     }
     265        2203 :     ELSE IF( GE_16( hDirACRend->hOutSetup.ambisonics_order, SBA_FOA_ORDER ) )
     266             :     {
     267        2203 :         Copy32( ls_azimuth_4d4_fx, ls_azimuth_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
     268        2203 :         Copy32( ls_elevation_4d4_fx, ls_elevation_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
     269             :     }
     270             : 
     271        3970 :     test();
     272        3970 :     test();
     273        3970 :     test();
     274        3970 :     test();
     275        3970 :     test();
     276        3970 :     test();
     277        3970 :     test();
     278        3970 :     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        3970 :     st_ivas->nchan_transport = nchan_transport_orig;
     294        3970 :     move16();
     295             : 
     296        3970 :     test();
     297        3970 :     test();
     298        3970 :     test();
     299        3970 :     test();
     300        3970 :     test();
     301        3970 :     test();
     302        3970 :     test();
     303        3970 :     test();
     304        3970 :     test();
     305        3970 :     test();
     306        3970 :     test();
     307        3970 :     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        3924 :     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         237 :         hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO;
     317         237 :         move32();
     318         237 :         hDirACRend->panningConf = DIRAC_PANNING_HOA3;
     319         237 :         move32();
     320         237 :         nchan_out_woLFE = 1;
     321         237 :         move16();
     322             :     }
     323        3687 :     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        1426 :         hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
     326        1426 :         move32();
     327        1426 :         hDirACRend->panningConf = DIRAC_PANNING_VBAP;
     328        1426 :         move32();
     329             :     }
     330        2261 :     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        1307 :         hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD;
     333        1307 :         move32();
     334        1307 :         hDirACRend->panningConf = DIRAC_PANNING_HOA3;
     335        1307 :         move32();
     336             :     }
     337             :     ELSE
     338             :     {
     339         954 :         hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD;
     340         954 :         move32();
     341         954 :         hDirACRend->panningConf = DIRAC_PANNING_HOA3;
     342         954 :         move32();
     343             :     }
     344             : 
     345        3970 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     346             :     {
     347         524 :         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         524 :         set16_fx( hDirACRend->frequency_axis_fx, 0, hSpatParamRendCom->num_freq_bands );
     352         524 :         ivas_dirac_dec_get_frequency_axis_fx( hDirACRend->frequency_axis_fx, output_Fs, hSpatParamRendCom->num_freq_bands );
     353             :     }
     354             : 
     355        3970 :     test();
     356        3970 :     test();
     357        3970 :     test();
     358        3970 :     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         318 :         test();
     361         318 :         test();
     362         318 :         IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect == NULL ) || EQ_16( flag_config, DIRAC_OPEN ) )
     363             :         {
     364         200 :             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         318 :         ivas_masa_init_stereotype_detection_fx( hDirACRend->masa_stereo_type_detect );
     370             :     }
     371             :     ELSE
     372             :     {
     373        3652 :         test();
     374        3652 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect != NULL )
     375             :         {
     376          76 :             free( hDirACRend->masa_stereo_type_detect );
     377             :         }
     378        3652 :         hDirACRend->masa_stereo_type_detect = NULL;
     379             :     }
     380             : 
     381        3970 :     hSpatParamRendCom->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */
     382        3970 :     move16();
     383             : 
     384             :     /*-----------------------------------------------------------------*
     385             :      * (re)configure sub-modules
     386             :      *-----------------------------------------------------------------*/
     387             : 
     388             :     /* prototype signal computation */
     389        3970 :     IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) )
     390             :     {
     391        3446 :         num_outputs_dir_old = hDirACRend->num_outputs_dir;
     392        3446 :         move16();
     393        3446 :         num_outputs_diff_old = hDirACRend->num_outputs_diff;
     394        3446 :         move16();
     395        3446 :         num_protos_diff_old = hDirACRend->num_protos_diff;
     396        3446 :         move16();
     397             :     }
     398             : 
     399             :     /* allocate output setup related arrays */
     400        3970 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
     401             :     {
     402             :         /* Directional and diffuses components in output LS format */
     403        1472 :         hDirACRend->num_outputs_diff = nchan_out_woLFE;
     404        1472 :         move16();
     405        1472 :         hDirACRend->num_outputs_dir = nchan_out_woLFE;
     406        1472 :         move16();
     407             :     }
     408        2498 :     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         954 :         hDirACRend->num_outputs_diff = mult0( ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) );
     413         954 :         move16();
     414         954 :         hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 );
     415         954 :         move16();
     416             :     }
     417        1544 :     ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
     418             :     {
     419        1307 :         hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS;
     420        1307 :         move16();
     421        1307 :         hDirACRend->num_outputs_dir = nchan_out_woLFE;
     422        1307 :         move16();
     423             :     }
     424         237 :     ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
     425             :     {
     426         237 :         hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */
     427         237 :         move16();
     428         237 :         hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */
     429         237 :         move16();
     430             :     }
     431             :     ELSE
     432             :     {
     433           0 :         assert( 0 && "DirAC: not existing synthesis methods!" );
     434             :     }
     435             : 
     436        3970 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     437             :     {
     438         524 :         num_outputs_dir_old = hDirACRend->num_outputs_dir;
     439         524 :         move16();
     440         524 :         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         524 :         num_outputs_diff_old = hDirACRend->num_outputs_diff;
     445         524 :         move16();
     446         524 :         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        3970 :     test();
     453        3970 :     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        3970 :     set16_fx( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir );
     462             : 
     463        3970 :     test();
     464        3970 :     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        3970 :     set16_fx( hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff );
     473             : 
     474        3970 :     hDirACRend->sba_map_tc = sba_map_tc;
     475             : 
     476        3970 :     test();
     477        3970 :     IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
     478             :     {
     479         997 :         test();
     480         997 :         if ( GT_16( st_ivas->sba_order, SBA_FOA_ORDER ) && GE_32( ivas_total_brate, IVAS_512k ) )
     481             :         {
     482          73 :             hDirACRend->sba_map_tc = sba_map_tc_512;
     483             :         }
     484             :     }
     485             : 
     486        3970 :     IF( EQ_16( nchan_transport, 1 ) )
     487             :     {
     488         892 :         hDirACRend->num_protos_ambi = 1;
     489         892 :         move16();
     490         892 :         hDirACRend->num_protos_dir = 1;
     491         892 :         move16();
     492         892 :         hDirACRend->num_protos_diff = 1;
     493         892 :         move16();
     494             :     }
     495        3078 :     ELSE IF( EQ_16( nchan_transport, 2 ) )
     496             :     {
     497        2081 :         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        2081 :         ELSE IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) )
     509             :         {
     510             :             /* Following the foa rendering for code compatibility */
     511         237 :             hDirACRend->num_protos_ambi = 2;
     512         237 :             move16();
     513         237 :             hDirACRend->num_protos_dir = 2;
     514         237 :             move16();
     515         237 :             hDirACRend->num_protos_diff = 3;
     516         237 :             move16();
     517         237 :             hDirACRend->proto_index_dir[0] = 0;
     518         237 :             move16();
     519         237 :             hDirACRend->proto_index_diff[0] = 0;
     520         237 :             move16();
     521             :         }
     522             :         ELSE
     523             :         {
     524        1844 :             hDirACRend->num_protos_ambi = 2;
     525        1844 :             move16();
     526        1844 :             hDirACRend->num_protos_diff = 3;
     527        1844 :             move16();
     528             : 
     529       16175 :             FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ )
     530             :             {
     531       14331 :                 IF( ls_azimuth_fx[k] > 0 )
     532             :                 {
     533        6743 :                     hDirACRend->proto_index_diff[k] = 1;
     534        6743 :                     move16();
     535             :                 }
     536        7588 :                 ELSE IF( ls_azimuth_fx[k] < 0 )
     537             :                 {
     538        6743 :                     hDirACRend->proto_index_diff[k] = 2;
     539        6743 :                     move16();
     540             :                 }
     541             :                 ELSE
     542             :                 {
     543         845 :                     hDirACRend->proto_index_diff[k] = 0;
     544         845 :                     move16();
     545             :                 }
     546             :             }
     547             : 
     548        1844 :             IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
     549             :             {
     550         870 :                 hDirACRend->num_protos_dir = 3;
     551         870 :                 move16();
     552         870 :                 Copy( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE );
     553             :             }
     554             :             ELSE
     555             :             {
     556         974 :                 hDirACRend->num_protos_dir = 2;
     557         974 :                 move16();
     558         974 :                 hDirACRend->proto_index_dir[1] = 1;
     559         974 :                 move16();
     560             :             }
     561             :         }
     562             :     }
     563             :     ELSE /* nchan_transport > 2 */
     564             :     {
     565         997 :         hDirACRend->num_protos_ambi = 4;
     566         997 :         move16();
     567         997 :         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         951 :             hDirACRend->num_protos_diff = 1;
     588         951 :             move16();
     589         951 :             hDirACRend->num_protos_dir = nchan_transport;
     590         951 :             move16();
     591             : 
     592        5602 :             FOR( k = 0; k < s_min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ )
     593             :             {
     594        4651 :                 if ( LT_16( hDirACRend->sba_map_tc[k], hDirACRend->num_outputs_dir ) )
     595             :                 {
     596        4651 :                     hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k;
     597        4651 :                     move16();
     598             :                 }
     599             :             }
     600             :         }
     601             :     }
     602             : 
     603        3970 :     test();
     604             :     /* direct/diffuse responses */
     605        3970 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     606             :     {
     607         524 :         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        3446 :     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        3970 :     test();
     624        3970 :     test();
     625        3970 :     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        3016 :         initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, nchan_out_woLFE, hDirACRend->hOutSetup.output_config,
     628        3016 :                                  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         954 :         initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, hDirACRend->num_outputs_dir, IVAS_AUDIO_CONFIG_FOA,
     633         954 :                                  hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, IVAS_AUDIO_CONFIG_INVALID );
     634             :     }
     635             : 
     636        3970 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
     637             :     {
     638        1307 :         test();
     639        1307 :         test();
     640        1307 :         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        1297 :         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        1307 :         set32_fx( hDirACRend->hoa_encoder_fx, 0, nchan_out_woLFE * hDirACRend->num_outputs_diff );
     657        1307 :         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        2663 :         test();
     662        2663 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder_fx )
     663             :         {
     664           0 :             free( hDirACRend->hoa_encoder_fx );
     665             :         }
     666        2663 :         hDirACRend->hoa_encoder_fx = NULL;
     667             :     }
     668             : 
     669             :     /* VBAP */
     670        3970 :     if ( EQ_16( flag_config, DIRAC_OPEN ) )
     671             :     {
     672         524 :         st_ivas->hVBAPdata = NULL;
     673             :     }
     674             : 
     675        3970 :     test();
     676        3970 :     IF( EQ_32( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) )
     677             :     {
     678        1472 :         test();
     679        1472 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL )
     680             :         {
     681        1314 :             vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
     682             :         }
     683        1472 :         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        2498 :     ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
     689             :     {
     690         237 :         test();
     691         237 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL )
     692             :         {
     693           0 :             vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
     694             :         }
     695         237 :         hDirACRend->hoa_decoder = NULL;
     696             :     }
     697        2261 :     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        3970 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     704             :     {
     705         524 :         hDirACRend->hoa_decoder = NULL;
     706         524 :         test();
     707         524 :         test();
     708         524 :         IF( ( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || ( GT_16( nchan_transport, 2 ) ) )
     709             :         {
     710         393 :             IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
     711             :             {
     712         135 :                 IF( st_ivas->hoa_dec_mtx != NULL )
     713             :                 {
     714         114 :                     free( st_ivas->hoa_dec_mtx );
     715         114 :                     st_ivas->hoa_dec_mtx = NULL;
     716             :                 }
     717         135 :                 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         135 :                 hDirACRend->hoa_decoder = st_ivas->hoa_dec_mtx;
     723             :             }
     724             :         }
     725             :     }
     726             : 
     727             :     /* decorrelation */
     728        3970 :     IF( flag_config == DIRAC_RECONFIGURE )
     729             :     {
     730        3446 :         proto_signal_decorr_on_old = hDirACRend->proto_signal_decorr_on;
     731        3446 :         move16();
     732             :     }
     733             :     ELSE
     734             :     {
     735         524 :         proto_signal_decorr_on_old = 0;
     736         524 :         move16();
     737             :     }
     738        3970 :     hDirACRend->proto_signal_decorr_on = 1;
     739        3970 :     move16();
     740        3970 :     test();
     741        3970 :     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        3970 :     if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
     748             :     {
     749         237 :         hDirACRend->proto_signal_decorr_on = 0;
     750         237 :         move16();
     751             :     }
     752             : 
     753        3970 :     test();
     754        3970 :     test();
     755        3970 :     test();
     756        3970 :     test();
     757        3970 :     test();
     758        3970 :     test();
     759        3970 :     test();
     760        3970 :     test();
     761        3970 :     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         426 :     {
     763             :         Word16 nchan_transport_tmp;
     764         426 :         IF( GT_16( nchan_transport, 2 ) )
     765             :         {
     766         282 :             nchan_transport_tmp = 4;
     767         282 :             move16();
     768             :         }
     769             :         ELSE
     770             :         {
     771         144 :             nchan_transport_tmp = nchan_transport;
     772         144 :             move16();
     773             :         }
     774         426 :         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        3544 :     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        3520 :     ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old )
     786             :     {
     787        3261 :         test();
     788        3261 :         test();
     789        3261 :         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        3261 :             IF( GT_16( nchan_transport, 2 ) )
     793             :             {
     794         669 :                 nchan_transport_tmp = 4;
     795         669 :                 move16();
     796             :             }
     797             :             ELSE
     798             :             {
     799        2592 :                 nchan_transport_tmp = nchan_transport;
     800        2592 :                 move16();
     801             :             }
     802             : 
     803             :             /* close and reopen the decorrelator */
     804        3261 :             ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
     805             : 
     806        3261 :             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        3970 :     test();
     817        3970 :     test();
     818        3970 :     IF( EQ_16( flag_config, DIRAC_OPEN ) )
     819             :     {
     820         524 :         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         524 :         hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on;
     825         524 :         move16();
     826             :     }
     827        3446 :     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        3423 :         ivas_dirac_dec_output_synthesis_close_fx( hDirACRend );
     830             : 
     831        3423 :         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        3423 :         hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on;
     836        3423 :         move16();
     837             :     }
     838             : 
     839        3970 :     test();
     840        3970 :     if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
     841             :     {
     842        2261 :         hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0;
     843        2261 :         move16();
     844             :     }
     845             : 
     846             :     /*-----------------------------------------------------------------*
     847             :      * memory allocation
     848             :      *-----------------------------------------------------------------*/
     849             : 
     850        3970 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
     851             :     {
     852         954 :         test();
     853         954 :         IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx )
     854             :         {
     855          24 :             free( hDirACRend->proto_frame_f_fx );
     856             :         }
     857         954 :         hDirACRend->proto_frame_f_fx = NULL;
     858             :     }
     859             :     ELSE
     860             :     {
     861        3016 :         test();
     862        3016 :         test();
     863        3016 :         test();
     864        3016 :         IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) )
     865             :         {
     866         287 :             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        2729 :         ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) )
     872             :         {
     873         725 :             proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx;
     874         725 :             free( proto_frame_f_old_fx );
     875         725 :             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        3016 :         hDirACRend->proto_frame_f_len = imult1616( 2, imult1616( hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands ) );
     881        3016 :         move16();
     882             :     }
     883             : 
     884        3970 :     if ( EQ_16( flag_config, DIRAC_OPEN ) )
     885             :     {
     886         524 :         hDirACRend->buffer_energy_fx = NULL;
     887             :     }
     888             : 
     889        3970 :     test();
     890        3970 :     test();
     891        3970 :     test();
     892        3970 :     test();
     893        3970 :     test();
     894        3970 :     test();
     895        3970 :     test();
     896        3970 :     test();
     897        3970 :     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         266 :         hDirACRend->index_buffer_intensity = 0;
     900         266 :         move16();
     901        1064 :         FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
     902             :         {
     903       26334 :             FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
     904             :             {
     905       25536 :                 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       25536 :                 set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
     910             :             }
     911             :         }
     912         266 :         set16_fx( hDirACRend->q_buffer_intensity_real, Q31, DIRAC_NO_COL_AVG_DIFF );
     913         266 :         IF( hDirACRend->buffer_energy_fx == NULL )
     914             :         {
     915         266 :             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         266 :         set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX );
     921         266 :         set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF );
     922             :     }
     923        3704 :     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        1540 :         FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
     926             :         {
     927       38115 :             FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
     928             :             {
     929       36960 :                 test();
     930       36960 :                 IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] )
     931             :                 {
     932        6528 :                     free( hDirACRend->buffer_intensity_real_fx[i][j] );
     933             :                 }
     934       36960 :                 hDirACRend->buffer_intensity_real_fx[i][j] = NULL;
     935             :             }
     936             :         }
     937         385 :         IF( hDirACRend->buffer_energy_fx != NULL )
     938             :         {
     939          68 :             free( hDirACRend->buffer_energy_fx );
     940          68 :             hDirACRend->buffer_energy_fx = NULL;
     941             :         }
     942             :     }
     943             :     /* output synthesis */
     944        3970 :     ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag );
     945             : 
     946             :     /* Allocate stack memory */
     947        3970 :     IF( NE_16( flag_config, DIRAC_OPEN ) )
     948             :     {
     949        3446 :         ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) );
     950             :     }
     951        3970 :     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        3970 :     if ( EQ_16( flag_config, DIRAC_OPEN ) )
     957             :     {
     958         524 :         st_ivas->hDirACRend = hDirACRend;
     959             :     }
     960             : 
     961        3970 :     return error;
     962             : }
     963             : 
     964             : 
     965             : /*-------------------------------------------------------------------------
     966             :  * ivas_dirac_dec_config()
     967             :  *
     968             :  * Open or reconfigure decoder DirAC/MASA handle
     969             :  *-------------------------------------------------------------------------*/
     970             : 
     971       12654 : 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       12654 :     error = IVAS_ERR_OK;
     990       12654 :     move32();
     991             : 
     992             :     /* Solve and setup flags for inits */
     993       12654 :     IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
     994             :     {
     995        1315 :         dec_config_flag = DIRAC_RECONFIGURE;
     996        1315 :         move32();
     997             :     }
     998             :     ELSE
     999             :     {
    1000       11339 :         dec_config_flag = flag_config_inp;
    1001       11339 :         move32();
    1002             :     }
    1003             : 
    1004       12654 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
    1005       12654 :     move32();
    1006       12654 :     hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
    1007       12654 :     IF( EQ_32( dec_config_flag, DIRAC_RECONFIGURE ) )
    1008             :     {
    1009       12025 :         dec_param_estim_old = st_ivas->hDirAC->hConfig->dec_param_estim;
    1010       12025 :         move16();
    1011             :     }
    1012             :     ELSE
    1013             :     {
    1014         629 :         dec_param_estim_old = FALSE;
    1015         629 :         move16();
    1016             :     }
    1017             : 
    1018       12654 :     num_poses = 1;
    1019       12654 :     move16();
    1020       12654 :     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       12654 :     sparfoa_flag = 0;
    1027       12654 :     move16();
    1028       12654 :     test();
    1029       12654 :     test();
    1030       12654 :     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       12654 :     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       12654 :     test();
    1043       12654 :     test();
    1044       12654 :     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        8648 :         st_ivas->hDirAC->hConfig->dec_param_estim = FALSE;
    1047        8648 :         move16();
    1048             :     }
    1049             : 
    1050       12654 :     dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim;
    1051       12654 :     move16();
    1052             : 
    1053             :     /* Setup renderers and meta */
    1054             :     /* First, free everything if in reconfig and not the active renderer */
    1055       12654 :     need_parambin = 0;
    1056       12654 :     move16();
    1057       12654 :     SWITCH( st_ivas->renderer_type )
    1058             :     {
    1059        8648 :         case RENDERER_BINAURAL_PARAMETRIC:
    1060             :         case RENDERER_BINAURAL_PARAMETRIC_ROOM:
    1061             :         case RENDERER_STEREO_PARAMETRIC:
    1062        8648 :             need_parambin = 1;
    1063        8648 :             move16();
    1064        8648 :             BREAK;
    1065        4006 :         default:
    1066        4006 :             need_parambin = 0;
    1067        4006 :             move16();
    1068             :     }
    1069             : 
    1070       12654 :     IF( !need_parambin )
    1071             :     {
    1072        4006 :         ivas_dirac_dec_close_binaural_data_fx( st_ivas->hDiracDecBin );
    1073             :     }
    1074             : 
    1075       12654 :     need_dirac_rend = 0;
    1076       12654 :     move16();
    1077       12654 :     SWITCH( st_ivas->renderer_type )
    1078             :     {
    1079        3970 :         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        3970 :             need_dirac_rend = 1;
    1087        3970 :             move16();
    1088        3970 :             BREAK;
    1089        8684 :         default:
    1090        8684 :             need_dirac_rend = 0;
    1091        8684 :             move16();
    1092             :     }
    1093             : 
    1094       12654 :     IF( !need_dirac_rend )
    1095             :     {
    1096        8684 :         ivas_dirac_rend_close_fx( &st_ivas->hDirACRend );
    1097             :     }
    1098             : 
    1099       12654 :     IF( !sparfoa_flag )
    1100             :     {
    1101       12654 :         IF( st_ivas->hSpatParamRendCom == NULL )
    1102             :         {
    1103         629 :             common_rend_config_flag = DIRAC_OPEN;
    1104         629 :             move32();
    1105             :         }
    1106             :         ELSE
    1107             :         {
    1108       12025 :             common_rend_config_flag = flag_config_inp;
    1109       12025 :             move32();
    1110             :         }
    1111             : 
    1112       12654 :         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       12654 :         IF( need_dirac_rend )
    1120             :         {
    1121        3970 :             IF( st_ivas->hDirACRend == NULL )
    1122             :             {
    1123         524 :                 rend_config_flag = DIRAC_OPEN;
    1124         524 :                 move32();
    1125             :             }
    1126             :             ELSE
    1127             :             {
    1128        3446 :                 rend_config_flag = flag_config_inp;
    1129        3446 :                 move32();
    1130             :             }
    1131        3970 :             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       12654 :         IF( need_parambin )
    1138             :         {
    1139        8648 :             IF( NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
    1140             :             {
    1141        6932 :                 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        8648 :             IF( st_ivas->hDiracDecBin[0] == NULL )
    1148             :             {
    1149         467 :                 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        8181 :                 test();
    1158        8181 :                 test();
    1159        8181 :                 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        4520 :                     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        8181 :                 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        8181 :                 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        8181 :                 IF( !st_ivas->hDiracDecBin[0]->useTdDecorr )
    1176             :                 {
    1177        5295 :                     IF( st_ivas->hDiracDecBin[0]->h_freq_domain_decorr_ap_params == NULL )
    1178             :                     {
    1179             :                         Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
    1180             : 
    1181        4526 :                         ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands );
    1182             : 
    1183        4526 :                         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       16362 :                 FOR( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
    1193             :                 {
    1194        8181 :                     st_ivas->hDiracDecBin[pos_idx]->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate );
    1195        8181 :                     move16();
    1196             :                 }
    1197             :             }
    1198             :         }
    1199             :     }
    1200             : 
    1201       12654 :     return error;
    1202             : }
    1203             : 
    1204             : 
    1205             : /*-------------------------------------------------------------------------
    1206             :  * ivas_dirac_dec_close()
    1207             :  *
    1208             :  * Close DirAC memories
    1209             :  *------------------------------------------------------------------------*/
    1210             : 
    1211        2984 : void ivas_dirac_dec_close_fx(
    1212             :     DIRAC_DEC_HANDLE *hDirAC_out )
    1213             : {
    1214             :     DIRAC_DEC_HANDLE hDirAC;
    1215             : 
    1216        2984 :     test();
    1217        2984 :     IF( hDirAC_out == NULL || *hDirAC_out == NULL )
    1218             :     {
    1219        2355 :         return;
    1220             :     }
    1221             : 
    1222         629 :     hDirAC = *hDirAC_out;
    1223             : 
    1224             :     /* Config & CLDFB */
    1225         629 :     IF( hDirAC->hConfig != NULL )
    1226             :     {
    1227         629 :         free( hDirAC->hConfig );
    1228         629 :         hDirAC->hConfig = NULL;
    1229             :     }
    1230             : 
    1231         629 :     free( *hDirAC_out );
    1232         629 :     *hDirAC_out = NULL;
    1233             : 
    1234         629 :     return;
    1235             : }
    1236             : 
    1237             : 
    1238             : /*-------------------------------------------------------------------------
    1239             :  * ivas_dirac_dec_read_BS_fx()
    1240             :  *
    1241             :  * Read DirAC parameters from the bitstream
    1242             :  *------------------------------------------------------------------------*/
    1243             : 
    1244      161063 : 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      161063 :     test();
    1261      161063 :     test();
    1262      161063 :     IF( !st->bfi && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
    1263             :     {
    1264      152923 :         next_bit_pos_orig = st->next_bit_pos;
    1265      152923 :         move16();
    1266      152923 :         st->next_bit_pos = sub( extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), 1 );
    1267      152923 :         move16();
    1268      152923 :         if ( last_bit_pos > 0 )
    1269             :         {
    1270       37736 :             st->next_bit_pos = last_bit_pos;
    1271       37736 :             move16();
    1272             :         }
    1273             :         /* 1 bit flag for signaling metadata to read */
    1274      152923 :         b = st->bit_stream[( st->next_bit_pos )--];
    1275      152923 :         move16();
    1276      152923 :         ( *nb_bits )++;
    1277             : 
    1278      152923 :         IF( EQ_16( b, 1 ) ) /* WB 4TCs condition, no other metadata to read*/
    1279             :         {
    1280         635 :             orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
    1281         635 :             move16();
    1282             : 
    1283         635 :             hQMetaData->sba_inactive_mode = 1;
    1284         635 :             move16();
    1285             : 
    1286             :             /* if we start with a SID frame, we need to init the azi/ele arrays.*/
    1287         635 :             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         635 :             *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), nchan_transport, NULL, SBA_FORMAT ) );
    1297         635 :             move16();
    1298             : 
    1299        3175 :             FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
    1300             :             {
    1301        2540 :                 hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0];
    1302        2540 :                 move32();
    1303        2540 :                 hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0];
    1304        2540 :                 move32();
    1305        2540 :                 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        2540 :                 move32();
    1307        2540 :                 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        2540 :                 move16();
    1309             :             }
    1310        3175 :             FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
    1311             :             {
    1312        7520 :                 FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- )
    1313             :                 {
    1314        4980 :                     hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0];
    1315        4980 :                     move32();
    1316        4980 :                     hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0];
    1317        4980 :                     move32();
    1318        4980 :                     hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0];
    1319        4980 :                     move32();
    1320        4980 :                     hQMetaData->q_direction[0].band_data[j].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_index[0];
    1321        4980 :                     move16();
    1322             :                 }
    1323             :             }
    1324             : 
    1325         635 :             hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
    1326         635 :             move16();
    1327             :         }
    1328             :         ELSE
    1329             :         {
    1330      152288 :             hQMetaData->sba_inactive_mode = 0;
    1331      152288 :             move16();
    1332      152288 :             hQMetaData->is_masa_ivas_format = 0;
    1333      152288 :             move16();
    1334      152288 :             IF( hQMetaData->useLowerRes )
    1335             :             {
    1336       11890 :                 hQMetaData->q_direction[0].cfg.nblocks = 1;
    1337       11890 :                 move16();
    1338             :             }
    1339             :             ELSE
    1340             :             {
    1341      140398 :                 hQMetaData->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES;
    1342      140398 :                 move16();
    1343             :             }
    1344      152288 :             *nb_bits = add( *nb_bits, ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag ) );
    1345      152288 :             move16();
    1346             :         }
    1347             : 
    1348      152923 :         st->next_bit_pos = next_bit_pos_orig;
    1349      152923 :         move16();
    1350             :     }
    1351        8140 :     ELSE IF( !st->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
    1352             :     {
    1353         233 :         next_bit_pos_orig = st->next_bit_pos;
    1354         233 :         move16();
    1355             : 
    1356             :         /* subtract mode signaling bits, since bitstream was moved after mode reading */
    1357         233 :         i = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
    1358         233 :         st->next_bit_pos = sub( sub( i, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS );
    1359             : 
    1360         233 :         move16();
    1361             :         /* 1 bit flag for signaling metadata to read */
    1362         233 :         b = st->bit_stream[( st->next_bit_pos )--];
    1363         233 :         move16();
    1364         233 :         ( *nb_bits )++;
    1365         233 :         hQMetaData->sba_inactive_mode = 1;
    1366         233 :         move16();
    1367         233 :         orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
    1368         233 :         move16();
    1369             : 
    1370             :         /* if we start with a SID frame, we need to init the azi/ele arrays.*/
    1371         233 :         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         233 :         *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), nchan_transport, NULL, SBA_FORMAT ) );
    1383         233 :         move16();
    1384             : 
    1385        1165 :         FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
    1386             :         {
    1387         932 :             hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0];
    1388         932 :             move32();
    1389         932 :             hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0];
    1390         932 :             move32();
    1391         932 :             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         932 :             move32();
    1393         932 :             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         932 :             move16();
    1395             :         }
    1396        1165 :         FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
    1397             :         {
    1398        2756 :             FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- )
    1399             :             {
    1400        1824 :                 hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0];
    1401        1824 :                 move32();
    1402        1824 :                 hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0];
    1403        1824 :                 move32();
    1404        1824 :                 hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0];
    1405        1824 :                 move32();
    1406        1824 :                 hQMetaData->q_direction[0].band_data[j].energy_ratio_index[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_index[0];
    1407        1824 :                 move16();
    1408             :             }
    1409             :         }
    1410             : 
    1411         233 :         hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
    1412         233 :         move16();
    1413             : 
    1414         233 :         st->next_bit_pos = next_bit_pos_orig;
    1415         233 :         move16();
    1416             :     }
    1417             : 
    1418      161063 :     test();
    1419      161063 :     IF( hDirAC != NULL && hSpatParamRendCom != NULL )
    1420             :     {
    1421      103791 :         ivas_qmetadata_to_dirac_fx( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands );
    1422             :     }
    1423             : 
    1424      161063 :     return;
    1425             : }
    1426             : 
    1427             : 
    1428             : /*-----------------------------------------------------------------------*
    1429             :  * ivas_qmetadata_to_dirac()
    1430             :  *
    1431             :  * Copy qmetedata to DirAC parameters for rendering
    1432             :  *-----------------------------------------------------------------------*/
    1433             : 
    1434      198842 : 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      198842 :     Word16 nbands = 0;
    1456      198842 :     move16();
    1457      198842 :     Word16 nblocks = 0;
    1458      198842 :     move16();
    1459             :     Word16 qBand_idx;
    1460      198842 :     Word16 idx_sec = 0;
    1461      198842 :     move16();
    1462      198842 :     Word16 no_secs = 1;
    1463      198842 :     move16();
    1464      198842 :     q_direction = &( hQMetaData->q_direction[0] );
    1465             : 
    1466      198842 :     hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions;
    1467      198842 :     move16();
    1468      198842 :     hSpatParamRendCom->numSimultaneousDirections = add( hSpatParamRendCom->numParametricDirections, hSpatParamRendCom->numIsmDirections );
    1469      198842 :     move16();
    1470      198842 :     test();
    1471      198842 :     IF( hMasa != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
    1472       93929 :     {
    1473             :         Word16 meta_write_index;
    1474       93929 :         band_mapping = hMasa->data.band_mapping;
    1475       93929 :         move16();
    1476             : 
    1477      469645 :         FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
    1478             :         {
    1479      375716 :             meta_write_index = add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) % hSpatParamRendCom->dirac_md_buffer_length;
    1480             : 
    1481     3847796 :             FOR( band = 0; band < hMasa->config.numCodingBands; ++band )
    1482             :             {
    1483    24665840 :                 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    21193760 :                     Word32 L_tmp = L_abs( q_direction->band_data[band].azimuth_fx[block] );
    1487    21193760 :                     hSpatParamRendCom->azimuth[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
    1488    21193760 :                     move16();
    1489             : 
    1490    21193760 :                     IF( q_direction->band_data[band].azimuth_fx[block] < 0 )
    1491             :                     {
    1492     6878447 :                         hSpatParamRendCom->azimuth[meta_write_index][b] = negate( hSpatParamRendCom->azimuth[meta_write_index][b] );
    1493     6878447 :                         move16();
    1494             :                     }
    1495             : 
    1496    21193760 :                     L_tmp = L_abs( q_direction->band_data[band].elevation_fx[block] );
    1497    21193760 :                     hSpatParamRendCom->elevation[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
    1498    21193760 :                     move16();
    1499             : 
    1500    21193760 :                     IF( q_direction->band_data[band].elevation_fx[block] < 0 )
    1501             :                     {
    1502     3812770 :                         hSpatParamRendCom->elevation[meta_write_index][b] = negate( hSpatParamRendCom->elevation[meta_write_index][b] );
    1503     3812770 :                         move16();
    1504             :                     }
    1505             : 
    1506    21193760 :                     hSpatParamRendCom->energy_ratio1_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block];
    1507    21193760 :                     move32();
    1508    21193760 :                     hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub( ONE_IN_Q30, q_direction->band_data[band].energy_ratio_fx[block] );
    1509    21193760 :                     move32();
    1510             : 
    1511    21193760 :                     IF( q_direction->coherence_band_data != NULL )
    1512             :                     {
    1513    11785200 :                         hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]];
    1514    11785200 :                         move16();
    1515             :                     }
    1516             :                     ELSE
    1517             :                     {
    1518     9408560 :                         hSpatParamRendCom->spreadCoherence_fx[meta_write_index][b] = 0;
    1519     9408560 :                         move16();
    1520             :                     }
    1521             : 
    1522    21193760 :                     IF( hQMetaData->surcoh_band_data != NULL )
    1523             :                     {
    1524    11785200 :                         hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = ivas_divde_255[hQMetaData->surcoh_band_data[band].surround_coherence[block]]; /*q15*/
    1525    11785200 :                         move16();
    1526             :                     }
    1527             :                     ELSE
    1528             :                     {
    1529     9408560 :                         hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][b] = 0;
    1530     9408560 :                         move16();
    1531             :                     }
    1532             :                 }
    1533             :             }
    1534             :         }
    1535             : 
    1536       93929 :         test();
    1537       93929 :         test();
    1538       93929 :         test();
    1539       93929 :         IF( EQ_32( hQMetaData->no_directions, 2 ) )
    1540             :         {
    1541       12759 :             q_direction = &( hQMetaData->q_direction[1] );
    1542       63795 :             FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
    1543             :             {
    1544       51036 :                 meta_write_index = ( add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) ) % hSpatParamRendCom->dirac_md_buffer_length;
    1545             : 
    1546      658092 :                 FOR( band = 0; band < hMasa->config.numCodingBands; ++band )
    1547             :                 {
    1548     3466016 :                     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     2858960 :                         Word32 L_tmp = L_abs( q_direction->band_data[band].azimuth_fx[block] );
    1552     2858960 :                         hSpatParamRendCom->azimuth2[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
    1553     2858960 :                         move16();
    1554     2858960 :                         IF( q_direction->band_data[band].azimuth_fx[block] < 0 )
    1555             :                         {
    1556      295806 :                             hSpatParamRendCom->azimuth2[meta_write_index][b] = negate( hSpatParamRendCom->azimuth2[meta_write_index][b] );
    1557      295806 :                             move16();
    1558             :                         }
    1559             : 
    1560     2858960 :                         L_tmp = L_abs( q_direction->band_data[band].elevation_fx[block] );
    1561     2858960 :                         hSpatParamRendCom->elevation2[meta_write_index][b] = extract_h( L_shr( L_tmp, 6 ) );
    1562     2858960 :                         move16();
    1563     2858960 :                         IF( q_direction->band_data[band].elevation_fx[block] < 0 )
    1564             :                         {
    1565       91778 :                             hSpatParamRendCom->elevation2[meta_write_index][b] = negate( hSpatParamRendCom->elevation2[meta_write_index][b] );
    1566       91778 :                             move16();
    1567             :                         }
    1568             : 
    1569     2858960 :                         hSpatParamRendCom->energy_ratio2_fx[meta_write_index][b] = q_direction->band_data[band].energy_ratio_fx[block];
    1570     2858960 :                         move32();
    1571     2858960 :                         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     2858960 :                         move32();
    1573             : 
    1574             :                         /* Sanitize diffuseness for rare cases where floating point inaccuracy could result in negative diffuseness. */
    1575     2858960 :                         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     2858960 :                         IF( q_direction->coherence_band_data != NULL )
    1582             :                         {
    1583     2858960 :                             hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = ivas_divde_255[q_direction->coherence_band_data[band].spread_coherence[block]];
    1584     2858960 :                             move16();
    1585             :                         }
    1586             :                         ELSE
    1587             :                         {
    1588           0 :                             hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][b] = 0;
    1589           0 :                             move16();
    1590             :                         }
    1591             :                     }
    1592             :                 }
    1593             :             }
    1594             :         }
    1595       81170 :         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      359910 :             FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block )
    1599             :             {
    1600      287928 :                 meta_write_index = add( hSpatParamRendCom->dirac_bs_md_write_idx, block ) % hSpatParamRendCom->dirac_md_buffer_length;
    1601      287928 :                 set16_fx( hSpatParamRendCom->azimuth2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
    1602      287928 :                 set16_fx( hSpatParamRendCom->elevation2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
    1603             : 
    1604      287928 :                 set32_fx( hSpatParamRendCom->energy_ratio2_fx[meta_write_index], 0, hSpatParamRendCom->num_freq_bands );
    1605      287928 :                 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      104913 :         Word32 diffuseness_sec_fx = 0;
    1615      104913 :         move32();
    1616             : 
    1617             :         /* ungroup */
    1618      104913 :         seed_ptr = &hDirAC->dithering_seed;
    1619      104913 :         nblocks = q_direction->cfg.nblocks;
    1620      104913 :         move16();
    1621      104913 :         nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands];
    1622      104913 :         move16();
    1623      104913 :         band_grouping = hDirAC->band_grouping;
    1624             : 
    1625      104913 :         test();
    1626      104913 :         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        1122 :             start_band = 0;
    1630        1122 :             move16();
    1631        1122 :             hDirAC->hConfig->nbands = 5;
    1632        1122 :             move16();
    1633             : 
    1634        1122 :             ivas_dirac_config_bands_fx( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL, 1 );
    1635             : 
    1636        1122 :             nbands = 5;
    1637        1122 :             move16();
    1638             :         }
    1639             :         ELSE
    1640             :         {
    1641      103791 :             start_band = hDirAC->hConfig->enc_param_start_band;
    1642      103791 :             move16();
    1643      103791 :             IF( EQ_32( ivas_format, SBA_FORMAT ) )
    1644             :             {
    1645      103791 :                 hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS;
    1646      103791 :                 move16();
    1647             :             }
    1648             :             ELSE
    1649             :             {
    1650           0 :                 hDirAC->hConfig->nbands = q_direction->cfg.nbands;
    1651           0 :                 move16();
    1652             :             }
    1653             : 
    1654      103791 :             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      103791 :             nbands = hDirAC->hConfig->nbands;
    1657      103791 :             move16();
    1658      103791 :             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      824841 :         FOR( band = 0; band < start_band; band++ )
    1668             :         {
    1669      719928 :             band_start = band_grouping[band];
    1670      719928 :             move16();
    1671      719928 :             band_end = band_grouping[band + 1];
    1672      719928 :             move16();
    1673      719928 :             tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
    1674      719928 :             move16();
    1675             : 
    1676     3599640 :             FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
    1677             :             {
    1678     6839316 :                 FOR( b = band_start; b < band_end; b++ )
    1679             :                 {
    1680     3959604 :                     tmp_write_idx_band = tmp_write_idx_param_band;
    1681     3959604 :                     move16();
    1682             : 
    1683     3959604 :                     hSpatParamRendCom->spreadCoherence_fx[block][b] = 0;
    1684     3959604 :                     move16();
    1685     3959604 :                     hSpatParamRendCom->surroundingCoherence_fx[block][b] = 0;
    1686     3959604 :                     move16();
    1687     3959604 :                     hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = 0;
    1688     3959604 :                     move32();
    1689     3959604 :                     hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
    1690     3959604 :                     move16();
    1691     3959604 :                     hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
    1692     3959604 :                     move16();
    1693     3959604 :                     hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
    1694     3959604 :                     move32();
    1695     3959604 :                     hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0;
    1696     3959604 :                     move16();
    1697     3959604 :                     hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0;
    1698     3959604 :                     move16();
    1699             : 
    1700     3959604 :                     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      104913 :         if ( hodirac_flag )
    1707             :         {
    1708       13800 :             no_secs = DIRAC_HO_NUMSECTORS;
    1709       13800 :             move16();
    1710             :         }
    1711             : 
    1712      223626 :         FOR( idx_sec = 0; idx_sec < no_secs; idx_sec++ )
    1713             :         {
    1714      815487 :             FOR( band = start_band; band < nbands; band++ )
    1715             :             {
    1716      696774 :                 band_start = band_grouping[band];
    1717      696774 :                 move16();
    1718      696774 :                 band_end = band_grouping[band + 1];
    1719      696774 :                 move16();
    1720      696774 :                 tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx;
    1721      696774 :                 move16();
    1722             : 
    1723      696774 :                 IF( EQ_32( ivas_format, SBA_FORMAT ) )
    1724             :                 {
    1725      691164 :                     qBand_idx = sub( dirac_to_spar_md_bands[band], start_band );
    1726             :                 }
    1727             :                 ELSE
    1728             :                 {
    1729        5610 :                     qBand_idx = band;
    1730        5610 :                     move16();
    1731             :                 }
    1732      696774 :                 diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0];
    1733      696774 :                 move16();
    1734             : 
    1735      696774 :                 diffuseness_fx = L_sub( ONE_IN_Q30, q_direction->band_data[qBand_idx].energy_ratio_fx[0] );
    1736             : 
    1737     3483870 :                 FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
    1738             :                 {
    1739             :                     Word16 block_qmetadata;
    1740             : 
    1741     2787096 :                     block_qmetadata = s_min( block, sub( nblocks, 1 ) );
    1742     2787096 :                     block_qmetadata = s_max( block_qmetadata, 0 );
    1743             : 
    1744             : 
    1745     2787096 :                     if ( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] < 0 )
    1746             :                     {
    1747     1198977 :                         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     1198977 :                         move32();
    1749             :                     }
    1750             : 
    1751     2787096 :                     test();
    1752     2787096 :                     IF( hMasa == NULL && hodirac_flag )
    1753             :                     {
    1754     1324800 :                         azimuth_fx = q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata];
    1755     1324800 :                         move32();
    1756     1324800 :                         elevation_fx = q_direction[idx_sec].band_data[qBand_idx].elevation_fx[block_qmetadata];
    1757     1324800 :                         move32();
    1758     1324800 :                         diffuseness_fx = L_sub( ONE_IN_Q30, q_direction[0].band_data[qBand_idx].energy_ratio_fx[block_qmetadata] );
    1759     1324800 :                         diffuseness_sec_fx = q_direction[1].band_data[qBand_idx].energy_ratio_fx[block_qmetadata];
    1760     1324800 :                         move32();
    1761     1324800 :                         assert( diffuseness_sec_fx < 1073849216 /*1.0001f in Q30*/ && diffuseness_sec_fx > -107374 /*-0.0001f in Q30*/ );
    1762             :                     }
    1763             :                     ELSE
    1764             :                     {
    1765     1462296 :                         azimuth_fx = q_direction->band_data[qBand_idx].azimuth_fx[block_qmetadata];
    1766     1462296 :                         move32();
    1767     1462296 :                         elevation_fx = q_direction->band_data[qBand_idx].elevation_fx[block_qmetadata];
    1768     1462296 :                         move32();
    1769             :                     }
    1770    22990852 :                     FOR( b = band_start; b < band_end; b++ )
    1771             :                     {
    1772    20203756 :                         tmp_write_idx_band = tmp_write_idx_param_band;
    1773    20203756 :                         move16();
    1774             : 
    1775    20203756 :                         IF( hodirac_flag )
    1776             :                         {
    1777     6542400 :                             azi = extract_h( L_shr( ( L_add( azimuth_fx, ONE_IN_Q21 ) ), 6 ) );
    1778     6542400 :                             ele = extract_h( L_shr( ( L_add( elevation_fx, ONE_IN_Q21 ) ), 6 ) );
    1779             :                             /*addition of one to compensate precision loss*/
    1780     6542400 :                             if ( azi < 0 )
    1781             :                             {
    1782           0 :                                 azi = add( azi, 1 );
    1783             :                             }
    1784     6542400 :                             if ( ele < 0 )
    1785             :                             {
    1786      941559 :                                 ele = add( ele, 1 );
    1787             :                             }
    1788             :                         }
    1789             :                         ELSE
    1790             :                         {
    1791             :                             Word16 a, b_tmp;
    1792             : 
    1793    13661356 :                             Word16 exp_factor = 0;
    1794    13661356 :                             move16();
    1795    13661356 :                             a = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor
    1796             : 
    1797    13661356 :                             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    13661356 :                             Word16 norm_op1 = norm_l( azimuth_fx );
    1801    13661356 :                             Word16 norm_op2 = norm_l( tmp1_32 );
    1802    13661356 :                             Word16 op2_e = add( exp_factor, 5 );
    1803    13661356 :                             final_1_exp = add( s_max( s_max( sub( 9, norm_op1 ), sub( op2_e, norm_op2 ) ), 0 ), 2 ); // 2 for headroom
    1804    13661356 :                             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    13661356 :                             b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor );               // q = exp_factor
    1807    13661356 :                             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    13661356 :                             norm_op1 = norm_l( elevation_fx );
    1812    13661356 :                             norm_op2 = norm_l( tmp4_32 );
    1813    13661356 :                             op2_e = add( exp_factor, 4 );
    1814    13661356 :                             final_2_exp = add( s_max( s_max( sub( 9, norm_op1 ), sub( op2_e, norm_op2 ) ), 0 ), 2 ); // 2 for headroom
    1815    13661356 :                             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    13661356 :                             final_1_32 = L_add( final_1_32, L_shl( 1, sub( 30, final_1_exp ) ) ); /*0.5 in q31*/
    1818    13661356 :                             final_2_32 = L_add( final_2_32, L_shl( 1, sub( 30, final_2_exp ) ) );
    1819    13661356 :                             azi = extract_h( L_shr( final_1_32, sub( 15, final_1_exp ) ) );
    1820    13661356 :                             ele = extract_h( L_shr( final_2_32, sub( 15, final_2_exp ) ) );
    1821             : 
    1822             : 
    1823             :                             /*addition of one to compensate precision loss*/
    1824    13661356 :                             if ( azi < 0 )
    1825             :                             {
    1826     1409354 :                                 azi = add( azi, 1 );
    1827             :                             }
    1828    13661356 :                             if ( ele < 0 )
    1829             :                             {
    1830     5017446 :                                 ele = add( ele, 1 );
    1831             :                             }
    1832             :                             /* limit the elevation to [-90, 90] */
    1833    13661356 :                             ele = s_min( 90, ele );
    1834    13661356 :                             ele = s_max( -90, ele );
    1835             :                         }
    1836             : 
    1837    20203756 :                         test();
    1838    20203756 :                         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    20203756 :                             hSpatParamRendCom->spreadCoherence_fx[tmp_write_idx_band][b] = 0;
    1846    20203756 :                             move16();
    1847             :                         }
    1848             : 
    1849    20203756 :                         test();
    1850    20203756 :                         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    20203756 :                             hSpatParamRendCom->surroundingCoherence_fx[tmp_write_idx_band][b] = 0;
    1858    20203756 :                             move16();
    1859             :                         }
    1860             : 
    1861    20203756 :                         hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio_fx[0];
    1862    20203756 :                         move32();
    1863    20203756 :                         hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx;
    1864    20203756 :                         move32();
    1865             : 
    1866    20203756 :                         IF( hodirac_flag )
    1867             :                         {
    1868     6542400 :                             IF( idx_sec == 0 )
    1869             :                             {
    1870     3271200 :                                 hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
    1871     3271200 :                                 move16();
    1872     3271200 :                                 hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
    1873     3271200 :                                 move16();
    1874     3271200 :                                 hSpatParamRendCom->energy_ratio1_fx[tmp_write_idx_band][b] = 0;
    1875     3271200 :                                 move32();
    1876             :                             }
    1877             :                             ELSE
    1878             :                             {
    1879     3271200 :                                 assert( idx_sec == 1 );
    1880     3271200 :                                 hSpatParamRendCom->elevation2[tmp_write_idx_band][b] = ele;
    1881     3271200 :                                 move16();
    1882     3271200 :                                 hSpatParamRendCom->azimuth2[tmp_write_idx_band][b] = azi;
    1883     3271200 :                                 move16();
    1884     3271200 :                                 hSpatParamRendCom->energy_ratio2_fx[tmp_write_idx_band][b] = L_sub( ONE_IN_Q30, diffuseness_sec_fx );
    1885     3271200 :                                 move32();
    1886             :                             }
    1887             :                         }
    1888             :                         ELSE
    1889             :                         {
    1890    13661356 :                             hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele;
    1891    13661356 :                             move16();
    1892    13661356 :                             hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi;
    1893    13661356 :                             move16();
    1894             :                         }
    1895             :                     }
    1896     2787096 :                     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      104913 :         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      198842 :     hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length;
    1936      198842 :     move16();
    1937             : 
    1938      198842 :     return;
    1939             : }
    1940             : 
    1941             : 
    1942             : /*-------------------------------------------------------------------------
    1943             :  * ivas_dirac_dec_set_md_map()
    1944             :  *
    1945             :  * Set metadata index mapping for DirAC
    1946             :  *------------------------------------------------------------------------*/
    1947             : 
    1948      216456 : 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      216456 :     hDirAC = st_ivas->hDirAC;
    1958      216456 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1959             : 
    1960             :     /* adapt subframes */
    1961      216456 :     hSpatParamRendCom->num_slots = nCldfbTs;
    1962      216456 :     move16();
    1963      216456 :     hSpatParamRendCom->slots_rendered = 0;
    1964      216456 :     move16();
    1965      216456 :     num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
    1966      216456 :     move16();
    1967      216456 :     hSpatParamRendCom->subframes_rendered = 0;
    1968      216456 :     move16();
    1969             : 
    1970      216456 :     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      216456 :     test();
    1975      216456 :     test();
    1976      216456 :     test();
    1977      216456 :     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      189190 :         st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes;
    1980      189190 :         move16();
    1981      189190 :         Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes );
    1982             :     }
    1983             : 
    1984             :     /* set mapping according to dirac_read_idx */
    1985      216456 :     set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
    1986             : 
    1987      216456 :     test();
    1988      216456 :     test();
    1989      216456 :     IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
    1990             :     {
    1991       62869 :         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      153587 :     ELSE IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 )
    1994             :     {
    1995      102911 :         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       50676 :         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      216456 :     test();
    2003      216456 :     test();
    2004      216456 :     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      165780 :         slot_idx_abs = 0;
    2014      165780 :         move16();
    2015      838076 :         FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ )
    2016             :         {
    2017      672296 :             tmp_fx = 0;
    2018      672296 :             move32();
    2019     3324958 :             FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ )
    2020             :             {
    2021     2652662 :                 tmp_fx = L_add( tmp_fx, L_deposit_h( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) );
    2022     2652662 :                 slot_idx_abs = add( slot_idx_abs, 1 );
    2023             :             }
    2024             : 
    2025      672296 :             exp_denom = 15, exp_num = 31;
    2026      672296 :             move16();
    2027      672296 :             move16();
    2028      672296 :             norm_num = norm_l( tmp_fx );
    2029      672296 :             num = L_shl( tmp_fx, norm_num );
    2030      672296 :             exp_num = sub( exp_num, norm_num );
    2031             : 
    2032      672296 :             norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] );
    2033      672296 :             denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom );
    2034      672296 :             exp_denom = sub( exp_denom, norm_denom );
    2035             : 
    2036      672296 :             exp = sub( exp_num, exp_denom );
    2037             : 
    2038      672296 :             IF( GT_32( num, L_deposit_l( denom ) ) )
    2039             :             {
    2040      506492 :                 num = L_shr( num, 1 );
    2041      506492 :                 exp = add( exp, 1 );
    2042             :             }
    2043             : 
    2044      672296 :             ans = div_l( num, denom );
    2045      672296 :             ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final );
    2046      672296 :             ans_fix_16 = round_fx( L_shr( ans_fix_32, sub( sub( Q31, exp_final ), Q16 ) ) );
    2047             : 
    2048      672296 :             hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; // Q0
    2049      672296 :             move16();
    2050             :         }
    2051      165780 :         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      216456 :     return;
    2055             : }
    2056             : 
    2057             : 
    2058             : /*-------------------------------------------------------------------------
    2059             :  * ivas_dirac_dec_render_fx()
    2060             :  *
    2061             :  * DirAC decoding renderer process
    2062             :  *------------------------------------------------------------------------*/
    2063             : 
    2064       39736 : 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       39736 :     Word16 temp = 0;
    2076       39736 :     move16();
    2077             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    2078             :     Word32 *output_fx_local[MAX_OUTPUT_CHANNELS];
    2079             :     Word32 *p_output_fx[MAX_OUTPUT_CHANNELS];
    2080             :     Word32 output_fx_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    2081             : 
    2082       39736 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    2083             : 
    2084       39736 :     nchan_intern = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
    2085      314323 :     FOR( ch = 0; ch < nchan_intern; ch++ )
    2086             :     {
    2087      274587 :         output_fx_local[ch] = output_fx_local_buff[ch];
    2088      274587 :         p_output_fx[ch] = output_fx[ch];
    2089             :     }
    2090       39736 :     slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL
    2091             : 
    2092             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    2093       39736 :     slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) );
    2094             : 
    2095       39736 :     *nSamplesRendered = i_mult( slots_to_render, slot_size );
    2096       39736 :     move16();
    2097             : 
    2098       39736 :     first_sf = hSpatParamRendCom->subframes_rendered;
    2099       39736 :     move16();
    2100       39736 :     last_sf = first_sf;
    2101       39736 :     move16();
    2102             : 
    2103      178222 :     WHILE( slots_to_render > 0 )
    2104             :     {
    2105      138486 :         slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] );
    2106      138486 :         last_sf = add( last_sf, 1 );
    2107             :     }
    2108             : 
    2109      178222 :     FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    2110             :     {
    2111      138486 :         ivas_dirac_dec_render_sf_fx( st_ivas, output_fx_local, nchan_transport, NULL, NULL );
    2112             : 
    2113      138486 :         n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size );
    2114             : 
    2115     1143529 :         FOR( ch = 0; ch < nchan_intern; ch++ )
    2116             :         {
    2117             :             /* move to output */
    2118     1005043 :             test();
    2119     1005043 :             test();
    2120     1005043 :             IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) )
    2121             :             {
    2122     1003291 :                 Copy32( output_fx_local_buff[ch], p_output_fx[ch], n_samples_sf );
    2123             :             }
    2124             : 
    2125     1005043 :             p_output_fx[ch] += n_samples_sf;
    2126             :         }
    2127             : 
    2128             :         /* update combined orientation access index */
    2129      138486 :         ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
    2130             :     }
    2131             : 
    2132             :     /* clang-format off */
    2133       39736 :     IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) )
    2134             :     {
    2135       34111 :         IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) )
    2136             :         {
    2137           0 :             temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS );
    2138           0 :             hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
    2139             :         }
    2140             :         ELSE
    2141             :         {
    2142       34111 :             temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS );
    2143       34111 :             hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0
    2144             :         }
    2145             :     }
    2146             : 
    2147       39736 :     *nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); // Q0
    2148       39736 :     move16();
    2149             : 
    2150       39736 :     return;
    2151             : }
    2152             : /* clang-format on */
    2153             : 
    2154             : 
    2155             : /*-------------------------------------------------------------------------
    2156             :  * Local functions to perform binaural rendering with optimized stack
    2157             :  *------------------------------------------------------------------------*/
    2158             : 
    2159           0 : static void binRenderer_split_fx(
    2160             :     BINAURAL_RENDERER_HANDLE hBinRenderer,                                                                        /* i/o: binaural renderer handle                      */
    2161             :     ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend,                                                             /* i/o: ISAR split binaural rendering handle          */
    2162             :     COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,                                                         /* i  : combined head and external orientation handle */
    2163             :     const Word16 numTimeSlots,                                                                                    /* i  : number of time slots to render                */
    2164             :     Word32 Cldfb_RealBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Rotated Binaural signals                      */
    2165             :     Word32 Cldfb_ImagBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Rotated Binaural signals                      */
    2166             :     Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],                                   /* i  : LS signals                                    */
    2167             :     Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],                                   /* i  : LS signals                                    */
    2168             : #ifndef FIX_1119_SPLIT_RENDERING_VOIP
    2169             :     const Word16 slot_idx_start,
    2170             : #endif
    2171             :     const Word16 num_freq_bands,
    2172             :     const Word16 nchan_out )
    2173             : {
    2174             :     Word16 pos_idx, slot_idx, ch, input_q;
    2175             :     Word32 Cldfb_RealBuffer_Binaural_loc[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2176             :     Word32 Cldfb_ImagBuffer_Binaural_loc[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2177             : 
    2178           0 :     input_q = Q6;
    2179           0 :     move16();
    2180             : 
    2181             :     /* Perform binaural rendering */
    2182           0 :     ivas_binRenderer_fx( hBinRenderer, &hSplitBinRend->splitrend.multiBinPoseData, hCombinedOrientationData, numTimeSlots,
    2183             : #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG
    2184             :                          NULL,
    2185             : #endif
    2186             :                          Cldfb_RealBuffer_Binaural_loc, Cldfb_ImagBuffer_Binaural_loc, RealBuffer_fx, ImagBuffer_fx, &input_q );
    2187             : 
    2188           0 :     FOR( slot_idx = 0; slot_idx < numTimeSlots; slot_idx++ )
    2189             :     {
    2190           0 :         FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    2191             :         {
    2192           0 :             Copy32( Cldfb_RealBuffer_Binaural_loc[0][ch][slot_idx], Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], num_freq_bands );
    2193           0 :             Copy32( Cldfb_ImagBuffer_Binaural_loc[0][ch][slot_idx], Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], num_freq_bands );
    2194             :         }
    2195             :     }
    2196             : 
    2197           0 :     FOR( pos_idx = 0; pos_idx < hBinRenderer->numPoses; pos_idx++ )
    2198             :     {
    2199           0 :         FOR( slot_idx = 0; slot_idx < numTimeSlots; slot_idx++ )
    2200             :         {
    2201           0 :             FOR( ch = 0; ch < nchan_out; ch++ )
    2202             :             {
    2203             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    2204           0 :                 ivas_CLDFB_RINGBUF_Push(
    2205           0 :                     hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch],
    2206           0 :                     Cldfb_RealBuffer_Binaural_loc[pos_idx][ch][slot_idx],
    2207           0 :                     Cldfb_ImagBuffer_Binaural_loc[pos_idx][ch][slot_idx],
    2208             :                     num_freq_bands );
    2209             : #else
    2210             :                 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 );
    2211             :                 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 );
    2212             : #endif
    2213             :             }
    2214             :         }
    2215             :     }
    2216             : 
    2217           0 :     return;
    2218             : }
    2219             : 
    2220             : 
    2221      127607 : static void binRenderer_fx(
    2222             :     BINAURAL_RENDERER_HANDLE hBinRenderer,                                                                        /* i/o: binaural renderer handle                      */
    2223             :     COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,                                                         /* i  : combined head and external orientation handle */
    2224             :     const Word16 numTimeSlots,                                                                                    /* i  : number of time slots to render                */
    2225             :     Word32 Cldfb_RealBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Rotated Binaural signals                      */
    2226             :     Word32 Cldfb_ImagBuffer_Binaural_fx[][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o  : Rotated Binaural signals                      */
    2227             :     Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],                                   /* i  : LS signals                                    */
    2228             :     Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]                                    /* i  : LS signals                                    */
    2229             : )
    2230             : {
    2231             :     Word16 input_q;
    2232             : 
    2233      127607 :     input_q = Q6;
    2234      127607 :     move16();
    2235             : 
    2236             :     /* Perform binaural rendering */
    2237      127607 :     ivas_binRenderer_fx( hBinRenderer, NULL, hCombinedOrientationData, numTimeSlots,
    2238             : #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG
    2239             :                          NULL,
    2240             : #endif
    2241             :                          Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, RealBuffer_fx, ImagBuffer_fx, &input_q );
    2242             : 
    2243      127607 :     return;
    2244             : }
    2245             : 
    2246             : 
    2247             : /*-------------------------------------------------------------------------
    2248             :  * ivas_dirac_dec_render_sf_fx()
    2249             :  *
    2250             :  * DirAC decoding renderer process
    2251             :  *------------------------------------------------------------------------*/
    2252             : 
    2253      387828 : void ivas_dirac_dec_render_sf_fx(
    2254             :     Decoder_Struct *st_ivas,      /* i/o: IVAS decoder structure                                  */
    2255             :     Word32 *output_buf_fx[],      /* i/o: synthesized core-coder transport channels/DirAC output  Q(6-1)*/
    2256             :     const Word16 nchan_transport, /* i  : number of transport channels                            */
    2257             :     Word32 *pppQMfFrame_ts_re_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX],
    2258             :     Word32 *pppQMfFrame_ts_im_fx[HOA3_CHANNELS][CLDFB_NO_COL_MAX] )
    2259             : {
    2260             :     Word16 i, ch, idx_in, idx_lfe;
    2261             :     DIRAC_DEC_HANDLE hDirAC;
    2262             :     DIRAC_REND_HANDLE hDirACRend;
    2263             :     Word16 subframe_idx;
    2264             :     Word16 slot_idx, index_slot;
    2265             :     Word16 hodirac_flag;
    2266             :     Word16 slot_idx_start, slot_idx_start_cldfb_synth, md_idx;
    2267             : 
    2268             :     /*CLDFB: last output channels reserved to LFT for CICPx*/
    2269             :     Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2270             :     Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2271             :     Word32 Cldfb_RealBuffer_Binaural_fx[1][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2272             :     Word32 Cldfb_ImagBuffer_Binaural_fx[1][BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    2273      387828 :     Word16 index = 0, num_freq_bands = 0;
    2274      387828 :     move16();
    2275      387828 :     move16();
    2276             : 
    2277             :     /* local copies of azi, ele, diffuseness */
    2278             :     Word16 azimuth[CLDFB_NO_CHANNELS_MAX];
    2279             :     Word16 elevation[CLDFB_NO_CHANNELS_MAX];
    2280             :     Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX];
    2281             :     Word32 *p_Rmat_fx;
    2282             :     Word32 *reference_power_fx, *reference_power_smooth_fx, *onset_filter_fx, *onset_filter_subframe_fx;
    2283             :     Word32 dirEne_fx;
    2284             :     Word32 surCohEner_fx;
    2285             :     Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX];
    2286      387828 :     Word16 surCohRatio_q_fx = 0, temp_q = 0;
    2287      387828 :     move16();
    2288      387828 :     move16();
    2289             : #ifndef FIX_2140_OBJECT_EDITING_SANITIZER_ISSUES
    2290             :     Word16 cldfb_buf_q;
    2291             : #endif
    2292      387828 :     Word16 offset = 0, buff_len = 0;
    2293      387828 :     move16();
    2294      387828 :     move16();
    2295      387828 :     Word16 q_cldfb, q_temp_cldfb = 0;
    2296      387828 :     move16();
    2297      387828 :     Word16 proto_length = 0;
    2298      387828 :     move16();
    2299             :     Word16 q_proto_direct_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
    2300             :     Word16 q_proto_diffuse_buffer[CLDFB_SLOTS_PER_SUBFRAME + 1];
    2301             :     Word16 size, size_ho;
    2302             : 
    2303             :     DIRAC_DEC_STACK_MEM DirAC_mem;
    2304      387828 :     Word32 *p_onset_filter_fx = NULL;
    2305             :     UWord16 coherence_flag;
    2306             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    2307      387828 :     Word16 scale = 0;
    2308      387828 :     move16();
    2309             :     DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
    2310             :     DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
    2311             :     Word16 num_channels_dir, exp;
    2312      387828 :     Word16 q_diffuseness_vector = Q31, q_reference_power_smooth[2] = { Q31, Q31 };
    2313      387828 :     move16();
    2314      387828 :     move16();
    2315      387828 :     move16();
    2316      387828 :     Word16 proto_power_smooth_len = 0;
    2317      387828 :     move16();
    2318             :     Word16 tmp1;
    2319             : 
    2320      387828 :     push_wmops( "ivas_dirac_dec_render" );
    2321             : 
    2322             :     /* Initialize aux buffers */
    2323     6593076 :     FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
    2324             :     {
    2325    31026240 :         FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
    2326             :         {
    2327    24820992 :             set32_fx( Cldfb_RealBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
    2328    24820992 :             set32_fx( Cldfb_ImagBuffer_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
    2329             :         }
    2330             :     }
    2331             : 
    2332      387828 :     hDirAC = st_ivas->hDirAC;
    2333      387828 :     hDirACRend = st_ivas->hDirACRend;
    2334      387828 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    2335             : 
    2336      387828 :     DirAC_mem = hDirACRend->stack_mem;
    2337             : 
    2338      387828 :     reference_power_fx = DirAC_mem.reference_power_fx;
    2339      387828 :     IF( DirAC_mem.reference_power_fx == NULL )
    2340             :     {
    2341       12019 :         reference_power_smooth_fx = NULL;
    2342             :     }
    2343             :     ELSE
    2344             :     {
    2345      375809 :         reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands;
    2346             :     }
    2347      387828 :     onset_filter_fx = DirAC_mem.onset_filter_fx;
    2348      387828 :     IF( DirAC_mem.onset_filter_fx == NULL )
    2349             :     {
    2350       24817 :         onset_filter_subframe_fx = NULL;
    2351             :     }
    2352             :     ELSE
    2353             :     {
    2354      363011 :         onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands;
    2355             :     }
    2356      387828 :     q_cldfb = Q11;
    2357      387828 :     move16();
    2358      387828 :     set16_fx( q_proto_direct_buffer, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
    2359      387828 :     set16_fx( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME + 1 );
    2360      387828 :     set_zero_fx( surCohRatio_fx, CLDFB_NO_CHANNELS_MAX );
    2361             : 
    2362      387828 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
    2363             :     {
    2364       10821 :         IF( hDirACRend->masa_stereo_type_detect )
    2365             :         {
    2366       10821 :             hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = 0;
    2367       10821 :             move32();
    2368       10821 :             hDirACRend->masa_stereo_type_detect->q_subtract_power_y = Q31;
    2369       10821 :             move16();
    2370             :         }
    2371             :     }
    2372             : 
    2373      387828 :     test();
    2374      387828 :     IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
    2375             :     {
    2376      129642 :         IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 )
    2377             :         {
    2378      115646 :             DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state );
    2379      115646 :             tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len );
    2380             : 
    2381      115646 :             scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); // Q(proto_power_diff_smooth_q + tmp1)
    2382      115646 :             state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 );
    2383      115646 :             move16();
    2384             :         }
    2385             :     }
    2386             : 
    2387      387828 :     h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
    2388      387828 :     h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
    2389      387828 :     num_channels_dir = hDirACRend->num_outputs_dir;
    2390      387828 :     move16();
    2391      387828 :     hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
    2392      387828 :     if ( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
    2393             :     {
    2394       91524 :         num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
    2395       91524 :         move16();
    2396             :     }
    2397             : 
    2398      387828 :     test();
    2399      387828 :     test();
    2400      387828 :     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 ) ) )
    2401             :     {
    2402       77528 :         tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    2403       77528 :         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
    2404       77528 :         h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1;
    2405       77528 :         move16();
    2406             :     }
    2407             : 
    2408      387828 :     test();
    2409      387828 :     IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2410             :     {
    2411             :         Word16 shift;
    2412       13996 :         shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    2413       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
    2414       13996 :         h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift );
    2415       13996 :         move16();
    2416       13996 :         shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    2417       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
    2418       13996 :         h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift );
    2419       13996 :         move16();
    2420       13996 :         tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    2421       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
    2422       13996 :         h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 );
    2423       13996 :         move16();
    2424             :     }
    2425             : 
    2426      387828 :     test();
    2427      387828 :     test();
    2428      387828 :     IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    2429             :     {
    2430      382821 :         FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
    2431             :         {
    2432      255214 :             st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
    2433      255214 :             move16();
    2434             :         }
    2435             :     }
    2436      260221 :     ELSE IF( !( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
    2437             :     {
    2438             :         Word16 outchannels;
    2439      138486 :         idx_lfe = 0;
    2440      138486 :         move16();
    2441      138486 :         idx_in = 0;
    2442      138486 :         move16();
    2443      138486 :         outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
    2444             : 
    2445      138486 :         test();
    2446      138486 :         test();
    2447      138486 :         test();
    2448      138486 :         test();
    2449      138486 :         test();
    2450      138486 :         test();
    2451      138486 :         test();
    2452      138486 :         IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
    2453             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
    2454             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
    2455             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
    2456             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
    2457             :                                                               ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
    2458             :         {
    2459         876 :             outchannels = add( outchannels, 1 );
    2460             :         }
    2461             : 
    2462      138486 :         test();
    2463      138486 :         IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
    2464             :         {
    2465           0 :             FOR( ch = 0; ch < outchannels; ch++ )
    2466             :             {
    2467           0 :                 test();
    2468           0 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    2469             :                 {
    2470           0 :                     IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    2471             :                     {
    2472           0 :                         idx_lfe = add( idx_lfe, 1 );
    2473             :                     }
    2474             :                 }
    2475             :             }
    2476             :         }
    2477             :         ELSE
    2478             :         {
    2479     1143529 :             FOR( ch = 0; ch < outchannels; ch++ )
    2480             :             {
    2481             : 
    2482     1005043 :                 test();
    2483     1005043 :                 test();
    2484     1005043 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    2485             :                 {
    2486       77528 :                     test();
    2487       77528 :                     IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
    2488             :                     {
    2489             :                         Word16 cldfbSynIdx;
    2490        6640 :                         cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
    2491        6640 :                         st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
    2492        6640 :                         move16();
    2493             :                     }
    2494             :                 }
    2495      927515 :                 ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
    2496             :                 {
    2497             :                 }
    2498             :                 ELSE
    2499             :                 {
    2500      926639 :                     st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
    2501      926639 :                     move16();
    2502      926639 :                     idx_in = add( idx_in, 1 );
    2503             :                 }
    2504             :             }
    2505             :         }
    2506             :     }
    2507             : 
    2508      387828 :     size = imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
    2509      387828 :     IF( hodirac_flag )
    2510             :     {
    2511       54520 :         size_ho = imult1616( size, DIRAC_HO_NUMSECTORS );
    2512             :     }
    2513             :     ELSE
    2514             :     {
    2515      333308 :         size_ho = size;
    2516      333308 :         move16();
    2517             :     }
    2518      387828 :     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
    2519      387828 :     hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26;
    2520      387828 :     move16();
    2521             : 
    2522      387828 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2523             :     {
    2524             :         Word16 shift;
    2525      247365 :         shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho );
    2526      247365 :         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)
    2527      247365 :         hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift );
    2528      247365 :         move16();
    2529             : 
    2530      247365 :         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
    2531      247365 :         hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26;
    2532      247365 :         move16();
    2533             : 
    2534      247365 :         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
    2535      247365 :         hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26;
    2536      247365 :         move16();
    2537             : 
    2538      247365 :         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
    2539      247365 :         hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26;
    2540      247365 :         move16();
    2541             :     }
    2542             :     ELSE
    2543             :     {
    2544             :         Word16 shift;
    2545      140463 :         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
    2546      140463 :         hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26;
    2547      140463 :         move16();
    2548             : 
    2549      140463 :         shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho );
    2550      140463 :         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)
    2551      140463 :         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 );
    2552      140463 :         move16();
    2553      140463 :         shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho );
    2554      140463 :         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)
    2555      140463 :         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 );
    2556      140463 :         move16();
    2557      140463 :         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 ) );
    2558      140463 :         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)
    2559      140463 :         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 );
    2560      140463 :         move16();
    2561      140463 :         tmp1 = 31;
    2562      140463 :         move16();
    2563      530713 :         FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
    2564             :         {
    2565      390250 :             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 ) ) );
    2566             :         }
    2567      530713 :         FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
    2568             :         {
    2569      390250 :             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)
    2570             :         }
    2571      140463 :         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 );
    2572      140463 :         move16();
    2573      140463 :         tmp1 = 31;
    2574      140463 :         move16();
    2575      530713 :         FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
    2576             :         {
    2577      390250 :             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 ) ) ) );
    2578             :         }
    2579      530713 :         FOR( i = 0; i < i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_dir ); i = add( i, hSpatParamRendCom->num_freq_bands ) )
    2580             :         {
    2581      390250 :             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)
    2582             :         }
    2583      140463 :         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 );
    2584      140463 :         move16();
    2585      140463 :         IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
    2586             :         {
    2587      115646 :             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 ) );
    2588      115646 :             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)
    2589      115646 :             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 );
    2590      115646 :             move16();
    2591             :         }
    2592             :     }
    2593             : 
    2594      387828 :     hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
    2595             : 
    2596      387828 :     test();
    2597      387828 :     test();
    2598      387828 :     IF( st_ivas->hQMetaData != NULL && NE_32( st_ivas->ivas_format, SBA_FORMAT ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    2599             :     {
    2600      138486 :         coherence_flag = st_ivas->hQMetaData->coherence_flag;
    2601      138486 :         move16();
    2602             :     }
    2603             :     ELSE
    2604             :     {
    2605      249342 :         coherence_flag = 0;
    2606      249342 :         move16();
    2607             :     }
    2608             :     /* Subframe loop */
    2609      387828 :     slot_idx_start = hSpatParamRendCom->slots_rendered;
    2610      387828 :     move16();
    2611      387828 :     slot_idx_start_cldfb_synth = 0;
    2612      387828 :     move16();
    2613             : 
    2614      387828 :     subframe_idx = hSpatParamRendCom->subframes_rendered;
    2615      387828 :     move16();
    2616      387828 :     IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
    2617             :     {
    2618      193006 :         md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
    2619      193006 :         move16();
    2620             :     }
    2621             :     ELSE
    2622             :     {
    2623      194822 :         md_idx = hSpatParamRendCom->render_to_md_map[slot_idx_start];
    2624      194822 :         move16();
    2625             :     }
    2626             : 
    2627             :     /* copy parameters into local buffers*/
    2628      387828 :     IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
    2629             :     {
    2630      193006 :         Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
    2631      193006 :         q_diffuseness_vector = Q30;
    2632      193006 :         move16();
    2633      193006 :         Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands );
    2634      193006 :         Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands );
    2635             :     }
    2636             :     ELSE
    2637             :     {
    2638      194822 :         set32_fx( diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands );
    2639      194822 :         q_diffuseness_vector = Q31;
    2640      194822 :         move16();
    2641             :     }
    2642             : 
    2643      387828 :     IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2644             :     {
    2645      140463 :         set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands );
    2646             :     }
    2647             :     ELSE
    2648             :     {
    2649      247365 :         set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands );
    2650             :     }
    2651             : 
    2652      387828 :     test();
    2653      387828 :     IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] )
    2654             :     {
    2655       41400 :         p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0];
    2656             : 
    2657       41400 :         IF( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
    2658             :         {
    2659       36800 :             num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
    2660       36800 :             move16();
    2661       36800 :             IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
    2662             :             {
    2663           0 :                 rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
    2664             :             }
    2665             :         }
    2666             :     }
    2667             :     ELSE
    2668             :     {
    2669      346428 :         p_Rmat_fx = 0;
    2670      346428 :         move32();
    2671             :     }
    2672             : 
    2673      387828 :     IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) )
    2674             :     {
    2675             :         Word16 *masa_band_mapping;
    2676             :         /* compute response */
    2677      193006 :         IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2678             :         {
    2679      126467 :             ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands,
    2680             :                                                      diffuseness_vector_fx,
    2681      126467 :                                                      hDirACRend->h_output_synthesis_psd_params.max_band_decorr,
    2682             :                                                      hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
    2683             :                                                      hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx );
    2684             : 
    2685      126467 :             hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29;
    2686      126467 :             move16();
    2687      126467 :             hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29;
    2688      126467 :             move16();
    2689             : 
    2690      126467 :             IF( coherence_flag )
    2691             :             {
    2692     3934144 :                 FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
    2693             :                 {
    2694     3867140 :                     dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // Q29
    2695     3867140 :                     move32();
    2696     3867140 :                     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
    2697             : 
    2698     3867140 :                     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
    2699     3867140 :                     move32();
    2700     3867140 :                     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
    2701     3867140 :                     move32();
    2702             : 
    2703     3867140 :                     surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale_newton( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q );
    2704     3867140 :                     move32();
    2705     3867140 :                     surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], sub( temp_q, 16 ) ); // Q15
    2706     3867140 :                     move32();
    2707             :                 }
    2708             :             }
    2709             :             ELSE
    2710             :             {
    2711       59463 :                 set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
    2712             :             }
    2713      126467 :             surCohRatio_q_fx = Q15;
    2714      126467 :             move16();
    2715             :         }
    2716             :         ELSE
    2717             :         {
    2718             :             Word16 max_exp_direct, max_exp_diffusion;
    2719       66539 :             max_exp_direct = 0;
    2720       66539 :             move16();
    2721       66539 :             max_exp_diffusion = 0;
    2722       66539 :             move16();
    2723       66539 :             ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands,
    2724       66539 :                                                     hSpatParamRendCom->diffuseness_vector_fx[md_idx],
    2725             :                                                     hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
    2726             :                                                     hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx,
    2727             :                                                     &max_exp_direct, &max_exp_diffusion );
    2728             : 
    2729       66539 :             hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( Q31, max_exp_direct );
    2730       66539 :             move16();
    2731       66539 :             hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( Q31, max_exp_diffusion );
    2732       66539 :             move16();
    2733             : 
    2734       66539 :             IF( coherence_flag )
    2735             :             {
    2736      264191 :                 FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
    2737             :                 {
    2738      259860 :                     surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] );
    2739      259860 :                     move32();
    2740             :                 }
    2741             :             }
    2742             :             ELSE
    2743             :             {
    2744       62208 :                 set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands );
    2745             :             }
    2746       66539 :             surCohRatio_q_fx = Q15;
    2747       66539 :             move16();
    2748             :         }
    2749             : 
    2750      193006 :         IF( st_ivas->hMasa == NULL )
    2751             :         {
    2752       54520 :             masa_band_mapping = NULL;
    2753             :         }
    2754             :         ELSE
    2755             :         {
    2756      138486 :             masa_band_mapping = st_ivas->hMasa->data.band_mapping;
    2757             :         }
    2758      193006 :         ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom,
    2759             :                                                          hDirACRend,
    2760             :                                                          st_ivas->hVBAPdata,
    2761             :                                                          masa_band_mapping,
    2762             :                                                          st_ivas->hMasaIsmData,
    2763             :                                                          azimuth,
    2764             :                                                          elevation,
    2765             :                                                          md_idx,
    2766             :                                                          surCohRatio_fx,
    2767             :                                                          surCohRatio_q_fx,
    2768             :                                                          hodirac_flag );
    2769             :     }
    2770             : 
    2771      387828 :     test();
    2772      387828 :     IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
    2773             :     {
    2774      149514 :         FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    2775             :         {
    2776      118447 :             index_slot = add( slot_idx_start, slot_idx );
    2777      118447 :             offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
    2778             :             /* CLDFB Analysis*/
    2779      355341 :             FOR( ch = 0; ch < nchan_transport; ch++ )
    2780             :             {
    2781      236894 :                 q_temp_cldfb = Q11;
    2782      236894 :                 move16();
    2783      236894 :                 cldfbAnalysis_ts_fx_fixed_q( &( st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ),
    2784      236894 :                                              Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], /* note: it is a tmp. buffer at this point */
    2785      236894 :                                              Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], /* note: it is a tmp. buffer at this point */
    2786      236894 :                                              hSpatParamRendCom->num_freq_bands,
    2787             :                                              st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
    2788             :             }
    2789      118447 :             q_cldfb = q_temp_cldfb;
    2790      118447 :             move16();
    2791             :         }
    2792             : 
    2793       31067 :         IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
    2794             :         {
    2795             : #ifdef FIX_2140_OBJECT_EDITING_SANITIZER_ISSUES
    2796        9184 :             ivas_omasa_preProcessStereoTransportsForEditedObjects_fx( st_ivas, Cldfb_RealBuffer_Binaural_fx[0], Cldfb_ImagBuffer_Binaural_fx[0], &q_cldfb, hSpatParamRendCom->num_freq_bands, subframe_idx );
    2797             : #else
    2798             :             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 );
    2799             : #endif
    2800             :         }
    2801             :     }
    2802             : 
    2803     1926849 :     FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    2804             :     {
    2805     1539021 :         index_slot = add( slot_idx_start, slot_idx );
    2806     1539021 :         IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
    2807             :         {
    2808      775083 :             md_idx = hSpatParamRendCom->render_to_md_map[index_slot];
    2809      775083 :             move16();
    2810             :         }
    2811             :         ELSE
    2812             :         {
    2813      763938 :             md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
    2814      763938 :             move16();
    2815             :         }
    2816     1539021 :         test();
    2817     1539021 :         test();
    2818     1539021 :         IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
    2819             :         {
    2820     6479463 :             FOR( ch = 0; ch < nchan_transport; ch++ )
    2821             :             {
    2822     5486300 :                 Copy32( pppQMfFrame_ts_re_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2823     5486300 :                 Copy32( pppQMfFrame_ts_im_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2824             :             }
    2825      993163 :             q_cldfb = Q6;
    2826      993163 :             move16();
    2827             :         }
    2828      545858 :         ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) )
    2829             :         {
    2830      355341 :             FOR( ch = 0; ch < nchan_transport; ch++ )
    2831             :             {
    2832      236894 :                 Copy32( Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2833      236894 :                 Copy32( Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands );
    2834             :             }
    2835             :         }
    2836             :         ELSE
    2837             :         {
    2838             :             /* CLDFB Analysis*/
    2839      427411 :             offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot );
    2840     1076314 :             FOR( ch = 0; ch < nchan_transport; ch++ )
    2841             :             {
    2842      648903 :                 q_temp_cldfb = Q11;
    2843      648903 :                 move16();
    2844      648903 :                 cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset],
    2845      648903 :                                              Cldfb_RealBuffer_fx[ch][0],
    2846      648903 :                                              Cldfb_ImagBuffer_fx[ch][0],
    2847      648903 :                                              hSpatParamRendCom->num_freq_bands,
    2848             :                                              st_ivas->cldfbAnaDec[ch], &q_temp_cldfb );
    2849             :             }
    2850      427411 :             q_cldfb = q_temp_cldfb;
    2851      427411 :             move16();
    2852             :         }
    2853             : 
    2854             :         /* CNG in DirAC, extra CLDFB ana for CNA*/
    2855     1539021 :         test();
    2856     1539021 :         test();
    2857     1539021 :         test();
    2858     1539021 :         test();
    2859     1539021 :         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 ) ) ) )
    2860             :         {
    2861       48060 :             Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
    2862       48060 :             Word16 Q_input = Q11;
    2863       48060 :             move16();
    2864       48060 :             q_temp_cldfb = Q11;
    2865       48060 :             move16();
    2866       48060 :             test();
    2867       48060 :             test();
    2868       48060 :             test();
    2869      144180 :             generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom,
    2870             :                                                   st_ivas->cldfbAnaDec[1],
    2871       48060 :                                                   &st_ivas->hTcBuffer->tc_fx[1][hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->slots_rendered],
    2872             :                                                   Cldfb_RealBuffer_fx[1][0],
    2873             :                                                   Cldfb_ImagBuffer_fx[1][0],
    2874             :                                                   slot_idx,
    2875       48060 :                                                   st->cna_dirac_flag && st->flag_cna,
    2876       48060 :                                                   ( ( ( 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 );
    2877       48060 :             Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
    2878       48060 :             Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6
    2879             :         }
    2880             : 
    2881             :         /* LFE synthesis */
    2882     1539021 :         test();
    2883     1539021 :         test();
    2884     1539021 :         test();
    2885     1539021 :         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 ) )
    2886             :         {
    2887       26560 :             ivas_lfe_synth_with_cldfb_fx( st_ivas->hMasa->hMasaLfeSynth,
    2888             :                                           Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    2889             :                                           Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1],
    2890             :                                           slot_idx,
    2891             :                                           md_idx,
    2892             :                                           nchan_transport, q_cldfb );
    2893             :         }
    2894             : 
    2895             :         /*-----------------------------------------------------------------*
    2896             :          * protoype signal computation
    2897             :          *-----------------------------------------------------------------*/
    2898     1539021 :         IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    2899             :         {
    2900      985239 :             test();
    2901      985239 :             test();
    2902      985239 :             IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
    2903             :             {
    2904      147200 :                 protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    2905             :                                                hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    2906             :                                                &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    2907             :                                                hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
    2908             :                                                &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
    2909             :                                                reference_power_fx, DirAC_mem.reference_power_q,
    2910             :                                                slot_idx, nchan_transport,
    2911      147200 :                                                hDirACRend->num_outputs_diff,
    2912      147200 :                                                hSpatParamRendCom->num_freq_bands,
    2913             :                                                p_Rmat_fx, q_cldfb );
    2914             :             }
    2915             :             ELSE
    2916             :             {
    2917      838039 :                 protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    2918             :                                                hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    2919             :                                                &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    2920             :                                                hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
    2921             :                                                &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
    2922             :                                                reference_power_fx, DirAC_mem.reference_power_q,
    2923             :                                                slot_idx, nchan_transport,
    2924      838039 :                                                hDirACRend->num_outputs_diff,
    2925      838039 :                                                hSpatParamRendCom->num_freq_bands,
    2926             :                                                0, q_cldfb );
    2927             :             }
    2928             : 
    2929      985239 :             q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
    2930      985239 :             move16();
    2931      985239 :             q_proto_diffuse_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q;
    2932      985239 :             move16();
    2933             :         }
    2934      553782 :         ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
    2935             :         {
    2936       43284 :             protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
    2937             :                                         &hDirACRend->proto_frame_f_q,
    2938             :                                         hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    2939             :                                         &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    2940             :                                         reference_power_fx,
    2941             :                                         DirAC_mem.reference_power_q,
    2942             :                                         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
    2943       43284 :                                         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
    2944       43284 :                                         0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect,
    2945             :                                         q_cldfb );
    2946             : 
    2947       43284 :             q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
    2948       43284 :             move16();
    2949             : 
    2950       43284 :             proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
    2951       43284 :             proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
    2952             :         }
    2953             :         ELSE
    2954             :         {
    2955      510498 :             SWITCH( nchan_transport )
    2956             :             {
    2957       55984 :                 case 11:
    2958             :                 case 8:
    2959             :                 case 6:
    2960             :                 case 4:
    2961       55984 :                     protoSignalComputation4_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    2962             :                                                 hDirACRend->proto_frame_f_fx,
    2963             :                                                 &hDirACRend->proto_frame_f_q,
    2964             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    2965             :                                                 &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    2966             :                                                 reference_power_fx,
    2967             :                                                 DirAC_mem.reference_power_q,
    2968             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
    2969       55984 :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
    2970       55984 :                                                 slot_idx, hDirACRend->num_outputs_diff,
    2971       55984 :                                                 hSpatParamRendCom->num_freq_bands,
    2972             :                                                 hDirACRend->hoa_decoder,
    2973             :                                                 nchan_transport,
    2974             :                                                 hDirACRend->sba_map_tc, q_cldfb );
    2975       55984 :                     proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    2976       55984 :                     proto_power_smooth_len = i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff );
    2977       55984 :                     BREAK;
    2978      296655 :                 case 2:
    2979      296655 :                     protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx,
    2980             :                                                 &hDirACRend->proto_frame_f_q,
    2981             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    2982             :                                                 &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    2983             :                                                 reference_power_fx,
    2984             :                                                 DirAC_mem.reference_power_q,
    2985             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
    2986      296655 :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
    2987      296655 :                                                 hDirACRend->hOutSetup.is_loudspeaker_setup,
    2988             :                                                 slot_idx,
    2989      296655 :                                                 hSpatParamRendCom->num_freq_bands,
    2990             :                                                 hDirACRend->masa_stereo_type_detect,
    2991             :                                                 q_cldfb );
    2992      296655 :                     proto_length = i_mult( 6, hSpatParamRendCom->num_freq_bands );
    2993      296655 :                     IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
    2994             :                     {
    2995      169137 :                         proto_power_smooth_len = i_mult( 3, hSpatParamRendCom->num_freq_bands );
    2996             :                     }
    2997             :                     ELSE
    2998             :                     {
    2999      127518 :                         proto_power_smooth_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
    3000             :                     }
    3001      296655 :                     BREAK;
    3002      157859 :                 case 1:
    3003      157859 :                     protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    3004             :                                                 hDirACRend->proto_frame_f_fx,
    3005             :                                                 &hDirACRend->proto_frame_f_q,
    3006             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
    3007             :                                                 &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
    3008             :                                                 reference_power_fx,
    3009             :                                                 DirAC_mem.reference_power_q,
    3010             :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
    3011      157859 :                                                 hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
    3012             :                                                 slot_idx,
    3013      157859 :                                                 hDirACRend->num_protos_diff,
    3014      157859 :                                                 hSpatParamRendCom->num_freq_bands, q_cldfb );
    3015      157859 :                     proto_length = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_diff ) );
    3016      157859 :                     proto_power_smooth_len = hSpatParamRendCom->num_freq_bands;
    3017      157859 :                     move16();
    3018      157859 :                     BREAK;
    3019           0 :                 default:
    3020           0 :                     return;
    3021             :             }
    3022      510498 :             q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
    3023      510498 :             move16();
    3024             :         }
    3025             : 
    3026             :         /*-----------------------------------------------------------------*
    3027             :          * Compute DirAC parameters at decoder side
    3028             :          *-----------------------------------------------------------------*/
    3029     1539021 :         IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) )
    3030             :         {
    3031      775083 :             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 ) );
    3032      775083 :             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 ) );
    3033             : 
    3034      775083 :             test();
    3035      775083 :             test();
    3036             : #ifdef IVAS_RTPDUMP
    3037      775083 :             test();
    3038      775083 :             IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation || st_ivas->hCombinedOrientationData ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
    3039             : #else
    3040             :             IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 )
    3041             : #endif
    3042             :             {
    3043      147200 :                 num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
    3044      147200 :                 move16();
    3045      147200 :                 rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx );
    3046             :             }
    3047             : 
    3048             :             /*hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1 */
    3049      775083 :             IF( hDirACRend->index_buffer_intensity == 0 )
    3050             :             {
    3051         263 :                 hDirACRend->index_buffer_intensity = 1;
    3052         263 :                 move16();
    3053             :             }
    3054             :             ELSE
    3055             :             {
    3056      774820 :                 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 */
    3057      774820 :                 move16();
    3058             :             }
    3059             : 
    3060      775083 :             index = hDirACRend->index_buffer_intensity;
    3061      775083 :             move16();
    3062      775083 :             num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band];
    3063      775083 :             move16();
    3064             : 
    3065      775083 :             computeIntensityVector_dec_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    3066             :                                            q_cldfb, num_freq_bands,
    3067      775083 :                                            hDirACRend->buffer_intensity_real_fx[0][index - 1],
    3068      775083 :                                            hDirACRend->buffer_intensity_real_fx[1][index - 1],
    3069      775083 :                                            hDirACRend->buffer_intensity_real_fx[2][index - 1],
    3070      775083 :                                            &hDirACRend->q_buffer_intensity_real[index - 1] );
    3071             : 
    3072      775083 :             computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][index - 1],
    3073      775083 :                                        hDirACRend->buffer_intensity_real_fx[1][index - 1],
    3074      775083 :                                        hDirACRend->buffer_intensity_real_fx[2][index - 1],
    3075      775083 :                                        hDirACRend->q_buffer_intensity_real[index - 1],
    3076             :                                        num_freq_bands, azimuth, elevation );
    3077             : 
    3078      775083 :             Copy32( reference_power_fx, &( hDirACRend->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands );
    3079      775083 :             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] ) );
    3080      775083 :             hDirACRend->q_buffer_energy[index - 1] = DirAC_mem.reference_power_q[0];
    3081      775083 :             move16();
    3082             : 
    3083      775083 :             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 );
    3084             :         }
    3085             : 
    3086             :         /*-----------------------------------------------------------------*
    3087             :          * frequency domain decorrelation
    3088             :          *-----------------------------------------------------------------*/
    3089             : 
    3090     1539021 :         IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) )
    3091             :         {
    3092             :             /* decorrelate prototype frame */
    3093     1439753 :             IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3094             :             {
    3095     2955717 :                 ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
    3096      985239 :                                                   hDirACRend->num_outputs_diff,
    3097      985239 :                                                   hDirACRend->num_protos_diff,
    3098             :                                                   hDirACRend->synthesisConf,
    3099             :                                                   nchan_transport,
    3100      985239 :                                                   &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 )],
    3101      985239 :                                                   hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
    3102      985239 :                                                   hDirACRend->num_protos_diff,
    3103      985239 :                                                   hDirACRend->proto_index_diff,
    3104      985239 :                                                   &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 ) )],
    3105             :                                                   &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
    3106             :                                                   onset_filter_fx,
    3107             :                                                   hDirACRend->h_freq_domain_decorr_ap_params,
    3108             :                                                   hDirACRend->h_freq_domain_decorr_ap_state );
    3109             : 
    3110      985239 :                 v_multc_fx( onset_filter_fx, 536870912 /* 0.25f in Q31 */, onset_filter_fx, hSpatParamRendCom->num_freq_bands );
    3111             : 
    3112      985239 :                 v_add_fx_no_hdrm( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */
    3113      985239 :                 p_onset_filter_fx = onset_filter_subframe_fx;
    3114             :             }
    3115             :             ELSE
    3116             :             {
    3117      454514 :                 scale = L_norm_arr( hDirACRend->proto_frame_f_fx, proto_length );
    3118      454514 :                 Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); // Q(proto_frame_f_q+scale)
    3119      454514 :                 hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, scale );
    3120      454514 :                 move16();
    3121      454514 :                 ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
    3122      454514 :                                                   hDirACRend->num_outputs_diff,
    3123      454514 :                                                   hDirACRend->num_protos_diff,
    3124             :                                                   hDirACRend->synthesisConf,
    3125             :                                                   nchan_transport,
    3126      454514 :                                                   hDirACRend->proto_frame_f_fx,
    3127      454514 :                                                   hDirACRend->proto_frame_f_q,
    3128      454514 :                                                   hDirACRend->num_protos_diff,
    3129      454514 :                                                   hDirACRend->proto_index_diff,
    3130             :                                                   DirAC_mem.frame_dec_f_fx,
    3131             :                                                   &DirAC_mem.frame_dec_f_q,
    3132             :                                                   onset_filter_fx,
    3133             :                                                   hDirACRend->h_freq_domain_decorr_ap_params,
    3134             :                                                   hDirACRend->h_freq_domain_decorr_ap_state );
    3135             : 
    3136      454514 :                 hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx;
    3137      454514 :                 hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q;
    3138      454514 :                 move16();
    3139      454514 :                 hDirACRend->proto_frame_dec_f_len = DirAC_mem.frame_dec_f_len;
    3140      454514 :                 move16();
    3141      454514 :                 p_onset_filter_fx = onset_filter_fx;
    3142             :             }
    3143             :         }
    3144             :         ELSE
    3145             :         {
    3146       99268 :             IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3147             :             {
    3148           0 :                 set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands );
    3149           0 :                 p_onset_filter_fx = onset_filter_subframe_fx;
    3150             :             }
    3151             :             ELSE
    3152             :             {
    3153             :                 /* no frequency domain decorrelation: use prototype frame */
    3154       99268 :                 hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx;
    3155       99268 :                 hDirACRend->proto_frame_dec_f_len = hDirACRend->proto_frame_f_len;
    3156       99268 :                 move16();
    3157       99268 :                 hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q;
    3158       99268 :                 move16();
    3159       99268 :                 p_onset_filter_fx = NULL;
    3160             :             }
    3161             :         }
    3162             : 
    3163             :         /*-----------------------------------------------------------------*
    3164             :          * output synthesis
    3165             :          *-----------------------------------------------------------------*/
    3166             : 
    3167     1539021 :         test();
    3168     1539021 :         IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) )
    3169             :         {
    3170             :             DIRAC_OUTPUT_SYNTHESIS_STATE *state;
    3171             :             Word16 diffuse_start;
    3172      510498 :             state = &( hDirACRend->h_output_synthesis_psd_state );
    3173      510498 :             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 ) );
    3174             : 
    3175      510498 :             exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len );
    3176      510498 :             scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); // hDirACRend->proto_frame_dec_f_q + exp
    3177      510498 :             hDirACRend->proto_frame_dec_f_q = add( hDirACRend->proto_frame_dec_f_q, exp );
    3178      510498 :             move16();
    3179      510498 :             exp = getScaleFactor32( state->proto_diffuse_buffer_f_fx, diffuse_start );
    3180      510498 :             scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); // state->proto_diffuse_buffer_f_q + exp
    3181      510498 :             state->proto_diffuse_buffer_f_q = add( state->proto_diffuse_buffer_f_q, exp );
    3182      510498 :             move16();
    3183             :             /*Compute diffuse prototypes*/
    3184      510498 :             ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx );
    3185             :         }
    3186             : 
    3187             :         /*Compute PSDs*/
    3188     1539021 :         h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
    3189     1539021 :         h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
    3190     1539021 :         num_channels_dir = hDirACRend->num_outputs_dir;
    3191     1539021 :         move16();
    3192             : 
    3193     1539021 :         if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) )
    3194             :         {
    3195      361524 :             num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE;
    3196      361524 :             move16();
    3197             :         }
    3198             : 
    3199     1539021 :         test();
    3200     1539021 :         test();
    3201     1539021 :         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 ) ) ) )
    3202             :         {
    3203      305540 :             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
    3204      305540 :             h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
    3205      305540 :             move16();
    3206             : 
    3207      305540 :             exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    3208      305540 :             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
    3209      305540 :             h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
    3210      305540 :             move16();
    3211             :         }
    3212             : 
    3213     1539021 :         test();
    3214     1539021 :         IF( ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) )
    3215             :         {
    3216       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
    3217       55984 :             h_dirac_output_synthesis_state->direct_power_factor_q = Q31;
    3218       55984 :             move16();
    3219             : 
    3220       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
    3221       55984 :             h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
    3222       55984 :             move16();
    3223             : 
    3224       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
    3225       55984 :             h_dirac_output_synthesis_state->direct_responses_q = Q31;
    3226       55984 :             move16();
    3227             : 
    3228       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
    3229       55984 :             h_dirac_output_synthesis_state->direct_responses_square_q = Q31;
    3230       55984 :             move16();
    3231             : 
    3232       55984 :             exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    3233       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
    3234       55984 :             h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp );
    3235       55984 :             move16();
    3236       55984 :             exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    3237       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
    3238       55984 :             h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, exp );
    3239       55984 :             move16();
    3240       55984 :             exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) );
    3241       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
    3242       55984 :             h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp );
    3243       55984 :             move16();
    3244             :         }
    3245             : 
    3246     1539021 :         ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fx,
    3247             :                                                          DirAC_mem.reference_power_q,
    3248             :                                                          p_onset_filter_fx,
    3249             :                                                          azimuth,
    3250             :                                                          elevation,
    3251     1539021 :                                                          hSpatParamRendCom->diffuseness_vector_fx[md_idx],
    3252     1539021 :                                                          hSpatParamRendCom->q_diffuseness_vector,
    3253             :                                                          hSpatParamRendCom,
    3254             :                                                          hDirACRend,
    3255             :                                                          st_ivas->hVBAPdata,
    3256             :                                                          hDirACRend->hOutSetup,
    3257             :                                                          nchan_transport,
    3258             :                                                          md_idx,
    3259             :                                                          hodirac_flag,
    3260     1539021 :                                                          hDirAC->hConfig->dec_param_estim );
    3261             : 
    3262             : 
    3263     1539021 :         IF( hDirAC->hConfig->dec_param_estim )
    3264             :         {
    3265             :             Word16 fac;
    3266      775083 :             fac = BASOP_Util_Divide3232_Scale( 1, hSpatParamRendCom->subframe_nbslots[subframe_idx], &exp );
    3267      775083 :             fac = shl_sat( fac, exp );
    3268             : 
    3269      775083 :             IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) )
    3270             :             {
    3271           0 :                 scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); // q_diffuseness_vector
    3272           0 :                 hSpatParamRendCom->q_diffuseness_vector = q_diffuseness_vector;
    3273           0 :                 move16();
    3274             :             }
    3275             :             ELSE
    3276             :             {
    3277      775083 :                 scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); // q_diffuseness_vector
    3278      775083 :                 q_diffuseness_vector = hSpatParamRendCom->q_diffuseness_vector;
    3279      775083 :                 move16();
    3280             :             }
    3281      775083 :             v_multc_acc_32_16( hSpatParamRendCom->diffuseness_vector_fx[md_idx], fac, diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands );
    3282             :         }
    3283             : 
    3284     1539021 :         IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3285             :         {
    3286      553782 :             v_add_fx_me( reference_power_fx, sub( 31, DirAC_mem.reference_power_q[0] ),
    3287      553782 :                          reference_power_smooth_fx, sub( 31, q_reference_power_smooth[0] ),
    3288             :                          reference_power_smooth_fx, &temp_q,
    3289      553782 :                          s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), 1 );
    3290      553782 :             q_reference_power_smooth[0] = sub( 31, temp_q );
    3291      553782 :             v_add_fx_me( reference_power_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, DirAC_mem.reference_power_q[1] ),
    3292      553782 :                          reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, sub( 31, q_reference_power_smooth[1] ),
    3293             :                          reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, &temp_q,
    3294      553782 :                          s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), 1 );
    3295      553782 :             q_reference_power_smooth[1] = sub( 31, temp_q );
    3296             :         }
    3297             :     }
    3298             : 
    3299      387828 :     minimum_s( q_proto_direct_buffer, add( hSpatParamRendCom->subframe_nbslots[subframe_idx], 1 ), &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q );
    3300      387828 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3301             :     {
    3302      247365 :         minimum_s( q_proto_diffuse_buffer, add( hSpatParamRendCom->subframe_nbslots[subframe_idx], 1 ), &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q );
    3303             :     }
    3304     1926849 :     FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3305             :     {
    3306     1539021 :         IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3307             :         {
    3308      985239 :             offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    3309      985239 :             buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
    3310      985239 :             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
    3311      985239 :             offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) );
    3312      985239 :             buff_len = i_mult( 2, i_mult( nchan_transport, hSpatParamRendCom->num_freq_bands ) );
    3313      985239 :             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
    3314             :         }
    3315      553782 :         ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
    3316             :         {
    3317       43284 :             offset = i_mult( slot_idx, i_mult( 4, hSpatParamRendCom->num_freq_bands ) );
    3318       43284 :             buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
    3319       43284 :             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
    3320             :         }
    3321             :         ELSE
    3322             :         {
    3323      510498 :             SWITCH( nchan_transport )
    3324             :             {
    3325       55984 :                 case 11:
    3326             :                 case 8:
    3327             :                 case 6:
    3328             :                 case 4:
    3329       55984 :                     offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    3330       55984 :                     buff_len = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    3331       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
    3332       55984 :                     BREAK;
    3333      296655 :                 case 2:
    3334      296655 :                     IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
    3335             :                     {
    3336      169137 :                         offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 3 );
    3337      169137 :                         buff_len = i_mult( 6, hSpatParamRendCom->num_freq_bands );
    3338             :                     }
    3339             :                     ELSE
    3340             :                     {
    3341      127518 :                         offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 2 );
    3342      127518 :                         buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands );
    3343             :                     }
    3344      296655 :                     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
    3345      296655 :                     BREAK;
    3346      157859 :                 case 1:
    3347      157859 :                     offset = i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) );
    3348      157859 :                     buff_len = i_mult( 2, hSpatParamRendCom->num_freq_bands );
    3349      157859 :                     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
    3350      157859 :                     BREAK;
    3351             :             }
    3352     1539021 :         }
    3353             :     }
    3354      387828 :     test();
    3355      387828 :     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 )
    3356             :     {
    3357        6146 :         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
    3358        6146 :         offset = i_mult( i_mult( sub( slot_idx, 1 ), 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) );
    3359        6146 :         buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) );
    3360        6146 :         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 )
    3361             :         {
    3362        2111 :             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
    3363             :         }
    3364             :     }
    3365      387828 :     ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    3366             : 
    3367      387828 :     size = i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands );
    3368      387828 :     IF( hodirac_flag )
    3369             :     {
    3370       54520 :         size_ho = i_mult( size, DIRAC_HO_NUMSECTORS );
    3371             :     }
    3372             :     ELSE
    3373             :     {
    3374      333308 :         size_ho = size;
    3375      333308 :         move16();
    3376             :     }
    3377             : 
    3378      387828 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    3379             :     {
    3380      247365 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, Q26 ) )
    3381             :         {
    3382      228769 :             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
    3383      228769 :             hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26;
    3384      228769 :             move16();
    3385             :         }
    3386      247365 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, Q26 ) )
    3387             :         {
    3388           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
    3389             :         }
    3390      247365 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
    3391             :         {
    3392       99818 :             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
    3393             :         }
    3394      247365 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
    3395             :         {
    3396       12019 :             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
    3397             :         }
    3398      247365 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
    3399             :         {
    3400       96773 :             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
    3401             :         }
    3402      247365 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, Q26 ) )
    3403             :         {
    3404           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
    3405             :         }
    3406      247365 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, Q26 ) )
    3407             :         {
    3408           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
    3409             :         }
    3410      247365 :         IF( NE_16( q_diffuseness_vector, Q30 ) )
    3411             :         {
    3412           0 :             scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); // Q30
    3413             :         }
    3414      247365 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
    3415             :         {
    3416           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
    3417             :         }
    3418      247365 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
    3419             :         {
    3420         857 :             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
    3421             :         }
    3422             : 
    3423      247365 :         ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx,
    3424             :                                                                       Cldfb_ImagBuffer_fx,
    3425             :                                                                       hSpatParamRendCom,
    3426             :                                                                       hDirACRend,
    3427             :                                                                       nchan_transport,
    3428      247365 :                                                                       hSpatParamRendCom->subframe_nbslots[subframe_idx],
    3429             :                                                                       p_onset_filter_fx,
    3430             :                                                                       diffuseness_vector_fx,
    3431             :                                                                       hodirac_flag,
    3432      247365 :                                                                       hDirAC->hConfig->dec_param_estim,
    3433             :                                                                       &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev,
    3434             :                                                                       &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev );
    3435             : 
    3436      247365 :         test();
    3437      247365 :         IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL )
    3438             :         {
    3439      495200 :             FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
    3440             :             {
    3441     2240000 :                 FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3442             :                 {
    3443     1792000 :                     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
    3444     1792000 :                     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
    3445             :                 }
    3446             :             }
    3447             :         }
    3448             :         ELSE
    3449             :         {
    3450     3158157 :             FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ )
    3451             :             {
    3452    14722616 :                 FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3453             :                 {
    3454    11764624 :                     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
    3455    11764624 :                     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
    3456             :                 }
    3457             :             }
    3458             :         }
    3459             :     }
    3460             :     ELSE
    3461             :     {
    3462             :         /* Determine encoding quality based additional smoothing factor */
    3463      140463 :         Word32 qualityBasedSmFactor_fx = ONE_IN_Q31;
    3464      140463 :         move32();
    3465      140463 :         Word16 q_Cldfb = 0;
    3466      140463 :         move16();
    3467             : 
    3468      140463 :         IF( st_ivas->hMasa != NULL )
    3469             :         {
    3470      126467 :             qualityBasedSmFactor_fx = L_mult( st_ivas->hMasa->data.dir_decode_quality_fx, st_ivas->hMasa->data.dir_decode_quality_fx ); /* (Q15, Q15) -> Q31 */
    3471             :         }
    3472             : 
    3473      140463 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) )
    3474             :         {
    3475      126467 :             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
    3476             :         }
    3477      140463 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) )
    3478             :         {
    3479      126467 :             Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31
    3480             :         }
    3481      140463 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) )
    3482             :         {
    3483       48939 :             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
    3484             :         }
    3485      140463 :         IF( NE_16( q_diffuseness_vector, Q31 ) )
    3486             :         {
    3487      140463 :             Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); // Q31
    3488             :         }
    3489      140463 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, Q31 ) )
    3490             :         {
    3491      126467 :             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
    3492             :         }
    3493             : 
    3494      140463 :         exp = L_norm_arr( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) );
    3495      140463 :         scale_sig32( reference_power_smooth_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), exp ); // q_reference_power_smooth[0] + exp
    3496      140463 :         q_reference_power_smooth[0] = add( q_reference_power_smooth[0], exp );
    3497      140463 :         IF( LT_16( q_reference_power_smooth[0], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] ) )
    3498             :         {
    3499        6267 :             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]
    3500        6267 :             hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] = q_reference_power_smooth[0];
    3501        6267 :             move16();
    3502             :         }
    3503             :         ELSE
    3504             :         {
    3505             :             Word32 temp;
    3506     4113296 :             FOR( i = 0; i < s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ); i++ )
    3507             :             {
    3508     3979100 :                 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] ) );
    3509     3979100 :                 reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
    3510     3979100 :                 move32();
    3511             :             }
    3512      134196 :             q_reference_power_smooth[0] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0];
    3513      134196 :             move16();
    3514             :         }
    3515             : 
    3516      140463 :         exp = L_norm_arr( reference_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
    3517      140463 :         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
    3518      140463 :         q_reference_power_smooth[1] = add( q_reference_power_smooth[1], exp );
    3519      140463 :         IF( LT_16( q_reference_power_smooth[1], hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] ) )
    3520             :         {
    3521        5756 :             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
    3522        5756 :             hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] = q_reference_power_smooth[1];
    3523        5756 :             move16();
    3524             :         }
    3525             :         ELSE
    3526             :         {
    3527             :             Word32 temp;
    3528     3863457 :             FOR( i = CLDFB_NO_CHANNELS_HALF; i < hSpatParamRendCom->num_freq_bands; i++ )
    3529             :             {
    3530     3728750 :                 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] ) );
    3531     3728750 :                 reference_power_smooth_fx[i] = L_max( temp, L_min( reference_power_smooth_fx[i], 1 ) );
    3532     3728750 :                 move32();
    3533             :             }
    3534      134707 :             q_reference_power_smooth[1] = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1];
    3535      134707 :             move16();
    3536             :         }
    3537             : 
    3538      140463 :         IF( hDirACRend->masa_stereo_type_detect != NULL )
    3539             :         {
    3540       23517 :             IF( LT_16( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) )
    3541             :             {
    3542       23092 :                 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
    3543       23092 :                 move32();
    3544       23092 :                 hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = hDirACRend->masa_stereo_type_detect->q_subtract_power_y;
    3545       23092 :                 move16();
    3546             :             }
    3547             :             ELSE
    3548             :             {
    3549         425 :                 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
    3550         425 :                 move32();
    3551         425 :                 hDirACRend->masa_stereo_type_detect->q_subtract_power_y = hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth;
    3552         425 :                 move16();
    3553             :             }
    3554             :         }
    3555             : 
    3556      140463 :         exp = 31;
    3557      140463 :         move16();
    3558      530713 :         FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3559             :         {
    3560      390250 :             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 ) ) );
    3561             :         }
    3562      530713 :         FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3563             :         {
    3564      390250 :             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)
    3565             :         }
    3566      140463 :         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], exp );
    3567      140463 :         move16();
    3568      140463 :         exp = 31;
    3569      140463 :         move16();
    3570      530713 :         FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3571             :         {
    3572      390250 :             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 ) ) ) );
    3573             :         }
    3574      530713 :         FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3575             :         {
    3576      390250 :             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)
    3577             :         }
    3578      140463 :         hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], exp );
    3579      140463 :         move16();
    3580             : 
    3581      140463 :         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] ) )
    3582             :         {
    3583      182578 :             FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3584             :             {
    3585      133455 :                 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
    3586             :             }
    3587       49123 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0];
    3588       49123 :             move16();
    3589             :         }
    3590             :         ELSE
    3591             :         {
    3592      348135 :             FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3593             :             {
    3594      256795 :                 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
    3595             :             }
    3596       91340 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0];
    3597       91340 :             move16();
    3598             :         }
    3599      140463 :         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] ) )
    3600             :         {
    3601      223411 :             FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3602             :             {
    3603      164358 :                 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
    3604             :             }
    3605       59053 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1];
    3606       59053 :             move16();
    3607             :         }
    3608             :         ELSE
    3609             :         {
    3610      307302 :             FOR( i = 0; proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
    3611             :             {
    3612      225892 :                 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
    3613             :             }
    3614       81410 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1];
    3615       81410 :             move16();
    3616             :         }
    3617             : 
    3618      140463 :         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 ) );
    3619      140463 :         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)
    3620      140463 :         hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, exp );
    3621      140463 :         move16();
    3622      140463 :         IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 )
    3623             :         {
    3624      115646 :             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 ) )
    3625             :             {
    3626       46202 :                 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
    3627       46202 :                 hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q;
    3628       46202 :                 move16();
    3629             :             }
    3630             :             ELSE
    3631             :             {
    3632       69444 :                 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
    3633       69444 :                 hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q;
    3634       69444 :                 move16();
    3635             :             }
    3636             :         }
    3637             : 
    3638      140463 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) )
    3639             :         {
    3640           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
    3641             :         }
    3642      140463 :         IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) )
    3643             :         {
    3644           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
    3645             :         }
    3646      140463 :         IF( hDirACRend->proto_signal_decorr_on )
    3647             :         {
    3648      115646 :             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
    3649      115646 :             hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
    3650      115646 :             move16();
    3651             :         }
    3652             : 
    3653      140463 :         ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx,
    3654             :                                                                     Cldfb_ImagBuffer_fx,
    3655             :                                                                     hSpatParamRendCom,
    3656             :                                                                     hDirACRend,
    3657      140463 :                                                                     hSpatParamRendCom->subframe_nbslots[subframe_idx],
    3658             :                                                                     diffuseness_vector_fx,
    3659             :                                                                     reference_power_smooth_fx,
    3660             :                                                                     q_reference_power_smooth,
    3661             :                                                                     qualityBasedSmFactor_fx,
    3662      140463 :                                                                     hDirAC->hConfig->enc_param_start_band,
    3663             :                                                                     &q_Cldfb );
    3664             : 
    3665      140463 :         Word16 allZero = 1;
    3666      140463 :         move16();
    3667    22894723 :         FOR( i = 0; i < proto_power_smooth_len; i++ )
    3668             :         {
    3669    22754260 :             if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx[i] != 0 )
    3670             :             {
    3671           0 :                 allZero = 0;
    3672           0 :                 move16();
    3673             :             }
    3674             :         }
    3675      140463 :         if ( allZero )
    3676             :         {
    3677      140463 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = 31;
    3678      140463 :             move16();
    3679             :         }
    3680      140463 :         if ( allZero )
    3681             :         {
    3682      140463 :             hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = 31;
    3683      140463 :             move16();
    3684             :         }
    3685             : 
    3686     1105046 :         FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
    3687             :         {
    3688     4776951 :             FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3689             :             {
    3690     3812368 :                 scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
    3691     3812368 :                 scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6
    3692             :             }
    3693             :         }
    3694             :     }
    3695             : 
    3696             :     /*-----------------------------------------------------------------*
    3697             :      * CLDFB synthesis (and binaural rendering)
    3698             :      *-----------------------------------------------------------------*/
    3699             : 
    3700      387828 :     index_slot = slot_idx_start_cldfb_synth;
    3701      387828 :     move16();
    3702             : 
    3703      387828 :     test();
    3704      387828 :     test();
    3705      387828 :     IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
    3706             :     {
    3707             :         /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */
    3708      127607 :         test();
    3709      127607 :         test();
    3710      127607 :         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 ) ) )
    3711             :         {
    3712             :             Word16 j, k, l;
    3713             :             Word16 num_objects, nchan_out_woLFE;
    3714             :             Word16 n_slots_to_render;
    3715             :             Word16 n_samples_to_render;
    3716             :             Word32 gain_fx, prev_gain_fx;
    3717             : 
    3718       16000 :             num_objects = st_ivas->nchan_ism;
    3719       16000 :             move16();
    3720       16000 :             nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
    3721       16000 :             move16();
    3722       16000 :             n_slots_to_render = st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->subframes_rendered];
    3723       16000 :             move16();
    3724       16000 :             n_samples_to_render = imult1616( hSpatParamRendCom->num_freq_bands, n_slots_to_render );
    3725             : 
    3726       16000 :             test();
    3727       16000 :             IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] )
    3728             :             {
    3729           0 :                 ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx );
    3730           0 :                 st_ivas->hIsmRendererData->interp_offset_fx = 0;
    3731           0 :                 move16();
    3732             :             }
    3733             : 
    3734       76000 :             FOR( i = 0; i < num_objects; i++ )
    3735             :             {
    3736             :                 /* Combined rotation: rotate the object positions depending the head and external orientations */
    3737       60000 :                 test();
    3738       60000 :                 IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
    3739             :                 {
    3740           0 :                     Word16 az_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ) );
    3741           0 :                     Word16 el_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, Q22 ) );
    3742             :                     Word32 az1_32, el1_32;
    3743             : 
    3744           0 :                     rotateAziEle_fx32( az_q0, el_q0, &az1_32, &el1_32, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup );
    3745             : 
    3746           0 :                     IF( st_ivas->hEFAPdata != NULL )
    3747             :                     {
    3748           0 :                         const Word32 azi_fx = L_shl( az1_32, Q22 - Q16 ); // Q16 -> Q22
    3749           0 :                         const Word32 ele_fx = L_shl( el1_32, Q22 - Q16 ); // Q16 -> Q22
    3750           0 :                         efap_determine_gains_fx( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains_fx[i], azi_fx, ele_fx, EFAP_MODE_EFAP );
    3751             :                         // TODO: Align Q-values
    3752           0 :                         IF( NE_32( st_ivas->hIsmMetaData[i]->edited_gain_fx, ONE_IN_Q29 ) )
    3753             :                         {
    3754           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
    3755           0 :                             Scale_sig32( st_ivas->hIsmRendererData->gains_fx[i], nchan_out_woLFE, Q2 );                                                                              // Q28 --> Q30
    3756             :                         }
    3757             :                     }
    3758             :                 }
    3759             : 
    3760      720000 :                 FOR( j = 0; j < nchan_out_woLFE; j++ )
    3761             :                 {
    3762      660000 :                     gain_fx = st_ivas->hIsmRendererData->gains_fx[i][j];
    3763      660000 :                     move32();
    3764      660000 :                     prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j];
    3765      660000 :                     move32();
    3766      660000 :                     test();
    3767      660000 :                     IF( ( L_abs( gain_fx ) > 0 || L_abs( prev_gain_fx ) > 0 ) )
    3768             :                     {
    3769             :                         Word32 *tc_re_fx, *tc_im_fx;
    3770             :                         Word16 *w1_fx, w2_fx;
    3771             : 
    3772      342740 :                         w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[st_ivas->hIsmRendererData->interp_offset_fx];
    3773      342740 :                         tc_re_fx = pppQMfFrame_ts_re_fx[nchan_transport + i][0];
    3774      342740 :                         move32();
    3775      342740 :                         tc_im_fx = pppQMfFrame_ts_im_fx[nchan_transport + i][0];
    3776      342740 :                         move32();
    3777     1713700 :                         FOR( k = 0; k < n_slots_to_render; k++ )
    3778             :                         {
    3779             :                             Word32 g_fx;
    3780     1370960 :                             w2_fx = sub( MAX16B, *w1_fx );
    3781     1370960 :                             g_fx = Madd_32_16( Mpy_32_16_1( gain_fx, *w1_fx ), prev_gain_fx, w2_fx ); // Q15
    3782    76314320 :                             FOR( l = 0; l < hSpatParamRendCom->num_freq_bands; l++ )
    3783             :                             {
    3784    74943360 :                                 Cldfb_RealBuffer_fx[j][k][l] = Madd_32_32( Cldfb_RealBuffer_fx[j][k][l], g_fx, L_shl( *tc_re_fx, 1 ) );
    3785    74943360 :                                 move32();
    3786    74943360 :                                 tc_re_fx++;
    3787    74943360 :                                 Cldfb_ImagBuffer_fx[j][k][l] = Madd_32_32( Cldfb_ImagBuffer_fx[j][k][l], g_fx, L_shl( *tc_im_fx, 1 ) );
    3788    74943360 :                                 move32();
    3789    74943360 :                                 tc_im_fx++;
    3790             :                             }
    3791     1370960 :                             w1_fx += hSpatParamRendCom->num_freq_bands;
    3792             :                         }
    3793             :                     }
    3794             :                     /* update here only in case of head rotation */
    3795      660000 :                     test();
    3796      660000 :                     IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) )
    3797             :                     {
    3798           0 :                         st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx;
    3799           0 :                         move32();
    3800             :                     }
    3801             :                 }
    3802             :             }
    3803       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] ) );
    3804             :         }
    3805             : 
    3806             :         /* Perform binaural rendering, output in Q6 format */
    3807      127607 :         test();
    3808      127607 :         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 ) )
    3809             :         {
    3810           0 :             IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
    3811             :             {
    3812           0 :                 FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3813             :                 {
    3814           0 :                     FOR( ch = 0; ch < st_ivas->hBinRenderer->nInChannels; ch++ )
    3815             :                     {
    3816           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 );
    3817           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 );
    3818             :                     }
    3819             :                 }
    3820           0 :                 st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
    3821           0 :                 move16();
    3822             :             }
    3823             : 
    3824           0 :             binRenderer_split_fx( st_ivas->hBinRenderer, st_ivas->hSplitBinRend, st_ivas->hCombinedOrientationData, hSpatParamRendCom->subframe_nbslots[subframe_idx],
    3825             :                                   Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
    3826             : #ifndef FIX_1119_SPLIT_RENDERING_VOIP
    3827             :                                   slot_idx_start,
    3828             : #endif
    3829           0 :                                   hSpatParamRendCom->num_freq_bands, st_ivas->hDecoderConfig->nchan_out );
    3830             :         }
    3831             :         ELSE
    3832             :         {
    3833      127607 :             binRenderer_fx( st_ivas->hBinRenderer, st_ivas->hCombinedOrientationData, hSpatParamRendCom->subframe_nbslots[subframe_idx],
    3834             :                             Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx );
    3835             :         }
    3836             : 
    3837             :         /* Inverse CLDFB*/
    3838      382821 :         FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
    3839             :         {
    3840             :             /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
    3841      255214 :             Word32 *synth_fx = &output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands];
    3842             :             Word32 *RealBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
    3843             :             Word32 *ImagBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
    3844     1275110 :             FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    3845             :             {
    3846     1019896 :                 RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[0][ch][i];
    3847     1019896 :                 move32();
    3848     1019896 :                 ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[0][ch][i];
    3849     1019896 :                 move32();
    3850             :             }
    3851             : 
    3852      255214 :             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
    3853      255214 :             st_ivas->cldfbSynDec[ch]->Q_cldfb_state = ( Q6 - 1 );
    3854      255214 :             move16();
    3855             : 
    3856      255214 :             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] );
    3857             : 
    3858      255214 :             Word16 no_col = st_ivas->cldfbSynDec[ch]->no_col;
    3859      255214 :             move16();
    3860      255214 :             Word16 no_channels = st_ivas->cldfbSynDec[ch]->no_channels;
    3861      255214 :             move16();
    3862      255214 :             Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    3863      255214 :             move16();
    3864      255214 :             IF( GT_16( samplesToProcess, -1 ) )
    3865             :             {
    3866             :                 Word16 tmp, tmp_e;
    3867      255214 :                 tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ), st_ivas->cldfbSynDec[ch]->no_channels, &tmp_e );
    3868      255214 :                 tmp = shr( tmp, 15 - tmp_e );
    3869      255214 :                 no_col = s_min( no_col, tmp );
    3870             :             }
    3871      255214 :             Word16 synth_len = imult1616( no_col, no_channels );
    3872             : 
    3873      255214 :             scale_sig32( synth_fx, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
    3874             :         }
    3875             :     }
    3876      260221 :     ELSE IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
    3877             :     {
    3878     1603959 :         FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
    3879             :         {
    3880     7351520 :             FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    3881             :             {
    3882     5869296 :                 Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], pppQMfFrame_ts_re_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
    3883     5869296 :                 Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], pppQMfFrame_ts_im_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); // Q6
    3884             :             }
    3885             :         }
    3886             :     }
    3887             :     ELSE
    3888             :     {
    3889             :         Word32 *RealBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
    3890             :         Word32 *ImagBuffer_fx[CLDFB_SLOTS_PER_SUBFRAME];
    3891             :         Word16 outchannels;
    3892             : 
    3893      138486 :         idx_in = 0;
    3894      138486 :         move16();
    3895      138486 :         idx_lfe = 0;
    3896      138486 :         move16();
    3897             : 
    3898      138486 :         outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
    3899             : 
    3900      138486 :         test();
    3901      138486 :         test();
    3902      138486 :         test();
    3903      138486 :         test();
    3904      138486 :         test();
    3905      138486 :         test();
    3906      138486 :         test();
    3907      138486 :         IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
    3908             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
    3909             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
    3910             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
    3911             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
    3912             :                                                               ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
    3913             :         {
    3914         876 :             outchannels = add( outchannels, 1 );
    3915             :         }
    3916             : 
    3917      138486 :         test();
    3918      138486 :         IF( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
    3919           0 :         {
    3920             :             Word32 tmp_separated_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    3921             :             Word32 tmp_lfe_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    3922           0 :             const Word16 subframe_start_sample = imult1616( index_slot, hSpatParamRendCom->num_freq_bands );
    3923           0 :             const Word16 num_samples_subframe = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    3924             : 
    3925             :             /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */
    3926           0 :             Copy32( &( output_buf_fx[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated_fx, num_samples_subframe );
    3927           0 :             if ( hDirACRend->hOutSetup.num_lfe > 0 )
    3928             :             {
    3929           0 :                 Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe );
    3930             :             }
    3931             : 
    3932           0 :             FOR( ch = 0; ch < outchannels; ch++ )
    3933             :             {
    3934             : 
    3935           0 :                 test();
    3936           0 :                 test();
    3937           0 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    3938             :                 {
    3939             :                     /* Move the LFE channel to the correct place */
    3940           0 :                     Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
    3941             : 
    3942           0 :                     IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    3943             :                     {
    3944           0 :                         idx_lfe = add( idx_lfe, 1 );
    3945             :                     }
    3946             :                 }
    3947           0 :                 ELSE IF( ( st_ivas->hLsSetupCustom->separate_ch_found ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
    3948             :                 {
    3949             :                     /*  Move the separated channel to the correct place. Thus, the separated channel is
    3950             :                      *  combined with the synthesized channels here when there is a matching channel. */
    3951           0 :                     Copy32( tmp_separated_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe );
    3952             :                 }
    3953             :                 ELSE
    3954             :                 {
    3955             :                     /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
    3956           0 :                     FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    3957             :                     {
    3958           0 :                         RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i];
    3959           0 :                         move32();
    3960           0 :                         ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i];
    3961           0 :                         move32();
    3962             :                     }
    3963           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] );
    3964             : 
    3965           0 :                     IF( !st_ivas->hLsSetupCustom->separate_ch_found )
    3966             :                     {
    3967             :                         /* Pan the separated channel and mix with the synthesized channels. Thus, the separated channel
    3968             :                          * is combined with the synthesized channels here when there is no matching channel. */
    3969           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 );
    3970             :                     }
    3971             : 
    3972           0 :                     idx_in = add( idx_in, 1 );
    3973             :                 }
    3974             :             }
    3975             :         }
    3976             :         ELSE
    3977             :         {
    3978     1143529 :             FOR( ch = 0; ch < outchannels; ch++ )
    3979             :             {
    3980     1005043 :                 test();
    3981     1005043 :                 test();
    3982     1005043 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    3983             :                 {
    3984       77528 :                     test();
    3985       77528 :                     test();
    3986       77528 :                     IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
    3987        6640 :                     {
    3988       33200 :                         FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    3989             :                         {
    3990       26560 :                             RealBuffer_fx[i] = Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i];
    3991       26560 :                             move32();
    3992       26560 :                             ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i];
    3993       26560 :                             move32();
    3994             :                         }
    3995        6640 :                         Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
    3996        6640 :                         Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    3997        6640 :                         Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] );
    3998             : 
    3999        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
    4000        6640 :                         st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = ( Q6 - 1 );
    4001        6640 :                         move16();
    4002        6640 :                         cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[cldfbSynIdx] );
    4003             : 
    4004             :                         // Calculating length of output
    4005        6640 :                         Word16 no_col = st_ivas->cldfbSynDec[cldfbSynIdx]->no_col;
    4006        6640 :                         move16();
    4007        6640 :                         Word16 no_channels = st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels;
    4008        6640 :                         move16();
    4009        6640 :                         IF( GT_16( samplesToProcess, -1 ) )
    4010             :                         {
    4011             :                             Word16 tmp, tmp_e;
    4012        6640 :                             tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ), st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, &tmp_e );
    4013        6640 :                             tmp = shr( tmp, 15 - tmp_e );
    4014        6640 :                             no_col = s_min( no_col, tmp );
    4015             :                         }
    4016        6640 :                         Word16 synth_len = imult1616( no_col, no_channels );
    4017             : 
    4018        6640 :                         scale_sig32( p_out, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11
    4019             :                     }
    4020       70888 :                     ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && hDirACRend->hOutSetup.separateChannelEnabled )
    4021             :                     {
    4022             :                         /* LFE has been synthesized in the time domain, do nothing. */
    4023             :                     }
    4024             :                     ELSE
    4025             :                     {
    4026       70012 :                         set32_fx( &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) );
    4027             :                     }
    4028       77528 :                     IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    4029             :                     {
    4030           0 :                         idx_lfe = add( idx_lfe, 1 );
    4031             :                     }
    4032             :                 }
    4033      927515 :                 ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
    4034             :                 {
    4035             :                     /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated
    4036             :                      * channel is combined with the synthesized channels here. */
    4037             :                 }
    4038             :                 ELSE
    4039             :                 {
    4040             :                     /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
    4041      926639 :                     Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] );
    4042             :                     Word16 samplesToProcess, out_len;
    4043     4587167 :                     FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    4044             :                     {
    4045     3660528 :                         RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; // Q6
    4046     3660528 :                         move32();
    4047     3660528 :                         ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; // Q6
    4048     3660528 :                         move32();
    4049             :                     }
    4050      926639 :                     samplesToProcess = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    4051             : 
    4052             :                     // Calculating length of processed output
    4053      926639 :                     Word16 no_col = st_ivas->cldfbSynDec[idx_in]->no_col;
    4054      926639 :                     move16();
    4055      926639 :                     Word16 no_channels = st_ivas->cldfbSynDec[idx_in]->no_channels;
    4056      926639 :                     move16();
    4057      926639 :                     IF( GT_16( samplesToProcess, -1 ) )
    4058             :                     {
    4059             :                         Word16 tmp, tmp_e;
    4060      926639 :                         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 );
    4061      926639 :                         tmp = shr( tmp, 15 - tmp_e );
    4062      926639 :                         no_col = s_min( no_col, tmp );
    4063             :                     }
    4064      926639 :                     out_len = imult1616( no_col, no_channels );
    4065             : 
    4066             :                     // Scaling cldfb_state to Q6-1
    4067      926639 :                     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 ) );
    4068      926639 :                     st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = ( Q6 - 1 );
    4069      926639 :                     move16();
    4070      926639 :                     cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, 0, 0, st_ivas->cldfbSynDec[idx_in] );
    4071             : 
    4072             :                     // Scaling output from Q6-1 to Q11
    4073      926639 :                     Scale_sig32( p_out, out_len, ( Q11 - ( Q6 - 1 ) ) );
    4074             : 
    4075      926639 :                     idx_in = add( idx_in, 1 );
    4076             :                 }
    4077             :             }
    4078             :         }
    4079             :     }
    4080             : 
    4081      387828 :     hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
    4082      387828 :     move16();
    4083      387828 :     hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 );
    4084      387828 :     move16();
    4085             : 
    4086      387828 :     IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
    4087             :     {
    4088      247365 :         hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev;
    4089      247365 :         move16();
    4090      247365 :         hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev;
    4091      247365 :         move16();
    4092             :     }
    4093             : 
    4094      387828 :     test();
    4095      387828 :     test();
    4096      387828 :     IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
    4097             :     {
    4098      382821 :         FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ )
    4099             :         {
    4100      255214 :             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
    4101      255214 :             st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11;
    4102      255214 :             move16();
    4103             :         }
    4104             :     }
    4105      260221 :     ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    4106             :     {
    4107             :     }
    4108             :     ELSE
    4109             :     {
    4110             :         Word16 outchannels;
    4111      138486 :         idx_lfe = 0;
    4112      138486 :         move16();
    4113      138486 :         idx_in = 0;
    4114      138486 :         move16();
    4115      138486 :         outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
    4116             : 
    4117      138486 :         test();
    4118      138486 :         test();
    4119      138486 :         test();
    4120      138486 :         test();
    4121      138486 :         test();
    4122      138486 :         test();
    4123      138486 :         test();
    4124      138486 :         IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) ||
    4125             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
    4126             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) ||
    4127             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ||
    4128             :                                                               EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
    4129             :                                                               ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) )
    4130             :         {
    4131         876 :             outchannels = add( outchannels, 1 );
    4132             :         }
    4133             : 
    4134      138486 :         test();
    4135      138486 :         IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) )
    4136             :         {
    4137           0 :             FOR( ch = 0; ch < outchannels; ch++ )
    4138             :             {
    4139           0 :                 test();
    4140           0 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    4141             :                 {
    4142           0 :                     IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    4143             :                     {
    4144           0 :                         idx_lfe = add( idx_lfe, 1 );
    4145             :                     }
    4146             :                 }
    4147             :             }
    4148             :         }
    4149             :         ELSE
    4150             :         {
    4151     1143529 :             FOR( ch = 0; ch < outchannels; ch++ )
    4152             :             {
    4153             : 
    4154     1005043 :                 test();
    4155     1005043 :                 test();
    4156     1005043 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) )
    4157             :                 {
    4158       77528 :                     test();
    4159       77528 :                     IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled )
    4160             :                     {
    4161        6640 :                         Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe );
    4162        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
    4163        6640 :                         st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11;
    4164        6640 :                         move16();
    4165             :                     }
    4166             :                 }
    4167      927515 :                 ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) )
    4168             :                 {
    4169      926639 :                     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
    4170      926639 :                     st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11;
    4171      926639 :                     move16();
    4172      926639 :                     idx_in = add( idx_in, 1 );
    4173             :                 }
    4174             :             }
    4175             :         }
    4176      138486 :         test();
    4177      138486 :         IF( !hDirACRend->hOutSetup.separateChannelEnabled || NE_32( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
    4178             :         {
    4179      138486 :             Word16 tmp_lfe_idx = 0;
    4180      138486 :             move16();
    4181     1143529 :             FOR( ch = 0; ch < outchannels; ch++ )
    4182             :             {
    4183     1005043 :                 test();
    4184     1005043 :                 IF( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[tmp_lfe_idx], ch ) ) )
    4185             :                 {
    4186       77528 :                     IF( LT_16( tmp_lfe_idx, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
    4187             :                     {
    4188           0 :                         tmp_lfe_idx = add( tmp_lfe_idx, 1 );
    4189             :                     }
    4190             :                 }
    4191             :             }
    4192             :         }
    4193             :     }
    4194             : 
    4195      387828 :     pop_wmops();
    4196             : 
    4197      387828 :     return;
    4198             : }

Generated by: LCOV version 1.14