LCOV - code coverage report
Current view: top level - lib_dec - ivas_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- long test vectors @ efe53129c9ed87a5067dd0a8fb9dca41db9c4add Lines: 385 432 89.1 %
Date: 2026-02-12 08:06:16 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2026 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             : #include "cnst.h"
      36             : #include "ivas_cnst.h"
      37             : #include "rom_com.h"
      38             : #include "prot.h"
      39             : #include "ivas_prot.h"
      40             : #include "ivas_prot_rend.h"
      41             : #include "ivas_rom_com.h"
      42             : #ifdef DEBUGGING
      43             : #include "debug.h"
      44             : #endif
      45             : #include "wmc_auto.h"
      46             : 
      47             : 
      48             : /*--------------------------------------------------------------------------*
      49             :  * ivas_dec()
      50             :  *
      51             :  * Principal IVAS decoder routine, decoding of metadata and transport channels
      52             :  *--------------------------------------------------------------------------*/
      53             : 
      54    14987349 : ivas_error ivas_dec(
      55             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure         */
      56             : )
      57             : {
      58             :     int16_t n, output_frame, nchan_out;
      59             :     Decoder_State *st;                       /* used for bitstream handling */
      60             :     float *p_output[MAX_TRANSPORT_CHANNELS]; /* 'float' buffer for output synthesis */
      61             :     int16_t nchan_remapped;
      62             :     int16_t nb_bits_metadata[MAX_SCE + 1];
      63             :     int32_t output_Fs, ivas_total_brate;
      64             :     AUDIO_CONFIG output_config;
      65             :     ivas_error error;
      66             :     int16_t num_md_sub_frames;
      67             :     int32_t ism_total_brate;
      68             : 
      69    14987349 :     push_wmops( "ivas_dec" );
      70             : 
      71             :     /*----------------------------------------------------------------*
      72             :      * Initialization of local vars after struct has been set
      73             :      *----------------------------------------------------------------*/
      74             : 
      75    14987349 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
      76    14987349 :     nchan_out = st_ivas->hTcBuffer->nchan_transport_rend;
      77    14987349 :     output_config = st_ivas->hDecoderConfig->output_config;
      78    14987349 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
      79             : 
      80    14987349 :     output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC );
      81             : 
      82             :     /* set pointers to transport channels audio */
      83   194835537 :     for ( n = 0; n < MAX_TRANSPORT_CHANNELS; n++ )
      84             :     {
      85   179848188 :         p_output[n] = st_ivas->p_output_f[n];
      86   179848188 :         if ( p_output[n] != NULL )
      87             :         {
      88    74472351 :             set_zero( p_output[n], L_FRAME48k );
      89             :         }
      90             :     }
      91             : 
      92             :     /*----------------------------------------------------------------*
      93             :      * Decoding + pre-rendering
      94             :      *----------------------------------------------------------------*/
      95             : 
      96    14987349 :     if ( st_ivas->ivas_format == STEREO_FORMAT )
      97             :     {
      98     2107422 :         st_ivas->hCPE[0]->element_brate = ivas_total_brate;
      99     2107422 :         if ( ( error = ivas_cpe_dec( st_ivas, 0, p_output, output_frame, 0 ) ) != IVAS_ERR_OK )
     100             :         {
     101           0 :             return error;
     102             :         }
     103             : 
     104             :         /* HP filtering */
     105     5640861 :         for ( n = 0; n < min( nchan_out, st_ivas->nchan_transport ); n++ )
     106             :         {
     107     3533439 :             hp20( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
     108             :         }
     109             :     }
     110    12879927 :     else if ( st_ivas->ivas_format == ISM_FORMAT )
     111             :     {
     112             :         /* Metadata decoding and configuration */
     113     1841583 :         if ( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA )
     114             :         {
     115       35658 :             ivas_ism_dtx_dec( st_ivas, nb_bits_metadata );
     116             : 
     117             :             /* decode dominant object first so the noise energy of the other objects can be limited */
     118       35658 :             if ( ( error = ivas_sce_dec( st_ivas, st_ivas->hISMDTX.sce_id_dtx, &p_output[st_ivas->hISMDTX.sce_id_dtx], output_frame, nb_bits_metadata[st_ivas->hISMDTX.sce_id_dtx] ) ) != IVAS_ERR_OK )
     119             :             {
     120           0 :                 return error;
     121             :             }
     122             : 
     123       35658 :             ivas_ism_dtx_limit_noise_energy_for_near_silence( st_ivas->hSCE, st_ivas->hISMDTX.sce_id_dtx, st_ivas->nchan_transport );
     124             : 
     125       35658 :             ivas_param_ism_dec_dequant_md( st_ivas );
     126             :         }
     127     1805925 :         else if ( st_ivas->ism_mode == ISM_MODE_PARAM )
     128             :         {
     129      365346 :             if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK )
     130             :             {
     131           0 :                 return error;
     132             :             }
     133             : 
     134      365346 :             ivas_param_ism_dec_dequant_md( st_ivas );
     135             :         }
     136             :         else /* ISM_MODE_DISC */
     137             :         {
     138     1440579 :             if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK )
     139             :             {
     140           0 :                 return error;
     141             :             }
     142             :         }
     143             : 
     144     6728910 :         for ( n = 0; n < st_ivas->nchan_transport; n++ )
     145             :         {
     146             :             /* for DTX frames, dominant object has already been decoded before */
     147     4887327 :             if ( !( ( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA ) && n == st_ivas->hISMDTX.sce_id_dtx ) )
     148             :             {
     149     4851669 :                 if ( ( error = ivas_sce_dec( st_ivas, n, &p_output[n], output_frame, nb_bits_metadata[n] ) ) != IVAS_ERR_OK )
     150             :                 {
     151           0 :                     return error;
     152             :                 }
     153             :             }
     154             : 
     155             :             /* HP filtering */
     156     4887327 :             hp20( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
     157             :         }
     158             : 
     159     1841583 :         if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX )
     160             :         {
     161       71907 :             ivas_ism_mono_dmx( st_ivas, p_output, output_frame );
     162             :         }
     163     1769676 :         else if ( st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) )
     164             :         {
     165             :             /* loudness correction */
     166      198957 :             ivas_dirac_dec_binaural_sba_gain( p_output, st_ivas->nchan_transport, output_frame );
     167             :         }
     168             :     }
     169    11038344 :     else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
     170             :     {
     171     7536051 :         set_s( nb_bits_metadata, 0, MAX_SCE );
     172             : 
     173             :         /* read parameters from the bitstream */
     174     7536051 :         if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hQMetaData != NULL )
     175             :         {
     176     1832706 :             st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
     177             : 
     178     1832706 :             if ( ( error = ivas_masa_decode( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     179             :             {
     180           0 :                 return error;
     181             :             }
     182             :         }
     183     5703345 :         else if ( st_ivas->ivas_format == SBA_FORMAT )
     184             :         {
     185     5703345 :             if ( ( error = ivas_spar_dec( st_ivas, nb_bits_metadata ) ) != IVAS_ERR_OK )
     186             :             {
     187           0 :                 return error;
     188             :             }
     189             :         }
     190             : 
     191     7536051 :         if ( st_ivas->nchan_transport == CPE_CHANNELS && st_ivas->nCPE >= 1 )
     192             :         {
     193     2802000 :             st_ivas->hCPE[0]->brate_surplus = 0;
     194     2802000 :             st_ivas->hCPE[0]->element_brate = ivas_total_brate;
     195             :         }
     196             : 
     197             :         /* core-decoding of transport channels */
     198     7536051 :         if ( st_ivas->nSCE == 1 )
     199             :         {
     200     2540526 :             if ( ( error = ivas_sce_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     201             :             {
     202           0 :                 return error;
     203             :             }
     204             :         }
     205     4995525 :         else if ( st_ivas->nCPE == 1 )
     206             :         {
     207     2802000 :             if ( ( error = ivas_cpe_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     208             :             {
     209           0 :                 return error;
     210             :             }
     211             :         }
     212     2193525 :         else if ( st_ivas->nCPE > 1 )
     213             :         {
     214     2193525 :             if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     215             :             {
     216           0 :                 return error;
     217             :             }
     218             :         }
     219             : 
     220             : #ifdef DEBUG_SBA_AUDIO_DUMP
     221             :         /* Dump audio signal after core-decoding */
     222             :         ivas_spar_dump_signal_wav( output_frame, NULL, output, st_ivas->nchan_transport, spar_foa_dec_wav[0], "core-decoding" );
     223             : #endif
     224             :         /* TCs remapping */
     225     7536051 :         nchan_remapped = st_ivas->nchan_transport;
     226     7536051 :         if ( st_ivas->sba_dirac_stereo_flag )
     227             :         {
     228      175494 :             nchan_remapped = nchan_out;
     229             : 
     230      175494 :             if ( st_ivas->ivas_format == SBA_FORMAT )
     231             :             {
     232      175494 :                 ivas_agc_dec_process( st_ivas->hSpar->hAgcDec, p_output, p_output, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );
     233             : 
     234      175494 :                 if ( st_ivas->hSpar->hPCA != NULL )
     235             :                 {
     236           0 :                     ivas_pca_dec( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, p_output );
     237             :                 }
     238             : 
     239      175494 :                 ivas_spar_dec_gen_umx_mat( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ) );
     240             :             }
     241             : 
     242      175494 :             ivas_sba_dirac_stereo_dec( st_ivas, p_output, output_frame );
     243             :         }
     244     7360557 :         else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ( ivas_total_brate > IVAS_SID_5k2 || ( ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE > 0 && st_ivas->hCPE[0]->nchan_out == 1 ) ) )
     245             :         {
     246      358749 :             nchan_remapped = 1; /* Only one channel transported */
     247             :         }
     248             : 
     249             :         /* HP filtering */
     250             : #ifndef DEBUG_SPAR_BYPASS_EVS_CODEC
     251    23133135 :         for ( n = 0; n < nchan_remapped; n++ )
     252             :         {
     253    15597084 :             hp20( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
     254             :         }
     255             : #endif
     256             : 
     257     7536051 :         if ( st_ivas->ivas_format == SBA_FORMAT )
     258             :         {
     259     5703345 :             nchan_remapped = ivas_sba_remapTCs( p_output, st_ivas, output_frame );
     260             : 
     261     5703345 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
     262             :             {
     263      892032 :                 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate );
     264      892032 :                 ivas_sba_mix_matrix_determiner( st_ivas->hSpar, p_output, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames );
     265             :             }
     266     4811313 :             else if ( st_ivas->renderer_type != RENDERER_DISABLE )
     267             :             {
     268     4594686 :                 ivas_spar_dec_agc_pca( st_ivas, p_output, output_frame );
     269             :             }
     270             :         }
     271             : 
     272     7536051 :         if ( st_ivas->ivas_format == MASA_FORMAT )
     273             :         {
     274     1832706 :             ivas_masa_prerender( st_ivas, p_output, output_frame, nchan_remapped );
     275             : 
     276             :             /* external output */
     277     1832706 :             if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL && st_ivas->hMasa->config.input_ivas_format == MASA_ISM_FORMAT )
     278             :             {
     279       22500 :                 for ( n = 0; n < st_ivas->nchan_ism; n++ )
     280             :                 {
     281       18000 :                     set_zero( p_output[st_ivas->nchan_transport + n], output_frame );
     282             :                 }
     283             : 
     284        4500 :                 ivas_omasa_rearrange_channels( p_output, st_ivas->nchan_ism, output_frame );
     285             :             }
     286             :         }
     287     5703345 :         else if ( st_ivas->ivas_format == SBA_FORMAT && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
     288             :         {
     289             :             /* loudness correction */
     290      892032 :             ivas_dirac_dec_binaural_sba_gain( p_output, nchan_remapped, output_frame );
     291             :         }
     292             :     }
     293     3502293 :     else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
     294             :     {
     295             :         int16_t nchan_ism, nchan_transport_ism;
     296             :         int16_t dirac_bs_md_write_idx;
     297             : 
     298      622791 :         set_s( nb_bits_metadata, 0, MAX_SCE + 1 );
     299             : 
     300             :         /* Set the number of objects for the parametric rendering */
     301      622791 :         dirac_bs_md_write_idx = 0;
     302      622791 :         if ( st_ivas->hSpatParamRendCom != NULL )
     303             :         {
     304      478719 :             st_ivas->hSpatParamRendCom->numIsmDirections = 0;
     305      478719 :             if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ )
     306             :             {
     307      151407 :                 st_ivas->hSpatParamRendCom->numIsmDirections = st_ivas->nchan_ism;
     308             :             }
     309             : 
     310      478719 :             dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */
     311             :         }
     312             : 
     313             :         /* MASA metadata decoding */
     314      622791 :         if ( ( error = ivas_masa_decode( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     315             :         {
     316           0 :             return error;
     317             :         }
     318             : 
     319             :         /* Configuration of combined-format bit-budget distribution */
     320      622791 :         ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate );
     321             : 
     322      622791 :         st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] );
     323             : 
     324             :         /* set ISM parameters and decode ISM metadata in OMASA format */
     325      622791 :         if ( ( error = ivas_omasa_ism_metadata_dec( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
     326             :         {
     327           0 :             return error;
     328             :         }
     329             : 
     330             :         /* decode ISM channels */
     331     1730238 :         for ( n = 0; n < nchan_transport_ism; n++ )
     332             :         {
     333     1107447 :             if ( ( error = ivas_sce_dec( st_ivas, n, &p_output[st_ivas->nchan_transport + n], output_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
     334             :             {
     335           0 :                 return error;
     336             :             }
     337             :         }
     338             : 
     339             :         /* decode MASA channels */
     340      622791 :         if ( ( error = ivas_cpe_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     341             :         {
     342           0 :             return error;
     343             :         }
     344             : 
     345      622791 :         if ( st_ivas->hCPE[0]->nchan_out == 1 )
     346             :         {
     347      114927 :             mvr2r( p_output[0], p_output[1], output_frame ); /* Copy mono signal to stereo output channels */
     348             :         }
     349             : 
     350             :         /* HP filtering */
     351     2975820 :         for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
     352             :         {
     353     2353029 :             hp20( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
     354             :         }
     355             : 
     356      622791 :         if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX )
     357             :         {
     358       81045 :             ivas_ism_mono_dmx( st_ivas, p_output, output_frame );
     359             :         }
     360      541746 :         else if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     361             :         {
     362       67527 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
     363             :             {
     364       58527 :                 ivas_omasa_rearrange_channels( p_output, nchan_transport_ism, output_frame );
     365             :             }
     366        9000 :             else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
     367             :             {
     368             :                 /* Convert separate object to MASA, combine with the original MASA, and output combined MASA + empty objects. */
     369        4500 :                 ivas_omasa_combine_separate_ism_with_masa( st_ivas, p_output, st_ivas->nchan_ism, output_frame );
     370             :             }
     371        4500 :             else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
     372             :             {
     373             :                 /* Extract objects from MASA, output MASA + all objects (i.e., extracted and separated objects) */
     374        4500 :                 ivas_omasa_render_objects_from_mix( st_ivas, p_output, st_ivas->nchan_ism, output_frame );
     375             :             }
     376             :         }
     377             :     }
     378     2879502 :     else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
     379             :     {
     380             :         int16_t nchan_ism, sba_ch_idx;
     381             : 
     382      879087 :         set_s( nb_bits_metadata, 0, MAX_SCE + 1 );
     383      879087 :         nchan_ism = st_ivas->nchan_ism;
     384      879087 :         if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
     385             :         {
     386             :             /* set ISM parameters and decode ISM metadata in OSBA format */
     387      536226 :             if ( ( error = ivas_osba_ism_metadata_dec( st_ivas, ivas_total_brate, &nchan_ism, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
     388             :             {
     389           0 :                 return error;
     390             :             }
     391      536226 :             sba_ch_idx = st_ivas->nchan_ism;
     392             :         }
     393             :         else
     394             :         {
     395      342861 :             nb_bits_metadata[1] += NO_BITS_MASA_ISM_NO_OBJ;
     396      342861 :             sba_ch_idx = 0;
     397             :         }
     398             : 
     399             :         /* SBA metadata decoding */
     400      879087 :         if ( ( error = ivas_spar_dec( st_ivas, nb_bits_metadata ) ) != IVAS_ERR_OK )
     401             :         {
     402           0 :             return error;
     403             :         }
     404             : 
     405      879087 :         if ( st_ivas->nchan_transport == CPE_CHANNELS && st_ivas->nCPE >= 1 )
     406             :         {
     407      151044 :             st_ivas->hCPE[0]->element_brate = ivas_total_brate;
     408             :         }
     409             : 
     410             :         /* core-decoding of transport channels */
     411      879087 :         if ( st_ivas->nSCE == 1 )
     412             :         {
     413      152457 :             if ( ( error = ivas_sce_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
     414             :             {
     415           0 :                 return error;
     416             :             }
     417             :         }
     418      726630 :         else if ( st_ivas->nCPE == 1 )
     419             :         {
     420      151044 :             if ( ( error = ivas_cpe_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
     421             :             {
     422           0 :                 return error;
     423             :             }
     424             :         }
     425      575586 :         else if ( st_ivas->nCPE > 1 )
     426             :         {
     427      575586 :             if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
     428             :             {
     429           0 :                 return error;
     430             :             }
     431             :         }
     432             : 
     433      879087 :         if ( st_ivas->sba_dirac_stereo_flag )
     434             :         {
     435       72423 :             ivas_agc_dec_process( st_ivas->hSpar->hAgcDec, &p_output[sba_ch_idx], &p_output[sba_ch_idx], st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );
     436             : 
     437       72423 :             if ( st_ivas->hSpar->hPCA != NULL )
     438             :             {
     439           0 :                 ivas_pca_dec( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, &p_output[sba_ch_idx] );
     440             :             }
     441             : 
     442       72423 :             ivas_spar_dec_gen_umx_mat( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, 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 ) );
     443             : 
     444       72423 :             ivas_sba_dirac_stereo_dec( st_ivas, &p_output[sba_ch_idx], output_frame );
     445             :         }
     446             : 
     447             :         /* HP filtering */
     448     4935888 :         for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
     449             :         {
     450     4056801 :             hp20( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
     451             :         }
     452             : 
     453      879087 :         nchan_remapped = ivas_sba_remapTCs( &p_output[sba_ch_idx], st_ivas, output_frame );
     454             : 
     455             : #ifdef DEBUG_OSBA
     456             :         if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
     457             :         {
     458             :             int16_t nchan = st_ivas->nchan_transport + st_ivas->nchan_ism;
     459             :             for ( int16_t t = 0; t < output_frame; t++ )
     460             :             {
     461             :                 for ( int16_t c = 0; c < nchan; c++ )
     462             :                 {
     463             :                     int16_t val = (int16_t) ( output[c][t] + 0.5f );
     464             :                     dbgwrite( &val, sizeof( int16_t ), 1, 1, "./res/TC_dec_core_out.raw" );
     465             :                 }
     466             :             }
     467             :         }
     468             : #endif
     469      879087 :         if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
     470             :         {
     471      188064 :             num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate );
     472             : 
     473      188064 :             ivas_sba_mix_matrix_determiner( st_ivas->hSpar, &p_output[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames );
     474             :         }
     475      691023 :         else if ( st_ivas->renderer_type != RENDERER_DISABLE && !st_ivas->sba_dirac_stereo_flag )
     476             :         {
     477      595515 :             ivas_spar_dec_agc_pca( st_ivas, &p_output[sba_ch_idx], output_frame );
     478             :         }
     479             : 
     480      879087 :         if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
     481             :         {
     482             :             /* loudness correction */
     483      188064 :             ivas_dirac_dec_binaural_sba_gain( &p_output[sba_ch_idx], nchan_remapped, output_frame );
     484             :         }
     485      691023 :         else if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX && st_ivas->ism_mode == ISM_SBA_MODE_DISC )
     486             :         {
     487       23928 :             ivas_ism_mono_dmx( st_ivas, p_output, output_frame );
     488             : 
     489             :             /* add W */
     490       47856 :             for ( n = 0; n < nchan_out; n++ )
     491             :             {
     492       23928 :                 v_add( p_output[n], p_output[n + max( nchan_out, nchan_ism )], p_output[n], output_frame );
     493             :             }
     494             :         }
     495             :     }
     496     2000415 :     else if ( st_ivas->ivas_format == MC_FORMAT )
     497             :     {
     498     2000415 :         st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
     499             : 
     500     2000415 :         if ( st_ivas->mc_mode == MC_MODE_MCT )
     501             :         {
     502             :             /* LFE channel decoder */
     503     1052247 :             ivas_lfe_dec( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output[LFE_CHANNEL] );
     504             : 
     505     1052247 :             if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, 0 ) ) != IVAS_ERR_OK )
     506             :             {
     507           0 :                 return error;
     508             :             }
     509             : 
     510             :             /* HP filtering */
     511     9482271 :             for ( n = 0; n < st_ivas->nchan_transport; n++ )
     512             :             {
     513     8430024 :                 if ( n != LFE_CHANNEL )
     514             :                 {
     515     7377777 :                     hp20( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
     516             :                 }
     517             :             }
     518             : 
     519     1052247 :             if ( st_ivas->transport_config != st_ivas->intern_config && ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_FOA || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA2 || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA3 ) )
     520             :             {
     521       31623 :                 if ( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) >= ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) )
     522             :                 {
     523           0 :                     ivas_mc2sba( st_ivas->hTransSetup, p_output, p_output, output_frame, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE );
     524             :                 }
     525             :             }
     526             : 
     527     1052247 :             if ( ( st_ivas->renderer_type == RENDERER_MC || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) && ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) >= ( st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ) )
     528             :             {
     529       78252 :                 if ( st_ivas->renderer_type == RENDERER_MC )
     530             :                 {
     531       78252 :                     ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, output_frame, p_output, p_output );
     532             :                 }
     533           0 :                 else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     534             :                 {
     535           0 :                     ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, output_frame, st_ivas->hOutSetup.ambisonics_order, 0.f );
     536             :                 }
     537             :             }
     538             :         }
     539      948168 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
     540             :         {
     541             :             /* LFE channel decoder */
     542      110394 :             ivas_lfe_dec( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output[LFE_CHANNEL] );
     543             : 
     544      110394 :             ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] );
     545             : 
     546      110394 :             if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     547             :             {
     548           0 :                 return error;
     549             :             }
     550             : 
     551             :             /* HP filtering */
     552      993546 :             for ( n = 0; n < st_ivas->nchan_transport; n++ )
     553             :             {
     554      883152 :                 if ( n != LFE_CHANNEL )
     555             :                 {
     556      772758 :                     hp20( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
     557             :                 }
     558             :             }
     559             : 
     560             :             /* Rendering */
     561      110394 :             if ( st_ivas->renderer_type == RENDERER_MC && ( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
     562             :             {
     563             :                 /* Compensate loudness for not doing full upmix */
     564       13500 :                 for ( n = 4; n < 8; n++ )
     565             :                 {
     566       10800 :                     v_multc( p_output[n], 2.0f, p_output[n], output_frame );
     567             :                 }
     568             : 
     569        2700 :                 if ( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO )
     570             :                 {
     571        2700 :                     ivas_ls_setup_conversion( st_ivas, audioCfg2channels( IVAS_AUDIO_CONFIG_5_1_2 ), output_frame, p_output, p_output );
     572             :                 }
     573             :             }
     574             :         }
     575      837774 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
     576             :         {
     577             :             /* read Parametric MC parameters from the bitstream */
     578      338124 :             ivas_param_mc_dec_read_BS( ivas_total_brate, st, st_ivas->hParamMC, &nb_bits_metadata[0] );
     579             : 
     580      338124 :             if ( st_ivas->nCPE == 1 )
     581             :             {
     582      310071 :                 if ( ( error = ivas_cpe_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     583             :                 {
     584           0 :                     return error;
     585             :                 }
     586             :             }
     587       28053 :             else if ( st_ivas->nCPE > 1 )
     588             :             {
     589       28053 :                 if ( ( error = ivas_mct_dec( st_ivas, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     590             :                 {
     591           0 :                     return error;
     592             :                 }
     593             :             }
     594             : 
     595             :             /* HP filtering */
     596     1042425 :             for ( n = 0; n < st_ivas->nchan_transport; n++ )
     597             :             {
     598      704301 :                 hp20( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
     599             :             }
     600             : 
     601             :             /* Rendering */
     602      338124 :             if ( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO )
     603             :             {
     604        2688 :                 ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, output_frame, p_output, p_output );
     605             :             }
     606             :         }
     607      499650 :         else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
     608             :         {
     609      499650 :             if ( st_ivas->hOutSetup.separateChannelEnabled )
     610             :             {
     611      104235 :                 st = st_ivas->hCPE[0]->hCoreCoder[0]; /* Metadata is always with CPE in the case of separated channel */
     612             :             }
     613             : 
     614             :             /* read McMASA parameters from the bitstream */
     615      499650 :             if ( ( error = ivas_masa_decode( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     616             :             {
     617           0 :                 return error;
     618             :             }
     619             : 
     620      499650 :             if ( st_ivas->hOutSetup.separateChannelEnabled )
     621             :             {
     622             :                 /* Decode the transport audio signals */
     623      104235 :                 if ( ( error = ivas_cpe_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     624             :                 {
     625           0 :                     return error;
     626             :                 }
     627             : 
     628             :                 /* Identify the index of the separated channel, always LFE_CHANNEL-1 here */
     629      104235 :                 n = LFE_CHANNEL - 1;
     630             : 
     631             :                 /* Decode the separated channel to output[n] to be combined with the synthesized channels */
     632      104235 :                 if ( ( error = ivas_sce_dec( st_ivas, 0, &p_output[n], output_frame, 0 ) ) != IVAS_ERR_OK )
     633             :                 {
     634           0 :                     return error;
     635             :                 }
     636             : 
     637             :                 /* Delay the separated channel to sync with CLDFB delay of the DirAC synthesis, and synthesize the LFE signal. */
     638      104235 :                 if ( output_config == IVAS_AUDIO_CONFIG_5_1 || output_config == IVAS_AUDIO_CONFIG_7_1 ||
     639       79719 :                      output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1_4 ||
     640       79719 :                      output_config == IVAS_AUDIO_CONFIG_5_1_2 || ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) || output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     641             :                 {
     642       32295 :                     ivas_lfe_synth_with_filters( st_ivas->hMasa->hMasaLfeSynth, p_output, output_frame, n, LFE_CHANNEL );
     643             :                 }
     644       71940 :                 else if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe == 0 )
     645             :                 {
     646             :                     /* Delay the separated channel to sync with the DirAC rendering */
     647           0 :                     delay_signal( p_output[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size );
     648             :                 }
     649             :             }
     650             :             else
     651             :             {
     652      395415 :                 if ( st_ivas->nSCE == 1 )
     653             :                 {
     654      325806 :                     if ( ( error = ivas_sce_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     655             :                     {
     656           0 :                         return error;
     657             :                     }
     658             :                 }
     659       69609 :                 else if ( st_ivas->nCPE == 1 )
     660             :                 {
     661       69609 :                     if ( ( error = ivas_cpe_dec( st_ivas, 0, p_output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
     662             :                     {
     663           0 :                         return error;
     664             :                     }
     665             :                 }
     666             :             }
     667             : 
     668      499650 :             if ( st_ivas->sba_dirac_stereo_flag ) /* use the flag to trigger the DFT upmix */
     669             :             {
     670       52860 :                 ivas_sba_dirac_stereo_dec( st_ivas, p_output, output_frame );
     671             :             }
     672             : 
     673             :             /* HP filtering */
     674     1330239 :             for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
     675             :             {
     676      830589 :                 hp20( p_output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
     677             :             }
     678             : 
     679      499650 :             if ( st_ivas->renderer_type == RENDERER_MCMASA_MONO_STEREO )
     680             :             {
     681       80622 :                 ivas_mono_stereo_downmix_mcmasa( st_ivas, p_output, output_frame );
     682             :             }
     683             :         }
     684             :     }
     685             : 
     686             :     /*----------------------------------------------------------------*
     687             :      * Common updates
     688             :      *----------------------------------------------------------------*/
     689             : 
     690    14987349 :     if ( !st_ivas->bfi ) /* do not update if first frame(s) are lost or NO_DATA */
     691             :     {
     692    14259252 :         st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate;
     693    14259252 :         st_ivas->last_active_ivas_total_brate = ( ivas_total_brate <= IVAS_SID_5k2 ) ? st_ivas->last_active_ivas_total_brate : ivas_total_brate;
     694             :     }
     695             : 
     696    14987349 :     if ( st_ivas->ini_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) ) /* keep "st_ivas->ini_frame = 0" until first good received frame */
     697             :     {
     698      369030 :         st_ivas->ini_frame++;
     699             :     }
     700             : 
     701    14987349 :     if ( st_ivas->ini_active_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && ivas_total_brate > IVAS_SID_5k2 ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */
     702             :     {
     703      369030 :         st_ivas->ini_active_frame++;
     704             :     }
     705             : 
     706    14987349 :     st_ivas->last_ivas_format = st_ivas->ivas_format;
     707             : 
     708             : #ifdef DEBUG_MODE_INFO
     709             :     dbgwrite( &st_ivas->bfi, sizeof( int16_t ), 1, output_frame, "res/bfi" );
     710             :     dbgwrite( &st_ivas->BER_detect, sizeof( int16_t ), 1, output_frame, "res/BER_detect" );
     711             :     {
     712             :         float tmpF = ivas_total_brate / 1000.0f;
     713             :         dbgwrite( &tmpF, sizeof( float ), 1, output_frame, "res/ivas_total_brate.dec" );
     714             :     }
     715             : #endif
     716             : 
     717    14987349 :     pop_wmops();
     718    14987349 :     return IVAS_ERR_OK;
     719             : }
     720             : 
     721             : 
     722             : /*--------------------------------------------------------------------------*
     723             :  * ivas_dec_get_num_tc_channels()
     724             :  *
     725             :  * Get the number of channels provided to the renderer
     726             :  *--------------------------------------------------------------------------*/
     727             : 
     728      301543 : int16_t ivas_dec_get_num_tc_channels(
     729             :     Decoder_Struct *st_ivas /* i  : IVAS decoder handle */
     730             : )
     731             : {
     732             :     int16_t num_tc;
     733             :     int32_t ivas_total_brate;
     734             :     AUDIO_CONFIG output_config;
     735             : 
     736      301543 :     if ( st_ivas->renderer_type == RENDERER_DISABLE )
     737             :     {
     738       27838 :         num_tc = st_ivas->hDecoderConfig->nchan_out;
     739             :     }
     740             :     else
     741             :     {
     742      273705 :         num_tc = st_ivas->nchan_transport;
     743             :     }
     744             : 
     745      301543 :     output_config = st_ivas->hDecoderConfig->output_config;
     746             : 
     747      301543 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     748             : 
     749      301543 :     if ( st_ivas->ivas_format == MONO_FORMAT )
     750             :     {
     751          64 :         num_tc = 1;
     752             :     }
     753      301479 :     else if ( st_ivas->ivas_format == STEREO_FORMAT && st_ivas->hDecoderConfig->nchan_out == 1 )
     754             :     {
     755          66 :         num_tc = 1;
     756             :     }
     757      301413 :     else if ( st_ivas->ivas_format == ISM_FORMAT )
     758             :     {
     759       21114 :         if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX )
     760             :         {
     761          81 :             num_tc = 1;
     762             :         }
     763             :     }
     764      280299 :     else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
     765             :     {
     766      105360 :         if ( st_ivas->sba_dirac_stereo_flag )
     767             :         {
     768        2874 :             num_tc = CPE_CHANNELS;
     769             :         }
     770      102486 :         else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ( ivas_total_brate > IVAS_SID_5k2 || ( ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE > 0 && st_ivas->hCPE[0] != NULL && st_ivas->hCPE[0]->nchan_out == 1 ) ) )
     771             :         {
     772       33456 :             num_tc = 1; /* Only one channel transported */
     773             :         }
     774             : 
     775      105360 :         if ( st_ivas->ivas_format == MASA_FORMAT && output_config == IVAS_AUDIO_CONFIG_EXTERNAL && st_ivas->nchan_transport == 2 && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2 )
     776             :         {
     777        1884 :             num_tc = CPE_CHANNELS;
     778             :         }
     779             : 
     780      105360 :         if ( st_ivas->ivas_format == SBA_FORMAT )
     781             :         {
     782       31926 :             if ( num_tc == 3 )
     783             :             {
     784        7980 :                 num_tc++;
     785             :             }
     786             :         }
     787             :     }
     788      174939 :     else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
     789             :     {
     790      100986 :         if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL )
     791             :         {
     792       94227 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
     793             :             {
     794       58062 :                 num_tc++;
     795             :             }
     796       36165 :             else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
     797             :             {
     798       36165 :                 num_tc += st_ivas->nchan_ism;
     799             :             }
     800             :         }
     801             :     }
     802       73953 :     else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
     803             :     {
     804       16164 :         if ( st_ivas->sba_dirac_stereo_flag )
     805             :         {
     806        2250 :             num_tc = CPE_CHANNELS;
     807             :         }
     808       16164 :         if ( num_tc == 3 )
     809             :         {
     810        4563 :             num_tc++;
     811             :         }
     812       16164 :         if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
     813             :         {
     814        7278 :             num_tc += st_ivas->nchan_ism;
     815             :         }
     816             :     }
     817       57789 :     else if ( st_ivas->ivas_format == MC_FORMAT )
     818             :     {
     819       57648 :         if ( output_config == IVAS_AUDIO_CONFIG_MONO )
     820             :         {
     821          15 :             num_tc = 1;
     822             :         }
     823       57633 :         else if ( output_config == IVAS_AUDIO_CONFIG_STEREO )
     824             :         {
     825        2967 :             num_tc = 2;
     826             :         }
     827       54666 :         else if ( st_ivas->mc_mode == MC_MODE_MCT )
     828             :         {
     829             :             /* do all static dmx already in the TC decoder if less channels than transported... */
     830       22191 :             if ( st_ivas->transport_config != st_ivas->intern_config && ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_FOA || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA2 || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA3 ) )
     831             :             {
     832         654 :                 if ( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) >= ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) )
     833             :                 {
     834           0 :                     num_tc = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
     835             :                 }
     836             :             }
     837       21537 :             else if ( ( st_ivas->renderer_type == RENDERER_MC || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) && ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) >= ( st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ) )
     838             :             {
     839           0 :                 num_tc = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe;
     840             :             }
     841             :         }
     842       32475 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
     843             :         {
     844        1704 :             num_tc = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
     845             :         }
     846       30771 :         else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
     847             :         {
     848       18000 :             if ( st_ivas->hOutSetup.separateChannelEnabled )
     849             :             {
     850        3771 :                 num_tc++;
     851             :             }
     852             : 
     853       18000 :             if ( st_ivas->hOutSetup.separateChannelEnabled && ( output_config == IVAS_AUDIO_CONFIG_5_1 || output_config == IVAS_AUDIO_CONFIG_7_1 ||
     854        3768 :                                                                 output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1_4 ||
     855        3768 :                                                                 output_config == IVAS_AUDIO_CONFIG_5_1_2 || ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) ) )
     856             :             {
     857             :                 /* LFE is synthesized in TD with the TCs */
     858           3 :                 num_tc++;
     859             :             }
     860             :         }
     861             :     }
     862             : 
     863      301543 :     return num_tc;
     864             : }
     865             : 
     866             : 
     867             : /*--------------------------------------------------------------------------*
     868             :  * ivas_dec_get_tc_buffer_mode()
     869             :  *
     870             :  *
     871             :  *--------------------------------------------------------------------------*/
     872             : 
     873      250072 : TC_BUFFER_MODE ivas_dec_get_tc_buffer_mode(
     874             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
     875             : )
     876             : {
     877             :     TC_BUFFER_MODE buffer_mode;
     878             : 
     879      250072 :     buffer_mode = TC_BUFFER_MODE_BUFFER;
     880             : 
     881      250072 :     switch ( st_ivas->renderer_type )
     882             :     {
     883             :             /* all renderers where we are done after TC decoding (might include DMX to mono/stereo */
     884       35809 :         case RENDERER_DISABLE:
     885             :         case RENDERER_MCMASA_MONO_STEREO:
     886             :         case RENDERER_OSBA_STEREO:
     887             :         case RENDERER_MONO_DOWNMIX:
     888       35809 :             buffer_mode = TC_BUFFER_MODE_BUFFER;
     889       35809 :             break;
     890      194694 :         case RENDERER_NON_DIEGETIC_DOWNMIX:
     891             :         case RENDERER_TD_PANNING:
     892             :         case RENDERER_BINAURAL_OBJECTS_TD:
     893             :         case RENDERER_BINAURAL_FASTCONV:
     894             :         case RENDERER_BINAURAL_FASTCONV_ROOM:
     895             :         case RENDERER_BINAURAL_PARAMETRIC:
     896             :         case RENDERER_BINAURAL_PARAMETRIC_ROOM:
     897             :         case RENDERER_STEREO_PARAMETRIC:
     898             :         case RENDERER_DIRAC:
     899             :         case RENDERER_PARAM_ISM:
     900             :         case RENDERER_BINAURAL_MIXER_CONV:
     901             :         case RENDERER_BINAURAL_MIXER_CONV_ROOM:
     902             :         case RENDERER_OMASA_OBJECT_EXT:
     903             :         case RENDERER_OMASA_MIX_EXT:
     904             :         case RENDERER_OSBA_AMBI:
     905             :         case RENDERER_OSBA_LS:
     906      194694 :             buffer_mode = TC_BUFFER_MODE_RENDERER;
     907      194694 :             break;
     908             :             break;
     909        4404 :         case RENDERER_MC_PARAMMC:
     910        4404 :             if ( st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO )
     911             :             {
     912         246 :                 buffer_mode = TC_BUFFER_MODE_BUFFER; /* TCs are already the DMX to mono or stereo */
     913             :             }
     914             :             else
     915             :             {
     916        4158 :                 buffer_mode = TC_BUFFER_MODE_RENDERER;
     917             :             }
     918        4404 :             break;
     919        3003 :         case RENDERER_MC:
     920        3003 :             if ( ivas_dec_get_num_tc_channels( st_ivas ) != st_ivas->hDecoderConfig->nchan_out )
     921             :             {
     922        2283 :                 buffer_mode = TC_BUFFER_MODE_RENDERER;
     923             :             }
     924        3003 :             break;
     925       12162 :         case RENDERER_SBA_LINEAR_ENC:
     926       12162 :             if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT && ( st_ivas->renderer_type == RENDERER_MC || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) && ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) >= ( st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ) )
     927             :             {
     928           0 :                 buffer_mode = TC_BUFFER_MODE_BUFFER;
     929             :             }
     930             :             else
     931             :             {
     932       12162 :                 buffer_mode = TC_BUFFER_MODE_RENDERER;
     933             :             }
     934       12162 :             break;
     935           0 :         case RENDERER_SBA_LINEAR_DEC:
     936           0 :             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 ) )
     937             :             {
     938           0 :                 buffer_mode = TC_BUFFER_MODE_BUFFER;
     939             :             }
     940             :             else
     941             :             {
     942           0 :                 buffer_mode = TC_BUFFER_MODE_RENDERER;
     943             :             }
     944           0 :             break;
     945             : #ifdef DEBUGGING
     946             :         default:
     947             :             assert( 0 );
     948             : #endif
     949             :     }
     950             : 
     951      250072 :     return buffer_mode;
     952             : }
     953             : 
     954             : 
     955             : /*--------------------------------------------------------------------------*
     956             :  * ivas_dec_tc_audio_allocate()
     957             :  *
     958             :  * allocate and initialize TC audio buffer
     959             :  *--------------------------------------------------------------------------*/
     960             : 
     961      215020 : static ivas_error ivas_dec_tc_audio_allocate(
     962             :     DECODER_TC_BUFFER_HANDLE hTcBuffer, /* i/o: TC buffer handle        */
     963             :     const int32_t output_Fs,            /* i  : output sampling rate    */
     964             :     const int16_t Opt_tsm               /* i  : TSM option flag         */
     965             : )
     966             : {
     967             :     int16_t nsamp_to_allocate;
     968             :     int16_t ch_idx, n_samp_full, n_samp_residual, offset;
     969             : 
     970      215020 :     if ( Opt_tsm )
     971             :     {
     972       64419 :         n_samp_full = ( NS2SA( output_Fs, MAX_JBM_L_FRAME_NS ) );
     973       64419 :         n_samp_full = max( n_samp_full, L_FRAME48k ); /* buffers are shared between 'hTcBuffer->tc[]' and 'p_output_f[]': ensure minimal length */
     974       64419 :         n_samp_residual = hTcBuffer->n_samples_granularity - 1;
     975             :     }
     976             :     else
     977             :     {
     978      150601 :         n_samp_full = (int16_t) ( output_Fs / FRAMES_PER_SEC );
     979      150601 :         n_samp_residual = 0;
     980             :     }
     981             : 
     982      215020 :     nsamp_to_allocate = max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ) * n_samp_full;
     983             : 
     984      215020 :     if ( Opt_tsm )
     985             :     {
     986             :         /* note: this is stack memory buffer for TC decoded and also time-scale modified audio signals */
     987       64419 :         if ( ( hTcBuffer->tc_buffer = (float *) malloc( nsamp_to_allocate * sizeof( float ) ) ) == NULL )
     988             :         {
     989           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TC Buffer\n" ) );
     990             :         }
     991       64419 :         set_zero( hTcBuffer->tc_buffer, nsamp_to_allocate );
     992             : 
     993       64419 :         offset = 0;
     994      301146 :         for ( ch_idx = 0; ch_idx < max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); ch_idx++ )
     995             :         {
     996      236727 :             hTcBuffer->tc[ch_idx] = &hTcBuffer->tc_buffer[offset];
     997      236727 :             offset += n_samp_full;
     998             :         }
     999      858396 :         for ( ; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ )
    1000             :         {
    1001      793977 :             hTcBuffer->tc[ch_idx] = NULL;
    1002             :         }
    1003             : 
    1004             :         /* memory buffer for TC audio samples not rendered in the previous frame */
    1005      301146 :         for ( ch_idx = 0; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ )
    1006             :         {
    1007      236727 :             if ( ( hTcBuffer->tc_buffer_old[ch_idx] = (float *) malloc( n_samp_residual * sizeof( float ) ) ) == NULL )
    1008             :             {
    1009           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TC Buffer\n" ) );
    1010             :             }
    1011      236727 :             set_zero( hTcBuffer->tc_buffer_old[ch_idx], n_samp_residual );
    1012             :         }
    1013      858396 :         for ( ; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ )
    1014             :         {
    1015      793977 :             hTcBuffer->tc_buffer_old[ch_idx] = NULL;
    1016             :         }
    1017             :     }
    1018             :     else
    1019             :     {
    1020      150601 :         hTcBuffer->tc_buffer = NULL;
    1021             : 
    1022     2560217 :         for ( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ )
    1023             :         {
    1024     2409616 :             hTcBuffer->tc[ch_idx] = NULL;
    1025             :         }
    1026             : 
    1027     2560217 :         for ( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ )
    1028             :         {
    1029     2409616 :             hTcBuffer->tc_buffer_old[ch_idx] = NULL;
    1030             :         }
    1031             :     }
    1032             : 
    1033      215020 :     hTcBuffer->tc_buffer2 = NULL;
    1034             : 
    1035      215020 :     return IVAS_ERR_OK;
    1036             : }
    1037             : 
    1038             : 
    1039             : /*--------------------------------------------------------------------------*
    1040             :  * ivas_dec_tc_buffer_open()
    1041             :  *
    1042             :  * Open and initialize transport channel buffer handle
    1043             :  *--------------------------------------------------------------------------*/
    1044             : 
    1045        1939 : ivas_error ivas_dec_tc_buffer_open(
    1046             :     Decoder_Struct *st_ivas,                /* i/o: IVAS decoder structure              */
    1047             :     const TC_BUFFER_MODE tc_buffer_mode,    /* i  : buffer mode                         */
    1048             :     const int16_t nchan_transport_rend,     /* i  : number of TCs for rendering         */
    1049             :     const int16_t nchan_transport_internal, /* i  : number of totally buffered channels */
    1050             :     const int16_t nchan_full,               /* i  : number of channels to fully store   */
    1051             :     const int16_t n_samples_granularity     /* i  : granularity of the renderer/buffer  */
    1052             : )
    1053             : {
    1054             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    1055             :     int16_t nMaxSlotsPerSubframe;
    1056             :     ivas_error error;
    1057             : 
    1058             :     /*-----------------------------------------------------------------*
    1059             :      * prepare library opening
    1060             :      *-----------------------------------------------------------------*/
    1061             : 
    1062        1939 :     if ( ( hTcBuffer = (DECODER_TC_BUFFER_HANDLE) malloc( sizeof( DECODER_TC_BUFFER ) ) ) == NULL )
    1063             :     {
    1064           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TC Buffer\n" ) );
    1065             :     }
    1066             : 
    1067        1939 :     hTcBuffer->tc_buffer_mode = tc_buffer_mode;
    1068        1939 :     hTcBuffer->nchan_transport_rend = nchan_transport_rend;
    1069        1939 :     hTcBuffer->nchan_transport_internal = nchan_transport_internal;
    1070        1939 :     hTcBuffer->nchan_buffer_full = nchan_full;
    1071        1939 :     hTcBuffer->n_samples_granularity = n_samples_granularity;
    1072        1939 :     hTcBuffer->n_samples_available = 0;
    1073        1939 :     hTcBuffer->n_samples_buffered = 0;
    1074        1939 :     hTcBuffer->n_samples_rendered = 0;
    1075        1939 :     hTcBuffer->slots_rendered = 0;
    1076        1939 :     hTcBuffer->subframes_rendered = 0;
    1077        1939 :     hTcBuffer->n_samples_discard = 0;
    1078        1939 :     hTcBuffer->n_samples_flushed = 0;
    1079        1939 :     hTcBuffer->nb_subframes = MAX_PARAM_SPATIAL_SUBFRAMES;
    1080             : 
    1081        1939 :     nMaxSlotsPerSubframe = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / hTcBuffer->n_samples_granularity;
    1082        1939 :     hTcBuffer->num_slots = nMaxSlotsPerSubframe * MAX_PARAM_SPATIAL_SUBFRAMES;
    1083        1939 :     set_s( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
    1084        1939 :     set_s( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES );
    1085             : 
    1086        1939 :     if ( ( error = ivas_dec_tc_audio_allocate( hTcBuffer, st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->Opt_tsm ) ) != IVAS_ERR_OK )
    1087             :     {
    1088           0 :         return error;
    1089             :     }
    1090             : 
    1091        1939 :     st_ivas->hTcBuffer = hTcBuffer;
    1092             : 
    1093        1939 :     return IVAS_ERR_OK;
    1094             : }
    1095             : 
    1096             : 
    1097             : /*--------------------------------------------------------------------------*
    1098             :  * ivas_dec_tc_audio_deallocate()
    1099             :  *
    1100             :  * deallocate TC audio buffer
    1101             :  *--------------------------------------------------------------------------*/
    1102             : 
    1103      215020 : static void ivas_dec_tc_audio_deallocate(
    1104             :     DECODER_TC_BUFFER_HANDLE hTcBuffer /* i/o: TC buffer handle     */
    1105             : )
    1106             : {
    1107             :     int16_t ch_idx;
    1108             : 
    1109      215020 :     if ( hTcBuffer != NULL )
    1110             :     {
    1111      215020 :         if ( hTcBuffer->tc_buffer != NULL )
    1112             :         {
    1113     1095123 :             for ( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ )
    1114             :             {
    1115     1030704 :                 hTcBuffer->tc[ch_idx] = NULL;
    1116             :             }
    1117             : 
    1118       64419 :             free( hTcBuffer->tc_buffer );
    1119       64419 :             hTcBuffer->tc_buffer = NULL;
    1120             :         }
    1121             : 
    1122     3655340 :         for ( ch_idx = 0; ch_idx < MAX_INTERN_CHANNELS; ch_idx++ )
    1123             :         {
    1124     3440320 :             if ( hTcBuffer->tc_buffer_old[ch_idx] != NULL )
    1125             :             {
    1126      236727 :                 free( hTcBuffer->tc_buffer_old[ch_idx] );
    1127      236727 :                 hTcBuffer->tc_buffer_old[ch_idx] = NULL;
    1128             :             }
    1129             :         }
    1130             : 
    1131      215020 :         if ( hTcBuffer->tc_buffer2 != NULL )
    1132             :         {
    1133      180754 :             free( hTcBuffer->tc_buffer2 );
    1134      180754 :             hTcBuffer->tc_buffer2 = NULL;
    1135             :         }
    1136             :     }
    1137             : 
    1138      215020 :     return;
    1139             : }
    1140             : 
    1141             : 
    1142             : /*--------------------------------------------------------------------------*
    1143             :  * ivas_dec_tc_buffer_close()
    1144             :  *
    1145             :  * Close transport channel buffer handle
    1146             :  *--------------------------------------------------------------------------*/
    1147             : 
    1148        1939 : void ivas_dec_tc_buffer_close(
    1149             :     DECODER_TC_BUFFER_HANDLE *phTcBuffer /* i/o: TC buffer handle */
    1150             : )
    1151             : {
    1152        1939 :     if ( *phTcBuffer != NULL )
    1153             :     {
    1154        1939 :         ivas_dec_tc_audio_deallocate( *phTcBuffer );
    1155             : 
    1156        1939 :         free( *phTcBuffer );
    1157        1939 :         *phTcBuffer = NULL;
    1158             :     }
    1159             : 
    1160        1939 :     return;
    1161             : }
    1162             : 
    1163             : 
    1164             : /*--------------------------------------------------------------------------*
    1165             :  * ivas_dec_tc_buffer_reconfigure()
    1166             :  *
    1167             :  * Reconfigure transport channel buffer handle
    1168             :  *--------------------------------------------------------------------------*/
    1169             : 
    1170      213081 : ivas_error ivas_dec_tc_buffer_reconfigure(
    1171             :     Decoder_Struct *st_ivas,                /* i/o: IVAS decoder structure                  */
    1172             :     const TC_BUFFER_MODE tc_buffer_mode,    /* i  : new buffer mode                         */
    1173             :     const int16_t nchan_transport_rend,     /* i  : new number of TCs for rendering         */
    1174             :     const int16_t nchan_transport_internal, /* i  : new number of totally buffered channels */
    1175             :     const int16_t nchan_full,               /* i  : new number of channels to fully store   */
    1176             :     const int16_t n_samples_granularity     /* i  : new granularity of the renderer/buffer  */
    1177             : )
    1178             : {
    1179             :     int16_t ch_idx, num_tc_buffer_mem, n_samples_still_available;
    1180             :     float tc_buffer_mem[MAX_INTERN_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES - 1];
    1181             :     ivas_error error;
    1182             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    1183             : 
    1184      213081 :     hTcBuffer = st_ivas->hTcBuffer;
    1185             : 
    1186      213081 :     num_tc_buffer_mem = 0;
    1187      213081 :     n_samples_still_available = 0;
    1188             : 
    1189      213081 :     if ( st_ivas->hDecoderConfig->Opt_tsm )
    1190             :     {
    1191             :         /* save samples of the TC buffer from the previous frame */
    1192       64308 :         num_tc_buffer_mem = min( hTcBuffer->nchan_transport_internal, nchan_transport_internal );
    1193       64308 :         n_samples_still_available = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_rendered;
    1194             : 
    1195             :         /* what is remaining from last frame needs always be smaller than the new granularity */
    1196       64308 :         assert( n_samples_still_available < n_samples_granularity );
    1197             : 
    1198      238152 :         for ( ch_idx = 0; ch_idx < num_tc_buffer_mem; ch_idx++ )
    1199             :         {
    1200      173844 :             mvr2r( hTcBuffer->tc_buffer_old[ch_idx] + hTcBuffer->n_samples_flushed, tc_buffer_mem[ch_idx], n_samples_still_available );
    1201             :         }
    1202             :     }
    1203             : 
    1204             :     /* if granularity changes, adapt subframe_nb_slots */
    1205      213081 :     if ( n_samples_granularity != hTcBuffer->n_samples_granularity )
    1206             :     {
    1207             : #ifdef DEBUGGING
    1208             :         int16_t nMaxSlotsPerSubframeOld;
    1209             : #endif
    1210             :         int16_t nMaxSlotsPerSubframeNew;
    1211             : 
    1212       48057 :         nMaxSlotsPerSubframeNew = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / n_samples_granularity;
    1213             : #ifdef DEBUGGING
    1214             :         nMaxSlotsPerSubframeOld = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity;
    1215             :         assert( hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] == nMaxSlotsPerSubframeOld );
    1216             :         if ( n_samples_granularity < hTcBuffer->n_samples_granularity )
    1217             :         {
    1218             :             assert( ( hTcBuffer->n_samples_granularity % n_samples_granularity ) == 0 );
    1219             :         }
    1220             :         else
    1221             :         {
    1222             :             assert( ( n_samples_granularity % hTcBuffer->n_samples_granularity ) == 0 );
    1223             :         }
    1224             : #endif
    1225             :         /* if samples were flushed, take that into account here */
    1226       48057 :         if ( n_samples_granularity < hTcBuffer->n_samples_granularity && hTcBuffer->n_samples_flushed > 0 )
    1227             :         {
    1228        4368 :             hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = hTcBuffer->n_samples_flushed / n_samples_granularity;
    1229        4368 :             hTcBuffer->n_samples_flushed = 0;
    1230             :         }
    1231             :         else
    1232             :         {
    1233       43689 :             hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = nMaxSlotsPerSubframeNew;
    1234             :         }
    1235             :     }
    1236             : 
    1237      213081 :     hTcBuffer->tc_buffer_mode = tc_buffer_mode;
    1238      213081 :     hTcBuffer->nchan_transport_rend = nchan_transport_rend;
    1239      213081 :     hTcBuffer->nchan_transport_internal = nchan_transport_internal;
    1240      213081 :     hTcBuffer->nchan_buffer_full = nchan_full;
    1241      213081 :     hTcBuffer->n_samples_granularity = n_samples_granularity;
    1242             : 
    1243             :     /* reallocate TC audio buffers */
    1244             : 
    1245      213081 :     ivas_dec_tc_audio_deallocate( hTcBuffer );
    1246             : 
    1247      213081 :     if ( ( error = ivas_dec_tc_audio_allocate( hTcBuffer, st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->Opt_tsm ) ) != IVAS_ERR_OK )
    1248             :     {
    1249           0 :         return error;
    1250             :     }
    1251             : 
    1252             :     /* propagate samples of the TC buffer from the previous frame */
    1253      386925 :     for ( ch_idx = 0; ch_idx < num_tc_buffer_mem; ch_idx++ )
    1254             :     {
    1255      173844 :         mvr2r( tc_buffer_mem[ch_idx], hTcBuffer->tc_buffer_old[ch_idx], n_samples_still_available );
    1256             :     }
    1257             : 
    1258      213081 :     return IVAS_ERR_OK;
    1259             : }

Generated by: LCOV version 1.14