[vlc-devel] [PATCH] equalizer: Enforce type correctness for floats

Ronald Wright logiconcepts819 at gmail.com
Fri Apr 5 21:25:22 CEST 2013


This patch enforces type correctness by changing all double-precision calls
and all double-precision and integral literals in the assignments to floats to
their single-precision equivalents.

---
 modules/audio_filter/equalizer.c         |   68 +++++++++++-----------
 modules/audio_filter/equalizer_presets.h |   91 ++++++++++++++++--------------
 2 files changed, 84 insertions(+), 75 deletions(-)

diff --git a/modules/audio_filter/equalizer.c b/modules/audio_filter/equalizer.c
index 623ea4c..3402bb8 100644
--- a/modules/audio_filter/equalizer.c
+++ b/modules/audio_filter/equalizer.c
@@ -92,7 +92,7 @@ vlc_module_begin ()
               TWOPASS_LONGTEXT, true )
     add_bool( "equalizer-vlcfreqs", true, VLC_BANDS_TEXT,
               VLC_BANDS_LONGTEXT, true )
-    add_float( "equalizer-preamp", 12.0, PREAMP_TEXT,
+    add_float( "equalizer-preamp", 12.0f, PREAMP_TEXT,
                PREAMP_LONGTEXT, true )
     set_callbacks( Open, Close )
     add_shortcut( "equalizer" )
@@ -131,7 +131,7 @@ struct filter_sys_t
 
 static block_t *DoWork( filter_t *, block_t * );
 
-#define EQZ_IN_FACTOR (0.25)
+#define EQZ_IN_FACTOR (0.25f)
 static int  EqzInit( filter_t *, int );
 static void EqzFilter( filter_t *, float *, float *, int, int );
 static void EqzClean( filter_t * );
@@ -220,12 +220,14 @@ typedef struct
 /* The frequency tables */
 static const float f_vlc_frequency_table_10b[EQZ_BANDS_MAX] =
 {
-    60, 170, 310, 600, 1000, 3000, 6000, 12000, 14000, 16000,
+    60.0f, 170.0f, 310.0f, 600.0f, 1000.0f, 3000.0f, 6000.0f, 12000.0f,
+    14000.0f, 16000.0f,
 };
 
 static const float f_iso_frequency_table_10b[EQZ_BANDS_MAX] =
 {
-    31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000,
+    31.25f, 62.5f, 125.0f, 250.0f, 500.0f, 1000.0f, 2000.0f, 4000.0f,
+    8000.0f, 16000.0f,
 };
 
 /* Equalizer coefficient calculation function based on equ-xmms */
@@ -237,10 +239,10 @@ static void EqzCoeffs( int i_rate, float f_octave_percent,
                                   ? f_vlc_frequency_table_10b
                                   : f_iso_frequency_table_10b;
     float f_rate = (float) i_rate;
-    float f_nyquist_freq = 0.5 * f_rate;
-    float f_octave_factor = pow( 2.0, 0.5 * f_octave_percent );
-    float f_octave_factor_1 = 0.5 * ( f_octave_factor + 1.0 );
-    float f_octave_factor_2 = 0.5 * ( f_octave_factor - 1.0 );
+    float f_nyquist_freq = 0.5f * f_rate;
+    float f_octave_factor = powf( 2.0f, 0.5f * f_octave_percent );
+    float f_octave_factor_1 = 0.5f * ( f_octave_factor + 1.0f );
+    float f_octave_factor_2 = 0.5f * ( f_octave_factor - 1.0f );
 
     p_eqz_config->i_band = EQZ_BANDS_MAX;
 
@@ -252,24 +254,24 @@ static void EqzCoeffs( int i_rate, float f_octave_percent,
 
         if( f_freq <= f_nyquist_freq )
         {
-            float f_theta_1 = ( 2.0 * M_PI * f_freq ) / f_rate;
+            float f_theta_1 = ( 2.0f * M_PI * f_freq ) / f_rate;
             float f_theta_2 = f_theta_1 / f_octave_factor;
-            float f_sin     = sin( f_theta_2 );
-            float f_sin_prd = sin( f_theta_2 * f_octave_factor_1 )
-                            * sin( f_theta_2 * f_octave_factor_2 );
-            float f_sin_hlf = f_sin * 0.5;
+            float f_sin     = sinf( f_theta_2 );
+            float f_sin_prd = sinf( f_theta_2 * f_octave_factor_1 )
+                            * sinf( f_theta_2 * f_octave_factor_2 );
+            float f_sin_hlf = f_sin * 0.5f;
             float f_den     = f_sin_hlf + f_sin_prd;
 
             p_eqz_config->band[i].f_alpha = f_sin_prd / f_den;
             p_eqz_config->band[i].f_beta  = ( f_sin_hlf - f_sin_prd ) / f_den;
-            p_eqz_config->band[i].f_gamma = f_sin * cos( f_theta_1 ) / f_den;
+            p_eqz_config->band[i].f_gamma = f_sin * cosf( f_theta_1 ) / f_den;
         }
         else
         {
             /* Any frequency beyond the Nyquist frequency is no good... */
             p_eqz_config->band[i].f_alpha =
             p_eqz_config->band[i].f_beta  =
-            p_eqz_config->band[i].f_gamma = 0.0;
+            p_eqz_config->band[i].f_gamma = 0.0f;
         }
     }
 }
@@ -284,11 +286,11 @@ static inline float EqzConvertdB( float db )
      * -> amp = EQZ_IN_FACTOR*(10^(db/20) - 1)
      **/
 
-    if( db < -20.0 )
-        db = -20.0;
-    else if(  db > 20.0 )
-        db = 20.0;
-    return EQZ_IN_FACTOR * ( pow( 10, db / 20.0 ) - 1.0 );
+    if( db < -20.0f )
+        db = -20.0f;
+    else if(  db > 20.0f )
+        db = 20.0f;
+    return EQZ_IN_FACTOR * ( powf( 10.0f, db / 20.0f ) - 1.0f );
 }
 
 static int EqzInit( filter_t *p_filter, int i_rate )
