[vlc-commits] Visual: use of FFT windowing in spectrum effect

Ron Wright git at videolan.org
Sat Feb 8 15:39:41 CET 2014


vlc | branch: master | Ron Wright <logiconcepts819 at gmail.com> | Sat Feb  8 15:33:42 2014 +0100| [cf024724079899b6d2091421b333c1968e416434] | committer: Jean-Baptiste Kempf

Visual: use of FFT windowing in spectrum effect

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cf024724079899b6d2091421b333c1968e416434
---

 modules/visualization/Modules.am       |    3 ++-
 modules/visualization/visual/effects.c |   30 ++++++++++++++++++++++++++++++
 modules/visualization/visual/visual.c  |   16 ++++++++++++++++
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/modules/visualization/Modules.am b/modules/visualization/Modules.am
index 517c3b9..60d376d 100644
--- a/modules/visualization/Modules.am
+++ b/modules/visualization/Modules.am
@@ -10,7 +10,8 @@ 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
 
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,



More information about the vlc-commits mailing list