X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faudio_filter%2Fnormvol.c;h=6a4b585f596150d3e21efd9036b69f5866e5acbc;hb=f458ada1046dcf8ab43b33010ebac061c8512f11;hp=ec4d79ac5194a08e4f71a5eef0b055a999f38473;hpb=906b68fe0317ff981addd5e9bfe4a5fc5efde6c3;p=vlc diff --git a/modules/audio_filter/normvol.c b/modules/audio_filter/normvol.c index ec4d79ac51..6a4b585f59 100644 --- a/modules/audio_filter/normvol.c +++ b/modules/audio_filter/normvol.c @@ -1,10 +1,10 @@ /***************************************************************************** - * normvol.c : volume normalizer + * normvol.c: volume normalizer ***************************************************************************** - * Copyright (C) 2001 VideoLAN + * Copyright (C) 2001, 2006 the VideoLAN team * $Id$ * - * Authors: Clément Stenac + * Authors: Clément Stenac * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ * * 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. *****************************************************************************/ /* @@ -31,21 +31,21 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include #include /* ENOMEM */ -#include #include #include #include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include -#include -#include +#include /***************************************************************************** * Local prototypes @@ -69,8 +69,8 @@ typedef struct aout_filter_sys_t #define BUFF_TEXT N_("Number of audio buffers" ) #define BUFF_LONGTEXT N_("This is the number of audio buffers on which the " \ "power measurement is made. A higher number of buffers will " \ - "increase the response time of the filter to a high " \ - "power but will make it less sensitive to short variations." ) + "increase the response time of the filter to a spike " \ + "but will make it less sensitive to short variations." ) #define LEVEL_TEXT N_("Max level" ) #define LEVEL_LONGTEXT N_("If the average power over the last N buffers " \ @@ -80,14 +80,14 @@ typedef struct aout_filter_sys_t vlc_module_begin(); set_description( _("Volume normalizer") ); - set_shortname( N_("Volume normalizer") ); + set_shortname( _("Volume normalizer") ); set_category( CAT_AUDIO ); set_subcategory( SUBCAT_AUDIO_AFILTER ); add_shortcut( "volnorm" ); add_integer( "norm-buff-size", 20 ,NULL ,BUFF_TEXT, BUFF_LONGTEXT, - VLC_TRUE); + true); add_float( "norm-max-level", 2.0, NULL, LEVEL_TEXT, - LEVEL_LONGTEXT, VLC_TRUE ); + LEVEL_LONGTEXT, true ); set_capability( "audio filter", 0 ); set_callbacks( Open, Close ); vlc_module_end(); @@ -98,28 +98,38 @@ vlc_module_end(); static int Open( vlc_object_t *p_this ) { aout_filter_t *p_filter = (aout_filter_t*)p_this; + bool b_fit = true; int i_channels; - aout_filter_sys_t *p_sys = p_filter->p_sys = - malloc( sizeof( aout_filter_sys_t ) ); + aout_filter_sys_t *p_sys; 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 = 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 = 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; } p_filter->pf_do_work = DoWork; - p_filter->b_in_place = VLC_TRUE; + p_filter->b_in_place = true; i_channels = aout_FormatNbChannels( &p_filter->input ); + p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) ); p_sys->i_nb = var_CreateGetInteger( p_filter->p_parent, "norm-buff-size" ); p_sys->f_max = var_CreateGetFloat( p_filter->p_parent, "norm-max-level" ); @@ -171,7 +181,7 @@ static int Open( vlc_object_t *p_this ) p_in += i_channels; } - /* sum now contains for each channel the sigma(value²) */ + /* sum now contains for each channel the sigma(value²) */ for( i_chan = 0; i_chan < i_channels; i_chan++ ) { /* Shift our lastbuff */ @@ -179,7 +189,7 @@ static int Open( vlc_object_t *p_this ) &p_sys->p_last[i_chan * p_sys->i_nb + 1], (p_sys->i_nb-1) * sizeof( float ) ); - /* Insert the new average : sqrt(sigma(value²)) */ + /* Insert the new average : sqrt(sigma(value²)) */ p_sys->p_last[ i_chan * p_sys->i_nb + p_sys->i_nb - 1] = sqrt( pf_sum[i_chan] ); @@ -233,7 +243,7 @@ static void Close( vlc_object_t *p_this ) if( p_sys ) { - if( p_sys->p_last) free( p_sys->p_last ); + free( p_sys->p_last ); free( p_sys ); } }