Commit 17d1c880 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

tune/reduce memory allocation for EFAP

parent 36b63cd5
Loading
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -1458,12 +1458,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                       36                          /* Upper bound on number of polygons */
#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 */
+1 −0
Original line number Diff line number Diff line
@@ -169,6 +169,7 @@
#define FIX_989_TD_REND_ROM                             /* Eri: Clean-up for TD renderer and completion of ROM generation tool */

#define FIX_1068_ASAN_IN_MC_2_BINAURAL_ROOM_IR          /* issue 1068 : Memory leak in MC to BINAURAL_ROOM decoding with bitrate switching*/
#define FIX_1050_EFAP_ALLOC                             /* FhG: issue 1050: reduction of memory allocated to EFAP handle */

/* #################### End BE switches ################################## */

+7 −0
Original line number Diff line number Diff line
@@ -66,7 +66,14 @@ ivas_error ivas_ism_renderer_open(
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer\n" ) );
    }

#ifdef FIX_1050_EFAP_ALLOC
    if ( st_ivas->hIntSetup.is_loudspeaker_setup &&
         st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO &&
         st_ivas->hIntSetup.ls_azimuth != NULL && st_ivas->hIntSetup.ls_elevation != NULL &&
         st_ivas->hEFAPdata == NULL )
#else
    if ( st_ivas->hIntSetup.is_loudspeaker_setup && st_ivas->hIntSetup.ls_azimuth != NULL && st_ivas->hIntSetup.ls_elevation != NULL && st_ivas->hEFAPdata == NULL )
#endif
    {
        if ( ( error = efap_init_data( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth, st_ivas->hIntSetup.ls_elevation, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK )
        {
+45 −4
Original line number Diff line number Diff line
@@ -51,6 +51,12 @@
#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_1050_EFAP_ALLOC
#ifdef DEBUG_EFAP_POLY_TOFILE
#define PANNING_AZI_RESOLUTION 2
#define PANNING_ELE_RESOLUTION 5
#endif
#endif


/*-----------------------------------------------------------------------*
@@ -147,6 +153,9 @@ ivas_error efap_init_data(
)
{
    /* Handle instance declaration  */
#ifdef FIX_1050_EFAP_ALLOC
    int8_t polyset_size;
#endif
    EFAP *efap;
    ivas_error error;

@@ -163,13 +172,13 @@ ivas_error efap_init_data(
     * 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" ) );
    }

    /* Memory Allocation and update for aziSpk & eleSpk arrays*/
    /* Memory allocation and update for aziSpk & eleSpk arrays*/
    if ( ( efap->aziSpk = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP speaker azimuths\n" ) );
@@ -179,7 +188,7 @@ ivas_error efap_init_data(
        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" ) );
@@ -190,6 +199,22 @@ ivas_error efap_init_data(
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for EFAP bufferS\n" ) );
    }
#ifdef FIX_1050_EFAP_ALLOC
    /* calculate upper bound of number of polygons required (heuristic) */
    polyset_size = 2 * num_speaker_nodes + 6;

    /* 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
@@ -333,6 +358,14 @@ void efap_free_data(

    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 );
    ( *hEFAPdata )->bufferLong = NULL;
@@ -401,7 +434,11 @@ static ivas_error poly_init(
        if ( efap->vtxData.vertexArray[n].ele > 90.0 - 1e-6 ||
             efap->vtxData.vertexArray[n].ele < 1e-6 - 90.0 )
        {
#ifdef FIX_1050_EFAP_ALLOC
            efap->vtxData.vertexArray[n].isNaN = true;
#else
            efap->vtxData.vertexArray[n].isNaN = 1;
#endif
        }
    }

@@ -1494,7 +1531,11 @@ static void add_vertex(
    vtxArray[pos].idx = (int16_t) idxAziTmp + 181 * (int16_t) idxEleTmp;

/* Setting the nan flag to 0 */
#ifdef FIX_1050_EFAP_ALLOC
    vtxArray[pos].isNaN = false;
#else
    vtxArray[pos].isNaN = 0;
#endif

    /* Set the default downmix type */
    vtxArray[pos].dmxType = dmxType;
+28 −10
Original line number Diff line number Diff line
@@ -584,7 +584,11 @@ typedef struct EFAP_VERTEX
    float ele;    /* elevation of the loudspeaker */
    float pos[3]; /* [x y z] cartesian coordinate vector */
    int16_t idx;  /* integer, that corresponds to the first index for the LS in the 1D output */
#ifdef FIX_1050_EFAP_ALLOC
    bool isNaN; /* used to indicate if the vertex is a virtual speaker */
#else
    int16_t isNaN;                                /* used to indicate if the vertex is a virtual speaker */
#endif
    EFAP_VTX_DMX_TYPE dmxType; /* virtual speaker downmix type */

} EFAP_VERTEX;
@@ -599,9 +603,15 @@ typedef struct EFAP_VERTEX_DATA

typedef struct EFAP_POLYSET
{
#ifdef FIX_1050_EFAP_ALLOC
    int8_t chan[EFAP_MAX_CHAN_NUM];  /* An array indicating the loudspeaker index of the polygon vertices                                 */
    int8_t isNaN[EFAP_MAX_CHAN_NUM]; /* Indicates if one of the vertices isNaN                                                            */
    int8_t numChan;                  /* An integer between 0 and EFAP_MAX_CHAN_NUM corresponding to the number of vertices of the polygon */
#else
    int16_t chan[EFAP_MAX_CHAN_NUM];              /* An array indicating the loudspeaker index of the polygon vertices                                 */
    int16_t isNaN[EFAP_MAX_CHAN_NUM];             /* Indicates if one of the vertices isNaN                                                            */
    int16_t numChan;                              /* An integer between 0 and EFAP_MAX_CHAN_NUM corresponding to the number of vertices of the polygon */
#endif
    float polyAzi[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the azimuth of the channels                                */
    float polyEle[EFAP_MAX_CHAN_NUM]; /* An array (same length as "chan"), with the elevation of the channels                              */

@@ -615,9 +625,17 @@ typedef struct EFAP_LS_TRIANGLE

typedef struct EFAP_POLYSET_DATA
{
#ifdef FIX_1050_EFAP_ALLOC
    EFAP_POLYSET *polysetArray; /* Array of polygons       */
#else
    EFAP_POLYSET polysetArray[EFAP_MAX_POLY_SET]; /* Array of polygons       */
#endif
    int16_t 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
    int16_t numTri; /* Number of triangles     */

} EFAP_POLYSET_DATA;