Commit 5e8c2dd3 authored by Dominik Weckbecker's avatar Dominik Weckbecker 💬
Browse files

only allocate more memory for cy_cross_dir_smooth_prev and gains_dir_prev when it is actually used

parent 49a8c09b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -3524,11 +3524,19 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
    const RENDERER_TYPE renderer_type,                          /* i  : renderer type                               */
    const int16_t nchan_transport,                              /* i  : number of transport channels                */
    const int32_t output_Fs                                     /* i  : output sampling rate                        */
#ifdef HODIRAC
	,
    const int16_t hodirac          /* i : flag to indicate HO-DirAC mode*/
#endif
);

void ivas_dirac_dec_output_synthesis_init(
    DIRAC_DEC_HANDLE hDirAC,                                    /* i/o: DirAC handle                                */
    const int16_t nchan_out_woLFE                               /* i  : number of output audio channels without LFE */
#ifdef HODIRAC
    ,
    const int16_t hodirac          /* flag to indicate HO-DirAC mode */
#endif
);

void ivas_dirac_dec_output_synthesis_close(
+26 −11
Original line number Diff line number Diff line
@@ -773,7 +773,12 @@ ivas_error ivas_dirac_dec_config(
    /* output synthesis */
    if ( flag_config == DIRAC_OPEN )
    {
        if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs ) ) != IVAS_ERR_OK )
        if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs
#ifdef HODIRAC
                                                     ,
                                                     st_ivas->sba_analysis_order > 1
#endif
                                                     ) ) != IVAS_ERR_OK )
        {
            return error;
        }
@@ -783,7 +788,12 @@ ivas_error ivas_dirac_dec_config(
    {
        ivas_dirac_dec_output_synthesis_close( hDirAC );

        if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs ) ) != IVAS_ERR_OK )
        if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs 
#ifdef HODIRAC
                                                     ,
                                                     st_ivas->sba_analysis_order > 1
#endif
		) ) != IVAS_ERR_OK )
        {
            return error;
        }
@@ -877,7 +887,12 @@ ivas_error ivas_dirac_dec_config(
    }

    /* output synthesis */
    ivas_dirac_dec_output_synthesis_init( hDirAC, nchan_out_woLFE );
    ivas_dirac_dec_output_synthesis_init( hDirAC, nchan_out_woLFE
#ifdef HODIRAC
		,
		st_ivas->sba_analysis_order
#endif
	);

    /* Allocate stack memory */
    if ( flag_config != DIRAC_OPEN )
+35 −4
Original line number Diff line number Diff line
@@ -91,9 +91,16 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
    RENDERER_TYPE renderer_type,   /* i  : renderer type               */
    const int16_t nchan_transport, /* i  : number of transport channels*/
    const int32_t output_Fs        /* i  : output sampling rate        */
#ifdef HODIRAC
    ,
    const int16_t hodirac /* i : flag to indicate HO-DirAC mode*/
#endif
)
{
    int16_t idx, ch_idx;
#ifdef HODIRAC
    int16_t size;
#endif
    float tmp;
    uint16_t num_diffuse_responses;
    float temp_alpha_synthesis[CLDFB_NO_CHANNELS_MAX];
@@ -168,7 +175,15 @@ ivas_error ivas_dirac_dec_output_synthesis_open(

    /* target PSD buffers */
#ifdef HODIRAC
    if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS * sizeof( float ) ) ) == NULL )
    if ( hodirac )
    {
        size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS;
    }
    else
    {
        size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir;
    }
    if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
    }
@@ -212,7 +227,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open(

    /* direct and diffuse gain buffers */
#ifdef HODIRAC
    if ( ( dirac_output_synthesis_state->gains_dir_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS * sizeof( float ) ) ) == NULL )
    if ( ( dirac_output_synthesis_state->gains_dir_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) );
    }
@@ -360,8 +375,16 @@ ivas_error ivas_dirac_dec_output_synthesis_open(
void ivas_dirac_dec_output_synthesis_init(
    DIRAC_DEC_HANDLE hDirAC,      /* i/o: DirAC handle                                */
    const int16_t nchan_out_woLFE /* i  : number of output audio channels without LFE */
#ifdef HODIRAC
    ,
    const int16_t hodirac /* flag to indicate HO-DirAC mode */
#endif
)
{
#ifdef HODIRAC
    int16_t size;
#endif

    DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
    DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;

@@ -379,7 +402,15 @@ void ivas_dirac_dec_output_synthesis_init(
    }

#ifdef HODIRAC
    set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS );
    if ( hodirac )
    {
        size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS;
    }
    else
    {
        size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir;
    }
    set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size );
#else
    set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir );
#endif
@@ -401,7 +432,7 @@ void ivas_dirac_dec_output_synthesis_init(
        set_zero( h_dirac_output_synthesis_state->proto_power_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_protos_dir );
    }
#ifdef HODIRAC
    set_zero( h_dirac_output_synthesis_state->gains_dir_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS );
    set_zero( h_dirac_output_synthesis_state->gains_dir_prev, size );
#else
    set_zero( h_dirac_output_synthesis_state->gains_dir_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir );
#endif