LCOV - code coverage report
Current view: top level - lib_dec - ivas_ism_param_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 867217ee32c8e8cd2cf5aae69e60c58e00160b49 Lines: 457 477 95.8 %
Date: 2025-12-15 05:59:49 Functions: 19 19 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <stdint.h>
      34             : #include <assert.h>
      35             : #include <math.h>
      36             : #include "options.h"
      37             : #include "ivas_prot.h"
      38             : #include "ivas_prot_rend.h"
      39             : #include "prot.h"
      40             : #include "ivas_rom_com.h"
      41             : #include "ivas_rom_dec.h"
      42             : #ifdef DEBUGGING
      43             : #include "debug.h"
      44             : #endif
      45             : #include "wmc_auto.h"
      46             : 
      47             : 
      48             : /*-----------------------------------------------------------------------*
      49             :  * Local function declarations
      50             :  *-----------------------------------------------------------------------*/
      51             : 
      52             : static void ivas_ism_param_dec_tc_gain_adjust( Decoder_Struct *st_ivas, const int16_t nSamples, const int16_t nFadeLength, float *p_data_f[] );
      53             : 
      54             : /*-----------------------------------------------------------------------*
      55             :  * Local function definitions
      56             :  *-----------------------------------------------------------------------*/
      57             : 
      58      148488 : static void ivas_param_ism_dec_dequant_DOA(
      59             :     PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle      */
      60             :     const int16_t nchan_ism            /* i  : number of ISM channels       */
      61             : )
      62             : {
      63             :     int16_t i;
      64             :     PARAM_ISM_CONFIG_HANDLE hParamIsm;
      65             : 
      66      148488 :     hParamIsm = hParamIsmDec->hParamIsm;
      67             : 
      68      148488 :     assert( nchan_ism <= MAX_NUM_OBJECTS );
      69             : 
      70             :     /* Get the azimuth and elevation values */
      71      676503 :     for ( i = 0; i < nchan_ism; i++ )
      72             :     {
      73      528015 :         hParamIsmDec->azimuth_values[i] = ism_dequant_meta( hParamIsm->azi_index[i], ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS );
      74      528015 :         hParamIsmDec->elevation_values[i] = ism_dequant_meta( hParamIsm->ele_index[i], ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS );
      75             :     }
      76             : 
      77      148488 :     return;
      78             : }
      79             : 
      80             : 
      81      148488 : static void ivas_param_ism_dec_dequant_powrat(
      82             :     PARAM_ISM_DEC_HANDLE hParamIsmDec /* i/o: decoder ParamISM handle         */
      83             : )
      84             : {
      85             :     int16_t band_idx, slot_idx;
      86             :     PARAM_ISM_CONFIG_HANDLE hParamIsm;
      87             : 
      88      148488 :     hParamIsm = hParamIsmDec->hParamIsm;
      89             : 
      90             :     /* Get the power ratio values */
      91     1781856 :     for ( band_idx = 0; band_idx < hParamIsm->nbands; band_idx++ )
      92             :     {
      93     3266736 :         for ( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ )
      94             :         {
      95     1633368 :             hParamIsmDec->power_ratios[band_idx][slot_idx][0] = (float) ( hParamIsm->power_ratios_idx[band_idx][slot_idx] ) / (float) ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) / 2.0f + 0.5f;
      96     1633368 :             hParamIsmDec->power_ratios[band_idx][slot_idx][1] = 1.0f - hParamIsmDec->power_ratios[band_idx][slot_idx][0];
      97             :         }
      98             :     }
      99             : 
     100      148488 :     return;
     101             : }
     102             : 
     103             : 
     104        2670 : static void ivas_ism_get_interpolator(
     105             :     const int16_t subframe_nbslots,
     106             :     float *interpolator )
     107             : {
     108        2670 :     int16_t interp_idx = 0;
     109             : 
     110       65646 :     for ( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ )
     111             :     {
     112       62976 :         interpolator[interp_idx] = (float) ( interp_idx + 1 ) / (float) subframe_nbslots;
     113             :     }
     114             : 
     115        2670 :     return;
     116             : }
     117             : 
     118             : 
     119        1034 : static void ivas_ism_get_proto_matrix(
     120             :     IVAS_OUTPUT_SETUP hOutSetup,
     121             :     const int16_t nchan_transport,
     122             :     float *proto_matrix )
     123             : {
     124             :     int16_t idx;
     125             : 
     126             :     /* compute proto_matrix */
     127        1034 :     switch ( nchan_transport )
     128             :     {
     129        1034 :         case 2:
     130             :         {
     131        1034 :             if ( hOutSetup.nchan_out_woLFE )
     132             :             {
     133       10460 :                 for ( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ )
     134             :                 {
     135        9426 :                     if ( hOutSetup.ls_azimuth[idx] > 0.0f )
     136             :                     {
     137        4196 :                         proto_matrix[idx] = 1.0f;
     138        4196 :                         proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.0f;
     139             :                     }
     140        5230 :                     else if ( hOutSetup.ls_azimuth[idx] < 0.0f )
     141             :                     {
     142        4196 :                         proto_matrix[idx] = 0.0f;
     143        4196 :                         proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 1.0f;
     144             :                     }
     145             :                     else
     146             :                     {
     147        1034 :                         proto_matrix[idx] = 0.5f;
     148        1034 :                         proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.5f;
     149             :                     }
     150             :                 }
     151             :             }
     152             :             else
     153             :             {
     154           0 :                 assert( 0 && "Error: number of output channels not supported" );
     155             :             }
     156        1034 :             break;
     157             :         }
     158             : 
     159           0 :         default:
     160           0 :             assert( 0 && "Error: number of transport channels not supported" );
     161             :     }
     162             : 
     163        1034 :     return;
     164             : }
     165             : 
     166             : 
     167     2218188 : static void ivas_param_ism_collect_slot(
     168             :     PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */
     169             :     float *Cldfb_RealBuffer_in,
     170             :     float *Cldfb_ImagBuffer_in,
     171             :     const int16_t ch,
     172             :     float ref_power[],
     173             :     float cx_diag[][PARAM_ISM_MAX_DMX] )
     174             : {
     175             : 
     176             :     int16_t band_idx, bin_idx;
     177             :     int16_t brange[2];
     178             :     float tmp;
     179             : 
     180             :     /* loop over parameter bands to collect transport channel energies */
     181    26618256 :     for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
     182             :     {
     183    24400068 :         brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
     184    24400068 :         brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
     185   127493268 :         for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
     186             :         {
     187   103093200 :             tmp = 0.0f;
     188   103093200 :             tmp += ( Cldfb_RealBuffer_in[bin_idx] * Cldfb_RealBuffer_in[bin_idx] );
     189   103093200 :             tmp += ( Cldfb_ImagBuffer_in[bin_idx] * Cldfb_ImagBuffer_in[bin_idx] );
     190   103093200 :             cx_diag[bin_idx][ch] += tmp;
     191   103093200 :             ref_power[bin_idx] += tmp;
     192             :         }
     193             :     }
     194             : 
     195     2218188 :     return;
     196             : }
     197             : 
     198             : 
     199       69318 : static void ivas_param_ism_compute_mixing_matrix(
     200             :     const int16_t nchan_ism,           /* i  : number of ISM channels       */
     201             :     PARAM_ISM_DEC_HANDLE hParamIsmDec, /* i/o: decoder ParamISM handle */
     202             :     ISM_DTX_DATA_DEC hISMDTX,          /* i  : ISM DTX handle                */
     203             :     float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN],
     204             :     const int16_t nchan_transport,
     205             :     const int16_t nchan_out_woLFE,
     206             :     float cx_diag[][PARAM_ISM_MAX_DMX],
     207             :     float ref_power[],
     208             :     float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX] )
     209             : {
     210             :     int16_t band_idx, bin_idx;
     211             :     int16_t i, w, obj_indx;
     212             :     int16_t brange[2];
     213             :     float direct_power[MAX_NUM_OBJECTS];
     214             :     float cy_diag[PARAM_ISM_MAX_CHAN];
     215             :     float cy_diag_tmp[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN];
     216             :     float *dir_res_ptr;
     217             :     float *proto_matrix;
     218             :     float response_matrix[PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS];
     219             :     int16_t num_wave;
     220             : 
     221       69318 :     proto_matrix = hParamIsmDec->hParamIsmRendering->proto_matrix;
     222             : 
     223       69318 :     assert( ( nchan_ism == 3 ) || ( nchan_ism == 4 ) );
     224       69318 :     assert( nchan_transport == 2 );
     225             : 
     226       69318 :     if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
     227             :     {
     228         634 :         num_wave = nchan_ism;
     229             :     }
     230             :     else
     231             :     {
     232       68684 :         num_wave = MAX_PARAM_ISM_WAVE;
     233             :     }
     234       69318 :     set_zero( response_matrix, PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS );
     235             : 
     236             :     /* loop over parameter bands to compute the mixing matrix */
     237      831816 :     for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
     238             :     {
     239      762498 :         brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
     240      762498 :         brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
     241             : 
     242             :         /* Compute covaraince matrix from direct response*/
     243     2301442 :         for ( w = 0; w < num_wave; w++ )
     244             :         {
     245     1538944 :             set_zero( cy_diag_tmp[w], nchan_out_woLFE );
     246             : 
     247     1538944 :             if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
     248             :             {
     249       27896 :                 dir_res_ptr = direct_response[w];
     250             :             }
     251             :             else
     252             :             {
     253     1511048 :                 obj_indx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][w];
     254     1511048 :                 dir_res_ptr = direct_response[obj_indx];
     255             :             }
     256     1538944 :             mvr2r( dir_res_ptr, response_matrix + w * nchan_out_woLFE, nchan_out_woLFE );
     257             :             /* we only need the diagonal of Cy*/
     258     1538944 :             matrix_product_diag( dir_res_ptr, nchan_out_woLFE, 1, 0, dir_res_ptr, 1, nchan_out_woLFE, 0, cy_diag_tmp[w] );
     259             :         }
     260             : 
     261     3984138 :         for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
     262             :         {
     263             : 
     264     3221640 :             set_zero( cy_diag, nchan_out_woLFE );
     265     9741000 :             for ( w = 0; w < num_wave; w++ )
     266             :             {
     267     6519360 :                 if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
     268             :                 {
     269      152160 :                     direct_power[w] = ( 1.0f / nchan_ism ) * ref_power[bin_idx];
     270             :                 }
     271             :                 else
     272             :                 {
     273     6367200 :                     direct_power[w] = hParamIsmDec->power_ratios[band_idx][0][w] * ref_power[bin_idx];
     274             :                 }
     275             : 
     276     6519360 :                 if ( direct_power[w] != 0.f )
     277             :                 {
     278    53041837 :                     for ( i = 0; i < nchan_out_woLFE; i++ )
     279             :                     {
     280    47716846 :                         cy_diag[i] += direct_power[w] * cy_diag_tmp[w][i];
     281             :                     }
     282             :                 }
     283     6519360 :                 direct_power[w] = sqrtf( direct_power[w] );
     284             :             }
     285             : 
     286             :             /* Compute mixing matrix */
     287     3221640 :             computeMixingMatricesISM( nchan_transport, num_wave, nchan_out_woLFE, response_matrix, direct_power, cx_diag[bin_idx], cy_diag, proto_matrix, 1,
     288     3221640 :                                       PARAM_MC_REG_SX, PARAM_MC_REG_GHAT, mixing_matrix[bin_idx] );
     289             :         }
     290             :     }
     291             : 
     292       69318 :     return;
     293             : }
     294             : 
     295             : 
     296     1109094 : static void ivas_param_ism_render_slot(
     297             :     PARAM_ISM_DEC_HANDLE hParamIsmDec,
     298             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom,
     299             :     float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX],
     300             :     float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX],
     301             :     float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
     302             :     float Cldfb_ImagBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
     303             :     float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX],
     304             :     const int16_t interpolator_idx,
     305             :     const int16_t out_slot_idx,
     306             :     const int16_t num_ch_LS,
     307             :     const int16_t nchan_transport )
     308             : {
     309             :     int16_t outchIdx, inchIdx, bin_idx;
     310             :     float tmp_1, mixing_matrix_smooth;
     311             : 
     312     1109094 :     tmp_1 = hParamIsmDec->hParamIsmRendering->interpolator[interpolator_idx];
     313             : 
     314    52655694 :     for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
     315             :     {
     316             :         /* smooth the mixing matrix */
     317   516277920 :         for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ )
     318             :         {
     319  1394193960 :             for ( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ )
     320             :             {
     321   929462640 :                 mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][outchIdx + inchIdx * num_ch_LS] +
     322   929462640 :                                        ( 1 - tmp_1 ) * hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * num_ch_LS];
     323             : 
     324   929462640 :                 Cldfb_RealBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[inchIdx][bin_idx];
     325   929462640 :                 Cldfb_ImagBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[inchIdx][bin_idx];
     326             :             }
     327             :         }
     328             :     }
     329             : 
     330     1109094 :     return;
     331             : }
     332             : 
     333             : 
     334        2670 : static ivas_error ivas_param_ism_rendering_init(
     335             :     PARAM_ISM_RENDERING_HANDLE hParamIsmRendering,
     336             :     IVAS_OUTPUT_SETUP hOutSetup,
     337             :     const int16_t nchan_transport,
     338             :     const int16_t subframe_nbslots,
     339             :     AUDIO_CONFIG output_config )
     340             : {
     341             :     int16_t bin_idx;
     342             : 
     343             :     /* initialization of mixing matrix buffer for smoothing */
     344      162870 :     for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
     345             :     {
     346      160200 :         set_zero( hParamIsmRendering->mixing_matrix_lin_old[bin_idx], PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX );
     347             :     }
     348             : 
     349             :     /* memory allocation for proto matrix and interpolator */
     350        2670 :     if ( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL )
     351             :     {
     352           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for proto matrix\n" ) );
     353             :     }
     354        2670 :     if ( ( hParamIsmRendering->interpolator = (float *) malloc( subframe_nbslots * sizeof( float ) ) ) == NULL )
     355             :     {
     356           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) );
     357             :     }
     358             : 
     359        2670 :     if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
     360             :     {
     361             :         /* computation of proto matrix */
     362        1034 :         ivas_ism_get_proto_matrix( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix );
     363             :     }
     364             : 
     365             :     /* computation of interpolator*/
     366        2670 :     ivas_ism_get_interpolator( subframe_nbslots, hParamIsmRendering->interpolator );
     367             : 
     368        2670 :     return IVAS_ERR_OK;
     369             : }
     370             : 
     371             : 
     372       69318 : static void ivas_param_ism_update_mixing_matrix(
     373             :     PARAM_ISM_DEC_HANDLE hParamIsmDec,
     374             :     float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX],
     375             :     const int16_t nchan_in,
     376             :     const int16_t nchan_out )
     377             : {
     378             :     int16_t inchIdx, outchIdx, bin_idx, band_idx;
     379             :     int16_t brange[2];
     380             : 
     381      831816 :     for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
     382             :     {
     383      762498 :         brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
     384      762498 :         brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
     385             : 
     386     3984138 :         for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
     387             :         {
     388     9664920 :             for ( inchIdx = 0; inchIdx < nchan_in; inchIdx++ )
     389             :             {
     390    64534200 :                 for ( outchIdx = 0; outchIdx < nchan_out; outchIdx++ )
     391             :                 {
     392    58090920 :                     hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * nchan_out] = mixing_matrix[bin_idx][outchIdx + inchIdx * nchan_out];
     393             :                 }
     394             :             }
     395             :         }
     396             :     }
     397             : 
     398       69318 :     return;
     399             : }
     400             : 
     401             : 
     402             : /*-------------------------------------------------------------------------*
     403             :  * ivas_param_ism_dec_open()
     404             :  *
     405             :  * Open Param ISM handle
     406             :  *-------------------------------------------------------------------------*/
     407             : 
     408        2920 : ivas_error ivas_param_ism_dec_open(
     409             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
     410             : )
     411             : {
     412             :     int16_t i, granularity;
     413             :     PARAM_ISM_DEC_HANDLE hParamIsmDec;
     414             :     IVAS_OUTPUT_SETUP hOutSetup;
     415             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
     416             :     AUDIO_CONFIG output_config;
     417             :     int32_t output_Fs;
     418             :     ivas_error error;
     419             : 
     420        2920 :     error = IVAS_ERR_OK;
     421             : 
     422        2920 :     push_wmops( "ivas_param_ism_dec_open" );
     423             : 
     424             :     /*-----------------------------------------------------------------*
     425             :      * prepare library opening
     426             :      *-----------------------------------------------------------------*/
     427             : 
     428        2920 :     if ( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL )
     429             :     {
     430           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) );
     431             :     }
     432             : 
     433        2920 :     if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL )
     434             :     {
     435           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
     436             :     }
     437             : 
     438             :     /* Assign memory to Param Object handle */
     439        2920 :     if ( ( hParamIsmDec->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL )
     440             :     {
     441           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) );
     442             :     }
     443             : 
     444        2920 :     if ( ( hParamIsmDec->hParamIsmRendering = (PARAM_ISM_RENDERING_HANDLE) malloc( sizeof( PARAM_ISM_RENDERING_DATA ) ) ) == NULL )
     445             :     {
     446           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM Rendering handle\n" ) );
     447             :     }
     448             : 
     449        2920 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     450        2920 :     output_config = st_ivas->hDecoderConfig->output_config;
     451             : 
     452        2920 :     ivas_param_ism_config( hParamIsmDec->hParamIsm, st_ivas->nchan_ism );
     453             : 
     454             :     /*-----------------------------------------------------------------*
     455             :      * set input parameters
     456             :      *-----------------------------------------------------------------*/
     457             : 
     458        2920 :     hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );
     459        2920 :     set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
     460        2920 :     set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
     461        2920 :     hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
     462        2920 :     hSpatParamRendCom->subframes_rendered = 0;
     463        2920 :     hSpatParamRendCom->slots_rendered = 0;
     464        2920 :     hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
     465        2920 :     hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
     466             : 
     467        2920 :     hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS;
     468             : 
     469       37960 :     for ( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ )
     470             :     {
     471       35040 :         hParamIsmDec->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i];
     472             : 
     473       35040 :         if ( hParamIsmDec->hParamIsm->band_grouping[i] > hSpatParamRendCom->num_freq_bands )
     474             :         {
     475        3201 :             hParamIsmDec->hParamIsm->band_grouping[i] = hSpatParamRendCom->num_freq_bands;
     476             :         }
     477             :     }
     478             : 
     479             :     /*-----------------------------------------------------------------*
     480             :      * output setup
     481             :      *-----------------------------------------------------------------*/
     482             : 
     483             :     /* hIntSetup and hOutSetup differs only for Binaural rendering */
     484        2920 :     if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     485             :     {
     486             :         /* nchan_out is essential for memory initialization for CLDFB Synthesis */
     487         261 :         st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism;
     488         261 :         st_ivas->hIntSetup.is_loudspeaker_setup = 1;
     489             :     }
     490             : 
     491        2920 :     hOutSetup = st_ivas->hIntSetup;
     492             : 
     493        2920 :     if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
     494             :     {
     495             :         /* Initialize Param ISM Rendering handle */
     496        2670 :         if ( st_ivas->hDecoderConfig->Opt_tsm )
     497             :         {
     498        1266 :             if ( ( error = ivas_param_ism_rendering_init( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ) != IVAS_ERR_OK )
     499             :             {
     500           0 :                 return error;
     501             :             }
     502             :         }
     503             :         else
     504             :         {
     505        1404 :             if ( ( error = ivas_param_ism_rendering_init( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ) != IVAS_ERR_OK )
     506             :             {
     507           0 :                 return error;
     508             :             }
     509             :         }
     510             :     }
     511             : 
     512        3954 :     if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ||
     513        1161 :             output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
     514             :     {
     515             :         /* Initialize efap handle */
     516        1034 :         if ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth, hOutSetup.ls_elevation, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK )
     517             :         {
     518           0 :             return error;
     519             :         }
     520             :     }
     521             : 
     522             :     /* Azi and Ele values are transmitted once per frame per object */
     523        2920 :     set_zero( hParamIsmDec->azimuth_values, MAX_NUM_OBJECTS );
     524        2920 :     set_zero( hParamIsmDec->elevation_values, MAX_NUM_OBJECTS );
     525             : 
     526        2920 :     hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
     527        2920 :     hSpatParamRendCom->dirac_bs_md_write_idx = 0;
     528        2920 :     hSpatParamRendCom->dirac_read_idx = 0;
     529             : 
     530        2920 :     if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     531             :     {
     532        1375 :         if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK )
     533             :         {
     534           0 :             return error;
     535             :         }
     536             : 
     537        1375 :         if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK )
     538             :         {
     539           0 :             return error;
     540             :         }
     541             :     }
     542             : 
     543        2920 :     st_ivas->hISMDTX.dtx_flag = 0;
     544             : 
     545        2920 :     st_ivas->hParamIsmDec = hParamIsmDec;
     546        2920 :     st_ivas->hSpatParamRendCom = hSpatParamRendCom;
     547             : 
     548        2920 :     granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs );
     549             : 
     550        2920 :     if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE )
     551        2670 :     {
     552        2670 :         int16_t nchan_transport = st_ivas->nchan_transport;
     553        2670 :         int16_t nchan_full = 0;
     554             : 
     555        2670 :         if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
     556             :         {
     557        1375 :             nchan_full = nchan_transport;
     558        1375 :             hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
     559        1375 :             hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
     560             :         }
     561             :         else
     562             :         {
     563             :             int16_t n_slots_to_alloc;
     564        1295 :             if ( st_ivas->hDecoderConfig->Opt_tsm == 1 )
     565             :             {
     566         550 :                 n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS;
     567             :             }
     568             :             else
     569             :             {
     570         745 :                 n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES;
     571             :             }
     572        1295 :             if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
     573             : 
     574             :             {
     575           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) );
     576             :             }
     577        1295 :             set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
     578             : 
     579        1295 :             if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL )
     580             :             {
     581           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) );
     582             :             }
     583        1295 :             set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
     584             :         }
     585             : 
     586        2670 :         if ( st_ivas->hTcBuffer == NULL )
     587             :         {
     588        1356 :             if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, granularity ) ) != IVAS_ERR_OK )
     589             :             {
     590           0 :                 return error;
     591             :             }
     592             :         }
     593             :     }
     594             :     else
     595             :     {
     596         250 :         hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
     597         250 :         hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
     598         250 :         if ( st_ivas->hTcBuffer == NULL )
     599             :         {
     600         202 :             int16_t nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out;
     601             : 
     602         202 :             if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK )
     603             :             {
     604           0 :                 return error;
     605             :             }
     606             :         }
     607             :     }
     608             : 
     609        2920 :     pop_wmops();
     610        2920 :     return error;
     611             : }
     612             : 
     613             : 
     614             : /*-------------------------------------------------------------------------*
     615             :  * ivas_param_ism_dec_close()
     616             :  *
     617             :  * Close Param ISM handle
     618             :  *-------------------------------------------------------------------------*/
     619             : 
     620       17456 : void ivas_param_ism_dec_close(
     621             :     PARAM_ISM_DEC_HANDLE *hParamIsmDec_out,                    /* i/o: decoder DirAC handle         */
     622             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */
     623             :     AUDIO_CONFIG output_config                                 /* i  : output audio configuration   */
     624             : )
     625             : {
     626       17456 :     if ( hParamIsmDec_out != NULL && *hParamIsmDec_out != NULL )
     627             :     {
     628             :         PARAM_ISM_DEC_HANDLE hParamIsmDec;
     629        2920 :         hParamIsmDec = *hParamIsmDec_out;
     630             : 
     631             :         /* Config & CLDFB */
     632        2920 :         if ( hParamIsmDec->hParamIsm != NULL )
     633             :         {
     634        2920 :             free( hParamIsmDec->hParamIsm );
     635        2920 :             hParamIsmDec->hParamIsm = NULL;
     636             :         }
     637             : 
     638        2920 :         if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
     639             :         {
     640             :             /* Param ISM Rendering */
     641        2670 :             if ( hParamIsmDec->hParamIsmRendering->interpolator != NULL )
     642             :             {
     643        2670 :                 free( hParamIsmDec->hParamIsmRendering->interpolator );
     644        2670 :                 hParamIsmDec->hParamIsmRendering->interpolator = NULL;
     645             :             }
     646        2670 :             if ( hParamIsmDec->hParamIsmRendering->proto_matrix != NULL )
     647             :             {
     648        2670 :                 free( hParamIsmDec->hParamIsmRendering->proto_matrix );
     649        2670 :                 hParamIsmDec->hParamIsmRendering->proto_matrix = NULL;
     650             :             }
     651             :         }
     652             : 
     653        2920 :         if ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL )
     654             :         {
     655        1295 :             free( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc );
     656        1295 :             hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
     657             :         }
     658        2920 :         if ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc != NULL )
     659             :         {
     660        1295 :             free( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc );
     661        1295 :             hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
     662             :         }
     663             : 
     664        2920 :         if ( hParamIsmDec->hParamIsmRendering != NULL )
     665             :         {
     666        2920 :             free( hParamIsmDec->hParamIsmRendering );
     667        2920 :             hParamIsmDec->hParamIsmRendering = NULL;
     668             :         }
     669             : 
     670        2920 :         free( *hParamIsmDec_out );
     671        2920 :         *hParamIsmDec_out = NULL;
     672             :     }
     673             : 
     674       17456 :     if ( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL )
     675             :     {
     676        2920 :         if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
     677             :         {
     678        1375 :             ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 );
     679        1375 :             ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 );
     680             :         }
     681             : 
     682        2920 :         free( *hSpatParamRendCom_out );
     683        2920 :         *hSpatParamRendCom_out = NULL;
     684             :     }
     685             : 
     686       17456 :     return;
     687             : }
     688             : 
     689             : 
     690             : /*-------------------------------------------------------------------------*
     691             :  * ivas_ism_dec_digest_tc()
     692             :  *
     693             :  *
     694             :  *-------------------------------------------------------------------------*/
     695             : 
     696     1889349 : void ivas_ism_dec_digest_tc(
     697             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
     698             : )
     699             : {
     700     1889349 :     ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
     701             : 
     702     1889349 :     if ( st_ivas->renderer_type == RENDERER_TD_PANNING ||
     703     1574927 :          st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
     704     1412661 :          st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ||
     705     1211515 :          st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ||
     706     1136641 :          st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
     707     1005187 :          st_ivas->renderer_type == RENDERER_OSBA_LS ||
     708      790117 :          st_ivas->renderer_type == RENDERER_OSBA_STEREO ||
     709      744103 :          ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) )
     710             :     {
     711             :         int16_t i;
     712             : 
     713             :         /* we have a full frame interpolator, adapt it */
     714             :         /* for BE testing */
     715     1238395 :         if ( ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) == st_ivas->hTcBuffer->n_samples_available )
     716             :         {
     717     1238133 :             int16_t interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
     718             : 
     719     1238133 :             if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
     720     1075879 :                  st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
     721      944431 :                  st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) )
     722             :             {
     723      569484 :                 st_ivas->hIsmRendererData->interpolator[0] = 0.0f;
     724   395375040 :                 for ( i = 1; i < interpolator_length; i++ )
     725             :                 {
     726   394805556 :                     st_ivas->hIsmRendererData->interpolator[i] = st_ivas->hIsmRendererData->interpolator[i - 1] + 1.f / ( interpolator_length - 1 );
     727             :                 }
     728             :             }
     729             :             else
     730             :             {
     731   442423209 :                 for ( i = 0; i < interpolator_length; i++ )
     732             :                 {
     733   441754560 :                     st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length - 1 );
     734             :                 }
     735             :             }
     736             :         }
     737             :         else
     738             :         {
     739         262 :             ivas_jbm_dec_get_adapted_linear_interpolator( (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator );
     740             :         }
     741     1238395 :         st_ivas->hIsmRendererData->interp_offset = 0;
     742             : 
     743             :         /* also get the gains here */
     744     4410875 :         for ( i = 0; i < st_ivas->nchan_ism; i++ )
     745             :         {
     746     3172480 :             mvr2r( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmRendererData->prev_gains[i], MAX_OUTPUT_CHANNELS );
     747             : 
     748     3172480 :             if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_STEREO )
     749             :             {
     750      269338 :                 ivas_ism_get_stereo_gains( st_ivas->hIsmMetaData[i]->edited_azimuth, st_ivas->hIsmMetaData[i]->edited_elevation, &st_ivas->hIsmRendererData->gains[i][0], &st_ivas->hIsmRendererData->gains[i][1] );
     751      269338 :                 v_multc( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_gain, st_ivas->hIsmRendererData->gains[i], CPE_CHANNELS );
     752             :             }
     753             :             else
     754             :             {
     755     2903142 :                 if ( ( st_ivas->renderer_type == RENDERER_TD_PANNING ||
     756     2241242 :                        st_ivas->renderer_type == RENDERER_OSBA_LS ||
     757     1716932 :                        st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM || ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) &&
     758     1631174 :                      st_ivas->hCombinedOrientationData == NULL )
     759     1631174 :                 {
     760     1631174 :                     float elevation = st_ivas->hIsmMetaData[i]->edited_elevation;
     761             : 
     762     1631174 :                     if ( st_ivas->hIntSetup.is_planar_setup )
     763             :                     {
     764             :                         /* If no elevation support in output format, then rendering should be done with zero elevation */
     765      485296 :                         elevation = 0.f;
     766             :                     }
     767             : 
     768     1631174 :                     if ( st_ivas->hEFAPdata != NULL )
     769             :                     {
     770     1631174 :                         efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_azimuth, elevation, EFAP_MODE_EFAP );
     771     1631174 :                         v_multc( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_gain, st_ivas->hIsmRendererData->gains[i], st_ivas->hEFAPdata->numSpk );
     772             :                     }
     773             :                 }
     774     1271968 :                 else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
     775      839912 :                           st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
     776      519290 :                           st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
     777             :                 {
     778             :                     // TODO tmu review when #215 is resolved
     779             :                     int16_t azimuth, elevation;
     780             : 
     781     1271968 :                     azimuth = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_azimuth + 0.5f );
     782     1271968 :                     elevation = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_elevation + 0.5f );
     783             : 
     784             :                     /*get HOA gets for direction (ACN/SN3D)*/
     785     1271968 :                     ivas_dirac_dec_get_response( azimuth, elevation, st_ivas->hIsmRendererData->gains[i], st_ivas->hIntSetup.ambisonics_order );
     786     1271968 :                     v_multc( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_gain, st_ivas->hIsmRendererData->gains[i], ivas_sba_get_nchan( st_ivas->hIntSetup.ambisonics_order, 0 ) );
     787             :                 }
     788             :             }
     789             :         }
     790             :     }
     791             : 
     792     1889349 :     return;
     793             : }
     794             : 
     795             : 
     796             : /*-------------------------------------------------------------------------*
     797             :  * ivas_param_ism_dec_digest_tc()
     798             :  *
     799             :  *
     800             :  *-------------------------------------------------------------------------*/
     801             : 
     802       69318 : void ivas_param_ism_dec_digest_tc(
     803             :     Decoder_Struct *st_ivas,    /* i/o: IVAS decoder handle                                       */
     804             :     const uint16_t nCldfbSlots, /* i  : number of CLDFB slots in transport channels               */
     805             :     float *p_data_f[]           /* i/o: synthesized core-coder transport channels/DirAC output    */
     806             : )
     807             : {
     808             :     int16_t ch, slot_idx, output_frame;
     809             :     int16_t num_freq_bands, cldfb_ch, n_ch_cldfb;
     810             :     float *cldfb_real_buffer, *cldfb_imag_buffer;
     811             : 
     812             :     /* Initialization */
     813       69318 :     num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands;
     814       69318 :     output_frame = nCldfbSlots * num_freq_bands;
     815       69318 :     n_ch_cldfb = st_ivas->hTcBuffer->nchan_transport_jbm - st_ivas->hTcBuffer->nchan_buffer_full;
     816             : 
     817       69318 :     cldfb_real_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc;
     818       69318 :     cldfb_imag_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc;
     819             : 
     820       69318 :     ivas_ism_param_dec_tc_gain_adjust( st_ivas, output_frame, output_frame / 2, p_data_f );
     821             : 
     822             :     /* CLDFB Analysis */
     823      207954 :     for ( ch = 0, cldfb_ch = 0; cldfb_ch < n_ch_cldfb; cldfb_ch++, ch++ )
     824             :     {
     825     2356824 :         for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
     826             :         {
     827     2218188 :             cldfbAnalysis_ts( &( p_data_f[ch][num_freq_bands * slot_idx] ),
     828     2218188 :                               &cldfb_real_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
     829     2218188 :                               &cldfb_imag_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
     830             :                               num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch] );
     831             :         }
     832             :     }
     833             : 
     834       69318 :     return;
     835             : }
     836             : 
     837             : 
     838             : /*-------------------------------------------------------------------------*
     839             :  * ivas_param_ism_dec_dequant_md()
     840             :  *
     841             :  *
     842             :  *-------------------------------------------------------------------------*/
     843             : 
     844      155841 : void ivas_param_ism_dec_dequant_md(
     845             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder handle     */
     846             : )
     847             : {
     848             :     /* De-quantization */
     849      155841 :     if ( !( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 || st_ivas->hDecoderConfig->ivas_total_brate == FRAME_NO_DATA ) )
     850             :     {
     851      148488 :         ivas_param_ism_dec_dequant_DOA( st_ivas->hParamIsmDec, st_ivas->nchan_ism );
     852      148488 :         ivas_param_ism_dec_dequant_powrat( st_ivas->hParamIsmDec );
     853      148488 :         st_ivas->hISMDTX.dtx_flag = 0;
     854             :     }
     855             :     else
     856             :     {
     857        7353 :         st_ivas->hISMDTX.dtx_flag = 1;
     858             :     }
     859             : 
     860      155841 :     return;
     861             : }
     862             : 
     863             : 
     864             : /*-------------------------------------------------------------------------*
     865             :  * ivas_param_ism_dec_prepare_renderer()
     866             :  *
     867             :  *
     868             :  *-------------------------------------------------------------------------*/
     869             : 
     870       69318 : void ivas_param_ism_dec_prepare_renderer(
     871             :     Decoder_Struct *st_ivas,   /* i/o: IVAS decoder handle                          */
     872             :     const uint16_t nCldfbSlots /* i  : number of CLDFB slots in transport channels  */
     873             : )
     874             : {
     875             :     int16_t ch, nchan_transport, nchan_out, nchan_out_woLFE, i;
     876             :     int16_t slot_idx, bin_idx;
     877             :     float ref_power[CLDFB_NO_CHANNELS_MAX];
     878             :     float cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX];
     879             :     /* Direct Response/EFAP Gains */
     880             :     float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN];
     881             :     PARAM_ISM_DEC_HANDLE hParamIsmDec;
     882             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
     883             : 
     884             :     /* Initialization */
     885       69318 :     hParamIsmDec = st_ivas->hParamIsmDec;
     886       69318 :     assert( hParamIsmDec );
     887       69318 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
     888       69318 :     assert( hSpatParamRendCom );
     889             : 
     890       69318 :     nchan_transport = st_ivas->nchan_transport;
     891             : 
     892       69318 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     893             :     {
     894        5965 :         nchan_out = st_ivas->nchan_ism;
     895        5965 :         nchan_out_woLFE = nchan_out;
     896        5965 :         st_ivas->hDecoderConfig->nchan_out = nchan_out;
     897             :     }
     898             :     else
     899             :     {
     900       63353 :         nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
     901       63353 :         nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
     902             :     }
     903             : 
     904             :     /* general setup */
     905       69318 :     ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator );
     906             : 
     907       69318 :     ivas_dirac_dec_set_md_map( st_ivas, nCldfbSlots );
     908             : 
     909             :     /* set buffers to zero */
     910     4228398 :     for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
     911             :     {
     912     4159080 :         set_zero( cx_diag[bin_idx], PARAM_ISM_MAX_DMX );
     913             :     }
     914       69318 :     set_zero( ref_power, CLDFB_NO_CHANNELS_MAX );
     915             : 
     916             :     /* obtain the direct response using EFAP */
     917       69318 :     if ( !( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) )
     918             :     {
     919      284396 :         for ( i = 0; i < st_ivas->nchan_ism; i++ )
     920             :         {
     921      221043 :             efap_determine_gains( st_ivas->hEFAPdata, direct_response[i], hParamIsmDec->edited_azimuth_values[i], hParamIsmDec->edited_elevation_values[i], EFAP_MODE_EFAP );
     922             :         }
     923             :     }
     924             :     else
     925             :     {
     926             :         int16_t j;
     927             : 
     928       27657 :         for ( i = 0; i < st_ivas->nchan_ism; i++ )
     929             :         {
     930      101956 :             for ( j = 0; j < nchan_out_woLFE; j++ )
     931             :             {
     932       80264 :                 if ( i == j )
     933             :                 {
     934       21692 :                     direct_response[i][j] = 1.0f;
     935             :                 }
     936             :                 else
     937             :                 {
     938       58572 :                     direct_response[i][j] = 0.0f;
     939             :                 }
     940             :             }
     941             :         }
     942             : 
     943       27657 :         for ( j = 0; j < nchan_out_woLFE; j++ )
     944             :         {
     945       21692 :             if ( hParamIsmDec->azimuth_values[j] > 0.0f )
     946             :             {
     947        9175 :                 hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 1.0f;
     948        9175 :                 hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.0f;
     949             :             }
     950             :             else
     951             :             {
     952       12517 :                 if ( hParamIsmDec->azimuth_values[j] < 0.0f )
     953             :                 {
     954        9189 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.0f;
     955        9189 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 1.0f;
     956             :                 }
     957             :                 else /* == 0.0f */
     958             :                 {
     959        3328 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.5f;
     960        3328 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.5f;
     961             :                 }
     962             :             }
     963             :         }
     964             :     }
     965             : 
     966      207954 :     for ( ch = 0; ch < nchan_transport; ch++ )
     967             :     {
     968             :         /* CLDFB Analysis */
     969     2356824 :         for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
     970             :         {
     971     2218188 :             ivas_param_ism_collect_slot( hParamIsmDec, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], ch, ref_power, cx_diag );
     972             :         }
     973             :     }
     974             : 
     975             :     /* Obtain Mixing Matrix on a frame-level */
     976     3290958 :     for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
     977             :     {
     978     3221640 :         set_f( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE );
     979             :     }
     980             : 
     981             :     /* Compute mixing matrix */
     982       69318 :     ivas_param_ism_compute_mixing_matrix( st_ivas->nchan_ism, hParamIsmDec, st_ivas->hISMDTX, direct_response, nchan_transport, nchan_out_woLFE, cx_diag, ref_power, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin );
     983             : 
     984       69318 :     return;
     985             : }
     986             : 
     987             : 
     988             : /*-------------------------------------------------------------------------*
     989             :  * ivas_ism_param_dec_tc_gain_adjust()
     990             :  *
     991             :  *
     992             :  *-------------------------------------------------------------------------*/
     993             : 
     994       69318 : static void ivas_ism_param_dec_tc_gain_adjust(
     995             :     Decoder_Struct *st_ivas,   /* i/o: IVAS decoder handle                                   */
     996             :     const int16_t nSamples,    /* i  : number of samples to be compensate                    */
     997             :     const int16_t nFadeLength, /* i  : length of the crossfade in samples                    */
     998             :     float *p_data_f[]          /* i  : synthesized core-coder transport channels/DirAC output*/
     999             : )
    1000             : 
    1001             : {
    1002             :     int16_t i;
    1003             :     float gain, ene_tc, ene_sum, grad;
    1004             :     float last_gain;
    1005             : 
    1006       69318 :     ene_tc = 0.0f;
    1007       69318 :     ene_sum = 0.0f;
    1008       69318 :     last_gain = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain;
    1009             : 
    1010    51615918 :     for ( i = 0; i < nSamples; i++ )
    1011             :     {
    1012    51546600 :         ene_tc += p_data_f[0][i] * p_data_f[0][i] + p_data_f[1][i] * p_data_f[1][i];          /* L*L + R*R */
    1013    51546600 :         ene_sum += ( p_data_f[0][i] + p_data_f[1][i] ) * ( p_data_f[0][i] + p_data_f[1][i] ); /* (L+R)*(L+R) */
    1014             :     }
    1015       69318 :     gain = sqrtf( ene_tc / ( ene_sum + EPSILON ) );
    1016       69318 :     if ( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 1 )
    1017             :     {
    1018             :         /* Smoothing */
    1019       68425 :         gain = 0.75f * gain + 0.25f * last_gain;
    1020             :         /* 10ms ramp */
    1021       68425 :         grad = ( gain - last_gain ) / (float) nFadeLength; /* slope between two consecutive gains, 480 samples length */
    1022    25585885 :         for ( i = 0; i < ( nFadeLength ); i++ )
    1023             :         {
    1024    25517460 :             p_data_f[0][i] *= ( last_gain + i * grad );
    1025    25517460 :             p_data_f[1][i] *= ( last_gain + i * grad );
    1026             :         }
    1027    25585885 :         for ( ; i < nSamples; i++ )
    1028             :         {
    1029    25517460 :             p_data_f[0][i] *= gain;
    1030    25517460 :             p_data_f[1][i] *= gain;
    1031             :         }
    1032             :     }
    1033             :     else
    1034             :     {
    1035      512573 :         for ( i = 0; i < nSamples; i++ )
    1036             :         {
    1037      511680 :             p_data_f[0][i] *= gain;
    1038      511680 :             p_data_f[1][i] *= gain;
    1039             :         }
    1040             :     }
    1041             : 
    1042       69318 :     st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain = gain;
    1043             : 
    1044       69318 :     return;
    1045             : }
    1046             : 
    1047             : 
    1048             : /*-------------------------------------------------------------------------*
    1049             :  * ivas_ism_param_dec_render_sf()
    1050             :  *
    1051             :  *
    1052             :  *-------------------------------------------------------------------------*/
    1053             : 
    1054      285495 : static void ivas_ism_param_dec_render_sf(
    1055             :     Decoder_Struct *st_ivas,
    1056             :     IVAS_OUTPUT_SETUP hSetup,
    1057             :     const int16_t nchan_transport,
    1058             :     const int16_t nchan_out,
    1059             :     const int16_t nchan_out_woLFE,
    1060             :     float *output_f[] /* o  : rendered time signal                                    */
    1061             : )
    1062             : {
    1063             :     int16_t ch, slot_idx, i, index_slot;
    1064             :     /* CLDFB Output Buffers */
    1065             :     float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    1066             :     float Cldfb_ImagBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    1067             :     float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX];
    1068             :     float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX];
    1069             :     PARAM_ISM_DEC_HANDLE hParamIsmDec;
    1070             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    1071             :     int16_t slot_idx_start;
    1072             :     int16_t idx_in;
    1073             :     int16_t idx_lfe;
    1074             :     int16_t subframe_idx;
    1075             : 
    1076      285495 :     hParamIsmDec = st_ivas->hParamIsmDec;
    1077      285495 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1078      285495 :     slot_idx_start = hSpatParamRendCom->slots_rendered;
    1079      285495 :     subframe_idx = hSpatParamRendCom->subframes_rendered;
    1080             : 
    1081             :     /* Set some memories to zero */
    1082     2836584 :     for ( ch = 0; ch < nchan_out_woLFE; ch++ )
    1083             :     {
    1084    12393699 :         for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    1085             :         {
    1086     9842610 :             set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
    1087     9842610 :             set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
    1088             :         }
    1089             :     }
    1090             : 
    1091     1394589 :     for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    1092             :     {
    1093     1109094 :         index_slot = slot_idx_start + slot_idx;
    1094             : 
    1095     3327282 :         for ( ch = 0; ch < nchan_transport; ch++ )
    1096             :         {
    1097     2218188 :             Cldfb_RealBuffer_in[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands];
    1098     2218188 :             Cldfb_ImagBuffer_in[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands];
    1099             :         }
    1100             : 
    1101             :         /* Compute bandwise rendering to target LS using covariance rendering */
    1102     1109094 :         ivas_param_ism_render_slot( hParamIsmDec, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in,
    1103     1109094 :                                     Cldfb_RealBuffer, Cldfb_ImagBuffer, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, index_slot, slot_idx, nchan_out_woLFE, nchan_transport );
    1104             :     }
    1105             : 
    1106             :     /* CLDFB Synthesis */
    1107      285495 :     idx_in = 0;
    1108      285495 :     idx_lfe = 0;
    1109             : 
    1110     3098219 :     for ( ch = 0; ch < nchan_out; ch++ )
    1111             :     {
    1112     2812724 :         if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) )
    1113             :         {
    1114      261635 :             set_zero( output_f[ch], hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands );
    1115      261635 :             if ( idx_lfe < ( hSetup.num_lfe - 1 ) )
    1116             :             {
    1117           0 :                 idx_lfe++;
    1118             :             }
    1119             :         }
    1120             :         else
    1121             :         {
    1122             :             float *RealBuffer[16];
    1123             :             float *ImagBuffer[16];
    1124             : 
    1125             :             /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
    1126    12393699 :             for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    1127             :             {
    1128     9842610 :                 RealBuffer[i] = Cldfb_RealBuffer[idx_in][i];
    1129     9842610 :                 ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i];
    1130             :             }
    1131             : 
    1132     2551089 :             cldfbSynthesis( RealBuffer, ImagBuffer, output_f[ch], hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] );
    1133     2551089 :             idx_in++;
    1134             :         }
    1135             :     }
    1136             : 
    1137      285495 :     hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx];
    1138      285495 :     hSpatParamRendCom->subframes_rendered++;
    1139             : 
    1140      285495 :     return;
    1141             : }
    1142             : 
    1143             : 
    1144             : /*-------------------------------------------------------------------------*
    1145             :  * ivas_param_ism_dec_render()
    1146             :  *
    1147             :  *
    1148             :  *-------------------------------------------------------------------------*/
    1149             : 
    1150      102405 : void ivas_param_ism_dec_render(
    1151             :     Decoder_Struct *st_ivas,         /* i/o: IVAS decoder handle                            */
    1152             :     const uint16_t nSamplesAsked,    /* i  : number of CLDFB slots requested                */
    1153             :     uint16_t *nSamplesRendered,      /* o  : number of CLDFB slots rendered                 */
    1154             :     uint16_t *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render          */
    1155             :     float *output_f[]                /* i/o: synthesized core-coder TCs / rendered signal   */
    1156             : )
    1157             : {
    1158             :     int16_t ch, slots_to_render, first_sf, last_sf, subframe_idx;
    1159             :     uint16_t slot_size, n_samples_sf;
    1160             :     PARAM_ISM_DEC_HANDLE hParamIsmDec;
    1161             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    1162             :     IVAS_OUTPUT_SETUP hSetup;
    1163             :     int16_t nchan_transport, nchan_out, nchan_out_woLFE;
    1164             :     float *output_f_local[MAX_OUTPUT_CHANNELS];
    1165             : 
    1166      102405 :     hParamIsmDec = st_ivas->hParamIsmDec;
    1167      102405 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1168      102405 :     hSetup = st_ivas->hIntSetup;
    1169             : #ifdef DEBUGGING
    1170             :     assert( hParamIsmDec );
    1171             :     assert( hSpatParamRendCom );
    1172             : #endif
    1173      102405 :     nchan_transport = st_ivas->nchan_transport;
    1174      102405 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
    1175             :     {
    1176        5965 :         nchan_out = st_ivas->nchan_ism;
    1177        5965 :         nchan_out_woLFE = nchan_out;
    1178        5965 :         st_ivas->hDecoderConfig->nchan_out = nchan_out;
    1179             :     }
    1180             :     else
    1181             :     {
    1182       96440 :         nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
    1183       96440 :         nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
    1184             :     }
    1185      102405 :     slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
    1186             : 
    1187             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    1188      102405 :     slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size );
    1189      102405 :     *nSamplesRendered = slots_to_render * slot_size;
    1190      102405 :     first_sf = hSpatParamRendCom->subframes_rendered;
    1191      102405 :     last_sf = first_sf;
    1192             : 
    1193      387900 :     while ( slots_to_render > 0 )
    1194             :     {
    1195      285495 :         slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf];
    1196      285495 :         last_sf++;
    1197             :     }
    1198             : #ifdef DEBUGGING
    1199             :     assert( slots_to_render == 0 );
    1200             : #endif
    1201             : 
    1202     1153961 :     for ( ch = 0; ch < nchan_out; ch++ )
    1203             :     {
    1204     1051556 :         output_f_local[ch] = &output_f[ch][0];
    1205             :     }
    1206             : 
    1207      387900 :     for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    1208             :     {
    1209      285495 :         ivas_ism_param_dec_render_sf( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local );
    1210      285495 :         n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size;
    1211     3098219 :         for ( ch = 0; ch < nchan_out; ch++ )
    1212             :         {
    1213     2812724 :             output_f_local[ch] += n_samples_sf;
    1214             :         }
    1215             :     }
    1216             : 
    1217      102405 :     if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots )
    1218             :     {
    1219             :         /* copy the memories */
    1220             :         /* store mixing matrix for next subframe */
    1221       69318 :         ivas_param_ism_update_mixing_matrix( hParamIsmDec, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, nchan_transport, nchan_out_woLFE );
    1222             : 
    1223             :         /* store MetaData parameters */
    1224      312053 :         for ( ch = 0; ch < st_ivas->nchan_ism; ch++ )
    1225             :         {
    1226      242735 :             if ( st_ivas->hParamIsmDec->azimuth_values[ch] > 180.0f )
    1227             :             {
    1228           0 :                 st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->edited_azimuth_values[ch] - 360.0f;
    1229             :             }
    1230             :             else
    1231             :             {
    1232      242735 :                 st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->edited_azimuth_values[ch];
    1233             :             }
    1234      242735 :             st_ivas->hIsmMetaData[ch]->elevation = st_ivas->hParamIsmDec->edited_elevation_values[ch];
    1235             :         }
    1236             :     }
    1237             : 
    1238      102405 :     *nSamplesAvailableNext = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size;
    1239             : 
    1240      102405 :     return;
    1241             : }
    1242             : 
    1243             : 
    1244             : /*-------------------------------------------------------------------------*
    1245             :  * ivas_param_ism_params_to_masa_param_mapping()
    1246             :  *
    1247             :  *
    1248             :  *-------------------------------------------------------------------------*/
    1249             : 
    1250       57383 : void ivas_param_ism_params_to_masa_param_mapping(
    1251             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
    1252             : )
    1253             : {
    1254             :     PARAM_ISM_DEC_HANDLE hParamIsmDec;
    1255             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    1256             :     int16_t nBins;
    1257             :     int16_t band_idx, bin_idx, sf_idx;
    1258             :     int16_t brange[2];
    1259             :     int16_t azimuth[2];
    1260             :     int16_t elevation[2];
    1261             :     float power_ratio[2];
    1262             :     MASA_ISM_DATA_HANDLE hMasaIsmData;
    1263             :     int16_t obj;
    1264             :     int16_t obj_idx;
    1265             : 
    1266       57383 :     hParamIsmDec = st_ivas->hParamIsmDec;
    1267       57383 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1268       57383 :     hMasaIsmData = st_ivas->hMasaIsmData;
    1269       57383 :     nBins = hSpatParamRendCom->num_freq_bands;
    1270             : 
    1271       57383 :     if ( st_ivas->hISMDTX.dtx_flag )
    1272             :     {
    1273             :         float energy_ratio;
    1274             : 
    1275        1258 :         energy_ratio = powf( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence[0], 2.0f );
    1276             : 
    1277        1258 :         hSpatParamRendCom->numSimultaneousDirections = 1;
    1278        1258 :         azimuth[0] = (int16_t) roundf( hParamIsmDec->azimuth_values[0] );
    1279        1258 :         elevation[0] = (int16_t) roundf( hParamIsmDec->elevation_values[0] );
    1280             : 
    1281        6290 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1282             :         {
    1283      306952 :             for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
    1284             :             {
    1285      301920 :                 hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
    1286      301920 :                 hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
    1287             : 
    1288      301920 :                 hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = energy_ratio;
    1289             : 
    1290      301920 :                 hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
    1291      301920 :                 hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
    1292             :             }
    1293             :         }
    1294             :     }
    1295             :     else
    1296             :     {
    1297       56125 :         hSpatParamRendCom->numSimultaneousDirections = 2;
    1298      673500 :         for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
    1299             :         {
    1300      617375 :             brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
    1301      617375 :             brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
    1302             : 
    1303      617375 :             azimuth[0] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] );
    1304      617375 :             elevation[0] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] );
    1305      617375 :             power_ratio[0] = hParamIsmDec->power_ratios[band_idx][0][0];
    1306             : 
    1307      617375 :             azimuth[1] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] );
    1308      617375 :             elevation[1] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] );
    1309      617375 :             power_ratio[1] = hParamIsmDec->power_ratios[band_idx][0][1];
    1310             : 
    1311     3086875 :             for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1312             :             {
    1313    13875740 :                 for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
    1314             :                 {
    1315    11406240 :                     hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
    1316    11406240 :                     hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
    1317    11406240 :                     hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = power_ratio[0];
    1318    11406240 :                     hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1];
    1319    11406240 :                     hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1];
    1320    11406240 :                     hSpatParamRendCom->energy_ratio2[sf_idx][bin_idx] = power_ratio[1];
    1321             :                 }
    1322             :             }
    1323             :         }
    1324             : 
    1325      280625 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1326             :         {
    1327    11630740 :             for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
    1328             :             {
    1329    11406240 :                 hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
    1330    11406240 :                 hSpatParamRendCom->spreadCoherence2[sf_idx][bin_idx] = 0.0f;
    1331    11406240 :                 hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
    1332             :             }
    1333             :         }
    1334             : 
    1335      264068 :         for ( obj = 0; obj < st_ivas->nchan_ism; obj++ )
    1336             :         {
    1337     1039715 :             for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1338             :             {
    1339      831772 :                 hMasaIsmData->azimuth_ism[obj][sf_idx] = (int16_t) roundf( hParamIsmDec->azimuth_values[obj] );
    1340      831772 :                 hMasaIsmData->elevation_ism[obj][sf_idx] = (int16_t) roundf( hParamIsmDec->elevation_values[obj] );
    1341             :             }
    1342             : 
    1343      207943 :             hMasaIsmData->azimuth_ism_edited[obj] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[obj] );
    1344      207943 :             hMasaIsmData->elevation_ism_edited[obj] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[obj] );
    1345             : 
    1346     1039715 :             for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1347             :             {
    1348      831772 :                 set_zero( hMasaIsmData->energy_ratio_ism[obj][sf_idx], CLDFB_NO_CHANNELS_MAX );
    1349             :             }
    1350             :         }
    1351             : 
    1352      168375 :         for ( obj = 0; obj < MAX_PARAM_ISM_WAVE; obj++ )
    1353             :         {
    1354     1347000 :             for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
    1355             :             {
    1356     1234750 :                 brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
    1357     1234750 :                 brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
    1358             : 
    1359     1234750 :                 obj_idx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][obj];
    1360     1234750 :                 power_ratio[obj] = hParamIsmDec->power_ratios[band_idx][0][obj];
    1361             : 
    1362     6173750 :                 for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1363             :                 {
    1364    27751480 :                     for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
    1365             :                     {
    1366    22812480 :                         hMasaIsmData->energy_ratio_ism[obj_idx][sf_idx][bin_idx] = power_ratio[obj];
    1367             :                     }
    1368             :                 }
    1369             :             }
    1370             :         }
    1371             :     }
    1372             : 
    1373       57383 :     return;
    1374             : }

Generated by: LCOV version 1.14