diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 9d842f9b37eba0ba9ac5e8dd640e0bccd524bbf2..b803c9860a4b925dff01c59baa9489b08ce52ee9 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1458,12 +1458,17 @@ typedef enum /*----------------------------------------------------------------------------------* * Amplitude Panning (EFAP, VBAP) constants *----------------------------------------------------------------------------------*/ - +#ifndef FIX_1050_EFAP_ALLOC #define PANNING_AZI_RESOLUTION 2 #define PANNING_ELE_RESOLUTION 5 +#endif #define EFAP_MAX_CHAN_NUM 5 /* Maximum number of channels that constitute a polygon, 4 or 5 */ +#ifdef FIX_1050_EFAP_ALLOC +#define EFAP_MAX_POLY_SET 54 /* Upper bound on number of polygons; found to be 54 in the worst case for a speaker setup of 16.0 */ +#else #define EFAP_MAX_POLY_SET 50 /* Upper bound on number of polygons; with a Speaker setup of 16.0, we obtain 44 polygons/triangles in the matlab implementation. */ +#endif #define EFAP_MODE_EFAP 0 /* EFAP Panning */ #define EFAP_MODE_EFIP 1 /* EFIP Panning */ diff --git a/lib_com/options.h b/lib_com/options.h index 6c4363df1775edf2e1fcac6b2c6b395dd8ed9ad1..8f854b63a67f2dff13b9f54f4d7d257fb9adc3dc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -175,6 +175,7 @@ #define FIX_989_TD_REND_ROM /* Eri: Clean-up for TD renderer and completion of ROM generation tool */ #define FIX_1068_ASAN_IN_MC_2_BINAURAL_ROOM_IR /* issue 1068 : Memory leak in MC to BINAURAL_ROOM decoding with bitrate switching*/ +#define FIX_1050_EFAP_ALLOC /* FhG: issue 1050: reduction of memory allocated to EFAP handle */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index b890dd98e5c64f778d5a9a2e0b3f7b146210b313..743a99275c1ca97ead6d075dac7f00e4f15a47c5 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -66,7 +66,14 @@ ivas_error ivas_ism_renderer_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer\n" ) ); } +#ifdef FIX_1050_EFAP_ALLOC + if ( st_ivas->hIntSetup.is_loudspeaker_setup && + st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO && + st_ivas->hIntSetup.ls_azimuth != NULL && st_ivas->hIntSetup.ls_elevation != NULL && + st_ivas->hEFAPdata == NULL ) +#else if ( st_ivas->hIntSetup.is_loudspeaker_setup && st_ivas->hIntSetup.ls_azimuth != NULL && st_ivas->hIntSetup.ls_elevation != NULL && st_ivas->hEFAPdata == NULL ) +#endif { if ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth, st_ivas->hIntSetup.ls_elevation, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 3caf13783fceb33c2dcd00f8a586084a275788f2..5be932d60f8fa13bf1d8890f7d0dd5ee07dcd299 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -38,6 +38,9 @@ #include "prot.h" #include "ivas_prot.h" #include "ivas_prot_rend.h" +#ifdef FIX_1050_EFAP_ALLOC +#include "ivas_rom_rend.h" +#endif #include "ivas_stat_dec.h" #ifdef DEBUGGING #include "debug.h" @@ -51,6 +54,12 @@ #define EFAP_MAX_SIZE_TMP_BUFF 30 #define EFAP_MAX_GHOST_LS 5 /* Maximum number of ghost Loudspeakers, for memory allocation purpose */ #define POLY_THRESH 1e-4f +#ifdef FIX_1050_EFAP_ALLOC +#ifdef DEBUG_EFAP_POLY_TOFILE +#define PANNING_AZI_RESOLUTION 2 +#define PANNING_ELE_RESOLUTION 5 +#endif +#endif /*-----------------------------------------------------------------------* @@ -147,6 +156,9 @@ ivas_error efap_init_data( ) { /* Handle instance declaration */ +#ifdef FIX_1050_EFAP_ALLOC + int8_t polyset_size; +#endif EFAP *efap; ivas_error error; @@ -163,13 +175,13 @@ ivas_error efap_init_data( * Allocate memory *-----------------------------------------------------------------*/ - /* Memory Allocations for efap */ + /* Memory allocation for main EFAP structure */ if ( ( efap = (EFAP *) malloc( sizeof( EFAP ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP handle\n" ) ); } - /* Memory Allocation and update for aziSpk & eleSpk arrays*/ + /* Memory allocation and update for aziSpk & eleSpk arrays*/ if ( ( efap->aziSpk = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP speaker azimuths\n" ) ); @@ -179,7 +191,7 @@ ivas_error efap_init_data( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP speaker elevations\n" ) ); } - /* Memory Allocation for vertexArray */ + /* Memory allocation for vertexArray */ if ( ( efap->vtxData.vertexArray = (EFAP_VERTEX *) malloc( ( num_speaker_nodes + EFAP_MAX_GHOST_LS ) * sizeof( EFAP_VERTEX ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP Vertex Array\n" ) ); @@ -190,6 +202,22 @@ ivas_error efap_init_data( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP bufferS\n" ) ); } +#ifdef FIX_1050_EFAP_ALLOC + /* get upper bound of number of polygons required */ + polyset_size = efap_poly_limit[num_speaker_nodes - 1]; + + /* Memory allocation for the polyset array */ + if ( ( efap->polyData.polysetArray = (EFAP_POLYSET *) malloc( polyset_size * sizeof( EFAP_POLYSET ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP bufferS\n" ) ); + } + + /* Memory allocation for the triangle array */ + if ( ( efap->polyData.triArray = (EFAP_LS_TRIANGLE *) malloc( polyset_size * sizeof( EFAP_LS_TRIANGLE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP bufferS\n" ) ); + } +#endif /*-----------------------------------------------------------------* * Initialize values @@ -333,6 +361,14 @@ void efap_free_data( free( ( *hEFAPdata )->vtxData.vtxOrder ); ( *hEFAPdata )->vtxData.vtxOrder = NULL; +#ifdef FIX_1050_EFAP_ALLOC + + free( ( *hEFAPdata )->polyData.polysetArray ); + ( *hEFAPdata )->vtxData.vtxOrder = NULL; + + free( ( *hEFAPdata )->polyData.triArray ); + ( *hEFAPdata )->vtxData.vtxOrder = NULL; +#endif free( ( *hEFAPdata )->bufferLong ); ( *hEFAPdata )->bufferLong = NULL; @@ -401,7 +437,11 @@ static ivas_error poly_init( if ( efap->vtxData.vertexArray[n].ele > 90.0 - 1e-6 || efap->vtxData.vertexArray[n].ele < 1e-6 - 90.0 ) { +#ifdef FIX_1050_EFAP_ALLOC + efap->vtxData.vertexArray[n].isNaN = true; +#else efap->vtxData.vertexArray[n].isNaN = 1; +#endif } } @@ -1493,8 +1533,12 @@ static void add_vertex( /* Final Idx */ vtxArray[pos].idx = (int16_t) idxAziTmp + 181 * (int16_t) idxEleTmp; - /* Setting the nan flag to 0 */ +/* Setting the nan flag to 0 */ +#ifdef FIX_1050_EFAP_ALLOC + vtxArray[pos].isNaN = false; +#else vtxArray[pos].isNaN = 0; +#endif /* Set the default downmix type */ vtxArray[pos].dmxType = dmxType; diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index 90a2feb86a4f0345bd215507bf8b7c2a47980684..61871f2e3391a149a0d0738ebe561fce18725d2b 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -388,8 +388,15 @@ const float ivas_reverb_default_DSR[IVAS_REVERB_DEFAULT_N_BANDS] = const float ls_azimuth_CICP1[1] = { 0.0f }; const float ls_elevation_CICP1[1] = { 0.0f }; +#ifdef FIX_1050_EFAP_ALLOC +/*----------------------------------------------------------------------------------* + * EFAP ROM tables + *----------------------------------------------------------------------------------*/ +const int8_t efap_poly_limit[MAX_OUTPUT_CHANNELS] = {22, 22, 22, 26, 30, 34, 36, 42, 42, 44, 47, 51, 52, 54, 54, 54}; + +#endif /*----------------------------------------------------------------------------------* * LS Renderer ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 9988962dbe62b3e3b8f10d54b735357bcc328701..2041585dbea6c5c5fa809fa90a91ed06366c9034 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -125,6 +125,15 @@ extern const float ls_azimuth_CICP1[1]; extern const float ls_elevation_CICP1[1]; +#ifdef FIX_1050_EFAP_ALLOC +/*----------------------------------------------------------------------------------* + * EFAP ROM tables + *----------------------------------------------------------------------------------*/ + +extern const int8_t efap_poly_limit[MAX_OUTPUT_CHANNELS]; + + +#endif /*----------------------------------------------------------------------------------* * LS Configuration Converter ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index d1f0fe4bca2b805fb03721aae9767df554c983ee..db5c99ab7052e03e4c3d9cc1a82a78e9b614b631 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -580,11 +580,15 @@ typedef struct ivas_binaural_rendering_conv_module_struct typedef struct EFAP_VERTEX { - float azi; /* azimuth of the loudspeaker */ - float ele; /* elevation of the loudspeaker */ - float pos[3]; /* [x y z] cartesian coordinate vector */ - int16_t idx; /* integer, that corresponds to the first index for the LS in the 1D output */ - int16_t isNaN; /* used to indicate if the vertex is a virtual speaker */ + float azi; /* azimuth of the loudspeaker */ + float ele; /* elevation of the loudspeaker */ + float pos[3]; /* [x y z] cartesian coordinate vector */ + int16_t idx; /* integer, that corresponds to the first index for the LS in the 1D output */ +#ifdef FIX_1050_EFAP_ALLOC + bool isNaN; /* used to indicate if the vertex is a virtual speaker */ +#else + int16_t isNaN; /* used to indicate if the vertex is a virtual speaker */ +#endif EFAP_VTX_DMX_TYPE dmxType; /* virtual speaker downmix type */ } EFAP_VERTEX; @@ -599,8 +603,12 @@ typedef struct EFAP_VERTEX_DATA typedef struct EFAP_POLYSET { - int16_t chan[EFAP_MAX_CHAN_NUM]; /* An array indicating the loudspeaker index of the polygon vertices */ - int16_t isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN */ + int16_t chan[EFAP_MAX_CHAN_NUM]; /* An array indicating the loudspeaker index of the polygon vertices */ +#ifdef FIX_1050_EFAP_ALLOC + bool isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN */ +#else + int16_t isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN */ +#endif int16_t numChan; /* An integer between 0 and EFAP_MAX_CHAN_NUM corresponding to the number of vertices of the polygon */ float polyAzi[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the azimuth of the channels */ float polyEle[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the elevation of the channels */ @@ -615,10 +623,18 @@ typedef struct EFAP_LS_TRIANGLE typedef struct EFAP_POLYSET_DATA { +#ifdef FIX_1050_EFAP_ALLOC + EFAP_POLYSET *polysetArray; /* Array of polygons */ +#else EFAP_POLYSET polysetArray[EFAP_MAX_POLY_SET]; /* Array of polygons */ - int16_t numPoly; /* Number of polygons */ +#endif + int16_t numPoly; /* Number of polygons */ +#ifdef FIX_1050_EFAP_ALLOC + EFAP_LS_TRIANGLE *triArray; /* Array of triangles */ +#else EFAP_LS_TRIANGLE triArray[EFAP_MAX_POLY_SET]; /* Array of triangles */ - int16_t numTri; /* Number of triangles */ +#endif + int16_t numTri; /* Number of triangles */ } EFAP_POLYSET_DATA;