LCOV - code coverage report
Current view: top level - lib_dec - ivas_sba_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 22b74eaeaa63d28e0fcc8ed21c8f7c451f461847 Lines: 369 403 91.6 %
Date: 2025-10-20 02:12:39 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <assert.h>
      34             : #include <stdint.h>
      35             : #include "options.h"
      36             : #include "cnst.h"
      37             : #include "ivas_cnst.h"
      38             : #include "prot_fx.h"
      39             : #include "ivas_prot_rend_fx.h"
      40             : #include "rom_com.h"
      41             : #include "ivas_rom_com.h"
      42             : #include "ivas_rom_dec.h"
      43             : #include <math.h>
      44             : #include "wmc_auto.h"
      45             : #include "ivas_prot_fx.h"
      46             : /*-------------------------------------------------------------------*
      47             :  * ivas_sba_set_cna_cng_flag()
      48             :  *
      49             :  * Set CNA/CNG flags in IVAS SBA decoder
      50             :  *-------------------------------------------------------------------*/
      51        2356 : void ivas_sba_set_cna_cng_flag(
      52             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
      53             : )
      54             : {
      55             :     Word16 n, cpe_id;
      56        2356 :     test();
      57        2356 :     test();
      58        2356 :     test();
      59        2356 :     test();
      60        2356 :     test();
      61        2356 :     test();
      62        2356 :     test();
      63        2356 :     IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( st_ivas->nchan_transport, 1 ) )
      64             :     {
      65             :         /* skip as done in init function */
      66             :         /* st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 0; */
      67             :         /* st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 0; */
      68             :     }
      69        1885 :     ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && EQ_16( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) || ( 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 ) ) ) )
      70             :     {
      71         158 :         st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1;
      72         158 :         move16();
      73         158 :         st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1;
      74         158 :         move16();
      75             :     }
      76        1727 :     ELSE IF( EQ_16( st_ivas->nchan_transport, 2 ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
      77             :     {
      78        2163 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
      79             :         {
      80        1442 :             st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0;
      81        1442 :             move16();
      82        1442 :             st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1;
      83        1442 :             move16();
      84             :         }
      85             :     }
      86             :     ELSE
      87             :     {
      88        3143 :         FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
      89             :         {
      90        6411 :             FOR( n = 0; n < CPE_CHANNELS; n++ )
      91             :             {
      92        4274 :                 st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0;
      93        4274 :                 move16();
      94        4274 :                 st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0;
      95        4274 :                 move16();
      96             :             }
      97             :         }
      98             :     }
      99             : 
     100        2356 :     return;
     101             : }
     102             : 
     103             : /*-------------------------------------------------------------------*
     104             :  * ivas_sba_dec_reconfigure_fx()
     105             :  *
     106             :  * Reconfigure IVAS SBA decoder
     107             :  *-------------------------------------------------------------------*/
     108             : 
     109        1582 : ivas_error ivas_sba_dec_reconfigure_fx(
     110             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure              */
     111             : )
     112             : {
     113             :     Word16 nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old;
     114             :     AUDIO_CONFIG intern_config_old;
     115             :     Word16 numCldfbAnalyses_old, numCldfbSyntheses_old;
     116             :     Word16 sba_dirac_stereo_flag_old;
     117             :     Word32 ivas_total_brate;
     118             :     Word32 last_ivas_total_brate;
     119             :     Word16 num_channels, num_md_sub_frames;
     120             :     Word16 nchan_out_buff, nchan_out_buff_old;
     121             :     Word16 sba_analysis_order_old_flush;
     122             :     DECODER_CONFIG_HANDLE hDecoderConfig;
     123             :     ivas_error error;
     124             :     ISM_MODE ism_mode_old;
     125             :     Word16 granularity_new;
     126             :     Word16 nchan_transport;
     127             : 
     128        1582 :     ism_mode_old = st_ivas->ism_mode;
     129        1582 :     hDecoderConfig = st_ivas->hDecoderConfig;
     130        1582 :     ivas_total_brate = hDecoderConfig->ivas_total_brate;
     131        1582 :     move32();
     132        1582 :     last_ivas_total_brate = st_ivas->last_active_ivas_total_brate;
     133        1582 :     move32();
     134        1582 :     sba_analysis_order_old_flush = st_ivas->sba_analysis_order;
     135        1582 :     move16();
     136             : 
     137             :     /*-----------------------------------------------------------------*
     138             :      * Set SBA high-level parameters
     139             :      * Save old SBA high-level parameters
     140             :      *-----------------------------------------------------------------*/
     141             : 
     142        1582 :     nchan_out_buff_old = ivas_get_nchan_buffers_dec_fx( st_ivas, sba_analysis_order_old_flush, last_ivas_total_brate );
     143             : 
     144        1582 :     ivas_init_dec_get_num_cldfb_instances_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
     145        1582 :     nchan_hp20_old = getNumChanSynthesis( st_ivas );
     146             : 
     147        1582 :     IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     148             :     {
     149         562 :         IF( EQ_16( ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ), ISM_SBA_MODE_DISC ) )
     150             :         {
     151         219 :             st_ivas->ism_mode = ISM_SBA_MODE_DISC;
     152         219 :             move16();
     153             :         }
     154             :         ELSE
     155             :         {
     156         343 :             st_ivas->ism_mode = ISM_MODE_NONE;
     157         343 :             move16();
     158             :         }
     159             :     }
     160             :     ELSE
     161             :     {
     162        1020 :         st_ivas->ism_mode = ISM_MODE_NONE;
     163        1020 :         move16();
     164             :     }
     165             : 
     166        1582 :     nSCE_old = st_ivas->nSCE;
     167        1582 :     move16();
     168        1582 :     nCPE_old = st_ivas->nCPE;
     169        1582 :     move16();
     170        1582 :     nchan_transport_old = st_ivas->nchan_transport;
     171        1582 :     move16();
     172        1582 :     sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag;
     173        1582 :     move16();
     174             : 
     175        1582 :     st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order );
     176             : 
     177        1582 :     granularity_new = st_ivas->hTcBuffer->n_samples_granularity; /*Q0*/
     178        1582 :     move16();
     179             : 
     180             :     /* we may need to flush only for binaural and OSBA and TSM */
     181        1582 :     test();
     182        1582 :     test();
     183        1582 :     test();
     184        1582 :     IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || 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 ) ) )
     185             :     {
     186             : #ifndef NONBE_1303_REND_GRANULARITY
     187             :         RENDERER_TYPE renderer_type_new;
     188             :         Word16 sba_order_internal;
     189             : 
     190             :         sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER );
     191             : 
     192             :         /* get new renderer type */
     193             :         /* copy the logic from ivas_renderer_select(), because calling this function has too many side effects that would affect the flushing */
     194             :         IF( LE_16( ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_order_internal ), 2 ) )
     195             :         {
     196             :             IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || 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 ) )
     197             :             {
     198             :                 renderer_type_new = RENDERER_BINAURAL_PARAMETRIC;
     199             :                 move16();
     200             :             }
     201             :             ELSE
     202             :             {
     203             :                 renderer_type_new = RENDERER_BINAURAL_PARAMETRIC_ROOM;
     204             :                 move16();
     205             :             }
     206             :         }
     207             :         ELSE
     208             :         {
     209             :             test();
     210             :             test();
     211             :             test();
     212             :             IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || 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 ) )
     213             :             {
     214             :                 renderer_type_new = RENDERER_BINAURAL_FASTCONV;
     215             :                 move16();
     216             :             }
     217             :             ELSE
     218             :             {
     219             :                 renderer_type_new = RENDERER_BINAURAL_FASTCONV_ROOM;
     220             :                 move16();
     221             :             }
     222             :         }
     223             : #endif
     224             :         /* determine new granularity */
     225             : #ifdef NONBE_1303_REND_GRANULARITY
     226         380 :         granularity_new = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), st_ivas->hDecoderConfig->output_Fs );
     227             : #else
     228             :         granularity_new = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/
     229             :         move16();
     230             : 
     231             :         /* this will change anyway only with binaural */
     232             :         test();
     233             :         IF( EQ_16( renderer_type_new, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     234             :         {
     235             :             granularity_new = i_mult( granularity_new, JBM_CLDFB_SLOTS_IN_SUBFRAME ); /*Q0*/
     236             :         }
     237             : #endif
     238             : 
     239             :         /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */
     240         380 :         IF( LT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
     241             :         {
     242             :             /* flush already done in IVAS_DEC_ReadFormat() */
     243             :         }
     244         275 :         ELSE IF( GT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
     245             :         {
     246         108 :             if ( NE_32( ( error = ivas_jbm_dec_set_discard_samples_fx( st_ivas ) ), IVAS_ERR_OK ) )
     247             :             {
     248           0 :                 return error;
     249             :             }
     250             : 
     251             :             /* make sure the changed number of slots in the last subframe is not lost in the following steps */
     252         108 :             IF( st_ivas->hSpatParamRendCom != NULL )
     253             :             {
     254         108 :                 st_ivas->hSpatParamRendCom->subframe_nbslots[st_ivas->hSpatParamRendCom->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; /*Q0*/
     255         108 :                 move32();
     256             :             }
     257         108 :             st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; /*Q0*/
     258         108 :             move32();
     259             :         }
     260             :     }
     261             : 
     262             :     /* save old */
     263        1582 :     IF( NE_16( ism_mode_old, ISM_SBA_MODE_DISC ) && NE_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
     264             :     {
     265        1130 :         test();
     266        1130 :         IF( st_ivas->hDirAC == NULL && st_ivas->hSpar != NULL )
     267             :         {
     268         203 :             st_ivas->hTcBuffer->num_slots = st_ivas->hSpar->num_slots;
     269         203 :             move16();
     270         203 :             st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpar->nb_subframes;
     271         203 :             move16();
     272         203 :             st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpar->slots_rendered;
     273         203 :             move16();
     274         203 :             st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpar->subframes_rendered;
     275         203 :             move16();
     276         203 :             Copy( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
     277             :         }
     278         927 :         ELSE IF( st_ivas->hSpatParamRendCom != NULL )
     279             :         {
     280         927 :             st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots;
     281         927 :             move16();
     282         927 :             st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes;
     283         927 :             move16();
     284         927 :             st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered;
     285         927 :             move16();
     286         927 :             st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered;
     287         927 :             move16();
     288         927 :             Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
     289             :         }
     290             :     }
     291             : 
     292             :     /*-----------------------------------------------------------------*
     293             :      * Allocate, initialize, and configure SBA handles
     294             :      *-----------------------------------------------------------------*/
     295             : 
     296             :     Word16 sba_order_internal;
     297             :     SPAR_DEC_HANDLE hSpar;
     298        1582 :     hSpar = st_ivas->hSpar;
     299             : 
     300        1582 :     sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/
     301             : 
     302        1582 :     IF( hSpar != NULL )
     303             :     {
     304        1582 :         test();
     305        1582 :         test();
     306        1582 :         IF( ( hSpar->hPCA != NULL ) && ( NE_32( hDecoderConfig->ivas_total_brate, PCA_BRATE ) || NE_16( st_ivas->sba_order, 1 ) ) )
     307             :         {
     308          12 :             free( st_ivas->hSpar->hPCA );
     309          12 :             hSpar->hPCA = NULL;
     310             :         }
     311             : 
     312        1582 :         test();
     313        1582 :         test();
     314        1582 :         test();
     315        1582 :         test();
     316        1582 :         test();
     317        1582 :         IF( NE_16( nchan_transport_old, ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_order_internal ) ) || ( GE_32( last_ivas_total_brate, IVAS_512k ) && LT_32( ivas_total_brate, IVAS_512k ) ) || ( LT_32( last_ivas_total_brate, IVAS_512k ) && GE_32( ivas_total_brate, IVAS_512k ) ) )
     318             :         {
     319        1279 :             ivas_spar_dec_close_fx( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 );
     320             : 
     321        1279 :             if ( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 1 ) ), IVAS_ERR_OK ) )
     322             :             {
     323           0 :                 return error;
     324             :             }
     325             :         }
     326         303 :         ELSE IF( LT_32( last_ivas_total_brate, IVAS_24k4 ) && GE_32( ivas_total_brate, IVAS_24k4 ) )
     327             :         {
     328          40 :             num_channels = st_ivas->hSpar->hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/
     329          40 :             move16();
     330          40 :             ivas_spar_md_dec_matrix_close_fx( st_ivas->hSpar->hMdDec, num_channels );
     331             : 
     332          40 :             num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order_internal, ivas_total_brate, st_ivas->last_active_ivas_total_brate );
     333          40 :             if ( NE_32( ( error = ivas_spar_md_dec_matrix_open_fx( st_ivas->hSpar->hMdDec, num_channels, num_md_sub_frames ) ), IVAS_ERR_OK ) )
     334             :             {
     335           0 :                 return error;
     336             :             }
     337             :         }
     338             : 
     339        1582 :         test();
     340        1582 :         test();
     341        1582 :         test();
     342        1582 :         test();
     343        1582 :         IF( hSpar->hPCA == NULL && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, PCA_BRATE ) && EQ_16( st_ivas->sba_order, 1 ) && ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
     344             :         {
     345           0 :             IF( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL )
     346             :             {
     347           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" );
     348             :             }
     349             : 
     350           0 :             ivas_pca_dec_init_fx( hSpar->hPCA );
     351             :         }
     352             : 
     353        1582 :         ivas_spar_config_fx( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format );
     354             :     }
     355             :     ELSE
     356             :     {
     357           0 :         if ( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) )
     358             :         {
     359           0 :             return error;
     360             :         }
     361             :     }
     362             : 
     363        1582 :     hSpar = st_ivas->hSpar;
     364        1582 :     st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
     365        1582 :     move16();
     366             : 
     367        1582 :     IF( EQ_16( st_ivas->nchan_transport, 1 ) )
     368             :     {
     369         567 :         st_ivas->element_mode_init = IVAS_SCE;
     370         567 :         move16();
     371             :     }
     372             :     ELSE
     373             :     {
     374        1015 :         st_ivas->element_mode_init = IVAS_CPE_MDCT;
     375        1015 :         move16();
     376             :     }
     377             : 
     378             :     /*-----------------------------------------------------------------*
     379             :      * Renderer selection
     380             :      *-----------------------------------------------------------------*/
     381             : 
     382             :     /* renderer might have changed */
     383        1582 :     intern_config_old = st_ivas->intern_config;
     384        1582 :     move16();
     385        1582 :     ivas_renderer_select( st_ivas );
     386             : 
     387             :     /* side effect of the renderer selection can be a changed internal config */
     388        1582 :     IF( NE_16( st_ivas->intern_config, intern_config_old ) )
     389             :     {
     390         282 :         ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
     391             :     }
     392             : 
     393             :     /*-------------------------------------------------------------------*
     394             :      * Reallocate and initialize binaural rendering handles
     395             :      *--------------------------------------------------------------------*/
     396             : 
     397        1582 :     test();
     398        1582 :     test();
     399        1582 :     test();
     400        1582 :     test();
     401        1582 :     IF( st_ivas->hBinRenderer == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
     402             :     {
     403             :         /* open fastconv binaural renderer */
     404         143 :         IF( NE_32( ( error = ivas_binRenderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
     405             :         {
     406           0 :             return error;
     407             :         }
     408             :     }
     409        1439 :     ELSE IF( st_ivas->hBinRenderer != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
     410             :     {
     411         139 :         ivas_binRenderer_close_fx( &st_ivas->hBinRenderer );
     412             :     }
     413             : 
     414        1582 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && st_ivas->hMonoDmxRenderer == NULL )
     415             :     {
     416           0 :         IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
     417             :         {
     418           0 :             return error;
     419             :         }
     420             :     }
     421             : 
     422        1582 :     IF( NE_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
     423             :     {
     424        1582 :         ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
     425             :     }
     426             : 
     427        1582 :     IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
     428             :     {
     429           0 :         return error;
     430             :     }
     431             : 
     432        1582 :     IF( ( ( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) && ( NE_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) ) ) || ( ( NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) && ( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) && ( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) ) )
     433        1144 :     {
     434             :         DIRAC_CONFIG_FLAG flag_config;
     435             : 
     436        1144 :         flag_config = DIRAC_OPEN;
     437        1144 :         if ( st_ivas->hDirAC != NULL )
     438             :         {
     439        1116 :             flag_config = DIRAC_RECONFIGURE_MODE;
     440             :         }
     441             : 
     442        1144 :         IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, flag_config ) ), IVAS_ERR_OK ) )
     443             :         {
     444           0 :             return error;
     445             :         }
     446             :     }
     447             :     ELSE
     448             :     {
     449             :         Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1];
     450             : 
     451         438 :         st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); /*Q0*/
     452         438 :         move16();
     453         438 :         IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
     454             :         {
     455          44 :             st_ivas->hSpar->enc_param_start_band = 0;
     456          44 :             move16();
     457             : 
     458          44 :             set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); /*Q0*/
     459          44 :             st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
     460          44 :             move16();
     461             :         }
     462             : 
     463         438 :         ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( L_add( st_ivas->hDecoderConfig->output_Fs, 400 ) / CLDFB_BANDWIDTH ),
     464         438 :                                     st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0, 1 );
     465             : 
     466         438 :         if ( st_ivas->hDirAC )
     467             :         {
     468          25 :             st_ivas->hDirAC->hConfig->enc_param_start_band = st_ivas->hSpar->enc_param_start_band;
     469          25 :             move16();
     470             :         }
     471             :     }
     472             : 
     473        1582 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) )
     474             :     {
     475         237 :         ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) );
     476         237 :         ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) );
     477         237 :         ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) );
     478         237 :         vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
     479             :     }
     480             : 
     481        1582 :     if ( st_ivas->hDirAC != NULL )
     482             :     {
     483        1144 :         st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
     484        1144 :         move16();
     485             :     }
     486             : 
     487             :     /*-----------------------------------------------------------------*
     488             :      * Allocate, initialize, and configure SCE/CPE/MCT handles
     489             :      *-----------------------------------------------------------------*/
     490             : 
     491        1582 :     nchan_transport = st_ivas->nchan_transport;
     492        1582 :     move16();
     493        1582 :     IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     494             :     {
     495         562 :         test();
     496         562 :         test();
     497         562 :         IF( EQ_16( ism_mode_old, ISM_MODE_NONE ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     498         160 :         {
     499             :             Word32 temp_brate[MAX_SCE];
     500             : 
     501         160 :             st_ivas->ism_mode = ISM_SBA_MODE_DISC;
     502         160 :             move16();
     503             : 
     504         160 :             IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) )
     505             :             {
     506           0 :                 return error;
     507             :             }
     508             : 
     509         160 :             test();
     510         160 :             test();
     511         160 :             test();
     512         160 :             test();
     513         160 :             test();
     514         160 :             test();
     515         160 :             test();
     516         160 :             test();
     517         160 :             IF( ( EQ_16( st_ivas->renderer_type, RENDERER_TD_PANNING ) ||
     518             :                   EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ||
     519             :                   EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ||
     520             :                   EQ_16( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ||
     521             :                   EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
     522             :                   EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
     523             :                   EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
     524             :                   EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
     525             :                   EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) )
     526             :             {
     527         134 :                 IF( NE_32( ( error = ivas_ism_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
     528             :                 {
     529           0 :                     return error;
     530             :                 }
     531             :             }
     532             : 
     533         160 :             IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
     534             :             {
     535           0 :                 IF( st_ivas->hMonoDmxRenderer == NULL )
     536             :                 {
     537           0 :                     IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
     538             :                     {
     539           0 :                         return error;
     540             :                     }
     541             :                 }
     542             :             }
     543             :             ELSE
     544             :             {
     545         160 :                 ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
     546             :             }
     547             : 
     548         160 :             IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
     549             :             {
     550             :                 /* Allocate TD renderer for the objects in DISC mode */
     551         108 :                 IF( st_ivas->hBinRendererTd == NULL )
     552             :                 {
     553             :                     Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
     554             :                     Word16 num_src;
     555         108 :                     IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) )
     556             :                     {
     557           0 :                         return error;
     558             :                     }
     559         108 :                     IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
     560             :                     {
     561          50 :                         IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) )
     562             :                         {
     563           0 :                             return error;
     564             :                         }
     565             :                     }
     566             :                 }
     567             :             }
     568             : 
     569             :             /* Allocate memory for OSBA delay buffer */
     570         160 :             IF( NE_32( ( error = ivas_osba_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
     571             :             {
     572           0 :                 return error;
     573             :             }
     574             : 
     575         160 :             nchan_transport = add( nchan_transport, st_ivas->nchan_ism );
     576         160 :             st_ivas->nCPE = shr_r( nchan_transport, 1 );
     577         160 :             move16();
     578             :         }
     579         402 :         ELSE IF( EQ_16( ism_mode_old, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->ism_mode, ISM_MODE_NONE ) )
     580             :         {
     581             :             /* ISM renderer handle */
     582         155 :             ivas_ism_renderer_close( &st_ivas->hIsmRendererData );
     583         155 :             ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 );
     584         155 :             ivas_osba_data_close_fx( &st_ivas->hSbaIsmData );
     585             : 
     586             :             /* Time Domain binaural renderer handle */
     587         155 :             IF( st_ivas->hBinRendererTd != NULL )
     588             :             {
     589         105 :                 ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd );
     590             :             }
     591             : 
     592         155 :             nchan_transport = st_ivas->nchan_transport;
     593         155 :             move16();
     594         155 :             nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); /*Q0*/
     595         155 :             st_ivas->ism_mode = ISM_MODE_NONE;
     596         155 :             move16();
     597             :         }
     598         247 :         ELSE IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     599             :         {
     600          59 :             nchan_transport = add( st_ivas->nchan_transport, st_ivas->nchan_ism );
     601          59 :             st_ivas->nCPE = shr_r( nchan_transport, 1 );
     602          59 :             nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism );
     603             :         }
     604             :     }
     605             : 
     606        1582 :     IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ), IVAS_ERR_OK ) )
     607             :     {
     608           0 :         return error;
     609             :     }
     610             : 
     611             :     /*-----------------------------------------------------------------*
     612             :      * HP20 memories
     613             :      *-----------------------------------------------------------------*/
     614             : 
     615        1582 :     IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ), IVAS_ERR_OK ) )
     616             :     {
     617           0 :         return error;
     618             :     }
     619             : 
     620             :     /*-----------------------------------------------------------------*
     621             :      * TD Decorrelator
     622             :      *-----------------------------------------------------------------*/
     623             : 
     624        1582 :     IF( st_ivas->hDiracDecBin[0] != NULL )
     625             :     {
     626         273 :         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 ) )
     627             :         {
     628           0 :             return error;
     629             :         }
     630             :     }
     631             : 
     632             :     /*-----------------------------------------------------------------*
     633             :      * CLDFB instances
     634             :      *-----------------------------------------------------------------*/
     635             : 
     636        1582 :     IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) )
     637             :     {
     638           0 :         return error;
     639             :     }
     640             : 
     641             :     /*-----------------------------------------------------------------*
     642             :      * JBM TC buffers
     643             :      *-----------------------------------------------------------------*/
     644             : 
     645             :     {
     646             :         Word16 tc_nchan_to_allocate;
     647             :         Word16 tc_nchan_tc;
     648             :         TC_BUFFER_MODE tc_buffer_mode;
     649             : 
     650        1582 :         tc_buffer_mode = TC_BUFFER_MODE_RENDERER;
     651        1582 :         move16();
     652        1582 :         tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/
     653        1582 :         tc_nchan_to_allocate = tc_nchan_tc;                           /*Q0*/
     654        1582 :         move16();
     655        1582 :         test();
     656        1582 :         test();
     657        1582 :         test();
     658        1582 :         test();
     659        1582 :         IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
     660             :         {
     661         273 :             test();
     662         273 :             test();
     663         273 :             IF( ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
     664             :             {
     665          36 :                 tc_nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*Q0*/
     666          36 :                 tc_nchan_to_allocate = tc_nchan_tc;                                          /*Q0*/
     667          36 :                 move16();
     668             :             }
     669             :             ELSE
     670             :             {
     671         237 :                 tc_buffer_mode = TC_BUFFER_MODE_BUFFER;
     672         237 :                 move16();
     673         237 :                 tc_nchan_tc = st_ivas->hDecoderConfig->nchan_out; /*Q0*/
     674         237 :                 move16();
     675         237 :                 tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/
     676         237 :                 move16();
     677             :             }
     678             :         }
     679        1309 :         ELSE 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 ) )
     680             :         {
     681         273 :             tc_nchan_to_allocate = shl( BINAURAL_CHANNELS, 1 ); /*2 * BINAURAL_CHANNELS*/
     682             :         }
     683        1036 :         ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     684             :         {
     685        1036 :             tc_nchan_to_allocate = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/
     686             : 
     687        1036 :             IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     688             :             {
     689         183 :                 tc_nchan_to_allocate = add( tc_nchan_to_allocate, st_ivas->nchan_ism ); /*Q0*/
     690             :             }
     691             :         }
     692             :         ELSE
     693             :         {
     694           0 :             test();
     695           0 :             test();
     696           0 :             test();
     697           0 :             test();
     698           0 :             IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && EQ_16( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) || ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) )
     699             :             {
     700           0 :                 tc_nchan_to_allocate++; /* we need a channel for the CNG in this case*/
     701             :             }
     702             :         }
     703             : 
     704        1582 :         test();
     705        1582 :         test();
     706        1582 :         test();
     707        1582 :         IF( NE_16( tc_nchan_tc, st_ivas->hTcBuffer->nchan_transport_jbm ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( tc_buffer_mode, st_ivas->hTcBuffer->tc_buffer_mode ) || NE_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
     708             :         {
     709        1098 :             if ( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode, tc_nchan_tc, tc_nchan_to_allocate, tc_nchan_to_allocate, granularity_new ) ), IVAS_ERR_OK ) )
     710             :             {
     711           0 :                 return error;
     712             :             }
     713             :         }
     714             :     }
     715             : 
     716             :     /* resync SPAR and DirAC JBM info from TC Buffer */
     717        1582 :     test();
     718        1582 :     IF( st_ivas->hSpatParamRendCom != NULL && EQ_16( st_ivas->hSpatParamRendCom->slot_size, st_ivas->hTcBuffer->n_samples_granularity ) )
     719             :     {
     720         997 :         Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
     721         997 :         st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
     722         997 :         move16();
     723         997 :         st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
     724         997 :         move16();
     725             :     }
     726        1582 :     Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpar->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
     727        1582 :     st_ivas->hSpar->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
     728        1582 :     move16();
     729        1582 :     st_ivas->hSpar->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
     730        1582 :     move16();
     731             : 
     732        1582 :     test();
     733        1582 :     test();
     734        1582 :     IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     735             :     {
     736         147 :         Word16 granularityMultiplier = idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ); /*Q0*/
     737             :         Word16 n;
     738        1323 :         FOR( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ )
     739             :         {
     740        1176 :             st_ivas->hSpatParamRendCom->subframe_nbslots[n] = i_mult( st_ivas->hTcBuffer->subframe_nbslots[n], granularityMultiplier ); /*Q0*/
     741        1176 :             move16();
     742        1176 :             st_ivas->hSpar->subframe_nbslots[n] = st_ivas->hSpatParamRendCom->subframe_nbslots[n];
     743        1176 :             move16();
     744             :         }
     745             :     }
     746             : 
     747             :     /*-----------------------------------------------------------------*
     748             :      * output audio buffers
     749             :      *-----------------------------------------------------------------*/
     750             : 
     751        1582 :     nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/
     752             : 
     753        1582 :     IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) )
     754             :     {
     755           0 :         return error;
     756             :     }
     757             : 
     758        1582 :     return IVAS_ERR_OK;
     759             : }
     760             : 
     761             : 
     762             : /*-------------------------------------------------------------------*
     763             :  * ivas_sba_dec_digest_tc()
     764             :  *
     765             :  *
     766             :  *-------------------------------------------------------------------*/
     767             : 
     768      182318 : void ivas_sba_dec_digest_tc_fx(
     769             :     Decoder_Struct *st_ivas,          /* i/o: IVAS decoder handle          */
     770             :     const Word16 nCldfbSlots,         /* i  : number of CLDFB slots        Q0*/
     771             :     const Word16 nSamplesForRendering /* i  : number of samples provided   Q0*/
     772             : )
     773             : {
     774             :     Word16 ch_idx, nchan_transport;
     775             : 
     776             :     /* set the md map */
     777      182318 :     test();
     778      182318 :     IF( st_ivas->hDirAC != NULL || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) )
     779             :     {
     780      140249 :         ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots );
     781             :     }
     782             : 
     783      182318 :     test();
     784      182318 :     IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     785             :     {
     786      141760 :         ivas_spar_dec_digest_tc_fx( st_ivas, st_ivas->nchan_transport, nCldfbSlots, nSamplesForRendering );
     787             :     }
     788             : 
     789      182318 :     test();
     790      182318 :     IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr )
     791             :     {
     792             :         Word16 nSamplesLeftForTD, default_frame;
     793             :         Word32 *decorr_signal[BINAURAL_CHANNELS];
     794             :         Word32 *p_tc[2 * BINAURAL_CHANNELS];
     795             : 
     796             :         /* default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */
     797       27178 :         default_frame = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /*Q0*/
     798       27178 :         nSamplesLeftForTD = nSamplesForRendering;                                                                /*Q0*/
     799       27178 :         move16();
     800             : 
     801       81534 :         FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ )
     802             :         {
     803       54356 :             decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[( ch_idx + BINAURAL_CHANNELS )]; /*Q11*/
     804       54356 :             move32();
     805       54356 :             p_tc[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx]; /*Q11*/
     806       54356 :             move32();
     807             :         }
     808             : 
     809       54361 :         WHILE( nSamplesLeftForTD )
     810             :         {
     811       27183 :             Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); /*Q0*/
     812             : 
     813       27183 :             IF( st_ivas->hDiracDecBin[0]->hTdDecorr )
     814             :             {
     815       27183 :                 ivas_td_decorr_process_fx( st_ivas->hDiracDecBin[0]->hTdDecorr, p_tc, decorr_signal, nSamplesToDecorr );
     816             :             }
     817             : 
     818       81549 :             FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ )
     819             :             {
     820       54366 :                 decorr_signal[ch_idx] += nSamplesToDecorr;
     821       54366 :                 p_tc[ch_idx] += nSamplesToDecorr;
     822             :             }
     823       27183 :             nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); /*Q0*/
     824             :         }
     825             :     }
     826             : 
     827             :     /* if we have a late CNG generation, do it here */
     828      182318 :     nchan_transport = st_ivas->nchan_transport; /*Q0*/
     829      182318 :     move16();
     830             : 
     831      182318 :     test();
     832      182318 :     test();
     833      182318 :     test();
     834      182318 :     test();
     835      182318 :     test();
     836      182318 :     if ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) && st_ivas->nCPE > 0 && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) )
     837             :     {
     838        6121 :         nchan_transport = 1;
     839        6121 :         move16(); /* Only one channel transported */
     840             :     }
     841             : 
     842      182318 :     test();
     843      182318 :     test();
     844      182318 :     test();
     845      182318 :     test();
     846      182318 :     test();
     847      182318 :     test();
     848      182318 :     test();
     849      182318 :     test();
     850      182318 :     test();
     851      182318 :     test();
     852      182318 :     test();
     853      182318 :     IF( ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag ) ||
     854             :         ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) && ( EQ_16( nchan_transport, 1 ) && NE_16( st_ivas->nchan_transport, 2 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag ) ) )
     855             :     {
     856       18828 :         Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
     857       18828 :         Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 2 ) ); /*Q12 -> Q13*/
     858             : 
     859       18828 :         generate_masking_noise_lb_dirac_fx( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc_fx[1], nCldfbSlots, st_ivas->hSpatParamRendCom, st->cna_dirac_flag && st->flag_cna );
     860             :     }
     861             : 
     862      182318 :     return;
     863             : }
     864             : 
     865             : /*-------------------------------------------------------------------*
     866             :  * ivas_sba_dec_render()
     867             :  *
     868             :  *
     869             :  *-------------------------------------------------------------------*/
     870             : 
     871      105638 : ivas_error ivas_sba_dec_render_fx(
     872             :     Decoder_Struct *st_ivas,        /* i/o: IVAS decoder handle                       */
     873             :     const UWord16 nSamplesAsked,    /* i  : number of CLDFB slots requested           Q0*/
     874             :     UWord16 *nSamplesRendered,      /* o  : number of CLDFB slots rendered            Q0*/
     875             :     UWord16 *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render     Q0*/
     876             :     Word32 *output_fx[]             /* o  : rendered time signal                      Q11*/
     877             : )
     878             : {
     879             :     Word16 slots_to_render, first_sf, last_sf, subframe_idx;
     880             :     UWord16 slot_size, ch;
     881             :     UWord16 nchan_internal, nchan_out;
     882             :     SPAR_DEC_HANDLE hSpar;
     883             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
     884             :     Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS];
     885             :     ivas_error error;
     886             : 
     887      105638 :     hSpar = st_ivas->hSpar;
     888      105638 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
     889      105638 :     nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
     890      105638 :     nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); /*Q0*/
     891             : 
     892     1147503 :     FOR( ch = 0; ch < nchan_out; ch++ )
     893             :     {
     894     1041865 :         output_f_local_fx[ch] = output_fx[ch]; /*Q11*/
     895             :     }
     896             : 
     897      105638 :     slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/
     898      105638 :     move16();
     899             : 
     900             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
     901      105638 :     slots_to_render = s_min( sub( hSpar->num_slots, hSpar->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); /*Q0*/
     902      105638 :     *nSamplesRendered = imult1616( slots_to_render, slot_size );                                                     /*Q0*/
     903      105638 :     move16();
     904      105638 :     first_sf = hSpar->subframes_rendered; /*Q0*/
     905      105638 :     last_sf = first_sf;                   /*Q0*/
     906      105638 :     move16();
     907      105638 :     move16();
     908      523456 :     WHILE( slots_to_render > 0 )
     909             :     {
     910      417818 :         slots_to_render = sub( slots_to_render, hSpar->subframe_nbslots[last_sf] ); /*Q0*/
     911      417818 :         last_sf = add( last_sf, 1 );
     912             :     }
     913             : 
     914      523456 :     FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
     915             :     {
     916      417818 :         Word16 n_samples_sf = imult1616( slot_size, hSpar->subframe_nbslots[subframe_idx] ); /*Q0*/
     917             : 
     918      417818 :         ivas_spar_dec_upmixer_sf_fx( st_ivas, output_f_local_fx, nchan_internal );
     919     4509534 :         FOR( ch = 0; ch < nchan_out; ch++ )
     920             :         {
     921     4091716 :             output_f_local_fx[ch] = output_f_local_fx[ch] + n_samples_sf; /*Q11*/
     922             :         }
     923             :         /* update combined orientation access index */
     924      417818 :         ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
     925             :     }
     926             : 
     927      105638 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) )
     928             :     {
     929       62950 :         if ( NE_32( ( error = ivas_sba_linear_renderer_fx( output_fx, *nSamplesRendered, st_ivas->hIntSetup.nchan_out_woLFE, 0, st_ivas->hDecoderConfig->output_config, st_ivas->hOutSetup ) ), IVAS_ERR_OK ) )
     930             :         {
     931           0 :             return error;
     932             :         }
     933             :     }
     934             : 
     935      105638 :     IF( st_ivas->hDirAC != NULL && EQ_16( hSpar->slots_rendered, hSpar->num_slots ) )
     936             :     {
     937       62139 :         IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) )
     938             :         {
     939       48849 :             hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/
     940       48849 :             move16();
     941             :         }
     942             :         ELSE
     943             :         {
     944       13290 :             hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/
     945       13290 :             move16();
     946             :         }
     947       62139 :         move16();
     948             :     }
     949             : 
     950      105638 :     *nSamplesAvailableNext = imult1616( sub( hSpar->num_slots, hSpar->slots_rendered ), slot_size ); /*Q0*/
     951      105638 :     move16();
     952             : 
     953      105638 :     return IVAS_ERR_OK;
     954             : }

Generated by: LCOV version 1.14