@@ -301,7 +303,7 @@ static int EqzInit( filter_t *p_filter, int i_rate )
     int i_ret = VLC_ENOMEM;
 
     bool b_vlcFreqs = var_InheritBool( p_aout, "equalizer-vlcfreqs" );
-    EqzCoeffs( i_rate, 1.0, b_vlcFreqs, &cfg );
+    EqzCoeffs( i_rate, 1.0f, b_vlcFreqs, &cfg );
 
     /* Create the static filter config */
     p_sys->i_band = cfg.i_band;
@@ -320,14 +322,14 @@ static int EqzInit( filter_t *p_filter, int i_rate )
 
     /* Filter dyn config */
     p_sys->b_2eqz = false;
-    p_sys->f_gamp = 1.0;
+    p_sys->f_gamp = 1.0f;
     p_sys->f_amp  = malloc( p_sys->i_band * sizeof(float) );
     if( !p_sys->f_amp )
         goto error;
 
     for( i = 0; i < p_sys->i_band; i++ )
     {
-        p_sys->f_amp[i] = 0.0;
+        p_sys->f_amp[i] = 0.0f;
     }
 
     /* Filter state */
@@ -336,14 +338,14 @@ static int EqzInit( filter_t *p_filter, int i_rate )
         p_sys->x[ch][0]  =
         p_sys->x[ch][1]  =
         p_sys->x2[ch][0] =
-        p_sys->x2[ch][1] = 0.0;
+        p_sys->x2[ch][1] = 0.0f;
 
         for( i = 0; i < p_sys->i_band; i++ )
         {
             p_sys->y[ch][i][0]  =
             p_sys->y[ch][i][1]  =
             p_sys->y2[ch][i][0] =
-            p_sys->y2[ch][i][1] = 0.0;
+            p_sys->y2[ch][i][1] = 0.0f;
         }
     }
 
