Commit 97a13b8f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

equalizer: rationalize the equalizer preset callback

This is just a wrapper from the pair of pre-amp and bands callbacks.
(This patch does not fix existing race conditions in init.)
parent b4cd28b3
...@@ -109,10 +109,6 @@ struct filter_sys_t ...@@ -109,10 +109,6 @@ struct filter_sys_t
float *f_beta; float *f_beta;
float *f_gamma; float *f_gamma;
float f_newpreamp;
char *psz_newbands;
bool b_first;
/* Filter dyn config */ /* Filter dyn config */
float *f_amp; /* Per band amp */ float *f_amp; /* Per band amp */
float f_gamp; /* Global preamp */ float f_gamp; /* Global preamp */
...@@ -336,8 +332,6 @@ static int EqzInit( filter_t *p_filter, int i_rate ) ...@@ -336,8 +332,6 @@ static int EqzInit( filter_t *p_filter, int i_rate )
} }
} }
p_sys->psz_newbands = NULL;
var_Create( p_aout, "equalizer-bands", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_aout, "equalizer-bands", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_Create( p_aout, "equalizer-preset", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_aout, "equalizer-preset", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
...@@ -347,19 +341,16 @@ static int EqzInit( filter_t *p_filter, int i_rate ) ...@@ -347,19 +341,16 @@ static int EqzInit( filter_t *p_filter, int i_rate )
/* Get initial values */ /* Get initial values */
var_Get( p_aout, "equalizer-preset", &val1 ); var_Get( p_aout, "equalizer-preset", &val1 );
PresetCallback( VLC_OBJECT( p_aout ), NULL, val1, val1, p_sys );
free( val1.psz_string );
var_Get( p_aout, "equalizer-bands", &val2 ); var_Get( p_aout, "equalizer-bands", &val2 );
var_Get( p_aout, "equalizer-preamp", &val3 ); var_Get( p_aout, "equalizer-preamp", &val3 );
p_sys->b_first = true;
PresetCallback( VLC_OBJECT( p_aout ), NULL, val1, val1, p_sys );
BandsCallback( VLC_OBJECT( p_aout ), NULL, val2, val2, p_sys ); BandsCallback( VLC_OBJECT( p_aout ), NULL, val2, val2, p_sys );
PreampCallback( VLC_OBJECT( p_aout ), NULL, val3, val3, p_sys ); PreampCallback( VLC_OBJECT( p_aout ), NULL, val3, val3, p_sys );
p_sys->b_first = false;
free( val1.psz_string );
/* Exit if we have no preset and no bands value */ /* Exit if we have no preset and no bands value */
if (p_sys->psz_newbands == NULL && (!val2.psz_string || !*val2.psz_string)) if (!val2.psz_string || !*val2.psz_string)
{ {
msg_Err(p_filter, "No preset selected"); msg_Err(p_filter, "No preset selected");
free( val2.psz_string ); free( val2.psz_string );
...@@ -367,16 +358,6 @@ static int EqzInit( filter_t *p_filter, int i_rate ) ...@@ -367,16 +358,6 @@ static int EqzInit( filter_t *p_filter, int i_rate )
i_ret = VLC_EGENERIC; i_ret = VLC_EGENERIC;
goto error; goto error;
} }
/* Register preset bands (for intf) if : */
/* We have no bands info --> the preset info must be given to the intf */
/* or The bands info matches the preset */
if( ( p_sys->psz_newbands && *(val2.psz_string) &&
strstr( p_sys->psz_newbands, val2.psz_string ) ) || !*val2.psz_string )
{
var_SetString( p_aout, "equalizer-bands", p_sys->psz_newbands );
if( p_sys->f_newpreamp == p_sys->f_gamp )
var_SetFloat( p_aout, "equalizer-preamp", p_sys->f_newpreamp );
}
free( val2.psz_string ); free( val2.psz_string );
/* Add our own callbacks */ /* Add our own callbacks */
...@@ -480,72 +461,53 @@ static void EqzClean( filter_t *p_filter ) ...@@ -480,72 +461,53 @@ static void EqzClean( filter_t *p_filter )
free( p_sys->f_gamma ); free( p_sys->f_gamma );
free( p_sys->f_amp ); free( p_sys->f_amp );
free( p_sys->psz_newbands );
} }
static int PresetCallback( vlc_object_t *p_aout, char const *psz_cmd, static int PresetCallback( vlc_object_t *p_aout, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); const eqz_preset_t *preset = NULL;
filter_sys_t *p_sys = p_data;
const char *psz_preset = newval.psz_string; const char *psz_preset = newval.psz_string;
vlc_mutex_lock( &p_sys->lock ); for( unsigned i = 0; i < NB_PRESETS; i++ )
if( !*psz_preset || p_sys->i_band != 10 ) if( !strcasecmp( eqz_preset_10b[i].psz_name, psz_preset ) )
{
preset = eqz_preset_10b + i;
break;
}
if( preset == NULL )
{ {
vlc_mutex_unlock( &p_sys->lock ); msg_Err( p_aout, "equalizer preset '%s' not found", psz_preset );
return VLC_SUCCESS; msg_Info( p_aout, "full list:" );
for( unsigned i = 0; i < NB_PRESETS; i++ )
msg_Info( p_aout, " - '%s'", eqz_preset_10b[i].psz_name );
return VLC_EGENERIC;
} }
for( unsigned i = 0; i < NB_PRESETS; i++ ) char *bands = NULL;
for( unsigned i = 0; i < EQZ_BANDS_MAX; i++ )
{ {
if( !strcasecmp( eqz_preset_10b[i].psz_name, psz_preset ) ) char *psz;
{
char *psz_newbands = NULL;
p_sys->f_gamp *= powf( 10.0f, eqz_preset_10b[i].f_preamp / 20.0f ); lldiv_t d = lldiv( lroundf(preset->f_amp[i] * 10000000.f), 10000000 );
for( int j = 0; j < p_sys->i_band; j++ )
{ if( asprintf( &psz, "%s %lld.%07llu", i ? bands : "",
lldiv_t d; d.quot, d.rem ) == -1 )
char *psz; psz = NULL;
p_sys->f_amp[j] = EqzConvertdB( eqz_preset_10b[i].f_amp[j] ); free( bands );
d = lldiv( eqz_preset_10b[i].f_amp[j] * 10000000, 10000000 ); if( unlikely(psz == NULL) )
if( asprintf( &psz, "%s %lld.%07llu", return VLC_ENOMEM;
psz_newbands ? psz_newbands : "", bands = psz;
d.quot, d.rem ) == -1 )
{
free( psz_newbands );
vlc_mutex_unlock( &p_sys->lock );
return VLC_ENOMEM;
}
free( psz_newbands );
psz_newbands = psz;
}
if( !p_sys->b_first )
{
vlc_mutex_unlock( &p_sys->lock );
var_SetString( p_aout, "equalizer-bands", psz_newbands );
var_SetFloat( p_aout, "equalizer-preamp",
eqz_preset_10b[i].f_preamp );
free( psz_newbands );
}
else
{
p_sys->psz_newbands = psz_newbands;
p_sys->f_newpreamp = eqz_preset_10b[i].f_preamp;
vlc_mutex_unlock( &p_sys->lock );
}
return VLC_SUCCESS;
}
} }
vlc_mutex_unlock( &p_sys->lock );
msg_Err( p_aout, "equalizer preset '%s' not found", psz_preset ); var_SetFloat( p_aout, "equalizer-preamp", preset->f_preamp );
msg_Info( p_aout, "full list:" ); var_SetString( p_aout, "equalizer-bands", bands );
for( unsigned i = 0; i < NB_PRESETS; i++ ) free( bands );
msg_Info( p_aout, " - '%s'", eqz_preset_10b[i].psz_name ); (void) psz_cmd; (void) oldval; (void) p_data;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
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