X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faudio_filter%2Fequalizer.c;h=bc9fa6ad2edaee1652132c91804cec7943938c09;hb=a130c17fc4c838c4e924f3fa67c47821ebff1779;hp=2433b708d5adc8791ace4c5e677d6ecc2ce77338;hpb=906b68fe0317ff981addd5e9bfe4a5fc5efde6c3;p=vlc diff --git a/modules/audio_filter/equalizer.c b/modules/audio_filter/equalizer.c index 2433b708d5..bc9fa6ad2e 100644 --- a/modules/audio_filter/equalizer.c +++ b/modules/audio_filter/equalizer.c @@ -1,7 +1,7 @@ /***************************************************************************** * equalizer.c: ***************************************************************************** - * Copyright (C) 2004 VideoLAN + * Copyright (C) 2004, 2006 the VideoLAN team * $Id$ * * Authors: Laurent Aimar @@ -18,19 +18,21 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ #include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include -#include -#include "aout_internal.h" +#include "vlc_aout.h" #include "equalizer_presets.h" /* TODO: @@ -50,26 +52,30 @@ static int Open ( vlc_object_t * ); static void Close( vlc_object_t * ); #define PRESET_TEXT N_( "Equalizer preset" ) -#define PRESET_LONGTEXT PRESET_TEXT +#define PRESET_LONGTEXT N_("Preset to use for the equalizer." ) #define BANDS_TEXT N_( "Bands gain") -#define BANDS_LONGTEXT N_( "Override preset bands gain in dB (-20 ... 20)" ) +#define BANDS_LONGTEXT N_( \ + "Don't use presets, but manually specified bands. You need to " \ + "provide 10 values between -20dB and 20dB, separated by spaces, " \ + "e.g. \"0 2 4 2 0 -2 -4 -2 0\"." ) #define TWOPASS_TEXT N_( "Two pass" ) -#define TWOPASS_LONGTEXT N_( "Filter twice the audio" ) +#define TWOPASS_LONGTEXT N_( "Filter the audio twice. This provides a more " \ + "intense effect.") #define PREAMP_TEXT N_("Global gain" ) -#define PREAMP_LONGTEXT N_("Set the global gain in dB (-20 ... 20)" ) +#define PREAMP_LONGTEXT N_("Set the global gain in dB (-20 ... 20)." ) vlc_module_begin(); - set_description( _("Equalizer 10 bands") ); - set_shortname( N_("Equalizer" ) ); + set_description( _("Equalizer with 10 bands") ); + set_shortname( _("Equalizer" ) ); set_capability( "audio filter", 0 ); set_category( CAT_AUDIO ); set_subcategory( SUBCAT_AUDIO_AFILTER ); add_string( "equalizer-preset", "flat", NULL, PRESET_TEXT, - PRESET_LONGTEXT, VLC_TRUE ); + PRESET_LONGTEXT, VLC_FALSE ); change_string_list( preset_list, preset_list_text, 0 ); add_string( "equalizer-bands", NULL, NULL, BANDS_TEXT, BANDS_LONGTEXT, VLC_TRUE ); @@ -116,7 +122,7 @@ static void DoWork( aout_instance_t *, aout_filter_t *, #define EQZ_IN_FACTOR (0.25) static int EqzInit( aout_filter_t *, int ); -static void EqzFilter( aout_instance_t *,aout_filter_t *, float *, float *, +static void EqzFilter( aout_filter_t *, float *, float *, int, int ); static void EqzClean( aout_filter_t * ); @@ -136,16 +142,26 @@ static int Open( vlc_object_t *p_this ) { aout_filter_t *p_filter = (aout_filter_t *)p_this; aout_filter_sys_t *p_sys; + vlc_bool_t b_fit = VLC_TRUE; if( p_filter->input.i_format != VLC_FOURCC('f','l','3','2' ) || p_filter->output.i_format != VLC_FOURCC('f','l','3','2') ) { - msg_Warn( p_filter, "Bad input or output format" ); - return VLC_EGENERIC; + b_fit = VLC_FALSE; + p_filter->input.i_format = VLC_FOURCC('f','l','3','2'); + p_filter->output.i_format = VLC_FOURCC('f','l','3','2'); + msg_Warn( p_filter, "bad input or output format" ); } if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) ) { + b_fit = VLC_FALSE; + memcpy( &p_filter->output, &p_filter->input, + sizeof(audio_sample_format_t) ); msg_Warn( p_filter, "input and output formats are not similar" ); + } + + if ( ! b_fit ) + { return VLC_EGENERIC; } @@ -181,10 +197,11 @@ static void Close( vlc_object_t *p_this ) static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter, aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) { + VLC_UNUSED(p_aout); p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes; - EqzFilter( p_aout, p_filter, (float*)p_out_buf->p_buffer, + EqzFilter( p_filter, (float*)p_out_buf->p_buffer, (float*)p_in_buf->p_buffer, p_in_buf->i_nb_samples, aout_FormatNbChannels( &p_filter->input ) ); } @@ -277,7 +294,7 @@ static int EqzInit( aout_filter_t *p_filter, int i_rate ) else { /* TODO compute the coeffs on the fly */ - msg_Err( p_filter, "unsupported rate" ); + msg_Err( p_filter, "rate not supported" ); return VLC_EGENERIC; } @@ -349,7 +366,8 @@ static int EqzInit( aout_filter_t *p_filter, int i_rate ) strstr( p_sys->psz_newbands, val2.psz_string ) ) || !*val2.psz_string ) { var_SetString( p_aout, "equalizer-bands", p_sys->psz_newbands ); - var_SetFloat( p_aout, "equalizer-preamp", p_sys->f_newpreamp ); + if( p_sys->f_newpreamp == p_sys->f_gamp ) + var_SetFloat( p_aout, "equalizer-preamp", p_sys->f_newpreamp ); } /* Add our own callbacks */ @@ -368,8 +386,7 @@ static int EqzInit( aout_filter_t *p_filter, int i_rate ) return VLC_SUCCESS; } -static void EqzFilter( aout_instance_t *p_aout, - aout_filter_t *p_filter, float *out, float *in, +static void EqzFilter( aout_filter_t *p_filter, float *out, float *in, int i_samples, int i_channels ) { aout_filter_sys_t *p_sys = p_filter->p_sys; @@ -452,6 +469,7 @@ static void EqzClean( aout_filter_t *p_filter ) static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); aout_filter_sys_t *p_sys = (aout_filter_sys_t *)p_data; aout_instance_t *p_aout = (aout_instance_t *)p_this; @@ -472,10 +490,13 @@ static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd, p_sys->f_gamp *= pow( 10, eqz_preset_10b[i]->f_preamp / 20.0 ); for( j = 0; j < p_sys->i_band; j++ ) { + lldiv_t div; p_sys->f_amp[j] = EqzConvertdB( eqz_preset_10b[i]->f_amp[j] ); - sprintf( psz_newbands, "%s %f", psz_newbands, - eqz_preset_10b[i]->f_amp[j] ); + div = lldiv( eqz_preset_10b[i]->f_amp[j] * 10000000, + 10000000 ); + sprintf( psz_newbands, "%s "I64Fd".%07u", psz_newbands, + (int64_t)div.quot, (unsigned int) div.rem ); } if( p_sys->b_first == VLC_FALSE ) { @@ -505,6 +526,7 @@ static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd, static int PreampCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); aout_filter_sys_t *p_sys = (aout_filter_sys_t *)p_data; if( newval.f_float < -20.0 ) @@ -519,6 +541,7 @@ static int PreampCallback( vlc_object_t *p_this, char const *psz_cmd, static int BandsCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); aout_filter_sys_t *p_sys = (aout_filter_sys_t *)p_data; char *psz_bands = newval.psz_string;