diff --git a/lib_com/options.h b/lib_com/options.h index 6e43c33f3733e67c54380e13171eb29f914d5255..de9b2f4d3f405ddedce60f109f4945b6a4e1a497 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -171,6 +171,7 @@ #define USE_RTPDUMP /* FhG: RTPDUMP format (rtptools standard) instead of custom format */ #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_allrad_dec.c b/lib_rend/ivas_allrad_dec.c index 6f8dcd5ae64785ec23402b8c38c31971ca56e85a..141e538817c686b0e3b282e38567b1434d325866 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; diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index d7ec93ffda23eec4588eead6b4e07c5069db1965..c889957cd82e952c218965567173c0285577bbfb 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 ); @@ -159,9 +172,21 @@ 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, "pointer to 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 ) { +#ifndef FIX_1574_EFAP_CODE_LINT hEFAPdata = NULL; +#endif return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "EFAP requires arrays of speaker azimuths and elevations" ); } @@ -202,13 +227,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 +388,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 +542,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 +554,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 +684,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++ ) @@ -739,13 +779,15 @@ 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 */ - 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 */ + 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 */ float ele[EFAP_MAX_SIZE_TMP_BUFF]; float tmpEle; float tmpAzi[EFAP_MAX_SIZE_TMP_BUFF]; @@ -755,7 +797,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 +882,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 +895,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 +908,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 +1243,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 +1991,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 +2008,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 +2030,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;