@@ -425,7 +427,7 @@ static void EqzFilter( filter_t *p_filter, float *out, float *in,
         for( ch = 0; ch < i_channels; ch++ )
         {
             const float x = in[ch];
-            float o = 0.0;
+            float o = 0.0f;
 
             for( j = 0; j < p_sys->i_band; j++ )
             {
@@ -445,7 +447,7 @@ static void EqzFilter( filter_t *p_filter, float *out, float *in,
             if( p_sys->b_2eqz )
             {
                 const float x2 = EQZ_IN_FACTOR * x + o;
-                o = 0.0;
+                o = 0.0f;
                 for( j = 0; j < p_sys->i_band; j++ )
                 {
                     float y = p_sys->f_alpha[j] * ( x2 - p_sys->x2[ch][1] ) +
@@ -516,7 +518,7 @@ static int PresetCallback( vlc_object_t *p_aout, char const *psz_cmd,
         {
             char *psz_newbands = NULL;
 
-            p_sys->f_gamp *= pow( 10, eqz_preset_10b[i].f_preamp / 20.0 );
+            p_sys->f_gamp *= powf( 10.0f, eqz_preset_10b[i].f_preamp / 20.0f );
             for( int j = 0; j < p_sys->i_band; j++ )
             {
                 lldiv_t d;
@@ -566,13 +568,13 @@ static int PreampCallback( vlc_object_t *p_this, char const *psz_cmd,
     VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
     filter_sys_t *p_sys = p_data;
 
-    if( newval.f_float < -20.0 )
-        newval.f_float = -20.0;
-    else if( newval.f_float > 20.0 )
-        newval.f_float = 20.0;
+    if( newval.f_float < -20.0f )
+        newval.f_float = -20.0f;
+    else if( newval.f_float > 20.0f )
+        newval.f_float = 20.0f;
 
     vlc_mutex_lock( &p_sys->lock );
-    p_sys->f_gamp = pow( 10, newval.f_float /20.0);
+    p_sys->f_gamp = powf( 10.0f, newval.f_float / 20.0f );
     vlc_mutex_unlock( &p_sys->lock );
 
     return VLC_SUCCESS;
diff --git a/modules/audio_filter/equalizer_presets.h b/modules/audio_filter/equalizer_presets.h
index ff0121a..03f9f6f 100644
--- a/modules/audio_filter/equalizer_presets.h
+++ b/modules/audio_filter/equalizer_presets.h
@@ -54,81 +54,88 @@ typedef struct
 static const eqz_preset_t eqz_preset_10b[NB_PRESETS] =
 {
     {
-        "flat", 10, 12.0,
-        { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
+        "flat", 10, 12.0f,
+        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
     },
     {
-        "classical", 10, 12.0,
-        { -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15,
-          -1.11022e-15, -1.11022e-15, -7.2, -7.2, -7.2, -9.6 }
+        "classical", 10, 12.0f,
+        { -1.11022e-15f, -1.11022e-15f, -1.11022e-15f, -1.11022e-15f,
+          -1.11022e-15f, -1.11022e-15f, -7.2f, -7.2f, -7.2f, -9.6f }
     },
     {
-        "club", 10, 6.0,
-        { -1.11022e-15, -1.11022e-15, 8, 5.6, 5.6, 5.6, 3.2, -1.11022e-15,
-          -1.11022e-15, -1.11022e-15 }
+        "club", 10, 6.0f,
+        { -1.11022e-15f, -1.11022e-15f, 8.0f, 5.6f, 5.6f, 5.6f, 3.2f,
+          -1.11022e-15f, -1.11022e-15f, -1.11022e-15f }
     },
     {
-        "dance", 10, 5.0,
-        { 9.6, 7.2, 2.4, -1.11022e-15, -1.11022e-15, -5.6, -7.2, -7.2,
-          -1.11022e-15, -1.11022e-15 }
+        "dance", 10, 5.0f,
+        { 9.6f, 7.2f, 2.4f, -1.11022e-15f, -1.11022e-15f, -5.6f, -7.2f, -7.2f,
+          -1.11022e-15f, -1.11022e-15f }
     },
     {
-        "fullbass", 10, 5.0,
-        { -8, 9.6, 9.6, 5.6, 1.6, -4, -8, -10.4, -11.2, -11.2  }
+        "fullbass", 10, 5.0f,
+        { -8.0f, 9.6f, 9.6f, 5.6f, 1.6f, -4.0f, -8.0f, -10.4f, -11.2f, -11.2f }
     },
     {
-        "fullbasstreble", 10, 4.0,
-        { 7.2, 5.6, -1.11022e-15, -7.2, -4.8, 1.6, 8, 11.2, 12, 12 }
+        "fullbasstreble", 10, 4.0f,
+        { 7.2f, 5.6f, -1.11022e-15f, -7.2f, -4.8f, 1.6f, 8.0f, 11.2f,
+          12.0f, 12.0f }
     },
     {
-        "fulltreble", 10, 3.0,
-        { -9.6, -9.6, -9.6, -4, 2.4, 11.2, 16, 16, 16, 16.8 }
+        "fulltreble", 10, 3.0f,
+        { -9.6f, -9.6f, -9.6f, -4.0f, 2.4f, 11.2f, 16.0f, 16.0f, 16.0f, 16.8f }
     },
     {
-        "headphones", 10, 4.0,
-        { 4.8, 11.2, 5.6, -3.2, -2.4, 1.6, 4.8, 9.6, 12.8, 14.4 }
+        "headphones", 10, 4.0f,
+        { 4.8f, 11.2f, 5.6f, -3.2f, -2.4f, 1.6f, 4.8f, 9.6f, 12.8f, 14.4f }
     },
     {
-        "largehall", 10, 5.0,
-        { 10.4, 10.4, 5.6, 5.6, -1.11022e-15, -4.8, -4.8, -4.8, -1.11022e-15,
-          -1.11022e-15 }
+        "largehall", 10, 5.0f,
+        { 10.4f, 10.4f, 5.6f, 5.6f, -1.11022e-15f, -4.8f, -4.8f, -4.8f,
+          -1.11022e-15f, -1.11022e-15f }
     },
     {
-        "live", 10, 7.0,
-        { -4.8, -1.11022e-15, 4, 5.6, 5.6, 5.6, 4, 2.4, 2.4, 2.4 }
+        "live", 10, 7.0f,
+        { -4.8f, -1.11022e-15f, 4.0f, 5.6f, 5.6f, 5.6f, 4.0f, 2.4f,
+          2.4f, 2.4f }
     },
     {
-        "party", 10, 6.0,
-        { 7.2, 7.2, -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15,
-          -1.11022e-15, -1.11022e-15, 7.2, 7.2 }
+        "party", 10, 6.0f,
+        { 7.2f, 7.2f, -1.11022e-15f, -1.11022e-15f, -1.11022e-15f,
+          -1.11022e-15f, -1.11022e-15f, -1.11022e-15f, 7.2f, 7.2f }
     },
     {
-        "pop", 10, 6.0,
-        { -1.6, 4.8, 7.2, 8, 5.6, -1.11022e-15, -2.4, -2.4, -1.6, -1.6 }
+        "pop", 10, 6.0f,
+        { -1.6f, 4.8f, 7.2f, 8.0f, 5.6f, -1.11022e-15f, -2.4f, -2.4f,
+          -1.6f, -1.6f }
     },
     {
-        "reggae", 10, 8.0,
-        { -1.11022e-15, -1.11022e-15, -1.11022e-15, -5.6, -1.11022e-15, 6.4,
-          6.4, -1.11022e-15, -1.11022e-15, -1.11022e-15 }
+        "reggae", 10, 8.0f,
+        { -1.11022e-15f, -1.11022e-15f, -1.11022e-15f, -5.6f, -1.11022e-15f,
+          6.4f, 6.4f, -1.11022e-15f, -1.11022e-15f, -1.11022e-15f }
     },
     {
-        "rock", 10, 5.0,
-        { 8, 4.8, -5.6, -8, -3.2, 4, 8.8, 11.2, 11.2, 11.2 }
+        "rock", 10, 5.0f,
+        { 8.0f, 4.8f, -5.6f, -8.0f, -3.2f, 4.0f, 8.8f, 11.2f, 11.2f, 11.2f }
     },
     {
-        "ska", 10, 6.0,
-        { -2.4, -4.8, -4, -1.11022e-15, 4, 5.6, 8.8, 9.6, 11.2, 9.6 }
+        "ska", 10, 6.0f,
+        { -2.4f, -4.8f, -4.0f, -1.11022e-15f, 4.0f, 5.6f, 8.8f, 9.6f,
+          11.2f, 9.6f }
     },
     {
-        "soft", 10, 5.0,
-        { 4.8, 1.6, -1.11022e-15, -2.4, -1.11022e-15, 4, 8, 9.6, 11.2, 12 }
+        "soft", 10, 5.0f,
+        { 4.8f, 1.6f, -1.11022e-15f, -2.4f, -1.11022e-15f, 4.0f, 8.0f, 9.6f,
+          11.2f, 12.0f }
     },
     {
-        "softrock", 10, 7.0,
-        { 4, 4, 2.4, -1.11022e-15, -4, -5.6, -3.2, -1.11022e-15, 2.4, 8.8 }
+        "softrock", 10, 7.0f,
+        { 4.0f, 4.0f, 2.4f, -1.11022e-15f, -4.0f, -5.6f, -3.2f, -1.11022e-15f,
+          2.4f, 8.8f }
     },
     {
-        "techno", 10, 5.0,
-        { 8, 5.6, -1.11022e-15, -5.6, -4.8, -1.11022e-15, 8, 9.6, 9.6, 8.8 }
+        "techno", 10, 5.0f,
+        { 8.0f, 5.6f, -1.11022e-15f, -5.6f, -4.8f, -1.11022e-15f, 8.0f, 9.6f,
+          9.6f, 8.8f }
     },
 };
-- 
1.7.10.4




More information about the vlc-devel mailing list