LCOV - code coverage report
Current view: top level - lib_dec - ivas_dec_render.c (source / functions) Hit Total Coverage
Test: Coverage on main -- merged total coverage @ efe53129c9ed87a5067dd0a8fb9dca41db9c4add Lines: 592 633 93.5 %
Date: 2026-02-12 08:06:51 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    21882874 : 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    21882874 :     hTcBuffer = st_ivas->hTcBuffer;
      80    21882874 :     n_ch_cldfb = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;
      81             : 
      82    21882874 :     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     3126749 :         n_samples_still_available = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_rendered;
      88     3126749 :         hTcBuffer->n_samples_buffered = n_samples_still_available + nSamplesForRendering + hTcBuffer->n_samples_discard;
      89     3126749 :         hTcBuffer->n_samples_available = hTcBuffer->n_samples_granularity * ( hTcBuffer->n_samples_buffered / hTcBuffer->n_samples_granularity );
      90     3126749 :         *nSamplesResidual = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_available;
      91     3126749 :         n_ch_full_copy = min( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full );
      92     3126749 :         n_ch_res_copy = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;
      93             : 
      94    12495021 :         for ( ch = 0; ch < n_ch_full_copy; ch++ )
      95             :         {
      96     9368272 :             mvr2r( hTcBuffer->tc[ch], tmp_buf, nSamplesForRendering );
      97     9368272 :             set_zero( hTcBuffer->tc[ch], hTcBuffer->n_samples_discard );
      98     9368272 :             mvr2r( hTcBuffer->tc_buffer_old[ch], hTcBuffer->tc[ch] + hTcBuffer->n_samples_discard, n_samples_still_available );
      99     9368272 :             mvr2r( tmp_buf, hTcBuffer->tc[ch] + n_samples_still_available + hTcBuffer->n_samples_discard, nSamplesForRendering - *nSamplesResidual );
     100     9368272 :             mvr2r( tmp_buf + nSamplesForRendering - *nSamplesResidual, hTcBuffer->tc_buffer_old[ch], *nSamplesResidual );
     101             :         }
     102             : 
     103     3126749 :         if ( n_ch_res_copy > 0 )
     104             :         {
     105      413726 :             for ( ; ch < hTcBuffer->nchan_transport_rend; ch++ )
     106             :             {
     107      282444 :                 p_data_f[ch] = hTcBuffer->tc[ch];
     108      282444 :                 mvr2r( hTcBuffer->tc[ch], tmp_buf, nSamplesForRendering );
     109      282444 :                 mvr2r( hTcBuffer->tc_buffer_old[ch], p_data_f[ch], n_samples_still_available );
     110      282444 :                 mvr2r( tmp_buf, p_data_f[ch] + n_samples_still_available, nSamplesForRendering - *nSamplesResidual );
     111      282444 :                 mvr2r( tmp_buf + nSamplesForRendering - *nSamplesResidual, hTcBuffer->tc_buffer_old[ch], *nSamplesResidual );
     112             :             }
     113             :         }
     114             : 
     115     3126749 :         n_render_timeslots = hTcBuffer->n_samples_available / hTcBuffer->n_samples_granularity;
     116             :     }
     117             :     else
     118             :     {
     119    19817351 :         for ( n = 0; n < n_ch_cldfb; n++ )
     120             :         {
     121     1061226 :             p_data_f[n] = &st_ivas->p_output_f[n][0];
     122             :         }
     123             : 
     124    18756125 :         ch = max( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full );
     125    88539951 :         for ( n = 0; n < ch; n++ )
     126             :         {
     127    69783826 :             hTcBuffer->tc[n] = st_ivas->p_output_f[n]; /* note: buffers needed in the TD decorellator */
     128             :         }
     129             : 
     130    18756125 :         hTcBuffer->n_samples_buffered = nSamplesForRendering;
     131    18756125 :         hTcBuffer->n_samples_available = hTcBuffer->n_samples_buffered;
     132    18756125 :         *nSamplesResidual = 0;
     133             : 
     134    18756125 :         n_render_timeslots = DEFAULT_JBM_CLDFB_TIMESLOTS;
     135             :     }
     136             : 
     137             :     /* CLDFB analysis for ParamMC/ParamISM */
     138    21882874 :     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      193826 :         ivas_param_ism_dec_digest_tc( st_ivas, n_render_timeslots, p_data_f );
     141             :     }
     142    21689048 :     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      448549 :         ivas_param_mc_dec_digest_tc( st_ivas, (uint8_t) n_render_timeslots, p_data_f );
     145             :     }
     146             : 
     147    21882874 :     hTcBuffer->n_samples_rendered = 0;
     148    21882874 :     hTcBuffer->subframes_rendered = 0;
     149             : 
     150    21882874 :     return;
     151             : }
     152             : 
     153             : 
     154             : /*--------------------------------------------------------------------------*
     155             :  * ivas_dec_render()
     156             :  *
     157             :  * Principal IVAS internal rendering routine
     158             :  *--------------------------------------------------------------------------*/
     159             : 
     160    42953626 : 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    42953626 :     push_wmops( "ivas_dec_render" );
     181             :     /*----------------------------------------------------------------*
     182             :      * Initialization of local vars after struct has been set
     183             :      *----------------------------------------------------------------*/
     184             : 
     185    42953626 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     186    42953626 :     nchan_out = st_ivas->hDecoderConfig->nchan_out;
     187    42953626 :     nchan_transport_rend = st_ivas->hTcBuffer->nchan_transport_rend;
     188    42953626 :     output_config = st_ivas->hDecoderConfig->output_config;
     189    42953626 :     nSamplesAskedLocal = nSamplesAsked + st_ivas->hTcBuffer->n_samples_discard;
     190             : 
     191   902026146 :     for ( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
     192             :     {
     193   859072520 :         p_output[n] = st_ivas->p_output_f[n];
     194             :     }
     195             : 
     196    42953626 :     if ( !st_ivas->hDecoderConfig->Opt_tsm )
     197             :     {
     198   646132345 :         for ( n = 0; n < MAX_INTERN_CHANNELS; n++ )
     199             :         {
     200   608124560 :             st_ivas->hTcBuffer->tc[n] = p_output[n];
     201             :         }
     202             :     }
     203             : 
     204   200439177 :     for ( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ )
     205             :     {
     206   157485551 :         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    42953626 :     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     5904841 :         st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start -= st_ivas->hTcBuffer->n_samples_discard;
     217             : 
     218     5904841 :         ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     219             :     }
     220             : 
     221             :     /*----------------------------------------------------------------*
     222             :      * Rendering
     223             :      *----------------------------------------------------------------*/
     224             : 
     225    42953626 :     *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
     226             : 
     227    42953626 :     if ( st_ivas->ivas_format == UNDEFINED_FORMAT )
     228             :     {
     229           0 :         assert( 0 );
     230             :     }
     231    42953626 :     else if ( st_ivas->hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_BUFFER )
     232             :     {
     233     9611795 :         ivas_dec_tc_buffer_playout( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output );
     234             :     }
     235    33341831 :     else if ( st_ivas->ivas_format == MONO_FORMAT || st_ivas->ivas_format == STEREO_FORMAT )
     236             :     {
     237             :         /* Rendering */
     238      269080 :         if ( st_ivas->renderer_type == RENDERER_MC )
     239             :         {
     240       62775 :             ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc, p_output );
     241             :         }
     242      206305 :         else if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX )
     243             :         {
     244       91044 :             ivas_apply_non_diegetic_panning( p_tc[0], p_output, st_ivas->hDecoderConfig->non_diegetic_pan_gain, *nSamplesRendered );
     245             :         }
     246      115261 :         else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     247             :         {
     248      115261 :             ivas_stereo2sba( p_tc, p_output, *nSamplesRendered );
     249             :         }
     250             :     }
     251    33072751 :     else if ( st_ivas->ivas_format == ISM_FORMAT )
     252             :     {
     253             :         /* Rendering */
     254     4717912 :         if ( st_ivas->ism_mode == ISM_MODE_PARAM )
     255             :         {
     256     1030282 :             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      606695 :                 ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output );
     259             :             }
     260      423587 :             else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     261             :             {
     262      423587 :                 ivas_param_ism_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output );
     263             : 
     264      423587 :                 if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     265             :                 {
     266             :                     /* Convert CICP19 -> Ambisonics */
     267      309705 :                     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     3687630 :             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     1372464 :                 ivas_ism_render_sf( st_ivas, st_ivas->renderer_type, p_output, *nSamplesRendered );
     278             :             }
     279     2315166 :             else if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX )
     280             :             {
     281       65865 :                 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     2249301 :             else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     287             : #endif
     288             :             {
     289             :                 /* Convert to Ambisonics */
     290      508560 :                 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     3687630 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
     295             :             {
     296     1740741 :                 if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     297             :                 {
     298       27156 :                     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     1713585 :                     if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK )
     306             :                     {
     307           0 :                         return error;
     308             :                     }
     309             :                 }
     310             :             }
     311     1946889 :             else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM )
     312             :             {
     313      604552 :                 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      604552 :                                                                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    28354839 :     else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
     322             :     {
     323    18484525 :         nchan_remapped = nchan_transport_rend;
     324             : 
     325             :         /* Loudspeakers, Ambisonics or Binaural rendering */
     326    18484525 :         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     4938978 :             ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     329             :         }
     330    13545547 :         else if ( st_ivas->ivas_format == MASA_FORMAT )
     331             :         {
     332     1814334 :             if ( st_ivas->renderer_type == RENDERER_DIRAC )
     333             :             {
     334     1814334 :                 ivas_dirac_dec_render( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output );
     335             :             }
     336             :         }
     337             :         else
     338             :         {
     339    11731213 :             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     9870314 :     else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
     346             :     {
     347     1833628 :         nchan_remapped = st_ivas->nchan_transport;
     348             : 
     349     1833628 :         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     1049432 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
     352             :             {
     353      205348 :                 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      844084 :                 ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     361             :             }
     362             :         }
     363      784196 :         else if ( st_ivas->renderer_type == RENDERER_DIRAC )
     364             :         {
     365      766948 :             ivas_omasa_dirac_rend( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     366             :         }
     367       17248 :         else if ( st_ivas->renderer_type == RENDERER_OMASA_OBJECT_EXT || st_ivas->renderer_type == RENDERER_OMASA_MIX_EXT )
     368             :         {
     369       17248 :             ivas_dec_tc_buffer_playout( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output );
     370       17248 :             ivas_omasa_rearrange_channels( p_output, st_ivas->nchan_ism, *nSamplesRendered );
     371             :         }
     372             :     }
     373     8036686 :     else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
     374             :     {
     375     3538003 :         nchan_remapped = nchan_transport_rend;
     376             : 
     377             :         /* Loudspeakers, Ambisonics or Binaural rendering */
     378     3538003 :         if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
     379             :         {
     380     1995991 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
     381             :             {
     382      826024 :                 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     1169967 :             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      135733 :                 if ( st_ivas->nchan_ism == 1 && st_ivas->hDecoderConfig->Opt_tsm == 0 )
     391             :                 {
     392        5940 :                     mvr2r( p_tc[2], p_output[3], *nSamplesRendered );
     393        5940 :                     mvr2r( p_tc[1], p_output[2], *nSamplesRendered );
     394        5940 :                     p_tc[1] = p_output[2];
     395        5940 :                     p_tc[2] = p_output[3];
     396             :                 }
     397             : 
     398             :                 /* render objects */
     399      135733 :                 ivas_ism_render_sf( st_ivas, st_ivas->renderer_type, p_output, *nSamplesRendered );
     400             : 
     401             :                 /* add already rendered SBA part */
     402      135733 :                 ivas_osba_stereo_add_channels( p_tc, p_output, st_ivas->hSbaIsmData->gain_bed, nchan_out, st_ivas->nchan_ism, *nSamplesRendered );
     403             :             }
     404     1034234 :             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      922290 :                 if ( ( error = ivas_osba_render_sf( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK )
     407             :                 {
     408           0 :                     return error;
     409             :                 }
     410             :             }
     411      111944 :             else if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) /*EXT output = individual objects + HOA3*/
     412             :             {
     413      111944 :                 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      411071 :                 for ( n = 0; n < st_ivas->nchan_ism; n++ )
     419             :                 {
     420      299127 :                     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     1542012 :         else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
     432             :         {
     433      757620 :             ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     434     2272860 :             for ( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     435             :             {
     436     1515240 :                 v_multc( p_output[n], 2.0f, p_output[n], *nSamplesRendered );
     437             :             }
     438             :         }
     439             :         else
     440             :         {
     441      784392 :             if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK )
     442             :             {
     443           0 :                 return error;
     444             :             }
     445             : 
     446      784392 :             if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     447             :             {
     448             : #ifdef DEBUGGING
     449             :                 assert( st_ivas->ism_mode == ISM_MODE_NONE );
     450             : #endif
     451      881082 :                 for ( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- )
     452             :                 {
     453      807654 :                     mvr2r( p_output[n], p_output[n + st_ivas->nchan_ism], *nSamplesRendered );
     454             :                 }
     455      282846 :                 for ( n = 0; n < st_ivas->nchan_ism; n++ )
     456             :                 {
     457      209418 :                     set_zero( p_output[n], *nSamplesRendered );
     458             :                 }
     459             :             }
     460     7781306 :             for ( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     461             :             {
     462     6996914 :                 v_multc( p_output[n], 2.0f, p_output[n], *nSamplesRendered );
     463             :             }
     464             :         }
     465             :     }
     466     4498683 :     else if ( st_ivas->ivas_format == MC_FORMAT )
     467             :     {
     468     4498683 :         if ( st_ivas->mc_mode == MC_MODE_MCT )
     469             :         {
     470     2370150 :             int16_t crendInPlaceRotation = FALSE;
     471             : 
     472     2370150 :             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       89836 :                 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       89836 :                     crendInPlaceRotation = TRUE;
     477       89836 :                     ivas_mc2sba( st_ivas->hTransSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE );
     478             :                 }
     479             :             }
     480             : 
     481             :             /* Rendering */
     482     2370150 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM )
     483             :             {
     484     1616672 :                 if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     485             :                 {
     486       27070 :                     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       27070 :                                                                             &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     3206274 :                     if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
     495     3206274 :                                                                    &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     1603137 :                     ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output );
     501             :                 }
     502             :             }
     503      753478 :             else if ( st_ivas->renderer_type == RENDERER_MC )
     504             :             {
     505      271644 :                 ivas_ls_setup_conversion( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc, p_output );
     506             :             }
     507      481834 :             else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     508             :             {
     509       57276 :                 ivas_mc2sba( st_ivas->hIntSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
     510             :             }
     511      424558 :             else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
     512             :             {
     513      424558 :                 if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     514             :                 {
     515      115589 :                     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      308969 :                     if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK )
     523             :                     {
     524           0 :                         return error;
     525             :                     }
     526             : 
     527      308969 :                     ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output );
     528             :                 }
     529             :             }
     530             :         }
     531     2128533 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
     532             :         {
     533      277385 :             ivas_mc_paramupmix_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc, p_output );
     534             : 
     535             :             /* Rendering */
     536      277385 :             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       65537 :                 if ( output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     540             :                 {
     541       65537 :                     ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_output, p_output );
     542             :                 }
     543             :             }
     544      211848 :             else if ( st_ivas->renderer_type == RENDERER_MC )
     545             :             {
     546        1188 :                 ivas_ls_setup_conversion( st_ivas, MC_PARAMUPMIX_MAX_INPUT_CHANS, *nSamplesRendered, p_output, p_output );
     547             :             }
     548      210660 :             else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     549             :             {
     550        6676 :                 ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
     551             :             }
     552             :         }
     553     1851148 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
     554             :         {
     555      915179 :             ivas_param_mc_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output );
     556             :         }
     557      935969 :         else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
     558             :         {
     559      935969 :             nchan_remapped = st_ivas->nchan_transport;
     560             : 
     561      935969 :             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      648519 :                 ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output );
     564             :             }
     565      287450 :             else if ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) /* rendering to CICPxx and Ambisonics */
     566             :             {
     567      287450 :                 ivas_dirac_dec_render( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output );
     568             : 
     569      287450 :                 if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
     570             :                 {
     571             :                     /* we still need to copy the separate channel if available  */
     572       69398 :                     if ( st_ivas->hOutSetup.separateChannelEnabled )
     573             :                     {
     574       16086 :                         mvr2r( p_tc[LFE_CHANNEL - 1], p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
     575             :                     }
     576             : 
     577       69398 :                     ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f );
     578             :                 }
     579      218052 :                 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        8040 :                     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        6030 :                         set_zero( p_output[n], *nSamplesRendered );
     584             :                     }
     585             :                 }
     586             :             }
     587             : 
     588             :             /* copy discrete C and TD LFE from internal TC to output  */
     589      935969 :             if ( st_ivas->hOutSetup.separateChannelEnabled )
     590             :             {
     591      130670 :                 if ( output_config == IVAS_AUDIO_CONFIG_5_1 || output_config == IVAS_AUDIO_CONFIG_7_1 ||
     592       67719 :                      output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1_4 ||
     593       64599 :                      output_config == IVAS_AUDIO_CONFIG_5_1_2 || ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) )
     594             :                 {
     595       66071 :                     mvr2r( p_tc[LFE_CHANNEL], p_output[LFE_CHANNEL], *nSamplesRendered );
     596       66071 :                     mvr2r( p_tc[LFE_CHANNEL - 1], p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
     597             :                 }
     598       64599 :                 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    42953626 :     st_ivas->hTcBuffer->n_samples_available -= *nSamplesRendered;
     613    42953626 :     st_ivas->hTcBuffer->n_samples_rendered += *nSamplesRendered;
     614             : 
     615             :     /* update global combined orientation start index */
     616    42953626 :     ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
     617             : 
     618    42953626 :     if ( st_ivas->hTcBuffer->n_samples_discard > 0 )
     619             :     {
     620       47247 :         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       42052 :             p_output[n] += st_ivas->hTcBuffer->n_samples_discard;
     623             :         }
     624        5195 :         *nSamplesRendered -= st_ivas->hTcBuffer->n_samples_discard;
     625        5195 :         st_ivas->hTcBuffer->n_samples_discard = 0;
     626             :     }
     627             : 
     628    42953626 :     if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     629             :     {
     630      610411 :         nchan_out_syn_output = BINAURAL_CHANNELS * st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses;
     631             : #ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR
     632      610411 :         if ( st_ivas->flushing )
     633             :         {
     634         770 :             nchan_out_syn_output = BINAURAL_CHANNELS;
     635             :         }
     636             : #endif
     637             :     }
     638             :     else
     639             :     {
     640    42343215 :         nchan_out_syn_output = nchan_out;
     641             :     }
     642             : 
     643    42953626 :     if ( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 )
     644             :     {
     645    42343215 :         if ( st_ivas->ivas_format != MONO_FORMAT )
     646             :         {
     647             : #ifndef DISABLE_LIMITER
     648    41967393 :             ivas_limiter_dec( st_ivas->hLimiter, p_output, nchan_out, *nSamplesRendered, st_ivas->BER_detect );
     649             : #endif
     650             :         }
     651             :     }
     652             : 
     653    42953626 :     switch ( pcm_resolution )
     654             :     {
     655    42343985 :         case PCM_INT16:
     656             : #ifdef DEBUGGING
     657             :             st_ivas->noClipping +=
     658             : #endif
     659    42343985 :                 ivas_syn_output( p_output, *nSamplesRendered, nchan_out_syn_output, (int16_t *) data );
     660             : 
     661    42343985 :             break;
     662      609641 :         case PCM_FLOAT32:
     663      609641 :             ivas_buffer_deinterleaved_to_interleaved( p_output, (float *) data, nchan_out_syn_output, *nSamplesRendered );
     664      609641 :             break;
     665           0 :         default:
     666           0 :             error = IVAS_ERR_UNKNOWN;
     667           0 :             break;
     668             :     }
     669             : 
     670    42953626 :     *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available;
     671             : 
     672    42953626 :     pop_wmops();
     673    42953626 :     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        8728 : 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        8728 :     if ( !st_ivas->hDecoderConfig->Opt_tsm )
     706             :     {
     707           0 :         return IVAS_ERR_OK;
     708             :     }
     709             : 
     710      183288 :     for ( ch_idx = 0; ch_idx < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
     711             :     {
     712      174560 :         p_output[ch_idx] = st_ivas->p_output_f[ch_idx];
     713             :     }
     714             : 
     715        8728 :     *nSamplesRendered = 0;
     716        8728 :     hTcBuffer = st_ivas->hTcBuffer;
     717        8728 :     n_samples_granularity = hTcBuffer->n_samples_granularity;
     718             : 
     719             :     /* get number of possible slots in new granularity */
     720        8728 :     n_samples_still_available = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_rendered;
     721        8728 :     n_slots_still_available = n_samples_still_available / tc_granularity_new;
     722        8728 :     *nSamplesRendered = n_slots_still_available * tc_granularity_new;
     723        8728 :     n_samples_to_render = *nSamplesRendered;
     724        8728 :     n_samples_still_available -= n_samples_to_render;
     725        8728 :     assert( n_samples_still_available < tc_granularity_new );
     726             : 
     727             :     /* update combined orientation access index */
     728        8728 :     ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     729             : 
     730        8728 :     if ( n_slots_still_available )
     731             :     {
     732             :         /* render available full slots (with new lower granularity) */
     733       34701 :         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       29513 :             mvr2r( hTcBuffer->tc_buffer_old[ch_idx], hTcBuffer->tc[ch_idx], n_samples_to_render );
     737       29513 :             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        5188 :         hTcBuffer->num_slots = 1;
     742        5188 :         hTcBuffer->nb_subframes = 1;
     743        5188 :         hTcBuffer->subframes_rendered = 0;
     744        5188 :         hTcBuffer->slots_rendered = 0;
     745        5188 :         hTcBuffer->subframe_nbslots[0] = 1;
     746        5188 :         hTcBuffer->n_samples_buffered = n_samples_granularity + n_samples_still_available;
     747        5188 :         hTcBuffer->n_samples_available = 0;
     748        5188 :         hTcBuffer->n_samples_flushed = n_samples_to_render;
     749        5188 :         hTcBuffer->n_samples_rendered = 0;
     750             : 
     751             : 
     752        5188 :         if ( st_ivas->ivas_format == ISM_FORMAT )
     753             :         {
     754        2521 :             if ( ism_mode_old == ISM_MODE_DISC )
     755             :             {
     756             :                 /* Binaural rendering */
     757        2521 :                 if ( renderer_type_old == RENDERER_BINAURAL_OBJECTS_TD )
     758             :                 {
     759        1374 :                     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        1147 :                 else if ( renderer_type_old == RENDERER_BINAURAL_MIXER_CONV_ROOM )
     765             :                 {
     766             :                     /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */
     767        1147 :                     set_f( st_ivas->hIsmRendererData->interpolator, 1.0f, n_samples_granularity );
     768             : 
     769        1147 :                     ivas_ism_render_sf( st_ivas, renderer_type_old, p_output, n_samples_granularity );
     770             : 
     771        1147 :                     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        1147 :                                                                    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        2667 :         else if ( st_ivas->ivas_format == MC_FORMAT )
     784             :         {
     785        1151 :             if ( mc_mode_old == MC_MODE_MCT )
     786             :             {
     787        1151 :                 int16_t crendInPlaceRotation = FALSE;
     788             : 
     789        1151 :                 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         526 :                     if ( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) < ( hIntSetupOld->nchan_out_woLFE + hIntSetupOld->num_lfe ) )
     792             :                     {
     793         526 :                         crendInPlaceRotation = TRUE;
     794         526 :                         ivas_mc2sba( st_ivas->hTransSetup, hTcBuffer->tc, p_output, n_samples_granularity, hIntSetupOld->ambisonics_order, GAIN_LFE );
     795             :                     }
     796             :                 }
     797        1151 :                 if ( renderer_type_old == RENDERER_BINAURAL_MIXER_CONV || renderer_type_old == RENDERER_BINAURAL_MIXER_CONV_ROOM )
     798             :                 {
     799         526 :                     if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, intern_config_old, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
     800         526 :                                                                    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         526 :                     ivas_binaural_add_LFE( st_ivas, n_samples_granularity, hTcBuffer->tc, p_output );
     806             :                 }
     807         625 :                 else if ( renderer_type_old == RENDERER_BINAURAL_OBJECTS_TD )
     808             :                 {
     809         625 :                     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         625 :                     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        1516 :         else if ( st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
     827             :         {
     828        1145 :             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        5725 :                 for ( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
     839             :                 {
     840        4580 :                     tc_local[ch_idx] = &hTcBuffer->tc[ch_idx + 2][hTcBuffer->n_samples_rendered];
     841        4580 :                     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        1145 :                 ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     846        1145 :                 renderer_type_orig = st_ivas->renderer_type;
     847        1145 :                 ism_mode_orig = st_ivas->ism_mode;
     848        1145 :                 st_ivas->ism_mode = ism_mode_old;
     849        1145 :                 st_ivas->renderer_type = renderer_type_old;
     850        1145 :                 st_ivas->hDecoderConfig->ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate;
     851        1145 :                 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        1145 :                 st_ivas->hSpatParamRendCom->nb_subframes = 1;
     855        1145 :                 st_ivas->hSpatParamRendCom->subframes_rendered = 0;
     856        1145 :                 st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     857        1145 :                 st_ivas->hSpatParamRendCom->slots_rendered = 0;
     858        1145 :                 st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     859        1145 :                 set_s( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available );
     860             : 
     861        1145 :                 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        1145 :                 st_ivas->ism_mode = ism_mode_orig;
     868        1145 :                 st_ivas->renderer_type = renderer_type_orig;
     869        1145 :                 st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate;
     870             :             }
     871             :         }
     872         371 :         else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
     873             :         {
     874         371 :             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         371 :                 ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     886         371 :                 renderer_type_orig = st_ivas->renderer_type;
     887         371 :                 ism_mode_orig = st_ivas->ism_mode;
     888         371 :                 st_ivas->ism_mode = ism_mode_old;
     889         371 :                 st_ivas->renderer_type = renderer_type_old;
     890         371 :                 st_ivas->hDecoderConfig->ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate;
     891         371 :                 last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1];
     892         371 :                 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        1113 :                 for ( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
     899             :                 {
     900         742 :                     tc_local[ch_idx] = &st_ivas->hTcBuffer->tc[ch_idx][hTcBuffer->n_samples_rendered];
     901         742 :                     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         371 :                 st_ivas->hSpar->nb_subframes = 1;
     906         371 :                 st_ivas->hSpar->subframes_rendered = 0;
     907         371 :                 st_ivas->hSpar->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     908         371 :                 st_ivas->hSpar->slots_rendered = 0;
     909         371 :                 st_ivas->hSpar->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     910         371 :                 st_ivas->hSpatParamRendCom->nb_subframes = 1;
     911         371 :                 st_ivas->hSpatParamRendCom->subframes_rendered = 0;
     912         371 :                 st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     913         371 :                 st_ivas->hSpatParamRendCom->slots_rendered = 0;
     914         371 :                 st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
     915             : 
     916             :                 /* also adapt md maps, just use the last index */
     917         371 :                 set_s( st_ivas->hSpar->render_to_md_map, last_spar_md_idx, n_slots_still_available );
     918         371 :                 set_s( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available );
     919             : 
     920             :                 /* render the last subframe */
     921         371 :                 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         371 :                 st_ivas->ism_mode = ism_mode_orig;
     928         371 :                 st_ivas->renderer_type = renderer_type_orig;
     929         371 :                 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        5188 :         hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity;
     938             :     }
     939             : 
     940             :     /* update global combined orientation start index */
     941        8728 :     ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
     942             : 
     943        8728 :     *nSamplesRendered = n_samples_to_render;
     944             : 
     945             :     /* Only write out the valid data*/
     946        8728 :     if ( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 )
     947             :     {
     948        8728 :         if ( st_ivas->ivas_format != MONO_FORMAT )
     949             :         {
     950             : #ifndef DISABLE_LIMITER
     951        8728 :             ivas_limiter_dec( st_ivas->hLimiter, p_output, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect );
     952             : #endif
     953             :         }
     954             :     }
     955             : 
     956        8728 :     switch ( pcm_resolution )
     957             :     {
     958        8728 :         case PCM_INT16:
     959             : #ifdef DEBUGGING
     960             :             st_ivas->noClipping +=
     961             : #endif
     962        8728 :                 ivas_syn_output( p_output, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, (int16_t *) data );
     963        8728 :             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        8728 :     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       29973 : 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       29973 :     nMaxSlotsPerSubframe = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity;
     991       29973 :     nSlotsInFirstSubframe = nMaxSlotsPerSubframe - st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1];
     992             : 
     993       29973 :     if ( nSlotsInFirstSubframe > 0 )
     994             :     {
     995        5195 :         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        5195 :         st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nMaxSlotsPerSubframe;
     998             :     }
     999             : 
    1000       29973 :     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      995708 : 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      995708 :     segment_len = ( default_interp_length >> 1 );
    1023      995708 :     dec = 1.0f / default_interp_length;
    1024             : 
    1025      995708 :     interpolator[interp_length - 1] = 1.0f;
    1026    34450483 :     for ( idx = interp_length - 2; idx >= segment_len; idx-- )
    1027             :     {
    1028    33454775 :         interpolator[idx] = max( 0.0f, interpolator[idx + 1] - dec );
    1029             :     }
    1030             : 
    1031      995708 :     if ( interpolator[idx + 1] > 0.0f )
    1032             :     {
    1033      995490 :         dec = interpolator[idx + 1] / ( segment_len + 1 );
    1034    35192867 :         for ( ; idx >= 0; idx-- )
    1035             :         {
    1036    34197377 :             interpolator[idx] = interpolator[idx + 1] - dec;
    1037             :         }
    1038             :     }
    1039             :     else
    1040             :     {
    1041         218 :         set_f( interpolator, 0.0f, idx + 1 );
    1042             :     }
    1043             : 
    1044      995708 :     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    18288538 : 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    18288538 :     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    18288538 :     nSlotsInFirstSubframe = ( PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - subframe_nbslots[*nb_subframes - 1] );
    1066    18288538 :     *nb_subframes = 0;
    1067    18288538 :     if ( nSlotsInFirstSubframe > 0 )
    1068             :     {
    1069      470187 :         *nb_subframes = 1;
    1070      470187 :         nCldfbSlotsLocal -= nSlotsInFirstSubframe;
    1071             :     }
    1072             : 
    1073    18288538 :     *nb_subframes += (int16_t) ceilf( (float) nCldfbSlotsLocal / (float) PARAM_MC_MAX_NSLOTS_IN_SUBFRAME );
    1074    18288538 :     nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME;
    1075             : 
    1076    18288538 :     set_s( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
    1077    18288538 :     set_s( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes );
    1078             : 
    1079    18288538 :     if ( nSlotsInFirstSubframe > 0 )
    1080             :     {
    1081      470187 :         subframe_nbslots[0] = nSlotsInFirstSubframe;
    1082             :     }
    1083             : 
    1084    18288538 :     if ( nSlotsInLastSubframe > 0 )
    1085             :     {
    1086      470811 :         subframe_nbslots[*nb_subframes - 1] = nSlotsInLastSubframe;
    1087             :     }
    1088             : 
    1089    18288538 :     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    15819225 : 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    15819225 :     jbm_segment_len = ( default_len >> 1 );
    1115    15819225 :     dec = 1.0f / default_len;
    1116             : 
    1117   142393800 :     for ( map_idx = len - 1, src_idx = default_len - 1; map_idx >= jbm_segment_len; map_idx--, src_idx-- )
    1118             :     {
    1119   126574575 :         src_idx_map = max( 0, src_idx / subframe_len );
    1120   126574575 :         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    15819225 :     if ( src_idx >= 0 )
    1126             :     {
    1127    15817688 :         dec = ( (float) ( src_idx + 1 ) ) / ( (float) jbm_segment_len );
    1128    15817688 :         src_idx_f = (float) ( src_idx + 1 ) - dec;
    1129   142359192 :         for ( ; map_idx >= 0; map_idx-- )
    1130             :         {
    1131   126541504 :             src_idx = max( 0, ( (int16_t) round_f( src_idx_f ) ) / subframe_len );
    1132   126541504 :             map[map_idx] = ( offset + src_idx ) % buf_len;
    1133   126541504 :             src_idx_f -= dec;
    1134             :         }
    1135             :     }
    1136             :     else
    1137             :     {
    1138        1537 :         set_s( map, offset, map_idx + 1 );
    1139             :     }
    1140             : 
    1141    15819225 :     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     2118729 : 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     2118729 :     sf_length = len / subframe_len;
    1166     2118729 :     if ( len % subframe_len == 0 )
    1167             :     {
    1168             :         /* even subframes */
    1169    10590645 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1170             :         {
    1171     8472516 :             subframe_map_length[sf_idx] = sf_length;
    1172             :         }
    1173             :     }
    1174             :     else
    1175             :     {
    1176             :         /* uneven subframes */
    1177         600 :         decimal = ( (float) len / (float) subframe_len ) - (float) sf_length;
    1178         600 :         decimal_sum = decimal;
    1179         600 :         eps = 0.001f;
    1180        3000 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1181             :         {
    1182        2400 :             increment = (int16_t) floorf( decimal_sum + eps );
    1183        2400 :             subframe_map_length[sf_idx] = sf_length + increment;
    1184        2400 :             if ( increment > 0 )
    1185             :             {
    1186        1266 :                 decimal_sum -= 1.0f;
    1187             :             }
    1188        2400 :             decimal_sum += decimal;
    1189             :         }
    1190             :     }
    1191             : 
    1192             :     /* map slots to subframes */
    1193     2118729 :     sf_idx = 0;
    1194     2118729 :     subframes_written = 0;
    1195    36020855 :     for ( map_idx = 0; map_idx < len; map_idx++ )
    1196             :     {
    1197    33902126 :         map[map_idx] = ( offset + sf_idx ) % buf_len;
    1198    33902126 :         if ( map_idx - subframes_written >= subframe_map_length[sf_idx] - 1 )
    1199             :         {
    1200     8474916 :             subframes_written += subframe_map_length[sf_idx];
    1201     8474916 :             ++sf_idx;
    1202             :         }
    1203             :     }
    1204             : 
    1205     2118729 :     return;
    1206             : }
    1207             : 
    1208             : 
    1209             : /*--------------------------------------------------------------------------*
    1210             :  * ivas_dec_get_render_granularity()
    1211             :  *
    1212             :  * Get renderer granularity
    1213             :  *--------------------------------------------------------------------------*/
    1214             : 
    1215             : /*! r: render granularity */
    1216      445069 : 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      445069 :     if ( renderer_type == RENDERER_BINAURAL_OBJECTS_TD ||                                                       /* TD renderer */
    1225      426137 :          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       59377 :         render_granularity = NS2SA( output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
    1231             :     }
    1232             :     else
    1233             :     {
    1234             :         /* 1.25 ms granularity */
    1235      385692 :         render_granularity = NS2SA( output_Fs, CLDFB_SLOT_NS );
    1236             :     }
    1237             : 
    1238      445069 :     return render_granularity;
    1239             : }
    1240             : 
    1241             : 
    1242             : /*--------------------------------------------------------------------------*
    1243             :  * ivas_dec_tc_buffer_playout()
    1244             :  *
    1245             :  * Get TC buffer playout
    1246             :  *--------------------------------------------------------------------------*/
    1247             : 
    1248     9629043 : 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     9629043 :     hTcBuffer = st_ivas->hTcBuffer;
    1258     9629043 :     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     9629043 :     slots_to_render = min( hTcBuffer->num_slots - hTcBuffer->slots_rendered, nSamplesAsked / slot_size );
    1262     9629043 :     hTcBuffer->slots_rendered += slots_to_render;
    1263     9629043 :     *nSamplesRendered = (uint16_t) slots_to_render * slot_size;
    1264     9629043 :     first_sf = hTcBuffer->subframes_rendered;
    1265     9629043 :     last_sf = first_sf;
    1266             : 
    1267    30251208 :     while ( slots_to_render > 0 )
    1268             :     {
    1269    20622165 :         slots_to_render -= hTcBuffer->subframe_nbslots[last_sf];
    1270    20622165 :         last_sf++;
    1271             :     }
    1272             : #ifdef DEBUGGING
    1273             :     assert( slots_to_render == 0 );
    1274             : #endif
    1275             : 
    1276    28490368 :     for ( ch_idx = 0; ch_idx < hTcBuffer->nchan_transport_rend; ch_idx++ )
    1277             :     {
    1278    18861325 :         output[ch_idx] = st_ivas->hTcBuffer->tc[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered;
    1279             :     }
    1280             : 
    1281     9629043 :     hTcBuffer->subframes_rendered = last_sf;
    1282             : 
    1283     9629043 :     return;
    1284             : }
    1285             : 
    1286             : 
    1287             : /*--------------------------------------------------------------------------*
    1288             :  * ivas_dec_td_renderers_adapt_subframes()
    1289             :  *
    1290             :  * Adapt subframes for TD renderers
    1291             :  *--------------------------------------------------------------------------*/
    1292             : 
    1293    11449874 : 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    11449874 :     hTcBuffer = st_ivas->hTcBuffer;
    1302             : 
    1303    11449874 :     nMaxSlotsPerSubframe = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / hTcBuffer->n_samples_granularity;
    1304    11449874 :     nSlotsAvailable = hTcBuffer->n_samples_available / hTcBuffer->n_samples_granularity;
    1305    11449874 :     hTcBuffer->num_slots = nSlotsAvailable;
    1306    11449874 :     hTcBuffer->n_samples_available = nSlotsAvailable * hTcBuffer->n_samples_granularity;
    1307    11449874 :     nSlotsInFirstSubframe = nMaxSlotsPerSubframe - hTcBuffer->subframe_nbslots[hTcBuffer->nb_subframes - 1];
    1308    11449874 :     hTcBuffer->nb_subframes = 0;
    1309             : 
    1310    11449874 :     if ( nSlotsInFirstSubframe > 0 )
    1311             :     {
    1312      218705 :         hTcBuffer->nb_subframes = 1;
    1313      218705 :         nSlotsAvailable -= nSlotsInFirstSubframe;
    1314             :     }
    1315    11449874 :     hTcBuffer->nb_subframes += (int16_t) ceilf( (float) nSlotsAvailable / (float) nMaxSlotsPerSubframe );
    1316    11449874 :     nSlotsInLastSubframe = nSlotsAvailable % nMaxSlotsPerSubframe;
    1317    11449874 :     set_s( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
    1318    11449874 :     set_s( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, hTcBuffer->nb_subframes );
    1319             : 
    1320    11449874 :     if ( nSlotsInFirstSubframe > 0 )
    1321             :     {
    1322      218705 :         hTcBuffer->subframe_nbslots[0] = nSlotsInFirstSubframe;
    1323             :     }
    1324             : 
    1325    11449874 :     if ( nSlotsInLastSubframe > 0 )
    1326             :     {
    1327      218800 :         hTcBuffer->subframe_nbslots[hTcBuffer->nb_subframes - 1] = nSlotsInLastSubframe;
    1328             :     }
    1329             : 
    1330    11449874 :     hTcBuffer->slots_rendered = 0;
    1331    11449874 :     hTcBuffer->subframes_rendered = 0;
    1332             : 
    1333    11449874 :     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         510 : ivas_error ivas_jbm_dec_masa_metadata_open(
    1344             :     Decoder_Struct *st_ivas )
    1345             : {
    1346             :     JBM_METADATA_HANDLE hJbmMetadata;
    1347             : 
    1348         510 :     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         510 :     hJbmMetadata->sf_write_idx = 0;
    1354         510 :     hJbmMetadata->sf_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_PARAM_SPATIAL_SUBFRAMES;
    1355             : 
    1356         510 :     hJbmMetadata->slot_write_idx = 0;
    1357         510 :     hJbmMetadata->slot_read_idx = 0;
    1358         510 :     hJbmMetadata->slot_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
    1359             : 
    1360         510 :     st_ivas->hJbmMetadata = hJbmMetadata;
    1361             : 
    1362         510 :     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       97965 : 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       97965 :     hJbmMetadata = st_ivas->hJbmMetadata;
    1381       97965 :     extOutMeta = st_ivas->hMasa->data.extOutMeta;
    1382             : 
    1383      489825 :     for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
    1384             :     {
    1385      391860 :         write_idx = ( hJbmMetadata->sf_write_idx + sf ) % hJbmMetadata->sf_md_buffer_length;
    1386             : 
    1387     1175580 :         for ( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
    1388             :         {
    1389    19593000 :             for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    1390             :             {
    1391    18809280 :                 hJbmMetadata->directionIndexBuffer[dir][write_idx][band] = extOutMeta->directionIndex[dir][sf][band];
    1392    18809280 :                 hJbmMetadata->directToTotalRatioBuffer[dir][write_idx][band] = extOutMeta->directToTotalRatio[dir][sf][band];
    1393    18809280 :                 hJbmMetadata->spreadCoherenceBuffer[dir][write_idx][band] = extOutMeta->spreadCoherence[dir][sf][band];
    1394             :             }
    1395             :         }
    1396             : 
    1397     9796500 :         for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    1398             :         {
    1399     9404640 :             hJbmMetadata->diffuseToTotalRatioBuffer[write_idx][band] = extOutMeta->diffuseToTotalRatio[sf][band];
    1400     9404640 :             hJbmMetadata->surroundCoherenceBuffer[write_idx][band] = extOutMeta->surroundCoherence[sf][band];
    1401             :         }
    1402             : 
    1403      391860 :         hJbmMetadata->numberOfDirections[write_idx] = extOutMeta->descriptiveMeta.numberOfDirections;
    1404             :     }
    1405             : 
    1406       97965 :     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       97965 : 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       97965 :     ivas_jbm_dec_copy_masa_meta_to_buffer( st_ivas );
    1428             : 
    1429             :     /* Set values */
    1430       97965 :     hJbmMetadata = st_ivas->hJbmMetadata;
    1431       97965 :     num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
    1432             : 
    1433             :     /* Map input subframes to slots */
    1434       97965 :     ivas_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, MAX_PARAM_SPATIAL_SUBFRAMES, sf_to_slot_map );
    1435             : 
    1436     1665164 :     for ( slot_idx = 0; slot_idx < nCldfbTs; slot_idx++ )
    1437             :     {
    1438     1567199 :         write_idx = ( hJbmMetadata->slot_write_idx + slot_idx ) % hJbmMetadata->slot_md_buffer_length;
    1439     1567199 :         sf_index = ( hJbmMetadata->sf_write_idx + sf_to_slot_map[slot_idx] ) % hJbmMetadata->sf_md_buffer_length;
    1440             : 
    1441     1567199 :         hJbmMetadata->sf_to_slot_map[write_idx] = sf_index;
    1442             :     }
    1443             : 
    1444       97965 :     hJbmMetadata->sf_write_idx = ( hJbmMetadata->sf_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hJbmMetadata->sf_md_buffer_length;
    1445       97965 :     hJbmMetadata->slot_write_idx = ( hJbmMetadata->slot_write_idx + nCldfbTs ) % hJbmMetadata->slot_md_buffer_length;
    1446             : 
    1447       97965 :     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       97944 : 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       97944 :     hJbmMetadata = st_ivas->hJbmMetadata;
    1471       97944 :     extOutMeta = st_ivas->hMasa->data.extOutMeta;
    1472             : 
    1473             :     /* Map slots to subframes */
    1474      489720 :     for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1475             :     {
    1476      391776 :         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      391776 :         sf_to_sf_map[sf_idx] = hJbmMetadata->sf_to_slot_map[slot_read_idx];
    1478      391776 :         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      489720 :     for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1483             :     {
    1484      391776 :         sf_read_idx = sf_to_sf_map[sf_idx];
    1485             : 
    1486     1175328 :         for ( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
    1487             :         {
    1488    19588800 :             for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    1489             :             {
    1490    18805248 :                 extOutMeta->directionIndex[dir][sf_idx][band] = hJbmMetadata->directionIndexBuffer[dir][sf_read_idx][band];
    1491    18805248 :                 extOutMeta->directToTotalRatio[dir][sf_idx][band] = hJbmMetadata->directToTotalRatioBuffer[dir][sf_read_idx][band];
    1492    18805248 :                 extOutMeta->spreadCoherence[dir][sf_idx][band] = hJbmMetadata->spreadCoherenceBuffer[dir][sf_read_idx][band];
    1493             :             }
    1494             :         }
    1495             : 
    1496     9794400 :         for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
    1497             :         {
    1498     9402624 :             extOutMeta->diffuseToTotalRatio[sf_idx][band] = hJbmMetadata->diffuseToTotalRatioBuffer[sf_read_idx][band];
    1499     9402624 :             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       97944 :     numberOfDirections = 0;
    1505      423080 :     for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1506             :     {
    1507      342132 :         sf_read_idx = sf_to_sf_map[sf_idx];
    1508             : 
    1509      342132 :         if ( hJbmMetadata->numberOfDirections[sf_read_idx] == 1 )
    1510             :         {
    1511       16996 :             numberOfDirections = 1;
    1512       16996 :             break;
    1513             :         }
    1514             :     }
    1515             : 
    1516       97944 :     extOutMeta->descriptiveMeta.numberOfDirections = numberOfDirections;
    1517             : 
    1518       97944 :     return;
    1519             : }
    1520             : 
    1521             : 
    1522             : /*--------------------------------------------------------------------------*
    1523             :  * ivas_dec_prepare_renderer()
    1524             :  *
    1525             :  * Prepare IVAS renderer routine
    1526             :  *--------------------------------------------------------------------------*/
    1527             : 
    1528    21882874 : 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    21882874 :     push_wmops( "ivas_dec_prepare_renderer" );
    1537             : 
    1538    21882874 :     output_config = st_ivas->hDecoderConfig->output_config;
    1539    21882874 :     hTcBuffer = st_ivas->hTcBuffer;
    1540    21882874 :     n_samples_available = hTcBuffer->n_samples_available;
    1541    21882874 :     n_render_timeslots = n_samples_available / hTcBuffer->n_samples_granularity;
    1542             : 
    1543    21882874 :     if ( hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_BUFFER )
    1544             :     {
    1545     5122922 :         ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1546             : 
    1547     5122922 :         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       94875 :             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     5122922 :         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    16759952 :     else if ( st_ivas->ivas_format == MONO_FORMAT || st_ivas->ivas_format == STEREO_FORMAT )
    1559             :     {
    1560      153491 :         ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1561             :     }
    1562    16606461 :     else if ( st_ivas->ivas_format == ISM_FORMAT )
    1563             :     {
    1564     2444514 :         if ( st_ivas->ism_mode == ISM_MODE_PARAM )
    1565             :         {
    1566      461421 :             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      267595 :                 ivas_dirac_dec_set_md_map( st_ivas, n_render_timeslots );
    1569      267595 :                 ivas_param_ism_params_to_masa_param_mapping( st_ivas );
    1570             :             }
    1571      193826 :             else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
    1572             :             {
    1573      193826 :                 ivas_param_ism_dec_prepare_renderer( st_ivas, n_render_timeslots );
    1574             :             }
    1575             :         }
    1576             :         else /* ISM_MODE_DISC */
    1577             :         {
    1578     1983093 :             ivas_ism_dec_digest_tc( st_ivas );
    1579             :         }
    1580             :     }
    1581    14161947 :     else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
    1582             :     {
    1583     8581089 :         ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1584             :     }
    1585     5580858 :     else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    1586             :     {
    1587     2409748 :         if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
    1588             :         {
    1589     1287488 :             ivas_ism_dec_digest_tc( st_ivas );
    1590             : 
    1591             :             /* delay the objects here for all renderers where it is needed */
    1592     1287488 :             if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ||
    1593      815242 :                    st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ||
    1594      640017 :                    st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
    1595      459531 :                    st_ivas->renderer_type == RENDERER_OSBA_LS ||
    1596     1204623 :                    output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) &&
    1597     1126123 :                  ( output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    1598             :             {
    1599     4256789 :                 for ( n = 0; n < st_ivas->nchan_ism; n++ )
    1600             :                 {
    1601     3130666 :                     delay_signal( hTcBuffer->tc[n], n_samples_available, st_ivas->hSbaIsmData->delayBuffer[n], st_ivas->hSbaIsmData->delayBuffer_size );
    1602             :                 }
    1603             :             }
    1604             : 
    1605     1287488 :             if ( !st_ivas->sba_dirac_stereo_flag )
    1606             :             {
    1607     1204623 :                 if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
    1608             :                 {
    1609      472246 :                     n_render_timeslots *= ( hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size );
    1610             :                 }
    1611             : 
    1612     1204623 :                 ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1613             :             }
    1614             :         }
    1615             :         else
    1616             :         {
    1617     1122260 :             ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1618             : 
    1619     1122260 :             ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1620             :         }
    1621             :     }
    1622     3171110 :     else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
    1623             :     {
    1624     1008228 :         if ( st_ivas->renderer_type == RENDERER_OMASA_MIX_EXT || st_ivas->renderer_type == RENDERER_OMASA_OBJECT_EXT )
    1625             :         {
    1626       17248 :             ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1627             : 
    1628       17248 :             if ( st_ivas->hDecoderConfig->Opt_tsm )
    1629             :             {
    1630        3090 :                 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       17248 :             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      990980 :             if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC )
    1645             :             {
    1646      127460 :                 n_render_timeslots *= ( hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size );
    1647             :             }
    1648             : 
    1649      990980 :             ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1650             : 
    1651      990980 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
    1652             :             {
    1653      526127 :                 ivas_ism_dec_digest_tc( st_ivas );
    1654             :             }
    1655             : 
    1656      990980 :             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      672825 :                 nchan_transport_ism = 0;
    1662      672825 :                 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      181406 :                     nchan_transport_ism = 1;
    1665             :                 }
    1666      491419 :                 else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
    1667             :                 {
    1668      374877 :                     nchan_transport_ism = st_ivas->nchan_ism;
    1669             :                 }
    1670             : 
    1671      672825 :                 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      118568 :                     if ( st_ivas->hMasaIsmData->masa_gain_is_edited )
    1675             :                     {
    1676       62598 :                         for ( n = 0; n < CPE_CHANNELS; n++ )
    1677             :                         {
    1678       41732 :                             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     1737681 :                 for ( n = 0; n < nchan_transport_ism; n++ )
    1684             :                 {
    1685     1064856 :                     if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
    1686             :                     {
    1687             :                         float gainIsm;
    1688      327501 :                         gainIsm = OMASA_TDREND_MATCHING_GAIN;
    1689             : 
    1690      327501 :                         if ( st_ivas->hMasaIsmData->ism_gain_is_edited[n] )
    1691             :                         {
    1692       97472 :                             gainIsm *= st_ivas->hMasaIsmData->gain_ism_edited[n];
    1693             :                         }
    1694             : 
    1695      327501 :                         v_multc( hTcBuffer->tc[CPE_CHANNELS + n], gainIsm, hTcBuffer->tc[CPE_CHANNELS + n], n_samples_available );
    1696             :                     }
    1697             : 
    1698     1064856 :                     if ( output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
    1699             :                     {
    1700      974945 :                         delay_signal( hTcBuffer->tc[CPE_CHANNELS + n], n_samples_available, st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size );
    1701             :                     }
    1702             :                 }
    1703             : 
    1704      672825 :                 if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
    1705             :                 {
    1706             :                     int16_t tcBufferSize;
    1707      127460 :                     tcBufferSize = st_ivas->hSpatParamRendCom->num_slots * st_ivas->hSpatParamRendCom->slot_size;
    1708             : 
    1709      127460 :                     if ( st_ivas->hMasaIsmData->masa_gain_is_edited )
    1710             :                     {
    1711       83283 :                         for ( n = 0; n < BINAURAL_CHANNELS; n++ )
    1712             :                         {
    1713       55522 :                             v_multc( hTcBuffer->tc[n], st_ivas->hMasaIsmData->gain_masa_edited, hTcBuffer->tc[n], tcBufferSize );
    1714             :                         }
    1715             :                     }
    1716             :                 }
    1717             :             }
    1718             :         }
    1719             :     }
    1720     2162882 :     else if ( st_ivas->ivas_format == MC_FORMAT )
    1721             :     {
    1722     2162882 :         if ( st_ivas->mc_mode == MC_MODE_MCT )
    1723             :         {
    1724     1109992 :             ivas_dec_td_renderers_adapt_subframes( st_ivas );
    1725             :         }
    1726     1052890 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
    1727             :         {
    1728      127253 :             ivas_mc_paramupmix_dec_digest_tc( st_ivas, (uint8_t) n_render_timeslots, n_samples_available );
    1729             :         }
    1730      925637 :         else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
    1731             :         {
    1732      448549 :             ivas_param_mc_dec_prepare_renderer( st_ivas, (uint8_t) n_render_timeslots );
    1733             :         }
    1734      477088 :         else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
    1735             :         {
    1736      477088 :             ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, n_samples_available );
    1737             :         }
    1738             :     }
    1739             : 
    1740    21882874 :     pop_wmops();
    1741    21882874 :     return;
    1742             : }

Generated by: LCOV version 1.14