LCOV - code coverage report
Current view: top level - lib_dec - ivas_omasa_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ b5bd5e0684ad2d9250297e1e7a0ddc986cb7b37e Lines: 427 465 91.8 %
Date: 2025-10-27 07:01:45 Functions: 12 13 92.3 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include "options.h"
      34             : #include <stdlib.h>
      35             : #include <math.h>
      36             : #include "ivas_cnst.h"
      37             : #include "ivas_prot.h"
      38             : #include "prot.h"
      39             : #include "ivas_prot_rend.h"
      40             : #include "ivas_rom_com.h"
      41             : #ifdef DEBUGGING
      42             : #include "debug.h"
      43             : #endif
      44             : #include "wmc_auto.h"
      45             : 
      46             : /*-------------------------------------------------------------------------
      47             :  * Local constants
      48             :  *------------------------------------------------------------------------*/
      49             : 
      50             : #define EXT_RENDER_IIR_FAC 0.95f
      51             : 
      52             : /*-------------------------------------------------------------------*
      53             :  * ivas_omasa_data_open()
      54             :  *
      55             :  * Allocate and initialize MASA_ISM rendering handle
      56             :  *-------------------------------------------------------------------*/
      57             : 
      58       10287 : ivas_error ivas_omasa_data_open(
      59             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder handle  */
      60             : )
      61             : {
      62             :     MASA_ISM_DATA_HANDLE hMasaIsmData;
      63             :     int16_t ch;
      64             :     int16_t sf, obj_idx;
      65             : 
      66       10287 :     if ( ( hMasaIsmData = (MASA_ISM_DATA_HANDLE) malloc( sizeof( MASA_ISM_DATA ) ) ) == NULL )
      67             :     {
      68           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA ISM data\n" ) );
      69             :     }
      70             : 
      71      257175 :     for ( int16_t band_idx = 0; band_idx < MASA_FREQUENCY_BANDS; band_idx++ )
      72             :     {
      73      740664 :         for ( ch = 0; ch < 2; ch++ )
      74             :         {
      75      493776 :             hMasaIsmData->ismPreprocMatrix[ch][ch][band_idx] = 1.0f;
      76      493776 :             hMasaIsmData->ismPreprocMatrix[1 - ch][ch][band_idx] = 0.0f;
      77      493776 :             hMasaIsmData->eneMoveIIR[ch][band_idx] = 0.0f;
      78      493776 :             hMasaIsmData->enePreserveIIR[ch][band_idx] = 0.0f;
      79             :         }
      80      246888 :         hMasaIsmData->eneOrigIIR[band_idx] = 0.0f;
      81      246888 :         hMasaIsmData->preprocEneTarget[band_idx] = 0.0f;
      82      246888 :         hMasaIsmData->preprocEneRealized[band_idx] = 0.0f;
      83             :     }
      84             : 
      85       10287 :     hMasaIsmData->objectsEdited = 0;
      86       10287 :     hMasaIsmData->delayBuffer = NULL;
      87             : 
      88       51435 :     for ( ch = 0; ch < MAX_NUM_OBJECTS; ch++ )
      89             :     {
      90       41148 :         hMasaIsmData->ism_dir_is_edited[ch] = 0;
      91       41148 :         hMasaIsmData->ism_gain_is_edited[ch] = 0;
      92       41148 :         hMasaIsmData->q_elevation_old[ch] = 0.0f;
      93       41148 :         hMasaIsmData->q_azimuth_old[ch] = 0.0f;
      94             :     }
      95       10287 :     hMasaIsmData->masa_gain_is_edited = 0;
      96       10287 :     hMasaIsmData->idx_separated_ism = -1;
      97             : 
      98       51435 :     for ( obj_idx = 0; obj_idx < MAX_NUM_OBJECTS; obj_idx++ )
      99             :     {
     100       41148 :         set_s( hMasaIsmData->azimuth_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR );
     101       41148 :         set_s( hMasaIsmData->elevation_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR );
     102      288036 :         for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; sf++ )
     103             :         {
     104      246888 :             set_zero( hMasaIsmData->energy_ratio_ism[obj_idx][sf], CLDFB_NO_CHANNELS_MAX );
     105             :         }
     106             :     }
     107       10287 :     set_s( hMasaIsmData->azimuth_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR );
     108       10287 :     set_s( hMasaIsmData->elevation_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR );
     109             : 
     110       10287 :     hMasaIsmData->hExtData = NULL;
     111       10287 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     112             :     {
     113             :         MASA_ISM_EXT_DATA_HANDLE hExtData;
     114             : 
     115         554 :         if ( ( hExtData = (MASA_ISM_EXT_DATA_HANDLE) malloc( sizeof( MASA_ISM_EXT_DATA ) ) ) == NULL )
     116             :         {
     117           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA ISM data\n" ) );
     118             :         }
     119             : 
     120         554 :         hExtData->prev_idx_separated_ism = 0;
     121             : 
     122        2770 :         for ( ch = 0; ch < MAX_NUM_OBJECTS; ch++ )
     123             :         {
     124        2216 :             set_zero( hExtData->prev_panning_gains[ch], 2 );
     125             :         }
     126             : 
     127        2770 :         for ( ch = 0; ch < MAX_NUM_OBJECTS; ch++ )
     128             :         {
     129        2216 :             set_zero( hExtData->ism_render_proto_energy[ch], CLDFB_NO_CHANNELS_MAX );
     130        2216 :             set_zero( hExtData->ism_render_target_energy[ch], CLDFB_NO_CHANNELS_MAX );
     131             :         }
     132         554 :         set_zero( hExtData->masa_render_proto_energy, CLDFB_NO_CHANNELS_MAX );
     133         554 :         set_zero( hExtData->masa_render_target_energy, CLDFB_NO_CHANNELS_MAX );
     134             : 
     135        3878 :         for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; sf++ )
     136             :         {
     137        3324 :             set_zero( hExtData->masa_render_masa_to_total[sf], CLDFB_NO_CHANNELS_MAX );
     138             :         }
     139             : 
     140         554 :         hMasaIsmData->hExtData = hExtData;
     141             :     }
     142             : 
     143       10287 :     st_ivas->hMasaIsmData = hMasaIsmData;
     144             : 
     145       10287 :     return IVAS_ERR_OK;
     146             : }
     147             : 
     148             : 
     149             : /*-------------------------------------------------------------------*
     150             :  * ivas_omasa_data_close()
     151             :  *
     152             :  * Deallocate MASA_ISM rendering handle
     153             :  *-------------------------------------------------------------------*/
     154             : 
     155       86903 : void ivas_omasa_data_close(
     156             :     MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle    */
     157             : )
     158             : {
     159             :     int16_t i;
     160             : 
     161       86903 :     if ( hMasaIsmData == NULL || *hMasaIsmData == NULL )
     162             :     {
     163       76616 :         return;
     164             :     }
     165             : 
     166       10287 :     if ( ( *hMasaIsmData )->delayBuffer != NULL )
     167             :     {
     168       14185 :         for ( i = 0; i < ( *hMasaIsmData )->delayBuffer_nchan; i++ )
     169             :         {
     170        9285 :             free( ( *hMasaIsmData )->delayBuffer[i] );
     171             :         }
     172        4900 :         free( ( *hMasaIsmData )->delayBuffer );
     173        4900 :         ( *hMasaIsmData )->delayBuffer = NULL;
     174             :     }
     175             : 
     176       10287 :     if ( ( *hMasaIsmData )->hExtData != NULL )
     177             :     {
     178         554 :         free( ( *hMasaIsmData )->hExtData );
     179         554 :         ( *hMasaIsmData )->hExtData = NULL;
     180             :     }
     181             : 
     182       10287 :     free( *hMasaIsmData );
     183       10287 :     *hMasaIsmData = NULL;
     184             : 
     185       10287 :     return;
     186             : }
     187             : 
     188             : 
     189             : /*--------------------------------------------------------------------------*
     190             :  * ivas_omasa_dec_config()
     191             :  *
     192             :  * oMASA decoder configuration
     193             :  *--------------------------------------------------------------------------*/
     194             : 
     195        7272 : ivas_error ivas_omasa_dec_config(
     196             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure  */
     197             : )
     198             : {
     199             :     int16_t k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old;
     200             :     int32_t ivas_total_brate, ism_total_brate, cpe_brate;
     201             :     ISM_MODE ism_mode_old;
     202             :     IVAS_FORMAT ivas_format_orig;
     203             :     int16_t nchan_out_buff;
     204             :     ivas_error error;
     205             :     RENDERER_TYPE old_renderer_type;
     206             : 
     207             :     /* initializations */
     208        7272 :     ism_total_brate = 0;
     209        7272 :     ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
     210             : 
     211             :     /* save previous frame parameters */
     212        7272 :     ism_mode_old = ivas_omasa_ism_mode_select( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->nchan_ism );
     213        7272 :     st_ivas->ism_mode = ism_mode_old;
     214             : 
     215        7272 :     ivas_format_orig = st_ivas->ivas_format;
     216        7272 :     st_ivas->ivas_format = st_ivas->last_ivas_format;
     217        7272 :     ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
     218        7272 :     st_ivas->ivas_format = ivas_format_orig;
     219             : 
     220        7272 :     nSCE_old = st_ivas->nSCE;
     221        7272 :     nchan_hp20_old = getNumChanSynthesis( st_ivas );
     222             : 
     223             :     /* set ism_mode of current frame */
     224        7272 :     st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism );
     225             : 
     226             :     /*-----------------------------------------------------------------*
     227             :      * Renderer selection
     228             :      *-----------------------------------------------------------------*/
     229             : 
     230        7272 :     old_renderer_type = st_ivas->renderer_type;
     231             : 
     232             :     /* MASA reconfig. */
     233        7272 :     cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism );
     234        7272 :     if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ( cpe_brate < MASA_STEREO_MIN_BITRATE ) && st_ivas->nCPE == 1 )
     235             :     {
     236           0 :         st_ivas->hCPE[0]->nchan_out = 1;
     237             :     }
     238        7272 :     else if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK )
     239             :     {
     240           0 :         return error;
     241             :     }
     242             : 
     243        7272 :     if ( cpe_brate < MASA_STEREO_MIN_BITRATE )
     244             :     {
     245        2439 :         st_ivas->hCPE[0]->nchan_out = 1;
     246             :     }
     247             :     else
     248             :     {
     249        4833 :         st_ivas->hCPE[0]->nchan_out = 2;
     250             :     }
     251             : 
     252             :     /* OMASA reconfig. */
     253        7272 :     if ( st_ivas->hMasaIsmData == NULL && st_ivas->ivas_format == MASA_ISM_FORMAT )
     254             :     {
     255         750 :         if ( ( error = ivas_omasa_data_open( st_ivas ) ) != IVAS_ERR_OK )
     256             :         {
     257           0 :             return error;
     258             :         }
     259             :     }
     260             : 
     261        7272 :     ivas_set_omasa_TC( st_ivas->ism_mode, st_ivas->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE );
     262             : 
     263             :     /* re-configure hp20 memories */
     264        7272 :     if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK )
     265             :     {
     266           0 :         return error;
     267             :     }
     268             : 
     269             :     /* reconfigure core-coders for ISMs */
     270        7272 :     k = 0;
     271       65085 :     while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] )
     272             :     {
     273       57813 :         k++;
     274             :     }
     275             : 
     276       17490 :     for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
     277             :     {
     278       10218 :         ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1];
     279             :     }
     280             : 
     281        7272 :     if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, st_ivas->nSCE > 0 ? sep_object_brate[k - 2][st_ivas->nSCE - 1] : 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK )
     282             :     {
     283           0 :         return error;
     284             :     }
     285             : 
     286        7272 :     if ( ism_mode_old != st_ivas->ism_mode )
     287             :     {
     288             :         /* ISM MD reconfig. */
     289        6525 :         if ( st_ivas->hIsmMetaData[0] == NULL )
     290             :         {
     291         750 :             if ( ( error = ivas_ism_metadata_dec_create( st_ivas, st_ivas->nchan_ism, NULL ) ) != IVAS_ERR_OK )
     292             :             {
     293           0 :                 return error;
     294             :             }
     295             :         }
     296             :         else
     297             :         {
     298       23835 :             for ( k = 0; k < st_ivas->nchan_ism; k++ )
     299             :             {
     300       18060 :                 ivas_ism_reset_metadata_handle_dec( st_ivas->hIsmMetaData[k] );
     301             :             }
     302             :         }
     303             : 
     304        6525 :         st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate;
     305             : 
     306             :         /*-----------------------------------------------------------------*
     307             :          * Renderer selection
     308             :          *-----------------------------------------------------------------*/
     309             : 
     310        6525 :         ivas_renderer_select( st_ivas );
     311             : 
     312             :         /*-------------------------------------------------------------------*
     313             :          * Reallocate rendering handles
     314             :          *--------------------------------------------------------------------*/
     315             : 
     316        6525 :         if ( old_renderer_type != st_ivas->renderer_type )
     317             :         {
     318         510 :             if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX )
     319             :             {
     320         162 :                 if ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK )
     321             :                 {
     322           0 :                     return error;
     323             :                 }
     324             :             }
     325             :             else
     326             :             {
     327         348 :                 ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
     328             :             }
     329             :         }
     330             : 
     331             :         /* objects renderer reconfig. */
     332        6525 :         if ( st_ivas->hMasaIsmData != NULL || st_ivas->hIsmRendererData != NULL )
     333             :         {
     334             :             /* this calls also ivas_ism_renderer_close() closing st_ivas->hIsmRendererData used by the EXT renderers. also cleans st_ivas->hMasaIsmData */
     335        6525 :             ivas_omasa_separate_object_renderer_close( st_ivas );
     336             :         }
     337             : 
     338        6525 :         if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->hMasaIsmData != NULL ) /* this structure is in use only in ISM_MASA_MODE_PARAM_ONE_OBJ */
     339             :         {
     340        1239 :             MASA_ISM_DATA_HANDLE hMasaIsmData = st_ivas->hMasaIsmData;
     341        6195 :             for ( int16_t obj_idx = 0; obj_idx < MAX_NUM_OBJECTS; obj_idx++ )
     342             :             {
     343        4956 :                 set_s( hMasaIsmData->azimuth_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR );
     344        4956 :                 set_s( hMasaIsmData->elevation_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR );
     345       34692 :                 for ( int16_t sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; sf++ )
     346             :                 {
     347       29736 :                     set_zero( hMasaIsmData->energy_ratio_ism[obj_idx][sf], CLDFB_NO_CHANNELS_MAX );
     348             :                 }
     349             :             }
     350        1239 :             set_s( hMasaIsmData->azimuth_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR );
     351        1239 :             set_s( hMasaIsmData->elevation_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR );
     352             :         }
     353             : 
     354        6525 :         if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
     355             :         {
     356        1251 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
     357             :             {
     358             :                 /* Allocate TD renderer for the objects in DISC mode */
     359         363 :                 if ( st_ivas->hBinRendererTd == NULL )
     360             :                 {
     361         363 :                     if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK )
     362             :                     {
     363           0 :                         return error;
     364             :                     }
     365             : 
     366         363 :                     if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
     367             :                     {
     368           0 :                         if ( ( error = ivas_reverb_open( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
     369             :                         {
     370           0 :                             return error;
     371             :                         }
     372             :                     }
     373             :                 }
     374             : 
     375             :                 /* Allocate memory for delay buffer within 'hMasaIsmData' */
     376         363 :                 if ( ( error = ivas_omasa_objects_delay_open( st_ivas ) ) != IVAS_ERR_OK )
     377             :                 {
     378           0 :                     return error;
     379             :                 }
     380             :             }
     381             :             else
     382             :             {
     383         888 :                 if ( st_ivas->hBinRendererTd != NULL )
     384             :                 {
     385             :                     /* TD renderer handle */
     386         366 :                     ivas_td_binaural_close( &st_ivas->hBinRendererTd );
     387             :                 }
     388             :                 /* ISM renderer handle + ISM data handle */
     389         888 :                 ivas_omasa_separate_object_renderer_close( st_ivas );
     390             :             }
     391             :         }
     392             : 
     393        6525 :         if ( st_ivas->renderer_type == RENDERER_DIRAC )
     394             :         {
     395        2769 :             if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK )
     396             :             {
     397           0 :                 return error;
     398             :             }
     399             : 
     400        2769 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC )
     401             :             {
     402             :                 /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
     403        1839 :                 if ( ( error = ivas_omasa_objects_delay_open( st_ivas ) ) != IVAS_ERR_OK )
     404             :                 {
     405           0 :                     return error;
     406             :                 }
     407        1839 :                 if ( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK )
     408             :                 {
     409           0 :                     return error;
     410             :                 }
     411             :             }
     412             :             else
     413             :             {
     414             :                 /* ISM renderer handle + ISM data handle */
     415         930 :                 ivas_omasa_separate_object_renderer_close( st_ivas );
     416             :             }
     417             :         }
     418             : 
     419        6525 :         if ( st_ivas->renderer_type == RENDERER_OMASA_MIX_EXT )
     420             :         {
     421             :             /* Allocate 'hIsmRendererData' handle */
     422          54 :             if ( ( error = ivas_omasa_combine_separate_ism_with_masa_open( st_ivas ) ) != IVAS_ERR_OK )
     423             :             {
     424           0 :                 return error;
     425             :             }
     426             :         }
     427             : 
     428        6525 :         if ( st_ivas->renderer_type == RENDERER_OMASA_OBJECT_EXT )
     429             :         {
     430          57 :             DIRAC_CONFIG_FLAG common_rend_config_flag = st_ivas->hSpatParamRendCom == NULL ? DIRAC_OPEN : DIRAC_RECONFIGURE;
     431             : 
     432             :             /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
     433          57 :             if ( ( error = ivas_omasa_objects_delay_open( st_ivas ) ) != IVAS_ERR_OK )
     434             :             {
     435           0 :                 return error;
     436             :             }
     437             : 
     438          57 :             if ( ( error = ivas_spat_hSpatParamRendCom_config( &st_ivas->hSpatParamRendCom, common_rend_config_flag, 0,
     439          57 :                                                                st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs, 0, 0 ) ) != IVAS_ERR_OK )
     440             :             {
     441           0 :                 return error;
     442             :             }
     443             :         }
     444             : 
     445             :         /*-----------------------------------------------------------------*
     446             :          * TD Decorrelator
     447             :          *-----------------------------------------------------------------*/
     448             : 
     449        6525 :         if ( st_ivas->hDiracDecBin[0] != NULL )
     450             :         {
     451        2937 :             if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin[0]->hTdDecorr ), &( st_ivas->hDiracDecBin[0]->useTdDecorr ) ) ) != IVAS_ERR_OK )
     452             :             {
     453           0 :                 return error;
     454             :             }
     455             :         }
     456             : 
     457             :         /*-----------------------------------------------------------------*
     458             :          * CLDFB instances
     459             :          *-----------------------------------------------------------------*/
     460             : 
     461        6525 :         if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK )
     462             :         {
     463           0 :             return error;
     464             :         }
     465             : 
     466             :         /*-----------------------------------------------------------------*
     467             :          * floating-point output audio buffers
     468             :          *-----------------------------------------------------------------*/
     469             : 
     470        6525 :         nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 );
     471        6525 :         if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff, st_ivas->hDecoderConfig->Opt_tsm, st_ivas->hTcBuffer ) ) != IVAS_ERR_OK )
     472             :         {
     473           0 :             return error;
     474             :         }
     475             :     }
     476             : 
     477        7272 :     return IVAS_ERR_OK;
     478             : }
     479             : 
     480             : 
     481             : /*--------------------------------------------------------------------------*
     482             :  * ivas_set_surplus_brate_dec()
     483             :  *
     484             :  * set bit-rate surplus in combined format coding
     485             :  *--------------------------------------------------------------------------*/
     486             : 
     487      467186 : void ivas_set_surplus_brate_dec(
     488             :     Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
     489             :     int32_t *ism_total_brate /* i/o: ISM total bitrate      */
     490             : )
     491             : {
     492             :     int16_t n, bits_ism, bits_element[MAX_NUM_OBJECTS];
     493             :     int32_t ism_total_brate_ref, element_brate[MAX_NUM_OBJECTS];
     494             : 
     495      467186 :     *ism_total_brate = 0;
     496             : 
     497      467186 :     if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
     498             :     {
     499      119463 :         *ism_total_brate = ivas_interformat_brate( st_ivas->ism_mode, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 );
     500             : 
     501      119463 :         st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - *ism_total_brate;
     502             : 
     503             :         /* set 'st->total_brate'; there are no meta-data in ISM_MASA_MODE_PARAM_ONE_OBJ mode */
     504      119463 :         st_ivas->hSCE[0]->hCoreCoder[0]->total_brate = *ism_total_brate;
     505             : 
     506      119463 :         st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 0;
     507      119463 :         if ( st_ivas->hIsmMetaData[0]->ism_imp == ISM_NO_META )
     508             :         {
     509           0 :             st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 1;
     510             :         }
     511             :     }
     512      347723 :     else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
     513             :     {
     514             :         int16_t brate_limit_flag, ism_imp[MAX_NUM_OBJECTS];
     515             : 
     516     1100599 :         for ( n = 0; n < st_ivas->nchan_ism; n++ )
     517             :         {
     518      752876 :             ism_imp[n] = st_ivas->hIsmMetaData[n]->ism_imp;
     519             :         }
     520             : 
     521      347723 :         brate_limit_flag = calculate_brate_limit_flag( ism_imp, st_ivas->nchan_ism );
     522             : 
     523      347723 :         ism_total_brate_ref = 0;
     524     1100599 :         for ( n = 0; n < st_ivas->nchan_ism; n++ )
     525             :         {
     526      752876 :             ism_total_brate_ref += st_ivas->hSCE[n]->element_brate;
     527             :         }
     528             : 
     529      347723 :         bits_ism = (int16_t) ( ism_total_brate_ref / FRAMES_PER_SEC );
     530      347723 :         set_s( bits_element, bits_ism / st_ivas->nchan_ism, st_ivas->nchan_ism );
     531      347723 :         bits_element[st_ivas->nchan_ism - 1] += bits_ism % st_ivas->nchan_ism;
     532      347723 :         bitbudget_to_brate( bits_element, element_brate, st_ivas->nchan_ism );
     533             : 
     534      347723 :         *ism_total_brate = 0;
     535     1100599 :         for ( n = 0; n < st_ivas->nchan_ism; n++ )
     536             :         {
     537      752876 :             st_ivas->hSCE[n]->element_brate = element_brate[n];
     538             : 
     539      752876 :             *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp, brate_limit_flag );
     540             : 
     541      752876 :             if ( ism_imp[n] > 1 && st_ivas->flag_omasa_brate == 1 && brate_limit_flag >= 0 )
     542             :             {
     543        6939 :                 *ism_total_brate -= ADJUST_ISM_BRATE_NEG;
     544             :             }
     545             : 
     546      752876 :             if ( brate_limit_flag == -1 && ism_imp[n] >= 1 && st_ivas->nchan_ism >= 3 && ( ism_total_brate_ref - *ism_total_brate > IVAS_48k ) )
     547             :             {
     548           0 :                 *ism_total_brate += ADJUST_ISM_BRATE_POS;
     549             :             }
     550             :         }
     551      347723 :         st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - *ism_total_brate;
     552             : 
     553             :         /* 'st->total_brate' is set in ivas_ism_config */
     554             :     }
     555             :     else
     556             :     {
     557           0 :         st_ivas->hCPE[0]->brate_surplus = 0;
     558             :     }
     559             : 
     560      467186 :     return;
     561             : }
     562             : 
     563             : 
     564             : /*--------------------------------------------------------------------------*
     565             :  * ivas_omasa_ism_metadata_dec()
     566             :  *
     567             :  * decode ISM metadata in OMASA format
     568             :  *--------------------------------------------------------------------------*/
     569             : 
     570      467186 : ivas_error ivas_omasa_ism_metadata_dec(
     571             :     Decoder_Struct *st_ivas,             /* i/o: IVAS decoder structure            */
     572             :     const int32_t ism_total_brate,       /* i  : ISM total bitrate                 */
     573             :     int16_t *nchan_ism,                  /* o  : number of ISM separated channels  */
     574             :     int16_t *nchan_transport_ism,        /* o  : number of ISM TCs                 */
     575             :     const int16_t dirac_bs_md_write_idx, /* i  : DirAC bitstream write index       */
     576             :     int16_t nb_bits_metadata[]           /* o  : number of ISM metadata bits       */
     577             : )
     578             : {
     579             :     int16_t n, block;
     580             :     int16_t azimuth_ism, elevation_ism, meta_write_index;
     581             :     ivas_error error;
     582             : 
     583             :     /* set ISM parameters */
     584      467186 :     *nchan_ism = st_ivas->nchan_ism;
     585      467186 :     *nchan_transport_ism = st_ivas->nchan_ism;
     586      467186 :     if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
     587             :     {
     588       50367 :         *nchan_ism = 1;
     589       50367 :         *nchan_transport_ism = 1;
     590             :     }
     591      416819 :     else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
     592             :     {
     593       69096 :         *nchan_ism = 0;
     594       69096 :         *nchan_transport_ism = 1;
     595             :     }
     596             : 
     597      467186 :     if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
     598             :     {
     599             :         /* decode ISM metadata */
     600      398090 :         if ( ( error = ivas_ism_metadata_dec( ism_total_brate, *nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi,
     601      398090 :                                               nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK )
     602             :         {
     603           0 :             return error;
     604             :         }
     605             : 
     606      398090 :         if ( st_ivas->hDirAC != NULL )
     607             :         {
     608      349757 :             if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
     609             :             {
     610      962482 :                 for ( n = 0; n < st_ivas->nchan_ism; n++ )
     611             :                 {
     612      657572 :                     azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f );
     613      657572 :                     elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f );
     614             : 
     615     3287860 :                     for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
     616             :                     {
     617     2630288 :                         meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length;
     618     2630288 :                         st_ivas->hMasaIsmData->azimuth_ism[n][meta_write_index] = azimuth_ism;
     619     2630288 :                         st_ivas->hMasaIsmData->elevation_ism[n][meta_write_index] = elevation_ism;
     620             :                     }
     621             :                 }
     622             :             }
     623             :             else /* ISM_MASA_MODE_MASA_ONE_OBJ */
     624             :             {
     625       44847 :                 azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f );
     626       44847 :                 elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f );
     627             : 
     628      224235 :                 for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
     629             :                 {
     630      179388 :                     meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length;
     631      179388 :                     st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = azimuth_ism;
     632      179388 :                     st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = elevation_ism;
     633             :                 }
     634             :             }
     635             :         }
     636       48333 :         else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     637             :         {
     638        2484 :             azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f );
     639        2484 :             elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f );
     640             : 
     641        7452 :             for ( block = 0; block < 2; block++ )
     642             :             {
     643        4968 :                 st_ivas->hMasaIsmData->azimuth_separated_ism[block] = st_ivas->hMasaIsmData->azimuth_separated_ism[block + 2];
     644        4968 :                 st_ivas->hMasaIsmData->elevation_separated_ism[block] = st_ivas->hMasaIsmData->elevation_separated_ism[block + 2];
     645             :             }
     646        7452 :             for ( block = 2; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
     647             :             {
     648        4968 :                 st_ivas->hMasaIsmData->azimuth_separated_ism[block] = azimuth_ism;
     649        4968 :                 st_ivas->hMasaIsmData->elevation_separated_ism[block] = elevation_ism;
     650             :             }
     651             :         }
     652             :     }
     653             : 
     654      467186 :     return IVAS_ERR_OK;
     655             : }
     656             : 
     657             : 
     658             : /*--------------------------------------------------------------------------*
     659             :  * ivas_omasa_dirac_rend_jbm()
     660             :  *
     661             :  * Rendering in OMASA format for JBM
     662             :  *--------------------------------------------------------------------------*/
     663             : 
     664      225989 : void ivas_omasa_dirac_rend_jbm(
     665             :     Decoder_Struct *st_ivas,       /* i/o: IVAS decoder handle                      */
     666             :     const uint16_t nSamplesAsked,  /* i  : number of samples requested              */
     667             :     uint16_t *nSamplesRendered,    /* o  : number of samples rendered               */
     668             :     uint16_t *nSamplesAvailable,   /* o  : number of samples still to render        */
     669             :     const int16_t nchan_transport, /* i  : number of transport channels             */
     670             :     float *output_f[]              /* o  : rendered time signal                     */
     671             : )
     672             : {
     673             :     int16_t subframes_rendered;
     674             :     int16_t n;
     675             :     float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k];
     676             : 
     677      225989 :     *nSamplesRendered = min( nSamplesAsked, st_ivas->hTcBuffer->n_samples_available );
     678             : 
     679      225989 :     if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
     680             :     {
     681       58611 :         mvr2r( &output_f[CPE_CHANNELS][st_ivas->hTcBuffer->n_samples_rendered], data_separated_objects[0], *nSamplesRendered );
     682             : 
     683             : #ifdef NONBE_1399_1400_FIX_OBJ_EDIT_ISSUES
     684       58611 :         if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
     685             : #else
     686             :         if ( !st_ivas->hDecoderConfig->Opt_tsm && st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
     687             : #endif
     688             :         {
     689             :             /* Gain separated object, if edited */
     690      147894 :             for ( n = 0; n < st_ivas->nchan_ism; n++ )
     691             :             {
     692      113829 :                 if ( st_ivas->hMasaIsmData->ism_gain_is_edited[n] && st_ivas->hMasaIsmData->idx_separated_ism == n )
     693             :                 {
     694           0 :                     v_multc( data_separated_objects[0], st_ivas->hMasaIsmData->gain_ism_edited[n], data_separated_objects[0], *nSamplesRendered );
     695             :                 }
     696             :             }
     697             :         }
     698             :     }
     699             :     else
     700             :     {
     701      535325 :         for ( n = 0; n < st_ivas->nchan_ism; n++ )
     702             :         {
     703      367947 :             mvr2r( &output_f[n + CPE_CHANNELS][st_ivas->hTcBuffer->n_samples_rendered], data_separated_objects[n], *nSamplesRendered );
     704             : 
     705             :             /* Gain discrete objects, if edited */
     706             : #ifdef NONBE_1399_1400_FIX_OBJ_EDIT_ISSUES
     707      367947 :             if ( st_ivas->hMasaIsmData->ism_gain_is_edited[n] )
     708             : #else
     709             :             if ( !st_ivas->hDecoderConfig->Opt_tsm && st_ivas->hMasaIsmData->ism_gain_is_edited[n] )
     710             : #endif
     711             :             {
     712        2552 :                 v_multc( data_separated_objects[n], st_ivas->hMasaIsmData->gain_ism_edited[n], data_separated_objects[n], *nSamplesRendered );
     713             :             }
     714             :         }
     715             : 
     716             :         /* Gain MASA part, if edited in G192. MASA gaining with VOIP is done in ivas_dec_prepare_renderer() */
     717      167378 :         if ( !st_ivas->hDecoderConfig->Opt_tsm && st_ivas->hMasaIsmData->masa_gain_is_edited )
     718             :         {
     719           0 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     720             :             {
     721           0 :                 v_multc( output_f[n], st_ivas->hMasaIsmData->gain_masa_edited, output_f[n], *nSamplesRendered );
     722             :             }
     723             :         }
     724             :     }
     725             : 
     726      225989 :     subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered;
     727             : 
     728      225989 :     ivas_dirac_dec_render( st_ivas, nchan_transport, nSamplesAsked, nSamplesRendered, nSamplesAvailable, output_f );
     729             : 
     730      225989 :     ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered );
     731             : 
     732      225989 :     return;
     733             : }
     734             : 
     735             : 
     736             : /*--------------------------------------------------------------------------*
     737             :  * ivas_omasa_dirac_td_binaural_render()
     738             :  *
     739             :  * Binaural rendering in OMASA format for JBM
     740             :  *--------------------------------------------------------------------------*/
     741             : 
     742       69745 : ivas_error ivas_omasa_dirac_td_binaural_jbm(
     743             :     Decoder_Struct *st_ivas,       /* i/o: IVAS decoder handle                      */
     744             :     const uint16_t nSamplesAsked,  /* i  : number of samples requested              */
     745             :     uint16_t *nSamplesRendered,    /* o  : number of samples rendered               */
     746             :     uint16_t *nSamplesAvailable,   /* o  : number of samples still to render        */
     747             :     const int16_t nchan_transport, /* i  : number of transport channels             */
     748             :     float *output_f[]              /* o  : rendered time signal                     */
     749             : )
     750             : {
     751             :     int16_t n;
     752             :     float data_separated_objects[BINAURAL_CHANNELS][L_FRAME48k];
     753             :     ivas_error error;
     754             :     float *p_sepobj[BINAURAL_CHANNELS];
     755             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
     756             :     float *re, *im;
     757             : #else
     758             :     int16_t slot_idx_start;
     759             : 
     760             :     slot_idx_start = st_ivas->hSpatParamRendCom->slots_rendered;
     761             : #endif
     762             : 
     763      209235 :     for ( n = 0; n < BINAURAL_CHANNELS; n++ )
     764             :     {
     765      139490 :         p_sepobj[n] = &data_separated_objects[n][0];
     766             :     }
     767             : 
     768       69745 :     ivas_dirac_dec_binaural_render( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, nchan_transport, output_f );
     769             : 
     770             :     /* reset combined orientation access index before calling the td renderer */
     771       69745 :     ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     772             : 
     773       69745 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     774       36959 :     {
     775             :         int16_t slot_idx, num_cldfb_bands, nchan_transport_orig, cldfb_slots;
     776             :         float Cldfb_RealBuffer[CLDFB_NO_CHANNELS_MAX];
     777             :         float Cldfb_ImagBuffer[CLDFB_NO_CHANNELS_MAX];
     778             :         float *p_rend_obj[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS]; /* [8 * 2] */
     779             : 
     780      338421 :         for ( n = 0; n < st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS; n++ )
     781             :         {
     782      301462 :             p_rend_obj[n] = &output_f[n][0];
     783             :         }
     784             : 
     785       36959 :         num_cldfb_bands = st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[0]->no_channels;
     786       36959 :         nchan_transport_orig = st_ivas->nchan_transport;
     787       36959 :         st_ivas->nchan_transport = st_ivas->nchan_ism;
     788             : 
     789       36959 :         if ( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, p_rend_obj, *nSamplesRendered ) ) != IVAS_ERR_OK ) /* objects are read from st_ivas->hTcBuffer->tc[2..(1+n_isms)] */
     790             :         {
     791           0 :             return error;
     792             :         }
     793       36959 :         st_ivas->nchan_transport = nchan_transport_orig;
     794       36959 :         cldfb_slots = *nSamplesRendered / num_cldfb_bands;
     795             : 
     796      338421 :         for ( n = 0; n < st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS; ++n )
     797             :         {
     798     4174454 :             for ( slot_idx = 0; slot_idx < cldfb_slots; slot_idx++ )
     799             :             {
     800     3872992 :                 cldfbAnalysis_ts( &( p_rend_obj[n][num_cldfb_bands * slot_idx] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, num_cldfb_bands, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n] );
     801             : 
     802             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
     803     3872992 :                 ivas_CLDFB_RINGBUF_GetByIdx( st_ivas->hSplitBinRend->hMultiBinCldfbData[n], &re, &im, slot_idx - cldfb_slots );
     804     3872992 :                 v_add( re, Cldfb_RealBuffer, re, num_cldfb_bands );
     805     3872992 :                 v_add( im, Cldfb_ImagBuffer, im, num_cldfb_bands );
     806             : #else
     807             :                 v_add( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[n][slot_idx_start + slot_idx], Cldfb_RealBuffer, st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[n][slot_idx_start + slot_idx], num_cldfb_bands );
     808             :                 v_add( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[n][slot_idx_start + slot_idx], Cldfb_ImagBuffer, st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[n][slot_idx_start + slot_idx], num_cldfb_bands );
     809             : #endif
     810             :             }
     811             :         }
     812             :     }
     813             :     else
     814             :     {
     815       32786 :         if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK )
     816             :         {
     817           0 :             return error;
     818             :         }
     819             : 
     820       98358 :         for ( n = 0; n < BINAURAL_CHANNELS; n++ )
     821             :         {
     822       65572 :             v_add( output_f[n], p_sepobj[n], output_f[n], *nSamplesRendered );
     823             :         }
     824             :     }
     825             : 
     826       69745 :     return IVAS_ERR_OK;
     827             : }
     828             : 
     829             : 
     830             : /*--------------------------------------------------------------------------*
     831             :  * ivas_omasa_rearrange_channels()
     832             :  *
     833             :  * in case of external rendering, rearrange the channels order
     834             :  *--------------------------------------------------------------------------*/
     835             : 
     836       35823 : void ivas_omasa_rearrange_channels(
     837             :     float *output[],                   /* o  : output synthesis signal         */
     838             :     const int16_t nchan_transport_ism, /* o  : number of ISM TCs               */
     839             :     const int16_t output_frame         /* i  : output frame length per channel */
     840             : )
     841             : {
     842             :     int16_t n;
     843             :     float tmp_buff[CPE_CHANNELS][L_FRAME48k];
     844             : 
     845       35823 :     mvr2r( output[0], tmp_buff[0], output_frame );
     846       35823 :     mvr2r( output[1], tmp_buff[1], output_frame );
     847             : 
     848      125919 :     for ( n = 0; n < nchan_transport_ism; n++ )
     849             :     {
     850       90096 :         mvr2r( output[CPE_CHANNELS + n], output[n], output_frame );
     851             :     }
     852       35823 :     mvr2r( tmp_buff[0], output[n], output_frame );
     853       35823 :     mvr2r( tmp_buff[1], output[++n], output_frame );
     854             : 
     855       35823 :     return;
     856             : }
     857             : 
     858             : 
     859             : /*-------------------------------------------------------------------------*
     860             :  * ivas_omasa_combine_separate_ism_with_masa_open()
     861             :  *
     862             :  * Open structures, reserve memory, and init values.
     863             :  *-------------------------------------------------------------------------*/
     864             : 
     865         102 : ivas_error ivas_omasa_combine_separate_ism_with_masa_open(
     866             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
     867             : )
     868             : {
     869             :     int16_t i;
     870             :     int16_t interpolator_length;
     871             : 
     872         102 :     if ( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL )
     873             :     {
     874           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM renderer \n" ) );
     875             :     }
     876             : 
     877         510 :     for ( i = 0; i < MAX_NUM_OBJECTS; i++ )
     878             :     {
     879         408 :         set_zero( st_ivas->hIsmRendererData->prev_gains[i], MAX_OUTPUT_CHANNELS );
     880             :     }
     881             : 
     882         102 :     interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES );
     883         102 :     st_ivas->hIsmRendererData->interpolator = (float *) malloc( sizeof( float ) * interpolator_length );
     884             : 
     885       20742 :     for ( i = 0; i < interpolator_length; i++ )
     886             :     {
     887       20640 :         st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length );
     888             :     }
     889         102 :     st_ivas->hIsmRendererData->interpolator_length = interpolator_length;
     890             : 
     891         102 :     return IVAS_ERR_OK;
     892             : }
     893             : 
     894             : 
     895             : /*--------------------------------------------------------------------------*
     896             :  * ivas_omasa_combine_separate_ism_with_masa()
     897             :  *
     898             :  * in case of external rendering, combine separated ISM signal with MASA stream
     899             :  *--------------------------------------------------------------------------*/
     900             : 
     901        2484 : void ivas_omasa_combine_separate_ism_with_masa(
     902             :     Decoder_Struct *st_ivas,   /* i/o: IVAS decoder handle             */
     903             :     float *output[],           /* i/o: output synthesis signal         */
     904             :     const int16_t nchan_ism,   /* i  : number of ISMs                  */
     905             :     const int16_t output_frame /* i  : output frame length per channel */
     906             : )
     907             : {
     908             :     int16_t n, sf, band, bin, k;
     909             :     MASA_DECODER_EXT_OUT_META_HANDLE masaMetaHandle;
     910             :     MASA_DECODER_EXT_OUT_META_HANDLE ismMetaHandle;
     911             :     MASA_DECODER_EXT_OUT_META ismMeta;
     912             :     float eneMasa[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
     913             :     float eneIsm[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS];
     914             :     float inRe[3][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
     915             :     float inIm[3][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
     916             :     float azimuth, elevation;
     917             :     uint16_t directionIndex;
     918             :     float old_panning_gains[2];
     919             :     float new_panning_gains[2];
     920             :     float panned_signal[L_FRAME48k];
     921             :     int16_t nchan_in;
     922             :     int16_t nBins;
     923             :     int16_t slot;
     924             :     int16_t mrange[2], brange[2];
     925             :     int16_t processing_len, offset;
     926             :     float g1, g2;
     927             : 
     928        2484 :     masaMetaHandle = st_ivas->hMasa->data.extOutMeta;
     929        2484 :     ismMetaHandle = &ismMeta;
     930             : 
     931             :     /* Compute CLDFB analysis */
     932        2484 :     nchan_in = st_ivas->nchan_transport + 1;
     933        2484 :     nBins = output_frame / CLDFB_NO_COL_MAX;
     934       42228 :     for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
     935             :     {
     936      158976 :         for ( n = 0; n < nchan_in; n++ )
     937             :         {
     938      119232 :             cldfbAnalysis_ts(
     939      119232 :                 &( output[n][nBins * slot] ),
     940      119232 :                 inRe[n][slot],
     941      119232 :                 inIm[n][slot],
     942             :                 nBins, st_ivas->cldfbAnaDec[n] );
     943             :         }
     944             :     }
     945             : 
     946             :     /* Determine energies */
     947       12420 :     for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
     948             :     {
     949        9936 :         mrange[0] = st_ivas->hMasa->config.block_grouping[sf];
     950        9936 :         mrange[1] = st_ivas->hMasa->config.block_grouping[sf + 1];
     951             : 
     952        9936 :         set_zero( eneMasa[sf], MASA_FREQUENCY_BANDS );
     953        9936 :         set_zero( eneIsm[sf], MASA_FREQUENCY_BANDS );
     954             : 
     955       49680 :         for ( slot = mrange[0]; slot < mrange[1]; slot++ )
     956             :         {
     957      993600 :             for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
     958             :             {
     959      953856 :                 brange[0] = st_ivas->hMasa->config.band_grouping[band];
     960      953856 :                 brange[1] = st_ivas->hMasa->config.band_grouping[band + 1];
     961             : 
     962      953856 :                 if ( brange[1] > nBins )
     963             :                 {
     964       63360 :                     brange[1] = nBins;
     965             :                 }
     966             : 
     967     2861568 :                 for ( n = 0; n < MASA_MAX_TRANSPORT_CHANNELS; n++ )
     968             :                 {
     969     5156352 :                     for ( bin = brange[0]; bin < brange[1]; bin++ )
     970             :                     {
     971     3248640 :                         eneMasa[sf][band] += inRe[n][slot][bin] * inRe[n][slot][bin] + inIm[n][slot][bin] * inIm[n][slot][bin];
     972             :                     }
     973             :                 }
     974     2578176 :                 for ( bin = brange[0]; bin < brange[1]; bin++ )
     975             :                 {
     976     1624320 :                     eneIsm[sf][band] += inRe[MASA_MAX_TRANSPORT_CHANNELS][slot][bin] * inRe[MASA_MAX_TRANSPORT_CHANNELS][slot][bin] + inIm[MASA_MAX_TRANSPORT_CHANNELS][slot][bin] * inIm[MASA_MAX_TRANSPORT_CHANNELS][slot][bin];
     977             :                 }
     978             :             }
     979             :         }
     980             :     }
     981             : 
     982             :     /* Determine MASA metadata for the object */
     983        2484 :     ismMetaHandle->descriptiveMeta.numberOfDirections = 0u;
     984       12420 :     for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
     985             :     {
     986        9936 :         azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism[sf];
     987        9936 :         elevation = st_ivas->hMasaIsmData->elevation_separated_ism[sf];
     988             : 
     989        9936 :         directionIndex = index_theta_phi_16( &elevation, &azimuth, st_ivas->hMasa->data.sph_grid16 );
     990             : 
     991      248400 :         for ( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
     992             :         {
     993      238464 :             ismMetaHandle->directionIndex[0][sf][band] = directionIndex;
     994      238464 :             ismMetaHandle->directToTotalRatio[0][sf][band] = UINT8_MAX;
     995      238464 :             ismMetaHandle->spreadCoherence[0][sf][band] = 0;
     996      238464 :             ismMetaHandle->surroundCoherence[sf][band] = 0;
     997      238464 :             ismMetaHandle->diffuseToTotalRatio[sf][band] = 0;
     998             :         }
     999             :     }
    1000             : 
    1001             :     /* Merge MASA metadatas */
    1002        2484 :     ivas_prerend_merge_masa_metadata( masaMetaHandle, masaMetaHandle, IVAS_REND_AUDIO_CONFIG_TYPE_MASA, eneMasa, ismMetaHandle, IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED, eneIsm );
    1003             : 
    1004             :     /* Mix the separated object audio signal to the MASA audio signals */
    1005        2484 :     ivas_get_stereo_panning_gains( st_ivas->hMasaIsmData->azimuth_separated_ism[0], st_ivas->hMasaIsmData->elevation_separated_ism[0], old_panning_gains );
    1006        2484 :     ivas_get_stereo_panning_gains( st_ivas->hMasaIsmData->azimuth_separated_ism[2], st_ivas->hMasaIsmData->elevation_separated_ism[2], new_panning_gains );
    1007             : 
    1008        2484 :     processing_len = output_frame / 2;
    1009        7452 :     for ( n = 0; n < MASA_MAX_TRANSPORT_CHANNELS; n++ )
    1010             :     {
    1011        4968 :         v_multc( output[MASA_MAX_TRANSPORT_CHANNELS], old_panning_gains[n], panned_signal, processing_len );
    1012        4968 :         v_add( output[n], panned_signal, output[n], processing_len );
    1013             :     }
    1014        2484 :     offset = processing_len;
    1015             : 
    1016        2484 :     processing_len = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES;
    1017        7452 :     for ( n = 0; n < MASA_MAX_TRANSPORT_CHANNELS; n++ )
    1018             :     {
    1019      817128 :         for ( k = 0; k < processing_len; k++ )
    1020             :         {
    1021      812160 :             g1 = st_ivas->hIsmRendererData->interpolator[k];
    1022      812160 :             g2 = 1.0f - g1;
    1023      812160 :             output[n][k + offset] += ( g1 * new_panning_gains[n] + g2 * old_panning_gains[n] ) * output[MASA_MAX_TRANSPORT_CHANNELS][k + offset];
    1024             :         }
    1025             :     }
    1026        2484 :     offset += processing_len;
    1027             : 
    1028        7452 :     for ( n = 0; n < MASA_MAX_TRANSPORT_CHANNELS; n++ )
    1029             :     {
    1030        4968 :         v_multc( &output[MASA_MAX_TRANSPORT_CHANNELS][offset], new_panning_gains[n], panned_signal, processing_len );
    1031        4968 :         v_add( &output[n][offset], panned_signal, &output[n][offset], processing_len );
    1032             :     }
    1033             : 
    1034             :     /* Zero output object channels */
    1035       11232 :     for ( n = 0; n < nchan_ism; n++ )
    1036             :     {
    1037        8748 :         set_zero( output[MASA_MAX_TRANSPORT_CHANNELS + n], output_frame );
    1038             :     }
    1039             : 
    1040        2484 :     return;
    1041             : }
    1042             : 
    1043             : 
    1044             : /*-------------------------------------------------------------------------*
    1045             :  * ivas_omasa_objects_delay_open()
    1046             :  *
    1047             :  * Open structures, reserve memory, and init values for dela buffers of objects.
    1048             :  *-------------------------------------------------------------------------*/
    1049             : 
    1050        7156 : ivas_error ivas_omasa_objects_delay_open(
    1051             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
    1052             : )
    1053             : {
    1054             :     int16_t i;
    1055             : 
    1056        7156 :     if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
    1057             :     {
    1058        2061 :         st_ivas->hMasaIsmData->delayBuffer_nchan = 1;
    1059             :     }
    1060             :     else
    1061             :     {
    1062        5095 :         st_ivas->hMasaIsmData->delayBuffer_nchan = st_ivas->nchan_ism;
    1063             :     }
    1064             : 
    1065        7156 :     st_ivas->hMasaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES );
    1066             : 
    1067        7156 :     if ( ( st_ivas->hMasaIsmData->delayBuffer = (float **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL )
    1068             :     {
    1069           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) );
    1070             :     }
    1071             : 
    1072       21193 :     for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ )
    1073             :     {
    1074       14037 :         if ( ( st_ivas->hMasaIsmData->delayBuffer[i] = (float *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL )
    1075             :         {
    1076           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) );
    1077             :         }
    1078       14037 :         set_zero( st_ivas->hMasaIsmData->delayBuffer[i], st_ivas->hMasaIsmData->delayBuffer_size );
    1079             :     }
    1080             : 
    1081        7156 :     return IVAS_ERR_OK;
    1082             : }
    1083             : 
    1084             : 
    1085             : /*--------------------------------------------------------------------------*
    1086             :  * ivas_omasa_render_objects_from_mix()
    1087             :  *
    1088             :  * In case of external rendering, render objects from the transport signal
    1089             :  * mix containing MASA audio and object audio.
    1090             :  *--------------------------------------------------------------------------*/
    1091             : 
    1092        3984 : void ivas_omasa_render_objects_from_mix(
    1093             :     Decoder_Struct *st_ivas,   /* i/o: IVAS decoder handle             */
    1094             :     float *output[],           /* o  : output synthesis signal         */
    1095             :     const int16_t nchan_ism,   /* i  : number of ISMs                  */
    1096             :     const int16_t output_frame /* i  : output frame length per channel */
    1097             : )
    1098             : {
    1099             :     int16_t n, m, i;
    1100             :     MASA_ISM_EXT_DATA_HANDLE hExtData;
    1101             :     float separated_object[L_FRAME48k];
    1102             :     float rendered_objects[MAX_NUM_OBJECTS][L_FRAME48k];
    1103             :     int16_t coding_delay;
    1104             :     float new_panning_gains[2];
    1105             :     float panning_gains[2];
    1106             :     float azimuth, elevation;
    1107             :     float inRe[3][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1108             :     float inIm[3][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1109             :     float outRe[MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1110             :     float outIm[MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1111             :     float ism_proto_energy[MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1112             :     float transport_energy[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1113             :     float ism_target_energy[MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1114             :     float masa_target_energy[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1115             :     float ism_processing_gains[MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1116             :     float masa_processing_gains[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1117             :     int16_t slot;
    1118             :     int16_t sf;
    1119             :     int16_t bin;
    1120             :     int16_t nchan_transport;
    1121             :     int16_t nBins;
    1122             :     float interpVal;
    1123             :     float *outSlotRePr, *outSlotImPr;
    1124             :     int16_t md_idx;
    1125             :     float iir_factor_prev, iir_factor_curr;
    1126             : 
    1127             :     /* Create slot to metadata map */
    1128       19920 :     for ( sf = 0, slot = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
    1129             :     {
    1130       79680 :         for ( i = 0; i < CLDFB_SLOTS_PER_SUBFRAME; i++, slot++ )
    1131             :         {
    1132       63744 :             st_ivas->hSpatParamRendCom->render_to_md_map[slot] = st_ivas->hSpatParamRendCom->dirac_read_idx;
    1133             :         }
    1134       15936 :         st_ivas->hSpatParamRendCom->dirac_read_idx = ( st_ivas->hSpatParamRendCom->dirac_read_idx + 1 ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length;
    1135             :     }
    1136             : 
    1137             :     /* Move separated object signal and object channels */
    1138        3984 :     mvr2r( output[CPE_CHANNELS], separated_object, output_frame );
    1139       16944 :     for ( n = 0; n < nchan_ism; n++ )
    1140             :     {
    1141       12960 :         set_zero( output[CPE_CHANNELS + n], output_frame );
    1142             :     }
    1143             : 
    1144             :     /* Delay the separated object signal by the CLDFB delay */
    1145        3984 :     delay_signal( separated_object, output_frame, st_ivas->hMasaIsmData->delayBuffer[0], st_ivas->hMasaIsmData->delayBuffer_size );
    1146             : 
    1147             :     /* Set object metadata to the ism struct */
    1148       16944 :     for ( n = 0; n < nchan_ism; n++ )
    1149             :     {
    1150       12960 :         st_ivas->hIsmMetaData[n]->azimuth = st_ivas->hMasaIsmData->azimuth_ism[n][st_ivas->hSpatParamRendCom->dirac_read_idx];
    1151       12960 :         st_ivas->hIsmMetaData[n]->elevation = st_ivas->hMasaIsmData->elevation_ism[n][st_ivas->hSpatParamRendCom->dirac_read_idx];
    1152             :     }
    1153             : 
    1154             :     /* Move the separated object signal to the correct output channel */
    1155        3984 :     hExtData = st_ivas->hMasaIsmData->hExtData;
    1156        3984 :     coding_delay = output_frame / 20 * 17; /* 17 ms of coding and CLDFB delay */
    1157        3984 :     mvr2r( separated_object, output[CPE_CHANNELS + hExtData->prev_idx_separated_ism], coding_delay );
    1158        3984 :     mvr2r( &separated_object[coding_delay], &output[CPE_CHANNELS + st_ivas->hMasaIsmData->idx_separated_ism][coding_delay], output_frame - coding_delay );
    1159             : 
    1160             :     /* Compute CLDFB analysis */
    1161        3984 :     nchan_transport = st_ivas->nchan_transport;
    1162        3984 :     nBins = output_frame / CLDFB_NO_COL_MAX;
    1163       67728 :     for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1164             :     {
    1165      191232 :         for ( n = 0; n < nchan_transport; n++ )
    1166             :         {
    1167      127488 :             cldfbAnalysis_ts(
    1168      127488 :                 &( output[n][nBins * slot] ),
    1169      127488 :                 inRe[n][slot],
    1170      127488 :                 inIm[n][slot],
    1171             :                 nBins, st_ivas->cldfbAnaDec[n] );
    1172             :         }
    1173             :     }
    1174             : 
    1175             :     /* Create prototype signals */
    1176       16944 :     for ( n = 0; n < nchan_ism; n++ )
    1177             :     {
    1178       12960 :         azimuth = (float) st_ivas->hIsmMetaData[n]->azimuth;
    1179       12960 :         elevation = (float) st_ivas->hIsmMetaData[n]->elevation;
    1180       12960 :         ivas_get_stereo_panning_gains( azimuth, elevation, new_panning_gains );
    1181       12960 :         interpVal = 0.0f;
    1182             : 
    1183      220320 :         for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1184             :         {
    1185      207360 :             interpVal += 1.0f / (float) CLDFB_NO_COL_MAX;
    1186      622080 :             for ( m = 0; m < 2; m++ )
    1187             :             {
    1188      414720 :                 panning_gains[m] = ( 1.0f - interpVal ) * hExtData->prev_panning_gains[n][m] + interpVal * new_panning_gains[m];
    1189             :             }
    1190      207360 :             v_multc( inRe[0][slot], panning_gains[0], outRe[n][slot], nBins );
    1191      207360 :             v_multc( inIm[0][slot], panning_gains[0], outIm[n][slot], nBins );
    1192      207360 :             v_multc_acc( inRe[1][slot], panning_gains[1], outRe[n][slot], nBins );
    1193      207360 :             v_multc_acc( inIm[1][slot], panning_gains[1], outIm[n][slot], nBins );
    1194             :         }
    1195             : 
    1196       38880 :         for ( m = 0; m < 2; m++ )
    1197             :         {
    1198       25920 :             hExtData->prev_panning_gains[n][m] = new_panning_gains[m];
    1199             :         }
    1200             :     }
    1201             : 
    1202             :     /* Determine prototype energy */
    1203       16944 :     for ( n = 0; n < nchan_ism; n++ )
    1204             :     {
    1205      220320 :         for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1206             :         {
    1207     8847360 :             for ( bin = 0; bin < nBins; bin++ )
    1208             :             {
    1209     8640000 :                 ism_proto_energy[n][slot][bin] = ( outRe[n][slot][bin] * outRe[n][slot][bin] ) + ( outIm[n][slot][bin] * outIm[n][slot][bin] );
    1210             :             }
    1211             :         }
    1212             :     }
    1213             : 
    1214             :     /* Determine transport energy */
    1215       67728 :     for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1216             :     {
    1217       63744 :         set_zero( transport_energy[slot], nBins );
    1218             :     }
    1219       11952 :     for ( n = 0; n < CPE_CHANNELS; n++ )
    1220             :     {
    1221      135456 :         for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1222             :         {
    1223     5495808 :             for ( bin = 0; bin < nBins; bin++ )
    1224             :             {
    1225     5368320 :                 transport_energy[slot][bin] += ( inRe[n][slot][bin] * inRe[n][slot][bin] ) + ( inIm[n][slot][bin] * inIm[n][slot][bin] );
    1226             :             }
    1227             :         }
    1228             :     }
    1229             : 
    1230             :     /* Determine target energy */
    1231       16944 :     for ( n = 0; n < nchan_ism; n++ )
    1232             :     {
    1233      220320 :         for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1234             :         {
    1235      207360 :             md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[slot];
    1236     8847360 :             for ( bin = 0; bin < nBins; bin++ )
    1237             :             {
    1238     8640000 :                 ism_target_energy[n][slot][bin] = transport_energy[slot][bin] * st_ivas->hMasaIsmData->energy_ratio_ism[n][md_idx][bin];
    1239             :             }
    1240             :         }
    1241             :     }
    1242       67728 :     for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1243             :     {
    1244       63744 :         md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[slot];
    1245     2747904 :         for ( bin = 0; bin < nBins; bin++ )
    1246             :         {
    1247     2684160 :             masa_target_energy[slot][bin] = transport_energy[slot][bin] * hExtData->masa_render_masa_to_total[md_idx][bin];
    1248             :         }
    1249             :     }
    1250             : 
    1251             :     /* Determine temporally smoothed energies and determine gains using them */
    1252        3984 :     iir_factor_curr = ( 1.0f - EXT_RENDER_IIR_FAC );
    1253        3984 :     iir_factor_prev = EXT_RENDER_IIR_FAC;
    1254       16944 :     for ( n = 0; n < nchan_ism; n++ )
    1255             :     {
    1256      220320 :         for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1257             :         {
    1258     8847360 :             for ( bin = 0; bin < nBins; bin++ )
    1259             :             {
    1260     8640000 :                 hExtData->ism_render_proto_energy[n][bin] *= iir_factor_prev;
    1261     8640000 :                 hExtData->ism_render_proto_energy[n][bin] += iir_factor_curr * ism_proto_energy[n][slot][bin];
    1262     8640000 :                 hExtData->ism_render_target_energy[n][bin] *= iir_factor_prev;
    1263     8640000 :                 hExtData->ism_render_target_energy[n][bin] += iir_factor_curr * ism_target_energy[n][slot][bin];
    1264             : 
    1265     8640000 :                 ism_processing_gains[n][slot][bin] = fminf( 4.0f, sqrtf( hExtData->ism_render_target_energy[n][bin] / fmaxf( 1e-12f, hExtData->ism_render_proto_energy[n][bin] ) ) );
    1266             :             }
    1267             :         }
    1268             :     }
    1269       67728 :     for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1270             :     {
    1271     2747904 :         for ( bin = 0; bin < nBins; bin++ )
    1272             :         {
    1273     2684160 :             hExtData->masa_render_proto_energy[bin] *= iir_factor_prev;
    1274     2684160 :             hExtData->masa_render_proto_energy[bin] += iir_factor_curr * transport_energy[slot][bin];
    1275     2684160 :             hExtData->masa_render_target_energy[bin] *= iir_factor_prev;
    1276     2684160 :             hExtData->masa_render_target_energy[bin] += iir_factor_curr * masa_target_energy[slot][bin];
    1277             : 
    1278     2684160 :             masa_processing_gains[slot][bin] = fminf( 4.0f, sqrtf( hExtData->masa_render_target_energy[bin] / fmaxf( 1e-12f, hExtData->masa_render_proto_energy[bin] ) ) );
    1279             :         }
    1280             :     }
    1281             : 
    1282             :     /* Determine output signals */
    1283       16944 :     for ( n = 0; n < nchan_ism; n++ )
    1284             :     {
    1285      220320 :         for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1286             :         {
    1287     8847360 :             for ( bin = 0; bin < nBins; bin++ )
    1288             :             {
    1289     8640000 :                 outRe[n][slot][bin] *= ism_processing_gains[n][slot][bin];
    1290     8640000 :                 outIm[n][slot][bin] *= ism_processing_gains[n][slot][bin];
    1291             :             }
    1292             :         }
    1293             :     }
    1294       11952 :     for ( n = 0; n < MASA_MAX_TRANSPORT_CHANNELS; n++ )
    1295             :     {
    1296      135456 :         for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1297             :         {
    1298     5495808 :             for ( bin = 0; bin < nBins; bin++ )
    1299             :             {
    1300     5368320 :                 inRe[n][slot][bin] *= masa_processing_gains[slot][bin];
    1301     5368320 :                 inIm[n][slot][bin] *= masa_processing_gains[slot][bin];
    1302             :             }
    1303             :         }
    1304             :     }
    1305             : 
    1306             :     /* Compute CLDFB synthesis */
    1307       67728 :     for ( slot = 0; slot < CLDFB_NO_COL_MAX; slot++ )
    1308             :     {
    1309      191232 :         for ( n = 0; n < nchan_transport; n++ )
    1310             :         {
    1311      127488 :             outSlotRePr = &( inRe[n][slot][0] );
    1312      127488 :             outSlotImPr = &( inIm[n][slot][0] );
    1313      127488 :             cldfbSynthesis( &outSlotRePr, &outSlotImPr, &( output[n][nBins * slot] ), nBins, st_ivas->cldfbSynDec[n] );
    1314             :         }
    1315             : 
    1316      271104 :         for ( n = 0; n < nchan_ism; n++ )
    1317             :         {
    1318      207360 :             outSlotRePr = &( outRe[n][slot][0] );
    1319      207360 :             outSlotImPr = &( outIm[n][slot][0] );
    1320      207360 :             cldfbSynthesis( &outSlotRePr, &outSlotImPr, &( rendered_objects[n][nBins * slot] ), nBins, st_ivas->cldfbSynDec[n + CPE_CHANNELS] );
    1321             :         }
    1322             :     }
    1323             : 
    1324             :     /* Combine the rendered objects with the separated objects */
    1325       16944 :     for ( n = 0; n < nchan_ism; n++ )
    1326             :     {
    1327       12960 :         v_add( output[CPE_CHANNELS + n], rendered_objects[n], output[CPE_CHANNELS + n], output_frame );
    1328             :     }
    1329             : 
    1330        3984 :     hExtData->prev_idx_separated_ism = st_ivas->hMasaIsmData->idx_separated_ism;
    1331             : 
    1332        3984 :     return;
    1333             : }
    1334             : 
    1335             : 
    1336             : /*--------------------------------------------------------------------------*
    1337             :  * ivas_omasa_gain_masa_tc()
    1338             :  *
    1339             :  * in case of external rendering with object editing, MASA transport channels
    1340             :  * need to be gained
    1341             :  *--------------------------------------------------------------------------*/
    1342             : 
    1343           0 : void ivas_omasa_gain_masa_tc(
    1344             :     float *output[],                   /* i/o: output synthesis signal         */
    1345             :     const float gainMasa,              /* i  : gain                            */
    1346             :     const int16_t nchan_transport_ism, /* i  : number of ISM TCs               */
    1347             :     const int16_t output_frame         /* i  : output frame length per channel */
    1348             : )
    1349             : {
    1350             :     /* Edited OMASA EXT MASA transport gaining */
    1351           0 :     for ( int16_t ch = 0; ch < CPE_CHANNELS; ch++ )
    1352             :     {
    1353           0 :         v_multc( output[nchan_transport_ism + ch], gainMasa, output[nchan_transport_ism + ch], output_frame );
    1354             :     }
    1355             : 
    1356           0 :     return;
    1357             : }

Generated by: LCOV version 1.14