LCOV - code coverage report
Current view: top level - lib_dec - ivas_spar_decoder.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 539 566 95.2 %
Date: 2025-09-13 07:56:30 Functions: 20 20 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 <stdint.h>
      34             : #include "options.h"
      35             : #ifdef DEBUGGING
      36             : #include "debug.h"
      37             : #endif
      38             : #include "ivas_stat_dec.h"
      39             : #include "prot.h"
      40             : #include "string.h"
      41             : #include "ivas_prot.h"
      42             : #include "ivas_prot_rend.h"
      43             : #include "ivas_rom_com.h"
      44             : #include "ivas_rom_dec.h"
      45             : #include "ivas_stat_com.h"
      46             : #include <math.h>
      47             : #include <assert.h>
      48             : #include "wmc_auto.h"
      49             : 
      50             : 
      51             : /*-------------------------------------------------------------------*
      52             :  * Local function prototypes
      53             :  *--------------------------------------------------------------------*/
      54             : 
      55             : static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 );
      56             : 
      57             : 
      58             : /*-------------------------------------------------------------------------
      59             :  * ivas_spar_dec_open()
      60             :  *
      61             :  * Allocate and initialize SPAR decoder handle and sub-handles
      62             :  *------------------------------------------------------------------------*/
      63             : 
      64       68517 : ivas_error ivas_spar_dec_open(
      65             :     Decoder_Struct *st_ivas,         /* i/o: IVAS decoder handle        */
      66             :     const int16_t spar_reconfig_flag /* i  : SPAR reconfiguration flag  */
      67             : )
      68             : {
      69             :     SPAR_DEC_HANDLE hSpar;
      70             :     ivas_error error;
      71             :     int16_t sba_order_internal, num_channels_internal;
      72             :     IVAS_FB_CFG *fb_cfg;
      73             :     int16_t i, j, b, active_w_mixing;
      74             :     int32_t output_Fs;
      75             :     int16_t num_decor_chs, map_idx;
      76             : 
      77       68517 :     error = IVAS_ERR_OK;
      78             : 
      79       68517 :     sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER );
      80             : 
      81       68517 :     num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate );
      82             : 
      83       68517 :     hSpar = st_ivas->hSpar;
      84             : 
      85       68517 :     if ( !spar_reconfig_flag )
      86             :     {
      87             :         /* SPAR decoder handle */
      88       43863 :         if ( ( hSpar = (SPAR_DEC_HANDLE) malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL )
      89             :         {
      90           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder" );
      91             :         }
      92             :     }
      93             : 
      94       68517 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
      95       68517 :     if ( num_channels_internal > ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 ) )
      96             :     {
      97        2686 :         num_decor_chs = IVAS_HBR_MAX_DECOR_CHS;
      98             :     }
      99             :     else
     100             :     {
     101       65831 :         num_decor_chs = num_channels_internal - 1;
     102             :     }
     103             : 
     104             :     /* TD decorr. */
     105       68517 :     if ( ( st_ivas->ivas_format == SBA_FORMAT ) && ( ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) || ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_256k && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) ) )
     106             :     {
     107        4212 :         hSpar->hTdDecorr = NULL;
     108             :     }
     109             :     else
     110             :     {
     111       64305 :         if ( ( error = ivas_td_decorr_dec_open( &hSpar->hTdDecorr, output_Fs, num_decor_chs + 1, 1 ) ) != IVAS_ERR_OK )
     112             :         {
     113           0 :             return error;
     114             :         }
     115             :     }
     116             : 
     117             :     /* MD handle */
     118       68517 :     if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal, sba_order_internal, st_ivas->sid_format, st_ivas->last_active_ivas_total_brate ) ) != IVAS_ERR_OK )
     119             :     {
     120           0 :         return error;
     121             :     }
     122       68517 :     hSpar->hMdDec->td_decorr_flag = 1;
     123       68517 :     if ( hSpar->hTdDecorr )
     124             :     {
     125       64305 :         hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[hSpar->hMdDec->table_idx].td_ducking;
     126             :     }
     127             : 
     128             :     /* set FB config. */
     129       68517 :     active_w_mixing = -1;
     130       68517 :     if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, num_channels_internal, num_channels_internal, active_w_mixing, output_Fs, 0 ) ) != IVAS_ERR_OK )
     131             :     {
     132           0 :         return error;
     133             :     }
     134       68517 :     fb_cfg->pcm_offset = NS2SA( output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS );
     135       68517 :     fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order];
     136             : 
     137             :     /* FB mixer handle */
     138       68517 :     if ( ( error = ivas_FB_mixer_open( &hSpar->hFbMixer, output_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK )
     139             :     {
     140           0 :         return error;
     141             :     }
     142             : 
     143             :     /* AGC handle */
     144       68517 :     if ( ( error = ivas_spar_agc_dec_open( &hSpar->hAgcDec, output_Fs ) ) != IVAS_ERR_OK )
     145             :     {
     146           0 :         return error;
     147             :     }
     148             : 
     149             :     /* PCA handle */
     150       68517 :     hSpar->hPCA = NULL;
     151       68517 :     if ( st_ivas->hDecoderConfig->ivas_total_brate == PCA_BRATE && sba_order_internal == 1 )
     152             :     {
     153        1251 :         if ( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL )
     154             :         {
     155           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" );
     156             :         }
     157             : 
     158        1251 :         ivas_pca_dec_init( hSpar->hPCA );
     159             :     }
     160             : 
     161             :     /* mixer_mat intitialization */
     162      394977 :     for ( i = 0; i < num_channels_internal; i++ )
     163             :     {
     164     2105320 :         for ( j = 0; j < num_channels_internal; j++ )
     165             :         {
     166    23125180 :             for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ )
     167             :             {
     168    21346320 :                 hSpar->hMdDec->mixer_mat[i][j][b] = 0.0f;
     169   128077920 :                 for ( int16_t i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ )
     170             :                 {
     171   106731600 :                     hSpar->hMdDec->mixer_mat_prev[i_ts][i][j][b] = 0.0f;
     172             :                 }
     173             :             }
     174             :         }
     175             :     }
     176       68517 :     hSpar->i_subframe = 0;
     177       68517 :     hSpar->AGC_flag = 0;
     178             : 
     179             :     /*-----------------------------------------------------------------*
     180             :      * Configuration - set SPAR high-level parameters
     181             :      *-----------------------------------------------------------------*/
     182             : 
     183       68517 :     ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format );
     184             : 
     185       68517 :     switch ( sba_order_internal )
     186             :     {
     187       56315 :         case 1:
     188       56315 :             st_ivas->transport_config = IVAS_AUDIO_CONFIG_FOA;
     189       56315 :             break;
     190        5450 :         case 2:
     191        5450 :             st_ivas->transport_config = IVAS_AUDIO_CONFIG_HOA2;
     192        5450 :             break;
     193        6752 :         case 3:
     194        6752 :             st_ivas->transport_config = IVAS_AUDIO_CONFIG_HOA3;
     195        6752 :             break;
     196             :     }
     197             : 
     198       68517 :     ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config );
     199             : 
     200       68517 :     set_s( hSpar->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
     201       68517 :     set_s( hSpar->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
     202       68517 :     hSpar->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
     203       68517 :     hSpar->subframes_rendered = 0;
     204       68517 :     hSpar->slots_rendered = 0;
     205       68517 :     hSpar->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
     206             : 
     207             :     /* init render timeslot mapping */
     208       68517 :     set_s( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
     209     1164789 :     for ( map_idx = 0; map_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; map_idx++ )
     210             :     {
     211     1096272 :         hSpar->render_to_md_map[map_idx] = map_idx;
     212             :     }
     213             : 
     214             :     /* allocate transport channels*/
     215       68517 :     if ( st_ivas->hTcBuffer == NULL )
     216             :     {
     217             :         int16_t nchan_to_allocate;
     218             :         int16_t nchan_tc;
     219             :         TC_BUFFER_MODE buffer_mode;
     220             :         int16_t granularity;
     221             : 
     222       43863 :         buffer_mode = TC_BUFFER_MODE_RENDERER;
     223       43863 :         nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas );
     224       43863 :         nchan_to_allocate = num_channels_internal;
     225             : 
     226       43863 :         if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC )
     227             :         {
     228       11798 :             nchan_to_allocate += st_ivas->nchan_ism;
     229             :         }
     230             : 
     231       43863 :         if ( ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) )
     232             :         {
     233        5534 :             if ( ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) )
     234             :             {
     235         760 :                 nchan_tc = st_ivas->hDecoderConfig->nchan_out + st_ivas->nchan_ism;
     236         760 :                 nchan_to_allocate = nchan_tc;
     237             :             }
     238             :             else
     239             :             {
     240        4774 :                 buffer_mode = TC_BUFFER_MODE_BUFFER;
     241        4774 :                 nchan_tc = st_ivas->hDecoderConfig->nchan_out;
     242        4774 :                 nchan_to_allocate = nchan_tc;
     243             :             }
     244             :         }
     245       38329 :         else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
     246             :         {
     247        7492 :             nchan_to_allocate = 2 * BINAURAL_CHANNELS;
     248             :         }
     249             : 
     250       43863 :         granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, ivas_renderer_secondary_select( st_ivas ), output_Fs );
     251             : 
     252       43863 :         if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK )
     253             :         {
     254           0 :             return error;
     255             :         }
     256             :     }
     257             : 
     258       68517 :     st_ivas->hSpar = hSpar;
     259             : 
     260       68517 :     return error;
     261             : }
     262             : 
     263             : 
     264             : /*-------------------------------------------------------------------------
     265             :  * ivas_spar_dec_close()
     266             :  *
     267             :  * Deallocate SPAR handle
     268             :  *------------------------------------------------------------------------*/
     269             : 
     270      109294 : void ivas_spar_dec_close(
     271             :     SPAR_DEC_HANDLE *hSpar,          /* i/o: SPAR decoder handle        */
     272             :     const int32_t output_Fs,         /* i  : output sampling rate       */
     273             :     const int16_t spar_reconfig_flag /* i  : SPAR reconfiguration flag  */
     274             : )
     275             : {
     276      109294 :     if ( hSpar == NULL || *hSpar == NULL )
     277             :     {
     278       40777 :         return;
     279             :     }
     280             : 
     281             :     /* MD handle */
     282       68517 :     ivas_spar_md_dec_close( &( *hSpar )->hMdDec );
     283             : 
     284             :     /* TD decorrelator handle */
     285       68517 :     ivas_td_decorr_dec_close( &( *hSpar )->hTdDecorr );
     286             : 
     287             :     /* FB mixer handle */
     288       68517 :     ivas_FB_mixer_close( &( *hSpar )->hFbMixer, output_Fs, spar_reconfig_flag );
     289             : 
     290             :     /* AGC */
     291       68517 :     ivas_spar_agc_dec_close( &( *hSpar )->hAgcDec );
     292             : 
     293             :     /* PCA */
     294       68517 :     if ( ( *hSpar )->hPCA != NULL )
     295             :     {
     296        1071 :         free( ( *hSpar )->hPCA );
     297        1071 :         ( *hSpar )->hPCA = NULL;
     298             :     }
     299             : 
     300       68517 :     if ( !spar_reconfig_flag )
     301             :     {
     302       43863 :         free( ( *hSpar ) );
     303       43863 :         ( *hSpar ) = NULL;
     304             :     }
     305             : 
     306       68517 :     return;
     307             : }
     308             : 
     309             : 
     310             : /*-------------------------------------------------------------------*
     311             :  * ivas_spar_dec()
     312             :  *
     313             :  * Principal IVAS SPAR decoder routine
     314             :  *-------------------------------------------------------------------*/
     315             : 
     316     7090223 : ivas_error ivas_spar_dec(
     317             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct             */
     318             :     int16_t *nb_bits_read    /* o  : number of MD bits read          */
     319             : )
     320             : {
     321             :     DECODER_CONFIG_HANDLE hDecoderConfig;
     322             :     int16_t i, nb_bits_read_orig;
     323             :     Decoder_State *st0;
     324             :     int16_t next_bit_pos_orig, last_bit_pos;
     325             :     uint16_t bstr_meta[MAX_BITS_METADATA], *bit_stream_orig;
     326             :     ivas_error error;
     327             : 
     328     7090223 :     push_wmops( "ivas_spar_decode" );
     329     7090223 :     error = IVAS_ERR_OK;
     330     7090223 :     hDecoderConfig = st_ivas->hDecoderConfig;
     331             : 
     332     7090223 :     st0 = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
     333     7090223 :     bit_stream_orig = st0->bit_stream;
     334     7090223 :     next_bit_pos_orig = st0->next_bit_pos;
     335             : 
     336     7090223 :     if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
     337             :     {
     338     1962338 :         last_bit_pos = (int16_t) ( ( hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 ) - nb_bits_read[1];
     339             :     }
     340             :     else
     341             :     {
     342     5127885 :         *nb_bits_read = 0;
     343     5127885 :         last_bit_pos = 0;
     344             :     }
     345             : 
     346             :     /* read DirAC bitstream */
     347     7090223 :     if ( st_ivas->hQMetaData != NULL )
     348             :     {
     349     7090223 :         ivas_dirac_dec_read_BS( hDecoderConfig->ivas_total_brate, st0, st_ivas->hDirAC, st_ivas->hSpatParamRendCom, st_ivas->hQMetaData, nb_bits_read, last_bit_pos, ivas_get_hodirac_flag( hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ), st_ivas->nchan_transport, st_ivas->hSpar->dirac_to_spar_md_bands );
     350             :     }
     351             : 
     352     7090223 :     if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
     353             :     {
     354     1962338 :         last_bit_pos = (int16_t) ( ( hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 ) - nb_bits_read[1];
     355             :     }
     356             :     else
     357             :     {
     358     5127885 :         last_bit_pos = (int16_t) ( ( hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 );
     359             :     }
     360             : 
     361     7090223 :     if ( !st0->bfi && hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 )
     362             :     {
     363        2616 :         last_bit_pos -= ( SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS );
     364             :     }
     365     7090223 :     nb_bits_read_orig = *nb_bits_read;
     366     7090223 :     last_bit_pos -= nb_bits_read_orig;
     367             : 
     368             :     /* reverse the bitstream for easier reading of indices */
     369 10387132380 :     for ( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ )
     370             :     {
     371 10380042157 :         bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
     372             :     }
     373     7090223 :     st0->bit_stream = bstr_meta;
     374     7090223 :     st0->next_bit_pos = 0;
     375     7090223 :     st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 );
     376             : 
     377     7090223 :     if ( !st0->bfi )
     378             :     {
     379     6292299 :         st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */
     380             :     }
     381             : 
     382             :     /*---------------------------------------------------------------------*
     383             :      * Decode SPAR metadata
     384             :      *---------------------------------------------------------------------*/
     385             : 
     386     7090223 :     if ( ( error = ivas_spar_dec_MD( st_ivas, st0 ) ) != IVAS_ERR_OK )
     387             :     {
     388           0 :         return error;
     389             :     }
     390             : 
     391     7090223 :     *nb_bits_read = st0->next_bit_pos + nb_bits_read_orig;
     392     7090223 :     st0->bit_stream = bit_stream_orig;
     393     7090223 :     st0->next_bit_pos = next_bit_pos_orig;
     394             : 
     395     7090223 :     if ( !st0->bfi && hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 )
     396             :     {
     397             :         int16_t zero_pad_bits;
     398        2616 :         *nb_bits_read += SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS;
     399        2616 :         zero_pad_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - *nb_bits_read;
     400        2616 :         assert( zero_pad_bits <= 1 );
     401        2616 :         *nb_bits_read += zero_pad_bits;
     402             :     }
     403             : 
     404     7090223 :     pop_wmops();
     405             : 
     406     7090223 :     return error;
     407             : }
     408             : 
     409             : 
     410             : /*---------------------------------------------------------------------*
     411             :  * Function ivas_get_spar_table_idx_from_coded_idx()
     412             :  *
     413             :  * Get SPAR table index
     414             :  *---------------------------------------------------------------------*/
     415             : 
     416     6275913 : static int16_t ivas_get_spar_table_idx_from_coded_idx(
     417             :     const int32_t ivas_total_brate, /* i  : IVAS total bitrate                              */
     418             :     const int16_t sba_order,        /* i  : Ambisonic (SBA) order                           */
     419             :     Decoder_State *st0,             /* i/o: decoder state structure - for bitstream handling*/
     420             :     int16_t *bitlen                 /* o  : number of bits                                  */
     421             : )
     422             : {
     423             :     int16_t table_idx, ind1[IVAS_SPAR_BR_TABLE_LEN];
     424             :     int16_t i, j, ind2;
     425             : 
     426     6275913 :     j = 0;
     427   131794173 :     for ( i = 0; i < IVAS_SPAR_BR_TABLE_LEN; i++ )
     428             :     {
     429   125518260 :         ind1[j] = 0;
     430   125518260 :         if ( ( ivas_spar_br_table_consts[i].ivas_total_brate == ivas_total_brate ) && ( ivas_spar_br_table_consts[i].sba_order == sba_order ) )
     431             :         {
     432     6275913 :             ind1[j++] = i;
     433             :         }
     434             :     }
     435             : 
     436     6275913 :     assert( j > 0 );
     437     6275913 :     *bitlen = ivas_get_bits_to_encode( j - 1 );
     438             : 
     439     6275913 :     ind2 = get_next_indice( st0, *bitlen );
     440             : 
     441     6275913 :     table_idx = ind1[ind2];
     442             : 
     443     6275913 :     return table_idx;
     444             : }
     445             : 
     446             : 
     447             : /*---------------------------------------------------------------------*
     448             :  * Function ivas_parse_spar_header()
     449             :  *
     450             :  * Get SPAR table index
     451             :  *---------------------------------------------------------------------*/
     452             : 
     453     6275913 : static int16_t ivas_parse_spar_header(
     454             :     const int32_t ivas_total_brate, /* i  : IVAS total bitrate                              */
     455             :     const int16_t sba_order,        /* i  : Ambisonic (SBA) order                           */
     456             :     Decoder_State *st0,             /* i/o: decoder state structure - for bitstream handling*/
     457             :     int16_t *table_idx )
     458             : {
     459             :     int16_t bitlen, bwidth;
     460             : 
     461     6275913 :     *table_idx = ivas_get_spar_table_idx_from_coded_idx( ivas_total_brate, sba_order, st0, &bitlen );
     462             : 
     463     6275913 :     bwidth = ivas_spar_br_table_consts[( *table_idx )].bwidth;
     464             : 
     465     6275913 :     return bwidth;
     466             : }
     467             : 
     468             : 
     469    24371760 : static float get_random_number(
     470             :     int16_t *seed )
     471             : {
     472    24371760 :     float x = (float) own_random( seed ) / 32768.0f;
     473             : 
     474    24371760 :     return x;
     475             : }
     476             : 
     477             : 
     478      578196 : static float matrix_det(
     479             :     const float a00,
     480             :     const float a01,
     481             :     const float a10,
     482             :     const float a11 )
     483             : {
     484      578196 :     return a00 * a11 - a01 * a10;
     485             : }
     486             : 
     487             : 
     488       48183 : static void matrix_inverse(
     489             :     float in[3][3],
     490             :     float out[3][3],
     491             :     const int16_t size )
     492             : {
     493             :     float det, fac;
     494       48183 :     float eps = 1e-16f;
     495             : 
     496       48183 :     if ( size == 1 )
     497             :     {
     498           0 :         out[0][0] = 1.0f / max( in[0][0], eps );
     499             : 
     500           0 :         return;
     501             :     }
     502       48183 :     else if ( size == 2 )
     503             :     {
     504           0 :         det = matrix_det( in[0][1], in[0][1], in[1][0], in[1][1] );
     505           0 :         fac = 1.0f / max( det, eps );
     506             : 
     507           0 :         out[0][0] = in[1][1] * fac;
     508           0 :         out[1][0] = in[1][0] * ( -fac );
     509             : 
     510           0 :         out[0][1] = in[0][1] * ( -fac );
     511           0 :         out[1][1] = in[0][0] * fac;
     512             : 
     513           0 :         return;
     514             :     }
     515             : 
     516       48183 :     det = in[0][0] * matrix_det( in[1][1], in[1][2], in[2][1], in[2][2] ) - in[1][0] * matrix_det( in[0][1], in[0][2], in[2][1], in[2][2] ) + in[2][0] * matrix_det( in[0][1], in[0][2], in[1][1], in[1][2] );
     517       48183 :     fac = 1.0f / max( det, eps );
     518             : 
     519       48183 :     out[0][0] = matrix_det( in[1][1], in[1][2], in[2][1], in[2][2] ) * fac;
     520       48183 :     out[1][0] = matrix_det( in[1][0], in[1][2], in[2][0], in[2][2] ) * ( -fac );
     521       48183 :     out[2][0] = matrix_det( in[1][0], in[1][1], in[2][0], in[2][1] ) * fac;
     522             : 
     523       48183 :     out[0][1] = matrix_det( in[0][1], in[0][2], in[2][1], in[2][2] ) * ( -fac );
     524       48183 :     out[1][1] = matrix_det( in[0][0], in[0][2], in[2][0], in[2][2] ) * fac;
     525       48183 :     out[2][1] = matrix_det( in[0][0], in[0][1], in[2][0], in[2][1] ) * ( -fac );
     526             : 
     527       48183 :     out[0][2] = matrix_det( in[0][1], in[0][2], in[1][1], in[1][2] ) * fac;
     528       48183 :     out[1][2] = matrix_det( in[0][0], in[0][2], in[1][0], in[1][2] ) * ( -fac );
     529       48183 :     out[2][2] = matrix_det( in[0][0], in[0][1], in[1][0], in[1][1] ) * fac;
     530             : 
     531       48183 :     return;
     532             : }
     533             : 
     534             : 
     535             : /*---------------------------------------------------------------------*
     536             :  * Function ivas_spar_get_cldfb_gains()
     537             :  *
     538             :  *
     539             :  *---------------------------------------------------------------------*/
     540             : 
     541       48183 : void ivas_spar_get_cldfb_gains(
     542             :     SPAR_DEC_HANDLE hSpar,
     543             :     HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0,
     544             :     HANDLE_CLDFB_FILTER_BANK cldfbSynDec0,
     545             :     const DECODER_CONFIG_HANDLE hDecoderConfig )
     546             : {
     547       48183 :     float output_Fs = (float) hDecoderConfig->output_Fs;
     548             :     int16_t pt_len, stride, num_cldfb_bands, decfb_delay;
     549             :     int16_t encfb_delay, cf_start, cf_end, cf_len;
     550             :     float *weights;
     551             :     int16_t ts, cf_cldfb_start, cf_cldfb_end;
     552             :     float cf_start_s, cf_len_s;
     553             :     int16_t sample, num_cf_slots, num_samples;
     554             :     float T[3 * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX - CLDFB_NO_CHANNELS_MAX][3];
     555             :     float Tt_T[3][3];
     556             :     float Tt_T_inv[3][3];
     557             :     float Tt_tgt[3];
     558             :     float ts_inout[CLDFB_NO_CHANNELS_MAX];
     559             :     float ts_re[CLDFB_NO_CHANNELS_MAX];
     560             :     float ts_im[CLDFB_NO_CHANNELS_MAX];
     561             :     float *pp_ts_im[1], *pp_ts_re[1];
     562             :     float tgt[( 3 - 1 ) * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX];
     563             :     int16_t seed, split_band, slot_row, slot_col, slot, tmp_idx;
     564             : 
     565       48183 :     pt_len = cldfbAnaDec0->p_filter_length;
     566       48183 :     num_cldfb_bands = cldfbAnaDec0->no_channels;
     567             : 
     568       48183 :     stride = NS2SA( output_Fs, DELAY_CLDFB_NS );
     569       48183 :     encfb_delay = NS2SA( output_Fs, IVAS_FB_ENC_DELAY_NS );
     570       48183 :     decfb_delay = NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS );
     571             : 
     572       48183 :     cf_start = (int16_t) hSpar->hFbMixer->cross_fade_start_offset - encfb_delay + decfb_delay; /* time domain after CLDFB synthesis*/
     573       48183 :     cf_end = (int16_t) hSpar->hFbMixer->cross_fade_end_offset - encfb_delay + decfb_delay;
     574       48183 :     cf_len = cf_end - cf_start;
     575       48183 :     weights = hSpar->hFbMixer->cldfb_cross_fade;
     576             : 
     577       48183 :     cf_cldfb_start = (int16_t) ceil( ( cf_start - decfb_delay / 2 ) / (float) stride - 0.5f );
     578       48183 :     cf_cldfb_end = (int16_t) ( ( cf_start - decfb_delay / 2 + cf_len ) / (float) stride - 0.5f );
     579             : 
     580       48183 :     num_cf_slots = cf_cldfb_end - cf_cldfb_start + 1;
     581       48183 :     num_samples = num_cf_slots * stride + pt_len - stride;
     582       48183 :     seed = RANDOM_INITSEED;
     583       48183 :     split_band = SPAR_DIRAC_SPLIT_START_BAND;
     584       48183 :     pp_ts_im[0] = ts_im;
     585       48183 :     pp_ts_re[0] = ts_re;
     586       48183 :     set_f( tgt, 0, ( 3 - 1 ) * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX );
     587             : 
     588       48183 :     cf_start_s = ( cf_start - decfb_delay / 2 ) / output_Fs;
     589       48183 :     cf_len_s = hSpar->hFbMixer->cross_fade_end_offset / output_Fs - hSpar->hFbMixer->cross_fade_start_offset / output_Fs;
     590             : 
     591      819111 :     for ( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ )
     592             :     {
     593      770928 :         weights[ts] = ( ( ( ts + 0.5f ) * stride / output_Fs ) - cf_start_s ) / cf_len_s;
     594      770928 :         weights[ts] = max( min( weights[ts], 1.0f ), 0.0f );
     595             :     }
     596       48183 :     hSpar->hFbMixer->cldfb_cross_fade_start = cf_cldfb_start;
     597       48183 :     hSpar->hFbMixer->cldfb_cross_fade_end = cf_cldfb_end;
     598             : 
     599       48183 :     if ( num_cf_slots > 3 || pt_len > 10 * CLDFB_NO_CHANNELS_MAX || stride > CLDFB_NO_CHANNELS_MAX || split_band == IVAS_MAX_NUM_BANDS )
     600             :     {
     601           0 :         return;
     602             :     }
     603             : 
     604             :     /* optimization*/
     605             :     /* compute time-domain cross-fade for considered time slots*/
     606       48183 :     tmp_idx = cf_start - cf_cldfb_start * stride;
     607     6547319 :     for ( sample = 0; sample < cf_len; sample++ )
     608             :     {
     609             :         /* increasing window function */
     610     6499136 :         tgt[tmp_idx++] = hSpar->hFbMixer->pFilterbank_cross_fade[sample];
     611             :     }
     612             : 
     613    14671239 :     for ( ; tmp_idx < num_samples; tmp_idx++ )
     614             :     {
     615             :         /* fill up with ones*/
     616    14623056 :         tgt[tmp_idx] = 1.0f;
     617             :     }
     618             : 
     619    24419943 :     for ( sample = 0; sample < num_samples; sample++ )
     620             :     {
     621             :         /* initialize trasnform matrix with zeros*/
     622    24371760 :         T[sample][0] = T[sample][1] = T[sample][2] = 0.0f;
     623             :     }
     624             : 
     625    18327003 :     for ( sample = 0; sample < pt_len - stride; sample++ )
     626             :     {
     627             :         /* fill internal CLDFB analysis time buffer with data*/
     628    18278820 :         float x = get_random_number( &seed );
     629             : 
     630    18278820 :         cldfbAnaDec0->cldfb_state[sample] = x;
     631             :     }
     632             : 
     633      192732 :     for ( slot = 0; slot < num_cf_slots; slot++ )
     634             :     {
     635     6237489 :         for ( sample = 0; sample < stride; sample++ )
     636             :         {
     637     6092940 :             float x = get_random_number( &seed );
     638     6092940 :             ts_inout[sample] = x;
     639             :         }
     640             : 
     641      144549 :         cldfbAnalysis_ts( ts_inout, ts_re, ts_im, num_cldfb_bands, cldfbAnaDec0 );
     642      144549 :         cldfb_reset_memory( cldfbSynDec0 );
     643      144549 :         cldfbSynthesis( pp_ts_re, pp_ts_im, ts_inout, num_cldfb_bands, cldfbSynDec0 );
     644             : 
     645     6237489 :         for ( sample = 0; sample < stride; sample++ )
     646             :         {
     647     6092940 :             T[slot * stride + sample][slot] = ts_inout[sample];
     648             :         }
     649             : 
     650      144549 :         tmp_idx = pt_len - 1;
     651    54981009 :         for ( sample = stride; sample < pt_len; sample++ )
     652             :         {
     653    54836460 :             T[slot * stride + sample][slot] = cldfbSynDec0->cldfb_state[tmp_idx--];
     654             :         }
     655             :     }
     656             : 
     657             :     /* target is synthesis output times the cross-fade window*/
     658    24419943 :     for ( sample = 0; sample < num_samples; sample++ )
     659             :     {
     660    24371760 :         tgt[sample] *= ( T[sample][0] + T[sample][1] + T[sample][2] );
     661             :     }
     662             : 
     663             :     /* compute matrices */
     664      192732 :     for ( slot_row = 0; slot_row < num_cf_slots; slot_row++ )
     665             :     {
     666      433647 :         for ( slot_col = slot_row; slot_col < num_cf_slots; slot_col++ )
     667             :         {
     668      289098 :             Tt_T[slot_row][slot_col] = 0.0f;
     669   146519658 :             for ( sample = 0; sample < num_samples; sample++ )
     670             :             {
     671   146230560 :                 Tt_T[slot_row][slot_col] += T[sample][slot_row] * T[sample][slot_col];
     672             :             }
     673             :         }
     674             :     }
     675             : 
     676       48183 :     Tt_T[1][0] = Tt_T[0][1];
     677       48183 :     Tt_T[2][0] = Tt_T[0][2];
     678       48183 :     Tt_T[2][1] = Tt_T[1][2];
     679             : 
     680      192732 :     for ( slot_row = 0; slot_row < num_cf_slots; slot_row++ )
     681             :     {
     682      144549 :         Tt_tgt[slot_row] = 0.0f;
     683    73259829 :         for ( sample = 0; sample < num_samples; sample++ )
     684             :         {
     685    73115280 :             Tt_tgt[slot_row] += T[sample][slot_row] * tgt[sample];
     686             :         }
     687             :     }
     688             : 
     689       48183 :     matrix_inverse( Tt_T, Tt_T_inv, num_cf_slots );
     690             : 
     691             :     /* compute the optimal coefficients */
     692      192732 :     for ( slot_row = 0; slot_row < num_cf_slots; slot_row++ )
     693             :     {
     694      144549 :         float tmp = 0.0f;
     695      578196 :         for ( slot_col = 0; slot_col < num_cf_slots; slot_col++ )
     696             :         {
     697      433647 :             tmp += Tt_T_inv[slot_row][slot_col] * Tt_tgt[slot_col];
     698             :         }
     699      144549 :         weights[cf_cldfb_start + slot_row] = max( min( tmp, 1.0f ), 0.0f );
     700             :     }
     701             : 
     702       48183 :     cldfb_reset_memory( cldfbSynDec0 );
     703       48183 :     cldfb_reset_memory( cldfbAnaDec0 );
     704             : 
     705       48183 :     return;
     706             : }
     707             : 
     708             : 
     709             : /*---------------------------------------------------------------------*
     710             :  * Function ivas_is_res_channel()
     711             :  *
     712             :  * determines if an FOA input channel is transmitted as residual channel.
     713             :  *---------------------------------------------------------------------*/
     714             : 
     715             : /*! r: 1 if prediction residual channel */
     716  5676502020 : int16_t ivas_is_res_channel(
     717             :     const int16_t ch,             /* i  : ch index in WYZX ordering          */
     718             :     const int16_t nchan_transport /* i  : number of transport channels (1-4) */
     719             : )
     720             : {
     721  5676502020 :     const int16_t rc_map[FOA_CHANNELS][FOA_CHANNELS] = {
     722             :         { 0, 0, 0, 0 },
     723             :         { 0, 1, 0, 0 },
     724             :         { 0, 1, 0, 1 },
     725             :         { 0, 1, 1, 1 }
     726             :     };
     727             : 
     728  5676502020 :     if ( ch >= FOA_CHANNELS )
     729             :     {
     730             :         /* never transmitted */
     731   486575808 :         return 0;
     732             :     }
     733  5189926212 :     assert( nchan_transport <= FOA_CHANNELS );
     734             : 
     735  5189926212 :     return ( rc_map[nchan_transport - 1][ch] );
     736             : }
     737             : 
     738             : 
     739             : /*-------------------------------------------------------------------*
     740             :  * ivas_spar_dec_MD()
     741             :  *
     742             :  * IVAS SPAR MD decoder
     743             :  *-------------------------------------------------------------------*/
     744             : 
     745     7090223 : static ivas_error ivas_spar_dec_MD(
     746             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle                             */
     747             :     Decoder_State *st0       /* i/o: decoder state structure - for bitstream handling*/
     748             : )
     749             : {
     750             :     int16_t num_channels, table_idx, num_bands_out, bfi, sba_order;
     751             :     int32_t ivas_total_brate;
     752             :     int16_t num_md_sub_frames;
     753             :     ivas_error error;
     754     7090223 :     DECODER_CONFIG_HANDLE hDecoderConfig = st_ivas->hDecoderConfig;
     755     7090223 :     SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
     756             : 
     757     7090223 :     push_wmops( "ivas_spar_dec_MD" );
     758             : 
     759             :     /*---------------------------------------------------------------------*
     760             :      * Initialization
     761             :      *---------------------------------------------------------------------*/
     762             : 
     763     7090223 :     sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER );
     764     7090223 :     bfi = st_ivas->bfi;
     765     7090223 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     766     7090223 :     num_channels = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate );
     767     7090223 :     num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate );
     768             : 
     769     7090223 :     num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands;
     770             : 
     771     7090223 :     if ( ivas_total_brate > FRAME_NO_DATA && !bfi )
     772             :     {
     773     6278529 :         if ( ivas_total_brate > IVAS_SID_5k2 )
     774             :         {
     775     6275913 :             ivas_parse_spar_header( hDecoderConfig->ivas_total_brate, sba_order, st0, &table_idx );
     776             : 
     777     6275913 :             if ( hSpar->hMdDec->spar_hoa_md_flag )
     778             :             {
     779      634374 :                 hSpar->hMdDec->spar_md.num_bands = IVAS_MAX_NUM_BANDS;
     780             :             }
     781             :             else
     782             :             {
     783     5641539 :                 hSpar->hMdDec->spar_md.num_bands = min( SPAR_DIRAC_SPLIT_START_BAND, IVAS_MAX_NUM_BANDS );
     784             :             }
     785             : 
     786     6275913 :             if ( hSpar->hMdDec->table_idx != table_idx )
     787             :             {
     788        4484 :                 hSpar->hMdDec->table_idx = table_idx;
     789        4484 :                 if ( hSpar->hTdDecorr )
     790             :                 {
     791        4118 :                     hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking;
     792             :                 }
     793             : 
     794        4484 :                 if ( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels, sba_order ) ) != IVAS_ERR_OK )
     795             :                 {
     796           0 :                     return error;
     797             :                 }
     798             :             }
     799             :         }
     800             : 
     801             :         /*---------------------------------------------------------------------*
     802             :          * Decode MD
     803             :          *---------------------------------------------------------------------*/
     804             : 
     805     6278529 :         ivas_spar_md_dec_process( st_ivas, st0, num_bands_out, sba_order );
     806             : 
     807             :         /*---------------------------------------------------------------------*
     808             :          * read PCA bits
     809             :          *---------------------------------------------------------------------*/
     810             : 
     811     6278529 :         if ( hSpar->hPCA != NULL )
     812             :         {
     813      504820 :             ivas_pca_read_bits( st0, hSpar->hPCA );
     814             :         }
     815             : 
     816             :         /*---------------------------------------------------------------------*
     817             :          * Read AGC bits
     818             :          *---------------------------------------------------------------------*/
     819             : 
     820     6278529 :         if ( ivas_total_brate > IVAS_SID_5k2 && !bfi && hSpar->hMdDec->dtx_vad )
     821             :         {
     822     6266559 :             if ( hSpar->hMdDec->spar_md_cfg.nchan_transport == 1 )
     823             :             {
     824     2015984 :                 hSpar->AGC_flag = get_next_indice( st0, 1 );
     825             :             }
     826             : 
     827     6266559 :             ivas_agc_read_bits( hSpar->hAgcDec, st0, hSpar->hMdDec->spar_md_cfg.nchan_transport, hSpar->AGC_flag );
     828             :         }
     829             : 
     830             :         /*---------------------------------------------------------------------*
     831             :          * MD smoothing
     832             :          *---------------------------------------------------------------------*/
     833             : 
     834     6278529 :         if ( st0->m_old_frame_type == ZERO_FRAME && ivas_total_brate == IVAS_SID_5k2 && st0->prev_bfi == 0 && hSpar->hMdDec->spar_md_cfg.nchan_transport == 1 )
     835             :         {
     836         823 :             ivas_spar_setup_md_smoothing( hSpar->hMdDec, num_bands_out, num_md_sub_frames );
     837             :         }
     838             :         else
     839             :         {
     840     6277706 :             ivas_spar_update_md_hist( hSpar->hMdDec );
     841             :         }
     842             :     }
     843             :     else
     844             :     {
     845      811694 :         if ( !bfi )
     846             :         {
     847       13770 :             ivas_spar_smooth_md_dtx( hSpar->hMdDec, num_bands_out, num_md_sub_frames );
     848             :         }
     849             : 
     850      811694 :         set_s( hSpar->hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS );
     851             :     }
     852             : 
     853     7090223 :     pop_wmops();
     854     7090223 :     return IVAS_ERR_OK;
     855             : }
     856             : 
     857             : 
     858             : /*-------------------------------------------------------------------*
     859             :  * ivas_spar_get_cldfb_slot_gain()
     860             :  *
     861             :  *
     862             :  *-------------------------------------------------------------------*/
     863             : 
     864   106633952 : static float ivas_spar_get_cldfb_slot_gain(
     865             :     SPAR_DEC_HANDLE hSpar,                      /* i/o: SPAR decoder handle     */
     866             :     const DECODER_CONFIG_HANDLE hDecoderConfig, /* i  : configuration structure */
     867             :     const int16_t time_slot_idx,
     868             :     int16_t *time_slot_idx0,
     869             :     int16_t *time_slot_idx1,
     870             :     float *weight_lowfreq )
     871             : {
     872             :     float weight;
     873             :     float output_Fs, encfb_delay, decfb_delay;
     874             :     float xfade_start_ns;
     875             :     int16_t xfade_delay_subframes;
     876             :     int16_t i_hist;
     877             :     int16_t split_band;
     878             : 
     879   106633952 :     *weight_lowfreq = hSpar->hFbMixer->cldfb_cross_fade[time_slot_idx];
     880             : 
     881   106633952 :     output_Fs = (float) hDecoderConfig->output_Fs;
     882   106633952 :     encfb_delay = IVAS_FB_ENC_DELAY_NS;
     883   106633952 :     decfb_delay = IVAS_FB_DEC_DELAY_NS;
     884   106633952 :     xfade_start_ns = hSpar->hFbMixer->cross_fade_start_offset / output_Fs * 1000000000.f - encfb_delay + decfb_delay * 0.5f;
     885   106633952 :     xfade_delay_subframes = (int16_t) ( xfade_start_ns / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) );
     886             : 
     887   106633952 :     i_hist = 4 - xfade_delay_subframes;
     888   106633952 :     split_band = SPAR_DIRAC_SPLIT_START_BAND;
     889             : 
     890   106633952 :     if ( split_band < IVAS_MAX_NUM_BANDS )
     891             :     {
     892   106633952 :         if ( hSpar->i_subframe > 3 )
     893             :         {
     894   105684016 :             weight = (float) ( time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES ) / (float) MAX_PARAM_SPATIAL_SUBFRAMES;
     895             :         }
     896             :         else
     897             :         {
     898      949936 :             weight = 0.0f;
     899             :         }
     900   106633952 :         *time_slot_idx0 = i_hist;
     901   106633952 :         *time_slot_idx1 = i_hist + 1;
     902             :     }
     903             :     else
     904             :     {
     905             :         /* determine cross-fade gain for current frame Parameters*/
     906           0 :         *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start;
     907           0 :         *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end;
     908           0 :         weight = *weight_lowfreq;
     909             :     }
     910             : 
     911   106633952 :     return weight;
     912             : }
     913             : 
     914             : 
     915             : /*-------------------------------------------------------------------*
     916             :  * ivas_spar_get_parameters()
     917             :  *
     918             :  *
     919             :  *-------------------------------------------------------------------*/
     920             : 
     921   106633952 : void ivas_spar_get_parameters(
     922             :     SPAR_DEC_HANDLE hSpar,                      /* i/o: SPAR decoder handle     */
     923             :     const DECODER_CONFIG_HANDLE hDecoderConfig, /* i  : configuration structure */
     924             :     const int16_t ts,
     925             :     const int16_t num_ch_out,
     926             :     const int16_t num_ch_in,
     927             :     const int16_t num_spar_bands,
     928             :     float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] )
     929             : {
     930             :     int16_t spar_band, out_ch, in_ch;
     931             :     float weight, weight_20ms;
     932             :     int16_t ts0, ts1, split_band;
     933             : 
     934   106633952 :     weight = ivas_spar_get_cldfb_slot_gain( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms );
     935             : 
     936   106633952 :     split_band = SPAR_DIRAC_SPLIT_START_BAND;
     937  1335644672 :     for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
     938             :     {
     939  6631629408 :         for ( out_ch = 0; out_ch < num_ch_out; out_ch++ )
     940             :         {
     941  5402618688 :             if ( split_band < IVAS_MAX_NUM_BANDS
     942             :                  /* 20ms cross-fade for Transport channels in all frequency bands */
     943  5402618688 :                  && ( 0 == ivas_is_res_channel( out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/
     944             :             )
     945             :             {
     946 21777096900 :                 for ( in_ch = 0; in_ch < num_ch_in; in_ch++ )
     947             :                 {
     948 18017505168 :                     if ( hSpar->i_subframe > 3 )
     949             :                     {
     950 17821442960 :                         par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] +
     951 17821442960 :                                                             weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band];
     952             :                     }
     953             :                     else
     954             :                     {
     955   196062208 :                         par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band];
     956             :                     }
     957             :                 }
     958             :             }
     959             :             else
     960             :             {
     961  9674862204 :                 for ( in_ch = 0; in_ch < num_ch_in; in_ch++ )
     962             :                 {
     963             :                     /* 20ms Transport channel reconstruction with matching encoder/decoder processing */
     964  8031835248 :                     int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */
     965  8031835248 :                     par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band];
     966             :                 }
     967             :             }
     968             :         }
     969             :     }
     970             : 
     971   106633952 :     return;
     972             : }
     973             : 
     974             : 
     975             : /*-------------------------------------------------------------------*
     976             :  * ivas_spar_get_skip_mat()
     977             :  *
     978             :  *
     979             :  *-------------------------------------------------------------------*/
     980             : 
     981    23416977 : static void ivas_spar_get_skip_mat(
     982             :     SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */
     983             :     const int16_t num_ch_out,
     984             :     const int16_t num_ch_in,
     985             :     const int16_t num_spar_bands,
     986             :     int16_t skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
     987             :     const int16_t num_md_sub_frames )
     988             : {
     989             :     int16_t spar_band, out_ch, in_ch;
     990             :     int16_t i_ts, skip_flag;
     991             : 
     992   127480121 :     for ( out_ch = 0; out_ch < num_ch_out; out_ch++ )
     993             :     {
     994   615053048 :         for ( in_ch = 0; in_ch < num_ch_in; in_ch++ )
     995             :         {
     996   510989904 :             skip_mat[out_ch][in_ch] = 1;
     997   510989904 :             skip_flag = 1;
     998  1689905923 :             for ( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ )
     999             :             {
    1000 15274431493 :                 for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
    1001             :                 {
    1002 14095515474 :                     if ( hSpar->hMdDec->mixer_mat_prev[1 + i_ts][out_ch][in_ch][spar_band] != 0.0f )
    1003             :                     {
    1004   217698839 :                         skip_flag = 0;
    1005   217698839 :                         break;
    1006             :                     }
    1007             :                 }
    1008             : 
    1009  1396614858 :                 if ( skip_flag == 0 )
    1010             :                 {
    1011   217698839 :                     skip_mat[out_ch][in_ch] = 0;
    1012   217698839 :                     break;
    1013             :                 }
    1014             :             }
    1015             : 
    1016   510989904 :             if ( skip_mat[out_ch][in_ch] == 1 )
    1017             :             {
    1018  1216498030 :                 for ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ )
    1019             :                 {
    1020 11577466228 :                     for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
    1021             :                     {
    1022 10654259263 :                         if ( hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band + i_ts * IVAS_MAX_NUM_BANDS] != 0.0f )
    1023             :                         {
    1024      942746 :                             skip_flag = 0;
    1025      942746 :                             break;
    1026             :                         }
    1027             :                     }
    1028             : 
    1029   924149711 :                     if ( skip_flag == 0 )
    1030             :                     {
    1031      942746 :                         skip_mat[out_ch][in_ch] = 0;
    1032      942746 :                         break;
    1033             :                     }
    1034             :                 }
    1035             :             }
    1036             :         }
    1037             :     }
    1038             : 
    1039    23416977 :     return;
    1040             : }
    1041             : 
    1042             : 
    1043      337908 : static void ivas_spar_calc_smooth_facs(
    1044             :     float *cldfb_in_ts_re[CLDFB_NO_COL_MAX],
    1045             :     float *cldfb_in_ts_im[CLDFB_NO_COL_MAX],
    1046             :     int16_t nbands_spar,
    1047             :     const int16_t nSlots,
    1048             :     const int16_t isFirstSubframe,
    1049             :     ivas_fb_bin_to_band_data_t *bin2band,
    1050             :     float *smooth_fac,
    1051             :     float smooth_buf[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1] )
    1052             : {
    1053             :     int16_t b, bin, i, ts;
    1054             :     float subframe_band_nrg[IVAS_MAX_NUM_BANDS];
    1055             :     float smooth_long_avg[IVAS_MAX_NUM_BANDS];
    1056             :     float smooth_short_avg[IVAS_MAX_NUM_BANDS];
    1057             : 
    1058      337908 :     bin = 0;
    1059     4060652 :     for ( b = 0; b < nbands_spar; b++ )
    1060             :     {
    1061     3878512 :         if ( bin >= CLDFB_NO_CHANNELS_MAX || ( b > 0 && bin2band->p_cldfb_map_to_spar_band[bin] < bin2band->p_cldfb_map_to_spar_band[bin - 1] ) )
    1062             :         {
    1063             :             break;
    1064             :         }
    1065             : 
    1066             :         /* calculate band-wise subframe energies */
    1067     3722744 :         subframe_band_nrg[b] = 0.f;
    1068    17354184 :         while ( bin < CLDFB_NO_CHANNELS_MAX && b == bin2band->p_cldfb_map_to_spar_band[bin] )
    1069             :         {
    1070    68157200 :             for ( ts = 0; ts < nSlots; ts++ )
    1071             :             {
    1072    54525760 :                 subframe_band_nrg[b] += cldfb_in_ts_re[ts][bin] * cldfb_in_ts_re[ts][bin] + cldfb_in_ts_im[ts][bin] * cldfb_in_ts_im[ts][bin];
    1073             :             }
    1074    13631440 :             bin++;
    1075             :         }
    1076     3722744 :         subframe_band_nrg[b] = sqrtf( subframe_band_nrg[b] );
    1077     3722744 :         if ( isFirstSubframe && nSlots < MAX_PARAM_SPATIAL_SUBFRAMES )
    1078             :         {
    1079             :             /* fill up to full 5ms subframe */
    1080           0 :             smooth_buf[b][0] += subframe_band_nrg[b];
    1081             :         }
    1082             :         else
    1083             :         {
    1084     3722744 :             smooth_buf[b][0] = subframe_band_nrg[b];
    1085             :         }
    1086             :         /* calculate short and long energy averages */
    1087     3722744 :         smooth_short_avg[b] = EPSILON;
    1088    26059208 :         for ( i = 0; i < 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i++ )
    1089             :         {
    1090    22336464 :             smooth_short_avg[b] += smooth_buf[b][i];
    1091             :         }
    1092             : 
    1093     3722744 :         smooth_long_avg[b] = smooth_short_avg[b];
    1094    55841160 :         for ( i = 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i < 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i++ )
    1095             :         {
    1096    52118416 :             smooth_long_avg[b] += smooth_buf[b][i];
    1097             :         }
    1098     3722744 :         smooth_short_avg[b] /= ( 2 * SBA_DIRAC_NRG_SMOOTH_SHORT );
    1099     3722744 :         smooth_long_avg[b] /= ( 2 * SBA_DIRAC_NRG_SMOOTH_LONG );
    1100             : 
    1101             :         /* calculate smoothing factor based on energy averages */
    1102             :         /* reduce factor for higher short-term energy */
    1103     3722744 :         smooth_fac[b] = min( 1.f, smooth_long_avg[b] / smooth_short_avg[b] );
    1104             : 
    1105             :         /* map factor to range [0;1] */
    1106     3722744 :         smooth_fac[b] = max( 0.f, smooth_fac[b] - (float) SBA_DIRAC_NRG_SMOOTH_SHORT / SBA_DIRAC_NRG_SMOOTH_LONG ) * ( (float) SBA_DIRAC_NRG_SMOOTH_LONG / ( SBA_DIRAC_NRG_SMOOTH_LONG - SBA_DIRAC_NRG_SMOOTH_SHORT ) );
    1107             : 
    1108             :         /* compress factor (higher compression in lowest bands) */
    1109     3722744 :         if ( b < 2 )
    1110             :         {
    1111      675816 :             smooth_fac[b] = powf( smooth_fac[b], 0.25f );
    1112             :         }
    1113             :         else
    1114             :         {
    1115     3046928 :             smooth_fac[b] = powf( smooth_fac[b], 0.5f );
    1116             :         }
    1117             : 
    1118             :         /* apply upper bounds depending on band */
    1119     3722744 :         smooth_fac[b] = max( min_smooth_gains1[b], min( max_smooth_gains2[b], smooth_fac[b] ) );
    1120             :     }
    1121             : 
    1122             :     /* only update if we collected a full 5ms worth of energies for the buffer */
    1123      337908 :     if ( isFirstSubframe || nSlots == MAX_PARAM_SPATIAL_SUBFRAMES )
    1124             :     {
    1125     4216420 :         for ( b = 0; b < nbands_spar; b++ )
    1126             :         {
    1127    81448752 :             for ( i = 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i > 0; i-- )
    1128             :             {
    1129    77570240 :                 smooth_buf[b][i] = smooth_buf[b][i - 1];
    1130             :             }
    1131             :         }
    1132             :     }
    1133      337908 :     return;
    1134             : }
    1135             : 
    1136             : 
    1137             : /*-------------------------------------------------------------------*
    1138             :  * ivas_spar_dec_agc_pca()
    1139             :  *
    1140             :  *
    1141             :  *-------------------------------------------------------------------*/
    1142             : 
    1143     5902514 : void ivas_spar_dec_agc_pca(
    1144             :     Decoder_Struct *st_ivas,   /* i/o: IVAS decoder handle                     */
    1145             :     float *output[],           /* i/o: input/output audio channels             */
    1146             :     const int16_t output_frame /* i  : output frame length                     */
    1147             : )
    1148             : {
    1149             :     int16_t nchan_transport;
    1150             :     int16_t num_in_ingest;
    1151             :     DECODER_CONFIG_HANDLE hDecoderConfig;
    1152             :     SPAR_DEC_HANDLE hSpar;
    1153             : 
    1154     5902514 :     push_wmops( "ivas_spar_dec_agc_pca" );
    1155             : 
    1156     5902514 :     hSpar = st_ivas->hSpar;
    1157     5902514 :     hDecoderConfig = st_ivas->hDecoderConfig;
    1158     5902514 :     nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
    1159             : 
    1160     5902514 :     if ( st_ivas->nchan_transport >= 3 )
    1161             :     {
    1162             :         float temp;
    1163             :         int16_t i;
    1164             :         /*convert WYZX downmix to WYXZ*/
    1165  2094603903 :         for ( i = 0; i < output_frame; i++ )
    1166             :         {
    1167  2091717120 :             temp = output[2][i];
    1168  2091717120 :             output[2][i] = output[3][i];
    1169  2091717120 :             output[3][i] = temp;
    1170             :         }
    1171             :     }
    1172             : 
    1173     5902514 :     if ( hSpar->hMdDec->td_decorr_flag )
    1174             :     {
    1175     5902514 :         num_in_ingest = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
    1176             :     }
    1177             :     else
    1178             :     {
    1179           0 :         num_in_ingest = nchan_transport;
    1180             :     }
    1181             : 
    1182             :     /*---------------------------------------------------------------------*
    1183             :      * AGC
    1184             :      *---------------------------------------------------------------------*/
    1185             : 
    1186     5902514 :     ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame );
    1187             : #ifdef DEBUG_SBA_AUDIO_DUMP
    1188             :     /* Dump audio signal after ivas_agc_dec_process */
    1189             :     ivas_spar_dump_signal_wav( output_frame, NULL, output, st_ivas->nchan_transport, spar_foa_dec_wav[1], "ivas_agc_dec_process()" );
    1190             : #endif
    1191             : 
    1192     5902514 :     if ( hSpar->hPCA != NULL )
    1193             :     {
    1194      578674 :         ivas_pca_dec( hSpar->hPCA, output_frame, num_in_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output );
    1195             : #ifdef DEBUG_SBA_AUDIO_DUMP
    1196             :         /* Dump audio signal after ivas_pca_dec */
    1197             :         ivas_spar_dump_signal_wav( output_frame, NULL, output, num_in_ingest, spar_foa_dec_wav[2], "ivas_pca_dec()" );
    1198             : #endif
    1199             :     }
    1200     5902514 :     pop_wmops();
    1201             : 
    1202     5902514 :     return;
    1203             : }
    1204             : 
    1205             : 
    1206             : /*-------------------------------------------------------------------*
    1207             :  * ivas_spar_dec_set_render_map()
    1208             :  *
    1209             :  *
    1210             :  *-------------------------------------------------------------------*/
    1211             : 
    1212     6664581 : void ivas_spar_dec_set_render_map(
    1213             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure  */
    1214             :     const int16_t nCldfbTs   /* i  : number of CLDFB time slots */
    1215             : )
    1216             : {
    1217             :     SPAR_DEC_HANDLE hSpar;
    1218             : 
    1219     6664581 :     hSpar = st_ivas->hSpar;
    1220             : #ifdef DEBUGGING
    1221             :     assert( hSpar );
    1222             : #endif
    1223             : 
    1224             :     /* adapt subframes */
    1225     6664581 :     hSpar->num_slots = nCldfbTs;
    1226     6664581 :     hSpar->slots_rendered = 0;
    1227     6664581 :     hSpar->subframes_rendered = 0;
    1228             : 
    1229     6664581 :     set_s( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
    1230     6664581 :     ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpar->subframe_nbslots, &hSpar->nb_subframes );
    1231             : 
    1232             :     /* copy also to tc buffer */
    1233             :     /* only for non-combined formats and combinded formats w/o discrete objects */
    1234     6664581 :     if ( !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) )
    1235             :     {
    1236     5877638 :         st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes;
    1237     5877638 :         mvs2s( hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpar->nb_subframes );
    1238             :     }
    1239             : 
    1240     6664581 :     ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, 1, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hSpar->render_to_md_map );
    1241             : 
    1242     6664581 :     return;
    1243             : }
    1244             : 
    1245             : /*-------------------------------------------------------------------*
    1246             :  * ivas_spar_dec_set_render_params()
    1247             :  *
    1248             :  * IVAS SPAR set rendering parameters
    1249             :  *-------------------------------------------------------------------*/
    1250             : 
    1251     6664581 : void ivas_spar_dec_set_render_params(
    1252             :     Decoder_Struct *st_ivas,    /* i/o: IVAS decoder handle                     */
    1253             :     const int16_t n_cldfb_slots /* i  : number of cldfb slots in this frame     */
    1254             : )
    1255             : {
    1256             :     SPAR_DEC_HANDLE hSpar;
    1257             :     int16_t nchan_transport;
    1258             :     int16_t num_bands_out;
    1259             : 
    1260     6664581 :     hSpar = st_ivas->hSpar;
    1261     6664581 :     nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
    1262     6664581 :     num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands;
    1263     6664581 :     ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) );
    1264             : 
    1265     6664581 :     ivas_spar_dec_set_render_map( st_ivas, n_cldfb_slots );
    1266             : 
    1267     6664581 :     return;
    1268             : }
    1269             : 
    1270             : 
    1271             : /*-------------------------------------------------------------------*
    1272             :  * ivas_spar_dec_digest_tc()
    1273             :  *
    1274             :  *
    1275             :  *-------------------------------------------------------------------*/
    1276             : 
    1277     6664581 : void ivas_spar_dec_digest_tc(
    1278             :     Decoder_Struct *st_ivas,           /* i/o: IVAS decoder handle          */
    1279             :     const int16_t nchan_transport,     /* i  : number of transport channels */
    1280             :     const int16_t nCldfbSlots,         /* i  : number of CLDFB slots        */
    1281             :     const int16_t nSamplesForRendering /* i  : number of samples provided   */
    1282             : )
    1283             : {
    1284             :     SPAR_DEC_HANDLE hSpar;
    1285             : 
    1286     6664581 :     hSpar = st_ivas->hSpar;
    1287     6664581 :     if ( hSpar->hMdDec->td_decorr_flag && !( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
    1288             :     {
    1289             :         float Pcm_tmp[MAX_SPAR_INTERNAL_CHANNELS][L_FRAME48k];
    1290             :         float *pPcm_tmp[MAX_SPAR_INTERNAL_CHANNELS];
    1291             :         float *p_tc[MAX_SPAR_INTERNAL_CHANNELS];
    1292             :         int16_t nchan_internal, ch;
    1293             :         int16_t ch_sba_idx;
    1294             :         int16_t nSamplesLeftForTD, default_frame;
    1295             : 
    1296     5849724 :         ch_sba_idx = 0;
    1297     5849724 :         if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    1298             :         {
    1299     1378613 :             if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
    1300             :             {
    1301      786943 :                 ch_sba_idx = st_ivas->nchan_ism;
    1302             :             }
    1303             :         }
    1304             : 
    1305             :         /* TD decorrelator */
    1306     5849724 :         default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
    1307     5849724 :         nSamplesLeftForTD = nSamplesForRendering;
    1308     5849724 :         nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
    1309             : 
    1310    31847410 :         for ( ch = 0; ch < nchan_internal; ch++ )
    1311             :         {
    1312    25997686 :             pPcm_tmp[ch] = Pcm_tmp[ch];
    1313    25997686 :             p_tc[ch] = st_ivas->hTcBuffer->tc[ch + ch_sba_idx];
    1314             :         }
    1315             : 
    1316    11699464 :         while ( nSamplesLeftForTD )
    1317             :         {
    1318     5849740 :             int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame );
    1319             : 
    1320     5849740 :             if ( hSpar->hTdDecorr )
    1321             :             {
    1322     5066038 :                 ivas_td_decorr_process( hSpar->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr );
    1323     5066038 :                 if ( hSpar->hTdDecorr->num_apd_outputs >= ( nchan_internal - nchan_transport ) )
    1324             :                 {
    1325    15552461 :                     for ( ch = 0; ch < nchan_internal - nchan_transport; ch++ )
    1326             :                     {
    1327    10633197 :                         mvr2r( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - ch], p_tc[nchan_internal - 1 - ch], nSamplesToDecorr );
    1328             :                     }
    1329             :                 }
    1330             :                 else
    1331             :                 {
    1332     1174192 :                     for ( ch = 0; ch < nchan_internal - nchan_transport; ch++ )
    1333             :                     {
    1334     1027418 :                         set_zero( p_tc[nchan_internal - 1 - ch], nSamplesToDecorr );
    1335             :                     }
    1336      440322 :                     for ( ch = 0; ch < hSpar->hTdDecorr->num_apd_outputs; ch++ )
    1337             :                     {
    1338      293548 :                         mvr2r( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - ch], p_tc[nchan_internal - 1 - ch], nSamplesToDecorr );
    1339             :                     }
    1340             :                 }
    1341             :             }
    1342    31847490 :             for ( ch = 0; ch < nchan_internal; ch++ )
    1343             :             {
    1344    25997750 :                 p_tc[ch] += nSamplesToDecorr;
    1345             :             }
    1346             : 
    1347     5849740 :             nSamplesLeftForTD -= nSamplesToDecorr;
    1348             :         }
    1349             :     }
    1350             : 
    1351     6664581 :     ivas_spar_dec_set_render_params( st_ivas, nCldfbSlots );
    1352             : 
    1353     6664581 :     return;
    1354             : }
    1355             : 
    1356             : 
    1357             : /*-------------------------------------------------------------------*
    1358             :  * ivas_spar_dec_upmixer_sf()
    1359             :  *
    1360             :  * IVAS SPAR upmixer
    1361             :  *-------------------------------------------------------------------*/
    1362             : 
    1363    23416977 : void ivas_spar_dec_upmixer_sf(
    1364             :     Decoder_Struct *st_ivas,     /* i/o: IVAS decoder handle                     */
    1365             :     float *output[],             /* o  : output audio channels                   */
    1366             :     const int16_t nchan_internal /* i  : number of internal channels             */
    1367             : )
    1368             : {
    1369             :     int16_t cldfb_band, num_cldfb_bands, numch_in, numch_out;
    1370             :     float *cldfb_in_ts_re[HOA3_CHANNELS][CLDFB_NO_COL_MAX];
    1371             :     float *cldfb_in_ts_im[HOA3_CHANNELS][CLDFB_NO_COL_MAX];
    1372             :     int16_t i, b, ts, out_ch, in_ch;
    1373             :     int16_t num_spar_bands, spar_band, nchan_transport;
    1374             :     int16_t num_in_ingest, split_band;
    1375             :     int16_t slot_size, slot_idx_start;
    1376             :     float *p_tc[HOA3_CHANNELS];
    1377             :     int16_t md_idx;
    1378             :     float Pcm_tmp[HOA3_CHANNELS][2 /* Re, Im*/ * L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    1379             :     int16_t numch_out_dirac;
    1380             :     float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
    1381             :     int16_t b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
    1382             :     DECODER_CONFIG_HANDLE hDecoderConfig;
    1383             :     SPAR_DEC_HANDLE hSpar;
    1384             :     int16_t num_md_sub_frames;
    1385             : 
    1386    23416977 :     push_wmops( "ivas_spar_dec_upmixer_sf" );
    1387    23416977 :     hSpar = st_ivas->hSpar;
    1388    23416977 :     hDecoderConfig = st_ivas->hDecoderConfig;
    1389    23416977 :     nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
    1390             : 
    1391    23416977 :     num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands;
    1392    23416977 :     numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans;
    1393    23416977 :     numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans;
    1394    23416977 :     num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate );
    1395    23416977 :     slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
    1396    23416977 :     slot_idx_start = hSpar->slots_rendered;
    1397             : 
    1398    23416977 :     if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC )
    1399     3154553 :     {
    1400             :         int16_t nchan_ism;
    1401             : 
    1402     3154553 :         nchan_ism = st_ivas->nchan_ism;
    1403             : 
    1404    21451333 :         for ( i = 0; i < nchan_internal; i++ )
    1405             :         {
    1406    18296780 :             p_tc[i] = st_ivas->hTcBuffer->tc[i + nchan_ism] + slot_idx_start * slot_size;
    1407             :         }
    1408             : 
    1409             : #ifdef FIX_1372_OSBA_OBJECT_EDITING
    1410     3154553 :         if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
    1411             : #else
    1412             :         if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
    1413             : #endif
    1414             :         {
    1415     1702580 :             for ( i = 0; i < nchan_ism; i++ )
    1416             :             {
    1417     1274616 :                 p_tc[i + nchan_internal] = st_ivas->hTcBuffer->tc[i] + slot_idx_start * slot_size;
    1418             :             }
    1419             :         }
    1420             :     }
    1421             :     else
    1422             :     {
    1423   106028788 :         for ( i = 0; i < nchan_internal; i++ )
    1424             :         {
    1425    85766364 :             p_tc[i] = st_ivas->hTcBuffer->tc[i] + slot_idx_start * slot_size;
    1426             :         }
    1427             :     }
    1428             : 
    1429             : #ifdef DEBUG_SPAR_BYPASS_EVS_CODEC
    1430             :     /* by-pass core-coder */
    1431             :     /*write the core coder output to a file for debugging*/
    1432             :     {
    1433             :         float tmp;
    1434             :         int16_t pcm, j;
    1435             :         for ( j = 0; j < output_frame; j++ )
    1436             :         {
    1437             :             for ( i = 0; i < nchan_transport; i++ )
    1438             :             {
    1439             :                 tmp = roundf( output[i][j] * PCM16_TO_FLT_FAC );
    1440             :                 pcm = ( tmp > MAX16B_FLT ) ? MAX16B : ( tmp < MIN16B_FLT ) ? MIN16B
    1441             :                                                                            : (short) tmp;
    1442             :                 dbgwrite( &pcm, sizeof( int16_t ), 1, 1, "dmx_dec.raw" );
    1443             :             }
    1444             :         }
    1445             :     }
    1446             : 
    1447             :     /*overwrite the core coder output with core input for debugging*/
    1448             :     {
    1449             :         static FILE *fid_enc = 0;
    1450             :         int16_t smp;
    1451             : 
    1452             :         if ( !fid_enc )
    1453             :         {
    1454             :             fid_enc = fopen( "evs_input_float.raw", "rb" );
    1455             :         }
    1456             :         for ( smp = 0; smp < L_FRAME48k; smp++ )
    1457             :         {
    1458             :             for ( in_ch = 0; in_ch < nchan_transport; in_ch++ )
    1459             :             {
    1460             :                 fread( &output[in_ch][smp], sizeof( float ), 1, fid_enc );
    1461             :             }
    1462             :         }
    1463             :     }
    1464             : #endif
    1465             : 
    1466             :     /*---------------------------------------------------------------------*
    1467             :      * TD Decorr and pcm ingest
    1468             :      *---------------------------------------------------------------------*/
    1469             : 
    1470    23416977 :     if ( hSpar->hMdDec->td_decorr_flag )
    1471             :     {
    1472    23416977 :         num_in_ingest = nchan_internal;
    1473             :     }
    1474             :     else
    1475             :     {
    1476           0 :         num_in_ingest = nchan_transport;
    1477             :     }
    1478             : 
    1479             :     /*---------------------------------------------------------------------*
    1480             :      * PCA decoder
    1481             :      *---------------------------------------------------------------------*/
    1482             : #ifdef DEBUG_SBA_AUDIO_DUMP
    1483             :     hSpar->pca_ingest_channels = num_in_ingest;
    1484             : #endif
    1485             : 
    1486    23416977 :     hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest;
    1487             : 
    1488             : 
    1489             :     /*---------------------------------------------------------------------*
    1490             :      * Prepare CLDFB buffers
    1491             :      *---------------------------------------------------------------------*/
    1492             : 
    1493             :     /* set-up pointers */
    1494    23416977 :     if ( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA )
    1495             :     {
    1496             :         /* at this point, output channels are used as intermediate procesing buffers */
    1497   148973210 :         for ( in_ch = 0; in_ch < HOA3_CHANNELS; in_ch++ )
    1498             :         {
    1499   701050400 :             for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ )
    1500             :             {
    1501   560840320 :                 cldfb_in_ts_re[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands];
    1502   560840320 :                 cldfb_in_ts_im[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands];
    1503             :             }
    1504             :         }
    1505             :     }
    1506             :     else
    1507             :     {
    1508    73682755 :         for ( in_ch = 0; in_ch < numch_in; in_ch++ )
    1509             :         {
    1510   295144540 :             for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ )
    1511             :             {
    1512   236115632 :                 cldfb_in_ts_re[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands];
    1513   236115632 :                 cldfb_in_ts_im[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands];
    1514             :             }
    1515             :         }
    1516             :     }
    1517             : 
    1518             :     /*---------------------------------------------------------------------*
    1519             :      * CLDFB Processing and Synthesis
    1520             :      *---------------------------------------------------------------------*/
    1521             : 
    1522    23416977 :     num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands;
    1523             : 
    1524             :     /* apply parameters */
    1525             :     /* determine if we can skip certain data */
    1526    23416977 :     ivas_spar_get_skip_mat( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat, num_md_sub_frames ); /* this can be precomputed based on bitrate and format*/
    1527             : 
    1528    23416977 :     numch_out_dirac = hDecoderConfig->nchan_out;
    1529             : 
    1530             : #ifdef DEBUG_SBA_AUDIO_DUMP
    1531             :     /* Dump audio signal after ivas_agc_dec_process */
    1532             :     ivas_spar_dump_signal_wav( output_frame, p_tc, NULL, numch_in, spar_foa_dec_wav[4], "ivas_spar_upmixer()" );
    1533             : #endif
    1534             : 
    1535             :     /* CLDFB analysis of incoming frame */
    1536   127480121 :     for ( in_ch = 0; in_ch < numch_in; in_ch++ )
    1537             :     {
    1538   520029120 :         for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    1539             :         {
    1540   415965976 :             cldfbAnalysis_ts( &p_tc[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re[in_ch][ts], cldfb_in_ts_im[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch] );
    1541             :         }
    1542             :     }
    1543             : 
    1544    23416977 :     if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
    1545             :     {
    1546     1702580 :         for ( ; in_ch < st_ivas->nchan_ism + numch_in; in_ch++ )
    1547             :         {
    1548     6373080 :             for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    1549             :             {
    1550     5098464 :                 cldfbAnalysis_ts( &p_tc[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re[in_ch][ts], cldfb_in_ts_im[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch] );
    1551             :             }
    1552             :         }
    1553             :     }
    1554             : 
    1555    23416977 :     if ( hDecoderConfig->ivas_total_brate < IVAS_24k4 && ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA2 || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA3 ) )
    1556             :     {
    1557      337908 :         ivas_spar_calc_smooth_facs( cldfb_in_ts_re[0], cldfb_in_ts_im[0], num_spar_bands, hSpar->subframe_nbslots[hSpar->subframes_rendered], hSpar->subframes_rendered == 0, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_buf );
    1558             :     }
    1559             : 
    1560   117013235 :     for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    1561             :     {
    1562    93596258 :         md_idx = hSpar->render_to_md_map[ts + slot_idx_start];
    1563    93596258 :         ivas_spar_get_parameters( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat );
    1564             : 
    1565    93596258 :         if ( hDecoderConfig->ivas_total_brate < IVAS_24k4 && ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA2 || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA3 ) )
    1566             :         {
    1567    16865680 :             for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
    1568             :             {
    1569    77570240 :                 for ( out_ch = 0; out_ch < numch_out; out_ch++ )
    1570             :                 {
    1571   310280960 :                     for ( in_ch = 0; in_ch < numch_in; in_ch++ )
    1572             :                     {
    1573   248224768 :                         mixer_mat[out_ch][in_ch][spar_band] = ( 1 - hSpar->hMdDec->smooth_fac[spar_band] ) * mixer_mat[out_ch][in_ch][spar_band] + hSpar->hMdDec->smooth_fac[spar_band] * hSpar->hMdDec->mixer_mat_prev2[out_ch][in_ch][spar_band];
    1574   248224768 :                         hSpar->hMdDec->mixer_mat_prev2[out_ch][in_ch][spar_band] = mixer_mat[out_ch][in_ch][spar_band];
    1575             :                     }
    1576             :                 }
    1577             :             }
    1578             :         }
    1579             : 
    1580  4178456238 :         for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ )
    1581             :         {
    1582             :             float out_re[IVAS_SPAR_MAX_CH];
    1583             :             float out_im[IVAS_SPAR_MAX_CH];
    1584             :             float cldfb_par;
    1585  4084859980 :             ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band;
    1586             : 
    1587 22527226940 :             for ( out_ch = 0; out_ch < numch_out; out_ch++ )
    1588             :             {
    1589 18442366960 :                 out_re[out_ch] = 0.0f;
    1590 18442366960 :                 out_im[out_ch] = 0.0f;
    1591             : 
    1592 >11152*10^7 :                 for ( in_ch = 0; in_ch < numch_in; in_ch++ )
    1593             :                 {
    1594 93084698560 :                     if ( b_skip_mat[out_ch][in_ch] == 0 )
    1595             :                     {
    1596 39398683640 :                         if ( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */
    1597             :                         {
    1598  6117465774 :                             spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band];
    1599  6117465774 :                             cldfb_par = mixer_mat[out_ch][in_ch][spar_band];
    1600             :                         }
    1601             :                         else
    1602             :                         {
    1603 33281217866 :                             cldfb_par = 0.0f;
    1604 >17914*10^7 :                             for ( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ )
    1605             :                             {
    1606             :                                 /* accumulate contributions from all SPAR bands */
    1607 >14586*10^7 :                                 cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band];
    1608             :                             }
    1609             :                         }
    1610             : 
    1611 39398683640 :                         out_re[out_ch] += cldfb_in_ts_re[in_ch][ts][cldfb_band] * cldfb_par;
    1612 39398683640 :                         out_im[out_ch] += cldfb_in_ts_im[in_ch][ts][cldfb_band] * cldfb_par;
    1613             :                     }
    1614             :                 }
    1615             :             }
    1616             : 
    1617             :             /*update CLDFB data with the parameter-modified data*/
    1618 22527226940 :             for ( out_ch = 0; out_ch < numch_out; out_ch++ )
    1619             :             {
    1620 18442366960 :                 cldfb_in_ts_re[out_ch][ts][cldfb_band] = out_re[out_ch];
    1621 18442366960 :                 cldfb_in_ts_im[out_ch][ts][cldfb_band] = out_im[out_ch];
    1622             :             }
    1623             :         }
    1624             : 
    1625    93596258 :         if ( ( ( slot_idx_start + ts + 1 ) == hSpar->num_slots ) || ( ( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ) != ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME ) ) )
    1626             :         {
    1627             :             /* we have crossed an unadapted parameter sf border, update previous mixing matrices */
    1628    23399220 :             int16_t md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME;
    1629    23399220 :             split_band = SPAR_DIRAC_SPLIT_START_BAND;
    1630    23399220 :             md_sf = ( num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES ) ? md_sf : 0;
    1631    23399220 :             if ( split_band < IVAS_MAX_NUM_BANDS )
    1632             :             {
    1633    23399220 :                 mvr2r( hSpar->hMdDec->mixer_mat_prev[1][0][0], hSpar->hMdDec->mixer_mat_prev[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS );
    1634    23399220 :                 mvr2r( hSpar->hMdDec->mixer_mat_prev[2][0][0], hSpar->hMdDec->mixer_mat_prev[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS );
    1635    23399220 :                 mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS );
    1636    23399220 :                 mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS );
    1637             : 
    1638   127391412 :                 for ( out_ch = 0; out_ch < numch_out; out_ch++ )
    1639             :                 {
    1640   614698744 :                     for ( in_ch = 0; in_ch < numch_in; in_ch++ )
    1641             :                     {
    1642  6415789976 :                         for ( b = 0; b < num_spar_bands; b++ )
    1643             :                         {
    1644  5905083424 :                             hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS];
    1645             :                         }
    1646             :                     }
    1647             :                 }
    1648    23399220 :                 hSpar->i_subframe++;
    1649    23399220 :                 hSpar->i_subframe = min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES );
    1650             :             }
    1651             :         }
    1652             :     }
    1653             : 
    1654    23416977 :     if ( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA && hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO && hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO && !( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL && st_ivas->intern_config == IVAS_AUDIO_CONFIG_FOA ) )
    1655             :     {
    1656     8457286 :         ivas_dirac_dec_render_sf( st_ivas, output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im );
    1657             :     }
    1658             : 
    1659    23416977 :     if ( st_ivas->hDirAC != NULL )
    1660             :     {
    1661             :         int16_t outchannels, idx_in, idx_lfe, ch;
    1662     8739298 :         idx_in = 0;
    1663     8739298 :         idx_lfe = 0;
    1664             : 
    1665     8739298 :         outchannels = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe;
    1666             : 
    1667    83621798 :         for ( ch = 0; ch < outchannels; ch++ )
    1668             :         {
    1669    74882500 :             if ( ( st_ivas->hOutSetup.num_lfe > 0 ) && ( st_ivas->hOutSetup.index_lfe[idx_lfe] == ch ) )
    1670             :             {
    1671     3195704 :                 set_zero( output[ch], hSpar->subframe_nbslots[hSpar->subframes_rendered] * num_cldfb_bands );
    1672     3195704 :                 if ( idx_lfe < ( st_ivas->hDirACRend->hOutSetup.num_lfe - 1 ) )
    1673             :                 {
    1674           0 :                     idx_lfe++;
    1675             :                 }
    1676             :             }
    1677             :             else
    1678             :             {
    1679    71686796 :                 if ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA || !( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) &&
    1680    67592904 :                      !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) )
    1681             :                 {
    1682   311614664 :                     for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    1683             :                     {
    1684   249157328 :                         cldfbSynthesis( &cldfb_in_ts_re[idx_in][ts], &cldfb_in_ts_im[idx_in][ts], &output[ch][ts * num_cldfb_bands], num_cldfb_bands, st_ivas->cldfbSynDec[idx_in] );
    1685             :                     }
    1686             :                 }
    1687    71686796 :                 idx_in++;
    1688             :             }
    1689             :         }
    1690             : #ifdef DEBUG_SBA_AUDIO_DUMP
    1691             :         hSpar->numOutChannels = outchannels;
    1692             : #endif
    1693             :     }
    1694             :     else
    1695             :     {
    1696             :         /* CLDFB to time synthesis (overwrite mixer output) */
    1697    73388395 :         for ( out_ch = 0; out_ch < numch_out_dirac; out_ch++ )
    1698             :         {
    1699   293447792 :             for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
    1700             :             {
    1701   234737076 :                 cldfbSynthesis( &cldfb_in_ts_re[out_ch][ts], &cldfb_in_ts_im[out_ch][ts], &output[out_ch][ts * num_cldfb_bands], num_cldfb_bands, st_ivas->cldfbSynDec[out_ch] );
    1702             :             }
    1703             :         }
    1704             : #ifdef DEBUG_SBA_AUDIO_DUMP
    1705             :         hSpar->numOutChannels = numch_out_dirac;
    1706             : #endif
    1707             :     }
    1708             : #ifdef DEBUG_SBA_AUDIO_DUMP
    1709             :     /* Dump audio signal after cldfbSynthesis */
    1710             :     ivas_spar_dump_signal_wav( output_frame, NULL, output, hSpar->numOutChannels, spar_foa_dec_wav[3], "cldfbSynthesis()" );
    1711             : #endif
    1712             : 
    1713    23416977 :     hSpar->slots_rendered += hSpar->subframe_nbslots[hSpar->subframes_rendered];
    1714    23416977 :     hSpar->subframes_rendered++;
    1715             : 
    1716    23416977 :     pop_wmops();
    1717             : 
    1718    23416977 :     return;
    1719             : }

Generated by: LCOV version 1.14