Commit 014b4047 authored by Ronald Wright's avatar Ronald Wright Committed by Rémi Denis-Courmont

equalizer: Enforce type correctness for floats

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.
Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent 303033c7
...@@ -92,7 +92,7 @@ vlc_module_begin () ...@@ -92,7 +92,7 @@ vlc_module_begin ()
TWOPASS_LONGTEXT, true ) TWOPASS_LONGTEXT, true )
add_bool( "equalizer-vlcfreqs", true, VLC_BANDS_TEXT, add_bool( "equalizer-vlcfreqs", true, VLC_BANDS_TEXT,
VLC_BANDS_LONGTEXT, true ) VLC_BANDS_LONGTEXT, true )
add_float( "equalizer-preamp", 12.0, PREAMP_TEXT, add_float( "equalizer-preamp", 12.0f, PREAMP_TEXT,
PREAMP_LONGTEXT, true ) PREAMP_LONGTEXT, true )
set_callbacks( Open, Close ) set_callbacks( Open, Close )
add_shortcut( "equalizer" ) add_shortcut( "equalizer" )
...@@ -131,7 +131,7 @@ struct filter_sys_t ...@@ -131,7 +131,7 @@ struct filter_sys_t
static block_t *DoWork( filter_t *, block_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 int EqzInit( filter_t *, int );
static void EqzFilter( filter_t *, float *, float *, int, int ); static void EqzFilter( filter_t *, float *, float *, int, int );
static void EqzClean( filter_t * ); static void EqzClean( filter_t * );
...@@ -220,12 +220,14 @@ typedef struct ...@@ -220,12 +220,14 @@ typedef struct
/* The frequency tables */ /* The frequency tables */
static const float f_vlc_frequency_table_10b[EQZ_BANDS_MAX] = 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] = 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 */ /* Equalizer coefficient calculation function based on equ-xmms */
...@@ -237,10 +239,10 @@ static void EqzCoeffs( int i_rate, float f_octave_percent, ...@@ -237,10 +239,10 @@ static void EqzCoeffs( int i_rate, float f_octave_percent,
? f_vlc_frequency_table_10b ? f_vlc_frequency_table_10b
: f_iso_frequency_table_10b; : f_iso_frequency_table_10b;
float f_rate = (float) i_rate; float f_rate = (float) i_rate;
float f_nyquist_freq = 0.5 * f_rate; float f_nyquist_freq = 0.5f * f_rate;
float f_octave_factor = pow( 2.0, 0.5 * f_octave_percent ); float f_octave_factor = powf( 2.0f, 0.5f * f_octave_percent );
float f_octave_factor_1 = 0.5 * ( f_octave_factor + 1.0 ); float f_octave_factor_1 = 0.5f * ( f_octave_factor + 1.0f );
float f_octave_factor_2 = 0.5 * ( f_octave_factor - 1.0 ); float f_octave_factor_2 = 0.5f * ( f_octave_factor - 1.0f );
p_eqz_config->i_band = EQZ_BANDS_MAX; p_eqz_config->i_band = EQZ_BANDS_MAX;
...@@ -252,24 +254,24 @@ static void EqzCoeffs( int i_rate, float f_octave_percent, ...@@ -252,24 +254,24 @@ static void EqzCoeffs( int i_rate, float f_octave_percent,
if( f_freq <= f_nyquist_freq ) 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_theta_2 = f_theta_1 / f_octave_factor;
float f_sin = sin( f_theta_2 ); float f_sin = sinf( f_theta_2 );
float f_sin_prd = sin( f_theta_2 * f_octave_factor_1 ) float f_sin_prd = sinf( f_theta_2 * f_octave_factor_1 )
* sin( f_theta_2 * f_octave_factor_2 ); * sinf( f_theta_2 * f_octave_factor_2 );
float f_sin_hlf = f_sin * 0.5; float f_sin_hlf = f_sin * 0.5f;
float f_den = f_sin_hlf + f_sin_prd; 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_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_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 else
{ {
/* Any frequency beyond the Nyquist frequency is no good... */ /* Any frequency beyond the Nyquist frequency is no good... */
p_eqz_config->band[i].f_alpha = p_eqz_config->band[i].f_alpha =
p_eqz_config->band[i].f_beta = 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 ) ...@@ -284,11 +286,11 @@ static inline float EqzConvertdB( float db )
* -> amp = EQZ_IN_FACTOR*(10^(db/20) - 1) * -> amp = EQZ_IN_FACTOR*(10^(db/20) - 1)
**/ **/
if( db < -20.0 ) if( db < -20.0f )
db = -20.0; db = -20.0f;
else if( db > 20.0 ) else if( db > 20.0f )
db = 20.0; db = 20.0f;
return EQZ_IN_FACTOR * ( pow( 10, db / 20.0 ) - 1.0 ); return EQZ_IN_FACTOR * ( powf( 10.0f, db / 20.0f ) - 1.0f );
} }
static int EqzInit( filter_t *p_filter, int i_rate ) static int EqzInit( filter_t *p_filter, int i_rate )
...@@ -301,7 +303,7 @@ 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; int i_ret = VLC_ENOMEM;
bool b_vlcFreqs = var_InheritBool( p_aout, "equalizer-vlcfreqs" ); 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 */ /* Create the static filter config */
p_sys->i_band = cfg.i_band; p_sys->i_band = cfg.i_band;
...@@ -320,14 +322,14 @@ static int EqzInit( filter_t *p_filter, int i_rate ) ...@@ -320,14 +322,14 @@ static int EqzInit( filter_t *p_filter, int i_rate )
/* Filter dyn config */ /* Filter dyn config */
p_sys->b_2eqz = false; 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) ); p_sys->f_amp = malloc( p_sys->i_band * sizeof(float) );
if( !p_sys->f_amp ) if( !p_sys->f_amp )
goto error; goto error;
for( i = 0; i < p_sys->i_band; i++ ) 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 */ /* Filter state */
...@@ -336,14 +338,14 @@ static int EqzInit( filter_t *p_filter, int i_rate ) ...@@ -336,14 +338,14 @@ static int EqzInit( filter_t *p_filter, int i_rate )
p_sys->x[ch][0] = p_sys->x[ch][0] =
p_sys->x[ch][1] = p_sys->x[ch][1] =
p_sys->x2[ch][0] = 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++ ) for( i = 0; i < p_sys->i_band; i++ )
{ {
p_sys->y[ch][i][0] = p_sys->y[ch][i][0] =
p_sys->y[ch][i][1] = p_sys->y[ch][i][1] =
p_sys->y2[ch][i][0] = 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, ...@@ -425,7 +427,7 @@ static void EqzFilter( filter_t *p_filter, float *out, float *in,
for( ch = 0; ch < i_channels; ch++ ) for( ch = 0; ch < i_channels; ch++ )
{ {
const float x = in[ch]; const float x = in[ch];
float o = 0.0; float o = 0.0f;
for( j = 0; j < p_sys->i_band; j++ ) for( j = 0; j < p_sys->i_band; j++ )
{ {
...@@ -445,7 +447,7 @@ static void EqzFilter( filter_t *p_filter, float *out, float *in, ...@@ -445,7 +447,7 @@ static void EqzFilter( filter_t *p_filter, float *out, float *in,
if( p_sys->b_2eqz ) if( p_sys->b_2eqz )
{ {
const float x2 = EQZ_IN_FACTOR * x + o; const float x2 = EQZ_IN_FACTOR * x + o;
o = 0.0; o = 0.0f;
for( j = 0; j < p_sys->i_band; j++ ) for( j = 0; j < p_sys->i_band; j++ )
{ {
float y = p_sys->f_alpha[j] * ( x2 - p_sys->x2[ch][1] ) + 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, ...@@ -516,7 +518,7 @@ static int PresetCallback( vlc_object_t *p_aout, char const *psz_cmd,
{ {
char *psz_newbands = NULL; 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++ ) for( int j = 0; j < p_sys->i_band; j++ )
{ {
lldiv_t d; lldiv_t d;
...@@ -566,13 +568,13 @@ static int PreampCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -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); VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
filter_sys_t *p_sys = p_data; filter_sys_t *p_sys = p_data;
if( newval.f_float < -20.0 ) if( newval.f_float < -20.0f )
newval.f_float = -20.0; newval.f_float = -20.0f;
else if( newval.f_float > 20.0 ) else if( newval.f_float > 20.0f )
newval.f_float = 20.0; newval.f_float = 20.0f;
vlc_mutex_lock( &p_sys->lock ); 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 ); vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS; return VLC_SUCCESS;
......
...@@ -54,81 +54,88 @@ typedef struct ...@@ -54,81 +54,88 @@ typedef struct
static const eqz_preset_t eqz_preset_10b[NB_PRESETS] = static const eqz_preset_t eqz_preset_10b[NB_PRESETS] =
{ {
{ {
"flat", 10, 12.0, "flat", 10, 12.0f,
{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
}, },
{ {
"classical", 10, 12.0, "classical", 10, 12.0f,
{ -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15, { -1.11022e-15f, -1.11022e-15f, -1.11022e-15f, -1.11022e-15f,
-1.11022e-15, -1.11022e-15, -7.2, -7.2, -7.2, -9.6 } -1.11022e-15f, -1.11022e-15f, -7.2f, -7.2f, -7.2f, -9.6f }
}, },
{ {
"club", 10, 6.0, "club", 10, 6.0f,
{ -1.11022e-15, -1.11022e-15, 8, 5.6, 5.6, 5.6, 3.2, -1.11022e-15, { -1.11022e-15f, -1.11022e-15f, 8.0f, 5.6f, 5.6f, 5.6f, 3.2f,
-1.11022e-15, -1.11022e-15 } -1.11022e-15f, -1.11022e-15f, -1.11022e-15f }
}, },
{ {
"dance", 10, 5.0, "dance", 10, 5.0f,
{ 9.6, 7.2, 2.4, -1.11022e-15, -1.11022e-15, -5.6, -7.2, -7.2, { 9.6f, 7.2f, 2.4f, -1.11022e-15f, -1.11022e-15f, -5.6f, -7.2f, -7.2f,
-1.11022e-15, -1.11022e-15 } -1.11022e-15f, -1.11022e-15f }
}, },
{ {
"fullbass", 10, 5.0, "fullbass", 10, 5.0f,
{ -8, 9.6, 9.6, 5.6, 1.6, -4, -8, -10.4, -11.2, -11.2 } { -8.0f, 9.6f, 9.6f, 5.6f, 1.6f, -4.0f, -8.0f, -10.4f, -11.2f, -11.2f }
}, },
{ {
"fullbasstreble", 10, 4.0, "fullbasstreble", 10, 4.0f,
{ 7.2, 5.6, -1.11022e-15, -7.2, -4.8, 1.6, 8, 11.2, 12, 12 } { 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, "fulltreble", 10, 3.0f,
{ -9.6, -9.6, -9.6, -4, 2.4, 11.2, 16, 16, 16, 16.8 } { -9.6f, -9.6f, -9.6f, -4.0f, 2.4f, 11.2f, 16.0f, 16.0f, 16.0f, 16.8f }
}, },
{ {
"headphones", 10, 4.0, "headphones", 10, 4.0f,
{ 4.8, 11.2, 5.6, -3.2, -2.4, 1.6, 4.8, 9.6, 12.8, 14.4 } { 4.8f, 11.2f, 5.6f, -3.2f, -2.4f, 1.6f, 4.8f, 9.6f, 12.8f, 14.4f }
}, },
{ {
"largehall", 10, 5.0, "largehall", 10, 5.0f,
{ 10.4, 10.4, 5.6, 5.6, -1.11022e-15, -4.8, -4.8, -4.8, -1.11022e-15, { 10.4f, 10.4f, 5.6f, 5.6f, -1.11022e-15f, -4.8f, -4.8f, -4.8f,
-1.11022e-15 } -1.11022e-15f, -1.11022e-15f }
}, },
{ {
"live", 10, 7.0, "live", 10, 7.0f,
{ -4.8, -1.11022e-15, 4, 5.6, 5.6, 5.6, 4, 2.4, 2.4, 2.4 } { -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, "party", 10, 6.0f,
{ 7.2, 7.2, -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15, { 7.2f, 7.2f, -1.11022e-15f, -1.11022e-15f, -1.11022e-15f,
-1.11022e-15, -1.11022e-15, 7.2, 7.2 } -1.11022e-15f, -1.11022e-15f, -1.11022e-15f, 7.2f, 7.2f }
}, },
{ {
"pop", 10, 6.0, "pop", 10, 6.0f,
{ -1.6, 4.8, 7.2, 8, 5.6, -1.11022e-15, -2.4, -2.4, -1.6, -1.6 } { -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, "reggae", 10, 8.0f,
{ -1.11022e-15, -1.11022e-15, -1.11022e-15, -5.6, -1.11022e-15, 6.4, { -1.11022e-15f, -1.11022e-15f, -1.11022e-15f, -5.6f, -1.11022e-15f,
6.4, -1.11022e-15, -1.11022e-15, -1.11022e-15 } 6.4f, 6.4f, -1.11022e-15f, -1.11022e-15f, -1.11022e-15f }
}, },
{ {
"rock", 10, 5.0, "rock", 10, 5.0f,
{ 8, 4.8, -5.6, -8, -3.2, 4, 8.8, 11.2, 11.2, 11.2 } { 8.0f, 4.8f, -5.6f, -8.0f, -3.2f, 4.0f, 8.8f, 11.2f, 11.2f, 11.2f }
}, },
{ {
"ska", 10, 6.0, "ska", 10, 6.0f,
{ -2.4, -4.8, -4, -1.11022e-15, 4, 5.6, 8.8, 9.6, 11.2, 9.6 } { -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, "soft", 10, 5.0f,
{ 4.8, 1.6, -1.11022e-15, -2.4, -1.11022e-15, 4, 8, 9.6, 11.2, 12 } { 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, "softrock", 10, 7.0f,
{ 4, 4, 2.4, -1.11022e-15, -4, -5.6, -3.2, -1.11022e-15, 2.4, 8.8 } { 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, "techno", 10, 5.0f,
{ 8, 5.6, -1.11022e-15, -5.6, -4.8, -1.11022e-15, 8, 9.6, 9.6, 8.8 } { 8.0f, 5.6f, -1.11022e-15f, -5.6f, -4.8f, -1.11022e-15f, 8.0f, 9.6f,
9.6f, 8.8f }
}, },
}; };
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