diff --git a/lib_com/options.h b/lib_com/options.h index bb52fc1b0d347a98d53d5738c82bbe0113023b54..5c19f21395be14cc62329e03ca54bca70776b0f0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -121,8 +121,8 @@ #define FIX_BASOP_2522_MAP_PARAMS_DIRAC_STEREO /* FhG: BASOP issue 2522: Fix copy and paste error for side_gain calculation in map_params_dirac_to_stereo() */ #define FIX_2505_IVAS_DEC_SEGFAULT /* FhG: BASOP #2505: Add headroom to input of ivas_rend_crendProcessSubframe_fx() for ivas_mdft_fx() calculation */ #define HARMONIZE_DoRTFTn /* VA: harmonize functions DoRTFTn_fx() and DoRTFTn_fx_ivas() */ +#define FIX_1574_EFAP_CODE_LINT /* FhG: float issue 1574: Code quality fixes in ivas_efap.c */ #define FIX_BASOP_2529_MASA_RATIO_SCALINGS /* Nokia: BASOP issue 2529: Fix MASA ratio scalings and verifications */ -#define FIX_BASOP_2525_MASA_MERGE_WRONG_ASSIGN /* Nokia: BASOP issue 2525: Fix wrong assignment in MASA merge code */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_rend/ivas_allrad_dec_fx.c b/lib_rend/ivas_allrad_dec_fx.c index 34563e8c39256ed5d7bf19a7e2bf126dbb8f8c93..2c5c40b9c30c0eabcc2a43a01b21999c0ffeba84 100644 --- a/lib_rend/ivas_allrad_dec_fx.c +++ b/lib_rend/ivas_allrad_dec_fx.c @@ -110,6 +110,12 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( 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( NE_16( ( error = efap_init_data_fx( &( hEFAP ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, num_spk, EFAP_MODE_EFIP ) ), IVAS_ERR_OK ) ) { return error; diff --git a/lib_rend/ivas_efap_fx.c b/lib_rend/ivas_efap_fx.c index 34d34132a8290e22d1cc5baee544ac386b8fcc9b..2f1157e14e62a61160f5c7e4a20d05c77a310dcc 100644 --- a/lib_rend/ivas_efap_fx.c +++ b/lib_rend/ivas_efap_fx.c @@ -37,7 +37,9 @@ #include "prot_fx.h" #include "ivas_prot_rend_fx.h" #include "ivas_rom_rend.h" +#ifndef FIX_1574_EFAP_CODE_LINT #include "ivas_stat_dec.h" +#endif #include "wmc_auto.h" #include "ivas_prot_fx.h" @@ -60,6 +62,9 @@ #define Q22_180_DEG 754974720 #define Q22_360_DEG 1509949440 #define Q22_120_DEG 503316480 +#ifdef FIX_1574_EFAP_CODE_LINT +#define MAX_AZI_GAP 13421773 /* (1.f / 160.0f) in Q31 */ +#endif #define Q22_240_DEG 1006632960 /*-----------------------------------------------------------------------* @@ -86,7 +91,11 @@ static Word32 get_tri_gain_fx( const Word32 A[2] /*q22*/, const Word32 B[2] /*q2 * EFAP Utils *-----------------------------------------------------------------------*/ +#ifdef FIX_1574_EFAP_CODE_LINT +static void add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word16 pos, const EFAP_VTX_DMX_TYPE dmxType ); +#else static void add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word16 pos, const EFAP_VTX_DMX_TYPE ); +#endif static void efap_sort_s_fx( Word16 *x, Word16 *idx, const Word16 len ); static Word32 vertex_distance_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE tri, const Word16 vtxIdx ); @@ -99,7 +108,11 @@ static Word16 get_neighbours_fx( const EFAP_LS_TRIANGLE *triArray, const Word16 static void matrix_times_row_fx( Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF] /*q31*/, const Word32 *vec /*q31*/, const Word16 L, Word32 *out /*q31*/ ); static void tri_to_poly_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, const Word16 numVtx, const Word16 numTri, Word16 sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM], Word16 *outLengthPS, Word16 outLengthSorted[EFAP_MAX_POLY_SET] ); +#ifdef FIX_1574_EFAP_CODE_LINT +static Word16 compare_poly_fx( Word16 *old_poly, Word16 lenOld, Word16 *new_poly, Word16 lenNew ); +#else static Word16 compare_poly_fx( Word16 *old, Word16 lenOld, Word16 *new, Word16 lenNew ); +#endif static void sort_channels_vertex_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, Word16 channels[EFAP_MAX_CHAN_NUM], const Word16 lengthChannels, Word16 idxTri ); static Word32 efap_32mod32( const Word32 x /*q22*/, const Word32 y /*q22*/ ); @@ -135,11 +148,23 @@ ivas_error efap_init_data_fx( error = IVAS_ERR_OK; move32(); - /* Basic init checks */ +/* 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 test(); 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" ); } @@ -181,13 +206,21 @@ ivas_error efap_init_data_fx( /* 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 } /*-----------------------------------------------------------------* @@ -354,10 +387,18 @@ void efap_free_data_fx( ( *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_fx ); ( *hEFAPdata )->bufferLong_fx = NULL; @@ -634,11 +675,17 @@ static void initial_polyeder_fx( } /* 2. attempt to create a triangle with nonzero area */ +#ifndef FIX_1574_EFAP_CODE_LINT tmp = 0; move32(); +#endif v_sub_fx( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); // tmp1 Q(31-1) WHILE( LT_16( tetrahedron[2], numVtx ) ) { +#ifdef FIX_1574_EFAP_CODE_LINT + tmp = 0; + move32(); +#endif v_sub_fx( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3, 1 ); // tmp2 Q(31-1) efap_crossp_fx( tmp1, tmp2, tmpCross ); // tmpCross Q29 FOR( i = 0; i < 3; i++ ) @@ -750,9 +797,11 @@ static void add_ghost_speakers_fx( Word16 lengthHorGhst; /* Nb of Horizontal Ghost */ Word16 i, j, k, a; /* Integer for loops */ Word16 num_new; /* Number of new vertices to add */ - Word32 maxAngle; /* Max azimuth tolerance for extend the LS setup horizontaly */ - Word32 newDiff; /* Angle differences that will help us set the extended LS setup */ - Word32 newAzi; /* New azimuth for the new horizontal LS */ +#ifndef FIX_1574_EFAP_CODE_LINT + Word32 maxAngle; /* Max azimuth tolerance for extend the LS setup horizontaly */ +#endif + Word32 newDiff; /* Angle differences that will help us set the extended LS setup */ + Word32 newAzi; /* New azimuth for the new horizontal LS */ Word32 ele[EFAP_MAX_SIZE_TMP_BUFF]; Word32 tmpEle; Word32 tmpAzi[EFAP_MAX_SIZE_TMP_BUFF]; @@ -765,8 +814,10 @@ static void add_ghost_speakers_fx( move32(); numVertex = *numVtx; move16(); +#ifndef FIX_1574_EFAP_CODE_LINT maxAngle = 13421773; //(1.f / 160.0f) in Q31 move32(); +#endif /* Extracting Azi and Ele for computation purposes */ FOR( i = 0; i < numVertex; ++i ) @@ -857,7 +908,11 @@ static void add_ghost_speakers_fx( a = add( a, 2 ); lengthHorGhst = add( 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 */ sort_l( tmpAzi, k ); // tmpAzi q22 @@ -867,7 +922,11 @@ static void add_ghost_speakers_fx( { tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); // q22 move32(); +#ifdef FIX_1574_EFAP_CODE_LINT + sectors[i] = ceil_fx( Mpy_32_32( tmpAngleDiff[i], MAX_AZI_GAP ), Q22 ); // q22 +#else sectors[i] = ceil_fx( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); // q22 +#endif move32(); if ( GT_32( sectors[i], Q22_1 /*1 q22*/ ) ) @@ -877,7 +936,11 @@ static void add_ghost_speakers_fx( } tmpAngleDiff[k - 1] = L_sub( L_add( tmpAzi[0], Q22_360_DEG /*360 q22*/ ), tmpAzi[k - 1] ); // q22 +#ifdef FIX_1574_EFAP_CODE_LINT + sectors[k - 1] = ceil_fx( Mpy_32_32( tmpAngleDiff[k - 1], MAX_AZI_GAP ), Q22 ); // q22 +#else sectors[k - 1] = ceil_fx( Mpy_32_32( tmpAngleDiff[k - 1], maxAngle ), Q22 ); // q22 +#endif if ( GT_32( sectors[k - 1], Q22_1 /*1 q22*/ ) ) { @@ -1257,7 +1320,11 @@ static void remap_ghosts_fx( { IF( GT_16( triArray[i].LS[j], g ) ) { +#ifdef FIX_1574_EFAP_CODE_LINT + triArray[i].LS[j] = sub( triArray[i].LS[j], 1 ); +#else triArray[i].LS[j] = sub( g, 1 ); +#endif move16(); } } @@ -2159,7 +2226,11 @@ static void tri_to_poly_fx( /* Output */ *outLengthPS = lenPolySet; move16(); +#ifdef FIX_1574_EFAP_CODE_LINT + Copy( sortedLengths, outLengthSorted, lenPolySet ); +#else Copy( sortedLengths, outLengthSorted, EFAP_MAX_POLY_SET ); +#endif return; } @@ -2171,10 +2242,17 @@ static void tri_to_poly_fx( *-------------------------------------------------------------------------*/ static Word16 compare_poly_fx( +#ifdef FIX_1574_EFAP_CODE_LINT + Word16 *old_poly, /* i : Existing polygon */ + Word16 lenOld, /* i : Length of existing polygon */ + Word16 *new_poly, /* i : New polygon */ + Word16 lenNew /* i : Length of new polygon */ +#else Word16 *old, /* i : Existing polygon */ Word16 lenOld, /* i : Length of existing polygon */ Word16 *new, /* i : New polygon */ Word16 lenNew /* i : Length of new polygon */ +#endif ) { Word16 i, j; @@ -2187,7 +2265,11 @@ static Word16 compare_poly_fx( { FOR( j = count; j < lenNew; ++j ) { +#ifdef FIX_1574_EFAP_CODE_LINT + IF( EQ_16( old_poly[i], new_poly[j] ) ) +#else IF( EQ_16( old[i], new[j] ) ) +#endif { count = add( count, 1 ); BREAK;