Commit 4a220f6a authored by bayers's avatar bayers
Browse files

Merge branch '158-hdirac_mem-handle-in-sba-output-to-mc-or-binaural' into 'main'

#158: reduce the memory consumption of DirAC and the hDirAC_mem handle

See merge request !281
parents 141816b3 05fabca9
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@
#define FIX_I214_CLIPPING_STANDALONE_REND               /* Issue 214: TD standalone renderer does not handle clipping */
#define FIX_I218_PARAMISM_NOISY_SPEECH                  /* Issue 218: Fix noisy speech buffer in ParamISM */
#define FIX_I217_GSC_FLAG_IN_ISM                        /* Issue 217: fix BER detected in ISM4 due to desynchronized 'GSC_IVAS_mode' parameter */

#define FIX_158_DIRAC_MEM                               /* Issue 158: Reduce memory consumption in the hDirac_mem handle */

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
+102 −16
Original line number Diff line number Diff line
@@ -49,8 +49,11 @@
/*-----------------------------------------------------------------------*
 * Local function prototypes
 *-----------------------------------------------------------------------*/

#ifdef FIX_158_DIRAC_MEM
static void ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, const RENDERER_TYPE renderer_type, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem );
#else
static void ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem );
#endif

static void ivas_dirac_free_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem );

@@ -714,6 +717,13 @@ ivas_error ivas_dirac_dec_config(
        }
    }


#ifdef FIX_158_DIRAC_MEM
    if ( flag_config == DIRAC_OPEN )
    {
        hDirAC->buffer_energy = NULL;
    }
#endif
    if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == TRUE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) )
    {
        hDirAC->index_buffer_intensity = 0;
@@ -726,7 +736,12 @@ ivas_error ivas_dirac_dec_config(
                set_f( hDirAC->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX );
            }
        }

#ifdef FIX_158_DIRAC_MEM
        if ( hDirAC->buffer_energy == NULL )
        {
            hDirAC->buffer_energy = (float *) count_malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) );
        }
#endif
        set_f( hDirAC->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX );
    }
    else if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == FALSE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) )
@@ -742,6 +757,13 @@ ivas_error ivas_dirac_dec_config(
                hDirAC->buffer_intensity_real[i][j] = NULL;
            }
        }
#ifdef FIX_158_DIRAC_MEM
        if ( hDirAC->buffer_energy != NULL )
        {
            count_free( hDirAC->buffer_energy );
            hDirAC->buffer_energy = NULL;
        }
#endif
    }

    /* output synthesis */
@@ -752,7 +774,11 @@ ivas_error ivas_dirac_dec_config(
    {
        ivas_dirac_free_mem( &( hDirAC->stack_mem ) );
    }
#ifdef FIX_158_DIRAC_MEM
    ivas_dirac_alloc_mem( hDirAC, st_ivas->renderer_type, &( hDirAC->stack_mem ) );
#else
    ivas_dirac_alloc_mem( hDirAC, &( hDirAC->stack_mem ) );
#endif

    mvs2s( DirAC_block_grouping, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 );

@@ -935,6 +961,13 @@ void ivas_dirac_dec_close(
            }
        }
    }
#ifdef FIX_158_DIRAC_MEM
    if ( hDirAC->buffer_energy != NULL )
    {
        count_free( hDirAC->buffer_energy );
        hDirAC->buffer_energy = NULL;
    }
#endif

    for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ )
    {
@@ -1091,6 +1124,9 @@ void ivas_dirac_dec_close(

static void ivas_dirac_alloc_mem(
    DIRAC_DEC_HANDLE hDirAC,
#ifdef FIX_158_DIRAC_MEM
    const RENDERER_TYPE renderer_type,
#endif
    DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem )
{
    int16_t num_freq_bands, num_freq_bands_diff, size;
@@ -1123,8 +1159,14 @@ static void ivas_dirac_alloc_mem(
        set_zero( hDirAC_mem->proto_power_diff_smooth, size );
        hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size );
        set_zero( hDirAC_mem->direct_responses_square, size );

#ifdef FIX_158_DIRAC_MEM
        if ( hDirAC->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) )
        {
#endif
            hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands );
#ifdef FIX_158_DIRAC_MEM
        }
#endif
    }
    hDirAC->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth;
    hDirAC->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth;
@@ -1153,7 +1195,17 @@ static void ivas_dirac_alloc_mem(
    hDirAC->h_output_synthesis_psd_state.direct_responses = hDirAC_mem->direct_responses;

    /* Prototypes */
#ifdef FIX_158_DIRAC_MEM
    hDirAC_mem->proto_direct_buffer_f = NULL;
    hDirAC_mem->proto_diffuse_buffer_f = NULL;
    if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC )
    {
#endif
        hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands );
#ifdef FIX_158_DIRAC_MEM
        if ( hDirAC->proto_signal_decorr_on )
        {
#endif
            if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD )
            {
                hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size );
@@ -1162,12 +1214,25 @@ static void ivas_dirac_alloc_mem(
            {
                hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands );
            }
#ifdef FIX_158_DIRAC_MEM
        }
    }
#endif
    hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f;
    hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f;

    /* Gains/power factors*/
#ifdef FIX_158_DIRAC_MEM
    hDirAC_mem->direct_power_factor = NULL;
    hDirAC_mem->diffuse_power_factor = NULL;
    if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC )
    {
#endif
        hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands );
        hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands );
#ifdef FIX_158_DIRAC_MEM
    }
#endif
    hDirAC->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor;
    hDirAC->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor;

@@ -1175,8 +1240,20 @@ static void ivas_dirac_alloc_mem(
    hDirAC_mem->onset_filter = NULL;
    if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD )
    {
#ifdef FIX_158_DIRAC_MEM
        if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC )
        {
#endif
            hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands );
#ifdef FIX_158_DIRAC_MEM
            if ( hDirAC->proto_signal_decorr_on )
            {
#endif
                hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands );
#ifdef FIX_158_DIRAC_MEM
            }
        }
#endif
    }
    else
    {
@@ -1184,11 +1261,20 @@ static void ivas_dirac_alloc_mem(
        {
            hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands );
        }
#ifndef FIX_158_DIRAC_MEM
        else
        {
            hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * num_freq_bands );
        }
#endif
#ifdef FIX_158_DIRAC_MEM
        if ( hDirAC->proto_signal_decorr_on )
        {
#endif
            hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands );
#ifdef FIX_158_DIRAC_MEM
        }
#endif
    }

    return;
+4 −0
Original line number Diff line number Diff line
@@ -663,7 +663,11 @@ typedef struct ivas_dirac_dec_data_structure
    /*Parameter estimation*/
    int16_t index_buffer_intensity;
    float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF];
#ifdef FIX_158_DIRAC_MEM
    float *buffer_energy;
#else
    float buffer_energy[DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX];
#endif

    /*Decoder parameters */
    /*Prototypes*/