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

Generated by: LCOV version 1.14