Commit ba0d3b42 authored by emerit's avatar emerit
Browse files

ready for testing

parent a1482804
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@
/*#define FIX_I4_OL_PITCH*/                             /* fix open-loop pitch used for EVS core switching */
#define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR      /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */
#define NONBE_1122_KEEP_EVS_MODE_UNCHANGED              /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR.  */
#define FIX_2249_MEMORY_LEAK_IN_SBA                     /* OR : issue 2249 : Memory leak in SBA to BINAURAL_ROOM_REVERB with memory instrumentation */

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

+17 −2
Original line number Diff line number Diff line
@@ -1500,8 +1500,18 @@ ivas_error ivas_init_decoder(

    if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
    {
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
        /* Allocate HRTF statistics */
        if ( ( error = ivas_HRTF_statistics_binary_open( &( st_ivas->hHrtfStatistics ) ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        /* Init HRTF statistics */
        if ( ( error = ivas_HRTF_statistics_init_from_rom( &st_ivas->hHrtfStatistics, output_Fs ) ) != IVAS_ERR_OK )
#else
        if ( ( error = ivas_HRTF_statistics_init( &st_ivas->hHrtfStatistics, output_Fs ) ) != IVAS_ERR_OK )
#endif
        {
            return error;
        }
@@ -2990,16 +3000,21 @@ void ivas_destroy_dec(

    if ( st_ivas->hHrtfTD != NULL )
    {
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
        ivas_HRTF_td_binary_close( &st_ivas->hHrtfTD );
#else
        BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval );

        ivas_HRTF_binary_close( &st_ivas->hHrtfTD );
#endif
    }

    /* CRend binaural renderer handle */
    ivas_HRTF_CRend_binary_close( &st_ivas->hHrtfCrend );

#ifndef FIX_2249_MEMORY_LEAK_IN_SBA
    /* Fastconv HRTF memories */
    ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv );
#endif

    /* Fastconv HRTF filters */
    ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv );
@@ -3008,7 +3023,7 @@ void ivas_destroy_dec(
    ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin );

    /* HRTF statistics */
    ivas_HRTF_statistics_close( &st_ivas->hHrtfStatistics );
    ivas_HRTF_statistics_binary_close( &st_ivas->hHrtfStatistics );

    /* Config. Renderer */
    ivas_render_config_close( &( st_ivas->hRenderConfig ) );
+10 −1
Original line number Diff line number Diff line
@@ -2938,7 +2938,11 @@ ivas_error IVAS_DEC_HRTF_binary_open(
        /* TD binaural renderer */
        if ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hHrtfTD == NULL )
        {
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
            if ( ( error = ivas_HRTF_td_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK )
#else
            if ( ( error = ivas_HRTF_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK )
#endif
            {
                return error;
            }
@@ -3008,7 +3012,11 @@ ivas_error IVAS_DEC_HRTF_binary_close(
    {
        if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) )
        {
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
            ivas_HRTF_td_binary_close( &st_ivas->hHrtfTD );
#else
            ivas_HRTF_binary_close( &st_ivas->hHrtfTD );
#endif
        }

        if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) )
@@ -3019,9 +3027,10 @@ ivas_error IVAS_DEC_HRTF_binary_close(

        if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) )
        {
#ifndef FIX_2249_MEMORY_LEAK_IN_SBA
            /* Fastconv HRTF memories */
            ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv );

#endif
            /* Fastconv HRTF filters */
            ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv );
        }
+2 −0
Original line number Diff line number Diff line
@@ -1477,7 +1477,9 @@ void ivas_rend_closeCldfbRend(
    }

    ivas_binRenderer_close( &pCldfbRend->hCldfbRend );
#ifndef FIX_2249_MEMORY_LEAK_IN_SBA
    ivas_binaural_hrtf_close( &pCldfbRend->hHrtfFastConv );
#endif
    ivas_HRTF_fastconv_binary_close( &pCldfbRend->hHrtfFastConv );

    return;
+213 −13
Original line number Diff line number Diff line
@@ -40,13 +40,17 @@
#include "ivas_rom_binaural_crend_head.h"

/*-----------------------------------------------------------------------*
 * ivas_HRTF_binary_open()
 * ivas_HRTF_td_binary_open()
 *
 * Allocate HRTF binary handle for TD renderer
 *-----------------------------------------------------------------------*/

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
ivas_error ivas_HRTF_td_binary_open(
    TDREND_HRFILT_FiltSet_t **hHrtfTD )
#else
ivas_error ivas_HRTF_binary_open(
    TDREND_HRFILT_FiltSet_t **hHrtfTD )
#endif
{
    /* Allocate HR filter set for headphones configuration */
    *hHrtfTD = (TDREND_HRFILT_FiltSet_t *) malloc( sizeof( TDREND_HRFILT_FiltSet_t ) );
@@ -66,22 +70,79 @@ ivas_error ivas_HRTF_binary_open(
 *
 * Close HRTF binary handle for TD renderer
 *-------------------------------------------------------------------*/

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
void ivas_HRTF_td_binary_close(
    TDREND_HRFILT_FiltSet_t **hHrtfTD )
#else
void ivas_HRTF_binary_close(
    TDREND_HRFILT_FiltSet_t **hHrtfTD )
#endif
{
    if ( hHrtfTD == NULL || *hHrtfTD == NULL )
    {
        return;
    }

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
    int16_t i;

    if ( ( *hHrtfTD )->ModelParams.modelROM )
    {
        BSplineModelEvalDealloc( &( *hHrtfTD )->ModelParams, &( *hHrtfTD )->ModelEval );
    }
    else
    {
        if ( ( *hHrtfTD )->ModelParams.UseItdModel )
        {
            free( ( *hHrtfTD )->ModelParamsITD.elevKSeq_dyn );
            free( ( *hHrtfTD )->ModelParamsITD.azimKSeq_dyn );
            free( ( *hHrtfTD )->ModelParamsITD.W_dyn );
            free( ( *hHrtfTD )->ModelParamsITD.azimBsShape_dyn );
            free( ( *hHrtfTD )->ModelParamsITD.elevBsShape_dyn );
            free( ( *hHrtfTD )->ModelParamsITD.azimBsLen_dyn );
            free( ( *hHrtfTD )->ModelParamsITD.azimBsStart_dyn );
            free( ( *hHrtfTD )->ModelParamsITD.elevBsLen_dyn );
            free( ( *hHrtfTD )->ModelParamsITD.elevBsStart_dyn );
        }
        free( ( *hHrtfTD )->ModelParams.elevKSeq_dyn );
        free( ( *hHrtfTD )->ModelParams.azim_start_idx_dyn );
        free( ( *hHrtfTD )->ModelParams.azimDim3_dyn );
        free( ( *hHrtfTD )->ModelParams.AlphaL_dyn );
        free( ( *hHrtfTD )->ModelParams.AlphaR_dyn );
        free( ( *hHrtfTD )->ModelParams.azimSegSamples_dyn );

        free( ( *hHrtfTD )->ModelParams.azimShapeIdx_dyn );
        free( ( *hHrtfTD )->ModelParams.azimShapeSampFactor_dyn );
        free( ( *hHrtfTD )->ModelParams.elevBsLen_dyn );
        free( ( *hHrtfTD )->ModelParams.elevBsStart_dyn );
        free( ( *hHrtfTD )->ModelParams.elevBsShape_dyn );

        for ( i = 0; i < ( *hHrtfTD )->ModelParams.num_unique_azim_splines; i++ )
        {
            free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn[i] );
        }
        free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn );

        free( (void *) ( *hHrtfTD )->ModelParams.azimBsShape ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */
        for ( i = 0; i < ( *hHrtfTD )->ModelParams.elevDim3; i++ )
        {
            free( ( *hHrtfTD )->ModelParams.azimKSeq[i] );
        }
        free( ( *hHrtfTD )->ModelParams.azimKSeq );

        free( ( *hHrtfTD )->ModelParams.EL_dyn );
        free( ( *hHrtfTD )->ModelParams.ER_dyn );

        free( ( *hHrtfTD )->ModelEval.hrfModL );
        free( ( *hHrtfTD )->ModelEval.hrfModR );
    }
#endif
    free( *hHrtfTD );
    *hHrtfTD = NULL;

    return;
}


/*-----------------------------------------------------------------------*
 * ivas_HRTF_CRend_binary_open()
 *
@@ -106,17 +167,45 @@ ivas_error ivas_HRTF_CRend_binary_open(
    return IVAS_ERR_OK;
}


#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
/*-----------------------------------------------------------------------*
 * ivas_HRTF_CRend_binary_open_buffers_uint16()
 * ivas_HRTF_binary_open_buffers_int16()
 *
 * Allocate buffer with dynamic length for HRTF binary Crend handle
 *-----------------------------------------------------------------------*/

ivas_error ivas_HRTF_binary_open_buffers_int16(
    int16_t **buffer,       /* o  : buffer to allocate      */
    const uint32_t mem_size /* i  : size of buffer          */
)
{
    *buffer = (int16_t *) malloc( mem_size );

    if ( *buffer == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" );
    }

    return IVAS_ERR_OK;
}
#endif

/*-----------------------------------------------------------------------*
 * ivas_HRTF_binary_open_buffers_uint16()
 *
 * Allocate buffer with dynamic length for HRTF binary Crend handle
 *-----------------------------------------------------------------------*/
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
ivas_error ivas_HRTF_binary_open_buffers_uint16(
    uint16_t **buffer,      /* o  : buffer to allocate      */
    const uint32_t mem_size /* i  : size of buffer          */
)
#else
ivas_error ivas_HRTF_CRend_binary_open_buffers_uint16(
    uint16_t **buffer,      /* o  : buffer to allocate      */
    const uint32_t mem_size /* i  : size of buffer          */
)
#endif
{
    *buffer = (uint16_t *) malloc( mem_size );

@@ -128,17 +217,22 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_uint16(
    return IVAS_ERR_OK;
}


/*-----------------------------------------------------------------------*
 * ivas_HRTF_CRend_binary_open_buffers_float()
 * ivas_HRTF_binary_open_buffers_float()
 *
 * Allocate buffer with dynamic length for HRTF binary Crend handle
 *-----------------------------------------------------------------------*/

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
ivas_error ivas_HRTF_binary_open_buffers_float(
    float **buffer,         /* o  : buffer to allocate      */
    const uint32_t mem_size /* i  : size of buffer          */
)
#else
ivas_error ivas_HRTF_CRend_binary_open_buffers_float(
    float **buffer,         /* o  : buffer to allocate      */
    const uint32_t mem_size /* i  : size of buffer          */
)
#endif
{
    *buffer = (float *) malloc( mem_size );

@@ -150,6 +244,47 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_float(
    return IVAS_ERR_OK;
}

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
/*-----------------------------------------------------------------------*
 * ivas_HRTF_binary_open_buffers_float_ptr()
 *
 * Allocate buffer with dynamic length for HRTF binary Crend handle
 *-----------------------------------------------------------------------*/
ivas_error ivas_HRTF_binary_open_buffers_float_ptr(
    float ***buffer,        /* o  : buffer to allocate      */
    const uint32_t mem_size /* i  : size of buffer          */
)
{
    *buffer = (float **) malloc( mem_size );

    if ( *buffer == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" );
    }

    return IVAS_ERR_OK;
}
/*-----------------------------------------------------------------------*
 * ivas_HRTF_binary_open_buffers_float_ptr()
 *
 * Allocate buffer with dynamic length for HRTF binary Crend handle
 *-----------------------------------------------------------------------*/
ivas_error ivas_HRTF_binary_open_buffers_float_ptr_const(
    const float ***buffer,  /* o  : buffer to allocate      */
    const uint32_t mem_size /* i  : size of buffer          */
)
{
    *buffer = (const float **) malloc( mem_size );

    if ( *buffer == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" );
    }

    return IVAS_ERR_OK;
}
#endif


/*-------------------------------------------------------------------*
 * ivas_HRTF_CRend_binary_close()
@@ -242,6 +377,10 @@ void ivas_HRTF_fastconv_binary_close(
    {
        return;
    }
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
    /* Fastconv HRTF memories */
    ivas_binaural_hrtf_close( hHrtfFastConv );
#endif

    free( *hHrtfFastConv );
    *hHrtfFastConv = NULL;
@@ -305,7 +444,9 @@ ivas_error ivas_HRTF_statistics_binary_open(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" );
    }

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
    set_c( (int8_t *) ( *hHrtfStatistics ), 0, (int32_t) sizeof( HRTFS_STATISTICS ) );
#endif
    return IVAS_ERR_OK;
}

@@ -315,14 +456,35 @@ ivas_error ivas_HRTF_statistics_binary_open(
 *
 * Close HRTF binary handle for statistics handler
 *-----------------------------------------------------------------------*/

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
void ivas_HRTF_statistics_binary_close(
    HRTFS_STATISTICS **hHrtfStatistics )
#else
void ivas_HRTF_statistics_close(
    HRTFS_STATISTICS **hHrtfStatistics )
#endif
{
    if ( hHrtfStatistics == NULL || *hHrtfStatistics == NULL )
    {
        return;
    }
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
    if ( ( hHrtfStatistics != NULL ) && ( *hHrtfStatistics != NULL ) && ( ( *hHrtfStatistics )->fromROM == FALSE ) )
    {
        if ( ( *hHrtfStatistics )->average_energy_l_dyn != NULL )
        {
            free( ( *hHrtfStatistics )->average_energy_l_dyn );
        }
        if ( ( *hHrtfStatistics )->average_energy_r_dyn != NULL )
        {
            free( ( *hHrtfStatistics )->average_energy_r_dyn );
        }
        if ( ( *hHrtfStatistics )->inter_aural_coherence_dyn != NULL )
        {
            free( ( *hHrtfStatistics )->inter_aural_coherence_dyn );
        }
    }
#endif

    free( *hHrtfStatistics );
    *hHrtfStatistics = NULL;
@@ -331,15 +493,52 @@ void ivas_HRTF_statistics_close(
}

/*-----------------------------------------------------------------------*
 * ivas_HRTF_statistics_init()
 * ivas_HRTF_statistics_init_from_rom()
 *
 * Allocates HRTF statistics handle and initializes from ROM
 *-----------------------------------------------------------------------*/

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
ivas_error ivas_HRTF_statistics_init_from_rom(
    HRTFS_STATISTICS_HANDLE *hHrtfStatistics,
    const int32_t sampleRate )
#else
ivas_error ivas_HRTF_statistics_init(
    HRTFS_STATISTICS_HANDLE *hHrtfStatistics,
    const int32_t sampleRate )
#endif
{
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
    if ( hHrtfStatistics == NULL || *hHrtfStatistics != NULL )
    {
        /* Tables not initialised */
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    switch ( sampleRate )
    {
        case 48000:
            ( *hHrtfStatistics )->average_energy_l = defaultHRIR_left_avg_power_48kHz;
            ( *hHrtfStatistics )->average_energy_r = defaultHRIR_right_avg_power_48kHz;
            ( *hHrtfStatistics )->inter_aural_coherence = defaultHRIR_coherence_48kHz;
            break;
        case 32000:
            ( *hHrtfStatistics )->average_energy_l = defaultHRIR_left_avg_power_32kHz;
            ( *hHrtfStatistics )->average_energy_r = defaultHRIR_right_avg_power_32kHz;
            ( *hHrtfStatistics )->inter_aural_coherence = defaultHRIR_coherence_32kHz;
            break;
        case 16000:
            ( *hHrtfStatistics )->average_energy_l = defaultHRIR_left_avg_power_16kHz;
            ( *hHrtfStatistics )->average_energy_r = defaultHRIR_right_avg_power_16kHz;
            ( *hHrtfStatistics )->inter_aural_coherence = defaultHRIR_coherence_16kHz;
            break;
        default:
            ( *hHrtfStatistics )->average_energy_l = NULL;
            ( *hHrtfStatistics )->average_energy_r = NULL;
            ( *hHrtfStatistics )->inter_aural_coherence = NULL;
            break;
    }
    ( *hHrtfStatistics )->fromROM = TRUE;
#else
    HRTFS_STATISTICS *HrtfStatistics;

    if ( hHrtfStatistics != NULL && *hHrtfStatistics != NULL )
@@ -380,5 +579,6 @@ ivas_error ivas_HRTF_statistics_init(

    *hHrtfStatistics = HrtfStatistics;

#endif
    return IVAS_ERR_OK;
}
Loading