LCOV - code coverage report
Current view: top level - lib_dec - ivas_ism_param_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 455 475 95.8 %
Date: 2025-09-14 08:49:17 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      269370 : 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      269370 :     hParamIsm = hParamIsmDec->hParamIsm;
      67             : 
      68      269370 :     assert( nchan_ism <= MAX_NUM_OBJECTS );
      69             : 
      70             :     /* Get the azimuth and elevation values */
      71     1242600 :     for ( i = 0; i < nchan_ism; i++ )
      72             :     {
      73      973230 :         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      973230 :         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      269370 :     return;
      78             : }
      79             : 
      80             : 
      81      269370 : 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      269370 :     hParamIsm = hParamIsmDec->hParamIsm;
      89             : 
      90             :     /* Get the power ratio values */
      91     3232440 :     for ( band_idx = 0; band_idx < hParamIsm->nbands; band_idx++ )
      92             :     {
      93     5926140 :         for ( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ )
      94             :         {
      95     2963070 :             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     2963070 :             hParamIsmDec->power_ratios[band_idx][slot_idx][1] = 1.0f - hParamIsmDec->power_ratios[band_idx][slot_idx][0];
      97             :         }
      98             :     }
      99             : 
     100      269370 :     return;
     101             : }
     102             : 
     103             : 
     104        4445 : static void ivas_ism_get_interpolator(
     105             :     const int16_t subframe_nbslots,
     106             :     float *interpolator )
     107             : {
     108        4445 :     int16_t interp_idx = 0;
     109             : 
     110      108285 :     for ( interp_idx = 0; interp_idx < subframe_nbslots; interp_idx++ )
     111             :     {
     112      103840 :         interpolator[interp_idx] = (float) ( interp_idx + 1 ) / (float) subframe_nbslots;
     113             :     }
     114             : 
     115        4445 :     return;
     116             : }
     117             : 
     118             : 
     119        1177 : 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        1177 :     switch ( nchan_transport )
     128             :     {
     129        1177 :         case 2:
     130             :         {
     131        1177 :             if ( hOutSetup.nchan_out_woLFE )
     132             :             {
     133       12172 :                 for ( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ )
     134             :                 {
     135       10995 :                     if ( hOutSetup.ls_azimuth[idx] > 0.0f )
     136             :                     {
     137        4909 :                         proto_matrix[idx] = 1.0f;
     138        4909 :                         proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0.0f;
     139             :                     }
     140        6086 :                     else if ( hOutSetup.ls_azimuth[idx] < 0.0f )
     141             :                     {
     142        4909 :                         proto_matrix[idx] = 0.0f;
     143        4909 :                         proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 1.0f;
     144             :                     }
     145             :                     else
     146             :                     {
     147        1177 :                         proto_matrix[idx] = 0.5f;
     148        1177 :                         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        1177 :             break;
     157             :         }
     158             : 
     159           0 :         default:
     160           0 :             assert( 0 && "Error: number of transport channels not supported" );
     161             :     }
     162             : 
     163        1177 :     return;
     164             : }
     165             : 
     166             : 
     167     3474052 : 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    41688624 :     for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
     182             :     {
     183    38214572 :         brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
     184    38214572 :         brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
     185   216659612 :         for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
     186             :         {
     187   178445040 :             tmp = 0.0f;
     188   178445040 :             tmp += ( Cldfb_RealBuffer_in[bin_idx] * Cldfb_RealBuffer_in[bin_idx] );
     189   178445040 :             tmp += ( Cldfb_ImagBuffer_in[bin_idx] * Cldfb_ImagBuffer_in[bin_idx] );
     190   178445040 :             cx_diag[bin_idx][ch] += tmp;
     191   178445040 :             ref_power[bin_idx] += tmp;
     192             :         }
     193             :     }
     194             : 
     195     3474052 :     return;
     196             : }
     197             : 
     198             : 
     199      108568 : 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      108568 :     proto_matrix = hParamIsmDec->hParamIsmRendering->proto_matrix;
     222             : 
     223      108568 :     assert( ( nchan_ism == 3 ) || ( nchan_ism == 4 ) );
     224      108568 :     assert( nchan_transport == 2 );
     225             : 
     226      108568 :     if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
     227             :     {
     228         851 :         num_wave = nchan_ism;
     229             :     }
     230             :     else
     231             :     {
     232      107717 :         num_wave = MAX_PARAM_ISM_WAVE;
     233             :     }
     234      108568 :     set_zero( response_matrix, PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS );
     235             : 
     236             :     /* loop over parameter bands to compute the mixing matrix */
     237     1302816 :     for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
     238             :     {
     239     1194248 :         brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
     240     1194248 :         brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
     241             : 
     242             :         /* Compute covaraince matrix from direct response*/
     243     3601466 :         for ( w = 0; w < num_wave; w++ )
     244             :         {
     245     2407218 :             set_zero( cy_diag_tmp[w], nchan_out_woLFE );
     246             : 
     247     2407218 :             if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
     248             :             {
     249       37444 :                 dir_res_ptr = direct_response[w];
     250             :             }
     251             :             else
     252             :             {
     253     2369774 :                 obj_indx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][w];
     254     2369774 :                 dir_res_ptr = direct_response[obj_indx];
     255             :             }
     256     2407218 :             mvr2r( dir_res_ptr, response_matrix + w * nchan_out_woLFE, nchan_out_woLFE );
     257             :             /* we only need the diagonal of Cy*/
     258     2407218 :             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     6770888 :         for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
     262             :         {
     263             : 
     264     5576640 :             set_zero( cy_diag, nchan_out_woLFE );
     265    16832040 :             for ( w = 0; w < num_wave; w++ )
     266             :             {
     267    11255400 :                 if ( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag )
     268             :                 {
     269      204240 :                     direct_power[w] = ( 1.0f / nchan_ism ) * ref_power[bin_idx];
     270             :                 }
     271             :                 else
     272             :                 {
     273    11051160 :                     direct_power[w] = hParamIsmDec->power_ratios[band_idx][0][w] * ref_power[bin_idx];
     274             :                 }
     275             : 
     276    11255400 :                 if ( direct_power[w] != 0.f )
     277             :                 {
     278    92178758 :                     for ( i = 0; i < nchan_out_woLFE; i++ )
     279             :                     {
     280    83140934 :                         cy_diag[i] += direct_power[w] * cy_diag_tmp[w][i];
     281             :                     }
     282             :                 }
     283    11255400 :                 direct_power[w] = sqrtf( direct_power[w] );
     284             :             }
     285             : 
     286             :             /* Compute mixing matrix */
     287     5576640 :             computeMixingMatricesISM( nchan_transport, num_wave, nchan_out_woLFE, response_matrix, direct_power, cx_diag[bin_idx], cy_diag, proto_matrix, 1,
     288     5576640 :                                       PARAM_MC_REG_SX, PARAM_MC_REG_GHAT, mixing_matrix[bin_idx] );
     289             :         }
     290             :     }
     291             : 
     292      108568 :     return;
     293             : }
     294             : 
     295             : 
     296     1737026 : 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     1737026 :     tmp_1 = hParamIsmDec->hParamIsmRendering->interpolator[interpolator_idx];
     313             : 
     314    90959546 :     for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
     315             :     {
     316             :         /* smooth the mixing matrix */
     317   913884000 :         for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ )
     318             :         {
     319  2473984440 :             for ( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ )
     320             :             {
     321  1649322960 :                 mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][outchIdx + inchIdx * num_ch_LS] +
     322  1649322960 :                                        ( 1 - tmp_1 ) * hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * num_ch_LS];
     323             : 
     324  1649322960 :                 Cldfb_RealBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[inchIdx][bin_idx];
     325  1649322960 :                 Cldfb_ImagBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[inchIdx][bin_idx];
     326             :             }
     327             :         }
     328             :     }
     329             : 
     330     1737026 :     return;
     331             : }
     332             : 
     333             : 
     334        4445 : 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      271145 :     for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
     345             :     {
     346      266700 :         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        4445 :     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        4445 :     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        4445 :     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        1177 :         ivas_ism_get_proto_matrix( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix );
     363             :     }
     364             : 
     365             :     /* computation of interpolator*/
     366        4445 :     ivas_ism_get_interpolator( subframe_nbslots, hParamIsmRendering->interpolator );
     367             : 
     368        4445 :     return IVAS_ERR_OK;
     369             : }
     370             : 
     371             : 
     372      108568 : 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     1302816 :     for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
     382             :     {
     383     1194248 :         brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
     384     1194248 :         brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
     385             : 
     386     6770888 :         for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
     387             :         {
     388    16729920 :             for ( inchIdx = 0; inchIdx < nchan_in; inchIdx++ )
     389             :             {
     390   114241080 :                 for ( outchIdx = 0; outchIdx < nchan_out; outchIdx++ )
     391             :                 {
     392   103087800 :                     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      108568 :     return;
     399             : }
     400             : 
     401             : 
     402             : /*-------------------------------------------------------------------------*
     403             :  * ivas_param_ism_dec_open()
     404             :  *
     405             :  * Open Param ISM handle
     406             :  *-------------------------------------------------------------------------*/
     407             : 
     408        4697 : 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        4697 :     error = IVAS_ERR_OK;
     421             : 
     422        4697 :     push_wmops( "ivas_param_ism_dec_open" );
     423             : 
     424             :     /*-----------------------------------------------------------------*
     425             :      * prepare library opening
     426             :      *-----------------------------------------------------------------*/
     427             : 
     428        4697 :     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        4697 :     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        4697 :     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        4697 :     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        4697 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
     450        4697 :     output_config = st_ivas->hDecoderConfig->output_config;
     451             : 
     452        4697 :     ivas_param_ism_config( hParamIsmDec->hParamIsm, st_ivas->nchan_ism );
     453             : 
     454             :     /*-----------------------------------------------------------------*
     455             :      * set input parameters
     456             :      *-----------------------------------------------------------------*/
     457             : 
     458        4697 :     hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );
     459        4697 :     set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
     460        4697 :     set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
     461        4697 :     hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
     462        4697 :     hSpatParamRendCom->subframes_rendered = 0;
     463        4697 :     hSpatParamRendCom->slots_rendered = 0;
     464        4697 :     hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
     465        4697 :     hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
     466             : 
     467        4697 :     hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS;
     468             : 
     469       61061 :     for ( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ )
     470             :     {
     471       56364 :         hParamIsmDec->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i];
     472             : 
     473       56364 :         if ( hParamIsmDec->hParamIsm->band_grouping[i] > hSpatParamRendCom->num_freq_bands )
     474             :         {
     475        3630 :             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        4697 :     if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     485             :     {
     486             :         /* nchan_out is essential for memory initialization for CLDFB Synthesis */
     487         539 :         st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism;
     488         539 :         st_ivas->hIntSetup.is_loudspeaker_setup = 1;
     489             :     }
     490             : 
     491        4697 :     hOutSetup = st_ivas->hIntSetup;
     492             : 
     493        4697 :     if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
     494             :     {
     495             :         /* Initialize Param ISM Rendering handle */
     496        4445 :         if ( st_ivas->hDecoderConfig->Opt_tsm )
     497             :         {
     498        2045 :             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        2400 :             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        5874 :     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        1305 :             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        1177 :         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        4697 :     set_zero( hParamIsmDec->azimuth_values, MAX_NUM_OBJECTS );
     524        4697 :     set_zero( hParamIsmDec->elevation_values, MAX_NUM_OBJECTS );
     525             : 
     526        4697 :     hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
     527        4697 :     hSpatParamRendCom->dirac_bs_md_write_idx = 0;
     528        4697 :     hSpatParamRendCom->dirac_read_idx = 0;
     529             : 
     530        4697 :     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        2729 :         if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK )
     533             :         {
     534           0 :             return error;
     535             :         }
     536             : 
     537        2729 :         if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK )
     538             :         {
     539           0 :             return error;
     540             :         }
     541             :     }
     542             : 
     543        4697 :     st_ivas->hISMDTX.dtx_flag = 0;
     544             : 
     545        4697 :     st_ivas->hParamIsmDec = hParamIsmDec;
     546        4697 :     st_ivas->hSpatParamRendCom = hSpatParamRendCom;
     547             : 
     548        4697 :     granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs );
     549             : 
     550        4697 :     if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE )
     551        4445 :     {
     552        4445 :         int16_t nchan_transport = st_ivas->nchan_transport;
     553        4445 :         int16_t nchan_full = 0;
     554             : 
     555        4445 :         if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
     556             :         {
     557        2729 :             nchan_full = nchan_transport;
     558        2729 :             hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
     559        2729 :             hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
     560             :         }
     561             :         else
     562             :         {
     563             :             int16_t n_slots_to_alloc;
     564        1716 :             if ( st_ivas->hDecoderConfig->Opt_tsm == 1 )
     565             :             {
     566         552 :                 n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS;
     567             :             }
     568             :             else
     569             :             {
     570        1164 :                 n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES;
     571             :             }
     572        1716 :             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        1716 :             set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
     578             : 
     579        1716 :             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        1716 :             set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands );
     584             :         }
     585             : 
     586        4445 :         if ( st_ivas->hTcBuffer == NULL )
     587             :         {
     588        1368 :             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         252 :         hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
     597         252 :         hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
     598         252 :         if ( st_ivas->hTcBuffer == NULL )
     599             :         {
     600         204 :             int16_t nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out;
     601             : 
     602         204 :             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        4697 :     pop_wmops();
     610        4697 :     return error;
     611             : }
     612             : 
     613             : 
     614             : /*-------------------------------------------------------------------------*
     615             :  * ivas_param_ism_dec_close()
     616             :  *
     617             :  * Close Param ISM handle
     618             :  *-------------------------------------------------------------------------*/
     619             : 
     620       19213 : 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       19213 :     if ( hParamIsmDec_out != NULL && *hParamIsmDec_out != NULL )
     627             :     {
     628             :         PARAM_ISM_DEC_HANDLE hParamIsmDec;
     629        4697 :         hParamIsmDec = *hParamIsmDec_out;
     630             : 
     631             :         /* Config & CLDFB */
     632        4697 :         if ( hParamIsmDec->hParamIsm != NULL )
     633             :         {
     634        4697 :             free( hParamIsmDec->hParamIsm );
     635        4697 :             hParamIsmDec->hParamIsm = NULL;
     636             :         }
     637             : 
     638        4697 :         if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) )
     639             :         {
     640             :             /* Param ISM Rendering */
     641        4445 :             if ( hParamIsmDec->hParamIsmRendering->interpolator != NULL )
     642             :             {
     643        4445 :                 free( hParamIsmDec->hParamIsmRendering->interpolator );
     644        4445 :                 hParamIsmDec->hParamIsmRendering->interpolator = NULL;
     645             :             }
     646        4445 :             if ( hParamIsmDec->hParamIsmRendering->proto_matrix != NULL )
     647             :             {
     648        4445 :                 free( hParamIsmDec->hParamIsmRendering->proto_matrix );
     649        4445 :                 hParamIsmDec->hParamIsmRendering->proto_matrix = NULL;
     650             :             }
     651             :         }
     652             : 
     653        4697 :         if ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL )
     654             :         {
     655        1716 :             free( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc );
     656        1716 :             hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL;
     657             :         }
     658        4697 :         if ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc != NULL )
     659             :         {
     660        1716 :             free( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc );
     661        1716 :             hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL;
     662             :         }
     663             : 
     664        4697 :         if ( hParamIsmDec->hParamIsmRendering != NULL )
     665             :         {
     666        4697 :             free( hParamIsmDec->hParamIsmRendering );
     667        4697 :             hParamIsmDec->hParamIsmRendering = NULL;
     668             :         }
     669             : 
     670        4697 :         free( *hParamIsmDec_out );
     671        4697 :         *hParamIsmDec_out = NULL;
     672             :     }
     673             : 
     674       19213 :     if ( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL )
     675             :     {
     676        4697 :         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        2729 :             ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 );
     679        2729 :             ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 );
     680             :         }
     681             : 
     682        4697 :         free( *hSpatParamRendCom_out );
     683        4697 :         *hSpatParamRendCom_out = NULL;
     684             :     }
     685             : 
     686       19213 :     return;
     687             : }
     688             : 
     689             : 
     690             : /*-------------------------------------------------------------------------*
     691             :  * ivas_ism_dec_digest_tc()
     692             :  *
     693             :  *
     694             :  *-------------------------------------------------------------------------*/
     695             : 
     696     2357271 : void ivas_ism_dec_digest_tc(
     697             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
     698             : )
     699             : {
     700     2357271 :     ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
     701             : 
     702     2357271 :     if ( st_ivas->renderer_type == RENDERER_TD_PANNING ||
     703     1985279 :          st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
     704     1782475 :          st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ||
     705     1551131 :          st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ||
     706     1444140 :          st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
     707     1297010 :          st_ivas->renderer_type == RENDERER_OSBA_LS ||
     708     1066056 :          st_ivas->renderer_type == RENDERER_OSBA_STEREO ||
     709     1008225 :          ( 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     1490481 :         if ( ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) == st_ivas->hTcBuffer->n_samples_available )
     717             :         {
     718     1490424 :             int16_t interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
     719             : 
     720     1490424 :             if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
     721     1287647 :                  st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
     722     1140531 :                  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      688228 :                 st_ivas->hIsmRendererData->interpolator[0] = 0.0f;
     725   497999360 :                 for ( i = 1; i < interpolator_length; i++ )
     726             :                 {
     727   497311132 :                     st_ivas->hIsmRendererData->interpolator[i] = st_ivas->hIsmRendererData->interpolator[i - 1] + 1.f / ( interpolator_length - 1 );
     728             :                 }
     729             :             }
     730             :             else
     731             :             {
     732   563029076 :                 for ( i = 0; i < interpolator_length; i++ )
     733             :                 {
     734   562226880 :                     st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length - 1 );
     735             :                 }
     736             :             }
     737             :         }
     738             :         else
     739             :         {
     740          57 :             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     1490481 :         st_ivas->hIsmRendererData->interp_offset = 0;
     743             : 
     744             :         /* also get the gains here */
     745     5488379 :         for ( i = 0; i < st_ivas->nchan_ism; i++ )
     746             :         {
     747     3997898 :             mvr2r( st_ivas->hIsmRendererData->gains[i], st_ivas->hIsmRendererData->prev_gains[i], MAX_OUTPUT_CHANNELS );
     748             : 
     749     3997898 :             if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_STEREO )
     750             :             {
     751      378298 :                 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      378298 :                 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     3619600 :                 azimuth = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_azimuth + 0.5f );
     758     3619600 :                 elevation = (int16_t) floorf( st_ivas->hIsmMetaData[i]->edited_elevation + 0.5f );
     759             : 
     760     3619600 :                 if ( ( st_ivas->renderer_type == RENDERER_TD_PANNING ||
     761     2847490 :                        st_ivas->renderer_type == RENDERER_OSBA_LS ||
     762     2283223 :                        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     2052230 :                      st_ivas->hCombinedOrientationData == NULL )
     764             :                 {
     765     2052230 :                     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      550616 :                         elevation = 0;
     769             :                     }
     770             : 
     771     2052230 :                     if ( st_ivas->hEFAPdata != NULL )
     772             :                     {
     773     2052230 :                         efap_determine_gains( st_ivas->hEFAPdata, st_ivas->hIsmRendererData->gains[i], azimuth, elevation, EFAP_MODE_EFAP );
     774     2052230 :                         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     1567370 :                 else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ||
     778     1005720 :                           st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
     779      645765 :                           st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
     780             :                 {
     781             :                     /*get HOA gets for direction (ACN/SN3D)*/
     782     1567370 :                     ivas_dirac_dec_get_response( azimuth, elevation, st_ivas->hIsmRendererData->gains[i], st_ivas->hIntSetup.ambisonics_order );
     783     1567370 :                     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     2357271 :     return;
     790             : }
     791             : 
     792             : 
     793             : /*-------------------------------------------------------------------------*
     794             :  * ivas_param_ism_dec_digest_tc()
     795             :  *
     796             :  *
     797             :  *-------------------------------------------------------------------------*/
     798             : 
     799      108568 : 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      108568 :     num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands;
     811      108568 :     output_frame = nCldfbSlots * num_freq_bands;
     812      108568 :     n_ch_cldfb = st_ivas->hTcBuffer->nchan_transport_jbm - st_ivas->hTcBuffer->nchan_buffer_full;
     813             : 
     814      108568 :     cldfb_real_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc;
     815      108568 :     cldfb_imag_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc;
     816             : 
     817      108568 :     ivas_ism_param_dec_tc_gain_adjust( st_ivas, output_frame, output_frame / 2, p_data_f );
     818             : 
     819             :     /* CLDFB Analysis */
     820      325704 :     for ( ch = 0, cldfb_ch = 0; cldfb_ch < n_ch_cldfb; cldfb_ch++, ch++ )
     821             :     {
     822     3691188 :         for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
     823             :         {
     824     3474052 :             cldfbAnalysis_ts( &( p_data_f[ch][num_freq_bands * slot_idx] ),
     825     3474052 :                               &cldfb_real_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
     826     3474052 :                               &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      108568 :     return;
     832             : }
     833             : 
     834             : 
     835             : /*-------------------------------------------------------------------------*
     836             :  * ivas_param_ism_dec_dequant_md()
     837             :  *
     838             :  *
     839             :  *-------------------------------------------------------------------------*/
     840             : 
     841      288609 : void ivas_param_ism_dec_dequant_md(
     842             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder handle     */
     843             : )
     844             : {
     845             :     /* De-quantization */
     846      288609 :     if ( !( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 || st_ivas->hDecoderConfig->ivas_total_brate == FRAME_NO_DATA ) )
     847             :     {
     848      269370 :         ivas_param_ism_dec_dequant_DOA( st_ivas->hParamIsmDec, st_ivas->nchan_ism );
     849      269370 :         ivas_param_ism_dec_dequant_powrat( st_ivas->hParamIsmDec );
     850      269370 :         st_ivas->hISMDTX.dtx_flag = 0;
     851             :     }
     852             :     else
     853             :     {
     854       19239 :         st_ivas->hISMDTX.dtx_flag = 1;
     855             :     }
     856             : 
     857      288609 :     return;
     858             : }
     859             : 
     860             : 
     861             : /*-------------------------------------------------------------------------*
     862             :  * ivas_param_ism_dec_prepare_renderer()
     863             :  *
     864             :  *
     865             :  *-------------------------------------------------------------------------*/
     866             : 
     867      108568 : 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      108568 :     hParamIsmDec = st_ivas->hParamIsmDec;
     883      108568 :     assert( hParamIsmDec );
     884      108568 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
     885      108568 :     assert( hSpatParamRendCom );
     886             : 
     887      108568 :     nchan_transport = st_ivas->nchan_transport;
     888             : 
     889      108568 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
     890             :     {
     891        9173 :         nchan_out = st_ivas->nchan_ism;
     892        9173 :         nchan_out_woLFE = nchan_out;
     893        9173 :         st_ivas->hDecoderConfig->nchan_out = nchan_out;
     894             :     }
     895             :     else
     896             :     {
     897       99395 :         nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
     898       99395 :         nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
     899             :     }
     900             : 
     901             :     /* general setup */
     902      108568 :     ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hParamIsmDec->hParamIsmRendering->interpolator );
     903             : 
     904      108568 :     ivas_dirac_dec_set_md_map( st_ivas, nCldfbSlots );
     905             : 
     906             :     /* set buffers to zero */
     907     6622648 :     for ( bin_idx = 0; bin_idx < CLDFB_NO_CHANNELS_MAX; bin_idx++ )
     908             :     {
     909     6514080 :         set_zero( cx_diag[bin_idx], PARAM_ISM_MAX_DMX );
     910             :     }
     911      108568 :     set_zero( ref_power, CLDFB_NO_CHANNELS_MAX );
     912             : 
     913             :     /* obtain the direct response using EFAP */
     914      108568 :     if ( !( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) )
     915             :     {
     916      447437 :         for ( i = 0; i < st_ivas->nchan_ism; i++ )
     917             :         {
     918      348042 :             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       43697 :         for ( i = 0; i < st_ivas->nchan_ism; i++ )
     926             :         {
     927      166116 :             for ( j = 0; j < nchan_out_woLFE; j++ )
     928             :             {
     929      131592 :                 if ( i == j )
     930             :                 {
     931       34524 :                     direct_response[i][j] = 1.0f;
     932             :                 }
     933             :                 else
     934             :                 {
     935       97068 :                     direct_response[i][j] = 0.0f;
     936             :                 }
     937             :             }
     938             :         }
     939             : 
     940       43697 :         for ( j = 0; j < nchan_out_woLFE; j++ )
     941             :         {
     942       34524 :             if ( hParamIsmDec->azimuth_values[j] > 0.0f )
     943             :             {
     944       14218 :                 hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 1.0f;
     945       14218 :                 hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.0f;
     946             :             }
     947             :             else
     948             :             {
     949       20306 :                 if ( hParamIsmDec->azimuth_values[j] < 0.0f )
     950             :                 {
     951       14687 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.0f;
     952       14687 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 1.0f;
     953             :                 }
     954             :                 else /* == 0.0f */
     955             :                 {
     956        5619 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[j] = 0.5f;
     957        5619 :                     hParamIsmDec->hParamIsmRendering->proto_matrix[nchan_out_woLFE + j] = 0.5f;
     958             :                 }
     959             :             }
     960             :         }
     961             :     }
     962             : 
     963      325704 :     for ( ch = 0; ch < nchan_transport; ch++ )
     964             :     {
     965             :         /* CLDFB Analysis */
     966     3691188 :         for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
     967             :         {
     968     3474052 :             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     5685208 :     for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ )
     974             :     {
     975     5576640 :         set_f( hParamIsmDec->hParamIsmRendering->mixing_matrix_lin[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE );
     976             :     }
     977             : 
     978             :     /* Compute mixing matrix */
     979      108568 :     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      108568 :     return;
     982             : }
     983             : 
     984             : 
     985             : /*-------------------------------------------------------------------------*
     986             :  * ivas_ism_param_dec_tc_gain_adjust()
     987             :  *
     988             :  *
     989             :  *-------------------------------------------------------------------------*/
     990             : 
     991      108568 : 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      108568 :     ene_tc = 0.0f;
    1004      108568 :     ene_sum = 0.0f;
    1005      108568 :     last_gain = st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain;
    1006             : 
    1007    89331088 :     for ( i = 0; i < nSamples; i++ )
    1008             :     {
    1009    89222520 :         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    89222520 :         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      108568 :     gain = sqrtf( ene_tc / ( ene_sum + EPSILON ) );
    1013      108568 :     if ( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 1 )
    1014             :     {
    1015             :         /* Smoothing */
    1016      107668 :         gain = 0.75f * gain + 0.25f * last_gain;
    1017             :         /* 10ms ramp */
    1018      107668 :         grad = ( gain - last_gain ) / (float) nFadeLength; /* slope between two consecutive gains, 480 samples length */
    1019    44459728 :         for ( i = 0; i < ( nFadeLength ); i++ )
    1020             :         {
    1021    44352060 :             p_data_f[0][i] *= ( last_gain + i * grad );
    1022    44352060 :             p_data_f[1][i] *= ( last_gain + i * grad );
    1023             :         }
    1024    44459728 :         for ( ; i < nSamples; i++ )
    1025             :         {
    1026    44352060 :             p_data_f[0][i] *= gain;
    1027    44352060 :             p_data_f[1][i] *= gain;
    1028             :         }
    1029             :     }
    1030             :     else
    1031             :     {
    1032      519300 :         for ( i = 0; i < nSamples; i++ )
    1033             :         {
    1034      518400 :             p_data_f[0][i] *= gain;
    1035      518400 :             p_data_f[1][i] *= gain;
    1036             :         }
    1037             :     }
    1038             : 
    1039      108568 :     st_ivas->hParamIsmDec->hParamIsm->last_dmx_gain = gain;
    1040             : 
    1041      108568 :     return;
    1042             : }
    1043             : 
    1044             : 
    1045             : /*-------------------------------------------------------------------------*
    1046             :  * ivas_ism_param_dec_render_sf()
    1047             :  *
    1048             :  *
    1049             :  *-------------------------------------------------------------------------*/
    1050             : 
    1051      458220 : 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      458220 :     hParamIsmDec = st_ivas->hParamIsmDec;
    1074      458220 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1075      458220 :     slot_idx_start = hSpatParamRendCom->slots_rendered;
    1076      458220 :     subframe_idx = hSpatParamRendCom->subframes_rendered;
    1077             : 
    1078             :     /* Set some memories to zero */
    1079     4682180 :     for ( ch = 0; ch < nchan_out_woLFE; ch++ )
    1080             :     {
    1081    20065406 :         for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    1082             :         {
    1083    15841446 :             set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
    1084    15841446 :             set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands );
    1085             :         }
    1086             :     }
    1087             : 
    1088     2195246 :     for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
    1089             :     {
    1090     1737026 :         index_slot = slot_idx_start + slot_idx;
    1091             : 
    1092     5211078 :         for ( ch = 0; ch < nchan_transport; ch++ )
    1093             :         {
    1094     3474052 :             Cldfb_RealBuffer_in[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands];
    1095     3474052 :             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     1737026 :         ivas_param_ism_render_slot( hParamIsmDec, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in,
    1100     1737026 :                                     Cldfb_RealBuffer, Cldfb_ImagBuffer, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, index_slot, slot_idx, nchan_out_woLFE, nchan_transport );
    1101             :     }
    1102             : 
    1103             :     /* CLDFB Synthesis */
    1104      458220 :     idx_in = 0;
    1105      458220 :     idx_lfe = 0;
    1106             : 
    1107     5103708 :     for ( ch = 0; ch < nchan_out; ch++ )
    1108             :     {
    1109     4645488 :         if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) )
    1110             :         {
    1111      421528 :             set_zero( output_f[ch], hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands );
    1112      421528 :             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    20065406 :             for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
    1124             :             {
    1125    15841446 :                 RealBuffer[i] = Cldfb_RealBuffer[idx_in][i];
    1126    15841446 :                 ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i];
    1127             :             }
    1128             : 
    1129     4223960 :             cldfbSynthesis( RealBuffer, ImagBuffer, output_f[ch], hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] );
    1130     4223960 :             idx_in++;
    1131             :         }
    1132             :     }
    1133             : 
    1134      458220 :     hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx];
    1135      458220 :     hSpatParamRendCom->subframes_rendered++;
    1136             : 
    1137      458220 :     return;
    1138             : }
    1139             : 
    1140             : 
    1141             : /*-------------------------------------------------------------------------*
    1142             :  * ivas_param_ism_dec_render()
    1143             :  *
    1144             :  *
    1145             :  *-------------------------------------------------------------------------*/
    1146             : 
    1147      158676 : 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      158676 :     hParamIsmDec = st_ivas->hParamIsmDec;
    1164      158676 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1165      158676 :     hSetup = st_ivas->hIntSetup;
    1166             : #ifdef DEBUGGING
    1167             :     assert( hParamIsmDec );
    1168             :     assert( hSpatParamRendCom );
    1169             : #endif
    1170      158676 :     nchan_transport = st_ivas->nchan_transport;
    1171      158676 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL )
    1172             :     {
    1173        9173 :         nchan_out = st_ivas->nchan_ism;
    1174        9173 :         nchan_out_woLFE = nchan_out;
    1175        9173 :         st_ivas->hDecoderConfig->nchan_out = nchan_out;
    1176             :     }
    1177             :     else
    1178             :     {
    1179      149503 :         nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe;
    1180      149503 :         nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE;
    1181             :     }
    1182      158676 :     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      158676 :     slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size );
    1186      158676 :     *nSamplesRendered = slots_to_render * slot_size;
    1187      158676 :     first_sf = hSpatParamRendCom->subframes_rendered;
    1188      158676 :     last_sf = first_sf;
    1189             : 
    1190      616896 :     while ( slots_to_render > 0 )
    1191             :     {
    1192      458220 :         slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf];
    1193      458220 :         last_sf++;
    1194             :     }
    1195             : #ifdef DEBUGGING
    1196             :     assert( slots_to_render == 0 );
    1197             : #endif
    1198             : 
    1199     1825500 :     for ( ch = 0; ch < nchan_out; ch++ )
    1200             :     {
    1201     1666824 :         output_f_local[ch] = &output_f[ch][0];
    1202             :     }
    1203             : 
    1204      616896 :     for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    1205             :     {
    1206      458220 :         ivas_ism_param_dec_render_sf( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local );
    1207      458220 :         n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size;
    1208     5103708 :         for ( ch = 0; ch < nchan_out; ch++ )
    1209             :         {
    1210     4645488 :             output_f_local[ch] += n_samples_sf;
    1211             :         }
    1212             :     }
    1213             : 
    1214      158676 :     if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots )
    1215             :     {
    1216             :         /* copy the memories */
    1217             :         /* store mixing matrix for next subframe */
    1218      108568 :         ivas_param_ism_update_mixing_matrix( hParamIsmDec, hParamIsmDec->hParamIsmRendering->mixing_matrix_lin, nchan_transport, nchan_out_woLFE );
    1219             : 
    1220             :         /* store MetaData parameters */
    1221      491134 :         for ( ch = 0; ch < st_ivas->nchan_ism; ch++ )
    1222             :         {
    1223      382566 :             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      382566 :                 st_ivas->hIsmMetaData[ch]->azimuth = st_ivas->hParamIsmDec->edited_azimuth_values[ch];
    1230             :             }
    1231      382566 :             st_ivas->hIsmMetaData[ch]->elevation = st_ivas->hParamIsmDec->edited_elevation_values[ch];
    1232             :         }
    1233             :     }
    1234             : 
    1235      158676 :     *nSamplesAvailableNext = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size;
    1236             : 
    1237      158676 :     return;
    1238             : }
    1239             : 
    1240             : 
    1241             : /*-------------------------------------------------------------------------*
    1242             :  * ivas_param_ism_params_to_masa_param_mapping()
    1243             :  *
    1244             :  *
    1245             :  *-------------------------------------------------------------------------*/
    1246             : 
    1247      122802 : 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      122802 :     hParamIsmDec = st_ivas->hParamIsmDec;
    1264      122802 :     hSpatParamRendCom = st_ivas->hSpatParamRendCom;
    1265      122802 :     hMasaIsmData = st_ivas->hMasaIsmData;
    1266      122802 :     nBins = hSpatParamRendCom->num_freq_bands;
    1267             : 
    1268      122802 :     if ( st_ivas->hISMDTX.dtx_flag )
    1269             :     {
    1270             :         float energy_ratio;
    1271        2042 :         energy_ratio = powf( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence, 2.0f );
    1272             : 
    1273        2042 :         hSpatParamRendCom->numSimultaneousDirections = 1;
    1274        2042 :         azimuth[0] = (int16_t) roundf( hParamIsmDec->azimuth_values[0] );
    1275        2042 :         elevation[0] = (int16_t) roundf( hParamIsmDec->elevation_values[0] );
    1276             : 
    1277       10210 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1278             :         {
    1279      471848 :             for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
    1280             :             {
    1281      463680 :                 hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
    1282      463680 :                 hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
    1283             : 
    1284      463680 :                 hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = energy_ratio;
    1285             : 
    1286      463680 :                 hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
    1287      463680 :                 hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
    1288             :             }
    1289             :         }
    1290             :     }
    1291             :     else
    1292             :     {
    1293      120760 :         hSpatParamRendCom->numSimultaneousDirections = 2;
    1294     1449120 :         for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
    1295             :         {
    1296     1328360 :             brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
    1297     1328360 :             brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
    1298             : 
    1299     1328360 :             azimuth[0] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] );
    1300     1328360 :             elevation[0] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] );
    1301     1328360 :             power_ratio[0] = hParamIsmDec->power_ratios[band_idx][0][0];
    1302             : 
    1303     1328360 :             azimuth[1] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] );
    1304     1328360 :             elevation[1] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] );
    1305     1328360 :             power_ratio[1] = hParamIsmDec->power_ratios[band_idx][0][1];
    1306             : 
    1307     6641800 :             for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1308             :             {
    1309    31913280 :                 for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
    1310             :                 {
    1311    26599840 :                     hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0];
    1312    26599840 :                     hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0];
    1313    26599840 :                     hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = power_ratio[0];
    1314    26599840 :                     hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1];
    1315    26599840 :                     hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1];
    1316    26599840 :                     hSpatParamRendCom->energy_ratio2[sf_idx][bin_idx] = power_ratio[1];
    1317             :                 }
    1318             :             }
    1319             :         }
    1320             : 
    1321      603800 :         for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1322             :         {
    1323    27082880 :             for ( bin_idx = 0; bin_idx < nBins; bin_idx++ )
    1324             :             {
    1325    26599840 :                 hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f;
    1326    26599840 :                 hSpatParamRendCom->spreadCoherence2[sf_idx][bin_idx] = 0.0f;
    1327    26599840 :                 hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0;
    1328             :             }
    1329             :         }
    1330             : 
    1331      574678 :         for ( obj = 0; obj < st_ivas->nchan_ism; obj++ )
    1332             :         {
    1333     2269590 :             for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1334             :             {
    1335     1815672 :                 hMasaIsmData->azimuth_ism[obj][sf_idx] = (int16_t) roundf( hParamIsmDec->azimuth_values[obj] );
    1336     1815672 :                 hMasaIsmData->elevation_ism[obj][sf_idx] = (int16_t) roundf( hParamIsmDec->elevation_values[obj] );
    1337             :             }
    1338             : 
    1339      453918 :             hMasaIsmData->azimuth_ism_edited[obj] = (int16_t) roundf( hParamIsmDec->edited_azimuth_values[obj] );
    1340      453918 :             hMasaIsmData->elevation_ism_edited[obj] = (int16_t) roundf( hParamIsmDec->edited_elevation_values[obj] );
    1341             : 
    1342     2269590 :             for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1343             :             {
    1344     1815672 :                 set_zero( hMasaIsmData->energy_ratio_ism[obj][sf_idx], CLDFB_NO_CHANNELS_MAX );
    1345             :             }
    1346             :         }
    1347             : 
    1348      362280 :         for ( obj = 0; obj < MAX_PARAM_ISM_WAVE; obj++ )
    1349             :         {
    1350     2898240 :             for ( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ )
    1351             :             {
    1352     2656720 :                 brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx];
    1353     2656720 :                 brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1];
    1354             : 
    1355     2656720 :                 obj_idx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][obj];
    1356     2656720 :                 power_ratio[obj] = hParamIsmDec->power_ratios[band_idx][0][obj];
    1357             : 
    1358    13283600 :                 for ( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
    1359             :                 {
    1360    63826560 :                     for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ )
    1361             :                     {
    1362    53199680 :                         hMasaIsmData->energy_ratio_ism[obj_idx][sf_idx][bin_idx] = power_ratio[obj];
    1363             :                     }
    1364             :                 }
    1365             :             }
    1366             :         }
    1367             :     }
    1368             : 
    1369      122802 :     return;
    1370             : }

Generated by: LCOV version 1.14