Commit 68dd76f1 authored by Rémi Duraffort's avatar Rémi Duraffort

visual: save a huge number of allocation/deallocation.

parent 55348507
......@@ -100,25 +100,7 @@ int spectrum_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;
p_buffs = p_s16_buff;
i_80_bands = config_GetInt ( p_aout, "visual-80-bands" );
i_peak = config_GetInt ( p_aout, "visual-peaks" );
if( i_80_bands != 0)
{
xscale = xscale2;
i_nb_bands = 80;
}
else
{
xscale = xscale1;
i_nb_bands = 20;
}
/* Create p_data if needed */
if( !p_data )
{
p_effect->p_data = p_data = malloc( sizeof( spectrum_data ) );
......@@ -130,15 +112,43 @@ int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
p_data->peaks = calloc( 80, sizeof(int) );
p_data->prev_heights = calloc( 80, sizeof(int) );
p_data->i_prev_nb_samples = 0;
p_data->p_prev_s16_buff = NULL;
}
peaks = (int *)p_data->peaks;
prev_heights = (int *)p_data->prev_heights;
/* 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;
i_80_bands = config_GetInt ( p_aout, "visual-80-bands" );
i_peak = config_GetInt ( p_aout, "visual-peaks" );
if( i_80_bands != 0)
{
xscale = xscale2;
i_nb_bands = 80;
}
else
{
xscale = xscale1;
i_nb_bands = 20;
}
height = malloc( i_nb_bands * sizeof(int) );
if( !height )
{
free( p_s16_buff );
return -1;
}
/* Convert the buffer to int16_t */
......@@ -157,7 +167,6 @@ int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
if( !p_state)
{
free( height );
free( p_s16_buff );
msg_Err(p_aout,"unable to initialize FFT transform");
return -1;
}
......@@ -321,7 +330,6 @@ int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
fft_close( p_state );
free( p_s16_buff );
free( height );
return 0;
......
......@@ -397,6 +397,7 @@ static void Close( vlc_object_t *p_this )
{
free( ( ( spectrum_data * )p_effect->p_data )->peaks );
free( ( ( spectrum_data * )p_effect->p_data )->prev_heights );
free( ( ( spectrum_data * )p_effect->p_data )->p_prev_s16_buff );
}
free( p_effect->p_data );
free( p_effect->psz_args );
......
......@@ -42,6 +42,9 @@ typedef struct spectrum_data
{
int *peaks;
int *prev_heights;
unsigned i_prev_nb_samples;
int16_t *p_prev_s16_buff;
} spectrum_data;
......
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