[vlc-devel] [PATCH 2/2] visual: Allow use of FFT windowing in spectrum-based visualizations
Ronald Wright
logiconcepts819 at gmail.com
Fri Feb 7 19:12:01 CET 2014
---
modules/visualization/Modules.am | 6 ++++--
modules/visualization/glspectrum.c | 15 +++++++++++++++
modules/visualization/visual/effects.c | 30 ++++++++++++++++++++++++++++++
modules/visualization/visual/visual.c | 16 ++++++++++++++++
4 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/modules/visualization/Modules.am b/modules/visualization/Modules.am
index 517c3b9..ecea82f 100644
--- a/modules/visualization/Modules.am
+++ b/modules/visualization/Modules.am
@@ -10,10 +10,12 @@ visualization_LTLIBRARIES += $(LTLIBprojectm)
libvisual_plugin_la_SOURCES = \
visual/visual.c visual/visual.h \
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)
visualization_LTLIBRARIES += libvisual_plugin.la
SOURCES_vsxu = vsxu.cpp cyclic_buffer.h
-SOURCES_glspectrum = glspectrum.c visual/fft.c visual/fft.h
+SOURCES_glspectrum = glspectrum.c visual/fft.c visual/fft.h \
+ visual/window.c visual/window.h visual/window_presets.h
diff --git a/modules/visualization/glspectrum.c b/modules/visualization/glspectrum.c
index a361ef0..3b0ad9d 100644
--- a/modules/visualization/glspectrum.c
+++ b/modules/visualization/glspectrum.c
@@ -40,6 +40,7 @@
#include <math.h>
#include "visual/fft.h"
+#include "visual/window.h"
/*****************************************************************************
@@ -94,6 +95,9 @@ struct filter_sys_t
/* Window size */
int i_width;
int i_height;
+
+ /* FFT window parameters */
+ window_param wind_param;
};
@@ -135,6 +139,9 @@ static int Open(vlc_object_t * p_this)
p_sys->f_rotationAngle = 0;
p_sys->f_rotationIncrement = ROTATION_INCREMENT;
+ /* Fetch the FFT window parameters */
+ window_get_param( VLC_OBJECT( p_filter ), &p_sys->wind_param );
+
/* Create the FIFO for the audio data. */
p_sys->fifo = block_FifoNew();
if (p_sys->fifo == NULL)
@@ -425,6 +432,7 @@ static void *Thread( void *p_data )
36,47,62,82,107,141,184,255};
fft_state *p_state = NULL; /* internal FFT data */
+ DEFINE_WIND_CONTEXT(wind_ctx); /* internal window data */
unsigned i, j;
float p_output[FFT_BUFFER_SIZE]; /* Raw FFT Result */
@@ -471,6 +479,11 @@ static void *Thread( void *p_data )
msg_Err(p_filter,"unable to initialize FFT transform");
goto release;
}
+ if (!window_init(FFT_BUFFER_SIZE, &p_sys->wind_param, &wind_ctx))
+ {
+ msg_Err(p_filter,"unable to initialize FFT window");
+ goto release;
+ }
p_buffs = p_s16_buff;
for (i = 0 ; i < FFT_BUFFER_SIZE; i++)
{
@@ -481,6 +494,7 @@ static void *Thread( void *p_data )
if (p_buffs >= &p_s16_buff[block->i_nb_samples * p_sys->i_channels])
p_buffs = p_s16_buff;
}
+ window_scale_in_place (p_buffer1, &wind_ctx);
fft_perform (p_buffer1, p_output, p_state);
for (i = 0; i< FFT_BUFFER_SIZE; ++i)
@@ -532,6 +546,7 @@ static void *Thread( void *p_data )
}
release:
+ window_close(&wind_ctx);
fft_close(p_state);
block_Release(block);
vlc_restorecancel(canc);
diff --git a/modules/visualization/visual/effects.c b/modules/visualization/visual/effects.c
index f216de8..ca2e1bd 100644
--- a/modules/visualization/visual/effects.c
+++ b/modules/visualization/visual/effects.c
@@ -37,6 +37,7 @@
#include <math.h>
#include "fft.h"
+#include "window.h"
#define PEAK_SPEED 1
#define BAR_DECREASE_SPEED 5
@@ -72,6 +73,8 @@ typedef struct spectrum_data
unsigned i_prev_nb_samples;
int16_t *p_prev_s16_buff;
+
+ window_param wind_param;
} spectrum_data;
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;
fft_state *p_state; /* internal FFT data */
+ DEFINE_WIND_CONTEXT( wind_ctx ); /* internal window data */
int i , j , y , k;
int i_line;
@@ -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->p_prev_s16_buff = NULL;
+
+ window_get_param( p_aout, &p_data->wind_param );
}
peaks = (int *)p_data->peaks;
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,
msg_Err(p_aout,"unable to initialize FFT transform");
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;
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,
p_buffs = p_s16_buff;
}
+ window_scale_in_place( p_buffer1, &wind_ctx );
fft_perform( p_buffer1, p_output, p_state);
for( i = 0; i< FFT_BUFFER_SIZE ; i++ )
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,
}
}
+ window_close( &wind_ctx );
+
fft_close( p_state );
free( height );
@@ -370,6 +386,8 @@ typedef struct
unsigned i_prev_nb_samples;
int16_t *p_prev_s16_buff;
+
+ window_param wind_param;
} spectrometer_data;
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) */
fft_state *p_state; /* internal FFT data */
+ DEFINE_WIND_CONTEXT( wind_ctx ); /* internal window data */
int i , j , k;
int i_line = 0;
@@ -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->p_prev_s16_buff = NULL;
+ window_get_param( p_aout, &p_data->wind_param );
p_effect->p_data = (void*)p_data;
}
peaks = p_data->peaks;
@@ -511,6 +531,13 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
free( height );
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;
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,
if( p_buffs >= &p_s16_buff[p_buffer->i_nb_samples * p_effect->i_nb_chans] )
p_buffs = p_s16_buff;
}
+ window_scale_in_place( p_buffer1, &wind_ctx );
fft_perform( p_buffer1, p_output, p_state);
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,
}
}
+ window_close( &wind_ctx );
+
fft_close( p_state );
free( height );
diff --git a/modules/visualization/visual/visual.c b/modules/visualization/visual/visual.c
index 86557ec..628fd70 100644
--- a/modules/visualization/visual/visual.c
+++ b/modules/visualization/visual/visual.c
@@ -39,6 +39,8 @@
#include "visual.h"
+#include "window_presets.h"
+
/*****************************************************************************
* Module descriptor
*****************************************************************************/
@@ -56,6 +58,15 @@
#define HEIGHT_LONGTEXT N_( \
"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 SPNBBANDS_LONGTEXT N_( \
"More bands for the spectrometer : 80 if enabled else 20." )
@@ -115,6 +126,11 @@ vlc_module_begin ()
WIDTH_TEXT, WIDTH_LONGTEXT, false )
add_integer("effect-height" , VOUT_HEIGHT ,
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 )
add_obsolete_integer( "visual-nbbands" ) /* Since 1.0.0 */
add_bool("visual-80-bands", true,
--
1.8.3.2
More information about the vlc-devel
mailing list