X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faudio_filter%2Fnormvol.c;h=ef80e2d67bb456ec65c4b54427ddb8a739dc0309;hb=260dcf6b2ea307d80679769d0477a0b84197976b;hp=80cb8f38e0c48c7edc2ad02bd71d658af4098cc8;hpb=dc8b128a9f34d9eb75d3158566cbb95df8bae61b;p=vlc diff --git a/modules/audio_filter/normvol.c b/modules/audio_filter/normvol.c index 80cb8f38e0..ef80e2d67b 100644 --- a/modules/audio_filter/normvol.c +++ b/modules/audio_filter/normvol.c @@ -31,21 +31,22 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include /* ENOMEM */ -#include #include #include #include -#include -#include +#include +#include -#include +#include /***************************************************************************** * Local prototypes @@ -56,12 +57,12 @@ static void Close ( vlc_object_t * ); static void DoWork ( aout_instance_t * , aout_filter_t *, aout_buffer_t * , aout_buffer_t *); -typedef struct aout_filter_sys_t +struct aout_filter_sys_t { int i_nb; float *p_last; float f_max; -} aout_filter_sys_t; +}; /***************************************************************************** * Module descriptor @@ -78,19 +79,19 @@ typedef struct aout_filter_sys_t "This value is a positive floating point number. A value " \ "between 0.5 and 10 seems sensible." ) -vlc_module_begin(); - set_description( _("Volume normalizer") ); - set_shortname( _("Volume normalizer") ); - set_category( CAT_AUDIO ); - set_subcategory( SUBCAT_AUDIO_AFILTER ); - add_shortcut( "volnorm" ); +vlc_module_begin () + set_description( N_("Volume normalizer") ) + set_shortname( N_("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 ); - set_capability( "audio filter", 0 ); - set_callbacks( Open, Close ); -vlc_module_end(); + LEVEL_LONGTEXT, true ) + set_capability( "audio filter", 0 ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Open: initialize and create stuff @@ -98,24 +99,23 @@ vlc_module_end(); static int Open( vlc_object_t *p_this ) { aout_filter_t *p_filter = (aout_filter_t*)p_this; - vlc_bool_t b_fit = VLC_TRUE; + 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') ) + if( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 || + p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 ) { - 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'); + b_fit = false; + p_filter->fmt_in.audio.i_format = VLC_CODEC_FL32; + p_filter->fmt_out.audio.i_format = VLC_CODEC_FL32; msg_Warn( p_filter, "bad input or output format" ); } - if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) ) + if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) { - b_fit = VLC_FALSE; - memcpy( &p_filter->output, &p_filter->input, + b_fit = false; + memcpy( &p_filter->fmt_out.audio, &p_filter->fmt_in.audio, sizeof(audio_sample_format_t) ); msg_Warn( p_filter, "input and output formats are not similar" ); } @@ -126,20 +126,26 @@ static int Open( vlc_object_t *p_this ) } 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 ); + i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio ); + p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) ); + if( !p_sys ) + return VLC_ENOMEM; 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" ); if( p_sys->f_max <= 0 ) p_sys->f_max = 0.01; /* We need to store (nb_buffers+1)*nb_channels floats */ - p_sys->p_last = malloc( sizeof( float ) * (i_channels) * - (p_filter->p_sys->i_nb + 2) ); - memset( p_sys->p_last, 0 ,sizeof( float ) * (i_channels) * - (p_filter->p_sys->i_nb + 2) ); + p_sys->p_last = calloc( i_channels * (p_filter->p_sys->i_nb + 2), sizeof(float) ); + if( !p_sys->p_last ) + { + free( p_sys ); + return VLC_ENOMEM; + } + return VLC_SUCCESS; } @@ -155,19 +161,25 @@ static int Open( vlc_object_t *p_this ) int i, i_chan; int i_samples = p_in_buf->i_nb_samples; - int i_channels = aout_FormatNbChannels( &p_filter->input ); + int i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio ); float *p_out = (float*)p_out_buf->p_buffer; float *p_in = (float*)p_in_buf->p_buffer; struct aout_filter_sys_t *p_sys = p_filter->p_sys; - pf_sum = (float *)malloc( sizeof(float) * i_channels ); - memset( pf_sum, 0, sizeof(float) * i_channels ); + pf_sum = calloc( i_channels, sizeof(float) ); + if( !pf_sum ) + return; - pf_gain = (float *)malloc( sizeof(float) * i_channels ); + pf_gain = malloc( sizeof(float) * i_channels ); + if( !pf_gain ) + { + free( pf_sum ); + return; + } p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes; + p_out_buf->i_buffer = p_in_buf->i_buffer; /* Calculate the average power level on this buffer */ for( i = 0 ; i < i_samples; i++ ) @@ -241,9 +253,6 @@ static void Close( vlc_object_t *p_this ) aout_filter_t *p_filter = (aout_filter_t*)p_this; aout_filter_sys_t *p_sys = p_filter->p_sys; - if( p_sys ) - { - if( p_sys->p_last) free( p_sys->p_last ); - free( p_sys ); - } + free( p_sys->p_last ); + free( p_sys ); }