From 607dd6e77a54c313c2e12587f5f3e5d8e9eb34a1 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 15 Apr 2026 11:17:33 +0200 Subject: [PATCH 1/6] [fix] efap code lint --- lib_com/options.h | 1 + lib_rend/ivas_efap.c | 83 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index cc75ea885..79bf8c0f9 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -170,6 +170,7 @@ /* any switch which is non-be wrt. TS 26.258 V3.0 */ #define FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API /* Expose Payload Type setting in RTP Header */ +#define FIX_1574_EFAP_CODE_LINT /* FhG: issue 1574: Code quality fixes in ivas_efap.c */ #define FIX_FLOAT_1569_REND_RENDER_CONFIG_CHECKS /* Nokia: float issue 1569: fix render config checks in renderer */ #define FIX_1571_BFI_COPY_ARRAY_CORRECT_LEN /* FhG: issue 1571: use correct channel signal length for copying signal to buffer */ diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index d7ec93ffd..849065f9f 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -39,7 +39,9 @@ #include "ivas_prot.h" #include "ivas_prot_rend.h" #include "ivas_rom_rend.h" +#ifndef FIX_1574_EFAP_CODE_LINT #include "ivas_stat_dec.h" +#endif #ifdef DEBUGGING #include "debug.h" #endif @@ -52,6 +54,9 @@ #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_1574_EFAP_CODE_LINT +#define MAX_AZI_GAP 1.f / 160.f /* Max azimuth tolerance to extend the LS setup in the horizontal plane */ +#endif #ifdef DEBUG_EFAP_POLY_TOFILE #define PANNING_AZI_RESOLUTION 2 #define PANNING_ELE_RESOLUTION 5 @@ -97,7 +102,11 @@ static void get_poly_select( EFAP_POLYSET_DATA *polyData ); * EFAP Utils *-----------------------------------------------------------------------*/ +#ifdef FIX_1574_EFAP_CODE_LINT +static void add_vertex( EFAP_VERTEX *vtxArray, const float azi, const float ele, const int16_t pos, const EFAP_VTX_DMX_TYPE dmxType ); +#else static void add_vertex( EFAP_VERTEX *vtxArray, const float azi, const float ele, const int16_t pos, const EFAP_VTX_DMX_TYPE ); +#endif static void efap_sort_s( int16_t *x, int16_t *idx, const int16_t len ); @@ -119,7 +128,11 @@ static void matrix_times_row( float mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TM static void tri_to_poly( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const int16_t numVtx, const int16_t numTri, int16_t sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], int16_t *outLengthPS, int16_t outLengthSorted[EFAP_MAX_POLY_SET] ); +#ifdef FIX_1574_EFAP_CODE_LINT +static int16_t compare_poly( int16_t *old_poly, int16_t lenOld, int16_t *new_poly, int16_t lenNew ); +#else static int16_t compare_poly( int16_t *old, int16_t lenOld, int16_t *new, int16_t lenNew ); +#endif static void sort_channels_vertex( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, int16_t channels[EFAP_MAX_CHAN_NUM], const int16_t lengthChannels, int16_t idxTri ); @@ -161,7 +174,11 @@ ivas_error efap_init_data( /* Basic init checks */ if ( !speaker_node_azi_deg || !speaker_node_ele_deg ) { +#ifdef FIX_1574_EFAP_CODE_LINT + *hEFAPdata = NULL; +#else hEFAPdata = NULL; +#endif return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "EFAP requires arrays of speaker azimuths and elevations" ); } @@ -202,13 +219,21 @@ ivas_error efap_init_data( /* Memory allocation for the polyset array */ if ( ( efap->polyData.polysetArray = (EFAP_POLYSET *) malloc( polyset_size * sizeof( EFAP_POLYSET ) ) ) == NULL ) { +#ifdef FIX_1574_EFAP_CODE_LINT + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP polygon array\n" ) ); +#else return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP bufferS\n" ) ); +#endif } /* Memory allocation for the triangle array */ if ( ( efap->polyData.triArray = (EFAP_LS_TRIANGLE *) malloc( polyset_size * sizeof( EFAP_LS_TRIANGLE ) ) ) == NULL ) { +#ifdef FIX_1574_EFAP_CODE_LINT + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP triangle array\n" ) ); +#else return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP bufferS\n" ) ); +#endif } /*-----------------------------------------------------------------* @@ -355,10 +380,18 @@ void efap_free_data( ( *hEFAPdata )->vtxData.vtxOrder = NULL; free( ( *hEFAPdata )->polyData.polysetArray ); +#ifdef FIX_1574_EFAP_CODE_LINT + ( *hEFAPdata )->polyData.polysetArray = NULL; +#else ( *hEFAPdata )->vtxData.vtxOrder = NULL; +#endif free( ( *hEFAPdata )->polyData.triArray ); +#ifdef FIX_1574_EFAP_CODE_LINT + ( *hEFAPdata )->polyData.triArray = NULL; +#else ( *hEFAPdata )->vtxData.vtxOrder = NULL; +#endif free( ( *hEFAPdata )->bufferLong ); ( *hEFAPdata )->bufferLong = NULL; @@ -501,12 +534,10 @@ static void get_poly_select( int16_t azi_index, ele_index; float P[2]; -#ifdef DEBUG_EFAP_POLY_TOFILE /* Write polygon selection table to .csv file, modify filename according to selected loudspeaker layout! */ static FILE *pF = NULL; if ( pF == NULL ) pF = fopen( "./res/efap_poly_select_cicpX.csv", "w" ); -#endif for ( azi_index = 0; azi_index <= ( 360 / PANNING_AZI_RESOLUTION ); azi_index++ ) { @@ -515,17 +546,13 @@ static void get_poly_select( { P[1] = (float) ( ( ele_index * PANNING_ELE_RESOLUTION ) - 90 ); -#ifdef DEBUG_EFAP_POLY_TOFILE if ( pF != NULL ) fprintf( pF, "%d,", get_poly_num( P, polyData ) ); -#endif } } -#ifdef DEBUG_EFAP_POLY_TOFILE if ( pF != NULL ) fclose( pF ); -#endif return; } @@ -649,10 +676,15 @@ static void initial_polyeder( } /* 2. attempt to create a triangle with nonzero area */ +#ifndef FIX_1574_EFAP_CODE_LINT tmp = 0.0f; +#endif v_sub( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3 ); while ( tetrahedron[2] < numVtx ) { +#ifdef FIX_1574_EFAP_CODE_LINT // should be reset every loop iteration; happens to be BE + tmp = 0.0f; +#endif v_sub( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3 ); efap_crossp( tmp1, tmp2, tmpCross ); for ( i = 0; i < 3; i++ ) @@ -743,9 +775,11 @@ static void add_ghost_speakers( int16_t lengthHorGhst; /* Nb of Horizontal Ghost */ int16_t i, j, k, a; /* Integer for loops */ int16_t num_new; /* Number of new vertices to add */ +#ifndef FIX_1574_EFAP_CODE_LINT // use a static constant instead float maxAngle; /* Max azimuth tolerance for extend the LS setup horizontaly */ - float newDiff; /* Angle differences that will help us set the extended LS setup */ - float newAzi; /* New azimuth for the new horizontal LS */ +#endif + float newDiff; /* Angle differences that will help us set the extended LS setup */ + float newAzi; /* New azimuth for the new horizontal LS */ float ele[EFAP_MAX_SIZE_TMP_BUFF]; float tmpEle; float tmpAzi[EFAP_MAX_SIZE_TMP_BUFF]; @@ -755,7 +789,9 @@ static void add_ghost_speakers( vtxDmxType = EFAP_DMX_INTENSITY; numVertex = *numVtx; +#ifndef FIX_1574_EFAP_CODE_LINT maxAngle = 1.f / 160.0f; +#endif /* Extracting Azi and Ele for computation purposes */ for ( i = 0; i < numVertex; ++i ) @@ -838,7 +874,11 @@ static void add_ghost_speakers( a += 2; lengthHorGhst += 2; } +#ifdef FIX_1574_EFAP_CODE_LINT + else /* fill gaps greater than MAX_AZI_GAP */ +#else else /* fill gaps greater than maxAngle */ +#endif { /* Here, k correspond to the number of LS whose ele is < 45 deg, should be = numVertex */ v_sort( tmpAzi, 0, k - 1 ); @@ -847,7 +887,11 @@ static void add_ghost_speakers( for ( i = 0; i < k - 1; ++i ) { tmpAngleDiff[i] = tmpAzi[i + 1] - tmpAzi[i]; +#ifdef FIX_1574_EFAP_CODE_LINT + sectors[i] = ceilf( tmpAngleDiff[i] * MAX_AZI_GAP ); +#else sectors[i] = ceilf( tmpAngleDiff[i] * maxAngle ); +#endif if ( sectors[i] > 1 ) { @@ -856,7 +900,11 @@ static void add_ghost_speakers( } tmpAngleDiff[k - 1] = tmpAzi[0] + 360 - tmpAzi[k - 1]; +#ifdef FIX_1574_EFAP_CODE_LINT + sectors[k - 1] = ceilf( tmpAngleDiff[k - 1] * MAX_AZI_GAP ); +#else sectors[k - 1] = ceilf( tmpAngleDiff[k - 1] * maxAngle ); +#endif if ( sectors[k - 1] > 1 ) { @@ -1187,7 +1235,11 @@ static void remap_ghosts( { if ( triArray[i].LS[j] > g ) { +#ifdef FIX_1574_EFAP_CODE_LINT // g is the index being removed; happens to work since ghosts are always at the end of the array + triArray[i].LS[j]--; +#else triArray[i].LS[j] = g - 1; +#endif } } } @@ -1931,7 +1983,11 @@ static void tri_to_poly( /* Output */ *outLengthPS = lenPolySet; +#ifdef FIX_1574_EFAP_CODE_LINT // only move initialised members + mvs2s( sortedLengths, outLengthSorted, lenPolySet ); +#else mvs2s( sortedLengths, outLengthSorted, EFAP_MAX_POLY_SET ); +#endif return; } @@ -1944,10 +2000,17 @@ static void tri_to_poly( *-------------------------------------------------------------------------*/ static int16_t compare_poly( +#ifdef FIX_1574_EFAP_CODE_LINT // avoid the variable name "new" + int16_t *old_poly, /* i : Existing polygon */ + int16_t lenOld, /* i : Length of existing polygon */ + int16_t *new_poly, /* i : New polygon */ + int16_t lenNew /* i : Length of new polygon */ +#else int16_t *old, /* i : Existing polygon */ int16_t lenOld, /* i : Length of existing polygon */ int16_t *new, /* i : New polygon */ int16_t lenNew /* i : Length of new polygon */ +#endif ) { int16_t i, j; @@ -1959,7 +2022,11 @@ static int16_t compare_poly( { for ( j = count; j < lenNew; ++j ) { +#ifdef FIX_1574_EFAP_CODE_LINT + if ( old_poly[i] == new_poly[j] ) +#else if ( old[i] == new[j] ) +#endif { ++count; break; -- GitLab From bfc8b63705a6beedcef273d3fee5c459297e06a1 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 15 Apr 2026 11:21:08 +0200 Subject: [PATCH 2/6] clang-format --- lib_rend/ivas_efap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 849065f9f..8f1f8fb1c 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -771,12 +771,12 @@ static void add_ghost_speakers( ) { int16_t numVertex; - int16_t lengthVertGhst; /* Nb of vertical ghost added */ - int16_t lengthHorGhst; /* Nb of Horizontal Ghost */ - int16_t i, j, k, a; /* Integer for loops */ - int16_t num_new; /* Number of new vertices to add */ -#ifndef FIX_1574_EFAP_CODE_LINT // use a static constant instead - float maxAngle; /* Max azimuth tolerance for extend the LS setup horizontaly */ + int16_t lengthVertGhst; /* Nb of vertical ghost added */ + int16_t lengthHorGhst; /* Nb of Horizontal Ghost */ + int16_t i, j, k, a; /* Integer for loops */ + int16_t num_new; /* Number of new vertices to add */ +#ifndef FIX_1574_EFAP_CODE_LINT // use a static constant instead + float maxAngle; /* Max azimuth tolerance for extend the LS setup horizontaly */ #endif float newDiff; /* Angle differences that will help us set the extended LS setup */ float newAzi; /* New azimuth for the new horizontal LS */ @@ -2001,10 +2001,10 @@ static void tri_to_poly( static int16_t compare_poly( #ifdef FIX_1574_EFAP_CODE_LINT // avoid the variable name "new" - int16_t *old_poly, /* i : Existing polygon */ - int16_t lenOld, /* i : Length of existing polygon */ - int16_t *new_poly, /* i : New polygon */ - int16_t lenNew /* i : Length of new polygon */ + int16_t *old_poly, /* i : Existing polygon */ + int16_t lenOld, /* i : Length of existing polygon */ + int16_t *new_poly, /* i : New polygon */ + int16_t lenNew /* i : Length of new polygon */ #else int16_t *old, /* i : Existing polygon */ int16_t lenOld, /* i : Length of existing polygon */ -- GitLab From 937bfe917320736b0b0cacd462fd1c5e35032291 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 15 Apr 2026 13:32:30 +0200 Subject: [PATCH 3/6] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: sagnowski --- lib_rend/ivas_efap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 8f1f8fb1c..f004ca262 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -55,7 +55,7 @@ #define EFAP_MAX_GHOST_LS 5 /* Maximum number of ghost Loudspeakers, for memory allocation purpose */ #define POLY_THRESH 1e-4f #ifdef FIX_1574_EFAP_CODE_LINT -#define MAX_AZI_GAP 1.f / 160.f /* Max azimuth tolerance to extend the LS setup in the horizontal plane */ +#define MAX_AZI_GAP ( 1.f / 160.f ) /* Max azimuth tolerance to extend the LS setup in the horizontal plane */ #endif #ifdef DEBUG_EFAP_POLY_TOFILE #define PANNING_AZI_RESOLUTION 2 -- GitLab From e26548f44d77c68857a3ed8ad7044e66b11b6a56 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 15 Apr 2026 13:44:15 +0200 Subject: [PATCH 4/6] [fix] add proper NULL check for EFAP init --- lib_rend/ivas_efap.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index f004ca262..8b128edb0 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -172,11 +172,19 @@ ivas_error efap_init_data( error = IVAS_ERR_OK; /* Basic init checks */ +#ifdef FIX_1574_EFAP_CODE_LINT + if ( hEFAPdata == NULL ) + { + return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "EFAP handle is NULL" ); + } + if ( *hEFAPdata != NULL ) + { + return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "EFAP handle must be NULL before initialization" ); + } +#endif if ( !speaker_node_azi_deg || !speaker_node_ele_deg ) { -#ifdef FIX_1574_EFAP_CODE_LINT - *hEFAPdata = NULL; -#else +#ifndef FIX_1574_EFAP_CODE_LINT hEFAPdata = NULL; #endif return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "EFAP requires arrays of speaker azimuths and elevations" ); -- GitLab From 5863e0365b992513eae0fc26162105edb62de6cc Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 15 Apr 2026 13:52:21 +0200 Subject: [PATCH 5/6] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: sagnowski --- lib_rend/ivas_efap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 8b128edb0..c889957cd 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -175,7 +175,7 @@ ivas_error efap_init_data( #ifdef FIX_1574_EFAP_CODE_LINT if ( hEFAPdata == NULL ) { - return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "EFAP handle is NULL" ); + return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "pointer to EFAP handle is NULL" ); } if ( *hEFAPdata != NULL ) { -- GitLab From 3f12cd0f2bf4431cb9a393622f496e907eb425c2 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 15 Apr 2026 16:06:44 +0200 Subject: [PATCH 6/6] [fix] don't call EFAP with uninit handle in ALLRAD --- lib_rend/ivas_allrad_dec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_rend/ivas_allrad_dec.c b/lib_rend/ivas_allrad_dec.c index 6f8dcd5ae..141e53881 100644 --- a/lib_rend/ivas_allrad_dec.c +++ b/lib_rend/ivas_allrad_dec.c @@ -137,6 +137,10 @@ ivas_error ivas_sba_get_hoa_dec_matrix( else if ( hOutSetup.is_loudspeaker_setup ) { /* init EFIP */ +#ifdef FIX_1574_EFAP_CODE_LINT + /* ensure the handle is NULL before passing, otherwise efap_init_data will think this is allocated memory and return an error */ + hEFAP = NULL; +#endif if ( ( error = efap_init_data( &( hEFAP ), hOutSetup.ls_azimuth, hOutSetup.ls_elevation, num_spk, EFAP_MODE_EFIP ) ) != IVAS_ERR_OK ) { return error; -- GitLab