diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index b5c0a74941ca8ff268cdcd5a5790dc2dc1b37c6e..ec30ba914abcf9a8f2380edd61e171a58b0518cb 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1610,12 +1610,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 f2271d52751ceed54301ee4b81054a415f1a3eec..974b604bc49dcb9457b8bc8328b2e4c6a4599095 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -105,6 +105,7 @@ #define NONBE_1215_FIX_JBM_MAX_SCALING /* FhG: issue 1215: Fix assert hit in a specific VoIP decoder config. Caused by integer overflow in max scaling calculation. */ #define NONBE_FIX_991_PARAMBIN_BINARY_HRTF /* Nokia: issue #991: fix using of binary file HRTF in ParamBin (to activate when USE_NEW_HRTF_BINARY_FILE_FORMAT and FIX_777_COMBI_RENDER_CONFIG_FILE are on ) */ +#define FIX_1050_EFAP_ALLOC /* FhG: issue 1050: reduction of memory allocated to EFAP handle */ #define NONBE_FIX_1091_PMC_LOW_SIGNAL_BURSTS /* FhG: fix for #1091, fix limit calculation for the regularized inverse of Kx to avoid bursts in very low signals */ #define NONBE_FIX_1070_USAN_SEGFAULT_MC_TO_BIN_BTSW_HEADROT /* fix 1070 USAN: nullptr-with-offset and Segfaults in 7_1_4 to BINAURAL and BINAURAL_ROOM_REVERB decoding with bitrate switching and head rotation*/ diff --git a/lib_dec/ivas_ism_renderer_fx.c b/lib_dec/ivas_ism_renderer_fx.c index 8d141537dd112aaf8f1bd3eaf85314ed75f8f127..5ebae5c2fb8078ca51d20573189b587dc760583a 100644 --- a/lib_dec/ivas_ism_renderer_fx.c +++ b/lib_dec/ivas_ism_renderer_fx.c @@ -70,7 +70,15 @@ ivas_error ivas_ism_renderer_open_fx( test(); test(); test(); +#ifdef FIX_1050_EFAP_ALLOC + test(); + IF( st_ivas->hIntSetup.is_loudspeaker_setup && + st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO && + st_ivas->hIntSetup.ls_azimuth_fx != NULL && st_ivas->hIntSetup.ls_elevation_fx != NULL && + st_ivas->hEFAPdata == NULL ) +#else IF( st_ivas->hIntSetup.is_loudspeaker_setup && st_ivas->hIntSetup.ls_azimuth_fx != NULL && st_ivas->hIntSetup.ls_elevation_fx != NULL && st_ivas->hEFAPdata == NULL ) +#endif { IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { diff --git a/lib_rend/ivas_efap_fx.c b/lib_rend/ivas_efap_fx.c index 8afef5e39bc900aca9d59bdfd834cbab8482fbeb..bfe51a19ddd01d4ead1aa9e46b363ea7d9577915 100644 --- a/lib_rend/ivas_efap_fx.c +++ b/lib_rend/ivas_efap_fx.c @@ -37,6 +37,9 @@ #include "options.h" #include "prot_fx.h" #include "ivas_prot_rend_fx.h" +#ifdef FIX_1050_EFAP_ALLOC +#include "ivas_rom_rend.h" +#endif #include "ivas_stat_dec.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" @@ -49,13 +52,19 @@ #define EFAP_MAX_GHOST_LS 5 /* Maximum number of ghost Loudspeakers, for memory allocation purpose */ #define POLY_THRESH_Q29 53687LL // Q29 #define POLY_THRESH_Q28 26843 // Q28 -#define Q22_1 4194304 -#define Q22_45_DEG 188743680 -#define Q22_90_DEG 377487360 -#define Q22_180_DEG 754974720 -#define Q22_360_DEG 1509949440 -#define Q22_120_DEG 503316480 -#define Q22_240_DEG 1006632960 +#ifdef FIX_1050_EFAP_ALLOC +#ifdef DEBUG_EFAP_POLY_TOFILE +#define PANNING_AZI_RESOLUTION 2 +#define PANNING_ELE_RESOLUTION 5 +#endif +#endif +#define Q22_1 4194304 +#define Q22_45_DEG 188743680 +#define Q22_90_DEG 377487360 +#define Q22_180_DEG 754974720 +#define Q22_360_DEG 1509949440 +#define Q22_120_DEG 503316480 +#define Q22_240_DEG 1006632960 /*-----------------------------------------------------------------------* * Local function prototypes @@ -123,7 +132,10 @@ ivas_error efap_init_data_fx( const Word16 efap_mode /* i : indicates whether EFAP or EFIP is used */ ) { - /* Handle instance declaration */ +/* Handle instance declaration */ +#ifdef FIX_1050_EFAP_ALLOC + Word8 polyset_size; +#endif EFAP *efap; ivas_error error; @@ -142,7 +154,7 @@ ivas_error efap_init_data_fx( * 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" ) ); @@ -158,7 +170,7 @@ ivas_error efap_init_data_fx( 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" ) ); @@ -169,6 +181,22 @@ ivas_error efap_init_data_fx( { 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 @@ -332,6 +360,14 @@ void efap_free_data_fx( 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_fx ); ( *hEFAPdata )->bufferLong_fx = NULL; @@ -403,7 +439,11 @@ static ivas_error poly_init_fx( if ( GT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( Q22_90_DEG /*90.0 Q22*/ - 4 /*1e-6 Q22*/ ) ) || LT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( 4 /*1e-6 Q22*/ - Q22_90_DEG /*90.0 Q22*/ ) ) ) { +#ifdef FIX_1050_EFAP_ALLOC + efap->vtxData.vertexArray[n].isNaN = true; +#else efap->vtxData.vertexArray[n].isNaN = 1; +#endif move16(); } } @@ -1663,8 +1703,12 @@ static void add_vertex_fx( /* Final Idx */ vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); // q0 - /* 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 move16(); /* Set the default downmix type */ diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 6c966e4578a89ef5ef383f06fd5fdd07cf47308a..d05857e6056a8c12833354d1f934b699570aca95 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -114,6 +114,15 @@ extern const Word32 ivas_reverb_default_DSR_fx[]; /*Q-30*/ * Renderer SBA & MC enc/dec matrices *----------------------------------------------------------------------------------*/ +#ifdef FIX_1050_EFAP_ALLOC +/*----------------------------------------------------------------------------------* + * EFAP ROM tables + *----------------------------------------------------------------------------------*/ + +extern const Word8 efap_poly_limit[MAX_OUTPUT_CHANNELS]; + + +#endif /*----------------------------------------------------------------------------------* * LS Configuration Converter ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_rom_rend_fx.c b/lib_rend/ivas_rom_rend_fx.c index 6589adcf73587f10293187204be4bb40ac147f52..6cf454a8a5771b943e5f4303e00228dd7cc6d2a0 100644 --- a/lib_rend/ivas_rom_rend_fx.c +++ b/lib_rend/ivas_rom_rend_fx.c @@ -286,8 +286,15 @@ const Word32 ivas_reverb_default_DSR_fx[IVAS_REVERB_DEFAULT_N_BANDS] /*Q30*/ = * Renderer SBA & MC enc/dec matrices *----------------------------------------------------------------------------------*/ +#ifdef FIX_1050_EFAP_ALLOC +/*----------------------------------------------------------------------------------* + * EFAP ROM tables + *----------------------------------------------------------------------------------*/ + +const Word8 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_stat_rend.h b/lib_rend/ivas_stat_rend.h index 8723dcffd9331ff1afd110bef38f99d3be1a80ce..8fd13cdd412830f3b4273561d8a700013f723902 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -710,8 +710,12 @@ typedef struct EFAP_VERTEX Word32 ele; /* elevation of the loudspeaker */ /* Q22 */ Word32 pos[3]; /* [x y z] cartesian coordinate vector */ /* Q31 */ Word16 idx; /* integer, that corresponds to the first index for the LS in the 1D output */ - Word16 isNaN; /* used to indicate if the vertex is a virtual speaker */ - EFAP_VTX_DMX_TYPE dmxType; /* virtual speaker downmix type */ +#ifdef FIX_1050_EFAP_ALLOC + bool isNaN; /* used to indicate if the vertex is a virtual speaker */ +#else + Word16 isNaN; /* used to indicate if the vertex is a virtual speaker */ +#endif + EFAP_VTX_DMX_TYPE dmxType; /* virtual speaker downmix type */ } EFAP_VERTEX; @@ -724,8 +728,12 @@ typedef struct EFAP_VERTEX_DATA } EFAP_VERTEX_DATA; typedef struct EFAP_POLYSET { - Word16 chan[EFAP_MAX_CHAN_NUM]; /* An array indicating the loudspeaker index of the polygon vertices */ - Word16 isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN */ + Word16 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 + Word16 isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN */ +#endif Word16 numChan; /* An integer between 0 and EFAP_MAX_CHAN_NUM corresponding to the number of vertices of the polygon */ Word32 polyAzi[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the azimuth of the channels */ /* Q22 */ Word32 polyEle[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the elevation of the channels */ /* Q22 */ @@ -739,10 +747,18 @@ typedef struct EFAP_LS_TRIANGLE typedef struct EFAP_POLYSET_DATA { - EFAP_POLYSET polysetArray[EFAP_MAX_POLY_SET]; /* Array of polygons */ - Word16 numPoly; /* Number of polygons */ - EFAP_LS_TRIANGLE triArray[EFAP_MAX_POLY_SET]; /* Array of triangles */ - Word16 numTri; /* Number of triangles */ +#ifdef FIX_1050_EFAP_ALLOC + EFAP_POLYSET *polysetArray; /* Array of polygons */ +#else + EFAP_POLYSET polysetArray[EFAP_MAX_POLY_SET]; /* Array of polygons */ +#endif + Word16 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 */ +#endif + Word16 numTri; /* Number of triangles */ } EFAP_POLYSET_DATA;