LCOV - code coverage report
Current view: top level - lib_dec - ivas_dec_render.c (source / functions) Hit Total Coverage
Test: Coverage on main -- long test vectors @ efe53129c9ed87a5067dd0a8fb9dca41db9c4add Lines: 573 633 90.5 %
Date: 2026-02-12 08:06:16 Functions: 16 16 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             : #include <math.h>
      43             : #ifdef DEBUGGING
      44             : #include "debug.h"
      45             : #endif
      46             : #include "wmc_auto.h"
      47             : 
      48             : 
      49             : /*-----------------------------------------------------------------------*
      50             :  * Local function prototypes
      51             :  *-----------------------------------------------------------------------*/
      52             : 
      53             : 
      54             : static void ivas_dec_tc_buffer_playout( Decoder_Struct *st_ivas, const uint16_t nSamplesAsked, uint16_t *nSamplesRendered, float *output[] );
      55             : 
      56             : static void ivas_jbm_dec_copy_masa_meta_to_buffer( Decoder_Struct *st_ivas );
      57             : 
      58             : static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const int16_t nCldfbTs );
      59             : 
      60             : 
      61             : /*--------------------------------------------------------------------------*
      62             :  * ivas_dec_feed_tc_to_renderer()
      63             :  *
      64             :  * Feed decoded transport channels to the IVAS renderer routine
      65             :  * + digest TC channels in ParamISM and ParamMC
      66             :  *--------------------------------------------------------------------------*/
      67             : 
      68    15136445 : void ivas_dec_feed_tc_to_renderer(
      69             :     Decoder_Struct *st_ivas,            /* i/o: IVAS decoder structure                          */
      70             :     const int16_t nSamplesForRendering, /* i  : number of TC samples available for rendering    */
      71             :     int16_t *nSamplesResidual           /* o  : number of samples not fitting into the renderer grid and buffer for the next call*/
      72             : )
      73             : {
      74             :     float tmp_buf[MAX_JBM_L_FRAME48k];
      75             :     float *p_data_f[FOA_CHANNELS + MAX_NUM_OBJECTS];
      76             :     int16_t n, n_render_timeslots, n_ch_cldfb, ch;
      77             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
      78             : 
      79    15136445 :     hTcBuffer = st_ivas->hTcBuffer;
      80    15136445 :     n_ch_cldfb = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;
      81             : 
      82    15136445 :     if ( st_ivas->hDecoderConfig->Opt_tsm )
      83             :     {
      84             :         int16_t n_samples_still_available;
      85             :         int16_t n_ch_full_copy, n_ch_res_copy;
      86             : 
      87      813619 :         n_samples_still_available = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_rendered;
      88      813619 :         hTcBuffer->n_samples_buffered = n_samples_still_available + nSamplesForRendering + hTcBuffer->n_samples_discard;
      89      813619 :         hTcBuffer->n_samples_available = hTcBuffer->n_samples_granularity * ( hTcBuffer->n_samples_buffered / hTcBuffer->n_samples_granularity );
      90      813619 :         *nSamplesResidual = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_available;
      91      813619 :         n_ch_full_copy = min( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full );
      92      813619 :         n_ch_res_copy = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;
      93             : 
      94     3243302 :         for ( ch = 0; ch < n_ch_full_copy; ch++ )
      95             :         {
      96     2429683 :             mvr2r( hTcBuffer->tc[ch], tmp_buf, nSamplesForRendering );
      97     2429683 :             set_zero( hTcBuffer->tc[ch], hTcBuffer->n_samples_discard );
      98     2429683 :             mvr2r( hTcBuffer->tc_buffer_old[ch], hTcBuffer->tc[ch] + hTcBuffer->n_samples_discard, n_samples_still_available );
      99     2429683 :             mvr2r( tmp_buf, hTcBuffer->tc[ch] + n_samples_still_available + hTcBuffer->n_samples_discard, nSamplesForRendering - *nSamplesResidual );
     100     2429683 :             mvr2r( tmp_buf + nSamplesForRendering - *nSamplesResidual, hTcBuffer->tc_buffer_old[ch], *nSamplesResidual );
     101             :         }
     102             : 
     103      813619 :         if ( n_ch_res_copy > 0 )
     104             :         {
     105      191064 :             for ( ; ch < hTcBuffer->nchan_transport_rend; ch++ )
     106             :             {
     107      128931 :                 p_data_f[ch] = hTcBuffer->tc[ch];
     108      128931 :                 mvr2r( hTcBuffer->tc[ch], tmp_buf, nSamplesForRendering );
     109      128931 :                 mvr2r( hTcBuffer->tc_buffer_old[ch], p_data_f[ch], n_samples_still_available );
     110      128931 :                 mvr2r( tmp_buf, p_data_f[ch] + n_samples_still_available, nSamplesForRendering - *nSamplesResidual );
     111      128931 :                 mvr2r( tmp_buf + nSamplesForRendering - *nSamplesResidual, hTcBuffer->tc_buffer_old[ch], *nSamplesResidual );
     112             :             }
     113             :         }
     114             : 
     115      813619 :         n_render_timeslots = hTcBuffer->n_samples_available / hTcBuffer->n_samples_granularity;
     116             :     }
     117             :     else
     118             :     {
     119    15125632 :         for ( n = 0; n < n_ch_cldfb; n++ )
     120             :         {
     121      802806 :             p_data_f[n] = &st_ivas->p_output_f[n][0];
     122             :         }
     123             : 
     124    14322826 :         ch = max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full );
     125    67126751 :         for ( n = 0; n < ch; n++ )
     126             :         {
     127    52803925 :             hTcBuffer->tc[n] = st_ivas->p_output_f[n]; /* note: buffers needed in the TD decorellator */
     128             :         }
     129             : 
     130    14322826 :         hTcBuffer->n_samples_buffered = nSamplesForRendering;
     131    14322826 :         hTcBuffer->n_samples_available = hTcBuffer->n_samples_buffered;
     132    14322826 :         *nSamplesResidual = 0;
     133             : 
     134    14322826 :         n_render_timeslots = DEFAULT_JBM_CLDFB_TIMESLOTS;
     135             :     }
     136             : 
     137             :     /* CLDFB analysis for ParamMC/ParamISM */
     138    15136445 :     if ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) )
     139             :     {
     140      117750 :         ivas_param_ism_dec_digest_tc( st_ivas, n_render_timeslots, p_data_f );
     141             :     }
     142    15018695 :     else if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC && hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_RENDERER )
     143             :     {
     144      335436 :         ivas_param_mc_dec_digest_tc( st_ivas, (uint8_t) n_render_timeslots, p_data_f );
     145             :     }
     146             : 
     147    15136445 :     hTcBuffer->n_samples_rendered = 0;
     148    15136445 :     hTcBuffer->subframes_rendered = 0;
     149             : 
     150    15136445 :     return;
     151             : }
     152             : 
     153             : 
     154             : /*--------------------------------------------------------------------------*
     155             :  * ivas_dec_render()
     156             :  *
     157             :  * Principal IVAS internal rendering routine
     158             :  *--------------------------------------------------------------------------*/
     159             : 
     160    34161992 : ivas_error ivas_dec_render(
     161             :     Decoder_Struct *st_ivas,             /* i/o: IVAS decoder structure                                      */
     162             :     const uint16_t nSamplesAsked,        /* i  : number of samples wanted                                    */
     163             :     uint16_t *nSamplesRendered,          /* o  : number of samples rendered                                  */
     164             :     uint16_t *nSamplesAvailableNext,     /* o  : number of samples still available in the rendering pipeline */
     165             :     const PCM_RESOLUTION pcm_resolution, /* i  : type for the decoded PCM resolution                         */
     166             :     void *data                           /* o  : output synthesis signal                                     */
     167             : )
     168             : {
     169             :     int16_t n, nchan_out;
     170             :     int16_t nchan_transport_rend;
     171             :     int16_t nchan_remapped;
     172             :     int32_t output_Fs;
     173             :     AUDIO_CONFIG output_config;
     174             :     int16_t nSamplesAskedLocal;
     175             :     ivas_error error;
     176             :     float *p_output[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS];
     177             :     float *p_tc[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS];
     178             :     int16_t nchan_out_syn_output;
     179             : 
     180    34161992 :     push_wmops( "ivas_dec_render" );
     181             :     /*----------------------------------------------------------------*
     182             :      * Initialization of local vars after struct has been set
     183             :      *----------------------------------------------------------------*/
     184             : 
     185    34161992 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     186    34161992 :     nchan_out = st_ivas->hDecoderConfig->nchan_out;
     187    34161992 :     nchan_transport_rend = st_ivas->hTcBuffer->nchan_transport_rend;
     188    34161992 :     output_config = st_ivas->hDecoderConfig->output_config;
     189    34161992 :     nSamplesAskedLocal = nSamplesAsked + st_ivas->hTcBuffer->n_samples_discard;
     190             : 
     191   717401832 :     for ( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
     192             :     {
     193   683239840 :         p_output[n] = st_ivas->p_output_f[n];
     194             :     }
     195             : 
     196    34161992 :     if ( !st_ivas->hDecoderConfig->Opt_tsm )
     197             :     {
     198   542026742 :         for ( n = 0; n < MAX_INTERN_CHANNELS; n++ )
     199             :         {
     200   510142816 :             st_ivas->hTcBuffer->tc[n] = p_output[n];
     201             :         }
     202             :     }
     203             : 
     204   158646317 :     for ( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ )
     205             :     {
     206   124484325 :         p_tc[n] = &st_ivas->hTcBuffer->tc[n][st_ivas->hTcBuffer->n_samples_rendered];
     207             :     }
     208             : 
     209             :     /*----------------------------------------------------------------*
     210             :      * Update combined orientation access index
     211             :      *----------------------------------------------------------------*/
     212             : 
     213    34161992 :     if ( st_ivas->hCombinedOrientationData != NULL )
     214             :     {
     215             :         /* take the discard samples into account here to make sure head rotation stays on the correct 5ms grid */
     216     4654360 :         st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start -= st_ivas->hTcBuffer->n_samples_discard;
     217             : 
     218     4654360 :         ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     219             :     }
     220             : 
     221             :     /*----------------------------------------------------------------*
     222             :      * Rendering
     223             :      *----------------------------------------------------------------*/
     224             : 
     225    34161992 :     *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
     226             : 
     227    34161992 :     if ( st_ivas->ivas_format == UNDEFINED_FORMAT )
     228             :     {
     229           0 :         assert( 0 );
     230             :     }
     231    34161992 :     else if ( st_ivas->hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_BUFFER )
     232             :     {
     233     7965121 :         ivas_dec_tc_buffer_playout( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output );
     234             :     }
     235    26196871 :     else if ( st_ivas->ivas_format == MONO_FORMAT || st_ivas->ivas_format == STEREO_FORMAT )
     236             :     {
     237             :         /* Rendering */
     238      165417 :         if ( st_ivas->renderer_type == RENDERER_MC )
     239             :         {
     240           0 :             ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc, p_output );
     241             :         }
     242      165417 :         else if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX )
     243             :         {
     244       72352 :             ivas_apply_non_diegetic_panning( p_tc[0], p_output, st_ivas->hDecoderConfig->non_diegetic_pan_gain, *nSamplesRendered );
     245             :         }
     246       93065 :         else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     247             :         {
     248       93065 :             ivas_stereo2sba( p_tc, p_output, *nSamplesRendered );
     249             :         }
     250             :     }
     251    26031454 :     else if ( st_ivas->ivas_format == ISM_FORMAT )
     252             :     {
     253             :         /* Rendering */
     254     3312652 :         if ( st_ivas->ism_mode == ISM_MODE_PARAM )
     255             :         {
     256      799615 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
     257             :             {
     258      487934 :                 ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output );
     259             :             }
     260      311681 :             else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     261             :             {
     262      311681 :                 ivas_param_ism_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output );
     263             : 
     264      311681 :                 if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     265             :                 {
     266             :                     /* Convert CICP19 -> Ambisonics */
     267      241997 :                     ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
     268             :                 }
     269             :             }
     270             :         }
     271             :         else /* ISM_MODE_DISC */
     272             :         {
     273             :             /* Loudspeaker or Ambisonics rendering */
     274     2513037 :             if ( st_ivas->renderer_type == RENDERER_TD_PANNING || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM )
     275             :             {
     276             :                 /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */
     277      849428 :                 ivas_ism_render_sf( st_ivas, st_ivas->renderer_type, p_output, *nSamplesRendered );
     278             :             }
     279     1663609 :             else if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX )
     280             :             {
     281       53865 :                 ivas_apply_non_diegetic_panning( p_tc[0], p_output, st_ivas->hDecoderConfig->non_diegetic_pan_gain, *nSamplesRendered );
     282             :             }
     283             : #ifdef DEBUGGING
     284             :             else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
     285             : #else
     286     1609744 :             else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     287             : #endif
     288             :             {
     289             :                 /* Convert to Ambisonics */
     290      308522 :                 ivas_ism2sba_sf( p_tc, p_output, st_ivas->hIsmRendererData, st_ivas->nchan_transport, *nSamplesRendered, st_ivas->hTcBuffer->n_samples_rendered, st_ivas->hIntSetup.ambisonics_order );
     291             :             }
     292             : 
     293             :             /* Binaural rendering */
     294     2513037 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
     295             :             {
     296     1301222 :                 if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     297             :                 {
     298           0 :                     if ( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK )
     299             :                     {
     300           0 :                         return error;
     301             :                     }
     302             :                 }
     303             :                 else
     304             :                 {
     305     1301222 :                     if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK )
     306             :                     {
     307           0 :                         return error;
     308             :                     }
     309             :                 }
     310             :             }
     311     1211815 :             else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM )
     312             :             {
     313      446438 :                 if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL,
     314      446438 :                                                                NULL, NULL, st_ivas->hTcBuffer, p_output, p_output, *nSamplesRendered, output_Fs, 0 ) ) != IVAS_ERR_OK )
     315             :                 {
     316           0 :                     return error;
     317             :                 }
     318             :             }
     319             :         }
     320             :     }
     321    22718802 :     else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
     322             :     {
     323    15989751 :         nchan_remapped = nchan_transport_rend;
     324             : 
     325             :         /* Loudspeakers, Ambisonics or Binaural rendering */
     326    15989751 :         if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
     327             :         {
     328     4021690 :             ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     329             :         }
     330    11968061 :         else if ( st_ivas->ivas_format == MASA_FORMAT )
     331             :         {
     332     1417105 :             if ( st_ivas->renderer_type == RENDERER_DIRAC )
     333             :             {
     334     1417105 :                 ivas_dirac_dec_render( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output );
     335             :             }
     336             :         }
     337             :         else
     338             :         {
     339    10550956 :             if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK )
     340             :             {
     341           0 :                 return error;
     342             :             }
     343             :         }
     344             :     }
     345     6729051 :     else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
     346             :     {
     347     1184302 :         nchan_remapped = st_ivas->nchan_transport;
     348             : 
     349     1184302 :         if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
     350             :         {
     351      683004 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
     352             :             {
     353       91638 :                 if ( ( error = ivas_omasa_dirac_td_binaural( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ) ) != IVAS_ERR_OK )
     354             :                 {
     355           0 :                     return error;
     356             :                 }
     357             :             }
     358             :             else
     359             :             {
     360      591366 :                 ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     361             :             }
     362             :         }
     363      501298 :         else if ( st_ivas->renderer_type == RENDERER_DIRAC )
     364             :         {
     365      492298 :             ivas_omasa_dirac_rend( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     366             :         }
     367        9000 :         else if ( st_ivas->renderer_type == RENDERER_OMASA_OBJECT_EXT || st_ivas->renderer_type == RENDERER_OMASA_MIX_EXT )
     368             :         {
     369        9000 :             ivas_dec_tc_buffer_playout( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output );
     370        9000 :             ivas_omasa_rearrange_channels( p_output, st_ivas->nchan_ism, *nSamplesRendered );
     371             :         }
     372             :     }
     373     5544749 :     else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
     374             :     {
     375     1781884 :         nchan_remapped = nchan_transport_rend;
     376             : 
     377             :         /* Loudspeakers, Ambisonics or Binaural rendering */
     378     1781884 :         if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
     379             :         {
     380     1130883 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
     381             :             {
     382      532534 :                 if ( ( error = ivas_osba_dirac_td_binaural( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK )
     383             :                 {
     384           0 :                     return error;
     385             :                 }
     386             :             }
     387      598349 :             else if ( st_ivas->renderer_type == RENDERER_OSBA_STEREO )
     388             :             {
     389             :                 /* shift SBA channels to avoid overwrite by ISM upmix in 1 object case and non-TSM unified channel memory*/
     390       82719 :                 if ( st_ivas->nchan_ism == 1 && st_ivas->hDecoderConfig->Opt_tsm == 0 )
     391             :                 {
     392           0 :                     mvr2r( p_tc[2], p_output[3], *nSamplesRendered );
     393           0 :                     mvr2r( p_tc[1], p_output[2], *nSamplesRendered );
     394           0 :                     p_tc[1] = p_output[2];
     395           0 :                     p_tc[2] = p_output[3];
     396             :                 }
     397             : 
     398             :                 /* render objects */
     399       82719 :                 ivas_ism_render_sf( st_ivas, st_ivas->renderer_type, p_output, *nSamplesRendered );
     400             : 
     401             :                 /* add already rendered SBA part */
     402       82719 :                 ivas_osba_stereo_add_channels( p_tc, p_output, st_ivas->hSbaIsmData->gain_bed, nchan_out, st_ivas->nchan_ism, *nSamplesRendered );
     403             :             }
     404      515630 :             else if ( st_ivas->renderer_type == RENDERER_OSBA_AMBI || st_ivas->renderer_type == RENDERER_OSBA_LS || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
     405             :             {
     406      457100 :                 if ( ( error = ivas_osba_render_sf( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK )
     407             :                 {
     408           0 :                     return error;
     409             :                 }
     410             :             }
     411       58530 :             else if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) /*EXT output = individual objects + HOA3*/
     412             :             {
     413       58530 :                 if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output[st_ivas->nchan_ism] ) ) != IVAS_ERR_OK )
     414             :                 {
     415           0 :                     return error;
     416             :                 }
     417             : 
     418      223395 :                 for ( n = 0; n < st_ivas->nchan_ism; n++ )
     419             :                 {
     420      164865 :                     mvr2r( p_tc[n], p_output[n], *nSamplesRendered );
     421             :                 }
     422             :             }
     423             :             else
     424             :             {
     425           0 :                 if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK )
     426             :                 {
     427           0 :                     return error;
     428             :                 }
     429             :             }
     430             :         }
     431      651001 :         else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
     432             :         {
     433      445589 :             ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     434     1336767 :             for ( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     435             :             {
     436      891178 :                 v_multc( p_output[n], 2.0f, p_output[n], *nSamplesRendered );
     437             :             }
     438             :         }
     439             :         else
     440             :         {
     441      205412 :             if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK )
     442             :             {
     443           0 :                 return error;
     444             :             }
     445             : 
     446      205412 :             if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     447             :             {
     448             : #ifdef DEBUGGING
     449             :                 assert( st_ivas->ism_mode == ISM_MODE_NONE );
     450             : #endif
     451      221850 :                 for ( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- )
     452             :                 {
     453      208800 :                     mvr2r( p_output[n], p_output[n + st_ivas->nchan_ism], *nSamplesRendered );
     454             :                 }
     455       65250 :                 for ( n = 0; n < st_ivas->nchan_ism; n++ )
     456             :                 {
     457       52200 :                     set_zero( p_output[n], *nSamplesRendered );
     458             :                 }
     459             :             }
     460     1936304 :             for ( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     461             :             {
     462     1730892 :                 v_multc( p_output[n], 2.0f, p_output[n], *nSamplesRendered );
     463             :             }
     464             :         }
     465             :     }
     466     3762865 :     else if ( st_ivas->ivas_format == MC_FORMAT )
     467             :     {
     468     3762865 :         if ( st_ivas->mc_mode == MC_MODE_MCT )
     469             :         {
     470     1990837 :             int16_t crendInPlaceRotation = FALSE;
     471             : 
     472     1990837 :             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 ) )
     473             :             {
     474       74605 :                 if ( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) )
     475             :                 {
     476       74605 :                     crendInPlaceRotation = TRUE;
     477       74605 :                     ivas_mc2sba( st_ivas->hTransSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE );
     478             :                 }
     479             :             }
     480             : 
     481             :             /* Rendering */
     482     1990837 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM )
     483             :             {
     484     1449370 :                 if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     485             :                 {
     486           0 :                     if ( ( error = ivas_rend_crendProcessSubframesSplitBin( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
     487           0 :                                                                             &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output : p_tc, p_output, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK )
     488             :                     {
     489           0 :                         return error;
     490             :                     }
     491             :                 }
     492             :                 else
     493             :                 {
     494     2898740 :                     if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
     495     2898740 :                                                                    &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output : p_tc, p_output, *nSamplesRendered, output_Fs, 0 ) ) != IVAS_ERR_OK )
     496             :                     {
     497           0 :                         return error;
     498             :                     }
     499             : 
     500     1449370 :                     ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output );
     501             :                 }
     502             :             }
     503      541467 :             else if ( st_ivas->renderer_type == RENDERER_MC )
     504             :             {
     505      221599 :                 ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc, p_output );
     506             :             }
     507      319868 :             else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     508             :             {
     509       37933 :                 ivas_mc2sba( st_ivas->hIntSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
     510             :             }
     511      281935 :             else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
     512             :             {
     513      281935 :                 if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     514             :                 {
     515           0 :                     if ( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK )
     516             :                     {
     517           0 :                         return error;
     518             :                     }
     519             :                 }
     520             :                 else
     521             :                 {
     522      281935 :                     if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK )
     523             :                     {
     524           0 :                         return error;
     525             :                     }
     526             : 
     527      281935 :                     ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output );
     528             :                 }
     529             :             }
     530             :         }
     531     1772028 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
     532             :         {
     533      250309 :             ivas_mc_paramupmix_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc, p_output );
     534             : 
     535             :             /* Rendering */
     536      250309 :             if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && !st_ivas->hDecoderConfig->Opt_Headrotation )
     537             :             {
     538             :                 /* handled in CLDFB domain already */
     539       62916 :                 if ( output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     540             :                 {
     541       62916 :                     ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_output, p_output );
     542             :                 }
     543             :             }
     544      187393 :             else if ( st_ivas->renderer_type == RENDERER_MC )
     545             :             {
     546           0 :                 ivas_ls_setup_conversion( st_ivas, MC_PARAMUPMIX_MAX_INPUT_CHANS, *nSamplesRendered, p_output, p_output );
     547             :             }
     548      187393 :             else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     549             :             {
     550        5705 :                 ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
     551             :             }
     552             :         }
     553     1521719 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
     554             :         {
     555      759717 :             ivas_param_mc_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output );
     556             :         }
     557      762002 :         else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
     558             :         {
     559      762002 :             nchan_remapped = st_ivas->nchan_transport;
     560             : 
     561      762002 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
     562             :             {
     563      555560 :                 ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     564             :             }
     565      206442 :             else if ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) /* rendering to CICPxx and Ambisonics */
     566             :             {
     567      206442 :                 ivas_dirac_dec_render( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output );
     568             : 
     569      206442 :                 if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     570             :                 {
     571             :                     /* we still need to copy the separate channel if available  */
     572       45766 :                     if ( st_ivas->hOutSetup.separateChannelEnabled )
     573             :                     {
     574       11431 :                         mvr2r( p_tc[LFE_CHANNEL - 1], p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
     575             :                     }
     576             : 
     577       45766 :                     ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
     578             :                 }
     579      160676 :                 else if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_5_1 && ( output_config == IVAS_AUDIO_CONFIG_5_1_2 || output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1 ) )
     580             :                 {
     581           0 :                     for ( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; n++ )
     582             :                     {
     583           0 :                         set_zero( p_output[n], *nSamplesRendered );
     584             :                     }
     585             :                 }
     586             :             }
     587             : 
     588             :             /* copy discrete C and TD LFE from internal TC to output  */
     589      762002 :             if ( st_ivas->hOutSetup.separateChannelEnabled )
     590             :             {
     591      107968 :                 if ( output_config == IVAS_AUDIO_CONFIG_5_1 || output_config == IVAS_AUDIO_CONFIG_7_1 ||
     592       50764 :                      output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1_4 ||
     593       50764 :                      output_config == IVAS_AUDIO_CONFIG_5_1_2 || ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) )
     594             :                 {
     595       57204 :                     mvr2r( p_tc[LFE_CHANNEL], p_output[LFE_CHANNEL], *nSamplesRendered );
     596       57204 :                     mvr2r( p_tc[LFE_CHANNEL - 1], p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
     597             :                 }
     598       50764 :                 else if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe == 0 )
     599             :                 {
     600           0 :                     mvr2r( p_tc[LFE_CHANNEL - 1], p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
     601             :                 }
     602             :             }
     603             :         }
     604             :     }
     605             : 
     606             :     /*----------------------------------------------------------------*
     607             :      * Write IVAS output channels
     608             :      *   - compensation for saturation
     609             :      *   - float to integer conversion
     610             :      *----------------------------------------------------------------*/
     611             : 
     612    34161992 :     st_ivas->hTcBuffer->n_samples_available -= *nSamplesRendered;
     613    34161992 :     st_ivas->hTcBuffer->n_samples_rendered += *nSamplesRendered;
     614             : 
     615             :     /* update global combined orientation start index */
     616    34161992 :     ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
     617             : 
     618    34161992 :     if ( st_ivas->hTcBuffer->n_samples_discard > 0 )
     619             :     {
     620       41727 :         for ( n = 0; n < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); n++ )
     621             :         {
     622       37356 :             p_output[n] += st_ivas->hTcBuffer->n_samples_discard;
     623             :         }
     624        4371 :         *nSamplesRendered -= st_ivas->hTcBuffer->n_samples_discard;
     625        4371 :         st_ivas->hTcBuffer->n_samples_discard = 0;
     626             :     }
     627             : 
     628    34161992 :     if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     629             :     {
     630           0 :         nchan_out_syn_output = BINAURAL_CHANNELS * st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses;
     631             : #ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR
     632           0 :         if ( st_ivas->flushing )
     633             :         {
     634           0 :             nchan_out_syn_output = BINAURAL_CHANNELS;
     635             :         }
     636             : #endif
     637             :     }
     638             :     else
     639             :     {
     640    34161992 :         nchan_out_syn_output = nchan_out;
     641             :     }
     642             : 
     643    34161992 :     if ( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 )
     644             :     {
     645    34161992 :         if ( st_ivas->ivas_format != MONO_FORMAT )
     646             :         {
     647             : #ifndef DISABLE_LIMITER
     648    33885879 :             ivas_limiter_dec( st_ivas->hLimiter, p_output, nchan_out, *nSamplesRendered, st_ivas->BER_detect );
     649             : #endif
     650             :         }
     651             :     }
     652             : 
     653    34161992 :     switch ( pcm_resolution )
     654             :     {
     655    34161992 :         case PCM_INT16:
     656             : #ifdef DEBUGGING
     657             :             st_ivas->noClipping +=
     658             : #endif
     659    34161992 :                 ivas_syn_output( p_output, *nSamplesRendered, nchan_out_syn_output, (int16_t *) data );
     660             : 
     661    34161992 :             break;
     662           0 :         case PCM_FLOAT32:
     663           0 :             ivas_buffer_deinterleaved_to_interleaved( p_output, (float *) data, nchan_out_syn_output, *nSamplesRendered );
     664           0 :             break;
     665           0 :         default:
     666           0 :             error = IVAS_ERR_UNKNOWN;
     667           0 :             break;
     668             :     }
     669             : 
     670    34161992 :     *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available;
     671             : 
     672    34161992 :     pop_wmops();
     673    34161992 :     return IVAS_ERR_OK;
     674             : }
     675             : 
     676             : 
     677             : /*--------------------------------------------------------------------------*
     678             :  * ivas_jbm_dec_flush_renderer()
     679             :  *
     680             :  * Flush samples if renderer granularity changes on a bitrate change in JBM
     681             :  *--------------------------------------------------------------------------*/
     682             : 
     683        6363 : ivas_error ivas_jbm_dec_flush_renderer(
     684             :     Decoder_Struct *st_ivas,                     /* i/o: IVAS decoder structure    */
     685             :     const int16_t tc_granularity_new,            /* i  : new renderer granularity  */
     686             :     const RENDERER_TYPE renderer_type_old,       /* i  : old renderer type         */
     687             :     const AUDIO_CONFIG intern_config_old,        /* i  : old internal config       */
     688             :     const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i  : old internal output setup */
     689             :     const MC_MODE mc_mode_old,                   /* i  : old MC mode               */
     690             :     const ISM_MODE ism_mode_old,                 /* i  : old ISM mode              */
     691             :     uint16_t *nSamplesRendered,                  /* o  : number of samples flushed */
     692             :     const PCM_RESOLUTION pcm_resolution,         /* i  : type for the decoded PCM resolution */
     693             :     void *data                                   /* o  : output synthesis signal   */
     694             : )
     695             : {
     696             :     ivas_error error;
     697             :     int16_t n_samples_still_available;
     698             :     int16_t n_slots_still_available;
     699             :     int16_t n_samples_to_render;
     700             :     int16_t ch_idx;
     701             :     int16_t n_samples_granularity;
     702             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
     703             :     float *p_output[MAX_LS_CHANNELS + MAX_NUM_OBJECTS];
     704             : 
     705        6363 :     if ( !st_ivas->hDecoderConfig->Opt_tsm )
     706             :     {
     707           0 :         return IVAS_ERR_OK;
     708             :     }
     709             : 
     710      133623 :     for ( ch_idx = 0; ch_idx < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
     711             :     {
     712      127260 :         p_output[ch_idx] = st_ivas->p_output_f[ch_idx];
     713             :     }
     714             : 
     715        6363 :     *nSamplesRendered = 0;
     716        6363 :     hTcBuffer = st_ivas->hTcBuffer;
     717        6363 :     n_samples_granularity = hTcBuffer->n_samples_granularity;
     718             : 
     719             :     /* get number of possible slots in new granularity */
     720        6363 :     n_samples_still_available = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_rendered;
     721        6363 :     n_slots_still_available = n_samples_still_available / tc_granularity_new;
     722        6363 :     *nSamplesRendered = n_slots_still_available * tc_granularity_new;
     723        6363 :     n_samples_to_render = *nSamplesRendered;
     724        6363 :     n_samples_still_available -= n_samples_to_render;
     725        6363 :     assert( n_samples_still_available < tc_granularity_new );
     726             : 
     727             :     /* update combined orientation access index */
     728        6363 :     ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     729             : 
     730        6363 :     if ( n_slots_still_available )
     731             :     {
     732             :         /* render available full slots (with new lower granularity) */
     733       29541 :         for ( ch_idx = 0; ch_idx < max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full ); ch_idx++ )
     734             :         {
     735             :             /* move it at the beginning of the TC buffer with zero padding */
     736       25173 :             mvr2r( hTcBuffer->tc_buffer_old[ch_idx], hTcBuffer->tc[ch_idx], n_samples_to_render );
     737       25173 :             set_zero( hTcBuffer->tc[ch_idx] + n_samples_to_render, hTcBuffer->n_samples_granularity - n_samples_to_render );
     738             :         }
     739             : 
     740             :         /* simple change of the slot info */
     741        4368 :         hTcBuffer->num_slots = 1;
     742        4368 :         hTcBuffer->nb_subframes = 1;
     743        4368 :         hTcBuffer->subframes_rendered = 0;
     744        4368 :         hTcBuffer->slots_rendered = 0;
     745        4368 :         hTcBuffer->subframe_nbslots[0] = 1;
     746        4368 :         hTcBuffer->n_samples_buffered = n_samples_granularity + n_samples_still_available;
     747        4368 :         hTcBuffer->n_samples_available = 0;
     748        4368 :         hTcBuffer->n_samples_flushed = n_samples_to_render;
     749        4368 :         hTcBuffer->n_samples_rendered = 0;
     750             : 
     751             : 
     752        4368 :         if ( st_ivas->ivas_format == ISM_FORMAT )
     753             :         {
     754        2205 :             if ( ism_mode_old == ISM_MODE_DISC )
     755             :             {
     756             :                 /* Binaural rendering */
     757        2205 :                 if ( renderer_type_old == RENDERER_BINAURAL_OBJECTS_TD )
     758             :                 {
     759        1086 :                     if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, n_samples_granularity ) ) != IVAS_ERR_OK )
     760             :                     {
     761           0 :                         return error;
     762             :                     }
     763             :                 }
     764        1119 :                 else if ( renderer_type_old == RENDERER_BINAURAL_MIXER_CONV_ROOM )
     765             :                 {
     766             :                     /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */
     767        1119 :                     set_f( st_ivas->hIsmRendererData->interpolator, 1.0f, n_samples_granularity );
     768             : 
     769        1119 :                     ivas_ism_render_sf( st_ivas, renderer_type_old, p_output, n_samples_granularity );
     770             : 
     771        1119 :                     if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL,
     772        1119 :                                                                    NULL, NULL, hTcBuffer, p_output, p_output, n_samples_granularity, st_ivas->hDecoderConfig->output_Fs, 0 ) ) != IVAS_ERR_OK )
     773             :                     {
     774           0 :                         return error;
     775             :                     }
     776             :                 }
     777             :             }
     778             :             else
     779             :             {
     780           0 :                 return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong ISM_MODE in VoIP renderer flushing!" );
     781             :             }
     782             :         }
     783        2163 :         else if ( st_ivas->ivas_format == MC_FORMAT )
     784             :         {
     785        1143 :             if ( mc_mode_old == MC_MODE_MCT )
     786             :             {
     787        1143 :                 int16_t crendInPlaceRotation = FALSE;
     788             : 
     789        1143 :                 if ( st_ivas->transport_config != intern_config_old && ( intern_config_old == IVAS_AUDIO_CONFIG_FOA || intern_config_old == IVAS_AUDIO_CONFIG_HOA2 || intern_config_old == IVAS_AUDIO_CONFIG_HOA3 ) )
     790             :                 {
     791         522 :                     if ( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) < ( hIntSetupOld->nchan_out_woLFE + hIntSetupOld->num_lfe ) )
     792             :                     {
     793         522 :                         crendInPlaceRotation = TRUE;
     794         522 :                         ivas_mc2sba( st_ivas->hTransSetup, hTcBuffer->tc, p_output, n_samples_granularity, hIntSetupOld->ambisonics_order, GAIN_LFE );
     795             :                     }
     796             :                 }
     797        1143 :                 if ( renderer_type_old == RENDERER_BINAURAL_MIXER_CONV || renderer_type_old == RENDERER_BINAURAL_MIXER_CONV_ROOM )
     798             :                 {
     799         522 :                     if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, intern_config_old, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
     800         522 :                                                                    hIntSetupOld, st_ivas->hEFAPdata, hTcBuffer, crendInPlaceRotation ? p_output : hTcBuffer->tc, p_output, n_samples_granularity, st_ivas->hDecoderConfig->output_Fs, 0 ) ) != IVAS_ERR_OK )
     801             :                     {
     802           0 :                         return error;
     803             :                     }
     804             : 
     805         522 :                     ivas_binaural_add_LFE( st_ivas, n_samples_granularity, hTcBuffer->tc, p_output );
     806             :                 }
     807         621 :                 else if ( renderer_type_old == RENDERER_BINAURAL_OBJECTS_TD )
     808             :                 {
     809         621 :                     if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, n_samples_granularity ) ) != IVAS_ERR_OK )
     810             :                     {
     811           0 :                         return error;
     812             :                     }
     813             : 
     814         621 :                     ivas_binaural_add_LFE( st_ivas, n_samples_granularity, hTcBuffer->tc, p_output );
     815             :                 }
     816             :                 else
     817             :                 {
     818           0 :                     return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong renderer in MCT VoIP renderer flushing!" );
     819             :                 }
     820             :             }
     821             :             else
     822             :             {
     823           0 :                 return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong MC_MODE in VoIP renderer flushing!" );
     824             :             }
     825             :         }
     826        1020 :         else if ( st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
     827             :         {
     828         741 :             if ( ism_mode_old == ISM_MASA_MODE_DISC )
     829             :             {
     830             :                 float *tc_local[MAX_NUM_OBJECTS];
     831             :                 int16_t last_dirac_md_idx;
     832             :                 uint16_t nSamplesAvailableNext;
     833             :                 ISM_MODE ism_mode_orig;
     834             :                 RENDERER_TYPE renderer_type_orig;
     835             :                 int32_t ivas_total_brate;
     836             : 
     837             :                 /* copy from ISM delay buffer to the correct place in TCs */
     838        3705 :                 for ( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
     839             :                 {
     840        2964 :                     tc_local[ch_idx] = &hTcBuffer->tc[ch_idx + 2][hTcBuffer->n_samples_rendered];
     841        2964 :                     mvr2r( st_ivas->hMasaIsmData->delayBuffer[ch_idx], tc_local[ch_idx], st_ivas->hMasaIsmData->delayBuffer_size );
     842             :                 }
     843             : 
     844             :                 /* to render flushed samples, use configuration from the last received frame */
     845         741 :                 ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     846         741 :                 renderer_type_orig = st_ivas->renderer_type;
     847         741 :                 ism_mode_orig = st_ivas->ism_mode;
     848         741 :                 st_ivas->ism_mode = ism_mode_old;
     849         741 :                 st_ivas->renderer_type = renderer_type_old;
     850         741 :                 st_ivas->hDecoderConfig->ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate;
     851         741 :                 last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1];
     852             : 
     853             :                 /* transfer adapted sf info from hTcBuffer to DirAC */
     854         741 :                 st_ivas->hSpatParamRendCom->nb_subframes = 1;
     855         741 :                 st_ivas->hSpatParamRendCom->subframes_rendered = 0;
     856         741 :                 st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     857         741 :                 st_ivas->hSpatParamRendCom->slots_rendered = 0;
     858         741 :                 st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     859         741 :                 set_s( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available );
     860             : 
     861         741 :                 if ( ( error = ivas_omasa_dirac_td_binaural( st_ivas, (uint16_t) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, CPE_CHANNELS, p_output ) ) != IVAS_ERR_OK )
     862             :                 {
     863           0 :                     return error;
     864             :                 }
     865             : 
     866             :                 /* restore original configuration */
     867         741 :                 st_ivas->ism_mode = ism_mode_orig;
     868         741 :                 st_ivas->renderer_type = renderer_type_orig;
     869         741 :                 st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate;
     870             :             }
     871             :         }
     872         279 :         else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
     873             :         {
     874         279 :             if ( ism_mode_old == ISM_SBA_MODE_DISC )
     875             :             {
     876             :                 float *tc_local[MAX_TRANSPORT_CHANNELS];
     877             :                 int16_t last_spar_md_idx;
     878             :                 int16_t last_dirac_md_idx;
     879             :                 uint16_t nSamplesAvailableNext;
     880             :                 ISM_MODE ism_mode_orig;
     881             :                 RENDERER_TYPE renderer_type_orig;
     882             :                 int32_t ivas_total_brate;
     883             : 
     884             :                 /* to render flushed samples, use configuration from the last received frame */
     885         279 :                 ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     886         279 :                 renderer_type_orig = st_ivas->renderer_type;
     887         279 :                 ism_mode_orig = st_ivas->ism_mode;
     888         279 :                 st_ivas->ism_mode = ism_mode_old;
     889         279 :                 st_ivas->renderer_type = renderer_type_old;
     890         279 :                 st_ivas->hDecoderConfig->ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate;
     891         279 :                 last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1];
     892         279 :                 last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1];
     893             : #ifdef DEBUGGING
     894             :                 assert( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV );
     895             : #endif
     896             : 
     897             :                 /* copy from ISM delay buffer to the correct place in TCs */
     898         837 :                 for ( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
     899             :                 {
     900         558 :                     tc_local[ch_idx] = &st_ivas->hTcBuffer->tc[ch_idx][hTcBuffer->n_samples_rendered];
     901         558 :                     mvr2r( st_ivas->hSbaIsmData->delayBuffer[ch_idx], tc_local[ch_idx], st_ivas->hSbaIsmData->delayBuffer_size );
     902             :                 }
     903             : 
     904             :                 /* transfer adapted sf info from hTcBuffer to SPAR and DirAC */
     905         279 :                 st_ivas->hSpar->nb_subframes = 1;
     906         279 :                 st_ivas->hSpar->subframes_rendered = 0;
     907         279 :                 st_ivas->hSpar->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     908         279 :                 st_ivas->hSpar->slots_rendered = 0;
     909         279 :                 st_ivas->hSpar->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     910         279 :                 st_ivas->hSpatParamRendCom->nb_subframes = 1;
     911         279 :                 st_ivas->hSpatParamRendCom->subframes_rendered = 0;
     912         279 :                 st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     913         279 :                 st_ivas->hSpatParamRendCom->slots_rendered = 0;
     914         279 :                 st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     915             : 
     916             :                 /* also adapt md maps, just use the last index */
     917         279 :                 set_s( st_ivas->hSpar->render_to_md_map, last_spar_md_idx, n_slots_still_available );
     918         279 :                 set_s( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available );
     919             : 
     920             :                 /* render the last subframe */
     921         279 :                 if ( ( error = ivas_osba_dirac_td_binaural( st_ivas, (uint16_t) n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK )
     922             :                 {
     923           0 :                     return error;
     924             :                 }
     925             : 
     926             :                 /* restore original configuration */
     927         279 :                 st_ivas->ism_mode = ism_mode_orig;
     928         279 :                 st_ivas->renderer_type = renderer_type_orig;
     929         279 :                 st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate;
     930             :             }
     931             :         }
     932             :         else
     933             :         {
     934           0 :             return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong IVAS format in VoIP renderer flushing!" );
     935             :         }
     936             : 
     937        4368 :         hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity;
     938             :     }
     939             : 
     940             :     /* update global combined orientation start index */
     941        6363 :     ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
     942             : 
     943        6363 :     *nSamplesRendered = n_samples_to_render;
     944             : 
     945             :     /* Only write out the valid data*/
     946        6363 :     if ( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 )
     947             :     {
     948        6363 :         if ( st_ivas->ivas_format != MONO_FORMAT )
     949             :         {
     950             : #ifndef DISABLE_LIMITER
     951        6363 :             ivas_limiter_dec( st_ivas->hLimiter, p_output, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect );
     952             : #endif
     953             :         }
     954             :     }
     955             : 
     956        6363 :     switch ( pcm_resolution )
     957             :     {
     958        6363 :         case PCM_INT16:
     959             : #ifdef DEBUGGING
     960             :             st_ivas->noClipping +=
     961             : #endif
     962        6363 :                 ivas_syn_output( p_output, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, (int16_t *) data );
     963        6363 :             break;
     964           0 :         case PCM_FLOAT32:
     965           0 :             ivas_buffer_deinterleaved_to_interleaved( p_output, (float *) data, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered );
     966           0 :             break;
     967           0 :         default:
     968           0 :             error = IVAS_ERR_UNKNOWN;
     969           0 :             break;
     970             :     }
     971             : 
     972        6363 :     return IVAS_ERR_OK;
     973             : }
     974             : 
     975             : 
     976             : /*--------------------------------------------------------------------------*
     977             :  * ivas_jbm_dec_set_discard_samples()
     978             :  *
     979             :  * Set number of samples to discard in the first subframe
     980             :  * if the renderer granularity changes on a bitrate change in JBM processing
     981             :  *--------------------------------------------------------------------------*/
     982             : 
     983       24042 : ivas_error ivas_jbm_dec_set_discard_samples(
     984             :     Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */
     985             : )
     986             : {
     987             :     int16_t nMaxSlotsPerSubframe, nSlotsInFirstSubframe;
     988             : 
     989             :     /* render first frame with front zero padding and discarding those samples */
     990       24042 :     nMaxSlotsPerSubframe = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity;
     991       24042 :     nSlotsInFirstSubframe = nMaxSlotsPerSubframe - st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1];
     992             : 
     993       24042 :     if ( nSlotsInFirstSubframe > 0 )
     994             :     {
     995        4371 :         st_ivas->hTcBuffer->n_samples_discard = ( nMaxSlotsPerSubframe - nSlotsInFirstSubframe ) * st_ivas->hTcBuffer->n_samples_granularity;
     996             :         /* set last subframes number to max to ensure correct continuation */
     997        4371 :         st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nMaxSlotsPerSubframe;
     998             :     }
     999             : 
    1000       24042 :     return IVAS_ERR_OK;
    1001             : }
    1002             : 
    1003             : 
    1004             : /*--------------------------------------------------------------------------*
    1005             :  * ivas_dec_get_adapted_linear_interpolator()
    1006             :  *
    1007             :  * Get an interpolator that is adapted to (time scale modified) IVAS frame
    1008             :  *--------------------------------------------------------------------------*/
    1009             : 
    1010      744123 : void ivas_dec_get_adapted_linear_interpolator(
    1011             :     const int16_t default_interp_length, /* i  : default length of the (full-frame) interpolator */
    1012             :     const int16_t interp_length,         /* i  : length of the interpolator to be created        */
    1013             :     float *interpolator                  /* o  : the interpolator                                */
    1014             : )
    1015             : {
    1016             :     int16_t segment_len, idx;
    1017             :     float dec;
    1018             : #ifdef DEBUGGING
    1019             :     assert( default_interp_length % 2 == 0 );
    1020             : #endif
    1021             : 
    1022      744123 :     segment_len = ( default_interp_length >> 1 );
    1023      744123 :     dec = 1.0f / default_interp_length;
    1024             : 
    1025      744123 :     interpolator[interp_length - 1] = 1.0f;
    1026    26664261 :     for ( idx = interp_length - 2; idx >= segment_len; idx-- )
    1027             :     {
    1028    25920138 :         interpolator[idx] = max( 0.0f, interpolator[idx + 1] - dec );
    1029             :     }
    1030             : 
    1031      744123 :     if ( interpolator[idx + 1] > 0.0f )
    1032             :     {
    1033      744117 :         dec = interpolator[idx + 1] / ( segment_len + 1 );
    1034    27419022 :         for ( ; idx >= 0; idx-- )
    1035             :         {
    1036    26674905 :             interpolator[idx] = interpolator[idx + 1] - dec;
    1037             :         }
    1038             :     }
    1039             :     else
    1040             :     {
    1041           6 :         set_f( interpolator, 0.0f, idx + 1 );
    1042             :     }
    1043             : 
    1044      744123 :     return;
    1045             : }
    1046             : 
    1047             : 
    1048             : /*--------------------------------------------------------------------------*
    1049             :  * ivas_dec_get_adapted_subframes()
    1050             :  *
    1051             :  * Get an interpolator that is adapted to (time scale modified) IVAS frame
    1052             :  *--------------------------------------------------------------------------*/
    1053             : 
    1054    11779698 : void ivas_dec_get_adapted_subframes(
    1055             :     const int16_t nCldfbTs,    /* i  : number of time slots in the current frame */
    1056             :     int16_t *subframe_nbslots, /* i/o: subframe grid                             */
    1057             :     int16_t *nb_subframes      /* i/o: number of subframes in the frame          */
    1058             : )
    1059             : {
    1060             :     uint16_t nSlotsInLastSubframe, nSlotsInFirstSubframe;
    1061    11779698 :     uint16_t nCldfbSlotsLocal = nCldfbTs;
    1062             : 
    1063             :     /* get last subframe size from previous frame, determine how many slots have to be processed
    1064             :            in the first subframe (i.e. potential leftover of a 5ms subframe) */
    1065    11779698 :     nSlotsInFirstSubframe = ( PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - subframe_nbslots[*nb_subframes - 1] );
    1066    11779698 :     *nb_subframes = 0;
    1067    11779698 :     if ( nSlotsInFirstSubframe > 0 )
    1068             :     {
    1069      356115 :         *nb_subframes = 1;
    1070      356115 :         nCldfbSlotsLocal -= nSlotsInFirstSubframe;
    1071             :     }
    1072             : 
    1073    11779698 :     *nb_subframes += (int16_t) ceilf( (float) nCldfbSlotsLocal / (float) PARAM_MC_MAX_NSLOTS_IN_SUBFRAME );
    1074    11779698 :     nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME;
    1075             : 
    1076    11779698 :     set_s( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
    1077    11779698 :     set_s( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes );
    1078             : 
    1079    11779698 :     if ( nSlotsInFirstSubframe > 0 )
    1080             :     {
    1081      356115 :         subframe_nbslots[0] = nSlotsInFirstSubframe;
    1082             :     }
    1083             : 
    1084    11779698 :     if ( nSlotsInLastSubframe > 0 )
    1085             :     {
    1086      356178 :         subframe_nbslots[*nb_subframes - 1] = nSlotsInLastSubframe;
    1087             :     }
    1088             : 
    1089    11779698 :     return;
    1090             : }
    1091             : 
    1092             : 
    1093             : /*--------------------------------------------------------------------------*
    1094             :  * ivas_dec_get_md_map()
    1095             :  *
    1096             :  * Get an meta data map adapted to (time scale modified) IVAS frame
    1097             :  *--------------------------------------------------------------------------*/
    1098             : 
    1099    10063914 : void ivas_dec_get_md_map(
    1100             :     const int16_t default_len,  /* i  : default frame length in metadata slots          */
    1101             :     const int16_t len,          /* i  : length of the modified frames in metadata slots */
    1102             :     const int16_t subframe_len, /* i  : default length of a subframe                    */
    1103             :     const int16_t offset,       /* i  : current read offset into the MD buffer          */
    1104             :     const int16_t buf_len,      /* i  : length of the metadata buffer                   */
    1105             :     int16_t *map                /* o  : metadata index map                              */
    1106             : )
    1107             : {
    1108             :     int16_t jbm_segment_len, map_idx, src_idx, src_idx_map;
    1109             :     float dec, src_idx_f;
    1110             : 
    1111             : #ifdef DEBUGGING
    1112             :     assert( default_len % 2 == 0 );
    1113             : #endif
    1114    10063914 :     jbm_segment_len = ( default_len >> 1 );
    1115    10063914 :     dec = 1.0f / default_len;
    1116             : 
    1117    90573705 :     for ( map_idx = len - 1, src_idx = default_len - 1; map_idx >= jbm_segment_len; map_idx--, src_idx-- )
    1118             :     {
    1119    80509791 :         src_idx_map = max( 0, src_idx / subframe_len );
    1120    80509791 :         map[map_idx] = ( offset + src_idx_map ) % buf_len;
    1121             :     }
    1122             : 
    1123             :     /* changed part (first segment), interpolate index to parameters
    1124             :            (we do not want to interpolate and smooth acutal direction/diffuseness values even more) */
    1125    10063914 :     if ( src_idx >= 0 )
    1126             :     {
    1127    10063893 :         dec = ( (float) ( src_idx + 1 ) ) / ( (float) jbm_segment_len );
    1128    10063893 :         src_idx_f = (float) ( src_idx + 1 ) - dec;
    1129    90575037 :         for ( ; map_idx >= 0; map_idx-- )
    1130             :         {
    1131    80511144 :             src_idx = max( 0, ( (int16_t) round_f( src_idx_f ) ) / subframe_len );
    1132    80511144 :             map[map_idx] = ( offset + src_idx ) % buf_len;
    1133    80511144 :             src_idx_f -= dec;
    1134             :         }
    1135             :     }
    1136             :     else
    1137             :     {
    1138          21 :         set_s( map, offset, map_idx + 1 );
    1139             :     }
    1140             : 
    1141    10063914 :     return;
    1142             : }
    1143             : 
    1144             : 
    1145             : /*--------------------------------------------------------------------------*
    1146             :  * ivas_dec_get_md_map_even_spacing()
    1147             :  *
    1148             :  * Get an meta data map adapted to (time scale modified) IVAS frame.
    1149             :  * Distribute slots evenly across the (modified) frame.
    1150             :  *--------------------------------------------------------------------------*/
    1151             : 
    1152     1441701 : void ivas_dec_get_md_map_even_spacing(
    1153             :     const int16_t len,          /* i  : length of the modified frames in metadata slots */
    1154             :     const int16_t subframe_len, /* i  : default length of a subframe                    */
    1155             :     const int16_t offset,       /* i  : current read offset into the MD buffer          */
    1156             :     const int16_t buf_len,      /* i  : length of the metadata buffer                   */
    1157             :     int16_t *map                /* o  : metadata index map                              */
    1158             : )
    1159             : {
    1160             :     int16_t map_idx, sf_idx, sf_length, increment, subframes_written;
    1161             :     float decimal, decimal_sum, eps;
    1162             :     int16_t subframe_map_length[MAX_PARAM_SPATIAL_SUBFRAMES];
    1163             : 
    1164             :     /* subframe map length */
    1165     1441701 :     sf_length = len / subframe_len;
    1166     1441701 :     if ( len % subframe_len == 0 )
    1167             :     {
    1168             :         /* even subframes */
    1169     7207320 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1170             :         {
    1171     5765856 :             subframe_map_length[sf_idx] = sf_length;
    1172             :         }
    1173             :     }
    1174             :     else
    1175             :     {
    1176             :         /* uneven subframes */
    1177         237 :         decimal = ( (float) len / (float) subframe_len ) - (float) sf_length;
    1178         237 :         decimal_sum = decimal;
    1179         237 :         eps = 0.001f;
    1180        1185 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1181             :         {
    1182         948 :             increment = (int16_t) floorf( decimal_sum + eps );
    1183         948 :             subframe_map_length[sf_idx] = sf_length + increment;
    1184         948 :             if ( increment > 0 )
    1185             :             {
    1186         411 :                 decimal_sum -= 1.0f;
    1187             :             }
    1188         948 :             decimal_sum += decimal;
    1189             :         }
    1190             :     }
    1191             : 
    1192             :     /* map slots to subframes */
    1193     1441701 :     sf_idx = 0;
    1194     1441701 :     subframes_written = 0;
    1195    24507624 :     for ( map_idx = 0; map_idx < len; map_idx++ )
    1196             :     {
    1197    23065923 :         map[map_idx] = ( offset + sf_idx ) % buf_len;
    1198    23065923 :         if ( map_idx - subframes_written >= subframe_map_length[sf_idx] - 1 )
    1199             :         {
    1200     5766804 :             subframes_written += subframe_map_length[sf_idx];
    1201     5766804 :             ++sf_idx;
    1202             :         }
    1203             :     }
    1204             : 
    1205     1441701 :     return;
    1206             : }
    1207             : 
    1208             : 
    1209             : /*--------------------------------------------------------------------------*
    1210             :  * ivas_dec_get_render_granularity()
    1211             :  *
    1212             :  * Get renderer granularity
    1213             :  *--------------------------------------------------------------------------*/
    1214             : 
    1215             : /*! r: render granularity */
    1216      287116 : int16_t ivas_dec_get_render_granularity(
    1217             :     const RENDERER_TYPE renderer_type,     /* i  : renderer type            */
    1218             :     const RENDERER_TYPE renderer_type_sec, /* i  : secondary renderer type  */
    1219             :     const int32_t output_Fs                /* i  : sampling rate            */
    1220             : )
    1221             : {
    1222             :     int16_t render_granularity;
    1223             : 
    1224      287116 :     if ( renderer_type == RENDERER_BINAURAL_OBJECTS_TD ||                                                       /* TD renderer */
    1225      275518 :          renderer_type == RENDERER_BINAURAL_MIXER_CONV || renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM || /* Crend */
    1226             :          renderer_type_sec == RENDERER_BINAURAL_OBJECTS_TD                                                      /* TD rend as a secondary renderer -> set the common granularity for both renderers */
    1227             :     )
    1228             :     {
    1229             :         /* 5 ms granularity */
    1230       38490 :         render_granularity = NS2SA( output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
    1231             :     }
    1232             :     else
    1233             :     {
    1234             :         /* 1.25 ms granularity */
    1235      248626 :         render_granularity = NS2SA( output_Fs, CLDFB_SLOT_NS );
    1236             :     }
    1237             : 
    1238      287116 :     return render_granularity;
    1239             : }
    1240             : 
    1241             : 
    1242             : /*--------------------------------------------------------------------------*
    1243             :  * ivas_dec_tc_buffer_playout()
    1244             :  *
    1245             :  * Get TC buffer playout
    1246             :  *--------------------------------------------------------------------------*/
    1247             : 
    1248     7974121 : static void ivas_dec_tc_buffer_playout(
    1249             :     Decoder_Struct *st_ivas,
    1250             :     const uint16_t nSamplesAsked,
    1251             :     uint16_t *nSamplesRendered,
    1252             :     float *output[] )
    1253             : {
    1254             :     int16_t ch_idx, slot_size, slots_to_render, first_sf, last_sf;
    1255             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    1256             : 
    1257     7974121 :     hTcBuffer = st_ivas->hTcBuffer;
    1258     7974121 :     slot_size = hTcBuffer->n_samples_granularity;
    1259             : 
    1260             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    1261     7974121 :     slots_to_render = min( hTcBuffer->num_slots - hTcBuffer->slots_rendered, nSamplesAsked / slot_size );
    1262     7974121 :     hTcBuffer->slots_rendered += slots_to_render;
    1263     7974121 :     *nSamplesRendered = (uint16_t) slots_to_render * slot_size;
    1264     7974121 :     first_sf = hTcBuffer->subframes_rendered;
    1265     7974121 :     last_sf = first_sf;
    1266             : 
    1267    23753718 :     while ( slots_to_render > 0 )
    1268             :     {
    1269    15779597 :         slots_to_render -= hTcBuffer->subframe_nbslots[last_sf];
    1270    15779597 :         last_sf++;
    1271             :     }
    1272             : #ifdef DEBUGGING
    1273             :     assert( slots_to_render == 0 );
    1274             : #endif
    1275             : 
    1276    23588692 :     for ( ch_idx = 0; ch_idx < hTcBuffer->nchan_transport_rend; ch_idx++ )
    1277             :     {
    1278    15614571 :         output[ch_idx] = st_ivas->hTcBuffer->tc[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered;
    1279             :     }
    1280             : 
    1281     7974121 :     hTcBuffer->subframes_rendered = last_sf;
    1282             : 
    1283     7974121 :     return;
    1284             : }
    1285             : 
    1286             : 
    1287             : /*--------------------------------------------------------------------------*
    1288             :  * ivas_dec_td_renderers_adapt_subframes()
    1289             :  *
    1290             :  * Adapt subframes for TD renderers
    1291             :  *--------------------------------------------------------------------------*/
    1292             : 
    1293     6977849 : void ivas_dec_td_renderers_adapt_subframes(
    1294             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
    1295             : )
    1296             : {
    1297             :     int16_t nMaxSlotsPerSubframe, nSlotsAvailable;
    1298             :     uint16_t nSlotsInLastSubframe, nSlotsInFirstSubframe;
    1299             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    1300             : 
    1301     6977849 :     hTcBuffer = st_ivas->hTcBuffer;
    1302             : 
    1303     6977849 :     nMaxSlotsPerSubframe = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / hTcBuffer->n_samples_granularity;
    1304     6977849 :     nSlotsAvailable = hTcBuffer->n_samples_available / hTcBuffer->n_samples_granularity;
    1305     6977849 :     hTcBuffer->num_slots = nSlotsAvailable;
    1306     6977849 :     hTcBuffer->n_samples_available = nSlotsAvailable * hTcBuffer->n_samples_granularity;
    1307     6977849 :     nSlotsInFirstSubframe = nMaxSlotsPerSubframe - hTcBuffer->subframe_nbslots[hTcBuffer->nb_subframes - 1];
    1308     6977849 :     hTcBuffer->nb_subframes = 0;
    1309             : 
    1310     6977849 :     if ( nSlotsInFirstSubframe > 0 )
    1311             :     {
    1312      182269 :         hTcBuffer->nb_subframes = 1;
    1313      182269 :         nSlotsAvailable -= nSlotsInFirstSubframe;
    1314             :     }
    1315     6977849 :     hTcBuffer->nb_subframes += (int16_t) ceilf( (float) nSlotsAvailable / (float) nMaxSlotsPerSubframe );
    1316     6977849 :     nSlotsInLastSubframe = nSlotsAvailable % nMaxSlotsPerSubframe;
    1317     6977849 :     set_s( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
    1318     6977849 :     set_s( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, hTcBuffer->nb_subframes );
    1319             : 
    1320     6977849 :     if ( nSlotsInFirstSubframe > 0 )
    1321             :     {
    1322      182269 :         hTcBuffer->subframe_nbslots[0] = nSlotsInFirstSubframe;
    1323             :     }
    1324             : 
    1325     6977849 :     if ( nSlotsInLastSubframe > 0 )
    1326             :     {
    1327      182298 :         hTcBuffer->subframe_nbslots[hTcBuffer->nb_subframes - 1] = nSlotsInLastSubframe;
    1328             :     }
    1329             : 
    1330     6977849 :     hTcBuffer->slots_rendered = 0;
    1331     6977849 :     hTcBuffer->subframes_rendered = 0;
    1332             : 
    1333     6977849 :     return;
    1334             : }
    1335             : 
    1336             : 
    1337             : /*--------------------------------------------------------------------------*
    1338             :  * ivas_jbm_dec_masa_metadata_open()
    1339             :  *
    1340             :  * Open structure for MASA metadata buffering in JBM processing
    1341             :  *--------------------------------------------------------------------------*/
    1342             : 
    1343           9 : ivas_error ivas_jbm_dec_masa_metadata_open(
    1344             :     Decoder_Struct *st_ivas )
    1345             : {
    1346             :     JBM_METADATA_HANDLE hJbmMetadata;
    1347             : 
    1348           9 :     if ( ( hJbmMetadata = (JBM_METADATA_HANDLE) malloc( sizeof( JBM_METADATA ) ) ) == NULL )
    1349             :     {
    1350           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM metadata handle\n" ) );
    1351             :     }
    1352             : 
    1353           9 :     hJbmMetadata->sf_write_idx = 0;
    1354           9 :     hJbmMetadata->sf_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_PARAM_SPATIAL_SUBFRAMES;
    1355             : 
    1356           9 :     hJbmMetadata->slot_write_idx = 0;
    1357           9 :     hJbmMetadata->slot_read_idx = 0;
    1358           9 :     hJbmMetadata->slot_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
    1359             : 
    1360           9 :     st_ivas->hJbmMetadata = hJbmMetadata;
    1361             : 
    1362           9 :     return IVAS_ERR_OK;
    1363             : }
    1364             : 
    1365             : 
    1366             : /*--------------------------------------------------------------------------*
    1367             :  * ivas_jbm_dec_copy_masa_meta_to_buffer()
    1368             :  *
    1369             :  * Copy decoded MASA metadata to a ring buffer in JBM processing
    1370             :  *--------------------------------------------------------------------------*/
    1371             : 
    1372       61353 : static void ivas_jbm_dec_copy_masa_meta_to_buffer(
    1373             :     Decoder_Struct *st_ivas )
    1374             : {
    1375             :     int16_t sf, dir, band;
    1376             :     JBM_METADATA_HANDLE hJbmMetadata;
    1377             :     MASA_DECODER_EXT_OUT_META *extOutMeta;
    1378             :     int16_t write_idx;
    1379             : 
    1380       61353 :     hJbmMetadata = st_ivas->hJbmMetadata;
    1381       61353 :     extOutMeta = st_ivas->hMasa->data.extOutMeta;
    1382             : 
    1383      306765 :     for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
    1384             :     {
    1385      245412 :         write_idx = ( hJbmMetadata->sf_write_idx + sf ) % hJbmMetadata->sf_md_buffer_length;
    1386             : 
    1387      736236 :         for ( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
    1388             :         {
    1389    12270600 :             for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    1390             :             {
    1391    11779776 :                 hJbmMetadata->directionIndexBuffer[dir][write_idx][band] = extOutMeta->directionIndex[dir][sf][band];
    1392    11779776 :                 hJbmMetadata->directToTotalRatioBuffer[dir][write_idx][band] = extOutMeta->directToTotalRatio[dir][sf][band];
    1393    11779776 :                 hJbmMetadata->spreadCoherenceBuffer[dir][write_idx][band] = extOutMeta->spreadCoherence[dir][sf][band];
    1394             :             }
    1395             :         }
    1396             : 
    1397     6135300 :         for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    1398             :         {
    1399     5889888 :             hJbmMetadata->diffuseToTotalRatioBuffer[write_idx][band] = extOutMeta->diffuseToTotalRatio[sf][band];
    1400     5889888 :             hJbmMetadata->surroundCoherenceBuffer[write_idx][band] = extOutMeta->surroundCoherence[sf][band];
    1401             :         }
    1402             : 
    1403      245412 :         hJbmMetadata->numberOfDirections[write_idx] = extOutMeta->descriptiveMeta.numberOfDirections;
    1404             :     }
    1405             : 
    1406       61353 :     return;
    1407             : }
    1408             : 
    1409             : 
    1410             : /*--------------------------------------------------------------------------*
    1411             :  * ivas_jbm_masa_sf_to_slot_map()
    1412             :  *
    1413             :  * Map input MASA metadata subframes to slots in JBM processing
    1414             :  *--------------------------------------------------------------------------*/
    1415             : 
    1416       61353 : static void ivas_jbm_masa_sf_to_slot_map(
    1417             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure     */
    1418             :     const int16_t nCldfbTs   /* i  : number of CLDFB time slots */
    1419             : )
    1420             : {
    1421             :     int16_t sf_to_slot_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME];
    1422             :     int16_t num_slots_in_subfr;
    1423             :     JBM_METADATA_HANDLE hJbmMetadata;
    1424             :     int16_t slot_idx;
    1425             :     int16_t write_idx, sf_index;
    1426             : 
    1427       61353 :     ivas_jbm_dec_copy_masa_meta_to_buffer( st_ivas );
    1428             : 
    1429             :     /* Set values */
    1430       61353 :     hJbmMetadata = st_ivas->hJbmMetadata;
    1431       61353 :     num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
    1432             : 
    1433             :     /* Map input subframes to slots */
    1434       61353 :     ivas_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, MAX_PARAM_SPATIAL_SUBFRAMES, sf_to_slot_map );
    1435             : 
    1436     1042668 :     for ( slot_idx = 0; slot_idx < nCldfbTs; slot_idx++ )
    1437             :     {
    1438      981315 :         write_idx = ( hJbmMetadata->slot_write_idx + slot_idx ) % hJbmMetadata->slot_md_buffer_length;
    1439      981315 :         sf_index = ( hJbmMetadata->sf_write_idx + sf_to_slot_map[slot_idx] ) % hJbmMetadata->sf_md_buffer_length;
    1440             : 
    1441      981315 :         hJbmMetadata->sf_to_slot_map[write_idx] = sf_index;
    1442             :     }
    1443             : 
    1444       61353 :     hJbmMetadata->sf_write_idx = ( hJbmMetadata->sf_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hJbmMetadata->sf_md_buffer_length;
    1445       61353 :     hJbmMetadata->slot_write_idx = ( hJbmMetadata->slot_write_idx + nCldfbTs ) % hJbmMetadata->slot_md_buffer_length;
    1446             : 
    1447       61353 :     return;
    1448             : }
    1449             : 
    1450             : 
    1451             : /*--------------------------------------------------------------------------*
    1452             :  * ivas_jbm_masa_sf_to_sf_map()
    1453             :  *
    1454             :  * Map input MASA metadata subframes to output subframes in JBM processing
    1455             :  *--------------------------------------------------------------------------*/
    1456             : 
    1457       61332 : void ivas_jbm_masa_sf_to_sf_map(
    1458             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
    1459             : )
    1460             : {
    1461             :     int16_t sf_to_sf_map[MAX_PARAM_SPATIAL_SUBFRAMES];
    1462             :     JBM_METADATA_HANDLE hJbmMetadata;
    1463             :     MASA_DECODER_EXT_OUT_META *extOutMeta;
    1464             :     int16_t slot_read_idx, sf_read_idx;
    1465             :     int16_t sf_idx;
    1466             :     int16_t dir, band;
    1467             :     uint8_t numberOfDirections;
    1468             : 
    1469             :     /* Set values */
    1470       61332 :     hJbmMetadata = st_ivas->hJbmMetadata;
    1471       61332 :     extOutMeta = st_ivas->hMasa->data.extOutMeta;
    1472             : 
    1473             :     /* Map slots to subframes */
    1474      306660 :     for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1475             :     {
    1476      245328 :         slot_read_idx = ( hJbmMetadata->slot_read_idx + 2 ) % hJbmMetadata->slot_md_buffer_length; /* Take the latter one of the middle slots of the output subframe */
    1477      245328 :         sf_to_sf_map[sf_idx] = hJbmMetadata->sf_to_slot_map[slot_read_idx];
    1478      245328 :         hJbmMetadata->slot_read_idx = ( hJbmMetadata->slot_read_idx + CLDFB_SLOTS_PER_SUBFRAME ) % hJbmMetadata->slot_md_buffer_length;
    1479             :     }
    1480             : 
    1481             :     /* Copy mapped metadata to the EXT meta buffer for writing */
    1482      306660 :     for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1483             :     {
    1484      245328 :         sf_read_idx = sf_to_sf_map[sf_idx];
    1485             : 
    1486      735984 :         for ( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
    1487             :         {
    1488    12266400 :             for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    1489             :             {
    1490    11775744 :                 extOutMeta->directionIndex[dir][sf_idx][band] = hJbmMetadata->directionIndexBuffer[dir][sf_read_idx][band];
    1491    11775744 :                 extOutMeta->directToTotalRatio[dir][sf_idx][band] = hJbmMetadata->directToTotalRatioBuffer[dir][sf_read_idx][band];
    1492    11775744 :                 extOutMeta->spreadCoherence[dir][sf_idx][band] = hJbmMetadata->spreadCoherenceBuffer[dir][sf_read_idx][band];
    1493             :             }
    1494             :         }
    1495             : 
    1496     6133200 :         for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    1497             :         {
    1498     5887872 :             extOutMeta->diffuseToTotalRatio[sf_idx][band] = hJbmMetadata->diffuseToTotalRatioBuffer[sf_read_idx][band];
    1499     5887872 :             extOutMeta->surroundCoherence[sf_idx][band] = hJbmMetadata->surroundCoherenceBuffer[sf_read_idx][band];
    1500             :         }
    1501             :     }
    1502             : 
    1503             :     /* Determine the number of directions for the frame to be written */
    1504       61332 :     numberOfDirections = 0;
    1505      253284 :     for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1506             :     {
    1507      205476 :         sf_read_idx = sf_to_sf_map[sf_idx];
    1508             : 
    1509      205476 :         if ( hJbmMetadata->numberOfDirections[sf_read_idx] == 1 )
    1510             :         {
    1511       13524 :             numberOfDirections = 1;
    1512       13524 :             break;
    1513             :         }
    1514             :     }
    1515             : 
    1516       61332 :     extOutMeta->descriptiveMeta.numberOfDirections = numberOfDirections;
    1517             : 
    1518       61332 :     return;
    1519             : }
    1520             : 
    1521             : 
    1522             : /*--------------------------------------------------------------------------*
    1523             :  * ivas_dec_prepare_renderer()
    1524             :  *
    1525             :  * Prepare IVAS renderer routine
    1526             :  *--------------------------------------------------------------------------*/
    1527             : 
    1528    15136445 : void ivas_dec_prepare_renderer(
    1529             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
    1530             : )
    1531             : {
    1532             :     int16_t n, n_render_timeslots, n_samples_available;
    1533             :     AUDIO_CONFIG output_config;
    1534             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    1535             : 
    1536    15136445 :     push_wmops( "ivas_dec_prepare_renderer" );
    1537             : 
    1538    15136445 :     output_config = st_ivas->hDecoderConfig->output_config;
    1539    15136445 :     hTcBuffer = st_ivas->hTcBuffer;
    1540    15136445 :     n_samples_available = hTcBuffer->n_samples_available;
    1541    15136445 :     n_render_timeslots = n_samples_available / hTcBuffer->n_samples_granularity;
    1542             : 
    1543    15136445 :     if ( hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_BUFFER )
    1544             :     {
    1545     3922244 :         ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1546             : 
    1547     3922244 :         if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && output_config == IVAS_AUDIO_CONFIG_EXTERNAL && st_ivas->hDecoderConfig->Opt_tsm )
    1548             :         {
    1549       61353 :             ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
    1550             :         }
    1551             : 
    1552             :         /* MASA transport gaining for edited disc OMASA EXT. For ISMs, only metadata is modified */
    1553     3922244 :         if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL && st_ivas->hMasaIsmData->masa_gain_is_edited == 1 )
    1554             :         {
    1555           0 :             ivas_omasa_gain_masa_tc( st_ivas->hTcBuffer->tc, st_ivas->hMasaIsmData->gain_masa_edited, st_ivas->nchan_ism, st_ivas->hTcBuffer->n_samples_available );
    1556             :         }
    1557             :     }
    1558    11214201 :     else if ( st_ivas->ivas_format == MONO_FORMAT || st_ivas->ivas_format == STEREO_FORMAT )
    1559             :     {
    1560       62007 :         ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1561             :     }
    1562    11152194 :     else if ( st_ivas->ivas_format == ISM_FORMAT )
    1563             :     {
    1564     1382238 :         if ( st_ivas->ism_mode == ISM_MODE_PARAM )
    1565             :         {
    1566      316707 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
    1567             :             {
    1568      198957 :                 ivas_dirac_dec_set_md_map( st_ivas, n_render_timeslots );
    1569      198957 :                 ivas_param_ism_params_to_masa_param_mapping( st_ivas );
    1570             :             }
    1571      117750 :             else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
    1572             :             {
    1573      117750 :                 ivas_param_ism_dec_prepare_renderer( st_ivas, n_render_timeslots );
    1574             :             }
    1575             :         }
    1576             :         else /* ISM_MODE_DISC */
    1577             :         {
    1578     1065531 :             ivas_ism_dec_digest_tc( st_ivas );
    1579             :         }
    1580             :     }
    1581     9769956 :     else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
    1582             :     {
    1583     6867066 :         ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1584             :     }
    1585     2902890 :     else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    1586             :     {
    1587      795102 :         if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
    1588             :         {
    1589      512298 :             ivas_ism_dec_digest_tc( st_ivas );
    1590             : 
    1591             :             /* delay the objects here for all renderers where it is needed */
    1592      512298 :             if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ||
    1593      285012 :                    st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ||
    1594      188661 :                    st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
    1595      141633 :                    st_ivas->renderer_type == RENDERER_OSBA_LS ||
    1596      476847 :                    output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) &&
    1597      476847 :                  ( output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    1598             :             {
    1599     1969413 :                 for ( n = 0; n < st_ivas->nchan_ism; n++ )
    1600             :                 {
    1601     1492566 :                     delay_signal( hTcBuffer->tc[n], n_samples_available, st_ivas->hSbaIsmData->delayBuffer[n], st_ivas->hSbaIsmData->delayBuffer_size );
    1602             :                 }
    1603             :             }
    1604             : 
    1605      512298 :             if ( !st_ivas->sba_dirac_stereo_flag )
    1606             :             {
    1607      476847 :                 if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
    1608             :                 {
    1609      227286 :                     n_render_timeslots *= ( hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size );
    1610             :                 }
    1611             : 
    1612      476847 :                 ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1613             :             }
    1614             :         }
    1615             :         else
    1616             :         {
    1617      282804 :             ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1618             : 
    1619      282804 :             ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1620             :         }
    1621             :     }
    1622     2107788 :     else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
    1623             :     {
    1624      483219 :         if ( st_ivas->renderer_type == RENDERER_OMASA_MIX_EXT || st_ivas->renderer_type == RENDERER_OMASA_OBJECT_EXT )
    1625             :         {
    1626        9000 :             ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1627             : 
    1628        9000 :             if ( st_ivas->hDecoderConfig->Opt_tsm )
    1629             :             {
    1630           0 :                 ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
    1631             :             }
    1632             : 
    1633             :             /* MASA transport gaining for edited param_one OMASA EXT. For ISMs, only metadata is modified.  */
    1634        9000 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->hMasaIsmData->masa_gain_is_edited == 1 )
    1635             :             {
    1636           0 :                 for ( n = 0; n < CPE_CHANNELS; n++ )
    1637             :                 {
    1638           0 :                     v_multc( st_ivas->hTcBuffer->tc[n], st_ivas->hMasaIsmData->gain_masa_edited, st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->n_samples_available );
    1639             :                 }
    1640             :             }
    1641             :         }
    1642             :         else
    1643             :         {
    1644      474219 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC )
    1645             :             {
    1646       37551 :                 n_render_timeslots *= ( hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size );
    1647             :             }
    1648             : 
    1649      474219 :             ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1650             : 
    1651      474219 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
    1652             :             {
    1653      174120 :                 ivas_ism_dec_digest_tc( st_ivas );
    1654             :             }
    1655             : 
    1656      474219 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_DIRAC )
    1657             :             {
    1658             :                 int16_t nchan_transport_ism;
    1659             : 
    1660             :                 /* Delay the signal to match CLDFB delay. Delay the whole buffer. */
    1661      298638 :                 nchan_transport_ism = 0;
    1662      298638 :                 if ( ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC )
    1663             :                 {
    1664      114054 :                     nchan_transport_ism = 1;
    1665             :                 }
    1666      184584 :                 else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
    1667             :                 {
    1668      115572 :                     nchan_transport_ism = st_ivas->nchan_ism;
    1669             :                 }
    1670             : 
    1671      298638 :                 if ( st_ivas->hDecoderConfig->Opt_tsm && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_DIRAC )
    1672             :                 {
    1673             :                     /* Gain MASA part, if edited */
    1674       33024 :                     if ( st_ivas->hMasaIsmData->masa_gain_is_edited )
    1675             :                     {
    1676       51174 :                         for ( n = 0; n < CPE_CHANNELS; n++ )
    1677             :                         {
    1678       34116 :                             v_multc( st_ivas->hTcBuffer->tc[n], st_ivas->hMasaIsmData->gain_masa_edited, st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->n_samples_available );
    1679             :                         }
    1680             :                     }
    1681             :                 }
    1682             : 
    1683      733905 :                 for ( n = 0; n < nchan_transport_ism; n++ )
    1684             :                 {
    1685      435267 :                     if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
    1686             :                     {
    1687             :                         float gainIsm;
    1688      138204 :                         gainIsm = OMASA_TDREND_MATCHING_GAIN;
    1689             : 
    1690      138204 :                         if ( st_ivas->hMasaIsmData->ism_gain_is_edited[n] )
    1691             :                         {
    1692       79692 :                             gainIsm *= st_ivas->hMasaIsmData->gain_ism_edited[n];
    1693             :                         }
    1694             : 
    1695      138204 :                         v_multc( hTcBuffer->tc[CPE_CHANNELS + n], gainIsm, hTcBuffer->tc[CPE_CHANNELS + n], n_samples_available );
    1696             :                     }
    1697             : 
    1698      435267 :                     if ( output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
    1699             :                     {
    1700      435267 :                         delay_signal( hTcBuffer->tc[CPE_CHANNELS + n], n_samples_available, st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size );
    1701             :                     }
    1702             :                 }
    1703             : 
    1704      298638 :                 if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
    1705             :                 {
    1706             :                     int16_t tcBufferSize;
    1707       37551 :                     tcBufferSize = st_ivas->hSpatParamRendCom->num_slots * st_ivas->hSpatParamRendCom->slot_size;
    1708             : 
    1709       37551 :                     if ( st_ivas->hMasaIsmData->masa_gain_is_edited )
    1710             :                     {
    1711       68103 :                         for ( n = 0; n < BINAURAL_CHANNELS; n++ )
    1712             :                         {
    1713       45402 :                             v_multc( hTcBuffer->tc[n], st_ivas->hMasaIsmData->gain_masa_edited, hTcBuffer->tc[n], tcBufferSize );
    1714             :                         }
    1715             :                     }
    1716             :                 }
    1717             :             }
    1718             :         }
    1719             :     }
    1720     1624569 :     else if ( st_ivas->ivas_format == MC_FORMAT )
    1721             :     {
    1722     1624569 :         if ( st_ivas->mc_mode == MC_MODE_MCT )
    1723             :         {
    1724      842151 :             ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1725             :         }
    1726      782418 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
    1727             :         {
    1728      107694 :             ivas_mc_paramupmix_dec_digest_tc( st_ivas, (uint8_t) n_render_timeslots, n_samples_available );
    1729             :         }
    1730      674724 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
    1731             :         {
    1732      335436 :             ivas_param_mc_dec_prepare_renderer( st_ivas, (uint8_t) n_render_timeslots );
    1733             :         }
    1734      339288 :         else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
    1735             :         {
    1736      339288 :             ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1737             :         }
    1738             :     }
    1739             : 
    1740    15136445 :     pop_wmops();
    1741    15136445 :     return;
    1742             : }

Generated by: LCOV version 1.14