Commit 607dd6e7 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

[fix] efap code lint

parent 69d52e95
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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 */

+75 −8
Original line number Diff line number Diff line
@@ -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,7 +775,9 @@ 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 */
#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];
@@ -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;