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 @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 455 475 95.8 %
Date: 2025-05-23 08:37:30 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       61164 : 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       61164 :     hParamIsm = hParamIsmDec->hParamIsm;
      67             : 
      68       61164 :     assert( nchan_ism <= MAX_NUM_OBJECTS );
      69             : 
      70             :     /* Get the azimuth and elevation values */
      71      285555 :     for ( i = 0; i < nchan_ism; i++ )
      72             :     {
      73      224391 :         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      224391 :         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       61164 :     return;
      78             : }
      79             : 
      80             : 
      81       61164 : 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       61164 :     hParamIsm = hParamIsmDec->hParamIsm;
      89             : 
      90             :     /* Get the power ratio values */
      91      733968 :     for ( band_idx = 0; band_idx < hParamIsm->nbands; band_idx++ )
      92             :     {
      93     1345608 :         for ( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ )
      94             :         {
      95      672804 :             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      672804 :             hParamIsmDec->power_ratios[band_idx][slot_idx][1] = 1.0f - hParamIsmDec->power_ratios[band_idx][slot_idx][0];
      97             :         }
      98             :     }
      99             : 
     100       61164 :     return;
     101             : }
     102             : 
     103             : 
     104         954 : static void ivas_ism_get_interpolator(
     105             :     const int16_t subframe_nbslots,
     106             :     float *interpolator )
     107             : {
     108         954 :     int16_t interp_idx = 0;
     109             : 
     110       23514 :     for ( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ )
     111             :     {
     112       22560 :         interpolator[interp_idx] = (float) ( interp_idx + 1 ) / (float) subframe_nbslots;
     113             :     }
     114             : 
     115         954 :     return;
     116             : }
     117             : 
     118             : 
     119          66 : 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          66 :     switch ( nchan_transport )
     128             :     {
     129          66 :         case 2:
     130             :         {
     131          66 :             if ( hOutSetup.nchan_out_woLFE )
     132             :             {
     133         780 :                 for ( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ )
     134             :                 {
     135         714 :                     if ( hOutSetup.ls_azimuth[idx] > 0.0f )
     136             :                     {
     137         324 :                         proto_matrix[idx] = 1.0f;
     138         324 :                         proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.0f;
     139             :                     }
     140         390 :                     else if ( hOutSetup.ls_azimuth[idx] < 0.0f )
     141             :                     {
     142         324 :                         proto_matrix[idx] = 0.0f;
     143         324 :                         proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 1.0f;
     144             :                     }
     145             :                     else
     146             :                     {
     147          66 :                         proto_matrix[idx] = 0.5f;
     148          66 :                         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          66 :             break;
     157             :         }
     158             : 
     159           0 :         default:
     160           0 :             assert( 0 && "Error: number of transport channels not supported" );
     161             :     }
     162             : 
     163          66 :     return;
     164             : }
     165             : 
     166             : 
     167      648780 : 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     7785360 :     for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
     182             :     {
     183     7136580 :         brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
     184     7136580 :         brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
     185    46063380 :         for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
     186             :         {
     187    38926800 :             tmp = 0.0f;
     188    38926800 :             tmp += ( Cldfb_RealBuffer_in[bin_idx] * Cldfb_RealBuffer_in[bin_idx] );
     189    38926800 :             tmp += ( Cldfb_ImagBuffer_in[bin_idx] * Cldfb_ImagBuffer_in[bin_idx] );
     190    38926800 :             cx_diag[bin_idx][ch] += tmp;
     191    38926800 :             ref_power[bin_idx] += tmp;
     192             :         }
     193             :     }
     194             : 
     195      648780 :     return;
     196             : }
     197             : 
     198             : 
     199       20274 : 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       20274 :     proto_matrix = hParamIsmDec->hParamIsmRendering->proto_matrix;
     222             : 
     223       20274 :     assert( ( nchan_ism == 3 ) || ( nchan_ism == 4 ) );
     224       20274 :     assert( nchan_transport == 2 );
     225             : 
     226       20274 :     if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
     227             :     {
     228         180 :         num_wave = nchan_ism;
     229             :     }
     230             :     else
     231             :     {
     232       20094 :         num_wave = MAX_PARAM_ISM_WAVE;
     233             :     }
     234       20274 :     set_zero( response_matrix, PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS );
     235             : 
     236             :     /* loop over parameter bands to compute the mixing matrix */
     237      243288 :     for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
     238             :     {
     239      223014 :         brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
     240      223014 :         brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
     241             : 
     242             :         /* Compute covaraince matrix from direct response*/
     243      673002 :         for ( w = 0; w < num_wave; w++ )
     244             :         {
     245      449988 :             set_zero( cy_diag_tmp[w], nchan_out_woLFE );
     246             : 
     247      449988 :             if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
     248             :             {
     249        7920 :                 dir_res_ptr = direct_response[w];
     250             :             }
     251             :             else
     252             :             {
     253      442068 :                 obj_indx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][w];
     254      442068 :                 dir_res_ptr = direct_response[obj_indx];
     255             :             }
     256      449988 :             mvr2r( dir_res_ptr, response_matrix + w * nchan_out_woLFE, nchan_out_woLFE );
     257             :             /* we only need the diagonal of Cy*/
     258      449988 :             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     1439454 :         for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
     262             :         {
     263             : 
     264     1216440 :             set_zero( cy_diag, nchan_out_woLFE );
     265     3670920 :             for ( w = 0; w < num_wave; w++ )
     266             :             {
     267     2454480 :                 if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
     268             :                 {
     269       43200 :                     direct_power[w] = ( 1.0f / nchan_ism ) * ref_power[bin_idx];
     270             :                 }
     271             :                 else
     272             :                 {
     273     2411280 :                     direct_power[w] = hParamIsmDec->power_ratios[band_idx][0][w] * ref_power[bin_idx];
     274             :                 }
     275             : 
     276     2454480 :                 if ( direct_power[w] != 0.f )
     277             :                 {
     278    21377655 :                     for ( i = 0; i < nchan_out_woLFE; i++ )
     279             :                     {
     280    19347654 :                         cy_diag[i] += direct_power[w] * cy_diag_tmp[w][i];
     281             :                     }
     282             :                 }
     283     2454480 :                 direct_power[w] = sqrtf( direct_power[w] );
     284             :             }
     285             : 
     286             :             /* Compute mixing matrix */
     287     1216440 :             computeMixingMatricesISM( nchan_transport, num_wave, nchan_out_woLFE, response_matrix, direct_power, cx_diag[bin_idx], cy_diag, proto_matrix, 1,
     288     1216440 :                                       PARAM_MC_REG_SX, PARAM_MC_REG_GHAT, mixing_matrix[bin_idx] );
     289             :         }
     290             :     }
     291             : 
     292       20274 :     return;
     293             : }
     294             : 
     295             : 
     296      324390 : 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      324390 :     tmp_1 = hParamIsmDec->hParamIsmRendering->interpolator[interpolator_idx];
     313             : 
     314    19787790 :     for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
     315             :     {
     316             :         /* smooth the mixing matrix */
     317   205333920 :         for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ )
     318             :         {
     319   557611560 :             for ( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ )
     320             :             {
     321   371741040 :                 mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][outchIdx + inchIdx * num_ch_LS] +
     322   371741040 :                                        ( 1 - tmp_1 ) * hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * num_ch_LS];
     323             : 
     324   371741040 :                 Cldfb_RealBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[inchIdx][bin_idx];
     325   371741040 :                 Cldfb_ImagBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[inchIdx][bin_idx];
     326             :             }
     327             :         }
     328             :     }
     329             : 
     330      324390 :     return;
     331             : }
     332             : 
     333             : 
     334         954 : 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       58194 :     for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
     345             :     {
     346       57240 :         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         954 :     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         954 :     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         954 :     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          66 :         ivas_ism_get_proto_matrix( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix );
     363             :     }
     364             : 
     365             :     /* computation of interpolator*/
     366         954 :     ivas_ism_get_interpolator( subframe_nbslots, hParamIsmRendering->interpolator );
     367             : 
     368         954 :     return IVAS_ERR_OK;
     369             : }
     370             : 
     371             : 
     372       20274 : 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      243288 :     for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
     382             :     {
     383      223014 :         brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
     384      223014 :         brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
     385             : 
     386     1439454 :         for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
     387             :         {
     388     3649320 :             for ( inchIdx = 0; inchIdx < nchan_in; inchIdx++ )
     389             :             {
     390    25666200 :                 for ( outchIdx = 0; outchIdx < nchan_out; outchIdx++ )
     391             :                 {
     392    23233320 :                     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       20274 :     return;
     399             : }
     400             : 
     401             : 
     402             : /*-------------------------------------------------------------------------*
     403             :  * ivas_param_ism_dec_open()
     404             :  *
     405             :  * Open Param ISM handle
     406             :  *-------------------------------------------------------------------------*/
     407             : 
     408         960 : 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         960 :     error = IVAS_ERR_OK;
     421             : 
     422         960 :     push_wmops( "ivas_param_ism_dec_open" );
     423             : 
     424             :     /*-----------------------------------------------------------------*
     425             :      * prepare library opening
     426             :      *-----------------------------------------------------------------*/
     427             : 
     428         960 :     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         960 :     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         960 :     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         960 :     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         960 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     450         960 :     output_config = st_ivas->hDecoderConfig->output_config;
     451             : 
     452         960 :     ivas_param_ism_config( hParamIsmDec->hParamIsm, st_ivas->nchan_ism );
     453             : 
     454             :     /*-----------------------------------------------------------------*
     455             :      * set input parameters
     456             :      *-----------------------------------------------------------------*/
     457             : 
     458         960 :     hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );
     459         960 :     set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
     460         960 :     set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
     461         960 :     hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
     462         960 :     hSpatParamRendCom->subframes_rendered = 0;
     463         960 :     hSpatParamRendCom->slots_rendered = 0;
     464         960 :     hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
     465         960 :     hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
     466             : 
     467         960 :     hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS;
     468             : 
     469       12480 :     for ( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ )
     470             :     {
     471       11520 :         hParamIsmDec->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i];
     472             : 
     473       11520 :         if ( hParamIsmDec->hParamIsm->band_grouping[i] > hSpatParamRendCom->num_freq_bands )
     474             :         {
     475         225 :             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         960 :     if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     485             :     {
     486             :         /* nchan_out is essential for memory initialization for CLDFB Synthesis */
     487         141 :         st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism;
     488         141 :         st_ivas->hIntSetup.is_loudspeaker_setup = 1;
     489             :     }
     490             : 
     491         960 :     hOutSetup = st_ivas->hIntSetup;
     492             : 
     493         960 :     if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
     494             :     {
     495             :         /* Initialize Param ISM Rendering handle */
     496         954 :         if ( st_ivas->hDecoderConfig->Opt_tsm )
     497             :         {
     498         456 :             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         498 :             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        1026 :     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          69 :             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          66 :         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         960 :     set_zero( hParamIsmDec->azimuth_values, MAX_NUM_OBJECTS );
     524         960 :     set_zero( hParamIsmDec->elevation_values, MAX_NUM_OBJECTS );
     525             : 
     526         960 :     hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
     527         960 :     hSpatParamRendCom->dirac_bs_md_write_idx = 0;
     528         960 :     hSpatParamRendCom->dirac_read_idx = 0;
     529             : 
     530         960 :     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         747 :         if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK )
     533             :         {
     534           0 :             return error;
     535             :         }
     536             : 
     537         747 :         if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK )
     538             :         {
     539           0 :             return error;
     540             :         }
     541             :     }
     542             : 
     543         960 :     st_ivas->hISMDTX.dtx_flag = 0;
     544             : 
     545         960 :     st_ivas->hParamIsmDec = hParamIsmDec;
     546         960 :     st_ivas->hSpatParamRendCom = hSpatParamRendCom;
     547             : 
     548         960 :     granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs );
     549             : 
     550         960 :     if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE )
     551         954 :     {
     552         954 :         int16_t nchan_transport = st_ivas->nchan_transport;
     553         954 :         int16_t nchan_full = 0;
     554             : 
     555         954 :         if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
     556             :         {
     557         747 :             nchan_full = nchan_transport;
     558         747 :             hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
     559         747 :             hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
     560             :         }
     561             :         else
     562             :         {
     563             :             int16_t n_slots_to_alloc;
     564         207 :             if ( st_ivas->hDecoderConfig->Opt_tsm == 1 )
     565             :             {
     566           6 :                 n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS;
     567             :             }
     568             :             else
     569             :             {
     570         201 :                 n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES;
     571             :             }
     572         207 :             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         207 :             set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
     578             : 
     579         207 :             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         207 :             set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
     584             :         }
     585             : 
     586         954 :         if ( st_ivas->hTcBuffer == NULL )
     587             :         {
     588          45 :             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           6 :         hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
     597           6 :         hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
     598           6 :         if ( st_ivas->hTcBuffer == NULL )
     599             :         {
     600           6 :             int16_t nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out;
     601             : 
     602           6 :             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         960 :     pop_wmops();
     610         960 :     return error;
     611             : }
     612             : 
     613             : 
     614             : /*-------------------------------------------------------------------------*
     615             :  * ivas_param_ism_dec_close()
     616             :  *
     617             :  * Close Param ISM handle
     618             :  *-------------------------------------------------------------------------*/
     619             : 
     620        1140 : 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        1140 :     if ( hParamIsmDec_out != NULL && *hParamIsmDec_out != NULL )
     627             :     {
     628             :         PARAM_ISM_DEC_HANDLE hParamIsmDec;
     629         960 :         hParamIsmDec = *hParamIsmDec_out;
     630             : 
     631             :         /* Config & CLDFB */
     632         960 :         if ( hParamIsmDec->hParamIsm != NULL )
     633             :         {
     634         960 :             free( hParamIsmDec->hParamIsm );
     635         960 :             hParamIsmDec->hParamIsm = NULL;
     636             :         }
     637             : 
     638         960 :         if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
     639             :         {
     640             :             /* Param ISM Rendering */
     641         954 :             if ( hParamIsmDec->hParamIsmRendering->interpolator != NULL )
     642             :             {
     643         954 :                 free( hParamIsmDec->hParamIsmRendering->interpolator );
     644         954 :                 hParamIsmDec->hParamIsmRendering->interpolator = NULL;
     645             :             }
     646         954 :             if ( hParamIsmDec->hParamIsmRendering->proto_matrix != NULL )
     647             :             {
     648         954 :                 free( hParamIsmDec->hParamIsmRendering->proto_matrix );
     649         954 :                 hParamIsmDec->hParamIsmRendering->proto_matrix = NULL;
     650             :             }
     651             :         }
     652             : 
     653         960 :         if ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL )
     654             :         {
     655         207 :             free( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc );
     656         207 :             hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
     657             :         }
     658         960 :         if ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc != NULL )
     659             :         {
     660         207 :             free( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc );
     661         207 :             hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
     662             :         }
     663             : 
     664         960 :         if ( hParamIsmDec->hParamIsmRendering != NULL )
     665             :         {
     666         960 :             free( hParamIsmDec->hParamIsmRendering );
     667         960 :             hParamIsmDec->hParamIsmRendering = NULL;
     668             :         }
     669             : 
     670         960 :         free( *hParamIsmDec_out );
     671         960 :         *hParamIsmDec_out = NULL;
     672             :     }
     673             : 
     674        1140 :     if ( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL )
     675             :     {
     676         960 :         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         747 :             ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 );
     679         747 :             ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 );
     680             :         }
     681             : 
     682         960 :         free( *hSpatParamRendCom_out );
     683         960 :         *hSpatParamRendCom_out = NULL;
     684             :     }
     685             : 
     686        1140 :     return;
     687             : }
     688             : 
     689             : 
     690             : /*-------------------------------------------------------------------------*
     691             :  * ivas_ism_dec_digest_tc()
     692             :  *
     693             :  *
     694             :  *-------------------------------------------------------------------------*/
     695             : 
     696      251175 : void ivas_ism_dec_digest_tc(
     697             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
     698             : )
     699             : {
     700      251175 :     ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
     701             : 
     702      251175 :     if ( st_ivas->renderer_type == RENDERER_TD_PANNING ||
     703      220875 :          st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
     704      201675 :          st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ||
     705      170841 :          st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ||
     706      161841 :          st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
     707      155829 :          st_ivas->renderer_type == RENDERER_OSBA_LS ||
     708      149829 :          st_ivas->renderer_type == RENDERER_OSBA_STEREO ||
     709      145629 :          ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) )
     710             :     {
     711             :         int16_t i;
     712             :         int16_t azimuth, elevation;
     713             : 
     714             :         /* we have a full frame interpolator, adapt it */
     715             :         /* for BE testing */
     716      128943 :         if ( ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) == st_ivas->hTcBuffer->n_samples_available )
     717             :         {
     718      128919 :             int16_t interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
     719             : 
     720      128919 :             if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
     721      109731 :                  st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
     722      103725 :                  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 ) )
     723             :             {
     724       65028 :                 st_ivas->hIsmRendererData->interpolator[0] = 0.0f;
     725    57919680 :                 for ( i = 1; i < interpolator_length; i++ )
     726             :                 {
     727    57854652 :                     st_ivas->hIsmRendererData->interpolator[i] = st_ivas->hIsmRendererData->interpolator[i - 1] + 1.f / ( interpolator_length - 1 );
     728             :                 }
     729             :             }
     730             :             else
     731             :             {
     732    57413331 :                 for ( i = 0; i < interpolator_length; i++ )
     733             :                 {
     734    57349440 :                     st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length - 1 );
     735             :                 }
     736             :             }
     737             :         }
     738             :         else
     739             :         {
     740          24 :             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 );
     741             :         }
     742      128943 :         st_ivas->hIsmRendererData->interp_offset = 0;
     743             : 
     744             :         /* also get the gains here */
     745      530349 :         for ( i = 0; i < st_ivas->nchan_ism; i++ )
     746             :         {
     747      401406 :             mvr2r( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmRendererData->prev_gains[i], MAX_OUTPUT_CHANNELS );
     748             : 
     749      401406 :             if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_STEREO )
     750             :             {
     751       49200 :                 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] );
     752       49200 :                 v_multc( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_gain, st_ivas->hIsmRendererData->gains[i], CPE_CHANNELS );
     753             :             }
     754             :             else
     755             :             {
     756             :                 // TODO tmu review when #215 is resolved
     757      352206 :                 azimuth = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_azimuth + 0.5f );
     758      352206 :                 elevation = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_elevation + 0.5f );
     759             : 
     760      352206 :                 if ( ( st_ivas->renderer_type == RENDERER_TD_PANNING ||
     761      293706 :                        st_ivas->renderer_type == RENDERER_OSBA_LS ||
     762      278706 :                        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 ) ) &&
     763      175326 :                      st_ivas->hCombinedOrientationData == NULL )
     764             :                 {
     765      175326 :                     if ( st_ivas->hIntSetup.is_planar_setup )
     766             :                     {
     767             :                         /* If no elevation support in output format, then rendering should be done with zero elevation */
     768       33000 :                         elevation = 0;
     769             :                     }
     770             : 
     771      175326 :                     if ( st_ivas->hEFAPdata != NULL )
     772             :                     {
     773      175326 :                         efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], azimuth, elevation, EFAP_MODE_EFAP );
     774      175326 :                         v_multc( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmMetaData[i]->edited_gain, st_ivas->hIsmRendererData->gains[i], st_ivas->hEFAPdata->numSpk );
     775             :                     }
     776             :                 }
     777      176880 :                 else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
     778      115692 :                           st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
     779      100656 :                           st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
     780             :                 {
     781             :                     /*get HOA gets for direction (ACN/SN3D)*/
     782      176880 :                     ivas_dirac_dec_get_response( azimuth, elevation, st_ivas->hIsmRendererData->gains[i], st_ivas->hIntSetup.ambisonics_order );
     783      176880 :                     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 ) );
     784             :                 }
     785             :             }
     786             :         }
     787             :     }
     788             : 
     789      251175 :     return;
     790             : }
     791             : 
     792             : 
     793             : /*-------------------------------------------------------------------------*
     794             :  * ivas_param_ism_dec_digest_tc()
     795             :  *
     796             :  *
     797             :  *-------------------------------------------------------------------------*/
     798             : 
     799       20274 : void ivas_param_ism_dec_digest_tc(
     800             :     Decoder_Struct *st_ivas,    /* i/o: IVAS decoder handle                                       */
     801             :     const uint16_t nCldfbSlots, /* i  : number of CLDFB slots in transport channels               */
     802             :     float *p_data_f[]           /* i/o: synthesized core-coder transport channels/DirAC output    */
     803             : )
     804             : {
     805             :     int16_t ch, slot_idx, output_frame;
     806             :     int16_t num_freq_bands, cldfb_ch, n_ch_cldfb;
     807             :     float *cldfb_real_buffer, *cldfb_imag_buffer;
     808             : 
     809             :     /* Initialization */
     810       20274 :     num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands;
     811       20274 :     output_frame = nCldfbSlots * num_freq_bands;
     812       20274 :     n_ch_cldfb = st_ivas->hTcBuffer->nchan_transport_jbm - st_ivas->hTcBuffer->nchan_buffer_full;
     813             : 
     814       20274 :     cldfb_real_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc;
     815       20274 :     cldfb_imag_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc;
     816             : 
     817       20274 :     ivas_ism_param_dec_tc_gain_adjust( st_ivas, output_frame, output_frame / 2, p_data_f );
     818             : 
     819             :     /* CLDFB Analysis */
     820       60822 :     for ( ch = 0, cldfb_ch = 0; cldfb_ch < n_ch_cldfb; cldfb_ch++, ch++ )
     821             :     {
     822      689328 :         for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
     823             :         {
     824      648780 :             cldfbAnalysis_ts( &( p_data_f[ch][num_freq_bands * slot_idx] ),
     825      648780 :                               &cldfb_real_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
     826      648780 :                               &cldfb_imag_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
     827             :                               num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch] );
     828             :         }
     829             :     }
     830             : 
     831       20274 :     return;
     832             : }
     833             : 
     834             : 
     835             : /*-------------------------------------------------------------------------*
     836             :  * ivas_param_ism_dec_dequant_md()
     837             :  *
     838             :  *
     839             :  *-------------------------------------------------------------------------*/
     840             : 
     841       67563 : void ivas_param_ism_dec_dequant_md(
     842             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder handle     */
     843             : )
     844             : {
     845             :     /* De-quantization */
     846       67563 :     if ( !( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 || st_ivas->hDecoderConfig->ivas_total_brate == FRAME_NO_DATA ) )
     847             :     {
     848       61164 :         ivas_param_ism_dec_dequant_DOA( st_ivas->hParamIsmDec, st_ivas->nchan_ism );
     849       61164 :         ivas_param_ism_dec_dequant_powrat( st_ivas->hParamIsmDec );
     850       61164 :         st_ivas->hISMDTX.dtx_flag = 0;
     851             :     }
     852             :     else
     853             :     {
     854        6399 :         st_ivas->hISMDTX.dtx_flag = 1;
     855             :     }
     856             : 
     857       67563 :     return;
     858             : }
     859             : 
     860             : 
     861             : /*-------------------------------------------------------------------------*
     862             :  * ivas_param_ism_dec_prepare_renderer()
     863             :  *
     864             :  *
     865             :  *-------------------------------------------------------------------------*/
     866             : 
     867       20274 : void ivas_param_ism_dec_prepare_renderer(
     868             :     Decoder_Struct *st_ivas,   /* i/o: IVAS decoder handle                          */
     869             :     const uint16_t nCldfbSlots /* i  : number of CLDFB slots in transport channels  */
     870             : )
     871             : {
     872             :     int16_t ch, nchan_transport, nchan_out, nchan_out_woLFE, i;
     873             :     int16_t slot_idx, bin_idx;
     874             :     float ref_power[CLDFB_NO_CHANNELS_MAX];
     875             :     float cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX];
     876             :     /* Direct Response/EFAP Gains */
     877             :     float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN];
     878             :     PARAM_ISM_DEC_HANDLE hParamIsmDec;
     879             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
     880             : 
     881             :     /* Initialization */
     882       20274 :     hParamIsmDec = st_ivas->hParamIsmDec;
     883       20274 :     assert( hParamIsmDec );
     884       20274 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
     885       20274 :     assert( hSpatParamRendCom );
     886             : 
     887       20274 :     nchan_transport = st_ivas->nchan_transport;
     888             : 
     889       20274 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     890             :     {
     891        1629 :         nchan_out = st_ivas->nchan_ism;
     892        1629 :         nchan_out_woLFE = nchan_out;
     893        1629 :         st_ivas->hDecoderConfig->nchan_out = nchan_out;
     894             :     }
     895             :     else
     896             :     {
     897       18645 :         nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
     898       18645 :         nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
     899             :     }
     900             : 
     901             :     /* general setup */
     902       20274 :     ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator );
     903             : 
     904       20274 :     ivas_dirac_dec_set_md_map( st_ivas, nCldfbSlots );
     905             : 
     906             :     /* set buffers to zero */
     907     1236714 :     for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
     908             :     {
     909     1216440 :         set_zero( cx_diag[bin_idx], PARAM_ISM_MAX_DMX );
     910             :     }
     911       20274 :     set_zero( ref_power, CLDFB_NO_CHANNELS_MAX );
     912             : 
     913             :     /* obtain the direct response using EFAP */
     914       20274 :     if ( !( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) )
     915             :     {
     916       84210 :         for ( i = 0; i < st_ivas->nchan_ism; i++ )
     917             :         {
     918       65565 :             efap_determine_gains( st_ivas->hEFAPdata, direct_response[i], hParamIsmDec->edited_azimuth_values[i], hParamIsmDec->edited_elevation_values[i], EFAP_MODE_EFAP );
     919             :         }
     920             :     }
     921             :     else
     922             :     {
     923             :         int16_t j;
     924             : 
     925        8145 :         for ( i = 0; i < st_ivas->nchan_ism; i++ )
     926             :         {
     927       32580 :             for ( j = 0; j < nchan_out_woLFE; j++ )
     928             :             {
     929       26064 :                 if ( i == j )
     930             :                 {
     931        6516 :                     direct_response[i][j] = 1.0f;
     932             :                 }
     933             :                 else
     934             :                 {
     935       19548 :                     direct_response[i][j] = 0.0f;
     936             :                 }
     937             :             }
     938             :         }
     939             : 
     940        8145 :         for ( j = 0; j < nchan_out_woLFE; j++ )
     941             :         {
     942        6516 :             if ( hParamIsmDec->azimuth_values[j] > 0.0f )
     943             :             {
     944        2625 :                 hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 1.0f;
     945        2625 :                 hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.0f;
     946             :             }
     947             :             else
     948             :             {
     949        3891 :                 if ( hParamIsmDec->azimuth_values[j] < 0.0f )
     950             :                 {
     951        2835 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.0f;
     952        2835 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 1.0f;
     953             :                 }
     954             :                 else /* == 0.0f */
     955             :                 {
     956        1056 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.5f;
     957        1056 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.5f;
     958             :                 }
     959             :             }
     960             :         }
     961             :     }
     962             : 
     963       60822 :     for ( ch = 0; ch < nchan_transport; ch++ )
     964             :     {
     965             :         /* CLDFB Analysis */
     966      689328 :         for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
     967             :         {
     968      648780 :             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 );
     969             :         }
     970             :     }
     971             : 
     972             :     /* Obtain Mixing Matrix on a frame-level */
     973     1236714 :     for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
     974             :     {
     975     1216440 :         set_f( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE );
     976             :     }
     977             : 
     978             :     /* Compute mixing matrix */
     979       20274 :     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 );
     980             : 
     981       20274 :     return;
     982             : }
     983             : 
     984             : 
     985             : /*-------------------------------------------------------------------------*
     986             :  * ivas_ism_param_dec_tc_gain_adjust()
     987             :  *
     988             :  *
     989             :  *-------------------------------------------------------------------------*/
     990             : 
     991       20274 : static void ivas_ism_param_dec_tc_gain_adjust(
     992             :     Decoder_Struct *st_ivas,   /* i/o: IVAS decoder handle                                   */
     993             :     const int16_t nSamples,    /* i  : number of samples to be compensate                    */
     994             :     const int16_t nFadeLength, /* i  : length of the crossfade in samples                    */
     995             :     float *p_data_f[]          /* i  : synthesized core-coder transport channels/DirAC output*/
     996             : )
     997             : 
     998             : {
     999             :     int16_t i;
    1000             :     float gain, ene_tc, ene_sum, grad;
    1001             :     float last_gain;
    1002             : 
    1003       20274 :     ene_tc = 0.0f;
    1004       20274 :     ene_sum = 0.0f;
    1005       20274 :     last_gain = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain;
    1006             : 
    1007    19483674 :     for ( i = 0; i < nSamples; i++ )
    1008             :     {
    1009    19463400 :         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 */
    1010    19463400 :         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) */
    1011             :     }
    1012       20274 :     gain = sqrtf( ene_tc / ( ene_sum + EPSILON ) );
    1013       20274 :     if ( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 1 )
    1014             :     {
    1015             :         /* Smoothing */
    1016       20253 :         gain = 0.75f * gain + 0.25f * last_gain;
    1017             :         /* 10ms ramp */
    1018       20253 :         grad = ( gain - last_gain ) / (float) nFadeLength; /* slope between two consecutive gains, 480 samples length */
    1019     9741873 :         for ( i = 0; i < ( nFadeLength ); i++ )
    1020             :         {
    1021     9721620 :             p_data_f[0][i] *= ( last_gain + i * grad );
    1022     9721620 :             p_data_f[1][i] *= ( last_gain + i * grad );
    1023             :         }
    1024     9741873 :         for ( ; i < nSamples; i++ )
    1025             :         {
    1026     9721620 :             p_data_f[0][i] *= gain;
    1027     9721620 :             p_data_f[1][i] *= gain;
    1028             :         }
    1029             :     }
    1030             :     else
    1031             :     {
    1032       20181 :         for ( i = 0; i < nSamples; i++ )
    1033             :         {
    1034       20160 :             p_data_f[0][i] *= gain;
    1035       20160 :             p_data_f[1][i] *= gain;
    1036             :         }
    1037             :     }
    1038             : 
    1039       20274 :     st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain = gain;
    1040             : 
    1041       20274 :     return;
    1042             : }
    1043             : 
    1044             : 
    1045             : /*-------------------------------------------------------------------------*
    1046             :  * ivas_ism_param_dec_render_sf()
    1047             :  *
    1048             :  *
    1049             :  *-------------------------------------------------------------------------*/
    1050             : 
    1051       89319 : static void ivas_ism_param_dec_render_sf(
    1052             :     Decoder_Struct *st_ivas,
    1053             :     IVAS_OUTPUT_SETUP hSetup,
    1054             :     const int16_t nchan_transport,
    1055             :     const int16_t nchan_out,
    1056             :     const int16_t nchan_out_woLFE,
    1057             :     float *output_f[] /* o  : rendered time signal                                    */
    1058             : )
    1059             : {
    1060             :     int16_t ch, slot_idx, i, index_slot;
    1061             :     /* CLDFB Output Buffers */
    1062             :     float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    1063             :     float Cldfb_ImagBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
    1064             :     float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX];
    1065             :     float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX];
    1066             :     PARAM_ISM_DEC_HANDLE hParamIsmDec;
    1067             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    1068             :     int16_t slot_idx_start;
    1069             :     int16_t idx_in;
    1070             :     int16_t idx_lfe;
    1071             :     int16_t subframe_idx;
    1072             : 
    1073       89319 :     hParamIsmDec = st_ivas->hParamIsmDec;
    1074       89319 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1075       89319 :     slot_idx_start = hSpatParamRendCom->slots_rendered;
    1076       89319 :     subframe_idx = hSpatParamRendCom->subframes_rendered;
    1077             : 
    1078             :     /* Set some memories to zero */
    1079      954216 :     for ( ch = 0; ch < nchan_out_woLFE; ch++ )
    1080             :     {
    1081     3962739 :         for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    1082             :         {
    1083     3097842 :             set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
    1084     3097842 :             set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
    1085             :         }
    1086             :     }
    1087             : 
    1088      413709 :     for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    1089             :     {
    1090      324390 :         index_slot = slot_idx_start + slot_idx;
    1091             : 
    1092      973170 :         for ( ch = 0; ch < nchan_transport; ch++ )
    1093             :         {
    1094      648780 :             Cldfb_RealBuffer_in[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands];
    1095      648780 :             Cldfb_ImagBuffer_in[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands];
    1096             :         }
    1097             : 
    1098             :         /* Compute bandwise rendering to target LS using covariance rendering */
    1099      324390 :         ivas_param_ism_render_slot( hParamIsmDec, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in,
    1100      324390 :                                     Cldfb_RealBuffer, Cldfb_ImagBuffer, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, index_slot, slot_idx, nchan_out_woLFE, nchan_transport );
    1101             :     }
    1102             : 
    1103             :     /* CLDFB Synthesis */
    1104       89319 :     idx_in = 0;
    1105       89319 :     idx_lfe = 0;
    1106             : 
    1107     1037019 :     for ( ch = 0; ch < nchan_out; ch++ )
    1108             :     {
    1109      947700 :         if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) )
    1110             :         {
    1111       82803 :             set_zero( output_f[ch], hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands );
    1112       82803 :             if ( idx_lfe < ( hSetup.num_lfe - 1 ) )
    1113             :             {
    1114           0 :                 idx_lfe++;
    1115             :             }
    1116             :         }
    1117             :         else
    1118             :         {
    1119             :             float *RealBuffer[16];
    1120             :             float *ImagBuffer[16];
    1121             : 
    1122             :             /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
    1123     3962739 :             for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    1124             :             {
    1125     3097842 :                 RealBuffer[i] = Cldfb_RealBuffer[idx_in][i];
    1126     3097842 :                 ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i];
    1127             :             }
    1128             : 
    1129      864897 :             cldfbSynthesis( RealBuffer, ImagBuffer, output_f[ch], hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] );
    1130      864897 :             idx_in++;
    1131             :         }
    1132             :     }
    1133             : 
    1134       89319 :     hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx];
    1135       89319 :     hSpatParamRendCom->subframes_rendered++;
    1136             : 
    1137       89319 :     return;
    1138             : }
    1139             : 
    1140             : 
    1141             : /*-------------------------------------------------------------------------*
    1142             :  * ivas_param_ism_dec_render()
    1143             :  *
    1144             :  *
    1145             :  *-------------------------------------------------------------------------*/
    1146             : 
    1147       53361 : void ivas_param_ism_dec_render(
    1148             :     Decoder_Struct *st_ivas,         /* i/o: IVAS decoder handle                       */
    1149             :     const uint16_t nSamplesAsked,    /* i  : number of CLDFB slots requested           */
    1150             :     uint16_t *nSamplesRendered,      /* o  : number of CLDFB slots rendered            */
    1151             :     uint16_t *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render     */
    1152             :     float *output_f[]                /* o  : rendered time signal                      */
    1153             : )
    1154             : {
    1155             :     int16_t ch, slots_to_render, first_sf, last_sf, subframe_idx;
    1156             :     uint16_t slot_size, n_samples_sf;
    1157             :     PARAM_ISM_DEC_HANDLE hParamIsmDec;
    1158             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    1159             :     IVAS_OUTPUT_SETUP hSetup;
    1160             :     int16_t nchan_transport, nchan_out, nchan_out_woLFE;
    1161             :     float *output_f_local[MAX_OUTPUT_CHANNELS];
    1162             : 
    1163       53361 :     hParamIsmDec = st_ivas->hParamIsmDec;
    1164       53361 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1165       53361 :     hSetup = st_ivas->hIntSetup;
    1166             : #ifdef DEBUGGING
    1167             :     assert( hParamIsmDec );
    1168             :     assert( hSpatParamRendCom );
    1169             : #endif
    1170       53361 :     nchan_transport = st_ivas->nchan_transport;
    1171       53361 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
    1172             :     {
    1173        1629 :         nchan_out = st_ivas->nchan_ism;
    1174        1629 :         nchan_out_woLFE = nchan_out;
    1175        1629 :         st_ivas->hDecoderConfig->nchan_out = nchan_out;
    1176             :     }
    1177             :     else
    1178             :     {
    1179       51732 :         nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
    1180       51732 :         nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
    1181             :     }
    1182       53361 :     slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
    1183             : 
    1184             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    1185       53361 :     slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size );
    1186       53361 :     *nSamplesRendered = slots_to_render * slot_size;
    1187       53361 :     first_sf = hSpatParamRendCom->subframes_rendered;
    1188       53361 :     last_sf = first_sf;
    1189             : 
    1190      142680 :     while ( slots_to_render > 0 )
    1191             :     {
    1192       89319 :         slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf];
    1193       89319 :         last_sf++;
    1194             :     }
    1195             : #ifdef DEBUGGING
    1196             :     assert( slots_to_render == 0 );
    1197             : #endif
    1198             : 
    1199      638661 :     for ( ch = 0; ch < nchan_out; ch++ )
    1200             :     {
    1201      585300 :         output_f_local[ch] = &output_f[ch][0];
    1202             :     }
    1203             : 
    1204      142680 :     for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    1205             :     {
    1206       89319 :         ivas_ism_param_dec_render_sf( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local );
    1207       89319 :         n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size;
    1208     1037019 :         for ( ch = 0; ch < nchan_out; ch++ )
    1209             :         {
    1210      947700 :             output_f_local[ch] += n_samples_sf;
    1211             :         }
    1212             :     }
    1213             : 
    1214       53361 :     if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots )
    1215             :     {
    1216             :         /* copy the memories */
    1217             :         /* store mixing matrix for next subframe */
    1218       20274 :         ivas_param_ism_update_mixing_matrix( hParamIsmDec, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, nchan_transport, nchan_out_woLFE );
    1219             : 
    1220             :         /* store MetaData parameters */
    1221       92355 :         for ( ch = 0; ch < st_ivas->nchan_ism; ch++ )
    1222             :         {
    1223       72081 :             if ( st_ivas->hParamIsmDec->azimuth_values[ch] > 180.0f )
    1224             :             {
    1225           0 :                 st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->edited_azimuth_values[ch] - 360.0f;
    1226             :             }
    1227             :             else
    1228             :             {
    1229       72081 :                 st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->edited_azimuth_values[ch];
    1230             :             }
    1231       72081 :             st_ivas->hIsmMetaData[ch]->elevation = st_ivas->hParamIsmDec->edited_elevation_values[ch];
    1232             :         }
    1233             :     }
    1234             : 
    1235       53361 :     *nSamplesAvailableNext = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size;
    1236             : 
    1237       53361 :     return;
    1238             : }
    1239             : 
    1240             : 
    1241             : /*-------------------------------------------------------------------------*
    1242             :  * ivas_param_ism_params_to_masa_param_mapping()
    1243             :  *
    1244             :  *
    1245             :  *-------------------------------------------------------------------------*/
    1246             : 
    1247       32865 : void ivas_param_ism_params_to_masa_param_mapping(
    1248             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
    1249             : )
    1250             : {
    1251             :     PARAM_ISM_DEC_HANDLE hParamIsmDec;
    1252             :     SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
    1253             :     int16_t nBins;
    1254             :     int16_t band_idx, bin_idx, sf_idx;
    1255             :     int16_t brange[2];
    1256             :     int16_t azimuth[2];
    1257             :     int16_t elevation[2];
    1258             :     float power_ratio[2];
    1259             :     MASA_ISM_DATA_HANDLE hMasaIsmData;
    1260             :     int16_t obj;
    1261             :     int16_t obj_idx;
    1262             : 
    1263       32865 :     hParamIsmDec = st_ivas->hParamIsmDec;
    1264       32865 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1265       32865 :     hMasaIsmData = st_ivas->hMasaIsmData;
    1266       32865 :     nBins = hSpatParamRendCom->num_freq_bands;
    1267             : 
    1268       32865 :     if ( st_ivas->hISMDTX.dtx_flag )
    1269             :     {
    1270             :         float energy_ratio;
    1271         792 :         energy_ratio = powf( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence, 2.0f );
    1272             : 
    1273         792 :         hSpatParamRendCom->numSimultaneousDirections = 1;
    1274         792 :         azimuth[0] = (int16_t) roundf( hParamIsmDec->azimuth_values[0] );
    1275         792 :         elevation[0] = (int16_t) roundf( hParamIsmDec->elevation_values[0] );
    1276             : 
    1277        3960 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1278             :         {
    1279      193248 :             for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
    1280             :             {
    1281      190080 :                 hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
    1282      190080 :                 hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
    1283             : 
    1284      190080 :                 hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = energy_ratio;
    1285             : 
    1286      190080 :                 hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
    1287      190080 :                 hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
    1288             :             }
    1289             :         }
    1290             :     }
    1291             :     else
    1292             :     {
    1293       32073 :         hSpatParamRendCom->numSimultaneousDirections = 2;
    1294      384876 :         for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
    1295             :         {
    1296      352803 :             brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
    1297      352803 :             brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
    1298             : 
    1299      352803 :             azimuth[0] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] );
    1300      352803 :             elevation[0] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] );
    1301      352803 :             power_ratio[0] = hParamIsmDec->power_ratios[band_idx][0][0];
    1302             : 
    1303      352803 :             azimuth[1] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] );
    1304      352803 :             elevation[1] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] );
    1305      352803 :             power_ratio[1] = hParamIsmDec->power_ratios[band_idx][0][1];
    1306             : 
    1307     1764015 :             for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1308             :             {
    1309     8928492 :                 for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
    1310             :                 {
    1311     7517280 :                     hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
    1312     7517280 :                     hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
    1313     7517280 :                     hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = power_ratio[0];
    1314     7517280 :                     hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1];
    1315     7517280 :                     hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1];
    1316     7517280 :                     hSpatParamRendCom->energy_ratio2[sf_idx][bin_idx] = power_ratio[1];
    1317             :                 }
    1318             :             }
    1319             :         }
    1320             : 
    1321      160365 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1322             :         {
    1323     7645572 :             for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
    1324             :             {
    1325     7517280 :                 hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
    1326     7517280 :                 hSpatParamRendCom->spreadCoherence2[sf_idx][bin_idx] = 0.0f;
    1327     7517280 :                 hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
    1328             :             }
    1329             :         }
    1330             : 
    1331      153612 :         for ( obj = 0; obj < st_ivas->nchan_ism; obj++ )
    1332             :         {
    1333      607695 :             for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1334             :             {
    1335      486156 :                 hMasaIsmData->azimuth_ism[obj][sf_idx] = (int16_t) roundf( hParamIsmDec->azimuth_values[obj] );
    1336      486156 :                 hMasaIsmData->elevation_ism[obj][sf_idx] = (int16_t) roundf( hParamIsmDec->elevation_values[obj] );
    1337             :             }
    1338             : 
    1339      121539 :             hMasaIsmData->azimuth_ism_edited[obj] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[obj] );
    1340      121539 :             hMasaIsmData->elevation_ism_edited[obj] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[obj] );
    1341             : 
    1342      607695 :             for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1343             :             {
    1344      486156 :                 set_zero( hMasaIsmData->energy_ratio_ism[obj][sf_idx], CLDFB_NO_CHANNELS_MAX );
    1345             :             }
    1346             :         }
    1347             : 
    1348       96219 :         for ( obj = 0; obj < MAX_PARAM_ISM_WAVE; obj++ )
    1349             :         {
    1350      769752 :             for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
    1351             :             {
    1352      705606 :                 brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
    1353      705606 :                 brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
    1354             : 
    1355      705606 :                 obj_idx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][obj];
    1356      705606 :                 power_ratio[obj] = hParamIsmDec->power_ratios[band_idx][0][obj];
    1357             : 
    1358     3528030 :                 for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1359             :                 {
    1360    17856984 :                     for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
    1361             :                     {
    1362    15034560 :                         hMasaIsmData->energy_ratio_ism[obj_idx][sf_idx][bin_idx] = power_ratio[obj];
    1363             :                     }
    1364             :                 }
    1365             :             }
    1366             :         }
    1367             :     }
    1368             : 
    1369       32865 :     return;
    1370             : }

Generated by: LCOV version 1.14