Commit cf024724 authored by Ron Wright's avatar Ron Wright Committed by Jean-Baptiste Kempf

Visual: use of FFT windowing in spectrum effect

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 17b03dd5
...@@ -10,7 +10,8 @@ visualization_LTLIBRARIES += $(LTLIBprojectm) ...@@ -10,7 +10,8 @@ visualization_LTLIBRARIES += $(LTLIBprojectm)
libvisual_plugin_la_SOURCES = \ libvisual_plugin_la_SOURCES = \
visual/visual.c visual/visual.h \ visual/visual.c visual/visual.h \
visual/effects.c \ visual/effects.c \
visual/fft.c visual/fft.h visual/fft.c visual/fft.h \
visual/window.c visual/window.h visual/window_presets.h
libvisual_plugin_la_LIBADD = $(LIBM) libvisual_plugin_la_LIBADD = $(LIBM)
visualization_LTLIBRARIES += libvisual_plugin.la visualization_LTLIBRARIES += libvisual_plugin.la
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <math.h> #include <math.h>
#include "fft.h" #include "fft.h"
#include "window.h"
#define PEAK_SPEED 1 #define PEAK_SPEED 1
#define BAR_DECREASE_SPEED 5 #define BAR_DECREASE_SPEED 5
...@@ -72,6 +73,8 @@ typedef struct spectrum_data ...@@ -72,6 +73,8 @@ typedef struct spectrum_data
unsigned i_prev_nb_samples; unsigned i_prev_nb_samples;
int16_t *p_prev_s16_buff; int16_t *p_prev_s16_buff;
window_param wind_param;
} spectrum_data; } spectrum_data;
static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
...@@ -102,6 +105,7 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -102,6 +105,7 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
const int *xscale; const int *xscale;
fft_state *p_state; /* internal FFT data */ fft_state *p_state; /* internal FFT data */
DEFINE_WIND_CONTEXT( wind_ctx ); /* internal window data */
int i , j , y , k; int i , j , y , k;
int i_line; int i_line;
...@@ -127,6 +131,8 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -127,6 +131,8 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
p_data->i_prev_nb_samples = 0; p_data->i_prev_nb_samples = 0;
p_data->p_prev_s16_buff = NULL; p_data->p_prev_s16_buff = NULL;
window_get_param( p_aout, &p_data->wind_param );
} }
peaks = (int *)p_data->peaks; peaks = (int *)p_data->peaks;
prev_heights = (int *)p_data->prev_heights; prev_heights = (int *)p_data->prev_heights;
...@@ -182,6 +188,13 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -182,6 +188,13 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
msg_Err(p_aout,"unable to initialize FFT transform"); msg_Err(p_aout,"unable to initialize FFT transform");
return -1; return -1;
} }
if( !window_init( FFT_BUFFER_SIZE, &p_data->wind_param, &wind_ctx ) )
{
fft_close( p_state );
free( height );
msg_Err(p_aout,"unable to initialize FFT window");
return -1;
}
p_buffs = p_s16_buff; p_buffs = p_s16_buff;
for ( i = 0 ; i < FFT_BUFFER_SIZE ; i++) for ( i = 0 ; i < FFT_BUFFER_SIZE ; i++)
{ {
...@@ -193,6 +206,7 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -193,6 +206,7 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
p_buffs = p_s16_buff; p_buffs = p_s16_buff;
} }
window_scale_in_place( p_buffer1, &wind_ctx );
fft_perform( p_buffer1, p_output, p_state); fft_perform( p_buffer1, p_output, p_state);
for( i = 0; i< FFT_BUFFER_SIZE ; i++ ) for( i = 0; i< FFT_BUFFER_SIZE ; i++ )
p_dest[i] = p_output[i] * ( 2 ^ 16 ) / ( ( FFT_BUFFER_SIZE / 2 * 32768 ) ^ 2 ); p_dest[i] = p_output[i] * ( 2 ^ 16 ) / ( ( FFT_BUFFER_SIZE / 2 * 32768 ) ^ 2 );
...@@ -340,6 +354,8 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -340,6 +354,8 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
} }
} }
window_close( &wind_ctx );
fft_close( p_state ); fft_close( p_state );
free( height ); free( height );
...@@ -370,6 +386,8 @@ typedef struct ...@@ -370,6 +386,8 @@ typedef struct
unsigned i_prev_nb_samples; unsigned i_prev_nb_samples;
int16_t *p_prev_s16_buff; int16_t *p_prev_s16_buff;
window_param wind_param;
} spectrometer_data; } spectrometer_data;
static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
...@@ -420,6 +438,7 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -420,6 +438,7 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
const double y_scale = 3.60673760222; /* (log 256) */ const double y_scale = 3.60673760222; /* (log 256) */
fft_state *p_state; /* internal FFT data */ fft_state *p_state; /* internal FFT data */
DEFINE_WIND_CONTEXT( wind_ctx ); /* internal window data */
int i , j , k; int i , j , k;
int i_line = 0; int i_line = 0;
...@@ -447,6 +466,7 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -447,6 +466,7 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
} }
p_data->i_prev_nb_samples = 0; p_data->i_prev_nb_samples = 0;
p_data->p_prev_s16_buff = NULL; p_data->p_prev_s16_buff = NULL;
window_get_param( p_aout, &p_data->wind_param );
p_effect->p_data = (void*)p_data; p_effect->p_data = (void*)p_data;
} }
peaks = p_data->peaks; peaks = p_data->peaks;
...@@ -511,6 +531,13 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -511,6 +531,13 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
free( height ); free( height );
return -1; return -1;
} }
if( !window_init( FFT_BUFFER_SIZE, &p_data->wind_param, &wind_ctx ) )
{
fft_close( p_state );
free( height );
msg_Err(p_aout,"unable to initialize FFT window");
return -1;
}
p_buffs = p_s16_buff; p_buffs = p_s16_buff;
for ( i = 0 ; i < FFT_BUFFER_SIZE; i++) for ( i = 0 ; i < FFT_BUFFER_SIZE; i++)
{ {
...@@ -521,6 +548,7 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -521,6 +548,7 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
if( p_buffs >= &p_s16_buff[p_buffer->i_nb_samples * p_effect->i_nb_chans] ) if( p_buffs >= &p_s16_buff[p_buffer->i_nb_samples * p_effect->i_nb_chans] )
p_buffs = p_s16_buff; p_buffs = p_s16_buff;
} }
window_scale_in_place( p_buffer1, &wind_ctx );
fft_perform( p_buffer1, p_output, p_state); fft_perform( p_buffer1, p_output, p_state);
for(i = 0; i < FFT_BUFFER_SIZE; i++) for(i = 0; i < FFT_BUFFER_SIZE; i++)
{ {
...@@ -818,6 +846,8 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -818,6 +846,8 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
} }
} }
window_close( &wind_ctx );
fft_close( p_state ); fft_close( p_state );
free( height ); free( height );
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include "visual.h" #include "visual.h"
#include "window_presets.h"
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
*****************************************************************************/ *****************************************************************************/
...@@ -56,6 +58,15 @@ ...@@ -56,6 +58,15 @@
#define HEIGHT_LONGTEXT N_( \ #define HEIGHT_LONGTEXT N_( \
"The height of the effects video window, in pixels." ) "The height of the effects video window, in pixels." )
#define FFT_WINDOW_TEXT N_( "FFT window" )
#define FFT_WINDOW_LONGTEXT N_( \
"The type of FFT window to use for spectrum-based visualizations." )
#define KAISER_PARAMETER_TEXT N_( "Kaiser window parameter" )
#define KAISER_PARAMETER_LONGTEXT N_( \
"The parameter alpha for the Kaiser window. Increasing alpha " \
"increases the main-lobe width and decreases the side-lobe amplitude. " )
#define NBBANDS_TEXT N_( "Show 80 bands instead of 20" ) #define NBBANDS_TEXT N_( "Show 80 bands instead of 20" )
#define SPNBBANDS_LONGTEXT N_( \ #define SPNBBANDS_LONGTEXT N_( \
"More bands for the spectrometer : 80 if enabled else 20." ) "More bands for the spectrometer : 80 if enabled else 20." )
...@@ -115,6 +126,11 @@ vlc_module_begin () ...@@ -115,6 +126,11 @@ vlc_module_begin ()
WIDTH_TEXT, WIDTH_LONGTEXT, false ) WIDTH_TEXT, WIDTH_LONGTEXT, false )
add_integer("effect-height" , VOUT_HEIGHT , add_integer("effect-height" , VOUT_HEIGHT ,
HEIGHT_TEXT, HEIGHT_LONGTEXT, false ) HEIGHT_TEXT, HEIGHT_LONGTEXT, false )
add_string("effect-fft-window", "flat",
FFT_WINDOW_TEXT, FFT_WINDOW_LONGTEXT, true )
change_string_list( window_list, window_list_text )
add_float("effect-kaiser-param", 3.0f,
KAISER_PARAMETER_TEXT, KAISER_PARAMETER_LONGTEXT, true )
set_section( N_("Spectrum analyser") , NULL ) set_section( N_("Spectrum analyser") , NULL )
add_obsolete_integer( "visual-nbbands" ) /* Since 1.0.0 */ add_obsolete_integer( "visual-nbbands" ) /* Since 1.0.0 */
add_bool("visual-80-bands", true, add_bool("visual-80-bands", true,
......
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