Commit 60b30f42 authored by Rémi Duraffort's avatar Rémi Duraffort

visual: save again some allocation/deallocation cycles.

parent a034cdf6
......@@ -396,11 +396,38 @@ int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
int16_t *p_buffs; /* int16_t converted buffer */
int16_t *p_s16_buff; /* int16_t converted buffer */
p_s16_buff = malloc( p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t) );
if( !p_s16_buff )
return -1;
/* Create the data struct if needed */
spectrometer_data *p_data = p_effect->p_data;
if( !p_data )
{
p_data = malloc( sizeof(spectrometer_data) );
if( !p_data )
return -1;
p_data->peaks = calloc( 80, sizeof(int) );
if( !p_data->peaks )
{
free( p_data );
return -1;
}
p_data->i_prev_nb_samples = 0;
p_data->p_prev_s16_buff = NULL;
p_effect->p_data = (void*)p_data;
}
peaks = p_data->peaks;
/* Allocate the buffer only if the number of samples change */
if( p_buffer->i_nb_samples != p_data->i_prev_nb_samples )
{
free( p_data->p_prev_s16_buff );
p_data->p_prev_s16_buff = malloc( p_buffer->i_nb_samples *
p_effect->i_nb_chans *
sizeof(int16_t));
p_data->i_prev_nb_samples = p_buffer->i_nb_samples;
if( !p_data->p_prev_s16_buff )
return -1;
}
p_buffs = p_s16_buff = p_data->p_prev_s16_buff;
p_buffs = p_s16_buff;
i_original = config_GetInt ( p_aout, "spect-show-original" );
i_80_bands = config_GetInt ( p_aout, "spect-80-bands" );
i_separ = config_GetInt ( p_aout, "spect-separ" );
......@@ -425,23 +452,9 @@ int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
i_nb_bands = 20;
}
if( !p_effect->p_data )
{
p_effect->p_data = calloc( 80, sizeof(int) );
if( !p_effect->p_data )
{
free( p_s16_buff );
return -1;
}
}
peaks =(int *)p_effect->p_data;
height = malloc( i_nb_bands * sizeof(int) );
if( !height)
{
free( p_s16_buff );
return -1;
}
/* Convert the buffer to int16_t */
/* Pasted from float32tos16.c */
......@@ -460,7 +473,6 @@ int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
{
msg_Err(p_aout,"unable to initialize FFT transform");
free( height );
free( p_s16_buff );
return -1;
}
p_buffs = p_s16_buff;
......@@ -772,7 +784,6 @@ int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
fft_close( p_state );
free( p_s16_buff );
free( height );
return 0;
......
......@@ -399,6 +399,11 @@ static void Close( vlc_object_t *p_this )
free( ( ( spectrum_data * )p_effect->p_data )->prev_heights );
free( ( ( spectrum_data * )p_effect->p_data )->p_prev_s16_buff );
}
if( !strncmp( p_effect->psz_name, "spectrometer", strlen( "spectrometer" ) ) )
{
free( ((spectrometer_data*)p_effect->p_data)->peaks );
free( ((spectrometer_data*)p_effect->p_data)->p_prev_s16_buff );
}
free( p_effect->p_data );
free( p_effect->psz_args );
free( p_effect );
......
......@@ -47,6 +47,13 @@ typedef struct spectrum_data
int16_t *p_prev_s16_buff;
} spectrum_data;
typedef struct
{
int *peaks;
unsigned i_prev_nb_samples;
int16_t *p_prev_s16_buff;
} spectrometer_data;
/*****************************************************************************
* aout_filter_sys_t: visualizer audio filter method descriptor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment