LCOV - code coverage report
Current view: top level - lib_dec - ivas_sba_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 397 432 91.9 %
Date: 2025-08-23 01:22:27 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        2355 : 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        2355 :     test();
      57        2355 :     test();
      58        2355 :     test();
      59        2355 :     test();
      60        2355 :     test();
      61        2355 :     test();
      62             : #ifdef NONBE_FIX_ISM_XOVER_BR
      63        2355 :     test();
      64             : #endif
      65        2355 :     IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( st_ivas->nchan_transport, 1 ) )
      66             :     {
      67             :         /* skip as done in init function */
      68             :         /* st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 0; */
      69             :         /* st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 0; */
      70             :     }
      71        1884 :     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 ) ) ) )
      72             :     {
      73         158 :         st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1;
      74         158 :         move16();
      75         158 :         st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1;
      76         158 :         move16();
      77             :     }
      78             : #ifdef NONBE_FIX_ISM_XOVER_BR
      79        1726 :     ELSE IF( EQ_16( st_ivas->nchan_transport, 2 ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
      80             : #else
      81             :     ELSE IF( EQ_16( st_ivas->nchan_transport, 2 ) )
      82             : #endif
      83             :     {
      84        2163 :         FOR( n = 0; n < CPE_CHANNELS; n++ )
      85             :         {
      86        1442 :             st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0;
      87        1442 :             move16();
      88        1442 :             st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1;
      89        1442 :             move16();
      90             :         }
      91             :     }
      92             :     ELSE
      93             :     {
      94        3140 :         FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
      95             :         {
      96        6405 :             FOR( n = 0; n < CPE_CHANNELS; n++ )
      97             :             {
      98        4270 :                 st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0;
      99        4270 :                 move16();
     100        4270 :                 st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0;
     101        4270 :                 move16();
     102             :             }
     103             :         }
     104             :     }
     105             : 
     106        2355 :     return;
     107             : }
     108             : 
     109             : /*-------------------------------------------------------------------*
     110             :  * ivas_sba_dec_reconfigure_fx()
     111             :  *
     112             :  * Reconfigure IVAS SBA decoder
     113             :  *-------------------------------------------------------------------*/
     114             : 
     115        1582 : ivas_error ivas_sba_dec_reconfigure_fx(
     116             :     Decoder_Struct *st_ivas,  /* i/o: IVAS decoder structure              */
     117             :     UWord16 *nSamplesFlushed, /* o  : number of samples flushed           Q0*/
     118             :     Word16 *data              /* o  : output synthesis signal             Q0*/
     119             : )
     120             : {
     121             :     Word16 nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old;
     122             :     AUDIO_CONFIG intern_config_old;
     123             :     Word16 numCldfbAnalyses_old, numCldfbSyntheses_old;
     124             :     Word16 sba_dirac_stereo_flag_old;
     125             :     Word32 ivas_total_brate;
     126             :     Word32 last_ivas_total_brate;
     127             :     Word16 num_channels, num_md_sub_frames;
     128             :     Word16 nchan_out_buff, nchan_out_buff_old;
     129             :     Word16 sba_analysis_order_old_flush;
     130             :     DECODER_CONFIG_HANDLE hDecoderConfig;
     131             :     ivas_error error;
     132             :     ISM_MODE ism_mode_old;
     133             :     Word16 granularity_new;
     134             : #ifdef NONBE_FIX_ISM_XOVER_BR
     135             :     Word16 nchan_transport;
     136             : #endif
     137             : 
     138        1582 :     ism_mode_old = st_ivas->ism_mode;
     139        1582 :     hDecoderConfig = st_ivas->hDecoderConfig;
     140        1582 :     ivas_total_brate = hDecoderConfig->ivas_total_brate;
     141        1582 :     move32();
     142        1582 :     last_ivas_total_brate = st_ivas->last_active_ivas_total_brate;
     143        1582 :     move32();
     144        1582 :     sba_analysis_order_old_flush = st_ivas->sba_analysis_order;
     145        1582 :     move16();
     146             : 
     147             :     /*-----------------------------------------------------------------*
     148             :      * Set SBA high-level parameters
     149             :      * Save old SBA high-level parameters
     150             :      *-----------------------------------------------------------------*/
     151             : 
     152        1582 :     nchan_out_buff_old = ivas_get_nchan_buffers_dec_fx( st_ivas, sba_analysis_order_old_flush, last_ivas_total_brate );
     153             : 
     154        1582 :     ivas_init_dec_get_num_cldfb_instances_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
     155        1582 :     nchan_hp20_old = getNumChanSynthesis( st_ivas );
     156             : 
     157        1582 :     IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     158             :     {
     159             : #ifdef NONBE_FIX_ISM_XOVER_BR
     160         562 :         IF( EQ_16( ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ), ISM_SBA_MODE_DISC ) )
     161             : #else
     162             :         IF( GE_32( ivas_total_brate, IVAS_256k ) )
     163             : #endif
     164             :         {
     165         219 :             st_ivas->ism_mode = ISM_SBA_MODE_DISC;
     166         219 :             move16();
     167             :         }
     168             :         ELSE
     169             :         {
     170         343 :             st_ivas->ism_mode = ISM_MODE_NONE;
     171         343 :             move16();
     172             :         }
     173             :     }
     174             :     ELSE
     175             :     {
     176        1020 :         st_ivas->ism_mode = ISM_MODE_NONE;
     177        1020 :         move16();
     178             :     }
     179             : 
     180        1582 :     nSCE_old = st_ivas->nSCE;
     181        1582 :     move16();
     182        1582 :     nCPE_old = st_ivas->nCPE;
     183        1582 :     move16();
     184        1582 :     nchan_transport_old = st_ivas->nchan_transport;
     185        1582 :     move16();
     186        1582 :     sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag;
     187        1582 :     move16();
     188             : 
     189        1582 :     st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order );
     190             : 
     191        1582 :     *nSamplesFlushed = 0;
     192        1582 :     move16();
     193        1582 :     granularity_new = st_ivas->hTcBuffer->n_samples_granularity; /*Q0*/
     194        1582 :     move16();
     195             : 
     196             :     /* we may need to flush only for binaural and OSBA and TSM */
     197        1582 :     test();
     198        1582 :     test();
     199        1582 :     test();
     200        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 ) ) )
     201             :     {
     202             :         RENDERER_TYPE renderer_type_new;
     203             :         Word16 sba_order_internal;
     204             : 
     205         380 :         sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER );
     206             : 
     207             :         /* get new renderer type */
     208             :         /* copy the logic from ivas_renderer_select(), because calling this function has too many side effects that would affect the flushing */
     209         380 :         IF( LE_16( ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_order_internal ), 2 ) )
     210             :         {
     211         204 :             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 ) )
     212             :             {
     213         110 :                 renderer_type_new = RENDERER_BINAURAL_PARAMETRIC;
     214         110 :                 move16();
     215             :             }
     216             :             ELSE
     217             :             {
     218          94 :                 renderer_type_new = RENDERER_BINAURAL_PARAMETRIC_ROOM;
     219          94 :                 move16();
     220             :             }
     221             :         }
     222             :         ELSE
     223             :         {
     224         176 :             test();
     225         176 :             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 ) )
     226             :             {
     227          91 :                 renderer_type_new = RENDERER_BINAURAL_FASTCONV;
     228          91 :                 move16();
     229             :             }
     230             :             ELSE
     231             :             {
     232          85 :                 renderer_type_new = RENDERER_BINAURAL_FASTCONV_ROOM;
     233          85 :                 move16();
     234             :             }
     235             :         }
     236             : 
     237             :         /* determine new granularity */
     238         380 :         granularity_new = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/
     239         380 :         move16();
     240             : 
     241             :         /* this will change anyway only with binaural */
     242         380 :         test();
     243         380 :         IF( EQ_16( renderer_type_new, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     244             :         {
     245          78 :             granularity_new = i_mult( granularity_new, JBM_CLDFB_SLOTS_IN_SUBFRAME ); /*Q0*/
     246             :         }
     247             : 
     248             :         /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */
     249         380 :         IF( LT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
     250             :         {
     251             :             /* write back info for correct rendering of the flushable samples */
     252          56 :             st_ivas->sba_analysis_order = sba_analysis_order_old_flush; /*Q0*/
     253          56 :             move16();
     254          56 :             st_ivas->hDecoderConfig->ivas_total_brate = last_ivas_total_brate; /*Q0*/
     255          56 :             move32();
     256             : 
     257          56 :             if ( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, granularity_new, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, st_ivas->mc_mode, ism_mode_old, nSamplesFlushed, data ) ), IVAS_ERR_OK ) )
     258             :             {
     259           0 :                 return error;
     260             :             }
     261             : 
     262             :             /* restore correct values for the current frame*/
     263          56 :             st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order );
     264          56 :             move16();
     265          56 :             st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; /*Q0*/
     266          56 :             move32();
     267             :         }
     268         324 :         ELSE IF( GT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
     269             :         {
     270          58 :             if ( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) )
     271             :             {
     272           0 :                 return error;
     273             :             }
     274             : 
     275             :             /* make sure the changed number of slots in the last subframe is not lost in the following steps */
     276          58 :             IF( st_ivas->hSpatParamRendCom != NULL )
     277             :             {
     278          58 :                 st_ivas->hSpatParamRendCom->subframe_nbslots[st_ivas->hSpatParamRendCom->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; /*Q0*/
     279          58 :                 move32();
     280             :             }
     281          58 :             st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; /*Q0*/
     282          58 :             move32();
     283             :         }
     284             :     }
     285             : 
     286             :     /* save old */
     287        1582 :     IF( NE_16( ism_mode_old, ISM_SBA_MODE_DISC ) && NE_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
     288             :     {
     289        1130 :         test();
     290        1130 :         IF( st_ivas->hDirAC == NULL && st_ivas->hSpar != NULL )
     291             :         {
     292         203 :             st_ivas->hTcBuffer->num_slots = st_ivas->hSpar->num_slots;
     293         203 :             move16();
     294         203 :             st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpar->nb_subframes;
     295         203 :             move16();
     296         203 :             st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpar->slots_rendered;
     297         203 :             move16();
     298         203 :             st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpar->subframes_rendered;
     299         203 :             move16();
     300         203 :             Copy( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
     301             :         }
     302         927 :         ELSE IF( st_ivas->hSpatParamRendCom != NULL )
     303             :         {
     304         927 :             st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots;
     305         927 :             move16();
     306         927 :             st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes;
     307         927 :             move16();
     308         927 :             st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered;
     309         927 :             move16();
     310         927 :             st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered;
     311         927 :             move16();
     312         927 :             Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
     313             :         }
     314             :     }
     315             : 
     316             :     /*-----------------------------------------------------------------*
     317             :      * Allocate, initialize, and configure SBA handles
     318             :      *-----------------------------------------------------------------*/
     319             : 
     320             :     Word16 sba_order_internal;
     321             :     SPAR_DEC_HANDLE hSpar;
     322        1582 :     hSpar = st_ivas->hSpar;
     323             : 
     324        1582 :     sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/
     325             : 
     326        1582 :     IF( hSpar != NULL )
     327             :     {
     328        1582 :         test();
     329        1582 :         test();
     330        1582 :         IF( ( hSpar->hPCA != NULL ) && ( NE_32( hDecoderConfig->ivas_total_brate, PCA_BRATE ) || NE_16( st_ivas->sba_order, 1 ) ) )
     331             :         {
     332          12 :             free( st_ivas->hSpar->hPCA );
     333          12 :             hSpar->hPCA = NULL;
     334             :         }
     335             : 
     336        1582 :         test();
     337        1582 :         test();
     338        1582 :         test();
     339        1582 :         test();
     340        1582 :         test();
     341        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 ) ) )
     342             :         {
     343        1279 :             ivas_spar_dec_close_fx( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 );
     344             : 
     345        1279 :             if ( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 1 ) ), IVAS_ERR_OK ) )
     346             :             {
     347           0 :                 return error;
     348             :             }
     349             :         }
     350         303 :         ELSE IF( LT_32( last_ivas_total_brate, IVAS_24k4 ) && GE_32( ivas_total_brate, IVAS_24k4 ) )
     351             :         {
     352          40 :             num_channels = st_ivas->hSpar->hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/
     353          40 :             move16();
     354          40 :             ivas_spar_md_dec_matrix_close_fx( st_ivas->hSpar->hMdDec, num_channels );
     355             : 
     356          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 );
     357          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 ) )
     358             :             {
     359           0 :                 return error;
     360             :             }
     361             :         }
     362             : 
     363        1582 :         test();
     364        1582 :         test();
     365        1582 :         test();
     366        1582 :         test();
     367        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 ) ) )
     368             :         {
     369           0 :             IF( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL )
     370             :             {
     371           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" );
     372             :             }
     373             : 
     374           0 :             ivas_pca_dec_init_fx( hSpar->hPCA );
     375             :         }
     376             : 
     377        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 );
     378             :     }
     379             :     ELSE
     380             :     {
     381           0 :         if ( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) )
     382             :         {
     383           0 :             return error;
     384             :         }
     385             :     }
     386             : 
     387        1582 :     hSpar = st_ivas->hSpar;
     388        1582 :     st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
     389        1582 :     move16();
     390             : 
     391        1582 :     IF( EQ_16( st_ivas->nchan_transport, 1 ) )
     392             :     {
     393         567 :         st_ivas->element_mode_init = IVAS_SCE;
     394         567 :         move16();
     395             :     }
     396             :     ELSE
     397             :     {
     398        1015 :         st_ivas->element_mode_init = IVAS_CPE_MDCT;
     399        1015 :         move16();
     400             :     }
     401             : 
     402             :     /*-----------------------------------------------------------------*
     403             :      * Renderer selection
     404             :      *-----------------------------------------------------------------*/
     405             : 
     406             :     /* renderer might have changed */
     407        1582 :     intern_config_old = st_ivas->intern_config;
     408        1582 :     move16();
     409        1582 :     ivas_renderer_select( st_ivas );
     410             : 
     411             :     /* side effect of the renderer selection can be a changed internal config */
     412        1582 :     IF( NE_16( st_ivas->intern_config, intern_config_old ) )
     413             :     {
     414         282 :         ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
     415             :     }
     416             : 
     417             :     /*-------------------------------------------------------------------*
     418             :      * Reallocate and initialize binaural rendering handles
     419             :      *--------------------------------------------------------------------*/
     420             : 
     421        1582 :     test();
     422        1582 :     test();
     423        1582 :     test();
     424        1582 :     test();
     425        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 ) ) )
     426             :     {
     427             :         /* open fastconv binaural renderer */
     428         143 :         IF( NE_32( ( error = ivas_binRenderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
     429             :         {
     430           0 :             return error;
     431             :         }
     432             :     }
     433        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 ) ) )
     434             :     {
     435         139 :         ivas_binRenderer_close_fx( &st_ivas->hBinRenderer );
     436             :     }
     437             : 
     438        1582 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && st_ivas->hMonoDmxRenderer == NULL )
     439             :     {
     440           0 :         IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
     441             :         {
     442           0 :             return error;
     443             :         }
     444             :     }
     445             : 
     446        1582 :     IF( NE_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
     447             :     {
     448        1582 :         ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
     449             :     }
     450             : 
     451        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 ) )
     452             :     {
     453           0 :         return error;
     454             :     }
     455             : 
     456        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 ) ) ) )
     457        1144 :     {
     458             :         DIRAC_CONFIG_FLAG flag_config;
     459             : 
     460        1144 :         flag_config = DIRAC_OPEN;
     461        1144 :         if ( st_ivas->hDirAC != NULL )
     462             :         {
     463        1116 :             flag_config = DIRAC_RECONFIGURE_MODE;
     464             :         }
     465             : 
     466        1144 :         IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, flag_config ) ), IVAS_ERR_OK ) )
     467             :         {
     468           0 :             return error;
     469             :         }
     470             :     }
     471             :     ELSE
     472             :     {
     473             :         Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1];
     474             : 
     475         438 :         st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); /*Q0*/
     476         438 :         move16();
     477         438 :         IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
     478             :         {
     479          44 :             st_ivas->hSpar->enc_param_start_band = 0;
     480          44 :             move16();
     481             : 
     482          44 :             set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); /*Q0*/
     483          44 :             st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
     484          44 :             move16();
     485             :         }
     486             : 
     487         438 :         ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( L_add( st_ivas->hDecoderConfig->output_Fs, 400 ) / CLDFB_BANDWIDTH ),
     488         438 :                                     st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0, 1 );
     489             : 
     490         438 :         if ( st_ivas->hDirAC )
     491             :         {
     492          25 :             st_ivas->hDirAC->hConfig->enc_param_start_band = st_ivas->hSpar->enc_param_start_band;
     493          25 :             move16();
     494             :         }
     495             :     }
     496             : 
     497        1582 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) )
     498             :     {
     499         237 :         ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) );
     500         237 :         ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) );
     501         237 :         ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) );
     502         237 :         vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
     503             :     }
     504             : 
     505        1582 :     if ( st_ivas->hDirAC != NULL )
     506             :     {
     507        1144 :         st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
     508        1144 :         move16();
     509             :     }
     510             : 
     511             :     /*-----------------------------------------------------------------*
     512             :      * Allocate, initialize, and configure SCE/CPE/MCT handles
     513             :      *-----------------------------------------------------------------*/
     514             : 
     515             : #ifdef NONBE_FIX_ISM_XOVER_BR
     516        1582 :     nchan_transport = st_ivas->nchan_transport;
     517        1582 :     move16();
     518             : #endif
     519        1582 :     IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     520             :     {
     521         562 :         test();
     522         562 :         test();
     523         562 :         IF( EQ_16( ism_mode_old, ISM_MODE_NONE ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     524         160 :         {
     525             :             Word32 temp_brate[MAX_SCE];
     526             : 
     527         160 :             st_ivas->ism_mode = ISM_SBA_MODE_DISC;
     528         160 :             move16();
     529             : 
     530         160 :             IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) )
     531             :             {
     532           0 :                 return error;
     533             :             }
     534             : 
     535         160 :             test();
     536         160 :             test();
     537         160 :             test();
     538         160 :             test();
     539         160 :             test();
     540         160 :             test();
     541         160 :             test();
     542         160 :             test();
     543         160 :             IF( ( EQ_16( st_ivas->renderer_type, RENDERER_TD_PANNING ) ||
     544             :                   EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ||
     545             :                   EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ||
     546             :                   EQ_16( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ||
     547             :                   EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
     548             :                   EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
     549             :                   EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
     550             :                   EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
     551             :                   EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) )
     552             :             {
     553         134 :                 IF( NE_32( ( error = ivas_ism_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
     554             :                 {
     555           0 :                     return error;
     556             :                 }
     557             :             }
     558             : 
     559         160 :             IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
     560             :             {
     561           0 :                 IF( st_ivas->hMonoDmxRenderer == NULL )
     562             :                 {
     563           0 :                     IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
     564             :                     {
     565           0 :                         return error;
     566             :                     }
     567             :                 }
     568             :             }
     569             :             ELSE
     570             :             {
     571         160 :                 ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
     572             :             }
     573             : 
     574         160 :             IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
     575             :             {
     576             :                 /* Allocate TD renderer for the objects in DISC mode */
     577         108 :                 IF( st_ivas->hBinRendererTd == NULL )
     578             :                 {
     579             :                     Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
     580             :                     Word16 num_src;
     581         108 :                     IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) )
     582             :                     {
     583           0 :                         return error;
     584             :                     }
     585         108 :                     IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
     586             :                     {
     587          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 ) )
     588             :                         {
     589           0 :                             return error;
     590             :                         }
     591             :                     }
     592             :                 }
     593             :             }
     594             : 
     595             :             /* Allocate memory for OSBA delay buffer */
     596         160 :             IF( NE_32( ( error = ivas_osba_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
     597             :             {
     598           0 :                 return error;
     599             :             }
     600             : #ifdef NONBE_FIX_ISM_XOVER_BR
     601         160 :             nchan_transport = add( nchan_transport, st_ivas->nchan_ism );
     602         160 :             st_ivas->nCPE = shr_r( nchan_transport, 1 );
     603             : #else
     604             :             st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); /*Q0*/
     605             : #endif
     606         160 :             move16();
     607             :         }
     608         402 :         ELSE IF( EQ_16( ism_mode_old, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->ism_mode, ISM_MODE_NONE ) )
     609             :         {
     610             :             /* ISM renderer handle */
     611         155 :             ivas_ism_renderer_close( &st_ivas->hIsmRendererData );
     612         155 :             ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 );
     613         155 :             ivas_osba_data_close_fx( &st_ivas->hSbaIsmData );
     614             : 
     615             :             /* Time Domain binaural renderer handle */
     616         155 :             IF( st_ivas->hBinRendererTd != NULL )
     617             :             {
     618         105 :                 ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd );
     619             :             }
     620             : #ifdef NONBE_FIX_ISM_XOVER_BR
     621         155 :             nchan_transport = st_ivas->nchan_transport;
     622         155 :             move16();
     623             : #endif
     624         155 :             nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); /*Q0*/
     625         155 :             st_ivas->ism_mode = ISM_MODE_NONE;
     626         155 :             move16();
     627             :         }
     628         247 :         ELSE IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     629             :         {
     630             : #ifdef NONBE_FIX_ISM_XOVER_BR
     631          59 :             nchan_transport = add( st_ivas->nchan_transport, st_ivas->nchan_ism );
     632          59 :             st_ivas->nCPE = shr_r( nchan_transport, 1 );
     633          59 :             nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism );
     634             : #else
     635             :             st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); /*Q0*/
     636             :             move16();
     637             :             nCPE_old = st_ivas->nCPE;
     638             :             move16();
     639             :             nchan_transport_old = st_ivas->nchan_transport;
     640             :             move16();
     641             :             nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); /*Q0*/
     642             : #endif
     643             :         }
     644             :     }
     645             : 
     646        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 ) )
     647             :     {
     648           0 :         return error;
     649             :     }
     650             : 
     651             :     /*-----------------------------------------------------------------*
     652             :      * HP20 memories
     653             :      *-----------------------------------------------------------------*/
     654        1582 :     IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ), IVAS_ERR_OK ) )
     655             :     {
     656           0 :         return error;
     657             :     }
     658             : 
     659             :     /*-----------------------------------------------------------------*
     660             :      * TD Decorrelator
     661             :      *-----------------------------------------------------------------*/
     662             : 
     663        1582 :     IF( st_ivas->hDiracDecBin[0] != NULL )
     664             :     {
     665         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 ) )
     666             :         {
     667           0 :             return error;
     668             :         }
     669             :     }
     670             : 
     671             :     /*-----------------------------------------------------------------*
     672             :      * CLDFB instances
     673             :      *-----------------------------------------------------------------*/
     674        1582 :     IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) )
     675             :     {
     676           0 :         return error;
     677             :     }
     678             : 
     679             :     /*-----------------------------------------------------------------*
     680             :      * JBM TC buffers
     681             :      *-----------------------------------------------------------------*/
     682             : 
     683             :     {
     684             :         Word16 tc_nchan_to_allocate;
     685             :         Word16 tc_nchan_tc;
     686             :         TC_BUFFER_MODE tc_buffer_mode;
     687             : 
     688        1582 :         tc_buffer_mode = TC_BUFFER_MODE_RENDERER;
     689        1582 :         move16();
     690        1582 :         tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/
     691        1582 :         tc_nchan_to_allocate = tc_nchan_tc;                           /*Q0*/
     692        1582 :         move16();
     693        1582 :         test();
     694        1582 :         test();
     695        1582 :         test();
     696        1582 :         test();
     697        1582 :         IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
     698             :         {
     699         273 :             test();
     700         273 :             test();
     701         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 ) ) )
     702             :             {
     703          36 :                 tc_nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*Q0*/
     704          36 :                 tc_nchan_to_allocate = tc_nchan_tc;                                          /*Q0*/
     705          36 :                 move16();
     706             :             }
     707             :             ELSE
     708             :             {
     709         237 :                 tc_buffer_mode = TC_BUFFER_MODE_BUFFER;
     710         237 :                 move16();
     711         237 :                 tc_nchan_tc = st_ivas->hDecoderConfig->nchan_out; /*Q0*/
     712         237 :                 move16();
     713         237 :                 tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/
     714         237 :                 move16();
     715             :             }
     716             :         }
     717        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 ) )
     718             :         {
     719         273 :             tc_nchan_to_allocate = shl( BINAURAL_CHANNELS, 1 ); /*2 * BINAURAL_CHANNELS*/
     720             :         }
     721        1036 :         ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     722             :         {
     723        1036 :             tc_nchan_to_allocate = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/
     724             : 
     725        1036 :             IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
     726             :             {
     727         183 :                 tc_nchan_to_allocate = add( tc_nchan_to_allocate, st_ivas->nchan_ism ); /*Q0*/
     728             :             }
     729             :         }
     730             :         ELSE
     731             :         {
     732           0 :             test();
     733           0 :             test();
     734           0 :             test();
     735           0 :             test();
     736           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 ) ) ) )
     737             :             {
     738           0 :                 tc_nchan_to_allocate++; /* we need a channel for the CNG in this case*/
     739             :             }
     740             :         }
     741             : 
     742        1582 :         test();
     743        1582 :         test();
     744        1582 :         test();
     745        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 ) )
     746             :         {
     747        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 ) )
     748             :             {
     749           0 :                 return error;
     750             :             }
     751             :         }
     752             :     }
     753             : 
     754             :     /* resync SPAR and DirAC JBM info from TC Buffer */
     755        1582 :     test();
     756        1582 :     IF( st_ivas->hSpatParamRendCom != NULL && EQ_16( st_ivas->hSpatParamRendCom->slot_size, st_ivas->hTcBuffer->n_samples_granularity ) )
     757             :     {
     758        1066 :         Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
     759        1066 :         st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
     760        1066 :         move16();
     761        1066 :         st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
     762        1066 :         move16();
     763             :     }
     764        1582 :     Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpar->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
     765        1582 :     st_ivas->hSpar->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
     766        1582 :     move16();
     767        1582 :     st_ivas->hSpar->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
     768        1582 :     move16();
     769             : 
     770        1582 :     test();
     771        1582 :     test();
     772        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 ) )
     773             :     {
     774         147 :         Word16 granularityMultiplier = idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ); /*Q0*/
     775             :         Word16 n;
     776        1323 :         FOR( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ )
     777             :         {
     778        1176 :             st_ivas->hSpatParamRendCom->subframe_nbslots[n] = i_mult( st_ivas->hTcBuffer->subframe_nbslots[n], granularityMultiplier ); /*Q0*/
     779        1176 :             move16();
     780        1176 :             st_ivas->hSpar->subframe_nbslots[n] = st_ivas->hSpatParamRendCom->subframe_nbslots[n];
     781        1176 :             move16();
     782             :         }
     783             :     }
     784             : 
     785             :     /*-----------------------------------------------------------------*
     786             :      * floating-point output audio buffers
     787             :      *-----------------------------------------------------------------*/
     788             : 
     789        1582 :     nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/
     790             : 
     791        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 ) )
     792             :     {
     793           0 :         return error;
     794             :     }
     795             : 
     796        1582 :     return error;
     797             : }
     798             : 
     799             : 
     800      181343 : void ivas_sba_dec_digest_tc_fx(
     801             :     Decoder_Struct *st_ivas,          /* i/o: IVAS decoder handle          */
     802             :     const Word16 nCldfbSlots,         /* i  : number of CLDFB slots        Q0*/
     803             :     const Word16 nSamplesForRendering /* i  : number of samples provided   Q0*/
     804             : )
     805             : {
     806             :     Word16 ch_idx, nchan_transport;
     807             : 
     808             :     /* set the md map */
     809             : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
     810      181343 :     test();
     811      181343 :     IF( st_ivas->hDirAC != NULL || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) )
     812             : #else
     813             :     IF( st_ivas->hDirAC )
     814             : #endif
     815             :     {
     816      139273 :         ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots );
     817             :     }
     818             : 
     819      181343 :     test();
     820      181343 :     IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
     821             :     {
     822      140772 :         ivas_spar_dec_digest_tc_fx( st_ivas, st_ivas->nchan_transport, nCldfbSlots, nSamplesForRendering );
     823             :     }
     824             : 
     825      181343 :     test();
     826      181343 :     IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr )
     827             :     {
     828             :         Word16 nSamplesLeftForTD, default_frame;
     829             :         Word32 *decorr_signal[BINAURAL_CHANNELS];
     830             :         Word32 *p_tc[2 * BINAURAL_CHANNELS];
     831             : 
     832             :         /* default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */
     833       27183 :         default_frame = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /*Q0*/
     834       27183 :         nSamplesLeftForTD = nSamplesForRendering;                                                                /*Q0*/
     835       27183 :         move16();
     836             : 
     837       81549 :         FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ )
     838             :         {
     839       54366 :             decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[( ch_idx + BINAURAL_CHANNELS )]; /*Q11*/
     840       54366 :             move32();
     841       54366 :             p_tc[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx]; /*Q11*/
     842       54366 :             move32();
     843             :         }
     844             : 
     845       54374 :         WHILE( nSamplesLeftForTD )
     846             :         {
     847       27191 :             Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); /*Q0*/
     848             : 
     849       27191 :             IF( st_ivas->hDiracDecBin[0]->hTdDecorr )
     850             :             {
     851       27191 :                 ivas_td_decorr_process_fx( st_ivas->hDiracDecBin[0]->hTdDecorr, p_tc, decorr_signal, nSamplesToDecorr );
     852             :             }
     853             : 
     854       81573 :             FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ )
     855             :             {
     856       54382 :                 decorr_signal[ch_idx] += nSamplesToDecorr;
     857       54382 :                 p_tc[ch_idx] += nSamplesToDecorr;
     858             :             }
     859       27191 :             nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); /*Q0*/
     860             :         }
     861             :     }
     862             : 
     863             :     /* if we have a late CNG generation, do it here */
     864      181343 :     nchan_transport = st_ivas->nchan_transport; /*Q0*/
     865      181343 :     move16();
     866             : 
     867      181343 :     test();
     868      181343 :     test();
     869      181343 :     test();
     870      181343 :     test();
     871      181343 :     test();
     872      181343 :     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 ) ) ) )
     873             :     {
     874        6108 :         nchan_transport = 1;
     875        6108 :         move16(); /* Only one channel transported */
     876             :     }
     877             : 
     878      181343 :     test();
     879      181343 :     test();
     880      181343 :     test();
     881      181343 :     test();
     882      181343 :     test();
     883      181343 :     test();
     884      181343 :     test();
     885      181343 :     test();
     886      181343 :     test();
     887      181343 :     test();
     888      181343 :     test();
     889      181343 :     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 ) ||
     890             :         ( ( 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 ) ) )
     891             :     {
     892       18831 :         Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
     893       18831 :         Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 2 ) ); /*Q12 -> Q13*/
     894             : 
     895       18831 :         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 );
     896             :     }
     897             : 
     898      181343 :     return;
     899             : }
     900             : 
     901             : /*-------------------------------------------------------------------*
     902             :  * ivas_sba_dec_render()
     903             :  *
     904             :  *
     905             :  *-------------------------------------------------------------------*/
     906             : 
     907      104622 : ivas_error ivas_sba_dec_render_fx(
     908             :     Decoder_Struct *st_ivas,        /* i/o: IVAS decoder handle                       */
     909             :     const UWord16 nSamplesAsked,    /* i  : number of CLDFB slots requested           Q0*/
     910             :     UWord16 *nSamplesRendered,      /* o  : number of CLDFB slots rendered            Q0*/
     911             :     UWord16 *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render     Q0*/
     912             :     Word32 *output_fx[]             /* o  : rendered time signal                      Q11*/
     913             : )
     914             : {
     915             :     Word16 slots_to_render, first_sf, last_sf, subframe_idx;
     916             :     UWord16 slot_size, ch;
     917             :     UWord16 nchan_internal, nchan_out;
     918             :     SPAR_DEC_HANDLE hSpar;
     919             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
     920             :     Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS];
     921             :     ivas_error error;
     922             : 
     923      104622 :     hSpar = st_ivas->hSpar;
     924      104622 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
     925      104622 :     nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
     926      104622 :     nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); /*Q0*/
     927             : 
     928     1130204 :     FOR( ch = 0; ch < nchan_out; ch++ )
     929             :     {
     930     1025582 :         output_f_local_fx[ch] = output_fx[ch]; /*Q11*/
     931             :     }
     932             : 
     933      104622 :     slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/
     934      104622 :     move16();
     935             : 
     936             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
     937      104622 :     slots_to_render = s_min( sub( hSpar->num_slots, hSpar->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); /*Q0*/
     938      104622 :     *nSamplesRendered = imult1616( slots_to_render, slot_size );                                                     /*Q0*/
     939      104622 :     move16();
     940      104622 :     first_sf = hSpar->subframes_rendered; /*Q0*/
     941      104622 :     last_sf = first_sf;                   /*Q0*/
     942      104622 :     move16();
     943      104622 :     move16();
     944      518815 :     WHILE( slots_to_render > 0 )
     945             :     {
     946      414193 :         slots_to_render = sub( slots_to_render, hSpar->subframe_nbslots[last_sf] ); /*Q0*/
     947      414193 :         last_sf = add( last_sf, 1 );
     948             :     }
     949             : 
     950      518815 :     FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
     951             :     {
     952      414193 :         Word16 n_samples_sf = imult1616( slot_size, hSpar->subframe_nbslots[subframe_idx] ); /*Q0*/
     953             : 
     954      414193 :         ivas_spar_dec_upmixer_sf_fx( st_ivas, output_f_local_fx, nchan_internal );
     955     4447801 :         FOR( ch = 0; ch < nchan_out; ch++ )
     956             :         {
     957     4033608 :             output_f_local_fx[ch] = output_f_local_fx[ch] + n_samples_sf; /*Q11*/
     958             :         }
     959             :         /* update combined orientation access index */
     960      414193 :         ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
     961             :     }
     962             : 
     963      104622 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) )
     964             :     {
     965       61954 :         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 ) )
     966             :         {
     967           0 :             return error;
     968             :         }
     969             :     }
     970             : 
     971      104622 :     IF( st_ivas->hDirAC != NULL && EQ_16( hSpar->slots_rendered, hSpar->num_slots ) )
     972             :     {
     973       61122 :         IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) )
     974             :         {
     975       47833 :             hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/
     976       47833 :             move16();
     977             :         }
     978             :         ELSE
     979             :         {
     980       13289 :             hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/
     981       13289 :             move16();
     982             :         }
     983       61122 :         move16();
     984             :     }
     985             : 
     986      104622 :     *nSamplesAvailableNext = imult1616( sub( hSpar->num_slots, hSpar->slots_rendered ), slot_size ); /*Q0*/
     987      104622 :     move16();
     988             : 
     989      104622 :     return IVAS_ERR_OK;
     990             : }

Generated by: LCOV version 1.14